From 3fbe4b38d8bbc4cd980ac2009748e0d3d62bce68 Mon Sep 17 00:00:00 2001 From: apmantza Date: Wed, 9 Sep 2026 12:30:17 +0300 Subject: [PATCH] =?UTF-8?q?ci(strictness):=20spike=20=E2=80=94=20scratch?= =?UTF-8?q?=20configs,=20per-directory=20report,=20two-sided=20ratchet,=20?= =?UTF-8?q?advisory=20lane=20(refs=20#2697)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add report-only TypeScript strictness configs and per-directory baseline pins. Keep migration staged by directory while making both error populations visible. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_013gEp548mWcf8nWL9xivZWV --- .changelog/2697-strictness-spike.md | 5 ++ .github/workflows/lint.yml | 24 ++++++ scripts/strictness-report.d.mts | 15 ++++ scripts/strictness-report.mjs | 93 +++++++++++++++++++++ tests/config/advisory-tool-workflow.test.ts | 1 + tests/config/strictness-baseline.json | 37 ++++++++ tests/config/strictness-ratchet.test.ts | 57 +++++++++++++ tsconfig.strict-indexed.json | 7 ++ tsconfig.strict-optional.json | 7 ++ vitest.config.ts | 3 + 10 files changed, 249 insertions(+) create mode 100644 .changelog/2697-strictness-spike.md create mode 100644 scripts/strictness-report.d.mts create mode 100644 scripts/strictness-report.mjs create mode 100644 tests/config/strictness-baseline.json create mode 100644 tests/config/strictness-ratchet.test.ts create mode 100644 tsconfig.strict-indexed.json create mode 100644 tsconfig.strict-optional.json diff --git a/.changelog/2697-strictness-spike.md b/.changelog/2697-strictness-spike.md new file mode 100644 index 000000000..3e74944d4 --- /dev/null +++ b/.changelog/2697-strictness-spike.md @@ -0,0 +1,5 @@ +--- +section: Added +--- + +- **Add a TypeScript strictness spike with scratch configs, per-directory counts, a two-sided ratchet, and an advisory report lane (refs #2697)** — the migration remains staged by directory instead of enabling either flag globally. diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cf0457ed5..01b408c9e 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -642,6 +642,30 @@ jobs: path: reports/complexity/complexity.md if-no-files-found: ignore + strictness: + name: strictness (advisory) + needs: validate-merge-train-dispatch + continue-on-error: true + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + with: + ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.sha || github.ref }} + persist-credentials: false + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v6 + with: + node-version: "22" + cache: npm + - name: Install dependencies + run: npm ci --ignore-scripts + - name: Generate strictness report + run: node scripts/strictness-report.mjs | tee strictness-report.txt + - name: Publish strictness report + if: always() + run: cat strictness-report.txt >> "$GITHUB_STEP_SUMMARY" + yamllint: name: yamllint (advisory) needs: validate-merge-train-dispatch diff --git a/scripts/strictness-report.d.mts b/scripts/strictness-report.d.mts new file mode 100644 index 000000000..1c68b3606 --- /dev/null +++ b/scripts/strictness-report.d.mts @@ -0,0 +1,15 @@ +export interface StrictnessResult { + config: string; + exitCode: number; + total: number; + counts: Record; +} + +export declare const REPORT_ROOTS: readonly string[]; +export declare function parseDiagnostics( + output: string, + repoRoot: string, +): Record; +export declare function runCheck(config: string, repoRoot?: string): StrictnessResult; +export declare function formatReport(summary: StrictnessResult[]): string; +export declare function main(argv?: string[]): void; diff --git a/scripts/strictness-report.mjs b/scripts/strictness-report.mjs new file mode 100644 index 000000000..f24f69fdb --- /dev/null +++ b/scripts/strictness-report.mjs @@ -0,0 +1,93 @@ +import { spawnSync } from "node:child_process"; +import { resolve, relative, sep } from "node:path"; + +export const REPORT_ROOTS = ["clients", "tools", "mcp", "scripts", "tests"]; + +function reportDirectory(file) { + const normalized = file.split(sep).join("/"); + const root = REPORT_ROOTS.find( + (candidate) => normalized === candidate || normalized.startsWith(`${candidate}/`), + ); + if (!root) return "other"; + const parts = normalized.split("/"); + const rootIndex = parts.indexOf(root); + const directoryParts = parts.slice(0, -1); + // Keep two directory levels below each configured root. This preserves + // useful runner/LSP buckets such as tests/clients/dispatch/runners. + return directoryParts.slice(rootIndex, rootIndex + 4).join("/") || root; +} + +export function parseDiagnostics(output, repoRoot) { + const counts = new Map(); + const diagnosticPattern = /^(.*)\((\d+),(\d+)\): error TS\d+/; + for (const line of String(output).split(/\r?\n/)) { + const match = diagnosticPattern.exec(line); + if (!match) continue; + const file = relative(repoRoot, resolve(repoRoot, match[1])); + const directory = reportDirectory(file); + counts.set(directory, (counts.get(directory) ?? 0) + 1); + } + return Object.fromEntries([...counts].sort(([a], [b]) => a.localeCompare(b))); +} + +export function runCheck(config, repoRoot = resolve(import.meta.dirname, "..")) { + const tsc = resolve(repoRoot, "node_modules/typescript/bin/tsc"); + const result = spawnSync(process.execPath, [tsc, "-p", config, "--noEmit", "--pretty", "false"], { + cwd: repoRoot, + encoding: "utf8", + }); + const output = `${result.stdout ?? ""}${result.stderr ?? ""}`; + return { + config, + exitCode: result.status ?? 1, + total: (output.match(/^.*\(\d+,\d+\): error TS\d+/gm) ?? []).length, + counts: parseDiagnostics(output, repoRoot), + }; +} + +function table(summary) { + const directories = new Set(summary.flatMap(({ counts }) => Object.keys(counts))); + const rows = [...directories].sort().map((directory) => + `| ${directory} | ${summary[0].counts[directory] ?? 0} | ${summary[1].counts[directory] ?? 0} |`, + ); + return [ + "| Directory | noUncheckedIndexedAccess | exactOptionalPropertyTypes |", + "|---|---:|---:|", + ...rows, + ].join("\n"); +} + +export function formatReport(summary) { + return [ + "# TypeScript strictness spike", + "", + table(summary), + "", + "## JSON summary", + "", + "```json", + JSON.stringify(summary, null, 2), + "```", + "", + ].join("\n"); +} + +export function main(argv = process.argv.slice(2)) { + const repoRoot = resolve(import.meta.dirname, ".."); + const configs = argv.length > 0 ? argv : [ + "tsconfig.strict-indexed.json", + "tsconfig.strict-optional.json", + ]; + const summary = configs.map((config) => runCheck(config, repoRoot)); + process.stdout.write(formatReport(summary)); + process.stdout.write(`\n${JSON.stringify(summary)}\n`); +} + +if (import.meta.url === `file://${process.argv[1]}`) { + try { + main(); + } catch (error) { + console.error(`strictness report unavailable: ${error.message}`); + } + process.exitCode = 0; +} diff --git a/tests/config/advisory-tool-workflow.test.ts b/tests/config/advisory-tool-workflow.test.ts index ed6e30fba..89a2694ba 100644 --- a/tests/config/advisory-tool-workflow.test.ts +++ b/tests/config/advisory-tool-workflow.test.ts @@ -25,6 +25,7 @@ const mutationWorkflow = yaml.load( const tools = [ ["complexity", "complexity (advisory)"], + ["strictness", "strictness (advisory)"], ["jscpd", "jscpd (advisory)"], ["yamllint", "yamllint (advisory)"], ["typos", "typos (advisory)"], diff --git a/tests/config/strictness-baseline.json b/tests/config/strictness-baseline.json new file mode 100644 index 000000000..a376b172c --- /dev/null +++ b/tests/config/strictness-baseline.json @@ -0,0 +1,37 @@ +{ + "tsconfig.strict-indexed.json": { + "clients": 468, + "clients/config-core": 18, + "clients/dispatch": 29, + "clients/dispatch/rules": 12, + "clients/dispatch/runners": 95, + "clients/dispatch/runners/utils": 3, + "clients/lsp": 42, + "clients/lsp/wait-policy": 1, + "clients/project-diagnostics/runner-adapters": 1, + "clients/redact": 16, + "clients/review-graph": 18, + "mcp": 1, + "scripts": 1, + "tools": 4 + }, + "tsconfig.strict-optional.json": { + "clients": 359, + "clients/config-core": 1, + "clients/dispatch": 18, + "clients/dispatch/facts": 1, + "clients/dispatch/runners": 32, + "clients/dispatch/runners/utils": 9, + "clients/dispatch/utils": 2, + "clients/installer": 25, + "clients/lsp": 57, + "clients/mcp": 6, + "clients/project-diagnostics": 3, + "clients/project-diagnostics/runner-adapters": 3, + "clients/redact": 2, + "clients/review-graph": 42, + "mcp": 10, + "scripts": 1, + "tools": 48 + } +} diff --git a/tests/config/strictness-ratchet.test.ts b/tests/config/strictness-ratchet.test.ts new file mode 100644 index 000000000..341e440ae --- /dev/null +++ b/tests/config/strictness-ratchet.test.ts @@ -0,0 +1,57 @@ +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; +import { describe, expect, it } from "vitest"; +import { + runCheck, + type StrictnessResult, +} from "../../scripts/strictness-report.mjs"; + +const ROOT = resolve(import.meta.dirname, "../.."); +const baseline = JSON.parse( + readFileSync(resolve(import.meta.dirname, "strictness-baseline.json"), "utf8"), +) as Record>; +const productionRoots = ["clients", "tools", "mcp", "scripts"]; + +function productionCounts(result: StrictnessResult) { + return Object.fromEntries( + Object.entries(result.counts).filter(([directory]) => + productionRoots.some( + (root) => directory === root || directory.startsWith(`${root}/`), + ), + ), + ); +} + +function compare(result: StrictnessResult, expected: Record) { + const actual = productionCounts(result); + const problems: string[] = []; + for (const directory of new Set([...Object.keys(actual), ...Object.keys(expected)])) { + const before = expected[directory] ?? 0; + const after = actual[directory] ?? 0; + if (after > before) + problems.push(`${directory}: regression (${before} -> ${after})`); + if (after < before) + problems.push( + `${directory}: ratchet down — lower the baseline (${before} -> ${after})`, + ); + } + return problems; +} + +describe("TypeScript strictness spike ratchets", () => { + it( + "pins both scratch configurations without permitting drift", + () => { + const results = [ + runCheck("tsconfig.strict-indexed.json", ROOT), + runCheck("tsconfig.strict-optional.json", ROOT), + ]; + for (const result of results) { + expect(result.exitCode).toBe(1); + expect(result.total).toBeGreaterThan(0); + expect(compare(result, baseline[result.config])).toEqual([]); + } + }, + 120_000, + ); +}); diff --git a/tsconfig.strict-indexed.json b/tsconfig.strict-indexed.json new file mode 100644 index 000000000..044f90c49 --- /dev/null +++ b/tsconfig.strict-indexed.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noUncheckedIndexedAccess": true, + "noEmit": true + } +} diff --git a/tsconfig.strict-optional.json b/tsconfig.strict-optional.json new file mode 100644 index 000000000..a9d249684 --- /dev/null +++ b/tsconfig.strict-optional.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "exactOptionalPropertyTypes": true, + "noEmit": true + } +} diff --git a/vitest.config.ts b/vitest.config.ts index 53c9807ec..5d3e0ecff 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -315,6 +315,9 @@ const lspSpawnHeavyInclude = [ // host. Sweep coverage for other members lives in this list; new entries must // carry a wall-clock budget assertion, not just slowness. const wallClockBudgetInclude = [ + // #2697: the strictness ratchet spawns two real tsc processes and waits for + // their wall-clock completion; keep its 120s budget in the quiet phase. + "tests/config/strictness-ratchet.test.ts", "tests/clients/biome-config-decorator-metadata.test.ts", "tests/clients/build-identity.test.ts", "tests/clients/cascade-turn-merge.test.ts",