Skip to content

fix(rules): a rule that throws is reported once as not evaluated, not as a failure per page #1291 - #1342

Closed
nc9 wants to merge 2 commits into
mainfrom
fix/engine-robustness
Closed

nc9 wants to merge 2 commits into
mainfrom
fix/engine-robustness

Conversation

@nc9

@nc9 nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Closes #1291

A rule that threw was recorded as a failed <rule>-error with the rule's own severity on every page, so one defect in squirrel read as N failures and lowered the score. It is now handled like a rule that ran out of time (#960): a skipped <rule>-error (not evaluated; skipReason rule-timed-out, so merge, resolution and carry already treat it as a gap) with details.errored, the first error (clipped to 200 characters, it can quote page content) and the page count, plus one <rule>-errors info row per audit. The report prints a Not checked: line saying it is a squirrelscan defect, and --fail-on counts a thrown security rule as one warning like a timeout.

Score on a fixture (one rule, 26 pages, throws on 20): before 9, after 100, equal to the 6 good pages alone. Test: packages/audit-engine/tests/rule-throws-score-1291.test.ts (single check set, no fail tally, score equal to the audit without those pages), plus report and updated runner tests.

Design note: reuses rule-timed-out as the skip reason (marked errored: true) rather than a new one, so older dashboards and carry logic treat it as not evaluated without a release; wording branches on details.errored.

Docs: docs/rules/index.mdx (new "A rule that throws" section) and CHANGELOG under Unreleased. Skill: none.

@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1342. The change is coherent and the tests cover the main path. I read the diff only and did not run the tests. Findings:

  • (medium) packages/report/src/not-checked.ts (timedOutRules): errored = skipped.some(c => c.details?.errored === true) picks one summary row (-errors or -timeouts) per rule. A rule that times out on some pages and throws on others reports only the error side. The timed-out pages are dropped from the count and the message, and budgetMs is read from skipped[0]. Count the two kinds separately, or emit two entries. A test with mixed timeout and error rows would pin this down.
  • (low) packages/rules/src/runner.ts: a site-scope rule that throws (scopeForLog) now becomes a skipped row with no -errors summary and no erroredPageRules entry. The report count therefore falls back to the skipped-row heuristic, and the docs describe only the per-page behaviour. No test covers the site-rule throw path.
  • (low) packages/rules/src/runner.ts: the first page's details object is shared by reference and mutated (pages++) on later pages. That is intended, but it means a check already handed to the caller changes afterwards. Consider a comment, or snapshot it when building the summary.
  • (low) Reusing rule-timed-out as the skip reason means older consumers will label a defect as a timeout. The PR calls this out as a deliberate trade-off. It is acceptable, but resolution.ts and the other consumers should be checked for any wording that says "timed out" without branching on details.errored.
  • (nit) The error text is clipped to 200 characters but not stripped of control or bidi characters. Renderers should escape it, so please confirm that for every format.
  • (nit) docs/rules/index.mdx: the new section is followed by a double blank line, and the "Ordinary pages never come close..." paragraph now sits under the wrong heading. It was about timeouts, so it should stay with the timeout section.

nc9 added 2 commits October 30, 2026 19:30
…l-on counts a rule that threw, docs #1291

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/engine-robustness branch from fbf3c91 to 52dadbc Compare October 30, 2026 08:34
@claude

claude Bot commented Oct 30, 2026

Copy link
Copy Markdown

Review of #1342 (thrown rule reported as not evaluated). The approach is sound and reuses the timeout path cleanly. I read the diff and the surrounding runner code but did not run the tests.

  • (medium) packages/rules/src/runner.ts (~l.612): the first error is stored in erroredPageRules and reused as details.error on every later per-page row. That is intentional, so the report can fold the rows. But an error whose text depends on the page (for example "cannot read X of null") then shows the first page's text on the other pages' rows. This is acceptable, but the "first error" wording should stay explicit in the docs, as it is.
  • (medium) apps/cli/src/audit/fail-on.ts: timedOutSecurityRules now also returns non-security errored rules, but the name and the timedOutSecurity variable still say security. Rename them, or at least adjust the variable names, so the next reader does not assume the filter is security-only. The gate behaviour itself looks right: a rule that threw on every page still trips warnings and severity, but not errors or score.
  • (medium) A rule that throws on only some pages is not gated at all. Its <rule>-errors row is info, the skipped rows are not scored, and the --fail-on change counts it as one warning, so it should trip. If that is what happens, the docs sentence "a rule that throws on every page… leaves the score … as if it had passed" is slightly misleading, because the same applies on a partial failure. Please clarify.
  • (low) packages/report/src/not-checked.ts: timedOutRules decides errored with skipped.some(...). If a rule both times out on some pages and throws on others, the -timeouts summary is ignored and the timeout pages are miscounted as errors. It is an edge case, but a test would pin the behaviour.
  • (low) Reusing rule-timed-out as the skip reason is a pragmatic choice. Any consumer that reads budgetMs or says "timed out" without checking details.errored will mislabel these rows. A grep of rule-timed-out consumers outside packages/ (cloud and dashboard) is worth a pass before release.
  • (low) Test coverage: the runner, report, fail-on and score tests are good, and the score-parity test is the one that matters. Missing are a mixed timeout and throw case, a non-Error throw (throw "str"), and a __proto__-style rule id or message. The last is probably fine given the clipping.
  • (nit) The error message is clipped to 200 characters, but it is still site-derived text. It is printed in the report "Not checked" line, so confirm every renderer escapes it, as AGENTS.md requires (HTML and XML especially). The new report test covers only the JSON path.
  • (nit) The hintFor text "no finding there is not a clean result" is a confusing double negative. Consider "a missing finding there is not a clean result".
  • (nit) CHANGELOG, docs and the details.errored documentation are present. Per AGENTS.md, no docs.json change is needed.

No critical or high issues found.

@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.144 as 6e9ca14b 38f786fb via #1356. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.144. Closing this original.

nik

@nc9 nc9 closed this Oct 30, 2026
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.

runner: a rule that throws on every page reports one fail per page and lowers the score; report it once as not evaluated

1 participant