feat(calibration): pure BacktestCase corpus builder from fired/override events#8093
Conversation
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8093 +/- ##
==========================================
- Coverage 92.01% 92.00% -0.01%
==========================================
Files 754 755 +1
Lines 77188 77201 +13
Branches 23335 23337 +2
==========================================
+ Hits 71021 71030 +9
Misses 5061 5061
- Partials 1106 1110 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…de events Closes JSONbored#8083. Adds packages/loopover-engine/src/calibration/backtest-corpus.ts with the BacktestCase type and buildBacktestCorpus(ruleId, fired, overrides): pairs each rule firing with the human verdict that decided it (nearest override strictly after the firing, else most recent), excludes undecided firings, mirrors overrideMatchesRule's ruleId filter and computeRulePrecision's doc-comment style. Pure: no IO/DB/env/clock. Adds the barrel export and both the node:test (engine gate) and a vitest src-path test (codecov coverage).
0edc16c to
9a64b9b
Compare
|
Tip ✅ LoopOver review result - approve/merge recommendedReview updated: 2026-07-22 22:20:50 UTC
Review summary Nits — 5 non-blocking
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk 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.
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.
|
Summary
packages/loopover-engine/src/calibration/backtest-corpus.ts— a pure, storage-agnostic builder that turns the calibration module's rawRuleFiredEvent/HumanOverrideEventhistory into a labeledBacktestCase[]corpus (each "this rule fired against this target, a human later said reversed/confirmed" pair), the replayable input a backtest scorer needs.BacktestCaseandbuildBacktestCorpus(ruleId, fired, overrides)match the issue spec exactly: only events whoseruleIdmatches are considered (mirrorsoverrideMatchesRule'sevent.ruleId === ruleIdfilter insignal-tracking.ts); a firing with no matching override (same rule ANDtargetKey) is excluded, not emitted unlabeled (the same "only the decided ones count" discipline ascomputeRulePrecision); when a target was fired+judged more than once, each firing pairs with the nearest override strictly after it, else the most recent override;metadatais omitted entirely (never set toundefined) when the firing has none, honoring the package'sexactOptionalPropertyTypesdiscipline. Pure — no IO/DB/env/clock (Date.parseon the events' ownoccurredAtstrings is deterministic parsing, not a clock read).export * from "./calibration/backtest-corpus.js";topackages/loopover-engine/src/index.ts, on its own line immediately after the existingsignal-tracking.jsexport, as specified. Additive only — no existing consumer changes,signal-tracking.tsuntouched.Tests
Two test files, deliberately — this repo's engine coverage architecture requires it:
packages/loopover-engine/test/backtest-corpus.test.ts— the issue-requirednode:testfile, mirroring thesignal-tracking.test.tsprecedent from feat(calibration): shared ORB+AMS signal-tracking module, with AMS wired live #8079; it gates the engine workspace's ownnpm run test --workspace @loopover/engine(all 615 engine tests pass). This suite runs againstdistand is invisible to Codecov.test/unit/backtest-corpus.test.ts— a vitest unit test importing the engine src path directly, which is what providescodecov/patchcoverage: vitest'scoverage.includemeasurespackages/loopover-engine/src/**, but the engine'snode:testsuite runs againstdistwith no c8/source-map harvest step (only review-enrichment has one — seeci.yml's REES coverage note), so anode:test-only file would report 0% to Codecov. This vitest test independently exercises every branch (has/no override; single/multiple overrides incl. the no-strictly-following fallback; matching/non-matchingruleId; present/absentmetadata; empty input) — 100% of the diff's lines and branches, verified locally vianpm run test:coverage.Scope
type(scope): short summaryConventional Commit format, for examplefix(api): restore profile access checks.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #123) — a linked open issue is required for every contributor PR.Validation
git diff --checknpm run actionlintnpm run typechecknpm run test:coveragelocally;codecov/patchrequires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.npm run test:workersnpm run build:mcpnpm run test:mcp-packnpm run ui:openapi:checknpm run ui:lintnpm run ui:typechecknpm run ui:buildnpm audit --audit-level=moderateIf any required check was skipped, explain why:
@loopover/enginebuild + its 615-testnode:testsuite, whole-repotypecheck,test:engine-parity,engine-parity:drift-check,docs:drift-check, and the unshardedtest:coverage(confirming 100% patch coverage on the new file) were all run and pass. This change is a single pure, self-contained new engine file plus one additive barrel-export line and two test files — it touches no API/OpenAPI, migration, generated artifact, command, setting, or dependency, so the remainingtest:cisteps (workers, mcp/miner packs, ui:build, db/drift checks) cannot be affected by it.Safety
UI Evidencesection below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.UI Evidence
Not applicable — a pure calibration-engine function with no visible UI, frontend, docs, or extension change.
Notes
buildBacktestCorpushas no consumer yet (the scorer/export/split/report siblings are scripts: export the rule-precision backtest corpus as a versioned, checksummed JSON snapshot #8084–calibration: render a backtest score/comparison report as Markdown #8088). No behavior change to any existing code path.