Skip to content

test(e2e): windows-compatible hermetic registry e2e + real npm -g install test - #1880

Merged
ranxianglei merged 3 commits into
masterfrom
win-update-audit
Oct 2, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
win-update-audit

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

test(e2e): windows-compatible hermetic registry e2e + real npm -g install test

The hermetic registry e2e (local verdaccio, PR-gated) and the release
canary ran ubuntu-only, so the entire Windows install/update surface —
npm -g shims, NTFS junctions, USERPROFILE-mirrored npm config — had zero
CI coverage.

This PR ports the registry e2e suite to real Windows and adds a new
end-to-end test that exercises the real npm client:

  • tests/e2e/crossplat.ts (new): shared cross-platform helpers.
    • npmCliPath() runs npm via node npm-cli.js (no shell, no ENOENT on
      npm.cmd); npmRunSync() falls back to shell+quoting.
    • windowsSystemEnv() forwards SystemRoot/ComSpec/etc — a bare env
      without SystemRoot breaks node child processes on Windows.
    • npmHomeEnv() mirrors HOME to USERPROFILE/APPDATA (npm userconfig
      reads USERPROFILE, not HOME, on win32).
    • fakeVersionBin() writes a cross-platform fake CLI (.cmd on win32);
      the product's detectOpencodeMajor already shells out for .cmd/.bat.
  • registry-fixture.ts + both e2e suites use the helpers; hermetic env
    isolation (HOME + XDG_* + win mirrors) now holds on both platforms
    (paths.ts reads XDG_* on all platforms).
  • New test "hermetic npm -g install e2e": the real npm client installs
    billion-context@OLD --global into an isolated prefix (asserts the
    platform-correct layout: /node_modules + bili.cmd on win32,
    lib/node_modules + bin/bili on POSIX), then bili update flips it in
    place over the real chain, and the shim npm laid down reports the new
    version. Fixture tarballs are published with dependencies stripped for
    this test — the hermetic registry has no uplinks and dependency
    resolution would 404; the flip mechanics under test don't involve it.
  • ci-registry.yml: matrix ubuntu-latest + windows-latest (bash shell on
    both; artifacts collected with an os suffix).

Validated on a real win10 VM (not just GH runners): junction unit tests
11/11 (from #1872 follow-up), hermetic registry e2e 10/10 including the
new npm -g test — self-update flip, advisory rollback, real npm -g
install + shim + in-place flip all behave on real Windows. Product code
is unchanged; every failure found on the VM was in test infrastructure.

…tall test

The hermetic registry e2e (local verdaccio, PR-gated) and the release
canary ran ubuntu-only, so the entire Windows install/update surface —
npm -g shims, NTFS junctions, USERPROFILE-mirrored npm config — had zero
CI coverage.

This PR ports the registry e2e suite to real Windows and adds a new
end-to-end test that exercises the real npm client:

- tests/e2e/crossplat.ts (new): shared cross-platform helpers.
  - npmCliPath() runs npm via node npm-cli.js (no shell, no ENOENT on
    npm.cmd); npmRunSync() falls back to shell+quoting.
  - windowsSystemEnv() forwards SystemRoot/ComSpec/etc — a bare env
    without SystemRoot breaks node child processes on Windows.
  - npmHomeEnv() mirrors HOME to USERPROFILE/APPDATA (npm userconfig
    reads USERPROFILE, not HOME, on win32).
  - fakeVersionBin() writes a cross-platform fake CLI (.cmd on win32);
    the product's detectOpencodeMajor already shells out for .cmd/.bat.
- registry-fixture.ts + both e2e suites use the helpers; hermetic env
  isolation (HOME + XDG_* + win mirrors) now holds on both platforms
  (paths.ts reads XDG_* on all platforms).
- New test "hermetic npm -g install e2e": the real npm client installs
  billion-context@OLD --global into an isolated prefix (asserts the
  platform-correct layout: <prefix>/node_modules + bili.cmd on win32,
  lib/node_modules + bin/bili on POSIX), then `bili update` flips it in
  place over the real chain, and the shim npm laid down reports the new
  version. Fixture tarballs are published with dependencies stripped for
  this test — the hermetic registry has no uplinks and dependency
  resolution would 404; the flip mechanics under test don't involve it.
- ci-registry.yml: matrix ubuntu-latest + windows-latest (bash shell on
  both; artifacts collected with an os suffix).

Validated on a real win10 VM (not just GH runners): junction unit tests
11/11 (from #1872 follow-up), hermetic registry e2e 10/10 including the
new npm -g test — self-update flip, advisory rollback, real npm -g
install + shim + in-place flip all behave on real Windows. Product code
is unchanged; every failure found on the VM was in test infrastructure.
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: win-update-audit (d92bc47)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1878-pr.1880.16e1886

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-pr1880.tgz
npm install -g package

Install instructions are refreshed on each push.

ework-agent added 2 commits October 2, 2026 00:26
Review of #1880: when npmCliPath() misses, the fallback branch built
execFile(file="npm", args=[joined command], {shell:true}) — Node prepends
the file to the shell command line, so this executed `npm npm pack …`.
Pass the whole command as the file string with empty argv instead, and
quote whitespace-bearing args on all platforms (POSIX quoting was win32-only
in npmRunSync). Dead path on CI runners (npm-cli.js sits next to node);
only reachable on local dev machines.
… contract

Review of #1880: pre-existing strict-tsc mismatch (tests are excluded from
tsconfig.build.json, so CI never saw it) — runNpm resolves {stdout,stderr}
but RegistryFixture.publish declares Promise<void>. Discard the result at
the boundary instead of leaking it into the declared type.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #1880 review — 已拉取分支逐文件审完(5 files, +213/−77,单提交),并核对了产品代码侧的每个承重点。结论先行:方向正确、无回归、可合并;review 中顺手修了 2 个小问题(见下),已作为独立标注 commit 推到 win-update-audit,CI 在新 head 上重跑中。

查重:无重复。#1872(已合)是 Windows 自更新功能本体,本 PR 是其后的 CI 覆盖补齐,范围不重叠。


① 是什么问题:hermetic registry e2e 与 release canary 只有 ubuntu leg,Windows 安装/更新面(npm -g shim、NTFS junction、USERPROFILE 隔离)CI 覆盖为零;且现有 suite 全是手工 tar 展开路径,真实 npm 客户端的 -g 安装布局从未被端到端验证过。

② 什么原因导致的:原 suite 按 POSIX 假设写成——execFile("npm") 直接 spawn、#!/bin/sh fake bin、仅 HOME 隔离——在 Windows 全部不成立,所以此前只能跑 ubuntu。这是覆盖缺口,不是缺陷修复,方向无误。

③ 怎么修复的(机制层核对,均已逐一验证):

  • crossplat.ts 四个 helper 各自打中一个真实的平台差异:npmCliPath() 用 node npm-cli.js 绕开 npm.cmd 无 shell ENOENT;windowsSystemEnv() 转发 SystemRoot/ComSpec 等(裸 env 在 win32 起不了 node 子进程);npmHomeEnv() 把 HOME 镜像到 USERPROFILE/APPDATA(npm userconfig 在 win32 只认后者);fakeVersionBin() 出 .cmd shim(与产品 detectOpencodeMajor 的 .cmd/.bat shell 路由一致)。
  • 新测试用真 npm 客户端 install --global --prefix 进隔离前缀,断言平台正确布局(win: <prefix>/node_modules+bili.cmd;POSIX: lib/node_modules+bin/bili),再走真链 bili update 原地 flip,最后探针确认 npm 自己铺的 shim 报出新版本——断言有牙,钉住了 hostManagedInstall 对 npm-global 布局的分类契约(AGENTS.md §2.6)。
  • 关键承重声明均核实为真:paths.ts 确实全平台读 XDG_*(隔离在 Windows 成立);flip 消息 regex 精确匹配 src/update.ts:968 的实际输出;updater 全链不含 npm install(extract → sha512 → node --check entries → copy → flip),所以 bare tarball(剥依赖)不影响被测机制,理由成立。
  • 产品代码零改动(diff stat 确认仅 workflows + tests);两套旧 suite 是纯重构到共享 helper,POSIX env 形状逐键不变。

④ 是否有回归问题:逐项过完,无。

  • ubuntu leg:步骤序列不变;timeout 15→25min、artifact 名加 os 后缀、新增 windows leg——均为有意变更且 PR 正文已披露;全仓 grep 确认无其他工作流引用旧 artifact 名。
  • fixture runNpm:POSIX 行为等价(同参数、同 HOME 隔离;windowsSystemEnv() 在 POSIX 返回 {});ubuntu CI 绿即证明。
  • 高危模式逐项排除:无语义漂移、无 fail-fast 变吞错、无阈值/时序/输出格式漂移(除上述已披露 CI 项)、NPM_ALLOW_DANGEROUS 透传保留。
  • 新测试由 ACP_TEST_REGISTRY=1 门控,不进 npm test glob,不影响主套件。

⑤ 是否破坏缓存:不涉及——未触碰缓存/重试/增量游标/去重键任何逻辑。

⑥ 是否改了设计方向:不涉及——纯测试/CI 基建,两种压缩模式、wire、配置面均未动。

⑦ 是否引入新配置:不涉及——无新 env/config/默认值;用到的 BILI_UPDATE_REGISTRY/BILI_UPDATE_CHECK_INTERVAL_MS 均为既有 seam,默认值不变。


Review 顺手修的小问题(小问题直接修,独立 commit 已推分支):

  1. 499e8115 — 本 PR 新引入的真实缺陷:fixture runNpm 的 shell 回退分支构造为 execFile("npm", [整条命令串], {shell:true}),而 Node 在 shell:true 时把 file 拼到命令行前面——实际执行的是 npm npm pack …(本地探针实证)。修法:整条命令作 file 串 + 空 argv,且空白参数引号化改为全平台(npmRunSync 原来只在 win32 引号化)。该路径在 CI runner 上不可达(npm-cli.js 恒在 node 旁),仅本机 dev 可触发,故未阻塞原 head 的绿。
  2. d92bc474 — pre-existing 严格类型不匹配:RegistryFixture.publish 声明 Promise<void> 但实现泄漏 runNpm 的 {stdout,stderr};tests 不在 tsconfig.build.json 内所以 CI 从未见过。在边界丢弃返回值对齐声明。

验证证据:编辑后树本地跑 ACP_TEST_REGISTRY=1 全套(registry + advisory-rollback,含新 npm -g 测试)10/10 通过(POSIX);四个触碰文件 strict tsc 零错误;execFile shell 语义探针实证。Windows 侧以 GH runner 为准。

CI 状态:原 head ddfbcd50 上 hermetic registry e2e ubuntu ✅ / windows-latest ✅(本 PR 核心门禁双绿)、build-artifact/version-guard/各 lane e2e 全绿;主 ci.yml typecheck+test 矩阵当时仍在跑。我的两个 commit 使 head 变为 d92bc474,全套重跑中——等这轮 registry 双腿 + 主矩阵绿即可合。

非阻塞备注:分支名 win-update-audit 不符合 YYYY-MM-DD_short-title 约定;PR 已建、改名会孤儿化 PR 且无功能影响,留待 owner 定夺,不作为拦截项。diff 整洁度:5 文件全部与本 PR 目的相关,单线性提交,无空行 churn。

判定:可合并(待 d92bc474 的 CI 重跑转绿;合并操作归人)。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 CI 全绿确认:新 head d92bc474(含 review 顺手修的两个 commit)上全部 14 项 check 通过——hermetic registry e2e ubuntu ✅ / windows-latest ✅(本 PR 核心门禁)、主 ci.yml typecheck+test 矩阵(ubuntu/windows × node 22/24)✅、各 lane e2e / build-artifact / version-guard / codex overlay 全绿。

我此前给出的合并条件已满足,PR 可合并(合并操作归人)。review 结论见上一条评论(结构化七问 + 两个修复 commit 说明)。

@ranxianglei
ranxianglei merged commit efe815b into master Oct 2, 2026
14 checks passed
@ranxianglei
ranxianglei deleted the win-update-audit branch October 15, 2026 05:33
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.

1 participant