Skip to content
1 change: 1 addition & 0 deletions changelog.d/ratchet-config-holes.fixed.md
Original file line number Diff line number Diff line change
@@ -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.
185 changes: 185 additions & 0 deletions scripts/gate-ratchet.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading