Repository navigation
fix(cli): check rule options in config validate and before an audit #510 - #690
Conversation
|
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:
I found no security concerns, and nothing that blocks merging. |
|
Review triage (head now a78ed71):
|
|
Reviewed the diff. I found no blocking problems. I only read the code and did not run the tests.
Test coverage is good: unit tests for the check, the preflight and |
|
Re-review triage (head now c2dbf38): the CHANGELOG entry now says plainly that |
|
Reviewed the diff. The change is sound: it validates
|
|
Re-review triage (head c2dbf38, no code change):
|
|
Review of #690: The design is sound. The
|
|
Re-review triage (head now 9cd9896):
|
|
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:
I found nothing blocking. |
|
Triage of the 9cd9896 review, no code change: the |
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]>
…hape #510 Signed-off-by: Nik Cubrilovic <[email protected]>
…ption problems #510 Signed-off-by: Nik Cubrilovic <[email protected]>
Signed-off-by: Nik Cubrilovic <[email protected]>
Signed-off-by: Nik Cubrilovic <[email protected]>
9cd9896 to
aec610c
Compare
|
Reviewed the diff. The change is sound and well tested. The findings are minor.
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. |
squirrel config validateprintedConfig validfor 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 failedsquirrel auditafter 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 includingmeta.disabledones (newloadKnownRules; the CLI still reads thegaps/*options for the cloud). Kinds:unknown-rule(with a same-name rule as a hint:performance/ttfbsuggestsperf/ttfb),unknown-option(lists the options the rule takes, or says it takes none),ignored-value(anenabledthat is not a boolean, which the rule filter ignores) andinvalid-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 validateprints oneInvalid config:line per problem and exits 1.squirrel auditruns 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-excludeandenabledincluded) stops it withError: [rule_options."core/meta-title"] min_length: Invalid input: expected number, received string. Everything that changes nothing is aWarning: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.getRuleOptionserror names the table and key too, for callers that skip the CLI preflight.configsubcommands now read the file--config-filenames, the file the audit uses (codex review:validateotherwise checked a different file than the audit).validateConfigimports the rules package lazily, soconfig show/set/pathstay on the light startup path (feat(rules): rendered reflow, text spacing and text resize checks (repo#3091) #2023 in the private repo).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:Invalid config: [rule_options."performance/ttfb"]: no rule has this id, so the table changes nothing (did you mean "perf/ttfb"?)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 stringExit code 1 (was
Config valid, exit 0).squirrel audit http://127.0.0.1:<port>/ --http -m 1 --offlineagainst a local fixture prints the two warnings andError: [rule_options."core/meta-title"] min_length: Invalid input: expected number, received string, exits 1, writes no report and fetches nothing. Withcore/meta-titleinrules.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, disabledgaps/keywordsoptions, table order, and the runner error),apps/cli/tests/audit/rule-options-preflight.test.ts(error vs warning, rules the audit skips,enabled = trueoverriding 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 teston the five new or changed test files above, plustests/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 passpackages/rulesandapps/cli(bun run typecheck);apps/cliformat:checkandlintcleantangly check --strictpassed--config-file), fixed; delta pass "No findings"Agent skill: no change needed. The squirrelscan skill lists
squirrel config validatewithout describing what it checks; it could add "run it after editing[rule_options]", which is optional.Closes #510