The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 10:45 UTC
fix(scripts): check:changed compares forks against upstream, not a stale origin/main (#26122)
Co-authored-by: maria-rcks <maria@kuuro.net>
Tristan Knight committed
Oct 30, 2026 at 21:18 UTC
513bfbbaca87fb1f349c5841356e024fabc728b4
3 files changed
+138
-15
docs/operations/development.md
+2
-1
@@ -167,7 +167,8 @@ of the affected packages and their dependents, and the test files beside the cha
167
runs the checks that read other files: the agent context budget when the server is affected, and
168
React Compiler coverage for only the changed web and mobile files. It maps
169
files to packages with [ci-changes.cjs](../../.github/scripts/ci-changes.cjs), as CI does. It
170
-compares against the merge base with `origin/main`, or with a ref you pass. CI still runs the full
170
+compares against the closest merge base with any remote's `main`, so a fork whose `main` lags
171
+upstream still compares against upstream, or with a ref you pass. CI still runs the full
172
test suites and the jobs the summary lists, so a local pass does not promise a green CI run.
173
174
The steps run side by side, as many at once as the machine allows: one per two cores and per 6 GiB
scripts/check-changed.test.ts
+101
-2
@@ -1,13 +1,26 @@
1
+// @effect-diagnostics nodeBuiltinImport:off
2
+import * as NodeChildProcess from "node:child_process";
3
+import * as NodeFS from "node:fs";
4
+import * as NodeOS from "node:os";
5
+import * as NodePath from "node:path";
6
+import * as NodeServices from "@effect/platform-node/NodeServices";
7
+import * as Option from "effect/Option";
8
import { assert, describe, it } from "@effect/vitest";
9
import * as Clock from "effect/Clock";
10
import * as Effect from "effect/Effect";
11
import * as Fiber from "effect/Fiber";
12
import * as Sink from "effect/Sink";
13
import * as Stream from "effect/Stream";
7
-import { ChildProcessSpawner } from "effect/process";
14
+import { ChildProcess, ChildProcessSpawner } from "effect/process";
15
import * as TestClock from "effect/testing/TestClock";
16
10
-import { defaultConcurrency, gitLines, runSteps, type Step } from "./check-changed.ts";
17
+import {
18
+ comparisonBase,
19
+ defaultConcurrency,
20
+ gitLines,
21
+ runSteps,
22
+ type Step,
23
+} from "./check-changed.ts";
24
25
const GiB = 1024 ** 3;
26
@@ -152,3 +165,89 @@ describe("check:changed", () => {
165
});
166
});
167
});
168
+
169
+// Hooks export GIT_DIR and GIT_INDEX_FILE, and user config or the default
170
+// ~/.config/git/ignore can ignore or sign fixture files.
171
+const fixtureConfig = {
172
+ "core.excludesFile": NodeOS.devNull,
173
+ "user.name": "Fixture",
174
+ "user.email": "fixture@example.invalid",
175
+};
176
+const env = {
177
+ ...Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith("GIT_"))),
178
+ GIT_CONFIG_GLOBAL: NodeOS.devNull,
179
+ GIT_CONFIG_NOSYSTEM: "1",
180
+ GIT_CONFIG_COUNT: String(Object.keys(fixtureConfig).length),
181
+ ...Object.fromEntries(
182
+ Object.entries(fixtureConfig).flatMap(([key, value], index) => [
183
+ [`GIT_CONFIG_KEY_${index}`, key],
184
+ [`GIT_CONFIG_VALUE_${index}`, value],
185
+ ]),
186
+ ),
187
+};
188
+
189
+// History A -> B -> C, with HEAD at C. Each remote's main points at A or B.
190
+function fixture(remotes: Record<string, "A" | "B">) {
191
+ const root = NodeFS.realpathSync(
192
+ NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-check-changed-")),
193
+ );
194
+ const commits: Record<string, string> = {};
195
+ try {
196
+ const write = (file: string, content: string) => {
197
+ const path = NodePath.join(root, file);
198
+ NodeFS.mkdirSync(NodePath.dirname(path), { recursive: true });
199
+ NodeFS.writeFileSync(path, content);
200
+ };
201
+ const git = (...args: Array<string>) =>
202
+ NodeChildProcess.execFileSync("git", args, { cwd: root, encoding: "utf8", env }).trim();
203
+ git("init");
204
+ for (const name of ["A", "B", "C"]) {
205
+ write(`${name}.txt`, name);
206
+ git("add", ".");
207
+ git("commit", "-m", name);
208
+ commits[name] = git("rev-parse", "HEAD");
209
+ }
210
+ for (const [remote, commit] of Object.entries(remotes)) {
211
+ git("remote", "add", remote, NodePath.join(root, "missing"));
212
+ git("update-ref", `refs/remotes/${remote}/main`, commits[commit]!);
213
+ }
214
+ } catch (error) {
215
+ NodeFS.rmSync(root, { recursive: true, force: true });
216
+ throw error;
217
+ }
218
+ return {
219
+ commits,
220
+ root,
221
+ [Symbol.dispose]() {
222
+ NodeFS.rmSync(root, { recursive: true, force: true });
223
+ },
224
+ };
225
+}
226
+
227
+const compare = (root: string, ref: Option.Option<string>) =>
228
+ Effect.gen(function* () {
229
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
230
+ return yield* comparisonBase(root, ref).pipe(
231
+ Effect.provideService(
232
+ ChildProcessSpawner.ChildProcessSpawner,
233
+ ChildProcessSpawner.make((command) => spawner.spawn(ChildProcess.setEnv(command, env))),
234
+ ),
235
+ );
236
+ }).pipe(Effect.provide(NodeServices.layer), Effect.runPromise);
237
+
238
+it.each(["upstream", "team/upstream"])(
239
+ "compares against %s/main when the fork's origin/main lags it",
240
+ async (remote) => {
241
+ using project = fixture({ origin: "A", [remote]: "B" });
242
+ const result = await compare(project.root, Option.none());
243
+ assert.strictEqual(result.base, project.commits.B);
244
+ assert.strictEqual(result.ref, remote + "/main");
245
+ },
246
+);
247
+
248
+it("compares against an explicit ref instead of the closest remote main", async () => {
249
+ using project = fixture({ origin: "A", upstream: "B" });
250
+ const result = await compare(project.root, Option.some("origin/main"));
251
+ assert.strictEqual(result.base, project.commits.A);
252
+ assert.strictEqual(result.ref, "origin/main");
253
+});
scripts/check-changed.ts
+35
-12
@@ -7,7 +7,7 @@
7
// A dependency change also gets the unused-patch install check below. CI still
8
// runs the full test suites and the jobs listed in the summary.
9
//
10
-// vp run check:changed compare against the merge base with origin/main
10
+// vp run check:changed compare against the closest merge base with any remote main
11
// vp run check:changed <ref> compare against the merge base with <ref>
12
// vp run check:changed --concurrency 1 run the steps one at a time
13
//
@@ -142,6 +142,35 @@ export const git = Effect.fn("checkChanged.git")(function* (
142
export const gitLines = (cwd: string, args: ReadonlyArray<string>) =>
143
git(cwd, args).pipe(Effect.map((stdout) => stdout.toString().split("\n").filter(Boolean)));
144
145
+export const comparisonBase = Effect.fn("checkChanged.comparisonBase")(function* (
146
+ root: string,
147
+ explicitRef: Option.Option<string>,
148
+) {
149
+ const candidates = Option.isSome(explicitRef)
150
+ ? [{ ref: explicitRef.value, rev: explicitRef.value }]
151
+ : (yield* gitLines(root, ["remote"])).map((name) => ({
152
+ ref: name + "/main",
153
+ rev: "refs/remotes/" + name + "/main",
154
+ }));
155
+ let closest: { ref: string; base: string; ahead: number } | undefined;
156
+ for (const { ref, rev } of candidates) {
157
+ const base = yield* git(root, ["merge-base", "HEAD", rev]).pipe(
158
+ Effect.map((stdout) => stdout.toString().trim()),
159
+ Effect.orElseSucceed(() => undefined),
160
+ );
161
+ if (!base) continue;
162
+ const ahead = Number((yield* git(root, ["rev-list", "--count", base + "..HEAD"])).toString());
163
+ if (!closest || ahead < closest.ahead) closest = { ref, base, ahead };
164
+ }
165
+ if (!closest) {
166
+ const tried = candidates.map(({ ref }) => ref).join(", ") || "a remote main";
167
+ return yield* Effect.fail(
168
+ "check:changed: no merge base with " + tried + ". Run git fetch or pass a ref.",
169
+ );
170
+ }
171
+ return closest;
172
+});
173
+
174
const CODE = /\.[cm]?[jt]sx?$/;
175
const TEST = /\.test\.[cm]?[jt]sx?$/;
176
const escapeRegExp = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
@@ -162,7 +191,7 @@ const override = Effect.fn("checkChanged.override")(function* (
191
});
192
193
const checkChanged = Effect.fn("checkChanged")(function* (input: {
165
- readonly ref: string;
194
+ readonly ref: Option.Option<string>;
195
readonly concurrency: Option.Option<number>;
196
readonly timeout: Option.Option<number>;
197
}) {
@@ -190,23 +219,17 @@ const checkChanged = Effect.fn("checkChanged")(function* (input: {
219
220
const lines = (...args: Array<string>) => gitLines(root, args);
221
193
- const base = yield* git(root, ["merge-base", "HEAD", input.ref]).pipe(
194
- Effect.map((stdout) => stdout.toString().trim()),
195
- Effect.mapError(
196
- () =>
197
- `check:changed: no merge base with ${input.ref}. Run \`git fetch origin\` or pass a ref.`,
198
- ),
199
- );
222
+ const { ref, base } = yield* comparisonBase(root, input.ref);
223
// --no-renames lists a rename as its old and new path, as CI does.
224
const changedFiles = lines("diff", "--name-only", "--no-renames", base, "--");
225
const untrackedFiles = lines("ls-files", "--others", "--exclude-standard");
226
const files = [...new Set([...(yield* changedFiles), ...(yield* untrackedFiles)])].sort();
227
228
if (files.length === 0) {
206
- yield* Console.log(`check:changed: no changes since ${base.slice(0, 12)}.`);
229
+ yield* Console.log(`check:changed: no changes since ${base.slice(0, 12)} (${ref}).`);
230
return true;
231
}
209
- yield* Console.log(`check:changed: ${files.length} files since ${base.slice(0, 12)}`);
232
+ yield* Console.log(`check:changed: ${files.length} files since ${base.slice(0, 12)} (${ref})`);
233
234
// Ignored generated sources, declarations, env files, and install state affect check results.
235
// Include them in the key, but skip large ignored folders that no check reads.
@@ -521,7 +544,7 @@ export const checkChangedCommand = Command.make(
544
{
545
ref: Argument.String("ref").pipe(
546
Argument.withDescription("Compare against the merge base with this ref."),
524
- Argument.withDefault("origin/main"),
547
+ Argument.optional,
548
),
549
concurrency: Flag.Int("concurrency").pipe(
550
Flag.withDescription(