Skip to content

test(server): settle the abandoned installation-token request so stores.test.ts passes in any order (__tests__/server/stores.test.ts) - #633

Merged
mrbobbytables merged 1 commit into
mainfrom
quality/test-stores-token-dedupe-order
Oct 31, 2026
Merged

mrbobbytables merged 1 commit into
mainfrom
quality/test-stores-token-dedupe-order

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

One existing case in __tests__/server/stores.test.ts — main() gives up waiting after the grace period — plus a paragraph in docs/contributing.md ("Test order"). No src/, config, chart or workflow change.

  • the POST /app/installations/7/access_tokens handler no longer returns a promise that never resolves; it holds on a promise the test settles with a 500 in its finally
  • the parked delivery's error log line is awaited before process.stdout.write is un-spied, so nothing leaks into the next test's listeners
  • listening.close(0) is called in finally, as the sibling main() cases already do

Why. @octokit/auth-app 8.3.1 deduplicates concurrent token requests per installation in a module-level map (dist-src/get-installation-authentication.js:25, pendingPromises), shared by every createAppAuth in the process — not one per App or receiver. A token request the test never answers therefore parks every later installationToken(7) in the same file: the next test that mints a token hangs until its 5 s timeout without issuing a request (traced: SEEN done → TOKEN start → nothing, no fetch, no WebCrypto call). In source order only token-free cases follow gives up, so the default run is green by luck.

Evidence at main@ed3bb42: npx vitest run --sequence.shuffle --sequence.seed=<s> --exclude '__tests__/bundle/**' fails under seeds 777 (1 test), 31 and 20261030 (3 tests each), all in __tests__/server/stores.test.ts; pairwise reordering isolates gives up → locks an event about no issue or pull request under its own delivery id as the only poisoning pair. npm run test:shuffle is not a CI step, so nothing caught it. grep shows no other test file answers an access_tokens request with a never-settling promise.

Files / cluster claimed — __tests__/server/stores.test.ts (one case) and docs/contributing.md (Test order). Held #631 also edits stores.test.ts but adds cases and leaves gives up untouched; git merge-tree --write-tree of this head against #626, #630, #631 and #632 is clean. #631's new main() with nothing in flight case mints no token, so it is not affected either way.

Testing

  • the three failing seeds above, over the whole unit suite: 134 files / 2142 passed each, three for three
  • npx vitest run __tests__/server/stores.test.ts default order and seeds 777/31/20261030: 10/10
  • npx eslint __tests__/server/stores.test.ts and npx tsc -p tsconfig.test.json — clean
  • fails without the change: reverting the handler to () => new Promise(() => {}) reproduces the timeout under seed 777 on the single file

Related Issue

None — a test-order regression in an existing file with a one-case fix; the standing "test order" class and its CI gate (a shuffled test.yml job, workflow file, needs a human) were already recorded earlier.


Filed by quality agent (hold-gated mode). Human review required.

— hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88

…es.test.ts so the file passes in any order (__tests__/server/stores.test.ts)

@octokit/auth-app 8 deduplicates concurrent token requests per installation
in a module-level map shared by every createAppAuth in the process. The
'main() gives up waiting after the grace period' case answered the
access_tokens request with a promise that never resolves, so any later test
in the file that mints a token for installation 7 hung until its timeout
without issuing a request. In source order only token-free cases follow it,
which is why the default run stayed green; 'npm run test:shuffle' fails under
seeds 777, 31 and 20261030 at main@ed3bb42.

The handler now holds on a promise the test settles with a 500 in its
finally, the parked delivery's error line is awaited before the stdout spy is
restored, and listening.close(0) is called as the sibling cases do. The
contributing guide's 'Test order' section names this fourth leak.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive
hivecommons-hive Bot requested a review from jpmcb as a code owner October 30, 2026 13:57
@hivecommons-hive hivecommons-hive Bot added the hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 30, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Important

Held for human review by the hive's ACMM level gate.

This PR was opened by the "quality" agent while Hive policy required a human checkpoint for that agent. Agent PRs are held at ACMM L3–L5; an outreach PR that targets a repository this hive does not manage is held at every level because it publishes project-facing communication into someone else's project.

Hive will keep the hold label until a human removes it. Operators can make a deliberate one-off release during an ACMM level change with release_level_holds=true, but level changes never release this hold automatically.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the diff against the tree at merge-base and the PR head; this looks correct to me.

What I verified:

  • The mechanism is real: @octokit/auth-app 8 dedupes concurrent installation-token requests in a module-level pendingPromises map (dist-src/get-installation-authentication.js:25), shared across every createAppAuth in the process. The old handler's () => new Promise(() => {}) therefore parks every later mint for installation 7 in this file — the body's seed-777 reproduction matches what I traced independently on this suite.
  • await listening.close(0) in the new finally is safe after the SIGINT exit path: close() memoizes via closing ??= (src/server/node.ts:157-160), so the second call just returns the settled promise. This matches the sibling main() cases (e.g. the graceful-shutdown case's finally at tests/server/stores.test.ts:211).
  • The 500 genuinely ends the delivery with no further requests: the node server path builds octokit without a retry plugin (src/utils/octokit.ts; the only retry in src/ is the queue-message retry in src/server/worker.ts:165).
  • Awaiting the parked delivery's error log line before write.mockRestore() (tests/server/stores.test.ts:247-248) is the right order — the late log otherwise lands in whichever spy the next test installs.
  • docs/contributing.md "Test order" count 3→4 is consistent with the added bullet.

The diff does exactly what the body claims, scope is one test case plus the doc paragraph, and the hold gate means a maintainer still merges. No findings.

— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

/kind cleanup


🐝 Hive Agent: quality | Instance: hosted-available-lke648397-260827-5q9t | SHA: ed3bb42

— hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88

@github-actions github-actions Bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed needs-kind labels Oct 30, 2026
@mrbobbytables mrbobbytables removed the hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 31, 2026
@mrbobbytables
mrbobbytables merged commit c8d094a into main Oct 31, 2026
16 checks passed
@mrbobbytables
mrbobbytables deleted the quality/test-stores-token-dedupe-order branch October 31, 2026 00:26
mrbobbytables added a commit that referenced this pull request Oct 31, 2026
…nightly, and guard the Worker's entry points (#635)

Three gaps the last month of quality findings kept hitting by hand:

- test.yml gains a `shuffle` job running `npm run test:shuffle` (with the
  Redis service, so the store tests are in the order too). #633 found an
  order-poisoning pair only because someone ran the shuffle locally; the
  suite passes in source order by luck and nothing in CI knew.

- test.yml gains a `mutation` job on the daily schedule and on
  workflow_dispatch, running `npm run test:mutation:nightly` —
  stryker.nightly.config.mjs, the default merge-decision set of
  stryker.config.mjs with no incremental file and a `break` score of 95
  (main reaches 96 with six equivalent survivors). The job writes a
  per-file tally to the step summary and uploads reports/mutation/. The
  schedule trigger existed and gated nothing extra. This is the
  single-shard form of #594's proposal; the whole-tree five-shard matrix
  (5+ hours of runner time nightly) is declined for now.

- __tests__/worker/entryPoints.test.ts: src/server/worker.ts is excluded
  from both coverage runs because it only executes inside workerd, so
  scheduled(), queue() and deferViaQueue shipped with no test and no
  number moved (#629). The guard parses the file's default-export
  handlers, Hono routes and top-level functions, requires each to be
  listed with the evidence in __tests__/worker that drives it, and
  requires that evidence to be present — a new entry point or a deleted
  driver fails the unit run. The exclusion comment in vitest.config.mjs
  points at it.

docs/contributing.md records the two jobs and the new script.

Closes #594

Signed-off-by: Bob Killen <bkillen@linuxfoundation.org>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant