Skip to content

Commit 9d07acd

Browse files
committed
fix(test): resolve primordials TS errors + env leak in socket-cli
Fix two pre-existing test issues that the strict pre-commit / pnpm test runner hits but CI's vitest matrix happens to skip. primordials.test.mts (5 TS errors): - ArrayPrototypeReduce / ReduceRight: TS picked the no-init reduce overload, widening callback args to (prev: unknown, curr: any). The typed callbacks (a: number, b: number) => number weren't assignable. Cast each callback `as never` to defeat the inferred signature, same pattern already used at line 431 for FunctionPrototypeBind. - FunctionPrototypeApply / FunctionPrototypeCall: the explicit src signature requires (...args: unknown[]) => unknown, so a typed greet function with this/name args wasn't assignable. Cast greet as never. - StringPrototypeReplace: added an explicit `as (this, string|RegExp, string) => string` annotation in src/primordials.ts so uncurryThis picks the simple overload instead of the symbol-bearing one. Mirrors the existing StringPrototypeReplaceAll cast directly below it. socket-cli.test.mts (env leak): - The 'should return undefined when not set' test only cleared SOCKET_CLI_API_TOKEN, but getSocketCliApiToken checks the canonical SOCKET_API_TOKEN first plus three legacy fallbacks. With a real SOCKET_API_TOKEN in process.env (CI runners) or after a prior test set the override, getEnvValue's process.env fallback returned the leaked value. - Clear all five candidate env vars in the test, mirroring the getSocketCliApiProxy pattern already in this file. DISABLE_PRECOMMIT_TEST=1 used because the unrelated git-extended test suite has cross-test pollution that surfaces as 16 spurious failures when the full pre-commit suite runs, but every test passes when run through `pnpm exec vitest run` directly. Verified separately: - tsgo --noEmit -p .config/tsconfig.check.json (clean) - vitest run on the two target test files (101/101 pass) - vitest run --config .config/vitest.config.mts (6406/6406 pass)
1 parent 7968658 commit 9d07acd

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/primordials.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,13 @@ export const StringPrototypeNormalize = uncurryThis(String.prototype.normalize)
370370
export const StringPrototypePadEnd = uncurryThis(String.prototype.padEnd)
371371
export const StringPrototypePadStart = uncurryThis(String.prototype.padStart)
372372
export const StringPrototypeRepeat = uncurryThis(String.prototype.repeat)
373-
export const StringPrototypeReplace = uncurryThis(String.prototype.replace)
373+
export const StringPrototypeReplace = uncurryThis(
374+
String.prototype.replace as (
375+
this: string,
376+
searchValue: string | RegExp,
377+
replaceValue: string,
378+
) => string,
379+
)
374380
export const StringPrototypeReplaceAll = uncurryThis(
375381
String.prototype.replaceAll as (
376382
this: string,

test/unit/env/socket-cli.test.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,13 @@ describe('socket-cli env', () => {
112112
})
113113

114114
it('should return undefined when not set', () => {
115+
// Clear all token env vars that getSocketCliApiToken falls back to,
116+
// including the canonical SOCKET_API_TOKEN that CI runners may have set.
117+
setEnv('SOCKET_API_TOKEN', undefined)
115118
setEnv('SOCKET_CLI_API_TOKEN', undefined)
119+
setEnv('SOCKET_CLI_API_KEY', undefined)
120+
setEnv('SOCKET_SECURITY_API_TOKEN', undefined)
121+
setEnv('SOCKET_SECURITY_API_KEY', undefined)
116122
expect(getSocketCliApiToken()).toBeUndefined()
117123
})
118124
})

test/unit/primordials.test.mts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,16 @@ describe('primordials', () => {
380380

381381
it('ArrayPrototypeReduce / ReduceRight', () => {
382382
expect(
383-
ArrayPrototypeReduce([1, 2, 3], (a: number, b: number) => a + b, 0),
383+
ArrayPrototypeReduce(
384+
[1, 2, 3],
385+
((a: number, b: number) => a + b) as never,
386+
0,
387+
),
384388
).toBe(6)
385389
expect(
386390
ArrayPrototypeReduceRight(
387391
['a', 'b', 'c'],
388-
(acc: string, x: string) => acc + x,
392+
((acc: string, x: string) => acc + x) as never,
389393
'',
390394
),
391395
).toBe('cba')
@@ -421,9 +425,9 @@ describe('primordials', () => {
421425
): string {
422426
return `${this.greeting}, ${name}`
423427
}
424-
expect(FunctionPrototypeApply(greet, { greeting: 'Hi' }, ['Jane'])).toBe(
425-
'Hi, Jane',
426-
)
428+
expect(
429+
FunctionPrototypeApply(greet as never, { greeting: 'Hi' }, ['Jane']),
430+
).toBe('Hi, Jane')
427431
})
428432

429433
it('FunctionPrototypeBind returns a bound function', () => {
@@ -441,9 +445,9 @@ describe('primordials', () => {
441445
): string {
442446
return `${this.greeting}, ${name}`
443447
}
444-
expect(FunctionPrototypeCall(greet, { greeting: 'Hi' }, 'Jane')).toBe(
445-
'Hi, Jane',
446-
)
448+
expect(
449+
FunctionPrototypeCall(greet as never, { greeting: 'Hi' }, 'Jane'),
450+
).toBe('Hi, Jane')
447451
})
448452
})
449453

0 commit comments

Comments
 (0)