@@ -27,6 +27,35 @@ const asciiUnsafeRegexp = /[\u0000-\u0007\u0009\u000b-\u001f\u0080-\uffff]/g
2727// Note: The fixture directory is in the same directory as this utils file.
2828export const testPath = __dirname
2929
30+ // Optimize fixture paths for package manager integration tests
31+ export const OPTIMIZE_FIXTURE_PATH = path . join ( testPath , 'fixtures/optimize' )
32+ export const PNPM_V8_FIXTURE = path . join ( OPTIMIZE_FIXTURE_PATH , 'pnpm-v8' )
33+ export const PNPM_V9_FIXTURE = path . join ( OPTIMIZE_FIXTURE_PATH , 'pnpm-v9' )
34+ export const PNPM_V10_FIXTURE = path . join ( OPTIMIZE_FIXTURE_PATH , 'pnpm-v10' )
35+ export const YARN_CLASSIC_FIXTURE = path . join (
36+ OPTIMIZE_FIXTURE_PATH ,
37+ 'yarn-classic' ,
38+ )
39+ export const YARN_BERRY_FIXTURE = path . join ( OPTIMIZE_FIXTURE_PATH , 'yarn-berry' )
40+ export const BUN_FIXTURE = path . join ( OPTIMIZE_FIXTURE_PATH , 'bun' )
41+ export const VLT_FIXTURE = path . join ( OPTIMIZE_FIXTURE_PATH , 'vlt' )
42+
43+ // Agent fixture paths with installed package managers
44+ export const AGENT_FIXTURE_PATH = path . join ( testPath , 'fixtures/agent' )
45+ export const PNPM_V8_AGENT_FIXTURE = path . join ( AGENT_FIXTURE_PATH , 'pnpm-v8' )
46+ export const PNPM_V9_AGENT_FIXTURE = path . join ( AGENT_FIXTURE_PATH , 'pnpm-v9' )
47+ export const PNPM_V10_AGENT_FIXTURE = path . join ( AGENT_FIXTURE_PATH , 'pnpm-v10' )
48+ export const YARN_CLASSIC_AGENT_FIXTURE = path . join (
49+ AGENT_FIXTURE_PATH ,
50+ 'yarn-classic' ,
51+ )
52+ export const YARN_BERRY_AGENT_FIXTURE = path . join (
53+ AGENT_FIXTURE_PATH ,
54+ 'yarn-berry' ,
55+ )
56+ export const BUN_AGENT_FIXTURE = path . join ( AGENT_FIXTURE_PATH , 'bun' )
57+ export const VLT_AGENT_FIXTURE = path . join ( AGENT_FIXTURE_PATH , 'vlt' )
58+
3059function normalizeLogSymbols ( str : string ) : string {
3160 return str
3261 . replaceAll ( '✖' , '×' )
@@ -58,10 +87,47 @@ function toAsciiSafeString(str: string): string {
5887 } )
5988}
6089
90+ function stripTokenErrorMessages ( str : string ) : string {
91+ // Remove API token error messages to avoid snapshot inconsistencies
92+ // when local environment has/doesn't have tokens set.
93+ return str . replace (
94+ / ^ \s * [ × ✖ ] \s + T h i s c o m m a n d r e q u i r e s a S o c k e t A P I t o k e n f o r a c c e s s .* $ / gm,
95+ '' ,
96+ )
97+ }
98+
99+ function sanitizeTokens ( str : string ) : string {
100+ // Sanitize Socket API tokens to prevent leaking credentials into snapshots.
101+ // Socket tokens follow the format: sktsec_[alphanumeric+underscore characters]
102+
103+ // Match Socket API tokens: sktsec_ followed by word characters
104+ const tokenPattern = / s k t s e c _ \w + / g
105+ let result = str . replace ( tokenPattern , 'sktsec_REDACTED_TOKEN' )
106+
107+ // Sanitize token values in JSON-like structures
108+ result = result . replace (
109+ / " a p i T o k e n " \s * : \s * " s k t s e c _ [ ^ " ] + " / g,
110+ '"apiToken":"sktsec_REDACTED_TOKEN"' ,
111+ )
112+
113+ // Sanitize token prefixes that might be displayed (e.g., "zP416" -> "REDAC")
114+ // Match 5-character alphanumeric strings that appear after "token:" labels
115+ result = result . replace (
116+ / t o k e n : \s * \[ ? \d + m \] ? ( [ A - Z a - z 0 - 9 ] { 5 } ) \* { 3 } / gi,
117+ 'token: REDAC***' ,
118+ )
119+
120+ return result
121+ }
122+
61123export function cleanOutput ( output : string ) : string {
62124 return toAsciiSafeString (
63125 normalizeLogSymbols (
64- normalizeNewlines ( stripZeroWidthSpace ( stripAnsi ( output . trim ( ) ) ) ) ,
126+ normalizeNewlines (
127+ stripZeroWidthSpace (
128+ sanitizeTokens ( stripTokenErrorMessages ( stripAnsi ( output . trim ( ) ) ) ) ,
129+ ) ,
130+ ) ,
65131 ) ,
66132 )
67133}
0 commit comments