Skip to content

fix(cli): check rule options in config validate and before an audit #510 - #690

Merged
nc9 merged 5 commits into
mainfrom
fix/config-validate-rule-options-510
Oct 12, 2026
Merged

nc9 merged 5 commits into
mainfrom
fix/config-validate-rule-options-510

Conversation

@nc9

@nc9 nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

squirrel config validate printed Config valid for a [rule_options] table whose rule id matches no rule, an option the rule does not declare, and a value of the wrong type. The first two silently change nothing at audit time, and the third failed squirrel audit after the crawl with a raw zod issue list that named neither the rule nor the table.

Change

  • packages/rules/src/rule-options-check.ts: checkRuleOptions() checks each table against the rule it names, over every built-in rule including meta.disabled ones (new loadKnownRules; the CLI still reads the gaps/* options for the cloud). Kinds: unknown-rule (with a same-name rule as a hint: performance/ttfb suggests perf/ttfb), unknown-option (lists the options the rule takes, or says it takes none), ignored-value (an enabled that is not a boolean, which the rule filter ignores) and invalid-value (the schema's issues, with the path). Every message names the table as written, [rule_options."core/meta-title"], and the key.
  • squirrel config validate prints one Invalid config: line per problem and exits 1.
  • squirrel audit runs the same check right after loading the config, before the run is registered or anything is fetched. A wrong type on a rule this audit runs (same selection as the runner, --rule-include/--rule-exclude and enabled included) stops it with Error: [rule_options."core/meta-title"] min_length: Invalid input: expected number, received string. Everything that changes nothing is a Warning: line and the audit carries on, so no audit that ran before is stopped now: a wrong type on a rule the audit does not run only warns.
  • The runner's own getRuleOptions error names the table and key too, for callers that skip the CLI preflight.
  • The config subcommands now read the file --config-file names, the file the audit uses (codex review: validate otherwise checked a different file than the audit).
  • validateConfig imports the rules package lazily, so config show/set/path stay on the light startup path (feat(rules): rendered reflow, text spacing and text resize checks (repo#3091) #2023 in the private repo).
  • Docs: configuration/rule-options ("What happens to a mistake", "Checking your options"), cli/config (validate, config file resolution), configuration/index. CHANGELOG.

Acceptance evidence

Reproduced with the issue's config (plus [rule_options."core/meta-description"] no_such_option = 5), CLI from source, scratch HOME:

  • validate reports a table whose rule id matches no rule, naming the table:
    Invalid config: [rule_options."performance/ttfb"]: no rule has this id, so the table changes nothing (did you mean "perf/ttfb"?)
  • validate reports an undeclared key and a wrong type, naming the rule and the key:
    Invalid config: [rule_options."core/meta-description"] no_such_option: not an option of core/meta-description, so it changes nothing (options: min_length, max_length)
    Invalid config: [rule_options."core/meta-title"] min_length: Invalid input: expected number, received string
    Exit code 1 (was Config valid, exit 0).
  • A wrong type during audit names the rule and key: squirrel audit http://127.0.0.1:<port>/ --http -m 1 --offline against a local fixture prints the two warnings and Error: [rule_options."core/meta-title"] min_length: Invalid input: expected number, received string, exits 1, writes no report and fetches nothing. With core/meta-title in rules.disable, the same value is a warning and the audit completes and writes its report.

Tests: packages/rules/tests/rule-options-check.test.ts (each kind, hints, list index paths, disabled gaps/keywords options, table order, and the runner error), apps/cli/tests/audit/rule-options-preflight.test.ts (error vs warning, rules the audit skips, enabled = true overriding a disable), apps/cli/tests/controllers/config.test.ts (validateConfig), apps/cli/tests/commands/config-validate.test.ts (the command through citty with --config-file), apps/cli/tests/commands/audit-rule-options-wiring.test.ts (the audit command through citty stops before any request to the site and prints no zod issue JSON).

Checks

  • bun test on the five new or changed test files above, plus tests/config.test.ts, tests/toml-syntax-error.test.ts, tests/commands/audit-discovery-probes-wiring.test.ts, tests/audit/rule-filter.test.ts, packages/rules/tests/runner-concurrency.test.ts, runner-concurrency-isolation.test.ts, shared-regex.test.ts: all pass
  • tsgo clean in packages/rules and apps/cli (bun run typecheck); apps/cli format:check and lint clean
  • docs tangly check --strict passed
  • codex review: one finding (--config-file), fixed; delta pass "No findings"

Agent skill: no change needed. The squirrelscan skill lists squirrel config validate without describing what it checks; it could add "run it after editing [rule_options]", which is optional.

Closes #510

@nc9
nc9 marked this pull request as ready for review October 12, 2026 01:25
@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of #690. The change is well scoped and well tested. The error-versus-warning split is sensible, and the preflight uses the same rule selection as the runner. Findings:

  • (medium) packages/rules/src/rule-options-check.ts and apps/cli/src/audit/rule-options-preflight.ts: both checks use only built-in rules, because loadKnownRules() and getAllRuleIds() are called with no additionalNamespaces. The loader accepts additionalNamespaces (loader.ts:67), so plugin rules are possible. If the audit loads plugin rules, a valid [rule_options."plugin/foo"] table is reported as "no rule has this id". That makes config validate exit 1 on a valid config. In the audit it is only a warning, but it is still wrong. Please either confirm plugin rules can't be configured through [rule_options], or pass the plugin namespaces through to the check.
  • (low) rule-options-check.ts: the unknown-option check reads schema.shape, so it only works when optionsSchema is a plain z.object. If a rule ever uses an effects/refine-wrapped or union schema, declared is empty and every key is reported as "this rule takes no options". A test that asserts every built-in optionsSchema exposes shape would catch this.
  • (low) apps/cli/src/cli/commands/config.ts: config set now writes to the --config-file path. That is consistent with the audit. If the file doesn't exist, set may now create it at that location. Please confirm this is intended, and consider a test.
  • (nit) similarRuleIds matches on the last path segment only, so a common name like title could suggest unrelated rules. Capping at 3 limits the effect.
  • (nit) rule-options-check.ts is formatted with trailing commas and long lines, unlike the CLI files. Check format:check for packages/rules.

I found no security concerns, and nothing that blocks merging.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Review triage (head now a78ed71):

  • (medium) Plugin rules: they cannot reach the CLI's runner today. Nothing in apps/cli/src or packages/audit-engine/src passes additionalNamespaces, and loadPlugins (packages/rules/src/plugins.ts) is only called from apps/cli/tests/rules/plugin-manager.test.ts. The runner and the check both see exactly the built-in rules, so a [rule_options] table for a plugin id is already ignored at audit time, and saying so is accurate. When plugin rules are wired into audits, the same namespaces should be passed to checkRuleOptions and getAllRuleIds.
  • (low) schema.shape: RuleMeta.optionsSchema is typed z.ZodObject<z.ZodRawShape>, so a wrapped schema does not type-check today. Added the suggested test anyway: every built-in rule's options schema exposes shape.
  • (low) config set with --config-file: it does not create the file. setConfigValue returns FILE_NOT_FOUND when the path does not exist (covered by setConfigValue > returns error when file does not exist), so it now edits the file the flag names or fails, as config show reads it.
  • (nit) Same-name suggestions: kept, capped at three.
  • (nit) Formatting in packages/rules: packages/* have no format scripts and are not run through oxfmt (repo convention); the file follows the rules package's existing style.
  • CodeQL "incomplete URL substring sanitization" on the wiring test: the assertion now compares new URL(url).hostname instead of a substring.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the diff. I found no blocking problems. I only read the code and did not run the tests.

  • (low) apps/cli/src/cli/commands/config.ts: config validate now exits 1 for an unknown rule id or option, which the audit treats as a warning. Any script that runs config validate && ... will start failing on configs that used to pass. This is documented and intended, but the CHANGELOG could say it more plainly as a behaviour change.
  • (low) packages/rules/src/rule-options-check.ts: checkRuleOptions only knows built-in rules (loadKnownRules). If the repo ever loads external or plugin rules, their tables would be reported as unknown-rule. Nothing in the loader does this today, so no action is needed now.
  • (nit) packages/rules/src/rule-options-check.ts: similarRuleIds compares only the last path segment. A name like title could suggest several unrelated rules. The cap of three limits the noise, so this is fine.
  • (nit) preflightRuleOptions filters on getAllRuleIds(), so a disabled rule that has an invalid-value problem only warns. That matches the runner, and the test for enabled = true covers the re-enable case.

Test coverage is good: unit tests for the check, the preflight and validateConfig, plus wiring tests through citty that assert no request is made before the error. Docs and CHANGELOG are updated. The change that makes config subcommands honour --config-file is a sensible fix.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Re-review triage (head now c2dbf38): the CHANGELOG entry now says plainly that config validate exits 1 on these problems, so a squirrel config validate && ... check fails on a config that used to pass. The other points in that pass need no change (plugin rules are not loaded by any audit today; the suggestion cap and the disabled-rule warning are as intended).

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the diff. The change is sound: it validates [rule_options] before the crawl, only hard-fails on wrong types for rules that actually run, and has good test and doc coverage. I didn't run the tests. Findings:

  • (low) apps/cli/src/cli/commands/config.ts (configFilePath): config set now also writes to the --config-file path. That fits "same file as audit", but it is a behaviour change for set, beyond validate. It is worth a CHANGELOG line, and a test if there isn't one.
  • (low) packages/rules/src/rule-options-check.ts: unknown options are detected through schema.shape. A schema that is not a plain ZodObject (wrapped in refine/pipe) would have no shape and would report every key as unknown, or "takes no options". Currently safe if every optionsSchema is a ZodObject; a test asserting that over all built-in rules would guard it.
  • (nit) checkRuleOptions defaults to loadKnownRules(), which rebuilds the rule map on every call. This is cheap and runs once per audit, so it is fine.
  • (nit) validate only checks one config file, while the audit merges several (e.g. global config). Problems that come from a merged-in file won't show up in validate.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Re-review triage (head c2dbf38, no code change):

  • (low) config set follows --config-file: it is in the CHANGELOG ("The config subcommands now read the file --config-file names..."), and set never creates a missing file (setConfigValue > returns error when file does not exist).
  • (low) Non-object options schemas: covered by the test added in a78ed71, every built-in rule's options schema exposes its keys.
  • (nit) loadKnownRules() per call: once per validate or audit, as you say.
  • (nit) Several merged config files: the audit reads one file, the one --config-file names or else the nearest squirrel.toml, merged onto built-in defaults only (loadConfig in apps/cli/src/config.ts). config validate now checks that same file, so nothing an audit reads is left unchecked.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of #690: [rule_options] validation for config validate and the audit preflight. I read the diff and the new rule-options-check.ts. I did not run the tests.

The design is sound. The rules package loads lazily, so config show and config set stay fast. The preflight uses the runner's own filterRules, so enabled = true is handled the same way. Tests cover the controller, the preflight, and the end-to-end audit wiring with no network requests.

  • (medium) packages/rules/src/rule-options-check.ts: the declared options come from schema?.shape. If a rule's optionsSchema is wrapped (.refine, .transform, or a union), shape is undefined. Every key in that rule's table is then reported as unknown-option with "this rule takes no options". That is a false positive, and config validate now exits 1 on it. Please check that every built-in optionsSchema is a plain ZodObject, or unwrap it. A unit test that runs checkRuleOptions on each rule's declared options would catch this.
  • (low) apps/cli/src/cli/commands/config.ts: config set now writes to the --config-file path as well, not just validate. That seems right and is consistent with the audit. The CHANGELOG only mentions that the subcommands "read" the file, so add that set writes it. If the path does not exist, check that set creates the file or gives a clear error.
  • (low) Breaking change: config validate now exits 1 for unknown rule IDs and options, which an audit only warns about. This is called out in the CHANGELOG. If scripts rely on the old exit code, consider a --strict flag or warn-only behaviour for the unknown-* kinds.
  • (nit) similarRuleIds matches on the last path segment only, so core/title could suggest unrelated rules. It is capped at 3 results, so it is harmless.
  • (nit) The wiring test replaces process.env with a copy in afterEach. Restoring the keys in place is safer if other modules hold the original object.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Re-review triage (head now 9cd9896):

  • (medium) Wrapped options schemas: already pinned by every built-in rule's options schema exposes its keys (packages/rules/tests/rule-options-check.test.ts, added in a78ed71), which fails if any built-in optionsSchema lacks shape; RuleMeta.optionsSchema is also typed as a ZodObject.
  • (low) config set and --config-file: the CHANGELOG now says the subcommands read and write that file, and that set still never creates a missing one (it returns FILE_NOT_FOUND, covered by an existing controller test).
  • (low) Exit 1 as a behaviour change: stated in the CHANGELOG since c2dbf38.
  • CI: the earlier CLI tests failure was squirrel-home-guard.test.ts flagging the new config validate command test for using a plain temp dir; it runs in isolateSquirrelHome since 201e5fe, and that run's checks all passed.

@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Review of the `[rule_options]` validation change. I read the full diff plus `getGlobalConfigPath` and the `optionsSchema` type. I did not run the tests.

(low) `packages/rules/src/rule-options-check.ts`: unknown-option detection relies on `schema.shape`, which holds today because `optionsSchema` is typed `z.ZodObject`. If a rule later wraps its schema in `.refine()` or `.transform()`, or declares no keys but still reads options, every key gets flagged as unknown. The unknown-option kind is only a warning, so this would mislead rather than block. A test asserting that every built-in `optionsSchema` exposes `.shape` would catch it.

(low) `apps/cli/src/audit/rule-options-preflight.ts`: `checkRuleOptions` runs over all rules, but `filterRules` is called with `getAllRuleIds()`, which may exclude `meta.disabled` rules. This is intended and covered by the "runs / does not run" split. It would still help to add a test where a disabled rule has a bad value, to pin down that it warns and doesn't error.

(nit) `rule-options-check.ts`: `similarRuleIds` matches on the last path segment only, so a common name such as `title` could suggest unrelated rules. It is capped at 3, so the impact is small.

(nit) `config.ts`: `getGlobalConfigPath() ?? findConfigFile()` is correct, because the former returns `undefined` when `--config-file` is not set. The name is slightly misleading next to the doc comment, and a one-line note would help.

Positives:

  • `loadKnownRules` is imported lazily, so `config show` and `config set` keep a light startup.
  • The preflight runs before the crawl.
  • The tests cover the validate command, the audit wiring and the preflight.
  • The docs are updated.

I found nothing blocking.

@nc9

nc9 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Triage of the 9cd9896 review, no code change: the shape test it suggests exists (every built-in rule's options schema exposes its keys); a bad value on a rule the audit does not run is pinned as a warning by a wrong type on a rule this audit does not run only warns (rules turned off by disable or a narrower enable; a meta.disabled rule is outside getAllRuleIds() the same way); the suggestion cap and the configFilePath doc comment are as intended.

nc9 added 5 commits October 12, 2026 15:57


config validate printed Config valid for a [rule_options] table naming no
rule, an option the rule does not declare and a value of the wrong type,
and the wrong type then failed the audit after the crawl with a bare zod
issue list. checkRuleOptions (packages/rules) reports all three, one line
each naming the table and the key; config validate exits 1 on any. The
audit runs the same check before it registers or crawls: a wrong type on
a rule the audit runs stops it, the rest warn. The runner's own error now
names the table and key too. The config subcommands read the file
--config-file names, as the audit does.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/config-validate-rule-options-510 branch from 9cd9896 to aec610c Compare October 12, 2026 04:57
@claude

claude Bot commented Oct 12, 2026

Copy link
Copy Markdown

Reviewed the diff. The change is sound and well tested. The findings are minor.

  • (medium) packages/rules/src/rule-options-check.ts (schema.safeParse(table)): the whole table is parsed, including the filter-only enabled key. If any rule's optionsSchema is .strict(), a valid enabled = false reports a false invalid-value, which now stops the audit. The runner's getRuleOptions already parses the same table, so this would already fail at runtime. It is still worth confirming that no schema is strict, or stripping FILTER_OPTION_KEYS before parsing, and adding a test.
  • (low) apps/cli/src/audit/rule-options-preflight.ts: running comes from getAllRuleIds(), but checkRuleOptions uses loadKnownRules(), which includes meta.disabled rules. A disabled rule with a bad value therefore gets the "does not run" warning, which seems right. A test pinning that behaviour would help.
  • (low) apps/cli/src/cli/commands/config.ts: configFilePath() makes config set write to the --config-file path, where it used to write to the nearest squirrel.toml. This is the intended behaviour, but it is a behaviour change for set. Mention it in the changelog or docs.
  • (nit) similarRuleIds matches on the last path segment only, so common names like title could give loose suggestions. The cap of three keeps this harmless.
  • (nit) The new rule-options-check.ts has trailing commas and long lines in a style that may differ from the formatter config. Run the formatter.

I found no security issues. The unknown-rule, unknown-option and ignored-value problems only warn during an audit, so no previously working config is blocked.

@nc9
nc9 merged commit de74d03 into main Oct 12, 2026
15 checks passed
@nc9
nc9 deleted the fix/config-validate-rule-options-510 branch October 12, 2026 05:10
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.

cli: config validate passes rule options no rule can use, and a wrong type fails the whole audit

2 participants