Skip to content

Commit 0145a82

Browse files
authored
fix: move minimum-release-age to pnpm-workspace.yaml, fix Socket package downgrades (#136)
* fix: move minimum-release-age to pnpm-workspace.yaml, fix Socket package downgrades - Move pnpm's minimum-release-age from .npmrc to pnpm-workspace.yaml to avoid npm v11+ warning about unknown config key - Keep min-release-age=7 in .npmrc for npm - Fix update script: bypass age gate for @socketsecurity/* and @socketregistry/* via env override (prevents downgrades) * fix(test): replace flaky clock-skew cache tests with real TTL expiration test The two clock-skew tests didn't actually test clock skew — they just did set/get/clear without creating far-future entries. They were slow (filesystem IO) and caused CI worker timeouts. Replaced with a single memoized TTL expiration test that verifies entries expire after TTL.
1 parent 539f3ff commit 0145a82

4 files changed

Lines changed: 18 additions & 47 deletions

File tree

.npmrc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ ignore-scripts=true
22
link-workspace-packages=false
33
loglevel=error
44
prefer-workspace-packages=false
5-
# Minimum release age - wait 7 days before installing newly published packages
6-
# pnpm uses minimum-release-age (minutes), npm v11+ uses min-release-age (days)
7-
minimum-release-age=10080
5+
# Minimum release age for npm v11+ (days).
6+
# pnpm equivalent is in pnpm-workspace.yaml (minimumReleaseAge).
87
min-release-age=7
98

109
trust-policy=no-downgrade

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
settings:
2+
# Wait 7 days (10080 minutes) before installing newly published packages.
3+
minimumReleaseAge: 10080

scripts/update.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ async function main() {
4444
process.stdout.write('\r\x1b[K')
4545
}
4646

47-
// Always update Socket packages (bypass taze maturity period).
47+
// Update Socket packages — bypass minimum-release-age since these are
48+
// our own packages and we trust them immediately.
4849
if (!quiet) {
4950
logger.progress('Updating Socket packages...')
5051
}
@@ -60,12 +61,12 @@ async function main() {
6061
'-r',
6162
],
6263
{
64+
env: { ...process.env, npm_config_minimum_release_age: '0' },
6365
shell: WIN32,
6466
stdio: quiet ? 'pipe' : 'inherit',
6567
},
6668
)
6769

68-
// Clear progress line.
6970
if (!quiet) {
7071
process.stdout.write('\r\x1b[K')
7172
}

test/unit/cache-with-ttl.test.mts

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -467,52 +467,20 @@ describe.sequential('cache-with-ttl', () => {
467467
await refreshCache.clear()
468468
})
469469

470-
it('should treat far-future expiresAt as expired (clock skew protection)', async () => {
471-
// This tests the fix in cache-with-ttl.ts:190-203
472-
// The isExpired() function checks if expiresAt > now + ttl * 2
473-
// to detect clock skew or corruption
474-
475-
const clockSkewCache = createTtlCache({
476-
ttl: 1000, // 1 second TTL
477-
prefix: 'clock-skew-test',
478-
memoize: true, // Use memoization to test the isExpired logic directly
479-
})
480-
481-
// Set a value - this will create an entry with normal expiration
482-
await clockSkewCache.set('key', 'value')
483-
484-
// Verify value is cached
485-
expect(await clockSkewCache.get<string>('key')).toBe('value')
486-
487-
// The internal isExpired function will reject entries where:
488-
// expiresAt > Date.now() + ttl * 2
489-
// This protects against clock skew where the system clock jumps forward
490-
491-
// Note: We can't easily test the actual clock skew scenario without
492-
// manipulating cacache internals, but the fix is in place and handles:
493-
// - Entries with far-future expiresAt (>2x TTL) are treated as expired
494-
// - Normal future expiresAt values (within TTL) work correctly
495-
496-
await clockSkewCache.clear()
497-
})
498-
499-
it('should handle slightly future expiresAt within reasonable bounds', async () => {
500-
const normalCache = createTtlCache({
501-
ttl: 5000, // 5 second TTL
502-
prefix: 'normal-future-cache',
470+
it('should expire entries and return undefined after TTL (memoized)', async () => {
471+
const shortCache = createTtlCache({
472+
ttl: 200,
473+
prefix: 'short-memo-cache',
474+
memoize: true,
503475
})
504476

505-
// Set a value - expiresAt will be Date.now() + 5000
506-
await normalCache.set('key', 'value')
507-
508-
// Value should be retrievable immediately (expiresAt is in future as expected)
509-
const result = await normalCache.get<string>('key')
510-
expect(result).toBe('value')
477+
await shortCache.set('key', 'value')
478+
expect(await shortCache.get<string>('key')).toBe('value')
511479

512-
// Only far-future values (>2x TTL) should be treated as expired
513-
// This tests that normal future expiresAt values work correctly
480+
await new Promise(resolve => setTimeout(resolve, 300))
481+
expect(await shortCache.get<string>('key')).toBeUndefined()
514482

515-
await normalCache.clear()
483+
await shortCache.clear()
516484
})
517485
})
518486

0 commit comments

Comments
 (0)