diff --git a/package.json b/package.json index 728ea38..2cfe02a 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "LICENSE" ], "scripts": { - "test": "npm run validate:scheduler && npm run test:integration:e2e && node --test test/*.test.mjs test/*.test.js", + "test": "npm run validate:scheduler && npm run test:integration:e2e && node --test --test-timeout=30000 test/*.test.mjs test/*.test.js", "test:unit:lock-backend": "node --test test/lock-ops.test.mjs test/lock-ops-publish-retry.test.mjs", "lock:check:daily": "node bin/torch-lock.mjs check --cadence daily", "lock:check:weekly": "node bin/torch-lock.mjs check --cadence weekly", @@ -76,7 +76,6 @@ }, "devDependencies": { "@eslint/js": "^10.0.1", - "@playwright/test": "^1.58.2", "eslint": "^10.0.0", "globals": "^17.3.0" } diff --git a/test/build_verification.test.mjs b/test/build_verification.test.mjs index 6a90043..b8350b7 100644 --- a/test/build_verification.test.mjs +++ b/test/build_verification.test.mjs @@ -5,7 +5,7 @@ import assert from 'node:assert'; const DIST_DIR = path.resolve('dist'); -test('Build artifacts verification', async (t) => { +test('Build artifacts verification', { skip: !fs.existsSync(DIST_DIR) && 'dist/ not found — run npm run build first' }, async (t) => { await t.test('dist directory exists', () => { assert.strictEqual(fs.existsSync(DIST_DIR), true, 'dist directory should exist'); }); diff --git a/test/memory-cache.test.mjs b/test/memory-cache.test.mjs index 1adde03..702fbc6 100644 --- a/test/memory-cache.test.mjs +++ b/test/memory-cache.test.mjs @@ -23,15 +23,24 @@ test('stores runtime events in signer/session namespace and clears scope', () => assert.equal(cache.getRecentRuntimeEvents({ signer_id: 'alice', session_id: 's2' }).length, 1); }); -test('expires runtime events and records expiration metrics', async () => { - const cache = createMemoryCache(); - cache.setRuntimeEvent({ signer_id: 'alice', session_id: 's1' }, { id: 1 }, 1); +test('expires runtime events and records expiration metrics', () => { + const originalNow = Date.now; + try { + const start = originalNow.call(Date); + Date.now = () => start; - await new Promise((resolve) => setTimeout(resolve, 10)); + const cache = createMemoryCache(); + cache.setRuntimeEvent({ signer_id: 'alice', session_id: 's1' }, { id: 1 }, 1); - assert.equal(cache.getRecentRuntimeEvents({ signer_id: 'alice', session_id: 's1' }).length, 0); - const metrics = cache.getMetrics(); - assert.equal(metrics.runtime_events_expired, 1); + // Advance mocked clock past the 1ms TTL + Date.now = () => start + 10; + + assert.equal(cache.getRecentRuntimeEvents({ signer_id: 'alice', session_id: 's1' }).length, 0); + const metrics = cache.getMetrics(); + assert.equal(metrics.runtime_events_expired, 1); + } finally { + Date.now = originalNow; + } }); test('enforces LRU bounds and tracks eviction metrics', () => { diff --git a/test/memory.test.js b/test/memory.test.js index 10488f4..8c6fde8 100644 --- a/test/memory.test.js +++ b/test/memory.test.js @@ -15,7 +15,12 @@ import { SYNTHETIC_EVENTS, } from './fixtures/memory-fixtures.js'; -const wait = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms)); +/** Drain the async job queue without wall-clock dependency. */ +const flushAsync = async () => { + for (let i = 0; i < 10; i++) { + await new Promise((resolve) => setImmediate(resolve)); + } +}; const withMockedNow = async (now, run) => { const originalNow = Date.now; @@ -265,7 +270,7 @@ test('scheduler smoke test handles mocked clock and lock contention', async () = }, }); - await wait(30); + await flushAsync(); scheduler.stop(); });