Context
src/selfhost/queue-common.ts's jobCoalesceKey(message) builds the dedup key that lets the
self-host queue coalesce a re-enqueued job into an already-pending/processing one instead of inserting
a duplicate row (the same mechanism the #4505 regression fix relies on). Several of its per-job-type
switch branches build the key from a chain of normalizedX(...) ?? "<default>" fallbacks, but
test/unit/selfhost-queue-common.test.ts's "coalesces recurring maintenance jobs while preserving their semantic scope" test (and the rest of the file) only ever supplies every relevant field —
the missing-field fallback side of these ?? chains is never exercised. A local unsharded
npm run test:coverage run confirms src/selfhost/queue-common.ts sits at 96.23% branch coverage
(485/504) with these specific branches uncovered:
backfill-repo-segment (lines 952-960): only tested with repoFullName, segment, mode,
force, and cursor ALL present ("backfill-repo-segment:jsonbored/gittensory:labels:resume:1:page-2").
The ?? "unknown" (repo), ?? "unknown" (segment), ?? "default" (mode), and ?? "start" (cursor)
fallback arms are never taken.
backfill-pr-details (lines 961-967): has no test at all — not even the happy path.
generate-signal-snapshots" / "build-burden-forecasts" / "generate-review-recap" (line 974,
keyOf(type, normalizedRepo(message.repoFullName) ?? "all")): generate-review-recap is tested
with a real repoFullName (the #4505 regression test), but the ?? "all" fallback for a missing
repoFullName is untested for any of these three types.
refresh-contributor-activity (lines 990-995): tested only with both login and repoFullName
present; the ?? "unknown" (login) and ?? "all" (repoFullName) fallbacks are untested.
rollup-product-usage (lines 996-1001): tested only with both day and days present; the
?? "latest" and ?? "default" fallbacks are untested.
generate-weekly-value-report (lines 1004-1009): tested only with both variant and days
present; the ?? "operator" and ?? "default" fallbacks are untested.
Requirements
Add test cases to test/unit/selfhost-queue-common.test.ts (near the existing
"coalesces recurring maintenance jobs..." test) that call jobCoalesceKey with each of the six job
types above given ONLY the required fields, omitting every optional one, and assert the resulting key
uses the documented default token for each missing field:
backfill-repo-segment with only type+requestedBy (or the minimal required shape) →
"backfill-repo-segment:unknown:unknown:default:0:start".
backfill-pr-details with all fields present AND with fields omitted → asserts both the happy-path
key shape (currently untested) and the unknown:default:start fallback key.
generate-review-recap (or generate-signal-snapshots/build-burden-forecasts) with no
repoFullName → "<type>:all".
refresh-contributor-activity with no repoFullName → "refresh-contributor-activity:<login>:all",
and with no login → the unknown token.
rollup-product-usage with no day/days → "rollup-product-usage:latest:default".
generate-weekly-value-report with no variant/days → "generate-weekly-value-report:operator:default".
Deliverables
Test Coverage Requirements
src/selfhost/queue-common.ts is scored by the 99%+ codecov/patch gate on any future touching PR
(it is not in codecov.yml's ignore: list, unlike its sibling pg-adapter.ts/pg-queue.ts). This
closes the dozen-plus ?? "<default>" fallback branches identified above inside jobCoalesceKey.
Expected Outcome
Every jobCoalesceKey job-type branch is exercised on both the field-present AND field-missing side,
so a future refactor of the dedup-key format can't silently break the missing-field fallback without a
test catching it — the same category of gap the #4505 fix itself was filed to close for a
previously-uncovered job type.
Links & Resources
src/selfhost/queue-common.ts (function jobCoalesceKey, lines ~925-1010)
test/unit/selfhost-queue-common.test.ts (file to extend, see the existing
"coalesces recurring maintenance jobs while preserving their semantic scope" and
"REGRESSION (#4505): generate-review-recap coalesces per-repo..." tests for the pattern to mirror)
Context
src/selfhost/queue-common.ts'sjobCoalesceKey(message)builds the dedup key that lets theself-host queue coalesce a re-enqueued job into an already-pending/processing one instead of inserting
a duplicate row (the same mechanism the
#4505regression fix relies on). Several of its per-job-typeswitchbranches build the key from a chain ofnormalizedX(...) ?? "<default>"fallbacks, buttest/unit/selfhost-queue-common.test.ts's"coalesces recurring maintenance jobs while preserving their semantic scope"test (and the rest of the file) only ever supplies every relevant field —the missing-field fallback side of these
??chains is never exercised. A local unshardednpm run test:coveragerun confirmssrc/selfhost/queue-common.tssits at 96.23% branch coverage(485/504) with these specific branches uncovered:
backfill-repo-segment(lines 952-960): only tested withrepoFullName,segment,mode,force, andcursorALL present ("backfill-repo-segment:jsonbored/gittensory:labels:resume:1:page-2").The
?? "unknown"(repo),?? "unknown"(segment),?? "default"(mode), and?? "start"(cursor)fallback arms are never taken.
backfill-pr-details(lines 961-967): has no test at all — not even the happy path.generate-signal-snapshots"/"build-burden-forecasts"/"generate-review-recap"(line 974,keyOf(type, normalizedRepo(message.repoFullName) ?? "all")):generate-review-recapis testedwith a real
repoFullName(the#4505regression test), but the?? "all"fallback for a missingrepoFullNameis untested for any of these three types.refresh-contributor-activity(lines 990-995): tested only with bothloginandrepoFullNamepresent; the
?? "unknown"(login) and?? "all"(repoFullName) fallbacks are untested.rollup-product-usage(lines 996-1001): tested only with bothdayanddayspresent; the?? "latest"and?? "default"fallbacks are untested.generate-weekly-value-report(lines 1004-1009): tested only with bothvariantanddayspresent; the
?? "operator"and?? "default"fallbacks are untested.Requirements
Add test cases to
test/unit/selfhost-queue-common.test.ts(near the existing"coalesces recurring maintenance jobs..."test) that calljobCoalesceKeywith each of the six jobtypes above given ONLY the required fields, omitting every optional one, and assert the resulting key
uses the documented default token for each missing field:
backfill-repo-segmentwith onlytype+requestedBy(or the minimal required shape) →"backfill-repo-segment:unknown:unknown:default:0:start".backfill-pr-detailswith all fields present AND with fields omitted → asserts both the happy-pathkey shape (currently untested) and the
unknown:default:startfallback key.generate-review-recap(orgenerate-signal-snapshots/build-burden-forecasts) with norepoFullName→"<type>:all".refresh-contributor-activitywith norepoFullName→"refresh-contributor-activity:<login>:all",and with no
login→ theunknowntoken.rollup-product-usagewith noday/days→"rollup-product-usage:latest:default".generate-weekly-value-reportwith novariant/days→"generate-weekly-value-report:operator:default".Deliverables
it(...)block(s) intest/unit/selfhost-queue-common.test.tscovering the six job types'missing-field fallback keys per the requirements above.
Test Coverage Requirements
src/selfhost/queue-common.tsis scored by the 99%+codecov/patchgate on any future touching PR(it is not in
codecov.yml'signore:list, unlike its siblingpg-adapter.ts/pg-queue.ts). Thiscloses the dozen-plus
?? "<default>"fallback branches identified above insidejobCoalesceKey.Expected Outcome
Every
jobCoalesceKeyjob-type branch is exercised on both the field-present AND field-missing side,so a future refactor of the dedup-key format can't silently break the missing-field fallback without a
test catching it — the same category of gap the
#4505fix itself was filed to close for apreviously-uncovered job type.
Links & Resources
src/selfhost/queue-common.ts(functionjobCoalesceKey, lines ~925-1010)test/unit/selfhost-queue-common.test.ts(file to extend, see the existing"coalesces recurring maintenance jobs while preserving their semantic scope"and"REGRESSION (#4505): generate-review-recap coalesces per-repo..."tests for the pattern to mirror)