Skip to content

fix(report): preserve stored scan scope - #1118

Closed
WilliamK112 wants to merge 1 commit into
squirrelscan:mainfrom
WilliamK112:codex/restore-report-scan-scope-1050
Closed

WilliamK112 wants to merge 1 commit into
squirrelscan:mainfrom
WilliamK112:codex/restore-report-scan-scope-1050

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Summary

  • persist the exact audit scan scope on the crawl record so a later squirrel report can restore it
  • add an additive nullable SQLite migration while keeping older crawls free of inferred scope metadata
  • cover capped database reconstruction in both console and JSON output

Fixes #1050

Verification

  • npx --yes [email protected] test ./apps/cli/tests/reports/reconstruct-scan-scope-1050.test.ts ./apps/cli/tests/squirrel-home-guard.test.ts (4 pass)
  • npx --yes [email protected] test ./packages/crawler/tests/crawl-lease.test.ts ./packages/crawler/tests/retired-at-migration.test.ts (18 pass)
  • bun run typecheck in apps/cli, packages/core-contracts, and packages/crawler
  • bun run lint in apps/cli
  • bun run scripts/test-suites.ts --check
  • uvx --from detect-secrets detect-secrets-hook --baseline .secrets.baseline across tracked files

The full local CLI suite also reached an unrelated existing timeout in apps/cli/tests/tools/request-deadline.test.ts (checkReachability returns instead of hanging on a stalled body); that test still times out when run alone and none of its code is touched here.

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

Docs: none. Skill: none.

@nc9

nc9 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Thanks @WilliamK112, this is the right fix: storing the exact stamp beats re-deriving it, and leaving older crawls without a scope matches the issue's second criterion. Three changes before we merge:

  1. Migration test. Every ALTER-added column in sqlite.ts has an upgrade test (see packages/crawler/tests/crawl-lease.test.ts). Please add one for scan_scope: a v35-era database (crawls table without the column, schema_version 35) opens, gains the column, keeps its rows, and getCrawl() returns no scanScope; a database stamped at SCHEMA_VERSION without the column is repaired by the reconcile list (prove it with an updateCrawl({ scanScope }) round trip, since a missing column only throws on write); and an INSERT naming only the old columns still works, which is what an older squirrel does against an upgraded database.
  2. Reuse ScanScope. CrawlMetadata.scanScope re-declares the shape inline, a third copy beside ScanScope in core-contracts/src/index.ts. import type { ScanScope } from "./index" (as services.ts and limits.ts do) keeps a future field from being stored but not typed on read.
  3. Do not let the disclosure fail the audit. The new storage.updateCrawl(crawlId, { scanScope }) in runAudit is unguarded, so a busy or read-only database at that point turns a finished audit into "Audit failed". The scope is report-only: catch and log it, like the setReportStatus call just above.

Optional: validate the parsed scan_scope in rowToCrawlMetadata and drop it when malformed, and add a docs sentence in docs/cli/report.mdx (a stored audit shows the scan scope squirrel audit printed; audits stored by an older CLI rebuild without one), then make validate in docs/. Both tests seed the scope through updateCrawl, so removing the new line in audit.ts keeps them green; a small stamp-and-persist helper with its own test would close that.

Heads-up: #926 also claims migration 36. Both PRs put their columns on the reconcile lists, so either order self-heals; whichever lands second renumbers.

@WilliamK112
WilliamK112 force-pushed the codex/restore-report-scan-scope-1050 branch from be857b7 to 4bcfe19 Compare October 26, 2026 00:34
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Addressed at current head 4bcfe19: CrawlMetadata.scanScope now reuses the canonical ScanScope type; persisting the report-only scope is guarded and logs instead of failing a finished audit; and migration 36 now has coverage for a v35 upgrade, current-version reconciliation with an update/read round trip, and an older-CLI INSERT that omits the new column. The branch is rebased onto current main. The 5 focused tests, core-contracts/crawler/CLI typechecks, and repository-wide format check pass.

@WilliamK112
WilliamK112 force-pushed the codex/restore-report-scan-scope-1050 branch from 4bcfe19 to 95956db Compare October 26, 2026 06:38
@nc9 nc9 mentioned this pull request Oct 26, 2026
@nc9

nc9 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Merged: landed in the v0.0.134 batch (#1149), main commits a3d453c. Thank you @WilliamK112, storing the exact stamp instead of re-deriving it, plus the v35 upgrade, repair and older-CLI INSERT tests for the new column, was the right shape for a schema change. (Nik)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

squirrel report rebuilt from the project database has no scan scope

2 participants