Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/using-diffci.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ For `Unknown changed file` and `Deleted source/asset`, `observe --json` also ret
| `Infrastructure definition(s) changed; full validation required` | Edit a `Dockerfile` or `terraform/main.tf` | Yes: declare it in `inputs` |
| `Database definition(s) changed; full validation required` | Add a file under `migrations/` | Yes: declare it in `inputs` |
| `Language/framework configuration changed: …` | Edit `go.mod` or `pom.xml` | No |
| `Tool configuration changed: … (…); full validation required` | Change `.nvmrc`, `.node-version` or `.npmrc` | No |
| `Tool configuration changed: … (…); full validation required` | Change `.nvmrc`, `.node-version`, `.npmrc`, `tsconfig.base.json` or `tsconfig.test.json` | No |
| `Unknown changed file: …` | Change a file type no adapter models, such as `data.bin` read at runtime | Yes: declare it in `inputs` |
| `Infrastructure code … is outside the dependency graph; full validation required` | Edit a script under `ops/` that no test imports | Yes: declare it in `inputs` |
| `Lockfile readers could not be resolved: …; full validation required` | Change `yarn.lock` while repository code reads it in a way DiffCI cannot trace | No |
Expand Down
1 change: 1 addition & 0 deletions release-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@
"tests/repo/test-fixture-ownership.test.ts",
"tests/repo/test-framework.test.ts",
"tests/repo/tool-config-reasons.test.ts",
"tests/repo/tsconfig-variant-reason.test.ts",
"tests/repo/tsconfig-newer-options.test.ts",
"tests/repo/vite-config-change.test.ts",
"tests/repo/vitest-config-fallback.test.ts",
Expand Down
6 changes: 6 additions & 0 deletions src/git/git-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ export const CONFIG_PATTERNS = [
/^next\.config\./,
/^tsconfig\.json$/,
/^jsconfig\.json$/,
// `tsconfig.base.json`, `tsconfig.test.json`, `jsconfig.build.json`: monorepos keep shared options in
// the first and projects carry per-target variants of the rest (issue #141). Deliberately narrower
// than type-program.ts's `tsconfig[^/]*\.json`, which would also match the package name
// `tsconfig-paths.json`.
/^tsconfig\.[^/]+\.json$/,
/^jsconfig\.[^/]+\.json$/,
/^eslint\.config\./,
/^\.eslint/,
/^postcss\.config\./,
Expand Down
1 change: 1 addition & 0 deletions src/repo/impact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function toolConfigurationSubject(filePath: string): string | undefined {
const base = posix.basename(filePath);
if (base === ".nvmrc" || base === ".node-version") return "Node version";
if (base === ".npmrc") return "package manager settings";
if (/^tsconfig\.[^/]+\.json$/.test(base) || /^jsconfig\.[^/]+\.json$/.test(base)) return "TypeScript configuration";
return undefined;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/repo/config-patterns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const EXAMPLES = [
"next.config.mjs",
"tsconfig.json",
"jsconfig.json",
"tsconfig.base.json",
"jsconfig.test.json",
"eslint.config.js",
".eslintrc.json",
"postcss.config.cjs",
Expand Down Expand Up @@ -63,7 +65,7 @@ CONFIG_PATTERNS.forEach((pattern, i) => {
});
});

for (const name of ["eslint.rc", "npm-lock.json", "yarn-lock.yaml"]) {
for (const name of ["eslint.rc", "npm-lock.json", "yarn-lock.yaml", "tsconfig-paths.json"]) {
test(`no entry matches ${name}, which no tool reads`, () => {
assert.ok(!CONFIG_PATTERNS.some((pattern) => pattern.test(name)));
});
Expand Down
119 changes: 119 additions & 0 deletions tests/repo/tsconfig-variant-reason.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// SPDX-License-Identifier: MIT
/**
* `tsconfig.*.json` and `jsconfig.*.json` variants (issue #141).
*
* `tsconfig.json` changes were already configuration; a change to only `tsconfig.base.json` (extended by
* `tsconfig.json`, as monorepos do) or a standalone `tsconfig.test.json` fell back with
* `Unknown changed file: <path>`. Running everything is right — a compiler configuration decides every
* file's types — but the reason read like a gap in DiffCI, so each is now named:
* `Tool configuration changed: TypeScript configuration (tsconfig.base.json); full validation required`.
*
* The patterns are deliberately narrower than `type-program.ts`'s `tsconfig[^/]*\.json`: `tsconfig-paths.json`
* is a package name, not a project configuration, and must stay unknown.
*/
import assert from "node:assert/strict";
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 { test } from "node:test";
import { analyzeCheckout } from "../../src/analyze.js";

const TESTS = ["src/math.test.ts", "src/text.test.ts"];

const STRICT = JSON.stringify({
compilerOptions: { strict: true, target: "es2022", module: "esnext", moduleResolution: "bundler" },
include: ["src/**/*"],
});
const LOOSE = JSON.stringify({
compilerOptions: { strict: false, target: "es2022", module: "esnext", moduleResolution: "bundler" },
include: ["src/**/*"],
});

function tsProject(extra: Record<string, string>): Record<string, string> {
return {
"package.json": JSON.stringify({
name: "ts-config-fixture",
scripts: { test: "vitest" },
devDependencies: { vitest: "3.0.0" },
}),
"tsconfig.json": STRICT,
...extra,
"src/math.ts": "export const add = (a: number, b: number) => a + b;\n",
"src/math.test.ts": "import { add } from './math';\ntest('add', () => expect(add(1, 2)).toBe(3));\n",
"src/text.ts": "export const shout = (s: string) => s.toUpperCase();\n",
"src/text.test.ts": "import { shout } from './text';\ntest('shout', () => expect(shout('a')).toBe('A'));\n",
};
}

async function planForChange(files: Record<string, string>, changedPath: string, changedContent: string) {
const root = mkdtempSync(join(tmpdir(), "diffci-tsconfig-"));
try {
const git = (...args: string[]) =>
execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
git("init");
git("config", "user.name", "Core Test");
git("config", "user.email", "test@example.invalid");
git("config", "commit.gpgsign", "false");
for (const [path, content] of Object.entries(files)) {
mkdirSync(dirname(join(root, path)), { recursive: true });
writeFileSync(join(root, path), content);
}
git("add", ".");
git("commit", "-m", "base");
const base = git("rev-parse", "HEAD");
writeFileSync(join(root, changedPath), changedContent);
git("add", ".");
git("commit", "-m", `change ${changedPath}`);
const head = git("rev-parse", "HEAD");
return (await analyzeCheckout({ repoPath: root, base, head })).plan;
} finally {
rmSync(root, { recursive: true, force: true });
}
}

// The issue's two cases, plus a jsconfig variant.
for (const file of ["tsconfig.base.json", "tsconfig.test.json", "jsconfig.test.json"]) {
test(`a change to only ${file} runs every test and names it as TypeScript configuration`, async () => {
const plan = await planForChange(tsProject({ [file]: LOOSE }), file, STRICT);
assert.equal(plan.mode, "FULL");
assert.equal(plan.safety.fallbackRequired, true);
assert.deepEqual([...plan.selectedTests].sort(), TESTS);
assert.deepEqual(plan.skippedTests, []);
assert.ok(
plan.fallbackReasons.some(
(text) => text.startsWith("Tool configuration changed: TypeScript configuration") && text.includes(file),
),
plan.fallbackReasons.join("; "),
);
assert.ok(
!plan.fallbackReasons.some((text) => text.includes(`Unknown changed file: ${file}`)),
`still reported as unknown: ${plan.fallbackReasons.join("; ")}`,
);
});
}

// The root `tsconfig.json` keeps its original reason: the generic configuration sentence covers it, and
// this change must not move it.
test("a change to only tsconfig.json keeps the general configuration reason", async () => {
const plan = await planForChange(tsProject({}), "tsconfig.json", LOOSE);
assert.equal(plan.mode, "FULL");
assert.ok(
plan.fallbackReasons.some((text) => text.startsWith("Configuration file(s) changed")),
plan.fallbackReasons.join("; "),
);
assert.ok(
!plan.fallbackReasons.some((text) => text.startsWith("Tool configuration changed: TypeScript configuration")),
plan.fallbackReasons.join("; "),
);
});

// A name the pattern must not match: `tsconfig-paths.json` is a package's config file, not a project one.
test("tsconfig-paths.json stays unknown", async () => {
const plan = await planForChange(tsProject({ "tsconfig-paths.json": "x\n" }), "tsconfig-paths.json", "y\n");
assert.equal(plan.mode, "FULL");
assert.ok(
plan.fallbackReasons.some((text) => text.includes("Unknown changed file: tsconfig-paths.json")),
plan.fallbackReasons.join("; "),
);
});
Loading