diff --git a/docs/design/config-narrowing.md b/docs/design/config-narrowing.md new file mode 100644 index 00000000..821be6f7 --- /dev/null +++ b/docs/design/config-narrowing.md @@ -0,0 +1,43 @@ +# Design: narrowing config-only changes + +Status: candidate (2026-10-30). Not implemented. Today every edit to a file in `CONFIG_PATTERNS` +(`src/git/git-diff.ts`) sets `configChanged`, raises `CONFIG_GLOBAL` and forces the full suite. + +## Why + +On a replay of one production app's history, DiffCI fell back to the full suite on 58% of commits, +mostly because a config, `package.json`, workflow or lockfile change forced it to (issue #53). +Narrowing those safely is the main open problem. + +## Candidate: Vitest reporter or timeout edits + +A common agent edit to `vitest.config.*` only adds a reporter or changes `testTimeout`. Neither +changes which test files Vitest collects, so in principle the selection for the rest of the diff +could stand. + +`tests/repo/vitest-config-fallback.test.ts` records today's behaviour for both edits on a synthetic +repository: `configChanged=true`, `CONFIG_GLOBAL`, `fallbackRequired=true`. A narrowing change must +update that test deliberately, not by accident. + +## Safety rules + +Narrow only when all of these hold; otherwise keep the full fallback: + +- Both the old and the new config are statically recognizable (a literal `defineConfig({...})` or + plain object export). Computed, imported or conditional configs keep the fallback. +- The only changed field is on a short allowlist of fields known not to affect selection. +- Test inclusion is provably identical before and after: `include`, `exclude`, `dir`, `root`, + `projects`/workspace files, `setupFiles`, `globalSetup` and the CI invocation of the runner. +- Any field not on the allowlist, or not understood, keeps the fallback. + +Even allowlisted fields are not free: + +- A custom reporter is code and can have side effects or fail the run. Only built-in reporter names + qualify. +- A shorter `testTimeout` can turn a passing test into a failing one in tests DiffCI did not select. + Lowering it should keep the fallback; raising it is the safer direction. + +The fixture does not execute Vitest, and passing it does not show that any config change is safe. + +Thanks to robertwmccarty-caelum for the fixture and the narrowing conditions +([issue comment](https://github.com/DiffCI/core/issues/53#issuecomment-6514436312)). diff --git a/release-files.json b/release-files.json index bd49919c..3c45d232 100644 --- a/release-files.json +++ b/release-files.json @@ -197,6 +197,7 @@ "tests/repo/test-discovery.test.ts", "tests/repo/test-fixture-ownership.test.ts", "tests/repo/test-framework.test.ts", + "tests/repo/vitest-config-fallback.test.ts", "tests/repo/vue-scope.test.ts", "tests/repo/workspaces.test.ts", "tests/research/baseline/matcher.test.ts", @@ -222,6 +223,7 @@ "packages/diffci-cli/src/client/hook.ts", "packages/diffci-cli/tests/client/agent-default-path.test.ts", "docs/design/affected-checks.md", + "docs/design/config-narrowing.md", "docs/design/pipeline-impact.md", "docs/research/2026-10-28-seeded-regression-plan.md", "docs/research/2026-10-28-fallback-replay.md", diff --git a/tests/repo/vitest-config-fallback.test.ts b/tests/repo/vitest-config-fallback.test.ts new file mode 100644 index 00000000..cd1bfcb7 --- /dev/null +++ b/tests/repo/vitest-config-fallback.test.ts @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: MIT +// Regression fixture for issue #53: a non-selection Vitest config edit still falls back. +import { strict as assert } from "node:assert"; +import { execFileSync } from "node:child_process"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join } from "node:path"; +import { describe, it } from "node:test"; +import { analyzeGitDelta } from "../../src/git/git-diff.js"; +import { buildDependencyGraph } from "../../src/repo/graph.js"; +import { ImpactAnalyzer } from "../../src/repo/impact.js"; +import { repositoryFileReader } from "../../src/repo/file-references.js"; + +function write(root: string, path: string, content: string): void { + const full = join(root, path); + mkdirSync(dirname(full), { recursive: true }); + writeFileSync(full, content); +} +function git(root: string, ...args: string[]): string { + return execFileSync("git", args, { cwd: root, encoding: "utf8" }).trim(); +} +const config = (reporter: string, timeout: number) => + "import { defineConfig } from 'vitest/config';\n" + + "export default defineConfig({ test: { include: ['src/**/*.test.ts'], " + + "reporters: ['" + reporter + "'], testTimeout: " + timeout + " } });\n"; + +describe("Vitest config-only changes: conservative fallback (#53)", () => { + for (const testCase of [ + { name: "reporter-only", changed: config("verbose", 5000) }, + { name: "timeout-only", changed: config("default", 10000) }, + ]) { + it(testCase.name + " edit still requests the full test suite", async () => { + const root = mkdtempSync(join(tmpdir(), "diffci-vitest-config-")); + try { + git(root, "init", "--quiet"); + git(root, "config", "user.email", "fixture@diffci.local"); + git(root, "config", "user.name", "DiffCI fixture"); + write(root, "package.json", JSON.stringify({ + name: "vitest-config-fixture", private: true, type: "module", + scripts: { test: "vitest run" }, devDependencies: { vitest: "^3.0.0" }, + })); + write(root, "src/adder.ts", "export const add = (a: number, b: number) => a + b;\n"); + write(root, "src/adder.test.ts", + "import { test, expect } from 'vitest';\n" + + "import { add } from './adder';\n" + + "test('adds', () => expect(add(1, 2)).toBe(3));\n"); + write(root, "vitest.config.ts", config("default", 5000)); + git(root, "add", "-A"); + git(root, "commit", "--quiet", "-m", "baseline"); + const baseSha = git(root, "rev-parse", "HEAD"); + write(root, "vitest.config.ts", testCase.changed); + git(root, "add", "-A"); + git(root, "commit", "--quiet", "-m", testCase.name); + const headSha = git(root, "rev-parse", "HEAD"); + + const analyzed = await analyzeGitDelta({ repoPath: root, baseSha, headSha }); + assert.equal(analyzed.success, true); + if (!analyzed.success) return; + const delta = analyzed.delta; + assert.deepEqual(delta.files.map((f) => f.path), ["vitest.config.ts"]); + assert.equal(delta.analysis.configChanged, true); + assert.deepEqual(delta.analysis.signalPaths?.config, ["vitest.config.ts"]); + + const graph = await buildDependencyGraph({ repoPath: root, excludeDirs: [".git", "node_modules"] }); + const impact = new ImpactAnalyzer().analyze(delta, graph, graph.profile, { + repositoryFiles: analyzed.inventory?.files, + readRepositoryFile: repositoryFileReader(root), + }); + assert.equal(impact.fallbackRequired, true); + assert.ok(impact.riskSignals.some((s) => s.reason === "CONFIG_GLOBAL")); + assert.ok(impact.fallbackReasons.some((r) => /Configuration file\(s\) changed/.test(r))); + } finally { + rmSync(root, { recursive: true, force: true }); + } + }); + } +});