Skip to content

test(retention): cover pruneExpiredRecords's two defensive ?? 0 fallback arms#8504

Closed
shin-core wants to merge 1 commit into
JSONbored:mainfrom
shin-core:test/prune-expired-records-fallback-coverage-8370
Closed

test(retention): cover pruneExpiredRecords's two defensive ?? 0 fallback arms#8504
shin-core wants to merge 1 commit into
JSONbored:mainfrom
shin-core:test/prune-expired-records-fallback-coverage-8370

Conversation

@shin-core

Copy link
Copy Markdown
Contributor

What & why

Closes #8370.

pruneExpiredRecords (src/db/retention.ts) has two defensive ?? 0 fallback arms guarding against D1 driver anomalies — the dry-run count path (Number(row?.n ?? 0), line 75) and the delete-loop path (Number(result.meta?.changes ?? 0), line 85) — but neither had direct test coverage. The identical pattern on this file's sibling dedupeSignalSnapshots does have dedicated tests, and the repo's Codecov patch gate counts branches, so these two untested nullish-coalescing arms are exactly the gap the gate is meant to catch.

What's added (test-only — no source change)

Two tests in test/unit/retention.test.ts, mirroring dedupeSignalSnapshots's existing equivalents:

  • dry-run fallback: mock env.DB so the count query's first() returns undefined → assert row?.n ?? 0 falls back to deleted: 0 (not NaN).
  • delete-loop fallback: mock the delete run() to return an object with no meta → assert result.meta?.changes ?? 0 falls back to 0 (which is < batchSize, so the loop terminates immediately with deleted: 0).

Per the issue, pruneExpiredRecords's actual logic is untouched — this is coverage for existing, already-correct defensive code.

Validation

  • test/unit/retention.test.ts: 22 tests pass (20 existing + 2 new); typecheck clean; git diff --check clean.
  • Coverage-catch verified: changing either ?? 0 to a non-zero fallback makes the corresponding new test fail, proving the tests genuinely exercise the fallback arm.
  • Branched off current main, mergeable-clean.

…ack arms

pruneExpiredRecords has two defensive `?? 0` arms -- the dry-run count path
(`Number(row?.n ?? 0)`) and the delete-loop path (`Number(result.meta?.changes ?? 0)`)
-- with no direct test coverage, unlike the identical pattern on its sibling
dedupeSignalSnapshots (which has dedicated tests). Add two tests mirroring that
sibling's approach: mock env.DB so the count query returns no row / the delete
run() result lacks meta, and assert the function falls back to 0 rather than
producing NaN. No source change -- coverage-only for existing, correct code.
@shin-core
shin-core requested a review from JSONbored as a code owner July 24, 2026 15:55
@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 24, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

🚨 Contributor flagged. Click here for more info: Superagent Dashboard

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 24, 2026
@loopover-orb

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Caution

🛑 LoopOver review result - fixes required

Review updated: 2026-07-24 16:48:02 UTC

1 file · 1 AI reviewer · no blockers · CI failing · unknown

🛑 Suggested Action - Fix Blockers

Review summary
Test-only PR adding two tests to cover the previously-untested `?? 0` fallback arms in `pruneExpiredRecords` (dry-run count and delete-loop meta), mirroring the existing pattern already used for `dedupeSignalSnapshots`. The tests mock `env.DB` to return `undefined`/no-`meta` and assert the fallback yields `deleted: 0`, which correctly exercises the nullish-coalescing branches. This is a narrow, well-scoped coverage addition tied to issue #8370, consistent with the sibling test file's conventions, and involves no source changes.

Nits — 3 non-blocking
  • The two new tests duplicate the mock-shape boilerplate already used in the `dedupeSignalSnapshots` block (test/unit/retention.test.ts:150-180 area); consider a small shared helper for the 'DB returns undefined/no-meta' mock if this pattern grows further.
  • The PR description claims 'changing either `?? 0` to a non-zero fallback makes the corresponding new test fail' but that mutation-testing verification isn't visible in the diff/CI output, so it can't be independently confirmed here.
  • If a third defensive `?? 0` arm appears elsewhere in retention.ts in the future, extract the `noRowEnv`/`noMetaEnv` mock builders into a shared test helper to avoid further duplication.

CI checks failing

  • validate
  • validate-tests-merge
Flagged checks (non-blocking)
  • Contributor trust — Contributor flagged for review

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #8370
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 63 registered-repo PR(s), 30 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor shin-core; Gittensor profile; 63 PR(s), 0 issue(s).
Improvement ℹ️ Insufficient signal risk: clean · value: insufficient-signal · LLM: minor
Linked issue satisfaction

Addressed
The PR adds two tests in retention.test.ts that mock env.DB to trigger the row-missing dry-run path and the meta-missing delete-loop path, mirroring the sibling dedupeSignalSnapshots tests exactly as requested, with no production code changes.

Review context
  • Author: shin-core
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 63 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb

loopover-orb Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

LoopOver is closing this pull request on the maintainer's behalf (CI is failing (validate, validate-tests-merge)). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

@loopover-orb loopover-orb Bot closed this Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:flagged Contributor flagged for review by trust analysis. gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pruneExpiredRecords's defensive ?? 0 arms have zero test coverage, unlike its sibling function

1 participant