diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 543c258392..12052456bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -496,6 +496,8 @@ jobs: id: npm-cache uses: ./.github/actions/npm-cache - run: npm ci + - name: Require mutation targets in the checker projects + run: npm run verify:mutation-targets - name: Reuse portable build outputs across runs uses: ./.github/actions/portable-build-cache - name: Run reverse tools tests with coverage diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index bfa679a2fb..d5fa974964 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -24,7 +24,8 @@ jobs: mutation: name: Mutation sweep (${{ matrix.suite }}) runs-on: ubuntu-latest - timeout-minutes: 60 + # The complete reverse-tools sweep hit the previous 60-minute job limit. + timeout-minutes: 90 strategy: fail-fast: false max-parallel: 2 @@ -43,6 +44,8 @@ jobs: - name: Cache npm package downloads uses: ./.github/actions/npm-cache - run: npm ci + - name: Require mutation targets in the checker projects + run: npm run verify:mutation-targets - name: Reuse portable build outputs across runs uses: ./.github/actions/portable-build-cache - run: npm run test:prepare diff --git a/docs/development/testing.md b/docs/development/testing.md index 62508fb98b..14dc6a364f 100644 --- a/docs/development/testing.md +++ b/docs/development/testing.md @@ -1260,19 +1260,21 @@ Required CI retains fresh reverse-tools coverage and preflights both canonical Stryker configurations with `--dryRunOnly`. These preflights resolve the owned targets, instrument the source, and execute the real initial tests. Invalid configuration, target resolution, and initial test failures still fail the job. +Before the dry runs, the mutation project guard checks that each suite’s resolved +targets are root files in its configured TypeScript project. Preflights execute no mutants and produce no mutation-outcome report. Both fast feedback and full qualification, including exact-revision release qualification, require coverage and both preflights. A failed, canceled, skipped or missing selected quality job still fails the required gate. The separate **Mutation sweep** workflow runs both complete configurations daily -and on manual dispatch, in two isolated jobs. It is a maintenance check outside -the PR and release publication gates. `ci:full` requests full regression, +and on manual dispatch. Each isolated job has a 90-minute budget. The sweep runs +outside the PR and release publication gates. `ci:full` requests full regression, coverage and provider qualification; it does not request a complete mutation -sweep. Use the Mutation sweep workflow to request that result. Targets, -checkers, concurrency, deadlines and the existing non-blocking mutation-score -threshold are unchanged. `npm run test:mutation:reverse-tools` also retains both -complete passes for local callers. +sweep. Use the Mutation sweep workflow to request that result. Both jobs use the +canonical configurations, including their per-mutant timeouts and non-blocking +mutation-score thresholds. `npm run test:mutation:reverse-tools` runs both +complete passes locally. The two passes write separate JSON and HTML reports under `reports/mutation/`: `reverse-tools` and `reverse-tools-semantics`. Required CI retains focused diff --git a/package.json b/package.json index 46dd52a4ef..cf6306929e 100644 --- a/package.json +++ b/package.json @@ -139,7 +139,7 @@ "precheck:test": "npm run deps:check", "check:test": "node scripts/run-exclusive.mjs artifacts node scripts/run-turbo.mjs run typecheck lint format:check knip metadata:check test:run", "precheck:pr": "npm run deps:check", - "check:pr": "node scripts/run-exclusive.mjs artifacts node scripts/run-turbo.mjs run typecheck lint format:check knip metadata:check test:run && npm run test:python && npm run docs:check && npm run jscpd && npm run scan:todos && npm run knip:production && npm run lint:typed", + "check:pr": "npm run verify:mutation-targets && node scripts/run-exclusive.mjs artifacts node scripts/run-turbo.mjs run typecheck lint format:check knip metadata:check test:run && npm run test:python && npm run docs:check && npm run jscpd && npm run scan:todos && npm run knip:production && npm run lint:typed", "precheck:ci": "npm run deps:check", "precheck:ci:fast": "npm run deps:check", "precheck:ci:deep:job": "npm run deps:check", @@ -147,7 +147,7 @@ "check:ci:fast": "node scripts/run-exclusive.mjs artifacts npm run check:ci:fast:tasks", "check:ci:fast:tasks": "node scripts/run-turbo.mjs run typecheck lint format:check", "check:ci:deep": "npm run verify:architecture-guards && npm run check:ci:deep:job", - "check:ci:deep:job": "node scripts/run-exclusive.mjs artifacts npm run check:ci:deep:tasks && npm run verify:test-discovery && npm run test:python && npm run knip:production && npm run lint:typed", + "check:ci:deep:job": "npm run verify:mutation-targets && node scripts/run-exclusive.mjs artifacts npm run check:ci:deep:tasks && npm run verify:test-discovery && npm run test:python && npm run knip:production && npm run lint:typed", "check:ci:deep:tasks": "node scripts/run-turbo.mjs run knip metadata:check jscpd scan:todos", "ci:static-context": "node scripts/ci/static-task-context.mjs", "build:cached": "node scripts/check-dependency-install.mjs && node scripts/run-exclusive.mjs artifacts node scripts/run-turbo.mjs run artifacts:skills", @@ -185,7 +185,7 @@ "test:coverage:reverse-tools": "vitest run --config vitest.reverse-tools.config.ts --coverage.enabled", "pretest:coverage:reverse-tools": "npm run test:prepare", "test:mutation:reverse-tools": "node scripts/prepare-reverse-tools-mutation.mjs && stryker run stryker.config.mjs && stryker run stryker.semantics.config.mjs", - "pretest:mutation:reverse-tools": "npm run test:prepare", + "pretest:mutation:reverse-tools": "npm run verify:mutation-targets && npm run test:prepare", "test:ci": "npm run test:coverage -- --reporter=default --reporter=junit --outputFile.junit=test-results.xml", "pretest:ci:shard": "npm run test:prepare", "test:ci:shard": "npm run test:ci:shard:run", @@ -210,6 +210,7 @@ "verify:legacy-simulator": "npm run build:cached && node scripts/verify/apple/legacy-simulator.mjs", "verify:node-sea": "npm run build:cached && node scripts/verify-node-sea.mjs", "verify:architecture-guards": "node scripts/verify/architecture-guards.mjs", + "verify:mutation-targets": "node scripts/verify/mutation-target-tsconfig.mjs", "verify:apktool": "npm run build:cached && node scripts/verify-apktool.mjs", "verify:pcap": "npm run build:cached && node scripts/verify-pcap.mjs", "verify:pe:load-config": "npm run build:cached && node scripts/verify-pe-load-config.mjs", diff --git a/scripts/ci/scopes.mjs b/scripts/ci/scopes.mjs index 19850e8d0e..b7ec6ed025 100644 --- a/scripts/ci/scopes.mjs +++ b/scripts/ci/scopes.mjs @@ -97,6 +97,7 @@ const PATH_SCOPES = { "src/application/reverse/**", "src/application/binary/BinarySession.ts", "src/cutter/**", + "src/domain/analysisResourceLimits.ts", "src/gdb/**", "src/frida/frida-bindings.d.ts", "src/objdump/**", @@ -150,6 +151,7 @@ const PATH_SCOPES = { "stryker.semantics.config.mjs", "tsconfig.reverse-tools-mutation.json", "scripts/prepare-reverse-tools-mutation.mjs", + "scripts/verify/mutation-target-tsconfig.mjs", "scripts/lib/reverse-tools-mutation-targets.mjs", ], // Apple artifact CLI/MCP lane on macOS, including its focused regressions. diff --git a/scripts/verify/mutation-target-tsconfig.mjs b/scripts/verify/mutation-target-tsconfig.mjs new file mode 100644 index 0000000000..4e654aafbc --- /dev/null +++ b/scripts/verify/mutation-target-tsconfig.mjs @@ -0,0 +1,89 @@ +import { dirname, relative, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +import ts from "typescript6"; + +const rootUrl = new URL("../../", import.meta.url); +const root = fileURLToPath(rootUrl); +const configNames = ["stryker.config.mjs", "stryker.semantics.config.mjs"]; +const projectFiles = new Map(); +const failures = []; +const diagnosticsHost = { + getCanonicalFileName: (path) => path, + getCurrentDirectory: ts.sys.getCurrentDirectory, + getNewLine: () => ts.sys.newLine, +}; + +// Stryker's range selectors read source paths relative to the repository. +process.chdir(root); + +const fileKey = (path) => + ts.sys.useCaseSensitiveFileNames ? path : path.toLowerCase(); + +for (const configName of configNames) { + const { default: config } = await import(new URL(configName, rootUrl).href); + if (typeof config.tsconfigFile !== "string" || !config.tsconfigFile) + throw new Error(`${configName} must name a TypeScript checker project`); + + const projectPath = resolve(root, config.tsconfigFile); + const projectName = relative(root, projectPath); + if (!projectFiles.has(projectPath)) { + const project = ts.getParsedCommandLineOfConfigFile( + projectPath, + {}, + { + ...ts.sys, + onUnRecoverableConfigFileDiagnostic: (diagnostic) => { + throw new Error(ts.formatDiagnostic(diagnostic, diagnosticsHost)); + }, + }, + ); + if (project.errors.length > 0) + throw new Error(ts.formatDiagnostics(project.errors, diagnosticsHost)); + + // TypeScript silently drops unmatched include entries. Require literal paths + // in this project to exist while allowing globs and directory includes. + for (const entry of project.raw.include ?? []) { + const path = resolve(dirname(projectPath), entry); + if ( + !/[*?]/u.test(entry) && + !ts.sys.fileExists(path) && + !ts.sys.directoryExists(path) + ) + failures.push(`${projectName} has a missing include entry: ${entry}`); + } + projectFiles.set( + projectPath, + new Set(project.fileNames.map((path) => fileKey(resolve(path)))), + ); + } + + // A transitive import can be in the program without a Stryker file watcher. + // Check the compiler's root file list. Both configs emit concrete line ranges. + const targets = new Set( + config.mutate.map((target) => { + const match = /^(.+):\d+-\d+$/u.exec(target); + if (!match) + throw new Error( + `${configName} has an unreadable mutation target: ${target}`, + ); + return match[1]; + }), + ); + const files = projectFiles.get(projectPath); + for (const target of [...targets].sort()) { + if (!files.has(fileKey(resolve(root, target)))) + failures.push( + `${configName} requires ${target} as a root file in ${projectName}`, + ); + } +} + +if (failures.length > 0) { + console.error(`Mutation project guard failed:\n${failures.join("\n")}\n`); + process.exitCode = 1; +} else { + console.log( + `Mutation project guard passed for ${configNames.length} configurations.`, + ); +} diff --git a/tests/boundary/filesystem/ciChangeScope.test.ts b/tests/boundary/filesystem/ciChangeScope.test.ts index 723574666a..a4d03b157e 100644 --- a/tests/boundary/filesystem/ciChangeScope.test.ts +++ b/tests/boundary/filesystem/ciChangeScope.test.ts @@ -10,9 +10,10 @@ import { rm, writeFile, } from "node:fs/promises"; -import { dirname, join, matchesGlob } from "node:path"; +import { dirname, join, matchesGlob, relative, sep } from "node:path"; import { fileURLToPath } from "node:url"; +import ts from "typescript6"; import { afterAll, beforeAll, expect, it as sequentialIt } from "vitest"; import { parse } from "yaml"; import { z } from "zod"; @@ -830,6 +831,7 @@ it.each([ "stryker.semantics.config.mjs", "tsconfig.reverse-tools-mutation.json", "scripts/prepare-reverse-tools-mutation.mjs", + "scripts/verify/mutation-target-tsconfig.mjs", "scripts/lib/reverse-tools-mutation-targets.mjs", ])( "selects the reverse-tool coverage and mutation gate for %s", @@ -856,17 +858,24 @@ const reverseToolsVitestInputs = ( ([, path]) => path!.replace(/^\.\//u, ""), ), ); -const reverseToolsMutationConfig = JSON.parse( - await readFile( - new URL("../../../tsconfig.reverse-tools-mutation.json", import.meta.url), - "utf8", - ), -) as { include: string[] }; +const reverseToolsRoot = fileURLToPath(new URL("../../../", import.meta.url)); +const reverseToolsMutationConfig = ts.getParsedCommandLineOfConfigFile( + join(reverseToolsRoot, "tsconfig.reverse-tools-mutation.json"), + {}, + { + ...ts.sys, + onUnRecoverableConfigFileDiagnostic: (diagnostic) => { + throw new Error( + ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"), + ); + }, + }, +)!; const reverseToolsInputs = [ ...new Set([ ...reverseToolsVitestInputs, - ...reverseToolsMutationConfig.include.map((path) => - path.replace(/^\.\//u, ""), + ...reverseToolsMutationConfig.fileNames.map((path) => + relative(reverseToolsRoot, path).split(sep).join("/"), ), ]), ]; diff --git a/tests/boundary/filesystem/ciFeedback.test.ts b/tests/boundary/filesystem/ciFeedback.test.ts index 929b1c11e4..2a61ff478a 100644 --- a/tests/boundary/filesystem/ciFeedback.test.ts +++ b/tests/boundary/filesystem/ciFeedback.test.ts @@ -182,13 +182,19 @@ it.each(["fast", "full"] as const)( (command) => command.includes("mutation") || command.includes("stryker"), ); expect(mutationCommands).toEqual([ + "npm run verify:mutation-targets", "node scripts/prepare-reverse-tools-mutation.mjs", "npx --no-install stryker run stryker.config.mjs --dryRunOnly", "npx --no-install stryker run stryker.semantics.config.mjs --dryRunOnly", ]); + const guard = commands.indexOf("npm run verify:mutation-targets"); const coverage = commands.indexOf("npm run test:coverage:reverse-tools"); - expect(coverage).toBeGreaterThanOrEqual(0); - expect(coverage).toBeLessThan(commands.indexOf(mutationCommands[0]!)); + const preflight = commands.indexOf( + "node scripts/prepare-reverse-tools-mutation.mjs", + ); + expect(guard).toBeGreaterThanOrEqual(0); + expect(coverage).toBeGreaterThan(guard); + expect(preflight).toBeGreaterThan(coverage); const flags = await scopeFlags(); const context: Record< diff --git a/tests/boundary/filesystem/reverseToolsMutationConfig.test.ts b/tests/boundary/filesystem/reverseToolsMutationConfig.test.ts index 113fb910d1..e04ba19c44 100644 --- a/tests/boundary/filesystem/reverseToolsMutationConfig.test.ts +++ b/tests/boundary/filesystem/reverseToolsMutationConfig.test.ts @@ -1,7 +1,8 @@ -import { execFileSync } from "node:child_process"; -import { writeFile } from "node:fs/promises"; +import { execFile, execFileSync } from "node:child_process"; +import { copyFile, mkdir, symlink, writeFile } from "node:fs/promises"; import { join, resolve } from "node:path"; import { fileURLToPath, pathToFileURL } from "node:url"; +import { promisify } from "node:util"; import { describe, expect, it } from "vitest"; import { z } from "zod"; @@ -58,6 +59,67 @@ describe("reverse-tools mutation configuration", () => { ); }); + it("checks each configured project's roots and reports stale includes", async () => { + const temporary = await createTestTempDirectory("rea-mutation-project-"); + const directory = join(temporary, "checkout#1"); + const verifier = join( + directory, + "scripts/verify/mutation-target-tsconfig.mjs", + ); + const project = join(directory, "semantics.json"); + await mkdir(join(directory, "scripts/verify"), { recursive: true }); + await copyFile( + join(root, "scripts/verify/mutation-target-tsconfig.mjs"), + verifier, + ); + await symlink( + join(root, "node_modules"), + join(directory, "node_modules"), + process.platform === "win32" ? "junction" : "dir", + ); + await Promise.all([ + writeFile( + join(directory, "stryker.config.mjs"), + 'export default { tsconfigFile: "base.json", mutate: ["main.ts:1-1"] };', + ), + writeFile( + join(directory, "stryker.semantics.config.mjs"), + 'export default { tsconfigFile: "semantics.json", mutate: ["target.ts:1-1"] };', + ), + writeFile( + join(directory, "base.json"), + '{"files":["main.ts","target.ts"]}', + ), + writeFile(join(directory, "main.ts"), 'import "./target.js";'), + writeFile(join(directory, "target.ts"), "export const value = 1;"), + ]); + + const verify = () => + promisify(execFile)(process.execPath, [verifier], { + cwd: root, + encoding: "utf8", + }); + await writeFile( + project, + '{ // TypeScript accepts JSONC.\n "include": ["./target.*"] }', + ); + await expect(verify()).resolves.toMatchObject({ stderr: "" }); + + await writeFile( + project, + JSON.stringify({ + include: ["main.ts", "target.ts", "retired.ts"], + exclude: ["target.ts"], + }), + ); + await expect(verify()).rejects.toMatchObject({ + code: 1, + stderr: expect.stringMatching( + /semantics\.json has a missing include entry: retired\.ts[\s\S]*stryker\.semantics\.config\.mjs requires target\.ts as a root file in semantics\.json/u, + ), + }); + }); + it("fails closed when an owned mutation method is missing", async () => { const directory = await createTestTempDirectory("rea-mutation-selector-"); const source = join(directory, "source.ts"); diff --git a/tsconfig.reverse-tools-mutation.json b/tsconfig.reverse-tools-mutation.json index ae6ed4d872..173b7332c0 100644 --- a/tsconfig.reverse-tools-mutation.json +++ b/tsconfig.reverse-tools-mutation.json @@ -6,6 +6,7 @@ "src/cli/reverseEngineeringCommands.ts", "src/cutter/CutterBridgeClient.ts", "src/cutter/CutterBridgeService.ts", + "src/domain/analysisResourceLimits.ts", "src/gdb/GdbSessionManager.ts", "src/objdump/ObjdumpCommand.ts", "src/process/ownedDebuggerSession.ts", @@ -14,6 +15,8 @@ "src/server/serviceToolBindings.ts", "src/server/createServer.ts", "src/rizin/RizinCommand.ts", + "src/rizin/RizinDebugEvidence.ts", + "src/rizin/RizinDebugFrames.ts", "src/rizin/RizinDebugSessionManager.ts", "tests/boundary/providers/GdbSessionManagerCoverage.test.ts", "tests/boundary/mcp/rizinPendingOutput.test.ts",