Repository navigation
Conversation
- 审计 sandbox-network 真实静态导入图与编译态入口,拆分 3 处非沙盒耦合(loopback-peer-process.ts、system-bwrap-notice.ts、standalone-entry.ts 直连 __sandbox-network-runner),精准收窄 .github/workflows/sandbox-network.yml 触发路径(移除 worker/worker-pool/daemon/cli/services/**/workflows/**/types.ts 热路径,仅保留真实运行时依赖与主干 push 兜底),并新增 AST 传递依赖防漂移守卫 test/sandbox-network-paths.test.ts - 扩展 scripts/ci-binary-trigger.mjs 同步输出 run_binaries 与严格白名单 docs_only 判定,为 .github/workflows/ci.yml 增加纯文档 PR 快速通道(保持 build / test / bun-test-shards 并行入队无 needs: build;build 保留 audit-public-domains 审计,test 1/3 运行全量文档一致性单测,其余分片与 bun-test 聚合优雅跳过,master push 与异常一律 fail-open 全量执行) Co-Authored-By: Claude Code <noreply@anthropic.com>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 30, 2026 18:56
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景与目标
基于已合入的 #4082(
origin/masteraf916a9387),进一步缓解 GitHub Actions runner 队列拥堵,同时保证安全边界与 Ruleset 门禁零降级:.github/workflows/sandbox-network.yml触发路径,并以 AST 传递依赖守卫测试锁死零安全盲区;.github/workflows/ci.yml增加纯文档 PR 快速通道,保持build/test (1..3/3)/bun-test (1..2/2)并行入队(零二次排队),并保持 Ruleset 必检项build、test与bun-test聚合门禁完整有效。一、
sandbox-network.yml真实依赖图审计与精准收窄1. 静态导入图审计与 3 处低风险解耦
从
test/sandbox-network-linux.test.ts(含其动态导入../dist/adapters/backend/sandbox.js)、src/adapters/backend/sandbox.ts、src/sandbox-network-runner.ts、src/core/sandbox-network-*.ts和scripts/build-bun-binary.mjs出发,通过 TypeScript AST 递归解析真实本地运行时传递依赖,发现 3 处非沙盒强耦合导致依赖闭包膨胀:src/core/loopback-peer-process.ts(从src/core/current-actor-attestation.ts抽出)src/sandbox-network-runner.ts→src/core/protected-http-egress-loopback.ts→src/core/current-actor-attestation.ts仅为了resolveLoopbackPeerProcesses/ProcessIdentity,却经identity-cache.ts静态拉入 484 个业务模块(bot-registry.ts、config.ts、im/lark/*、全部 CLI adapter 与services/*)。src/core/loopback-peer-process.ts(仅依赖node:fs/node:path与utils/{darwin-libproc,proc-stat,loopback-peers,logger}.ts),current-actor-attestation.ts保留同名导出与包装函数兼容现有调用方及vi.spyOn测试;sandbox-network-runner.ts运行时闭包从 488 文件降至 ~20 文件。src/core/system-bwrap-notice.ts(从src/core/system-bwrap.ts抽出)system-bwrap.ts仅为 7 行的sandboxNamespaceNotice()引入src/i18n/index.ts→src/i18n/{en,zh}.ts(高频热文件,近 200 次提交命中 32 次),使sandbox.ts与sandbox-network-launch.ts间接绑定全量文案。sandboxNamespaceNotice独立至src/core/system-bwrap-notice.ts(仅更新唯一生产调用方src/core/worker-pool.ts与 2 处测试)。src/standalone-entry.ts直连__sandbox-network-runnerstatusline叶子分流一致,在src/standalone-entry.ts中对process.argv[2] === '__sandbox-network-runner'直接await import('./sandbox-network-runner.js'),跳过 23,000 行的src/cli.ts(近 200 次提交命中 35 次;src/cli.ts:22900仍保留作为兜底)。test/sandbox-network-linux.test.ts的编译态单文件二进制实测不再经过src/cli.ts,仅依赖src/standalone-entry.ts与打包脚本链路。2. 移除的热路径与保留的真实闭包
src/worker.ts、src/core/worker-pool.ts、src/daemon.ts、src/cli.ts、src/workflows/**、src/types.ts(仅import type)、src/services/**目录通配(以及经解耦剥离的src/i18n/**)。src/services/下真正被静态导入的单个文件src/services/plugin-registry-store.ts(由src/core/protected-http-egress.ts导入);src/core/system-bwrap.ts、src/core/pid-namespace-peer.ts、src/core/loopback-peer-process.ts、src/core/protected-http-egress*、src/core/protected-loopback-attestation.ts、src/core/protected-mcp-capabilities.ts、src/core/sandbox-wrapper-launch.ts、src/core/sandbox-send-route.ts、src/core/plugins/**真实依赖、src/adapters/cli/sandbox-mode.ts、src/adapters/cli/fs-policy.ts、src/utils/child-env.ts、src/utils/atomic-write.ts、src/standalone-entry.ts、scripts/build-bun-binary.mjs及其全部传递脚本、package.json/bun.lock/bunfig.toml/tsconfig.json/vitest.config.ts/.github/actions/setup-bun/**/scripts/ci-net-retry.mjs/test/helpers/ts-runner.ts等。src/adapters/backend/sandbox.ts:2406处仅位于startSendRelay()的懒加载import('../../services/remote-runner-session-tool.js')不在prepareDirectSandbox/ 网络边界链路内,已在守卫测试中显式登记并校验不漂移。on.push(branches: [master],与pull_request.paths完全一致),并将concurrency.cancel-in-progress改为${{ github.event_name == 'pull_request' }},避免后续合入取消进行中的 master 边界实测。origin/master提交):触发率从 150/200 (75.0%) 降至 19/200 (9.5%)(降幅 87.3%)。3. 防漂移守卫测试(
test/sandbox-network-paths.test.ts)src/standalone-entry.ts顶层静态导入的完整本地运行时传递闭包(区分import type/export type,同时审计任何新增动态import()/require()),断言每个真实运行时依赖均命中.github/workflows/sandbox-network.yml的paths;src/standalone-entry.ts中__sandbox-network-runner与./cli.js位于互斥if / else if / else分支且后续无 fallthrough;pull_request.paths与push.paths完全一致、无死模式、不取消 master 运行、热路径不再误触发。二、
ci.yml纯文档 PR 快速通道(Docs-only fast-path)1. 严格白名单与 fail-open 兜底(
scripts/ci-binary-trigger.mjs)在同一
fetch-depth: 2轻量 diff 判定脚本内扩展docs_only=true|false(与run_binaries=true|false一次 git diff 同出,不增二次 git 开销):README*.md、CHANGELOG*.md、CONTRIBUTING*.md、SECURITY*.md、LICENSE(?:-[A-Za-z0-9_]+)?(?:\.(?:md|txt))?、CLAUDE.md、AGENTS.md、CONTEXT.md、cover.svg;docs/**/*.{md,mdx,txt,png,jpg,jpeg,gif,webp,svg,ico,mp4,webm,avif}(明确排除docs/下的.py、.json、.html等脚本/数据/页面文件);docs-site/**/*.{md,mdx}及docs-site/{docs,static}/**/*.{png,jpg,jpeg,gif,webp,svg,ico,mp4,webm,avif}(明确排除rspress.config.ts、package.json、pnpm-lock.yaml、deploy.sh、scripts/**、index.html);gif/**/*.{png,jpg,jpeg,gif,webp,svg,mp4,webm,avif}。src/**、test/**、scripts/**、packages/**、desktop/**、build/**、.github/**、package.json及任意.ts/.tsx/.js/.mjs/.cjs/.json/.yml/.yaml/.lock/.sh/.py/.html/.css/.toml/.node/.env/.example、路径穿越..或绝对路径;--no-renames确保从src/重命名到docs/同样触发全量。push到master/ 非pull_request事件 / 任何 git diff 异常或浅克隆缺父提交,一律 fail-open 到docs_only=false(同时run_binaries=true)跑全量。2. 全仓文档校验清单与各 job 行为
全仓审计
test/与scripts/后,真实读取仓库文档的检查共 3 项,纯文档快速通道 100% 保留执行:scripts/audit-public-domains.mjs(扫描README.md、README.en.md、docs/、docs-site/中的内部域名泄漏,纯 Node 内置模块,<1s);test/slash-commands-doc-sync.test.ts(校验docs-site/docs/{en,zh}/slash-commands.md与代码命令及权限清单对称,不依赖dist/);test/update-badges.test.ts(校验README.md、README.en.md徽标地址与 workflow 一致,不依赖dist/)。各 job 调度与
bun-test聚合处理:test (1..3/3)与bun-test (1..2/2)均 不加needs: build,普通代码 PR 无二次排队。build(Ruleset 必检):docs_only == 'true'时运行node scripts/audit-public-domains.mjs后成功退出(跳过bun install/tsc/workflow-core),同时输出run_binaries=false让 3 条bun-binary*腿跳过;非纯文档时全量构建。test (1..3/3)+test-ok(Ruleset 必检test):docs_only == 'true'时:shard 1 安装依赖并运行全部DOCS_CONSISTENCY_TESTS(test/slash-commands-doc-sync.test.ts、test/update-badges.test.ts),跳过bwrap/build/ 全量分片;shard 2 & 3 跳过setup-bun/bun install/build/ 测试直接早退成功;任一文档单测失败仍由test-ok阻断合码。docs_only != 'true'(含空值 fail-open)时:3 个分片照常全量运行。bun-test-shards (1..2/2)+bun-test聚合:docs_only == 'true'时:两片跳过依赖安装、测试与 timings 上传;上传步骤改为if: ${{ always() && steps.pr-gate.outputs.docs_only != 'true' }},保证非纯文档分片失败时依然上传部分 timings,而纯文档快通不会触发if-no-files-found: error。bun-test聚合 job 仍首先执行Require every Bun shard(任一分片非success立即红灯),随后在fetch-depth: 2上执行同一确定性判定:当docs_only == 'true'时优雅跳过download-artifact、merge-bun-test-timings.mjs与upload-artifact并保持bun-test为success;当docs_only != 'true'(含 fail-open 空值)时照常校验全量覆盖并合并上传。影响面评估
src/core/loopback-peer-process.ts完整保留 Linux procfs 与 macOSdarwin-libproc两条分支(已跑darwin-peer-lineage.test.ts、current-actor-attestation.test.ts、current-actor-peer-scan.test.ts覆盖);CI 工作流均为 Linux runner 路径判定(路径分隔符已统一 POSIX 归一化)。src/core/current-actor-attestation.ts对外部导出签名与行为保持 100% 兼容(ipc-current-execution-route.test.ts/ipc-platform-lark-renewal.test.ts中vi.spyOn均通过);src/standalone-entry.ts新增__sandbox-network-runner叶子分流经真机单文件二进制编译与全量 smoke 验证。loopback-peer-process.ts、system-bwrap-notice.ts)并在standalone-entry.ts增加单入口分流,无持久状态语义变更。实际测试验证
workflow-core:bun run build && bun run workflow-core:testaudit:domains、tsc、typecheck、dashboard:bundle、audit-dist、audit-embedded-assets --require-dist、workflow-coreESM/CJS/types tarball smoke 全绿)。bun run test \ test/ci-binary-trigger.test.ts test/sandbox-network-paths.test.ts \ test/bun-ci-shards.test.ts test/ci-unit-shards.test.ts test/ci-concurrency.test.ts \ test/ci-net-retry.test.ts test/ci-glibc-baseline-gate.test.ts test/ci-musl-gate.test.ts \ test/release-darwin-codesign-gate.test.ts test/duration-shards.test.ts \ test/slash-commands-doc-sync.test.ts test/update-badges.test.ts test/test-hygiene.test.ts \ test/worker-ipc-preload.test.ts test/cli-runner-compiled-entries.test.ts \ test/sandbox-network-policy.test.ts test/sandbox-network-proxy.test.ts \ test/sandbox-network-runner-contract.test.ts test/current-actor-attestation.test.ts \ test/current-actor-peer-scan.test.ts test/crash-loop-diagnostic.test.ts \ test/protected-provider-loopback-linux.test.tsprotected-provider-loopback-linux按环境 gate 跳过),598 passed | 0 failed;另跑test/ipc-current-execution-route.test.ts、test/ipc-platform-lark-renewal.test.ts、test/darwin-peer-lineage.test.ts222 passed | 0 failed。fenced-run隔离 + self-check):test:bun:self-check1/1 green。BOTMUX_VERIFY_BAKED_VERSION="0.0.0-verify" bun scripts/build-bun-binary.mjs --target bun-linux-x64 --out /tmp/botmux-verify-aplus bun scripts/fenced-run.ts -- node scripts/smoke-bun-binary.mjs /tmp/botmux-verify-aplus /tmp/botmux-verify-aplus __sandbox-network-runner__sandbox-network-runner直接命中sandbox-network-runner.js输出[sandbox-network] missing network launch plan。git diff --check:通过。🤖 Generated with Claude Code