Skip to content

test(server,app): pin main() shutdown, memoryLocks tail cleanup and redisLocks ttl from #623 (__tests__/server/{stores,cronInterval}, __tests__/adapters/app/{lock,redis}) - #631

Merged
mrbobbytables merged 1 commit into
mainfrom
quality/test-623-stores-shutdown-locks
Oct 31, 2026
Merged

mrbobbytables merged 1 commit into
mainfrom
quality/test-623-stores-shutdown-locks

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Test Improvement

Assertions added to the four suites that already exercise #623's shared stores and the server's shutdown — __tests__/adapters/app/{lock,redis}.test.ts, __tests__/server/{stores,cronInterval}.test.ts. No src/, config, chart or docs change.

  • memoryLocks — a caller arriving after the first holder has finished, while a second is still queued, must wait behind that second one. The finally only deletes the key's tail when it is still its own (lock.ts:35); if it deleted unconditionally (or on !==) the newcomer would start a fresh chain and run alongside the queued holder — exactly the race the lock exists to prevent.
  • redisLocks — the ttlMs option (and its 60 s default) reaches the SET NX PX call. Under options.ttlMs && 60_000 every explicit ttl became 60 s and no test noticed.
  • redisStores — createClient receives { url }; without it the client dials localhost regardless of REDIS_URL.
  • main() shutdown with nothing in flight — new case: the listener is closed (a second fetch to the port is refused), the stores are closed once, exit(0) is called, and no "shutting down: waiting …" line is logged (the pending > 0 guard). The existing drain case now asserts the level of both shutdown lines.
  • main() + PROW_CRON_INTERVAL — after close() another period elapses under fake timers and the installations endpoint is not polled again, so clearInterval(timer) is asserted.
  • /healthz and /readyz bodies (ok, stores not ready).

Why. Line coverage for these files is already 100 %, but a Stryker pass over src/adapters/app/lock.ts, src/adapters/app/redis.ts and src/server/node.ts (172 mutants, npm run test:mutation -- --mutate … config, main@ed3bb42) left 22 survivors, 12 of them behavioural: server.close() and clearInterval(timer) deleted from close(), pending > 0 → true, the tail-cleanup comparison inverted, ?? → && on ttlMs, createClient({ url }) → createClient({}), and the response/log literals. With this PR the same run reports 162/172 killed; the 10 that remain are equivalent or outside the unit suite's reach: never deleting a finished key's tail (a leak only, no observable ordering change), the stored '1' value and the token's slice(2), the >=/> deadline boundary, releaseScript → '' (only the REDIS_TEST_URL real-server case can see it: an empty EVAL returns nil and the lock is never released, so excludes two clients … times out in build-test), and the two installPlatformScope(asyncLocalScope()) calls, which the suites pre-install in beforeAll for their non-main() cases.

Files / cluster claimed — the four test files above only. Disjoint from held #626 (charts/prow-github-app/tests/**) and #630 (__tests__/worker/worker.test.ts).

Testing

  • npx vitest run __tests__/adapters/app/lock.test.ts __tests__/adapters/app/redis.test.ts __tests__/server/stores.test.ts __tests__/server/cronInterval.test.ts — 27 passed, 3 skipped (the real-redis cases, no REDIS_TEST_URL locally), three runs in a row
  • npx eslint on the four files — clean
  • Stryker over the three source files before/after: 146 → 162 of 172 killed; every mutant named above as behavioural is killed by exactly the case that claims it

Related Issue

None — mutation-strength findings are held behind the gate proposal in #594; this pins the new #623 code only, and #594's decision is unaffected.


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

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

…behaviour from #623

main()'s close() cleared the cron interval and stopped the listener, and
memoryLocks only dropped a key's tail when it was still its own, without
any test noticing either: Stryker reported both calls, the pending > 0
guard, the `tails.get(key) === settled` comparison, redisLocks' ttlMs
default and createClient's url as survivors. Each is now asserted by a
test that fails with the statement removed or inverted.

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 added the hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 30, 2026
@hivecommons-hive
hivecommons-hive Bot requested a review from jpmcb as a code owner October 30, 2026 05:28
@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 sources it pins; everything checks out. Test-only change, no src/ edits, CI green at 8d19980.

Verified against the tree:

  • memoryLocks tail cleanup — src/adapters/app/lock.ts:35-37 deletes the key only when tails.get(key) === settled. The new a→b→c case in lock.test.ts genuinely exercises it: when a finishes, the map holds b's settled tail, so an unconditional (or !==) delete would let c start a fresh chain and run alongside b. The test's mid-sequence assertion (c:start absent until second.open()) would catch exactly that.
  • redisLocks default ttl — src/adapters/app/redis.ts:37 is options.ttlMs ?? 60_000; the new assertion set prow:lock:k {"NX":true,"PX":60000} matches the option order at redis.ts:44 as serialized by the existing fakeRedis helper. The strengthened explicit-ttl assertion (PX":500) now distinguishes ?? from &&, as the body claims.
  • shutdown with nothing in flight — src/server/node.ts:159-163: clearInterval(timer), server.close(), then the pending > 0 guard around the "shutting down: waiting…" line; :167 logs shut down, :172 calls exit(0). The new case asserts the exact log sequence (no waiting line), single store close, refused follow-up fetch — pinning server.close() and the guard.
  • cron interval cleared — advancing fake timers 60 s after close() with polls unchanged pins clearInterval(timer) at node.ts:159.
  • createClient({ url }) — node.ts:37; the new toHaveBeenLastCalledWith({ url: 'redis://x' }) would fail on createClient({}).

File set is disjoint from #626 (chart tests) and #630 (worker tests) as the body states. One minor note, not a defect: the new shutdown case binds a random port in 23000–23999, so a rare collision with a parallel test is possible; the existing drain case already uses the same pattern, so this follows repo precedent.

Looks correct to me — a maintainer can take this at face value. (PR carries the hold label; merging stays a human call.)

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

/kind cleanup

Test-only change, same classification jeefy gave the sibling test PR #626. hold stays; merge remains a maintainer call.


🐝 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

@mrbobbytables

Copy link
Copy Markdown
Member

Verified on main+this branch (after #633): npx vitest run --sequence.shuffle --sequence.seed=<777|31|20261030> --exclude '__tests__/bundle/**' __tests__/server __tests__/adapters — 15 files / 91 passed under each seed.

@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 6b9bad7 into main Oct 31, 2026
13 checks passed
@mrbobbytables
mrbobbytables deleted the quality/test-623-stores-shutdown-locks branch October 31, 2026 00:34
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