Skip to content

[PR] test(update): pin describeInstallLocation fixture to a resolved tmpdir path (#2068) - #2069

Closed
ranxianglei wants to merge 1 commit into
masterfrom
2026-10-04_fix-macos-tmpdir-flake
Closed

ranxianglei wants to merge 1 commit into
masterfrom
2026-10-04_fix-macos-tmpdir-flake

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

tests/update-install-dir.test.ts — the describeInstallLocation case failed deterministically on macOS: the fixture is built under mkdtempSync(path.join(tmpdir(), ...)), and on macOS tmpdir() (/var/folders/...) is itself a symlink to /private/var/folders/.... The implementation resolves the target with realpathSync and emits real= whenever resolved ≠ given — so the "plain, not-a-symlink" fixture case reported real=… and assert.doesNotMatch(plain, /real=/) (line 131) failed. The test exercises package-symlink detection but was confounded by an OS-level tmpdir symlink — the §7.2 "environmental luck" class (#360).

Fix

One-line test change: const base = realpathSync(mkdtempSync(path.join(tmpdir(), "bc-installdir-"))) in the affected test, so the given path and its resolved form are identical on every platform. A comment pins why the wrapper exists so it doesn't get "simplified" back. No production code touched.

Scope check: the other 6 tests in the file compare literal paths against each other (findPackageRoot never realpaths), so they are unaffected by a symlinked tmpdir — verified by running the whole file under both conditions.

Verification

Reproduced the exact failure signature on Linux by pointing TMPDIR at a symlinked directory (the same condition macOS creates natively):

  • before fix: not ok - describeInstallLocation … expected to not match /real=/ with target=<via-symlink> real=<resolved>
  • after fix: 7/7 pass under symlinked TMPDIR and under plain TMPDIR
  • npm run typecheck clean

Full suite/build left to CI (test-only change).

Behavior changes

None. Test-only; no config surface, no wire, no defaults.

Closes #2068

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-04_fix-macos-tmpdir-flake (025cf43)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2110-pr.2069.f65853a

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr2069.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #2069 Review — 可合并 ✅

结论先行:test-only 单文件修复(+4/−1),已本地 A/B 复现并验证、typecheck 干净、CI 全绿。方向正确、无回归、无行为变更、无新配置。建议合并(按规范由人工执行合并)。

七问:

  1. 是什么问题:tests/update-install-dir.test.ts 的 describeInstallLocation 用例在 macOS 上确定性失败。属「环境运气」类测试 flake(fix: emit /acp panel as persistent custom message and strip it from the proxy model context (#359) #360 同类),不是生产缺陷——fixture 建在未解析的 tmpdir() 下,而 macOS 的 tmpdir()(/var/folders/…)本身是指向 /private/var/folders/… 的符号链接,于是本该"非链接"的 plain 用例被 OS 层链接污染,describeInstallLocation 如实打出 real=,顶掉了 assert.doesNotMatch(plain, /real=/)(line 131)。

  2. 什么原因导致的:根因在测试 fixture,不在实现。实现(src/update.ts:344 describeInstallLocation)合法地对入参做 realpathSync,凡 resolved≠given 就追加 real=;fixture 用 mkdtempSync(path.join(tmpdir(),…)) 未解析路径,macOS 在 tmpdir 根部天然引入一次链接跳转 → given≠resolved。分层:表面现象是断言失败,病因是 fixture 基址未解析。

  3. 怎么修复的:把 tmpdir 预先解析——const base = realpathSync(mkdtempSync(…)),使各平台下 given==resolved。真正的断言 doesNotMatch(/real=/) 原样保留、未弱化;symlink 子用例仍验证真链接会打出 real=;另加 3 行注释钉死 wrapper 存在的原因防回退。这是源头级修复而非打掩码(§7.3)。零生产代码改动。

  4. 是否有回归问题:无。仅测试、单文件。逐一核过同文件其余 6 个用例不受符号链接 tmpdir 影响:findPackageRoot 从不 realpath,那几个用例要么同基址字面量比较、要么 realpath↔realpath(line 60);findInstallDir 解析的是真实运行副本;logInstallLocationOnce 用硬编码串。覆盖中性:plain 仍证"非链接→无 real=",link 仍证"链接→有 real="。describeInstallLocation/findPackageRoot 既有行为未变。

  5. 是否破坏缓存:不涉及。未触碰任何 cache/retry/游标/去重键逻辑。

  6. 是否改了设计方向:不涉及。无架构/边界/数据流转向。

  7. 是否引入了新的配置:不涉及。无新增 env/config/默认值。

我实际跑过的证据(Linux 上用符号链接目录指 TMPDIR,原生复现 macOS 条件):

  • 修复前(父提交版本)+ 符号链接 TMPDIR:not ok 6 … expected to not match /real=/,target=<via-symlink> vs real=<resolved>,6/7 pass、1 fail —— 与 tests: update-install-dir describeInstallLocation case is flaky on macOS (tmpdir symlink) #2068 描述逐字吻合。
  • 修复后:plain 与符号链接两种 TMPDIR 下均 7/7 pass。
  • npm run typecheck 干净。
  • CI(head 025cf43f):14 项 GHA check-run 全绿(build-artifact、version-guard、test 矩阵 ubuntu+windows × node22+24、dsh/opencode/codex/pi 真实客户端 e2e + hermetic registry)。

base/diff:单提交,自当前 master 切出(merge-base == origin/master tip 3a7308ab,无陈旧基线);diff 干净(单文件 +4/−1,无无关变更、无空白重排)。符合 §7.4 auto-merge 画像(pure test:、单模块、复现原缺陷、不碰 load-bearing infra)。

无需补 commit、无需立新 issue。请人工合并:#2069

@ranxianglei

Copy link
Copy Markdown
Owner Author

关闭:同一修复已经 #2086 合并落地(tmpdir symlink in describeInstallLocation fixture)。本 PR diff 对 master 的存在性检查 = 1.0(逐行命中),纯冗余。(孤儿 PR 扫描)

@ranxianglei ranxianglei changed the title test(update): pin describeInstallLocation fixture to a resolved tmpdir path (#2068) [PR] test(update): pin describeInstallLocation fixture to a resolved tmpdir path (#2068) Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests: update-install-dir describeInstallLocation case is flaky on macOS (tmpdir symlink)

1 participant