From e9b6e71b1f494644e105727248a36ead2b586aab Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 09:46:59 -0400 Subject: [PATCH] test(server): settle the abandoned installation-token request in stores.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> --- __tests__/server/stores.test.ts | 15 ++++++++++++++- docs/contributing.md | 12 +++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/__tests__/server/stores.test.ts b/__tests__/server/stores.test.ts index 7f8418b7..8534e315 100644 --- a/__tests__/server/stores.test.ts +++ b/__tests__/server/stores.test.ts @@ -221,7 +221,17 @@ describe('the server with stores', () => { const port = 21000 + Math.floor(Math.random() * 1000) const { passthrough } = await import('msw') server.use(http.all(`http://127.0.0.1:${port}/*`, () => passthrough())) - server.use(http.post(`${api}/app/installations/7/access_tokens`, () => new Promise(() => {}))) + // @octokit/auth-app shares one pending-request map per installation across every + // createAppAuth in the process, so a token request this test never answered would + // hang the next test of this file that mints a token for installation 7 + let abandonToken!: () => void + const tokenHeld = new Promise((resolve) => { + abandonToken = resolve + }) + server.use(http.post(`${api}/app/installations/7/access_tokens`, async () => { + await tokenHeld + return new Response('abandoned by the test', { status: 500 }) + })) const listening = main({ ...env, PORT: String(port), PROW_SHUTDOWN_GRACE_MS: '30' }, signals) try { await listening.ready @@ -234,6 +244,9 @@ describe('the server with stores', () => { await vi.waitFor(() => expect(exit).toHaveBeenCalledWith(0)) } finally { + abandonToken() + await vi.waitFor(() => expect(write.mock.calls.map(call => JSON.parse(String(call[0])) as { level: string })).toContainEqual(expect.objectContaining({ level: 'error' }))) + await listening.close(0) write.mockRestore() } }) diff --git a/docs/contributing.md b/docs/contributing.md index 14174d57..8a615c77 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -125,7 +125,7 @@ range of its own, is counted correctly. Vitest runs the tests of a file in source order, so a test that leaves state behind is only noticed by the tests that happen to follow it. `npm run test:shuffle` runs every file's tests in a random order (the seed is printed -with the failure; `--sequence.seed=` repeats it). The three ways a test has +with the failure; `--sequence.seed=` repeats it). The four ways a test has leaked into its neighbour here, and how each file now avoids them: - **A mutated fixture.** The JSON fixtures are imported once per file, so @@ -151,6 +151,16 @@ leaked into its neighbour here, and how each file now avoids them: `utils.newRun()`. A file that uses `vi.resetModules()` must import `@actions/core` and the module under test fresh together, or the assertion spies on a different `core` instance than the one the module warns through. +- **An installation-token request that never settles.** `@octokit/auth-app` + deduplicates concurrent token requests for one installation in a map that is + shared by every `createAppAuth` in the process, not one per App. An msw + handler for `POST /app/installations/{id}/access_tokens` that returns a + promise which never resolves therefore parks every later mint for that + installation in the same file, however many receivers the tests build — the + next test that mints a token hangs until its timeout without issuing a + request. Hold the handler on a promise the test settles in its `finally` + (a 500 ends the delivery with no further requests), and wait for the parked + delivery's failure line before restoring the spies it logs through. ### Mutation checks