Public: anyone can read this; the crew can change it.

"RepoSource: one repository, two places to read it from > a mirror reports its stages in order and ends holding the repo" passes every time on a loaded check machine #5399

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The test is fixed and no product code changed. `bun test --rerun-each 30 test/view-source.test.ts -t "a mirror reports its stages"` passes 30 of 30, and the whole file passes (23 tests). I didn't get a type check: `tsc` has no `bun` types here and I didn't run `bun install`. I've pushed the branch but haven't seen the forge's check result yet.

shipped production is serving it deploy 84c60a0

opened this

The test is fixed and no product code changed. bun test --rerun-each 30 test/view-source.test.ts -t "a mirror reports its stages" passes 30 of 30, and the whole file passes (23 tests). I didn't get a type check: tsc has no bun types here and I didn't run bun install. I've pushed the branch but haven't seen the forge's check result yet.

Cause: this was a race in the test. subscribe() in src/origins/jobs.ts replays only the stage the job is on when you subscribe, which is by design. The test subscribed after the POST returned and its body was read. On a loaded machine the mirror could finish in that gap. The subscriber then saw only done, so seen[0] was not creating and issues was missing.

Change:

  • The fake forge in test/fake-origin.ts gets an optional holdLabels promise that holds the label-list GET until it resolves.
  • The test sets it before the POST and releases it once it is subscribed. The job then can't get past the label import before the test is listening. It waits on that promise, with no sleep.
  • seen starts with the creating stage from the 202 response, since the subscription can no longer observe it.
  • Every assertion is unchanged: stage order, first is creating, last is done, issues seen, repo and finishedAt set. No timeouts or retries were added.

Left out: I didn't add stage history to jobs. The product behaves as designed, and the replay-latest rule is what the UI relies on.

Closes #5394

commented

The test is fixed and no product code changed. bun test --rerun-each 30 test/view-source.test.ts -t "a mirror reports its stages" passes 30 of 30, and the whole file passes (23 tests). I didn't get a type check: tsc has no bun types here and I didn't run bun install. I've pushed the branch but haven't seen the forge's check result yet.

Cause: this was a race in the test. subscribe() in src/origins/jobs.ts replays only the stage the job is on when you subscribe, which is by design. The test subscribed after the POST returned and its body was read. On a loaded machine the mirror could finish in that gap. The subscriber then saw only done, so seen[0] was not creating and issues was missing.

Change:

  • The fake forge in test/fake-origin.ts gets an optional holdLabels promise that holds the label-list GET until it resolves.
  • The test sets it before the POST and releases it once it is subscribed. The job then can't get past the label import before the test is listening. It waits on that promise, with no sleep.
  • seen starts with the creating stage from the 202 response, since the subscription can no longer observe it.
  • Every assertion is unchanged: stage order, first is creating, last is done, issues seen, repo and finishedAt set. No timeouts or retries were added.

Left out: I didn't add stage history to jobs. The product behaves as designed, and the replay-latest rule is what the UI relies on.

commented

The mirror-stages test no longer fails when the machine is loaded. No product code changed. The type errors that failed the check are fixed, and I've pushed the fix. tsc --noEmit is clean locally. The whole of test/view-source.test.ts passes 10 times over (230 runs, 0 fail). I haven't seen the forge's new check result yet.

Cause: a race in the test. subscribe() in src/origins/jobs.ts replays only the stage the job is on when you subscribe, by design. The test subscribed after the POST returned. On a loaded machine the mirror could finish in that gap, so the subscriber saw only done. Then seen[0] was not creating and issues was missing.

Change:

  • The fake forge in test/fake-origin.ts gets an optional holdLabels promise that holds the label-list GET until it resolves.
  • The test sets it before the POST and releases it once subscribed. That pins the job before its label import, and the test waits on the promise, not a sleep.
  • seen starts from the creating stage reported in the 202 response, since the subscription can no longer observe it.
  • All assertions are unchanged, and no timeouts or retries were added.

Check failure: holdLabels now has the type Promise<void> | undefined, which exactOptionalPropertyTypes requires. The job's stage is now typed MirrorStage.

Left out: I didn't add stage history to jobs. The replay-latest behaviour is what the UI relies on.

To try: bun test --rerun-each 30 test/view-source.test.ts -t "a mirror reports its stages".

Approved

Test-only fix for a real race: subscribe() replays only the current stage, so a job that finished before the subscription showed just done. Holding the fake forge label GET until the test is subscribed removes the race without a sleep or retry, and the assertions are unchanged. No product code, dependency or security surface touched. Two things I would do next: (1) reset holdLabels in a finally/afterEach so a failed assertion cannot leave later tests blocked (it is only cleared on the success path now); (2) the pull is not a UI change, so there is nothing to see in the preview; confirm the forge check result before landing.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs