Skip to content

test(selfhost): jobCoalesceKey's missing-field fallback branches are untested for 6 job types #5850

Description

@JSONbored

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:

  1. backfill-repo-segment with only type+requestedBy (or the minimal required shape) →
    "backfill-repo-segment:unknown:unknown:default:0:start".
  2. 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.
  3. generate-review-recap (or generate-signal-snapshots/build-burden-forecasts) with no
    repoFullName"<type>:all".
  4. refresh-contributor-activity with no repoFullName"refresh-contributor-activity:<login>:all",
    and with no login → the unknown token.
  5. rollup-product-usage with no day/days"rollup-product-usage:latest:default".
  6. generate-weekly-value-report with no variant/days"generate-weekly-value-report:operator:default".

Deliverables

  • New it(...) block(s) in test/unit/selfhost-queue-common.test.ts covering the six job types'
    missing-field fallback keys per the requirements above.

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions