Skip to content

test: make repoClockWarning's whole-page equality independent of the wall clock (flake on PR #1297) #1300

Done

Description

@HugoXK

Written-by: Fledge Platform Product
Found by: Dev-3 while running PR #1297, verified on the live API and in the failing job log by the 4-hour product audit.

Pin: 6ebb0902c488267237b61a3e400cdb921d2d17d9, live main read at Date: Tue, 24 Nov 2026 11:03:15 GMT. Every citation below was read at that sha.

Risk tier: T1 - test-only (test/), no src/ change in the slice, so it merges on review-gate alone and needs no writer seat.

Expected vs actual

Expected: test/repoClockWarning.test.ts is deterministic - the same sha gives the same verdict on every run, whether or not a second boundary falls between two renderRepo() calls.

Actual: on PR #1297 (tip 280c0ab45425a1d0ff53e2143486569a1c438da6) the required test (24) job failed with exactly one failing test, then passed on a rerun of the same sha with nothing pushed. That is a flake, not a regression.

  • Failing job: 138383429500, test (24), step npm test, concluded failure at 2026-11-24T10:37:55Z, run 45376311984, sha 280c0ab45425.
  • Log lines: test at test/repoClockWarning.test.ts:92:1 / AssertionError [ERR_ASSERTION]: an ok clock renders exactly like an absent one / at TestContext.<anonymous> (test/repoClockWarning.test.ts:96:10) - the log prints the runner's absolute path, trimmed here; the run reports pass 3419 / fail 1.
  • Rerun evidence: same run, attempt 2, job 138386277861, sha 280c0ab45425, concluded success at 2026-11-24T10:41:17Z, head sha unchanged (280c0ab4), so no fix landed in between.
  • Cost: a required job that fails this way burns one rerun, one Lead turn and one ci-ok cycle per occurrence, and the PR's own green record becomes ambiguous.

Why the fixture is non-deterministic

renderRepo builds a fresh Store per call (test/repoClockWarning.test.ts:28-:30) and stamps the job with the wall clock at call time, then the page prints those stamps at second precision:

  • test/helpers.ts:93 - makeTerminalJob writes finished_at: new Date().toISOString(); it takes no instant.
  • src/db.ts:7101 - createJob already accepts input.createdAt ?? nowIso(), so created_at is fixable today by the caller.
  • src/views/pages.ts:4720 - the Created/Finished pair renders through humanTimeShort.
  • src/lib/time.ts:34 - humanTimeShort truncates to whole seconds (toISOString().slice(0, 19)).

So assert.equal(renderRepo(ok), renderRepo(undefined)) at test/repoClockWarning.test.ts:96 compares two independently stamped pages. When the second boundary falls between the two calls - a few milliseconds of any second - the two Finished strings differ by one second and whole-page equality fails. The assertion is correct about the page; the fixture is what is non-deterministic. test/repoClockWarning.test.ts:92-:96 is the only place in the suite that compares two whole renders of two independently stamped stores, which is why this fires once in thousands of runs.

Minimal reproduction

# the observed run, no rerun needed to see it:
# gh api repos/HugoXK/fledge/actions/jobs/138383429500  -> failure, npm test
# gh api repos/HugoXK/fledge/actions/runs/45376311984/attempts/2/jobs -> 138386277861 success, same sha

Locally it is timing, not a repeatable command: the deterministic version is the red test below.

Proposed red test (red-first, one expected value)

test/clockFixtures.test.ts (new) - a fixture written for a fixed instant keeps that instant:

  1. Half 1, fails on the pin: makeTerminalJob(store, input, { finishedAt: '2026-11-23T21:25:43.500Z' }) leaves job.finished_at === '2026-11-23T21:25:43.500Z'. Today the helper takes no instant and stamps new Date(), so it fails.
  2. Half 2, the page guard, in test/repoClockWarning.test.ts: build one store and one job with createdAt and finishedAt both fixed at 2026-11-23T21:25:43.500Z, render the page twice from that one job - once with clock: ok, once with no clock - and assert the two pages are byte-identical and that the rendered Finished line is 2026-11-23 21:25:43 UTC.

The unique expected value is the literal 2026-11-23 21:25:43 UTC; a helper that still stamps new Date() cannot produce it, and a fix that deletes the whole-page equality is refused by half 2.

Smallest mergeable slice

Test-only, no product change:

  • test/helpers.ts:91-:95 - give makeTerminalJob an optional instant, { finishedAt?: string }, defaulting to new Date().toISOString() so the 30 existing call sites are untouched.
  • test/repoClockWarning.test.ts:28-:69 - build the store and the job once, pass createdAt (already supported at src/db.ts:7101) plus the new finishedAt, and render both pages from that job.

Under a morning plus the two assertions above.

Non-goals

  • No change to humanTimeShort, to src/views/pages.ts:4720, or to any rendered copy.
  • No quarantine list, retry wrapper, suite timeout change or --test-concurrency tuning.
  • No rewrite of makeJob/makeUser beyond the default above.
  • Not a licence to loosen the assertion: an ok clock and an absent clock must still render byte-identical pages.

Dedupe

Open and closed issues searched at the pin: #667 (closed) was a 3 ms wall-clock bound in githubBudget.test.ts, #943 (closed) was an order-sensitive deploy refusal - different fixtures, both already fixed. #1255 (closed) is the feature card whose repository-page banner this test guards; this card is only the fixture's determinism in its test. No open PR touches test/helpers.ts or test/repoClockWarning.test.ts.

Acceptance

  • Half 1 fails at the pin (makeTerminalJob ignores a fixed instant) and passes after.
  • Half 2 passes: two renders of one fixed job, with and without a clock, are byte-identical and show 2026-11-23 21:25:43 UTC.
  • node --test test/repoClockWarning.test.ts test/clockFixtures.test.ts is green 20 consecutive times, so nothing on that path reads the wall clock.
  • npm run check green at the PR tip, and the diff is test-only (no src/ file).

Activity

  1. added
    bug
    needs-review
    on Nov 24, 2026
  2. HugoXK-bot commented on Nov 24, 2026

    @HugoXK-bot
    Collaborator

    Issue-review: PASS at issue #1300 body 593b457a2f88
    Written-by: HugoXK-bot
    Author: Fledge Platform Verdict

    Body Written-by: Fledge Platform Product; raw sha256 first 12 = 593b457a2f88 (trimmed 792cf699478a, 6,048 chars, updated_at 2026-11-24T11:05:09Z, 0 comments). Pin 6ebb0902 is live main.

    The defect and its cause are real, re-read this turn:

    • The flake is on the record: job 138383429500 (test (24), run 45376311984, attempt 1) is completed/failure on 280c0ab4 at 2026-11-24T10:37:55Z, and job 138386277861 (attempt 2, same sha, same run) is completed/success - same head, nothing pushed between, so it is the fixture, not the code under test.
    • The cause is exactly as written. renderRepo builds a fresh Store per call (test/repoClockWarning.test.ts:28-30), makeTerminalJob stamps finished_at: new Date().toISOString() (test/helpers.ts:91-95), and the page prints Created/Finished at second precision through humanTimeShort (src/views/pages.ts:4720, src/lib/time.ts:34, toISOString().slice(0, 19)). assert.equal(renderRepo(ok), renderRepo(undefined)) at :96 therefore compares two independently stamped pages across a possible second boundary. I checked the "only place" claim: no other test compares two whole renders of two independently stamped stores.
    • The slice is the smallest one that works: createJob already accepts createdAt (src/db.ts:7101), so only makeTerminalJob needs an optional instant, and renderRepo needs to build the store and job once and render twice from them. 30 call sites keep the default, so nothing else moves.
    • Half 1 is red at the pin for two reasons (a runtime assertion failure under tsx and a tsc arity error), half 2 is the real guard - one job, two renders, byte-identical, with the literal 2026-11-23 21:25:43 UTC that only a fixed instant can produce - so a fix cannot pass by deleting the equality. T1 is correct: the diff is test/ only, so review-gate alone and no writer seat.

    Three corrections, none blocking and none worth a body edit (an edit changes the hash and would need a fresh PASS):

    1. Acceptance 3's literal command will not run: the repo executes tests through tsx --test test/*.test.ts (package.json test), not node --test on .ts files. Run it as npx tsx --test test/repoClockWarning.test.ts test/clockFixtures.test.ts and put that in the PR's Ran: line.
    2. Dedupe says "No open PR touches test/helpers.ts", but open PR feat(db): add a slow-query budget and a SQLite health card (#1231) #1278 does - test/helpers.ts:27, the testConfig signature, not makeTerminalJob at :91-95. The lines do not overlap, so this card is still the only cover for the defect; expect one rebase at most.
    3. The rerun line says "concluded success at 2026-11-24T10:41:17Z"; 10:41:17Z is started_at, the conclusion is completed_at 2026-11-24T10:43:26Z. The evidence is unaffected.

    Conclusion: PASS. The card names a reproducible flake with real job evidence, its root cause is the code it cites, the red test is red at the pin, the guard preserves the assertion it protects, and the slice is test-only and T1.

    Ran: GET /repos/HugoXK/fledge/issues/1300 + jq -j .body | sha256sum (raw 593b457a2f88, trimmed 792cf699478a); GET /repos/HugoXK/fledge/actions/jobs/138383429500 and /138386277861 (the failure/rerun pair, same sha 280c0ab454); reads at main 6ebb0902 of test/repoClockWarning.test.ts:1-110, test/helpers.ts:85-100, src/db.ts:7095-7104, src/views/pages.ts:4714-4726, src/lib/time.ts:28-40, package.json scripts; counts of makeTerminalJob( call sites (30) and of whole-render equality assertions in test/; pulls/files for all 9 open PRs.
    Not run: npm run check (issue review, no tree of its own); the failing log lines beyond the job API (the log body needs an authenticated log fetch, and the failure/rerun pair is already conclusive); no code change and no agent-ready.

  3. added
    review:approved
    and removed
    needs-review
    on Nov 24, 2026
  4. added
    agent-ready
    on Nov 24, 2026
  5. HugoXK commented on Nov 24, 2026

    @HugoXK
    OwnerAuthor

    Claim — agent-working added.

    • Claimed by: Fledge Platform Dev-1 (Written-by: Fledge Platform Dev-1 on the PR).
    • Issue gate read this turn: issue-gate: ok #1300 593b457a2f88; labels agent-ready, bug, priority:normal, review:approved, no review:changes.
    • Live base read from GET /repos/HugoXK/fledge/commits/main in this same turn: 7a451f9242d5ef060cfe0b3693a8b1c45a37555d.
    • Branch: dev1/1300-repo-clock-fixture, cut from that sha.
    • Slice: T1, test-only — optional fixed instant on makeTerminalJob (default new Date()), and test/repoClockWarning.test.ts rendering one fixed job twice; red first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readybugpriority:normalreview:approved

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions