Skip to content

feat(core-contracts): audit levels definition (quick, surface, full) - #602

Merged
nc9 merged 4 commits into
mainfrom
feat/audit-levels-core-contracts
Oct 9, 2026
Merged

nc9 merged 4 commits into
mainfrom
feat/audit-levels-core-contracts

Conversation

@nc9

@nc9 nc9 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

The shared audit levels definition, on its own, so the cloud dashboard can build on it before the CLI change in #598 lands.

What this adds

  • @squirrelscan/core-contracts/audit-levels (new subpath export): the three levels (quick, surface, full) plus custom, each level's preset settings (pages, crawl strategy, cloud checks, rendering, external link checks, probing), AUDIT_LEVEL_COPY and AUDIT_SETTING_COPY (the words surfaces show), resolveAuditSettings / levelOfSettings (a level plus edits, with "based on X, N changes"), plan and balance clamping (effectiveAuditSettings), the cloud's old four depths as legacy aliases (legacyCloudDepthSettings), crawlStrategyCoverageMode, and parseResolvedAuditSettings (reads a stored snapshot back without trusting it).
  • AuditReport.auditLevel?: ResolvedAuditSettings, optional; nothing stamps it yet.
  • CoverageMode is now the AuditLevel type: the same three words, so no caller changes.

Additive only: no CLI, engine, report or docs behaviour changes. The --level flag, the docs page and the CHANGELOG entry stay in #598, which will rebase onto this.

Checks

  • tsgo --noEmit in packages/core-contracts, apps/cli and packages/report: clean.
  • bun test packages/core-contracts/tests/audit-levels.test.ts: 29 pass.

Docs: none (no user-facing change). Skill: no change.

nc9 added 2 commits October 9, 2026 18:27
… a snapshot reader for audit levels

AUDIT_SETTING_COPY names each setting, crawlStrategyCoverageMode maps a
crawl strategy to the crawler's coverage mode, parseResolvedAuditSettings
reads a stored snapshot back without trusting it. AuditReport gains an
optional auditLevel snapshot and CoverageMode is now the AuditLevel type
(same three words). Additive: nothing stamps auditLevel yet.

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Reviewed the diff for #602. It's additive and well tested. I found nothing that should block merge, only a few smaller points.

  • (low) audit-levels.ts parseResolvedAuditSettings: a stored level and changes are kept whenever they are valid words, even if they contradict the parsed settings. For example, level: "surface" with changes: [] and pages: 80 is returned as is. The test pins this on purpose ("does not rewrite history"). Consumers must therefore not infer settings from level, and should read settings instead. A one-line doc note on ResolvedAuditSettings would make that clear. Also, changes can be non-empty while level is a preset, which the interface comment says can't happen.
  • (low) effectiveAuditSettings: planMaxPages and affordablePages are not validated. A NaN limit silently means "no limit" because pages > NaN is false. A negative or zero limit is floored to 1. The floor is tested, but you may want to clamp or ignore non-finite limits explicitly, since these values will come from billing code.
  • (low) clampAuditPages: a non-finite value falls back to the default level's page count (100). Infinity arguably means "as many as allowed", so it could clamp to AUDIT_MAX_PAGES instead. The current behaviour is tested, so this is a judgement call.
  • (nit) resolveAuditSettings uses the as unknown as Record<string, unknown> cast to assign by key. A small generic helper like assign<K extends AuditSettingKey> would remove the cast. The same applies to the as CrawlStrategy casts in the parser.
  • (nit) Several lines in the parser (the RENDER_POLICIES line and the level ternary) look longer than the repo's usual line width. Run the formatter.
  • (nit) Test coverage: there's no test that AuditReport.auditLevel survives a report schema or validation pass. If a TypeBox schema for reports exists, check that the new optional field isn't stripped or rejected. Nothing stamps it yet, so this is fine for now.

Security: the parser treats stored snapshots as untrusted and only returns the module's own strings, and the XSS-style test covers that. The CoverageMode alias changes no types, and the type-only imports create no runtime cycle.

@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review of #602 (audit levels definition). I read the diff and checked that COVERAGE_PAGE_LIMITS and REPORT_LIMITS.maxPages exist. I did not run the tests. The change is additive and the tests are thorough. I found nothing that should block merging.

  • (low) audit-levels.ts parseResolvedAuditSettings: the stored level and changes are kept even when they contradict the settings. Examples are level: "full" with basedOn: "quick", or level: "surface" with a non-empty changes. The test comment says this is deliberate, so history isn't rewritten. Consumers that build copy from level should not assume it agrees with settings. Also, level: "custom" with an empty changes is accepted as stored. Consider documenting this.
  • (low) clampAuditPages: Infinity falls back to 100, but a user who passes a huge value might expect AUDIT_MAX_PAGES. -Infinity also gets 100 rather than 1. The test pins this, so it is a design question only.
  • (low) effectiveAuditSettings: a NaN planMaxPages or affordablePages is silently ignored, because the comparison is false and the limit never applies. This fails open. Callers compute affordablePages from balances, so a NaN there would skip the balance limit. Consider treating a non-finite limit as a limit of 1, or validating it.
  • (nit) resolveAuditSettings uses an as unknown as Record<string, unknown> cast to assign by key. A small typed helper, or Object.assign over the defined overrides, would avoid the cast.
  • (nit) CoverageMode is now an alias of AuditLevel, but packages/crawler/src/core/types.ts:19 and packages/config/src/schema.ts:16 still define their own copies. They can drift from this one. Consider following up so there is a single source.
  • (nit) Test coverage is missing for parseResolvedAuditSettings when settings is absent. It should return all preset values. A basedOn that goes through the fast alias is also untested. The legacyCloudDepthSettings pages (10/50/250/500) are all below the plan minimum, but nothing asserts they respect AUDIT_MAX_PAGES.

…napshot's level is as stored

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Review triage:

  • NaN limit fails open: fixed in ed0185f. A NaN plan or balance limit now limits to one page; an infinite one still does not limit. Fractional limits round down (previous commit). Tests added.
  • Stored level/changes may disagree with settings: deliberate (a snapshot keeps the label it ran under). Documented on ResolvedAuditSettings: read settings, never infer from level.
  • clampAuditPages(Infinity) -> default pages: kept; a non-finite request is malformed input, not a request for the maximum.
  • Casts, line width, crawler/config CoverageMode copies, extra parser tests: nits, left for the CLI PR (feat(cli): audit levels (--level quick|surface|full) and the audit levels docs page #598) which touches those files.

@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Reviewed the diff. This is additive, well documented and well tested. No blocking problems found. Notes:

  • (low) audit-levels.ts clampAuditPages: a non-finite page count falls back to the default level's pages (100), not the basedOn level's. resolveAuditSettings("quick", { pages: NaN }) therefore resolves to 100 pages, more than Quick's 25, and is reported as custom. Probably unreachable from validated input, but parseResolvedAuditSettings already filters non-finite values. Consider having resolveAuditSettings ignore a non-finite override so it keeps the preset value.
  • (low) parseAuditLevel("fast") returns quick, but the legacy cloud depth fast (legacyCloudDepthSettings) is a different bundle. It has cloudChecks: true and 10 pages, where quick has no cloud checks and 25 pages. Two parsers give the same word two meanings. That is fine while the surfaces stay separate, but worth a comment on parseAuditLevel so a caller doesn't route a cloud fast through it.
  • (low) parseResolvedAuditSettings keeps a stored level even when it contradicts settings, for example level: "full" with pages: 80. The doc comment says this is intended, and a test pins it. Any consumer that branches on level (cost estimates, UI badges) needs to read settings, so this is easy to misuse. A levelOfSettings-based helper for the "what actually ran" label might help.
  • (nit) resolveAuditSettings uses an as unknown as Record<string, unknown> cast to assign by key. A small typed helper or a spread filtered by defined values would avoid the cast.
  • (nit) limits.ts imports the CoverageMode type from index.ts. index.ts now aliases CoverageMode to AuditLevel from audit-levels.ts, which imports limits.ts. This is a type-only cycle, so there is no runtime issue, but it could confuse tooling.
  • (nit) The test "the hard ceiling is 10,000 pages" hardcodes a number that tracks REPORT_LIMITS.maxPages. That is a deliberate pin, but it will need updating whenever the ceiling is raised.

Test coverage is good: preset pinning, clamping, the untrusted-snapshot parser, and the NaN and Infinity limit cases. I did not run the tests or tsgo myself, and I did not check consumers of CoverageMode.

@nc9
nc9 merged commit 0f960e9 into main Oct 9, 2026
15 checks passed
@nc9
nc9 deleted the feat/audit-levels-core-contracts branch October 9, 2026 07:46
nc9 pushed a commit that referenced this pull request Oct 9, 2026
* origin/main:
  feat(core-contracts): audit levels definition (quick, surface, full) (#602)
  test(rules): restore the real fetch when a graphql test stubs twice (#599)
  chore(release): v0.0.107 (#595)
  docs(changelog): release notes for v0.0.107 (#594)
  feat(rules): add GraphQL introspection and GET mutation probing rules (#593)
  fix(audit-engine): keep paid cloud prefetch results when the phase is abandoned (#582)
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.

1 participant