diff --git a/changelog.d/ratchet-config-holes.fixed.md b/changelog.d/ratchet-config-holes.fixed.md new file mode 100644 index 00000000..a8ac2412 --- /dev/null +++ b/changelog.d/ratchet-config-holes.fixed.md @@ -0,0 +1 @@ +- Gate ratchet: now reports as WEAKENED `blockExoticSubdeps: false` and `ignoreScripts: false` in `pnpm-workspace.yaml`, an empty `files` list in `tsconfig*.json` (also one holding only a comment or empty strings), `allowEmptyCatch` on the ESLint `no-empty` rule, and a second `vitest*.config.*` file that competes with the ratcheted one. The three pnpm switches follow an allow-list: only `true` passes, and any other value (`no`, `off`, `0`, `null`, `~`, a tag) or a key form it cannot judge (flow style, nested, quoted) is UNREADABLE. Non-literal `no-empty` options are UNREADABLE. A `pyrightconfig.json` or `tsconfig*.json` with an unquoted key or an unclosed object is UNREADABLE (exit 2) instead of silently accepted. A run that compared zero config files no longer reports ok. `.npmrc` `ignore-scripts` and `dangerously-allow-all-builds` follow the same allow-list (quotes and blanks stripped; `ignore-scripts=0`, `=no`, `=off`, an empty value and `dangerously-allow-all-builds=1` or `=yes` are UNREADABLE). A key written with a backslash (`no-empty` options, a quoted `pnpm-workspace.yaml` key, a `tsconfig*.json` or `pyrightconfig.json` key, an ESLint rule name) is UNREADABLE, and a stray quote inside an `.npmrc` value is UNREADABLE. diff --git a/scripts/gate-ratchet.test.sh b/scripts/gate-ratchet.test.sh index 470f2ec3..a26e9b79 100644 --- a/scripts/gate-ratchet.test.sh +++ b/scripts/gate-ratchet.test.sh @@ -169,6 +169,191 @@ expect() { for frag in "$@"; do has "$frag" "$OUT" "$label: reports $frag"; done } +# Config holes: each probe has a clean control that must pass. GR_ONLY=holes runs only this section; it prints one line per case. +holes_cases() { + local sel hts + hc() { echo "gate-ratchet.test: holes: $1"; } + + hc "ts controls" + seed ts + hts=$(git_ rev-parse HEAD) + reseed() { git_ checkout -q -f -B main "$1" && git_ clean -fdq; } + git_ checkout -q -B work main + expect 0 "holes: unchanged TS config passes" + passes pnpm-workspace.yaml "minimumReleaseAge: 10080" "minimumReleaseAge: 20160" "holes: tightened pnpm workspace" + passes tsconfig.json '"noImplicitOverride": true,' '"noImplicitOverride": true, + "noImplicitReturns": true,' "holes: tightened tsconfig" + passes eslint.config.mjs "['error', 15]" "['error', 10]" "holes: tightened eslint limit" + + hc "blockExoticSubdeps" + weakens pnpm-workspace.yaml "blockExoticSubdeps: true" "blockExoticSubdeps: false" "holes: blockExoticSubdeps false" "blockExoticSubdeps" + weakens pnpm-workspace.yaml "blockExoticSubdeps: true" '"blockExoticSubdeps": false' "holes: blockExoticSubdeps quoted key false" "blockExoticSubdeps" + weakens pnpm-workspace.yaml "blockExoticSubdeps: true" "blockExoticSubdeps: true +ignoreScripts: false" "holes: ignoreScripts false" "ignoreScripts" + passes pnpm-workspace.yaml "blockExoticSubdeps: true" "blockExoticSubdeps: true +ignoreScripts: true" "holes: ignoreScripts true" + passes pnpm-workspace.yaml "blockExoticSubdeps: true" "'blockExoticSubdeps': true" "holes: blockExoticSubdeps quoted key true" + for v in no off 0 '~' '!!bool false' null; do + edit pnpm-workspace.yaml "blockExoticSubdeps: true" "blockExoticSubdeps: $v" + expect 2 "holes: blockExoticSubdeps $v is unreadable" "UNREADABLE pnpm-workspace.yaml" "fail closed" + done + edit pnpm-workspace.yaml "blockExoticSubdeps: true" "strictDepBuilds: no +blockExoticSubdeps: true" + expect 2 "holes: strictDepBuilds no is unreadable" "UNREADABLE pnpm-workspace.yaml" "fail closed" + edit pnpm-workspace.yaml "blockExoticSubdeps: true" "blockExoticSubdeps: true +nested: + blockExoticSubdeps: false" + expect 2 "holes: nested blockExoticSubdeps is unreadable" "UNREADABLE pnpm-workspace.yaml" "fail closed" + edit pnpm-workspace.yaml "blockExoticSubdeps: true" "{blockExoticSubdeps: false}" + expect 2 "holes: flow-style blockExoticSubdeps is unreadable" "UNREADABLE pnpm-workspace.yaml" "fail closed" + passes pnpm-workspace.yaml "blockExoticSubdeps: true" "# blockExoticSubdeps: false +blockExoticSubdeps: true" "holes: blockExoticSubdeps false only in a comment" + + hc "tsconfig files" + weakens tsconfig.json '"include": [' '"files": [], "include": [' "holes: tsconfig empty files list" "files" + passes tsconfig.json '"include": [' '"files": ["src/main.ts"], "include": [' "holes: tsconfig files with an entry" + weakens tsconfig.json '"include": [' '"files": [ /* none */ ], "include": [' "holes: tsconfig files list holding only a comment" "files" + weakens tsconfig.json '"include": [' '"files": [""], "include": [' "holes: tsconfig files list holding only an empty string" "files" + + hc "npmrc switches" + for v in 'ignore-scripts="false"' "ignore-scripts='false'" " Ignore-Scripts = false"; do + weakens .npmrc "# note" "# note +$v" "holes: npmrc $v" "ignore-scripts=false" + done + for v in 'ignore-scripts=0' 'ignore-scripts=no' 'ignore-scripts=off' 'ignore-scripts=' 'ignore-scripts' 'dangerously-allow-all-builds=1' 'dangerously-allow-all-builds=yes' 'dangerously-allow-all-builds='; do + edit .npmrc "# note" "# note +$v" + expect 2 "holes: npmrc $v is unreadable" "UNREADABLE .npmrc" "fail closed" + done + for v in 'ignore-scripts="tr"ue' "ignore-scripts=\"true'" 'ignore-scripts=tr"ue"'; do + edit .npmrc "# note" "# note +$v" + expect 2 "holes: npmrc $v is unreadable" "UNREADABLE .npmrc" "fail closed" + done + weakens .npmrc "# note" '# note +"ignore-scripts"="false"' "holes: npmrc quoted key and value false" "ignore-scripts=false" + weakens .npmrc "# note" '# note +dangerously-allow-all-builds="true"' "holes: npmrc dangerously-allow-all-builds quoted true" "dangerously-allow-all-builds=true" + weakens .npmrc "# note" "# note +dangerously-allow-all-builds=true" "holes: npmrc dangerously-allow-all-builds true" "dangerously-allow-all-builds=true" + for v in 'ignore-scripts=true' 'ignore-scripts="true"' 'dangerously-allow-all-builds=false' '# ignore-scripts=false' '; ignore-scripts=0'; do + passes .npmrc "# note" "# note +$v" "holes: npmrc $v" + done + + hc "pnpm escaped key" + edit pnpm-workspace.yaml "blockExoticSubdeps: true" '"blockExoticSubdeps": true +"ignore\x53cripts": false' + expect 2 "holes: pnpm escaped switch key is unreadable" "UNREADABLE pnpm-workspace.yaml" "fail closed" + passes pnpm-workspace.yaml "blockExoticSubdeps: true" '"blockExoticSubdeps": true +"ignoreScripts": true' "holes: pnpm double-quoted switch keys without an escape" + edit pnpm-workspace.yaml "blockExoticSubdeps: true" 'blockExoticSubdeps: true +nested: + "ignore\x53cripts": false' + expect 2 "holes: pnpm indented escaped switch key is unreadable" "UNREADABLE pnpm-workspace.yaml" "fail closed" + edit pnpm-workspace.yaml "blockExoticSubdeps: true" "blockExoticSubdeps: true +'ignore\\x53cripts': false" + expect 2 "holes: pnpm single-quoted key with a backslash is unreadable" "UNREADABLE pnpm-workspace.yaml" "fail closed" + passes pnpm-workspace.yaml "blockExoticSubdeps: true" 'blockExoticSubdeps: true +# "ignore\x53cripts": false' "holes: pnpm escaped key only in a comment" + + weakens tsconfig.json '"include": [' '"files": [], "include": [' "holes: tsconfig plain files key control" "files" + edit tsconfig.json '"include": [' '"fil\u0065s": [], "include": [' + expect 2 "holes: tsconfig escaped top-level key is unreadable" "UNREADABLE tsconfig.json" "fail closed" + + hc "second vitest config" + add_file vitest.unit.config.ts "export default { test: { coverage: { thresholds: { lines: 1 } } } };" + expect 1 "holes: new second vitest config" "vitest.unit.config.ts" + add_file vitest.config.e2e.mts "export default {};" + expect 0 "holes: new e2e vitest config keeps its old route" + reseed "$hts" + git_ checkout -q -B work main + printf 'export default { test: { coverage: { thresholds: { lines: 80 } } } };\n' > "$R/vitest.unit.config.ts" + git_ add -A; git_ commit -q -m "second config"; git_ checkout -q -B main work + weakens vitest.unit.config.ts "lines: 80" "lines: 1" "holes: threshold lowered in a second vitest config" "was 80" "now 1" + passes vitest.unit.config.ts "lines: 80" "lines: 90" "holes: threshold raised in a second vitest config" + + hc "vitest config renamed" + reseed "$hts" + git_ checkout -q -B work main + git_ mv vitest.config.ts vitest.main.config.ts + git_ commit -q -m rename + expect 1 "holes: renamed vitest config is a removal" "vitest.config.ts" "now removed" + + hc "allowEmptyCatch" + reseed "$hts" + weakens eslint.config.mjs "// @ts-check" "// @ts-check +const noEmpty = { rules: { 'no-empty': ['error', { allowEmptyCatch: true }] } };" "holes: no-empty allowEmptyCatch true" "allow-empty-catch" + passes eslint.config.mjs "// @ts-check" "// @ts-check +const noEmpty = { rules: { 'no-empty': ['error', { allowEmptyCatch: false }] } };" "holes: no-empty allowEmptyCatch false" + ne() { printf '// @ts-check\nconst opts = { allowEmptyCatch: true };\nconst base = {};\nconst noEmpty = { rules: { %s } };' "$1"; } + weakens eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { 'allowEmptyCatch': true }]")" "holes: no-empty quoted allowEmptyCatch" "allow-empty-catch" + weakens eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { allowEmptyCatch: !0 }]")" "holes: no-empty allowEmptyCatch !0" "allow-empty-catch" + weakens eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { allowEmptyCatch: /* x */ true }]")" "holes: no-empty allowEmptyCatch after a comment" "allow-empty-catch" + weakens eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { x: { y: 1 }, allowEmptyCatch: true }]")" "holes: no-empty allowEmptyCatch after a nested object" "allow-empty-catch" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { 'allowEmptyC\\atch': true }]")" + expect 2 "holes: no-empty identity-escaped key is unreadable" "UNREADABLE eslint.config.mjs" "fail closed" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { \"allowEmpty\\Catch\": true }]")" + expect 2 "holes: no-empty double-quoted identity-escaped key is unreadable" "UNREADABLE eslint.config.mjs" "fail closed" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { 'allowEmpty\\ +Catch': true }]")" + expect 2 "holes: no-empty key with a line continuation is unreadable" "UNREADABLE eslint.config.mjs" "fail closed" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-em\\u0070ty': ['error', { allowEmptyCatch: true }]")" + expect 2 "holes: escaped no-empty rule name is unreadable" "UNREADABLE eslint.config.mjs" "fail closed" + passes eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { 'allowEmptyCatch': false }]")" "holes: no-empty quoted key false passes" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { \\u0061llowEmptyCatch: true }]")" + expect 2 "holes: no-empty unicode-escaped key is unreadable" "UNREADABLE eslint.config.mjs" "fail closed" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { 'allow\\x45mptyCatch': true }]")" + expect 2 "holes: no-empty hex-escaped quoted key is unreadable" "UNREADABLE eslint.config.mjs" "fail closed" + weakens eslint.config.mjs "// @ts-check" "$(ne "'no-empty': [2, { allowEmptyCatch: true }]")" "holes: no-empty numeric severity allowEmptyCatch true" "allow-empty-catch" + passes eslint.config.mjs "// @ts-check" "$(ne "'no-empty': [2, { allowEmptyCatch: false }]")" "holes: no-empty numeric severity allowEmptyCatch false" + passes eslint.config.mjs "// @ts-check" "$(ne "'no-empty': [2]")" "holes: no-empty numeric severity only" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', opts]")" + expect 2 "holes: no-empty options by variable are unreadable" "UNREADABLE eslint.config.mjs" "fail closed" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error', { ...base }]")" + expect 2 "holes: no-empty options with a spread are unreadable" "UNREADABLE eslint.config.mjs" "fail closed" + edit eslint.config.mjs "// @ts-check" "$(ne "'no-empty': ['error']")" + expect 0 "holes: no-empty with severity only passes" + + hc "unreadable effective eslint config" + reseed "$hts" + cp "$SH/template-ts/scripts/eslint-effective.mjs" "$R/scripts/eslint-effective.mjs" + git_ add -A; git_ commit -q -m helper + edit eslint.config.mjs "['error', 15]" "['error', 10]" + expect 2 "holes: no installed eslint is unreadable, never a pass" "UNREADABLE eslint.config.mjs" "fail closed" + + hc "malformed tsconfig" + reseed "$hts" + edit tsconfig.json '"compilerOptions": {' 'oops: 1, "compilerOptions": {' + expect 2 "holes: malformed tsconfig fails closed" "UNREADABLE tsconfig.json" + + hc "python controls" + seed py + git_ checkout -q -B work main + expect 0 "holes: unchanged Python config passes" + passes pyproject.toml '"TID251", "TID252",' '"TID251", "TID252", "ANN",' "holes: ruff select gains a family" + sel='"E4", "E7", "E9", "F", "I",' + weakens pyproject.toml "$sel" '"E4", "E7", "E9", "F",' "holes: ruff select loses a family" "select 'I'" + weakens pyproject.toml "$sel" '"E4",' "holes: ruff select narrowed" "select 'E7'" + hc "pyright" + edit pyrightconfig.json '"venvPath": ".",' '"venvPath": ".", oops: 1, "reportMissingImports": "none",' + expect 2 "holes: malformed pyrightconfig fails closed" "UNREADABLE pyrightconfig.json" + git_ checkout -q -B work main + printf '{ "typeCheckingMode": "strict"\n' > "$R/pyrightconfig.json" + git_ commit -q -am truncated + expect 2 "holes: truncated pyrightconfig fails closed" "UNREADABLE pyrightconfig.json" + passes pyrightconfig.json '"typeCheckingMode": "strict"' '"typeCheckingMode": "strict", "reportMissingImports": "error"' "holes: pyright gains a report setting" + edit pyrightconfig.json '"typeCheckingMode": "strict"' '"typeCheckingMode": "strict", "reportMissingImp\u006frts": "none"' + expect 2 "holes: pyright escaped key is unreadable" "UNREADABLE pyrightconfig.json" "fail closed" +} + +holes_cases +if [[ "${GR_ONLY:-}" == holes ]]; then + echo "gate-ratchet.test: $PASS passed, $FAIL failed" + [[ "$FAIL" -eq 0 ]] + exit +fi + TAB=$(printf '\t') NEWSHA=$(printf 'a%.0s' {1..40}) seed ts diff --git a/skills/scaffold/shared/template/scripts/gate-ratchet.sh b/skills/scaffold/shared/template/scripts/gate-ratchet.sh index e6c3c3b0..9eca0ded 100755 --- a/skills/scaffold/shared/template/scripts/gate-ratchet.sh +++ b/skills/scaffold/shared/template/scripts/gate-ratchet.sh @@ -7,6 +7,7 @@ # pytest: any change to a [tool.pytest.ini_options] key or a new key is a finding, except raising --cov-fail-under and the markers, pythonpath and asyncio_default_fixture_loop_scope keys. # import-linter: every key of [tool.importlinter] and its contracts must stay as it was (layers, root_packages, ignore_imports); a new .importlinter or setup.cfg competes with it. # Type checkers: tsconfig and pyright strictness may tighten, never loosen; a new tsconfig or pyright config may not switch strictness off. +# Closed list of config keys the ratchet reads beyond the above: pnpm-workspace.yaml strictDepBuilds, ignoreScripts and blockExoticSubdeps (allow-list: only the literal safe value true passes, false is a fact, any other value or key form the reader cannot judge is UNREADABLE), tsconfig files (an empty list, or one holding only empty strings, is a fact), eslint no-empty (any allowEmptyCatch other than literal false is a fact; options, or any key written with a backslash (no-empty options, a quoted pnpm-workspace.yaml key, a tsconfig or pyright key, an eslint rule name), cannot be read and are UNREADABLE), .npmrc ignore-scripts (true safe, false a fact) and dangerously-allow-all-builds (false safe, true a fact; blanks stripped and one matching quote pair removed, any other value UNREADABLE), and every vitest*.config.* file (an existing one is compared by its facts; a new one beside a vite or vitest config is WEAKENED). A value the readers cannot parse fails closed; nothing they read is skipped. # Gate-time budget: .claude/gate-budget.conf may not be deleted, and its three limits may not rise; a conf with no merge-base copy is held to the seeded defaults (600, 180, 25) and may not set a higher limit or leave one out. The kind is not enforced, so a human applying the allow-gate-change label can waive a raise or a deletion, by design. # Allow-lists: dep-audit-allow.txt may only lose lines; comment-hygiene-patterns.txt may only gain lines at the end. # Seeded-file exemptions: when the merge base has .claude/harness.json, a new entry, a changed origin_hash or a path added to .claude/seeded-paths.txt is WEAKENED, a dropped manifest is WEAKENED, an entry or list line removed is fine, and an unreadable or duplicated manifest is UNREADABLE. The seedmf kind is not enforced, so the human-applied allow-gate-change label waives WEAKENED (the bless, upgrade and refresh routes change hashes and entries and need it); UNREADABLE is never waived. When the merge base has .claude/gates.txt but no manifest, a manifest added in this change is WEAKENED (human waiver only). Without any harness at the merge base (adoption) one NOTE counts the exempt files. @@ -100,6 +101,7 @@ kind_of() { .jscpd.json | */.jscpd.json) KIND=jscpd ;; eslint.config.* | */eslint.config.* | layers.config.mjs | */layers.config.mjs) KIND=eslint ;; vitest.config.* | vite.config.* | vitest.workspace.* | jest.config.* | */vitest.config.* | */vite.config.* | */vitest.workspace.* | */jest.config.*) KIND=vitest ;; + vitest*.config.* | */vitest*.config.*) KIND=vitest ;; .coveragerc | */.coveragerc) KIND=coveragerc ;; sonar-project.properties | */sonar-project.properties) KIND=sonar ;; package.json | */package.json) KIND=pkgjson ;; @@ -275,6 +277,15 @@ shadow_reason() { fi done ;; + vitest?*.config.*) + case "${name#*.config.}" in js | mjs | cjs | ts | mts | cts | json) ;; *) return 1 ;; esac + for f in vite vitest; do + if gs_test awk -v pre="${dir}${f}.config." 'index($0, pre) == 1 && substr($0, length(pre) + 1) ~ /^([cm]?[jt]s|json)$/ { hit = 1 } END { exit !hit }' "$wd/base.paths"; then + echo "a second vitest config can carry its own coverage thresholds, and a run reads only the config it is pointed at" + return 0 + fi + done + ;; eslint.config.* | vitest.config.* | vite.config.* | jest.config.*) case "${name#*.config.}" in js | mjs | cjs | ts | mts | cts | json) ;; *) return 1 ;; esac fam=${name%%.config.*} @@ -674,9 +685,33 @@ function do_eslint_import( from, m) { } } -function do_eslint( from, m, name, rest, sev, seen, p, opt, sc, key, lim) { +# no-empty options (index i is just after the severity): none, or one object literal whose allowEmptyCatch is only ever the literal false. Any other allowEmptyCatch (true, !0, 1, a variable, a shorthand, nested) is a fact; an options argument that is not an object literal, or one with a spread, a computed key or any backslash, cannot be read and fails closed. +function no_empty(i, arr, key, q, n, body, r, after, flagged) { + if (!arr) return + n = length(T); q = i + if (substr(T, i - 1, 1) == "]") return + if (substr(T, i - 1, 1) == ",") q = i - 1 + while (q <= n && substr(T, q, 1) ~ /[ \t\n]/) q++ + if (substr(T, q, 1) == "]") return + if (substr(T, q, 1) != ",") fail("no-empty is set in a form the reader cannot judge: " oneline(substr(T, q, 30))) + q++ + while (q <= n && substr(T, q, 1) ~ /[ \t\n]/) q++ + if (substr(T, q, 1) != "{") fail("no-empty options are not an object literal, so allowEmptyCatch cannot be read: " oneline(substr(T, q, 30))) + body = substr(T, q, CL[q] - q + 1) + if (body ~ /[.][.][.]/ || body ~ /[[]/) fail("no-empty options use a spread or a computed key, so allowEmptyCatch cannot be read") + if (body ~ /[\\]/) fail("no-empty options hold a backslash, so a key could hide allowEmptyCatch behind an escape and cannot be read") + flagged = 0; r = body + while (match(r, /allowEmptyCatch/)) { + after = substr(r, RSTART + RLENGTH) + if (after !~ /^["']?[ \t\n]*:[ \t\n]*false[ \t\n]*([,}]|$)/) flagged = 1 + r = after + } + if (flagged) emit("set", "allow-empty-catch", key) +} + +function do_eslint( from, m, name, rest, sev, seen, p, opt, sc, key, lim, ne_seen, ne_all) { code_scan() - seen = 0; from = 1 + seen = 0; from = 1; ne_seen = 0 brace_map() while (find("['\"]?[@A-Za-z0-9/_.-]+['\"]?[ \t\n]*:[ \t\n]*([[][ \t\n]*)?(['\"](off|warn|error)['\"]|[012][],} \t\n])", from)) { sc = scope_of(MS) @@ -689,9 +724,15 @@ function do_eslint( from, m, name, rest, sev, seen, p, opt, sc, key, lim) { emit("sev", key, sev); seen = 1 if (sev < 2 && in_rules(MS)) emit("set", "rule-below-error", key) p = substr(T, from) + if (name == "no-empty") { ne_seen++; no_empty(from, rest ~ /^[ \t\n]*[[]/, key) } if (match(p, /^[ \t\n]*,[ \t\n]*[0-9]+[ \t\n]*[],]/)) emit("max", lim, num_in(substr(p, 1, RLENGTH))) else if (match(p, /^[ \t\n]*,[ \t\n]*[{][^}]*(max|maximum|threshold|complexity)[ \t\n]*:[ \t\n]*[0-9]+/)) { opt = substr(p, 1, RLENGTH); sub(/.*:[ \t\n]*/, "", opt); emit("max", lim, opt) } } + from = 1; ne_all = 0 + while (find("(^|[^A-Za-z0-9_$./@-])[\"']?no-empty[\"']?[ \t\n]*:", from)) { ne_all++; from = MS + ML } + if (ne_all > ne_seen) fail("no-empty is set in a form the reader cannot judge (its value is not a severity or a [severity, options] array)") + from = 1 + if (find("['\"][^'\"\n]*[\\\\][^'\"\n]*['\"][ \t\n]*:[ \t\n]*([[][ \t\n]*)?(['\"](off|warn|error)['\"]|[012][],} \t\n])", from)) fail("a rule name with a backslash is set to a severity, so the rule behind the escape cannot be read: " oneline(substr(T, MS, 40))) from = 1 while (find("[A-Za-z0-9_]+[.]configs[.][A-Za-z0-9_.]+|[A-Za-z0-9_]+[.]recommended", from)) { emit("req", "preset", substr(T, MS, ML)); from = MS + ML; seen = 1 } from = 1 @@ -1147,15 +1188,20 @@ function do_tsconfig( p, n, j, key, v) { if (p <= 1) fail("tsconfig is not a JSON object") while (p > 1 && p <= n) { while (p <= n && substr(T, p, 1) ~ /[ \t\n,]/) p++ - if (substr(T, p, 1) != "\"") break + if (substr(T, p, 1) != "\"") { if (substr(T, p, 1) != "}") fail("a key is not a quoted name, so the rest of the file is unread: " substr(T, p, 20)); break } j = jstr_end(p); key = substr(T, p + 1, j - p - 1); p = j + 1 + if (key ~ /\\/) fail("tsconfig key with an escape sequence: " key) while (p <= n && substr(T, p, 1) ~ /[ \t\n:]/) p++ if (key == "compilerOptions") ts_options(p) else if (key == "extends") emit("cfg", "extends", vtext(p)) else if (key == "exclude") strict_array(p, "set", "exclude") - else if (key == "include" || key == "files") strict_array(p, "req", key) + else if (key == "include" || key == "files") { + strict_array(p, "req", key) + if (key == "files") { v = vtext(p); gsub(/""|''|``/, "", v); if (v ~ /^\[[ \t\n,]*\]$/) emit("set", "files", "empty") } + } v = vtext(p); p = VEND } + if (p > n) fail("the top-level object is not closed") } function sev_of(v) { @@ -1171,8 +1217,9 @@ function do_pyright( p, n, j, key, v, m, sv, mode) { if (p <= 1) fail("pyrightconfig is not a JSON object") while (p > 1 && p <= n) { while (p <= n && substr(T, p, 1) ~ /[ \t\n,]/) p++ - if (substr(T, p, 1) != "\"") break + if (substr(T, p, 1) != "\"") { if (substr(T, p, 1) != "}") fail("a key is not a quoted name, so the rest of the file is unread: " substr(T, p, 20)); break } j = jstr_end(p); key = substr(T, p + 1, j - p - 1); p = j + 1 + if (key ~ /\\/) fail("pyrightconfig key with an escape sequence: " key) while (p <= n && substr(T, p, 1) ~ /[ \t\n:]/) p++ v = vtext(p) if (key == "typeCheckingMode") { @@ -1189,6 +1236,7 @@ function do_pyright( p, n, j, key, v, m, sv, mode) { else if (key !~ /^(venvPath|venv|pythonVersion|pythonPlatform|extraPaths|stubPath|typeshedPath|verboseOutput)$/) emit("cfg", key, v) p = VEND } + if (p > n) fail("the top-level object is not closed") emit("min", "pyright-mode", mode) emit("flag", "typeCheckingMode", (mode >= 2) ? 1 : 0) } @@ -1360,16 +1408,27 @@ function norm_yaml(line) { if (line ~ /^["'][A-Za-z]+["'][ \t]*:/) { sub(/^["']/, "", line); sub(/["'][ \t]*:/, ":", line) } return line } +# strictDepBuilds, ignoreScripts and blockExoticSubdeps are safe only as the plain literal true at column 0. The weak literal false is a fact; any other value, and any other spelling or place of the key (nested, flow style, spaced colon), cannot be judged and fails closed. +function pnpm_switch(line, k, v) { + match(line, /(strictDepBuilds|ignoreScripts|blockExoticSubdeps)/); k = substr(line, RSTART, RLENGTH) + if (line !~ ("^" k ":[ \t]*[^ \t]")) fail("pnpm-workspace.yaml has " k " in a form the reader cannot judge (nested, flow style, quoted with a space, or with no value): " substr(line, 1, 60)) + v = line; sub(/^[^:]*:[ \t]*/, "", v); gsub(/^["']|["']$/, "", v) + if (yes(v)) return + if (no(v)) { emit("set", k, "false"); return } + fail("pnpm-workspace.yaml " k " is not the plain literal true or false: " v) +} function do_pnpmws( i, n, L, line, v, inbuilds, inlist) { n = split(T, L, "\n"); inbuilds = 0; inlist = "" for (i = 1; i <= n; i++) { + if (L[i] ~ /^[ \t]*#/) continue + if (L[i] ~ /^[ \t]*([-][ \t]+)?["'][^"']*[\\][^"']*["'][ \t]*:/) fail("pnpm-workspace.yaml has a quoted key with a backslash, which can hide a switch key behind an escape and cannot be read: " substr(L[i], 1, 60)) line = norm_yaml(L[i]) + if (line ~ /(strictDepBuilds|ignoreScripts|blockExoticSubdeps)/) { pnpm_switch(line); continue } if (line ~ /^[^ \t#-]/) { inbuilds = (line ~ /^allowBuilds:/); inlist = ""; if (line ~ /^(onlyBuiltDependencies|minimumReleaseAgeExclude|neverBuiltDependencies):/) { inlist = line; sub(/:.*$/, "", inlist) } } if (inlist != "" && line ~ /^[ \t]*-[ \t]/) { v = line; sub(/^[ \t]*-[ \t]+/, "", v); gsub(/^[ \t'"'"'"]+|[ \t'"'"'"]+$/, "", v); if (inlist != "neverBuiltDependencies") emit("set", inlist, v); continue } if (line ~ /^minimumReleaseAge:/) { v = line; sub(/^[^:]*:[ \t]*/, "", v); gsub(/^["']|["']$/, "", v); if (!plain_num(v)) fail("minimumReleaseAge is not a plain number"); emit("min", "minimumReleaseAge", v) } else if (line ~ /^minimumReleaseAgeExclude:/) emit("set", "minimumReleaseAgeExclude", "present") else if (line ~ /^dangerouslyAllowAllBuilds:/) { v = line; sub(/^[^:]*:[ \t]*/, "", v); gsub(/^["']|["']$/, "", v); if (yes(v)) emit("set", "dangerouslyAllowAllBuilds", "true") } - else if (line ~ /^(strictDepBuilds|ignoreScripts):/) { v = line; sub(/^[^:]*:[ \t]*/, "", v); gsub(/^["']|["']$/, "", v); if (no(v)) { sub(/:.*$/, "", line); emit("set", line, "false") } } else if (inbuilds && line ~ /^[ \t]+[^ \t].*:[ \t]*["']?[Tt][Rr][Uu][Ee]["']?[ \t]*$/) { v = line; sub(/:[ \t]*["']?[Tt][Rr][Uu][Ee]["']?[ \t]*$/, "", v); gsub(/^[ \t'"'"'"]+|[ \t'"'"'"]+$/, "", v); emit("set", "allowBuilds", v) } } } @@ -1385,12 +1444,28 @@ function do_dependabot( i, n, L, line, v) { } } -function do_npmrc( i, n, L, line) { +# ignore-scripts is safe only as true; false is a fact. dangerously-allow-all-builds is safe only as false or absent; true is a fact. Blanks are stripped and one matching quote pair around the key or around the value is removed; any other value (a quote anywhere else included), or the key with no value, cannot be judged and fails closed. +function unquote(x) { + if (length(x) >= 2 && (x ~ /^".*"$/ || x ~ /^'.*'$/)) return substr(x, 2, length(x) - 2) + return x +} +function npmrc_switch(k, v, safe, weak) { + if (v == safe) return + if (v == weak) { emit("set", "npmrc", k "=" weak); return } + fail(".npmrc " k " is not the plain literal true or false: " v) +} +function do_npmrc( i, n, L, line, k, v) { n = split(T, L, "\n") for (i = 1; i <= n; i++) { line = L[i]; sub(/\r$/, "", line); line = tolower(line); gsub(/[ \t]+/, "", line) - if (line ~ /^ignore-scripts=false/) emit("set", "npmrc", "ignore-scripts=false") - else if (line ~ /^dangerously-allow-all-builds=true/) emit("set", "npmrc", "dangerously-allow-all-builds=true") + if (line ~ /^[#;]/) continue + k = line; sub(/=.*$/, "", k); k = unquote(k) + if (k == "ignore-scripts" || k == "dangerously-allow-all-builds") { + if (line !~ /=/) fail(".npmrc has " k " with no value: " substr(line, 1, 60)) + v = line; sub(/^[^=]*=/, "", v); v = unquote(v) + if (k == "ignore-scripts") npmrc_switch(k, v, "true", "false") + else npmrc_switch(k, v, "false", "true") + } else if (line ~ /^(@[^:]+:)?registry=/) emit("set", "npmrc-registry", line) } } @@ -2479,7 +2554,7 @@ fp_cfg() { awk -v p="$pre" ' index($0, p) == 1 { n = split($0, a, "/"); name = a[n]; dir = substr($0, 1, length($0) - length(name)) - if (name ~ /^(vite|vitest)[.]config[.]([cm]?[jt]s|json)$/) v[dir]++ + if (name ~ /^(vite[.]config|vitest[^\/]*[.]config)[.]([cm]?[jt]s|json)$/) v[dir]++ if (name ~ /^eslint[.]config[.]([cm]?[jt]s|json)$/) e[dir]++ if (name ~ /^vitest[.]workspace[.]/) printf "WEAKENED %s: a vitest workspace file replaces the test projects of the seeded vitest config, so its coverage floor may not apply\n", $0 if (name ~ /^sonar-project[.]properties$/ || name ~ /^[.]sonarcloud[.]properties$/) s[dir]++ @@ -2792,4 +2867,5 @@ if [ "$unreadable" -eq 1 ]; then echo "Fix: make the file parseable again (restore it from the merge base), then rerun." exit 2 fi +[ "$checked" -gt 0 ] || die "no config file was compared, so nothing was checked; a run that checked nothing is never a pass" echo "gate-ratchet: ok, no gate weaker than at the merge base ($checked config files compared)" diff --git a/tests/golden/fastapi-azure.sha256 b/tests/golden/fastapi-azure.sha256 index 4524962b..3373ddb1 100644 --- a/tests/golden/fastapi-azure.sha256 +++ b/tests/golden/fastapi-azure.sha256 @@ -86,7 +86,7 @@ ab80c3ab9f8ac2eeab4c5a0f0004f1e26fd6adacbc75469fd4bfe00e791070e7 scripts/check- 84d10ea43df30579ca62c7d212bff597b7a5d14fd2b2be631b636ee038ff3476 scripts/export-openapi.py 37e7b2aade49bc372a2050dcdf842217f2bb8322fc3ef388b27415e08671f6e6 scripts/gate-baseline.sh cccb8022930f0043802d74bb9a48c681d7bcf0dc68705387c2b0a1550eb98cb8 scripts/gate-baselined.sh -9a8a1c1992b0a2105f9a74c7f9f62d3d4ebb1b4adadce3fcc40ebf6d9b1b9392 scripts/gate-ratchet.sh +e37f59acaafd1b99f99cc11563164bc309981b464a3f2c6d6c88374bb43b2763 scripts/gate-ratchet.sh f105c09063c535f5aed591915e34621227d0ea3f98f337794d78cb1dfaff3b9a scripts/generate-sbom.sh 55604fae082ab98f07e6b263221a614e5399f46c1dbbf89aad5351eb68531748 scripts/hook-shim.sh 70edb543475618e2dddc2954a0b9f24309a312cb114cfe3596ff9ebe91db6d7e scripts/py-env.py diff --git a/tests/golden/fastapi-github.sha256 b/tests/golden/fastapi-github.sha256 index b7e36f28..1ded4ddb 100644 --- a/tests/golden/fastapi-github.sha256 +++ b/tests/golden/fastapi-github.sha256 @@ -86,7 +86,7 @@ ab80c3ab9f8ac2eeab4c5a0f0004f1e26fd6adacbc75469fd4bfe00e791070e7 scripts/check- 84d10ea43df30579ca62c7d212bff597b7a5d14fd2b2be631b636ee038ff3476 scripts/export-openapi.py 37e7b2aade49bc372a2050dcdf842217f2bb8322fc3ef388b27415e08671f6e6 scripts/gate-baseline.sh cccb8022930f0043802d74bb9a48c681d7bcf0dc68705387c2b0a1550eb98cb8 scripts/gate-baselined.sh -9a8a1c1992b0a2105f9a74c7f9f62d3d4ebb1b4adadce3fcc40ebf6d9b1b9392 scripts/gate-ratchet.sh +e37f59acaafd1b99f99cc11563164bc309981b464a3f2c6d6c88374bb43b2763 scripts/gate-ratchet.sh f105c09063c535f5aed591915e34621227d0ea3f98f337794d78cb1dfaff3b9a scripts/generate-sbom.sh 55604fae082ab98f07e6b263221a614e5399f46c1dbbf89aad5351eb68531748 scripts/hook-shim.sh 70edb543475618e2dddc2954a0b9f24309a312cb114cfe3596ff9ebe91db6d7e scripts/py-env.py diff --git a/tests/golden/nestjs-azure.sha256 b/tests/golden/nestjs-azure.sha256 index e4e7e545..1f8092e9 100644 --- a/tests/golden/nestjs-azure.sha256 +++ b/tests/golden/nestjs-azure.sha256 @@ -92,7 +92,7 @@ ab80c3ab9f8ac2eeab4c5a0f0004f1e26fd6adacbc75469fd4bfe00e791070e7 scripts/check- 5cf243f9c1e927b4b5fa4bdbffc2cb7331643405b2cb15c2cebf4d44f2c42530 scripts/export-openapi.mjs 37e7b2aade49bc372a2050dcdf842217f2bb8322fc3ef388b27415e08671f6e6 scripts/gate-baseline.sh cccb8022930f0043802d74bb9a48c681d7bcf0dc68705387c2b0a1550eb98cb8 scripts/gate-baselined.sh -9a8a1c1992b0a2105f9a74c7f9f62d3d4ebb1b4adadce3fcc40ebf6d9b1b9392 scripts/gate-ratchet.sh +e37f59acaafd1b99f99cc11563164bc309981b464a3f2c6d6c88374bb43b2763 scripts/gate-ratchet.sh f105c09063c535f5aed591915e34621227d0ea3f98f337794d78cb1dfaff3b9a scripts/generate-sbom.sh 70edb543475618e2dddc2954a0b9f24309a312cb114cfe3596ff9ebe91db6d7e scripts/py-env.py ff24e2d2b39700e7434a461746fadfcd285814185f1ac297e3f6f0517f4479ac scripts/record-review.sh diff --git a/tests/golden/nestjs-github.sha256 b/tests/golden/nestjs-github.sha256 index 67dbba79..11653812 100644 --- a/tests/golden/nestjs-github.sha256 +++ b/tests/golden/nestjs-github.sha256 @@ -92,7 +92,7 @@ ab80c3ab9f8ac2eeab4c5a0f0004f1e26fd6adacbc75469fd4bfe00e791070e7 scripts/check- 5cf243f9c1e927b4b5fa4bdbffc2cb7331643405b2cb15c2cebf4d44f2c42530 scripts/export-openapi.mjs 37e7b2aade49bc372a2050dcdf842217f2bb8322fc3ef388b27415e08671f6e6 scripts/gate-baseline.sh cccb8022930f0043802d74bb9a48c681d7bcf0dc68705387c2b0a1550eb98cb8 scripts/gate-baselined.sh -9a8a1c1992b0a2105f9a74c7f9f62d3d4ebb1b4adadce3fcc40ebf6d9b1b9392 scripts/gate-ratchet.sh +e37f59acaafd1b99f99cc11563164bc309981b464a3f2c6d6c88374bb43b2763 scripts/gate-ratchet.sh f105c09063c535f5aed591915e34621227d0ea3f98f337794d78cb1dfaff3b9a scripts/generate-sbom.sh 70edb543475618e2dddc2954a0b9f24309a312cb114cfe3596ff9ebe91db6d7e scripts/py-env.py ff24e2d2b39700e7434a461746fadfcd285814185f1ac297e3f6f0517f4479ac scripts/record-review.sh diff --git a/tests/golden/nextjs-azure.sha256 b/tests/golden/nextjs-azure.sha256 index 65efa019..851c567c 100644 --- a/tests/golden/nextjs-azure.sha256 +++ b/tests/golden/nextjs-azure.sha256 @@ -97,7 +97,7 @@ ab80c3ab9f8ac2eeab4c5a0f0004f1e26fd6adacbc75469fd4bfe00e791070e7 scripts/check- 32a4c641ed3fa587143c2638c02c8ee86dc7a57119ef87f7dfd435487c531144 scripts/eslint-effective.mjs 37e7b2aade49bc372a2050dcdf842217f2bb8322fc3ef388b27415e08671f6e6 scripts/gate-baseline.sh cccb8022930f0043802d74bb9a48c681d7bcf0dc68705387c2b0a1550eb98cb8 scripts/gate-baselined.sh -9a8a1c1992b0a2105f9a74c7f9f62d3d4ebb1b4adadce3fcc40ebf6d9b1b9392 scripts/gate-ratchet.sh +e37f59acaafd1b99f99cc11563164bc309981b464a3f2c6d6c88374bb43b2763 scripts/gate-ratchet.sh f105c09063c535f5aed591915e34621227d0ea3f98f337794d78cb1dfaff3b9a scripts/generate-sbom.sh 70edb543475618e2dddc2954a0b9f24309a312cb114cfe3596ff9ebe91db6d7e scripts/py-env.py ff24e2d2b39700e7434a461746fadfcd285814185f1ac297e3f6f0517f4479ac scripts/record-review.sh diff --git a/tests/golden/nextjs-github.sha256 b/tests/golden/nextjs-github.sha256 index 4be5b0bc..5ed65b84 100644 --- a/tests/golden/nextjs-github.sha256 +++ b/tests/golden/nextjs-github.sha256 @@ -97,7 +97,7 @@ ab80c3ab9f8ac2eeab4c5a0f0004f1e26fd6adacbc75469fd4bfe00e791070e7 scripts/check- 32a4c641ed3fa587143c2638c02c8ee86dc7a57119ef87f7dfd435487c531144 scripts/eslint-effective.mjs 37e7b2aade49bc372a2050dcdf842217f2bb8322fc3ef388b27415e08671f6e6 scripts/gate-baseline.sh cccb8022930f0043802d74bb9a48c681d7bcf0dc68705387c2b0a1550eb98cb8 scripts/gate-baselined.sh -9a8a1c1992b0a2105f9a74c7f9f62d3d4ebb1b4adadce3fcc40ebf6d9b1b9392 scripts/gate-ratchet.sh +e37f59acaafd1b99f99cc11563164bc309981b464a3f2c6d6c88374bb43b2763 scripts/gate-ratchet.sh f105c09063c535f5aed591915e34621227d0ea3f98f337794d78cb1dfaff3b9a scripts/generate-sbom.sh 70edb543475618e2dddc2954a0b9f24309a312cb114cfe3596ff9ebe91db6d7e scripts/py-env.py ff24e2d2b39700e7434a461746fadfcd285814185f1ac297e3f6f0517f4479ac scripts/record-review.sh diff --git a/tests/golden/vite-react-azure.sha256 b/tests/golden/vite-react-azure.sha256 index d094ca5c..41653da6 100644 --- a/tests/golden/vite-react-azure.sha256 +++ b/tests/golden/vite-react-azure.sha256 @@ -95,7 +95,7 @@ ab80c3ab9f8ac2eeab4c5a0f0004f1e26fd6adacbc75469fd4bfe00e791070e7 scripts/check- 32a4c641ed3fa587143c2638c02c8ee86dc7a57119ef87f7dfd435487c531144 scripts/eslint-effective.mjs 37e7b2aade49bc372a2050dcdf842217f2bb8322fc3ef388b27415e08671f6e6 scripts/gate-baseline.sh cccb8022930f0043802d74bb9a48c681d7bcf0dc68705387c2b0a1550eb98cb8 scripts/gate-baselined.sh -9a8a1c1992b0a2105f9a74c7f9f62d3d4ebb1b4adadce3fcc40ebf6d9b1b9392 scripts/gate-ratchet.sh +e37f59acaafd1b99f99cc11563164bc309981b464a3f2c6d6c88374bb43b2763 scripts/gate-ratchet.sh f105c09063c535f5aed591915e34621227d0ea3f98f337794d78cb1dfaff3b9a scripts/generate-sbom.sh 70edb543475618e2dddc2954a0b9f24309a312cb114cfe3596ff9ebe91db6d7e scripts/py-env.py ff24e2d2b39700e7434a461746fadfcd285814185f1ac297e3f6f0517f4479ac scripts/record-review.sh diff --git a/tests/golden/vite-react-github.sha256 b/tests/golden/vite-react-github.sha256 index 1b73212f..7a7f84e5 100644 --- a/tests/golden/vite-react-github.sha256 +++ b/tests/golden/vite-react-github.sha256 @@ -95,7 +95,7 @@ ab80c3ab9f8ac2eeab4c5a0f0004f1e26fd6adacbc75469fd4bfe00e791070e7 scripts/check- 32a4c641ed3fa587143c2638c02c8ee86dc7a57119ef87f7dfd435487c531144 scripts/eslint-effective.mjs 37e7b2aade49bc372a2050dcdf842217f2bb8322fc3ef388b27415e08671f6e6 scripts/gate-baseline.sh cccb8022930f0043802d74bb9a48c681d7bcf0dc68705387c2b0a1550eb98cb8 scripts/gate-baselined.sh -9a8a1c1992b0a2105f9a74c7f9f62d3d4ebb1b4adadce3fcc40ebf6d9b1b9392 scripts/gate-ratchet.sh +e37f59acaafd1b99f99cc11563164bc309981b464a3f2c6d6c88374bb43b2763 scripts/gate-ratchet.sh f105c09063c535f5aed591915e34621227d0ea3f98f337794d78cb1dfaff3b9a scripts/generate-sbom.sh 70edb543475618e2dddc2954a0b9f24309a312cb114cfe3596ff9ebe91db6d7e scripts/py-env.py ff24e2d2b39700e7434a461746fadfcd285814185f1ac297e3f6f0517f4479ac scripts/record-review.sh