Skip to content

Commit 317fa31

Browse files
committed
fix(test): anchor changed mode at merge base
1 parent 8301b6c commit 317fa31

11 files changed

Lines changed: 127 additions & 45 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ it binds you regardless of which mechanism is within reach.
163163
```bash
164164
bun install
165165
bun run typecheck # bun x tsc --noEmit (strict)
166-
bun run test:changed # tests whose import graph touches the diff against `dev`
166+
bun run test:changed # import-graph tests against the resolved `dev` merge base
167167
bun run test # full tests/ suite (PR-ready / explicit ask only)
168168
bun run lint:gui # GUI eslint
169169
bun run privacy:scan # credential/privacy scan used by CI

‎docs-site/src/content/docs/contributing.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ scripts so local commands match CI:
3030

3131
```bash
3232
bun run typecheck # strict TypeScript check
33-
bun run test:changed # import-graph tests against the resolved dev ref
33+
bun run test:changed # import-graph tests against the resolved dev merge base
3434
bun run test # complete tests/ suite (PR-ready / explicit ask)
3535
bun test tests/router.test.ts # focused test file
3636
bun run build:gui # Vite GUI build + package preparation
3737
bun run privacy:scan # credential/privacy scan used by CI
3838
bun run prepare:package # refresh package launchers/assets
3939
```
4040

41-
`test:changed` reports and uses the first comparison ref that exists, in order:
42-
`upstream/dev`, `origin/dev`, then local `dev`.
41+
`test:changed` selects the first comparison ref that exists, in order: `upstream/dev`,
42+
`origin/dev`, then local `dev`. It reports that ref and the exact `git merge-base HEAD <ref>`
43+
commit, then passes the merge-base SHA to Bun.
4344

4445
Most tests are flat `tests/*.test.ts` Bun tests. `tests/helpers/` contains shared fixtures and
4546
`tests/e2e-style/` contains broader native-parity scenarios. Keep a focused regression near the

‎docs-site/src/content/docs/fr/contributing.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ distincte. Utilisez les scripts enregistrés afin que les commandes locales corr
3030

3131
```bash
3232
bun run typecheck # strict TypeScript check
33-
bun run test:changed # tests liés par le graphe d’import à la ref dev résolue
33+
bun run test:changed # tests liés au merge-base dev résolu
3434
bun run test # complete tests/ suite (PR-ready / explicit ask)
3535
bun test tests/router.test.ts # focused test file
3636
bun run build:gui # Vite GUI build + package preparation
3737
bun run privacy:scan # credential/privacy scan used by CI
3838
bun run prepare:package # refresh package launchers/assets
3939
```
4040

41-
`test:changed` indique et utilise la première ref de comparaison existante, dans cet ordre :
42-
`upstream/dev`, `origin/dev`, puis la ref locale `dev`.
41+
`test:changed` choisit la première ref de comparaison existante, dans cet ordre : `upstream/dev`,
42+
`origin/dev`, puis la ref locale `dev`. Il indique cette ref et le commit exact obtenu par
43+
`git merge-base HEAD <ref>`, puis transmet le SHA du merge-base à Bun.
4344

4445
La plupart des tests Bun sont des fichiers plats `tests/*.test.ts`. `tests/helpers/` contient les fixtures
4546
partagées et `tests/e2e-style/` des scénarios plus larges de parité native. Placez une régression ciblée près

‎docs-site/src/content/docs/ja/contributing.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bun run test # 全体スイート (PR review-ready / 明示
2828

2929
```bash
3030
bun run typecheck # 厳密な TypeScript 検査
31-
bun run test:changed # 解決済み dev ref の差分に import graph でつながるテスト
31+
bun run test:changed # 解決済み dev merge-base との差分テスト
3232
bun run test # tests/ の全体スイート (PR review-ready / 明示時)
3333
bun test tests/router.test.ts # 特定テストファイル
3434
bun run build:gui # Vite GUI ビルド + パッケージ準備
@@ -37,7 +37,8 @@ bun run prepare:package # パッケージランチャー/asset 更新
3737
```
3838

3939
`test:changed` は、`upstream/dev`、`origin/dev`、ローカルの `dev` の順に最初に存在する
40-
比較 ref を使用し、その ref を出力します。
40+
比較 ref を選びます。その ref と `git merge-base HEAD <ref>` で得た正確な commit を出力し、
41+
merge-base の SHA を Bun に渡します。
4142

4243
ほとんどのテストは `tests/*.test.ts` に並んで配置された Bun テストです。共有 fixture は
4344
`tests/helpers/`、範囲の広いネイティブ等価性シナリオは `tests/e2e-style/` にあります。変更した

‎docs-site/src/content/docs/ko/contributing.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bun run test # 전체 스위트 (PR review-ready / 명시
2828

2929
```bash
3030
bun run typecheck # 엄격한 TypeScript 검사
31-
bun run test:changed # 결정된 dev ref의 diff와 import graph로 연결된 테스트
31+
bun run test:changed # 결정된 dev merge-base와 연결된 테스트
3232
bun run test # tests/ 전체 스위트 (PR review-ready / 명시 요청 시)
3333
bun test tests/router.test.ts # 특정 테스트 파일
3434
bun run build:gui # Vite GUI 빌드 + 패키지 준비
@@ -37,7 +37,8 @@ bun run prepare:package # 패키지 런처/asset 갱신
3737
```
3838

3939
`test:changed`는 `upstream/dev`, `origin/dev`, 로컬 `dev` 순으로 처음 존재하는 비교 ref를
40-
사용하고 그 ref를 출력합니다.
40+
선택합니다. 그 ref와 `git merge-base HEAD <ref>`로 구한 정확한 commit을 출력하고,
41+
merge-base SHA를 Bun에 전달합니다.
4142

4243
대부분의 테스트는 `tests/*.test.ts`에 나란히 놓인 Bun 테스트입니다. 공용 fixture는
4344
`tests/helpers/`, 범위가 넓은 네이티브 동등성 시나리오는 `tests/e2e-style/`에 있습니다. 바꾼

‎docs-site/src/content/docs/ru/contributing.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ bun run test # полный набор (PR review-ready /
2727

2828
```bash
2929
bun run typecheck # строгая проверка TypeScript
30-
bun run test:changed # тесты, связанные с diff выбранной dev-ref
30+
bun run test:changed # тесты относительно выбранной dev merge-base
3131
bun run test # полный набор tests/ (PR review-ready / явная просьба)
3232
bun test tests/router.test.ts # отдельный тестовый файл
3333
bun run build:gui # сборка GUI на Vite + подготовка пакета
3434
bun run privacy:scan # проверка учётных данных/приватности, используемая в CI
3535
bun run prepare:package # обновление лаунчеров/ресурсов пакета
3636
```
3737

38-
`test:changed` сообщает и использует первую существующую ref для сравнения в порядке:
39-
`upstream/dev`, `origin/dev`, затем локальную `dev`.
38+
`test:changed` выбирает первую существующую ref для сравнения в порядке: `upstream/dev`,
39+
`origin/dev`, затем локальную `dev`. Команда сообщает эту ref и точный commit из
40+
`git merge-base HEAD <ref>`, после чего передаёт SHA merge-base в Bun.
4041

4142
Большинство тестов — плоские Bun-тесты `tests/*.test.ts`. В `tests/helpers/` лежат общие fixtures,
4243
а в `tests/e2e-style/` — более широкие сценарии нативного паритета. Добавляйте сфокусированный

‎docs-site/src/content/docs/tr/contributing.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Yerel komutların CI ile eşleşmesi için depodaki betikleri kullanın:
3434

3535
```bash
3636
bun run typecheck # katı TypeScript denetimi
37-
bun run test:changed # çözümlenen dev ref farkına import grafiğiyle bağlı testler
37+
bun run test:changed # çözümlenen dev merge-base farkına bağlı testler
3838
bun run test # tests/ paketinin tamamı (PR review-ready / açık istek)
3939
bun test tests/router.test.ts # odaklanmış test dosyası
4040
bun run build:gui # Vite GUI derlemesi + paket hazırlığı
@@ -43,7 +43,8 @@ bun run prepare:package # paket başlatıcılarını ve varlıkların
4343
```
4444

4545
`test:changed`, karşılaştırma için sırasıyla `upstream/dev`, `origin/dev`, ardından yerel `dev`
46-
ref'lerinden var olan ilkini kullanır ve çıktıda bildirir.
46+
ref'lerinden var olan ilkini seçer. Bu ref'i ve `git merge-base HEAD <ref>` ile bulunan kesin
47+
commit'i bildirir, ardından merge-base SHA'sını Bun'a geçirir.
4748

4849
Testlerin çoğu düz `tests/*.test.ts` Bun testleridir. `tests/helpers/`
4950
paylaşılan test ortamlarını (fixtures) ve `tests/e2e-style/` daha geniş yerel

‎docs-site/src/content/docs/zh-cn/contributing.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ bun run test # 完整 suite(PR review-ready / 明确要
2727

2828
```bash
2929
bun run typecheck # 严格 TypeScript 检查
30-
bun run test:changed # 通过 import graph 与已解析 dev ref 的 diff 关联的测试
30+
bun run test:changed # 针对已解析 dev merge-base 的 import graph 测试
3131
bun run test # 完整 tests/ suite(PR review-ready / 明确要求时)
3232
bun test tests/router.test.ts # 聚焦单个测试文件
3333
bun run build:gui # Vite GUI 构建 + package 准备
3434
bun run privacy:scan # CI 使用的 credential/privacy 扫描
3535
bun run prepare:package # 刷新 package launcher/asset
3636
```
3737

38-
`test:changed` 会按 `upstream/dev`、`origin/dev`、本地 `dev` 的顺序使用第一个实际存在的
39-
比较 ref,并在输出中报告该 ref。
38+
`test:changed` 会按 `upstream/dev`、`origin/dev`、本地 `dev` 的顺序选择第一个实际存在的
39+
比较 ref,并报告该 ref 及 `git merge-base HEAD <ref>` 得到的精确 commit,然后把 merge-base
40+
SHA 传给 Bun。
4041

4142
大多数测试是平铺在 `tests/*.test.ts` 下的 Bun test。`tests/helpers/` 存放共享 fixture,
4243
`tests/e2e-style/` 存放范围更广的原生一致性场景。请在对应 subsystem 的现有测试附近加入聚焦的

‎docs-site/src/content/docs/zh-tw/contributing.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ bun run test # 完整 suite(PR review-ready / 明確要
2727

2828
```bash
2929
bun run typecheck # 嚴格 TypeScript 檢查
30-
bun run test:changed # 透過 import graph 與已解析 dev ref 的 diff 關聯的測試
30+
bun run test:changed # 針對已解析 dev merge-base 的 import graph 測試
3131
bun run test # 完整 tests/ suite(PR review-ready / 明確要求時)
3232
bun test tests/router.test.ts # 聚焦單個測試檔案
3333
bun run build:gui # Vite GUI 建置 + package 準備
3434
bun run privacy:scan # CI 使用的 credential/privacy 掃描
3535
bun run prepare:package # 重新整理 package launcher/asset
3636
```
3737

38-
`test:changed` 會依 `upstream/dev`、`origin/dev`、本機 `dev` 的順序使用第一個實際存在的
39-
比較 ref,並在輸出中回報該 ref。
38+
`test:changed` 會依 `upstream/dev`、`origin/dev`、本機 `dev` 的順序選擇第一個實際存在的
39+
比較 ref,並回報該 ref 與 `git merge-base HEAD <ref>` 得到的精確 commit,再把 merge-base
40+
SHA 傳給 Bun。
4041

4142
大多數測試是平鋪在 `tests/*.test.ts` 下的 Bun test。`tests/helpers/` 存放共享 fixture,
4243
`tests/e2e-style/` 存放範圍更廣的原生一致性場景。請在對應 subsystem 的現有測試附近加入聚焦的

‎scripts/test.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ const BUN_TEST_OPTIONS_REQUIRING_VALUES = new Set([
140140

141141
export interface ChangedRunPreflight {
142142
comparisonRef: string;
143+
comparisonCommit: string;
143144
changedFiles: string[];
144145
}
145146

@@ -220,25 +221,22 @@ export function inspectChangedRun(
220221
);
221222
}
222223

223-
const resolved = Bun.spawnSync(
224-
["git", "rev-parse", "--verify", "--quiet", `${comparisonRef}^{commit}`],
225-
{ cwd, env, stdout: "pipe", stderr: "pipe" },
226-
);
227-
if (resolved.exitCode !== 0) {
224+
if (!gitRefExists(comparisonRef, cwd, env)) {
228225
throw new Error(
229226
`[test] --changed comparison ref ${JSON.stringify(comparisonRef)} does not resolve to a commit.`,
230227
);
231228
}
232-
const comparisonCommit = decodeOutput(resolved.stdout).trim();
229+
230+
const comparisonCommit = gitOutput(["merge-base", "HEAD", comparisonRef], cwd, env).trim();
233231
if (!comparisonCommit) {
234232
throw new Error(
235-
`[test] --changed comparison ref ${JSON.stringify(comparisonRef)} resolved without a commit id.`,
233+
`[test] --changed comparison ref ${JSON.stringify(comparisonRef)} has no merge base with HEAD.`,
236234
);
237235
}
238236

239237
const diff = gitOutput(["diff", "--name-only", comparisonCommit, "--"], cwd, env);
240238
const changedFiles = [...new Set(diff.split("\n").filter(Boolean))];
241-
return { comparisonRef, changedFiles };
239+
return { comparisonRef, comparisonCommit, changedFiles };
242240
}
243241

244242
/** Refuse a successful changed-mode run when Bun silently selected no tests for a real diff. */
@@ -251,10 +249,10 @@ export function changedSelectionFailure(
251249
.replace(/\u001B\[[0-?]*[ -/]*[@-~]/g, "")
252250
.match(/Ran\s+(\d+)\s+tests?\s+across\s+(\d+)\s+files?\b/i);
253251
if (!summary) {
254-
return `[test] could not validate --changed=${preflight.comparisonRef}: Bun did not emit a recognizable selection summary for a diff containing ${preflight.changedFiles.length} changed file(s).`;
252+
return `[test] could not validate --changed=${preflight.comparisonCommit} (${preflight.comparisonRef} merge base): Bun did not emit a recognizable selection summary for a diff containing ${preflight.changedFiles.length} changed file(s).`;
255253
}
256254
if (Number(summary[1]) !== 0 || Number(summary[2]) !== 0) return null;
257-
return `[test] --changed=${preflight.comparisonRef} selected 0 tests across 0 files, but the diff contains ${preflight.changedFiles.length} changed file(s). Bun follows only the parsed module graph; run the relevant focused tests for subprocess, read-as-data, or golden-file dependencies, or run the full suite.`;
255+
return `[test] --changed=${preflight.comparisonCommit} (${preflight.comparisonRef} merge base) selected 0 tests across 0 files, but the diff contains ${preflight.changedFiles.length} changed file(s). Bun follows only the parsed module graph; run the relevant focused tests for subprocess, read-as-data, or golden-file dependencies, or run the full suite.`;
258256
}
259257

260258
/**
@@ -288,12 +286,12 @@ function isFullSuiteRun(requested: string[]): boolean {
288286
*/
289287
export function resolveBunTestArgs(
290288
requested: string[],
291-
resolvedChangedRef?: string,
289+
comparisonCommit?: string,
292290
): string[] {
293-
const effectiveRequested = resolvedChangedRef
291+
const effectiveRequested = comparisonCommit
294292
? requested.map(arg => (
295293
arg === "--changed" || arg.startsWith("--changed=")
296-
? `--changed=${resolvedChangedRef}`
294+
? `--changed=${comparisonCommit}`
297295
: arg
298296
))
299297
: requested;
@@ -393,15 +391,17 @@ async function main(): Promise<number> {
393391
return 1;
394392
}
395393
if (changedRun) {
396-
console.log(`[test] changed mode comparison ref: ${changedRun.comparisonRef}`);
394+
console.log(
395+
`[test] changed mode comparison ref: ${changedRun.comparisonRef}; merge base: ${changedRun.comparisonCommit}`,
396+
);
397397
}
398398
await waitForExclusiveRun(process.pid);
399399
const startedAt = Date.now();
400400
const child = Bun.spawnSync(
401401
[
402402
process.execPath,
403403
"test",
404-
...resolveBunTestArgs(requestedTests, changedRun?.comparisonRef),
404+
...resolveBunTestArgs(requestedTests, changedRun?.comparisonCommit),
405405
],
406406
{
407407
env: isolated.env,

0 commit comments

Comments
 (0)