@@ -10,8 +10,9 @@ import {
1010} from "e2e/output" ;
1111import { captureRegistryHelp } from "e2e/registry-smoke" ;
1212import { runNodeMain , type RunCliResult } from "e2e/runner" ;
13- import { CommandRegistry , createCli , resolve } from "bailian-cli-runtime " ;
13+ import { buildIsolatedCliEnv } from "e2e/isolation " ;
1414import { runInProcess } from "e2e/in-process" ;
15+ import { CommandRegistry , createCli , resolve } from "bailian-cli-runtime" ;
1516import { loadRouteCommands } from "./harness/routes.ts" ;
1617import { E2E_HARNESS_IDENTITY } from "./harness/identity.ts" ;
1718import { withHarnessUpdateFixture } from "./harness/update-fixture.ts" ;
@@ -50,10 +51,8 @@ const e2eDir = dirname(fileURLToPath(import.meta.url));
5051const harnessMainTs = join ( e2eDir , "harness" , "main.ts" ) ;
5152const registryCache = new WeakMap < E2eRouteExports , Promise < CommandRegistry > > ( ) ;
5253
53- /** `packages/commands` 根目录 */
5454export const commandsPackageRoot = join ( e2eDir , ".." , ".." ) ;
5555
56- /** E2E fixtures 目录 */
5756export const e2eFixturesDir = join ( e2eDir , "fixtures" ) ;
5857
5958function serializeRoutes ( routes : E2eRouteExports ) : string {
@@ -73,7 +72,7 @@ function getCommandRegistry(routes: E2eRouteExports): Promise<CommandRegistry> {
7372 return registryPromise ;
7473}
7574
76- /** 使用 topic 最小路由在当前 Vitest worker 中渲染命令 help,不启动 CLI 子进程。 */
75+ /** In-worker help via topic routes (no CLI subprocess). */
7776export async function captureCommandHelp (
7877 routes : E2eRouteExports ,
7978 commandPath : string [ ] ,
@@ -86,7 +85,7 @@ export async function captureCommandHelp(
8685 return captureRegistryHelp ( registry , commandPath ) ;
8786}
8887
89- /** 与 runCommandE2e 的结果结构兼容,但 help 在当前 Vitest worker 中渲染。 */
88+ /** Same result shape as runCommandE2e; help is rendered in- worker. */
9089export async function runCommandHelp (
9190 routes : E2eRouteExports ,
9291 args : string [ ] ,
@@ -99,14 +98,11 @@ export async function runCommandHelp(
9998}
10099
101100export interface CommandE2eRunOptions {
102- /** 把本机 config 里的 console access_token 写入隔离配置。 */
101+ /** Copy host console access_token into the isolated config. */
103102 seedCredentials ?: boolean ;
104103}
105104
106- /**
107- * 通过 harness 子进程执行命令 E2E。
108- * `routes` 为本用例所需的最小 path → export 映射,不维护全量产品 map。
109- */
105+ /** Harness subprocess E2E; `routes` is the minimal path → export map for this topic. */
110106export async function runCommandE2e (
111107 routes : E2eRouteExports ,
112108 args : string [ ] ,
@@ -123,7 +119,7 @@ export async function runCommandE2e(
123119 } ) ;
124120}
125121
126- /** Console live 用例:隔离环境里带上本机 access_token。 */
122+ /** Console live: isolate and seed host access_token. */
127123export async function runConsoleCommandE2e (
128124 routes : E2eRouteExports ,
129125 args : string [ ] ,
@@ -132,7 +128,10 @@ export async function runConsoleCommandE2e(
132128 return runCommandE2e ( routes , args , envOverrides , { seedCredentials : true } ) ;
133129}
134130
135- /** Opt-in for offline cases; process preloads and proxy configuration retain real subprocesses. */
131+ /**
132+ * Offline opt-in: real createCli in-process with e2e/isolation.
133+ * Falls back to a subprocess when NODE_OPTIONS or HTTP(S)_PROXY is set.
134+ */
136135export async function runCommandInProcess (
137136 routes : E2eRouteExports ,
138137 args : string [ ] ,
@@ -145,12 +144,18 @@ export async function runCommandInProcess(
145144 environment . HTTPS_PROXY ||
146145 environment . http_proxy ||
147146 environment . https_proxy
148- )
147+ ) {
149148 return runCommandE2e ( routes , args , envOverrides ) ;
150- const commands = await loadRouteCommands ( routes ) ;
151- return runInProcess (
152- ( ) => withHarnessUpdateFixture ( ( ) => createCli ( commands , E2E_HARNESS_IDENTITY ) . run ( args ) ) ,
153- args ,
154- { cwd : commandsPackageRoot , env : envOverrides , entrypoint : harnessMainTs } ,
155- ) ;
149+ }
150+ const isolated = buildIsolatedCliEnv ( { overrides : envOverrides } ) ;
151+ try {
152+ const commands = await loadRouteCommands ( routes ) ;
153+ return await runInProcess (
154+ ( ) => withHarnessUpdateFixture ( ( ) => createCli ( commands , E2E_HARNESS_IDENTITY ) . run ( args ) ) ,
155+ args ,
156+ { cwd : commandsPackageRoot , env : isolated . env , entrypoint : harnessMainTs } ,
157+ ) ;
158+ } finally {
159+ isolated . dispose ( ) ;
160+ }
156161}
0 commit comments