From 748835b266483588f910ac683b58128adb76f24a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 28 Aug 2026 00:13:08 +0000 Subject: [PATCH] Fix time-bomb test fixture: dynamic expires_at in commit.test.ts test/services/previews/v1/commit.test.ts hardcoded a fixed calendar expiry (2026-08-27T10:00:00Z) for its sample artifact. Once that date passed, ttlForArtifact() in src/services/previews/v1/routes/commit.ts computed a negative remaining-retention TTL for it, which fell below cache.ts's 60s KV floor and silently disabled caching for every test relying on it - breaking: - 'shares the metadata route's cache instead of re-listing artifacts on every download' (expected 1 artifacts-list call, got 2, since the lookup was no longer cached between the metadata and download requests) - 'caches the commit lookup for longer than the default 60s' (expected a KV put() call, got 0, since the computed TTL was negative) Replaced the fixed date with a FAR_FUTURE_EXPIRES_AT computed relative to Date.now() (matching the pattern the file's other TTL tests already use), so the fixture never again silently expires. Applied to all three artifacts in the file that represent an actual matched/cached artifact. Verified: full suite (520 tests), lint, and typecheck all pass. --- test/services/previews/v1/commit.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/services/previews/v1/commit.test.ts b/test/services/previews/v1/commit.test.ts index edbdb87..6990a3f 100644 --- a/test/services/previews/v1/commit.test.ts +++ b/test/services/previews/v1/commit.test.ts @@ -16,6 +16,15 @@ import { request as ghRequest } from "@octokit/request"; const SHA = "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2"; +// A fixed calendar date here would eventually land in the past and make +// ttlForArtifact() compute a negative TTL, silently disabling the caching +// these tests exist to verify - GitHub's own artifact retention is 14 +// days, so anything comfortably longer reads as "not expiring any time +// soon" for as long as this suite keeps running. +const FAR_FUTURE_EXPIRES_AT = new Date( + Date.now() + 365 * 24 * 60 * 60 * 1000 +).toISOString(); + const SAMPLE_ARTIFACTS = { total_count: 1, artifacts: [ @@ -23,7 +32,7 @@ const SAMPLE_ARTIFACTS = { id: 555, size_in_bytes: 12345, created_at: "2026-08-13T10:00:00Z", - expires_at: "2026-08-27T10:00:00Z", + expires_at: FAR_FUTURE_EXPIRES_AT, expired: false, digest: "sha256:deadbeef", workflow_run: { id: 999, head_sha: SHA } @@ -297,7 +306,7 @@ describe("Previews API v1 - GET /previews/v1/commit/:sha", () => { name: "FOSSBilling-preview-deadbee.zip", size_in_bytes: 99, created_at: "2026-08-13T11:00:00Z", - expires_at: "2026-08-27T11:00:00Z", + expires_at: FAR_FUTURE_EXPIRES_AT, expired: false, digest: "sha256:fromfork", workflow_run: { id: 888, head_sha: SHA } @@ -354,7 +363,7 @@ describe("Previews API v1 - GET /previews/v1/commit/:sha", () => { name: "FOSSBilling-preview-deadbee.zip", size_in_bytes: 99, created_at: "2026-08-13T11:00:00Z", - expires_at: "2026-08-27T11:00:00Z", + expires_at: FAR_FUTURE_EXPIRES_AT, expired: false, digest: "sha256:page6", workflow_run: { id: 888, head_sha: SHA }