From bc27535dfab68ee133638e6fc7fb4766eaaf0308 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Wed, 18 Nov 2026 07:26:46 +0800 Subject: [PATCH] chore(ci): retire completed Incur migration guards (#11894) --- scripts/verify/architecture-guards.mjs | 27 ----- scripts/verify/incur-import-guard.d.mts | 2 - scripts/verify/incur-import-guard.mjs | 112 ------------------ .../boundary/filesystem/ciChangeScope.test.ts | 2 +- tests/evaluation/incurImportGuard.test.ts | 68 ----------- 5 files changed, 1 insertion(+), 210 deletions(-) delete mode 100644 scripts/verify/incur-import-guard.d.mts delete mode 100644 scripts/verify/incur-import-guard.mjs delete mode 100644 tests/evaluation/incurImportGuard.test.ts diff --git a/scripts/verify/architecture-guards.mjs b/scripts/verify/architecture-guards.mjs index a7bd2035c3..591574dd97 100644 --- a/scripts/verify/architecture-guards.mjs +++ b/scripts/verify/architecture-guards.mjs @@ -9,10 +9,6 @@ import { } from "./counted-baseline.mjs"; import { localCompletenessEnumCount } from "./completeness-enum-guard.mjs"; import { countKeyedFirstMatches } from "./keyed-first-match.mjs"; -import { - incurImportedNameCount, - incurZodImportCount, -} from "./incur-import-guard.mjs"; import { budgetArithmeticCount } from "./budget-arithmetic-guard.mjs"; import { localLimitErrorClassCount } from "./limit-class-guard.mjs"; import { countDefaultValidationClients } from "./mcp-client-validation.mjs"; @@ -937,18 +933,6 @@ checkCounted( [], ); -// Schemas import zod directly. incur's `z` is a re-export of the same package; -// importing it through the CLI framework ties schemas to a dependency REA is -// removing (#11654). Declarations are read from code tokens, so the text in a -// comment or string fixture does not count. -checkCounted( - 'zod imported through incur (import { z } from "zod")', - "incur-zod-reexport", - [...files, ...testFiles], - (_content, file) => incurZodImportCount(file.source ?? file.content), - [], -); - // Every CLI command is registered through src/cli/commandRegistry.ts, which // records it in REA's command table (name, inputs, contract operations and // their flags) before handing it to the dispatcher (#11654). A direct @@ -961,17 +945,6 @@ checkCounted( ["src/cli/commandRegistry.ts"], ); -// REA is replacing incur with its own CLI owners (#11654). Each replacement -// removes the names it superseded; this counted list only shrinks until incur -// leaves package.json. -checkCounted( - "name imported from incur (use REA's CLI owner in src/cli)", - "incur-import", - [...files, ...testFiles], - (_content, file) => incurImportedNameCount(file.source ?? file.content), - [], -); - // `find` on a parsed section, program-header or load-command table silently // keeps the first of repeated declarations. Select keyed entries through // src/domain/keyedCollection (`uniqueKeyed`, `allKeyed`, or diff --git a/scripts/verify/incur-import-guard.d.mts b/scripts/verify/incur-import-guard.d.mts deleted file mode 100644 index fc95d91699..0000000000 --- a/scripts/verify/incur-import-guard.d.mts +++ /dev/null @@ -1,2 +0,0 @@ -export function incurZodImportCount(source: string): number; -export function incurImportedNameCount(source: string): number; diff --git a/scripts/verify/incur-import-guard.mjs b/scripts/verify/incur-import-guard.mjs deleted file mode 100644 index 13909980d5..0000000000 --- a/scripts/verify/incur-import-guard.mjs +++ /dev/null @@ -1,112 +0,0 @@ -// Reads the bindings that import and re-export declarations take from incur: -// named (`import { Cli, type Help } from "incur"`, `export { z } from 'incur'`), -// default, namespace (`import * as Incur from "incur"`), star re-exports -// (`export * from "incur"`), side-effect imports and dynamic `import("incur")`. -// Declarations are read from code tokens, so the same text in a comment, -// string or template is not counted. -import { tokenize } from "./source-tokens.mjs"; - -const isIncurSpecifier = (source, token) => - token?.kind === "string" && - (source.startsWith('"incur"', token.start) || - source.startsWith("'incur'", token.start)); - -/** - * Read `{ a, type b, c as d }` starting at the `{` token. - * @returns {{ names: string[], end: number } | undefined} imported names and - * the index after `}` - */ -const namedBindings = (tokens, open) => { - const names = []; - let expectName = true; - let at = open + 1; - for (; at < tokens.length && tokens[at].text !== "}"; at += 1) { - const token = tokens[at]; - if (token.text === ",") expectName = true; - // In `{ z as zod }` the imported name is z; in `{ type Cli }`, Cli. - else if ( - expectName && - token.kind === "id" && - !(token.text === "type" && tokens[at + 1]?.kind === "id") - ) { - names.push(token.text); - expectName = false; - } - } - return at < tokens.length ? { names, end: at + 1 } : undefined; -}; - -/** - * The bindings of the declaration whose `import` or `export` keyword is at - * `index`, or undefined when it does not take anything from incur. - * @returns {string[] | undefined} - */ -const incurBindings = (source, tokens, index) => { - let at = index + 1; - // `import("incur")` and `import "incur"` bind nothing by name. - if (tokens[index].text === "import" && tokens[at]?.text === "(") - return isIncurSpecifier(source, tokens[at + 1]) ? ["import()"] : undefined; - if (tokens[index].text === "import" && tokens[at]?.kind === "string") - return isIncurSpecifier(source, tokens[at]) ? ["import"] : undefined; - if (tokens[at]?.kind === "id" && tokens[at].text === "type") at += 1; - const names = []; - // A default import may precede a named or namespace clause. - if ( - tokens[index].text === "import" && - tokens[at]?.kind === "id" && - tokens[at].text !== "from" - ) { - names.push("default"); - at += 1; - if (tokens[at]?.text !== ",") return finish(source, tokens, at, names); - at += 1; - } - if (tokens[at]?.text === "*") { - names.push("*"); - at += 1; - if (tokens[at]?.kind === "id" && tokens[at].text === "as") at += 2; - } else if (tokens[at]?.text === "{") { - const named = namedBindings(tokens, at); - if (named === undefined) return undefined; - names.push(...named.names); - at = named.end; - } else if (names.length === 0) return undefined; - return finish(source, tokens, at, names); -}; - -const finish = (source, tokens, at, names) => - tokens[at]?.text === "from" && isIncurSpecifier(source, tokens[at + 1]) - ? names - : undefined; - -/** - * The bindings of each declaration that takes something from incur. - * @param {string} source - * @returns {string[][]} - */ -const incurDeclarations = (source) => { - const { tokens } = tokenize(source); - const declarations = []; - for (let index = 0; index < tokens.length; index += 1) { - const keyword = tokens[index]; - if ( - keyword.kind !== "id" || - (keyword.text !== "import" && keyword.text !== "export") - ) - continue; - const bindings = incurBindings(source, tokens, index); - if (bindings !== undefined) declarations.push(bindings); - } - return declarations; -}; - -/** Declarations that take zod's `z` from incur. @param {string} source */ -export const incurZodImportCount = (source) => - incurDeclarations(source).filter((names) => names.includes("z")).length; - -/** - * Bindings taken from incur: one per named binding, and one for each default, - * namespace, star, side-effect or dynamic import. @param {string} source - */ -export const incurImportedNameCount = (source) => - incurDeclarations(source).reduce((count, names) => count + names.length, 0); diff --git a/tests/boundary/filesystem/ciChangeScope.test.ts b/tests/boundary/filesystem/ciChangeScope.test.ts index e67fc48f5d..f471667453 100644 --- a/tests/boundary/filesystem/ciChangeScope.test.ts +++ b/tests/boundary/filesystem/ciChangeScope.test.ts @@ -559,7 +559,7 @@ it("routes license inventories to docs checks and keeps blame-ignore edits forma for (const staticOnly of [ "scripts/lib/module-layers.baseline.json", "scripts/verify/architecture-guards.mjs", - "scripts/verify/baselines/incur-import.json", + "scripts/verify/baselines/raw-buffer-read.json", "tsconfig.scripts.json", ]) { expect(await classifyPaths([staticOnly]), staticOnly).toMatchObject({ diff --git a/tests/evaluation/incurImportGuard.test.ts b/tests/evaluation/incurImportGuard.test.ts deleted file mode 100644 index 900320f885..0000000000 --- a/tests/evaluation/incurImportGuard.test.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { expect, it } from "vitest"; -import { - incurImportedNameCount, - incurZodImportCount, -} from "../../scripts/verify/incur-import-guard.mjs"; - -it("counts every name a declaration takes from incur", () => { - expect(incurImportedNameCount('import { Cli } from "incur";')).toBe(1); - expect( - incurImportedNameCount( - 'import { Errors, type MiddlewareHandler } from "incur";', - ), - ).toBe(2); - expect(incurImportedNameCount("import type { Cli as C } from 'incur';")).toBe( - 1, - ); - expect( - incurImportedNameCount( - 'import { Help } from "incur";\nexport { Filter } from "incur";', - ), - ).toBe(2); - expect(incurImportedNameCount('import { Help } from "./help.js";')).toBe(0); - expect(incurImportedNameCount('// import { Help } from "incur";')).toBe(0); -}); - -it("counts namespace, default, star, side-effect and dynamic imports", () => { - expect(incurImportedNameCount('import * as Incur from "incur";')).toBe(1); - expect(incurImportedNameCount('import type * as I from "incur";')).toBe(1); - expect(incurImportedNameCount('import incur from "incur";')).toBe(1); - expect(incurImportedNameCount('import incur, { Help } from "incur";')).toBe( - 2, - ); - expect(incurImportedNameCount('import incur, * as I from "incur";')).toBe(2); - expect(incurImportedNameCount('export * from "incur";')).toBe(1); - expect(incurImportedNameCount('export * as Incur from "incur";')).toBe(1); - expect(incurImportedNameCount('import "incur";')).toBe(1); - expect(incurImportedNameCount('const m = await import("incur");')).toBe(1); - expect(incurImportedNameCount('import * as Zod from "zod";')).toBe(0); - expect(incurImportedNameCount("export const from = 1;")).toBe(0); - expect(incurImportedNameCount('const u = import.meta.url; "incur";')).toBe(0); -}); - -it("counts declarations that take z from incur in every spelling", () => { - expect(incurZodImportCount('import { z } from "incur";')).toBe(1); - expect(incurZodImportCount("import type { z } from 'incur';")).toBe(1); - expect(incurZodImportCount('import { Cli, type z } from "incur";')).toBe(1); - expect(incurZodImportCount('import { z as zod } from "incur";')).toBe(1); - expect(incurZodImportCount('export { z } from "incur";')).toBe(1); - expect( - incurZodImportCount( - 'import {\n Cli,\n z,\n} from "incur";\nconst a = 1;', - ), - ).toBe(1); -}); - -it("ignores other names, other modules and non-declaration text", () => { - expect(incurZodImportCount('import { Cli } from "incur";')).toBe(0); - expect(incurZodImportCount('import { schema as z } from "incur";')).toBe(0); - expect(incurZodImportCount('import { z } from "zod";')).toBe(0); - expect(incurZodImportCount('// import { z } from "incur";')).toBe(0); - expect(incurZodImportCount('/* import { z } from "incur"; */')).toBe(0); - expect( - incurZodImportCount("const fixture = 'import { z } from \"incur\";';"), - ).toBe(0); - expect( - incurZodImportCount('const fixture = `\nimport { z } from "incur";\n`;'), - ).toBe(0); -});