mirror of
https://github.com/apmantza/pi-lens.git
synced 2026-11-23 15:21:07 +08:00
ci(strictness): spike — scratch configs, per-directory report, two-sided ratchet, advisory lane (refs #2697)
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013gEp548mWcf8nWL9xivZWV
This commit is contained in:
1 parent
d26d4a92ec
commit
3fbe4b38d8
10 files changed
+249
No files matched your search
@@ -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.
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
export interface StrictnessResult {
|
||||
config: string;
|
||||
exitCode: number;
|
||||
total: number;
|
||||
counts: Record<string, number>;
|
||||
}
|
||||
|
||||
export declare const REPORT_ROOTS: readonly string[];
|
||||
export declare function parseDiagnostics(
|
||||
output: string,
|
||||
repoRoot: string,
|
||||
): Record<string, number>;
|
||||
export declare function runCheck(config: string, repoRoot?: string): StrictnessResult;
|
||||
export declare function formatReport(summary: StrictnessResult[]): string;
|
||||
export declare function main(argv?: string[]): void;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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)"],
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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<string, Record<string, number>>;
|
||||
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<string, number>) {
|
||||
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,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noUncheckedIndexedAccess": true,
|
||||
"noEmit": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"exactOptionalPropertyTypes": true,
|
||||
"noEmit": true
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user