Skip to content

feat(scripts): export rule-precision backtest corpus as checksummed JSON#8102

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
andriypolanski:feat/8084-backtest-corpus-export
Jul 22, 2026
Merged

feat(scripts): export rule-precision backtest corpus as checksummed JSON#8102
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
andriypolanski:feat/8084-backtest-corpus-export

Conversation

@andriypolanski

Copy link
Copy Markdown
Contributor

Summary

  • Pure scripts/backtest-corpus-export-core.ts: checksumCases + buildBacktestCorpusManifest (same canonicalize-then-SHA-256 + optional meta spread as export-d1-core).
  • Thin scripts/backtest-corpus-export.ts CLI: wrangler D1 read of signal.rule_fired:<ruleId> / signal.human_override:<ruleId>, reconstruct events like signal-tracking-wire, run buildBacktestCorpus, write pretty JSON.

Closes #8084

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npx vitest run test/unit/backtest-corpus-export-core.test.ts — 5 passed
  • npm run build --workspace @loopover/engine
  • npm run test:workers
  • npm run build:mcp
  • npm run build:miner
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • Scripts-only change. Core is unit-tested like export-d1-core; the CLI wrapper is intentionally untested (same precedent as export-d1-data.ts). scripts/** is ignored by Codecov.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section 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.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

UI Evidence

N/A — CLI export script; no UI.

Notes

…SON (JSONbored#8084)

Add a pure buildBacktestCorpusManifest/checksumCases core (mirroring
export-d1-core) plus a thin wrangler D1 CLI that snapshots one rule's
fired/override audit_events into a portable labeled corpus file.

Co-authored-by: Cursor <cursoragent@cursor.com>
@andriypolanski andriypolanski changed the title ``` feat(scripts): export rule-precision backtest corpus as checksummed JSON feat(scripts): export rule-precision backtest corpus as checksummed JSON Jul 22, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.01%. Comparing base (423a3d1) to head (994e9dc).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8102   +/-   ##
=======================================
  Coverage   92.01%   92.01%           
=======================================
  Files         755      755           
  Lines       77201    77201           
  Branches    23337    23338    +1     
=======================================
  Hits        71034    71034           
  Misses       5061     5061           
  Partials     1106     1106           
Flag Coverage Δ
shard-1 53.69% <ø> (-5.89%) ⬇️
shard-2 57.08% <ø> (+5.98%) ⬆️
shard-3 51.54% <ø> (+1.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@andriypolanski

Copy link
Copy Markdown
Contributor Author

Hi @JSONbored,
I think this PR may now have merge conflicts because #8098 and #8097 were merged shortly at the nearest time.
May I resolve the conflicts and merge it?

@andriypolanski

Copy link
Copy Markdown
Contributor Author

Nothing

@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 22, 2026
@loopover-orb

loopover-orb Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-22 22:49:12 UTC

3 files · 1 AI reviewer · no blockers · readiness 98/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
Adds a thin CLI (backtest-corpus-export.ts) that reads rule_fired/human_override audit events from D1 via wrangler and reconstructs events, plus a pure core (backtest-corpus-export-core.ts) that canonicalizes and SHA-256-checksums the resulting BacktestCase[] into a manifest, closely mirroring the existing export-d1-core.ts split. Rule ID is properly escaped via sqlStringLiteral before SQL interpolation, avoiding injection, and the core is exercised by 5 focused unit tests covering checksum stability, meta-spread, and copy semantics. The CLI wrapper itself is intentionally untested, consistent with the export-d1-data.ts precedent cited in the PR description, and scripts/** is excluded from Codecov so this doesn't violate the coverage bar.

Nits — 5 non-blocking
  • scripts/backtest-corpus-export.ts:38 uses a non-null assertion (`argv[++i]!`) for `--db` while every other flag leaves the value as `string | undefined`; if `--db` is the last argv token this silently assigns `undefined` typed as `string`, which then gets passed straight into the wrangler `db` positional arg.
  • scripts/backtest-corpus-export.ts:49 hardcodes `maxBuffer: 256 * 1024 * 1024` inline; a named constant would make the 256MB ceiling self-documenting.
  • scripts/backtest-corpus-export.ts:157 truncates the checksum with a magic `12`; consider a named constant like `CHECKSUM_PREVIEW_LEN` for readability.
  • No test exists for the CLI's row-projection helpers (`toRuleFiredEvent`/`toHumanOverrideEvent`/`rowEventType` etc.); since these are pure and easily extracted, a couple of unit tests would catch drift from `signal-tracking-wire.ts` cheaply, though this isn't required by the stated scripts/** coverage exemption.
  • Extract `toRuleFiredEvent`/`toHumanOverrideEvent` into the -core file (they're pure) so they get the same unit-test coverage as `checksumCases`/`buildBacktestCorpusManifest`.

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 #8084
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: 211 registered-repo PR(s), 135 merged, 22 issue(s).
Contributor context ✅ Confirmed Gittensor contributor andriypolanski; Gittensor profile; 211 PR(s), 22 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The PR adds the pure scripts/backtest-corpus-export-core.ts with checksumCases and buildBacktestCorpusManifest mirroring export-d1-core's canonicalize-then-hash and meta-spread pattern, plus the thin scripts/backtest-corpus-export.ts CLI wrapper that queries D1 for rule_fired/human_override rows, reconstructs events mirroring signal-tracking-wire.ts, and calls buildBacktestCorpus, matching the iss

Review context
  • Author: andriypolanski
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, JavaScript, Rust, Cuda, Kotlin, MDX, Scala
  • Official Gittensor activity: 211 PR(s), 22 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
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 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit cf5cd19 into JSONbored:main Jul 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scripts: export the rule-precision backtest corpus as a versioned, checksummed JSON snapshot

2 participants