diff --git a/src/cli/run-main.import-boundary.test.ts b/src/cli/run-main.import-boundary.test.ts new file mode 100644 index 000000000000..3c0a3af0dd6a --- /dev/null +++ b/src/cli/run-main.import-boundary.test.ts @@ -0,0 +1,14 @@ +// Run-main owns these modules eagerly, so lazy imports only add ineffective bundle edges. +import { readFileSync } from "node:fs"; +import { describe, expect, it } from "vitest"; + +const source = readFileSync(new URL("./run-main.ts", import.meta.url), "utf8"); + +describe("run-main import boundary", () => { + it("does not lazy-import its eager startup owners", () => { + for (const specifier of ["../config/paths.js", "./command-startup-policy.js"]) { + expect(source).toContain(`from "${specifier}"`); + expect(source).not.toContain(`import("${specifier}")`); + } + }); +}); diff --git a/src/cli/run-main.ts b/src/cli/run-main.ts index a5cb0469b9c6..160a3966331b 100644 --- a/src/cli/run-main.ts +++ b/src/cli/run-main.ts @@ -6,7 +6,7 @@ import { normalizeOptionalString } from "@openclaw/normalization-core/string-coe import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice"; import type { Command as CommanderCommand, Option as CommanderOption } from "commander"; import { sanitizeTerminalText } from "../../packages/terminal-core/src/safe-text.js"; -import { resolveStateDir } from "../config/paths.js"; +import { resolveGatewayPort, resolveStateDir } from "../config/paths.js"; import type { ConfigFileSnapshot, OpenClawConfig } from "../config/types.openclaw.js"; import { isLoopbackAddress, isSecureWebSocketUrl } from "../gateway/net.js"; import { normalizeWebSocketProtocol } from "../gateway/websocket-protocol.js"; @@ -172,7 +172,6 @@ async function tryRunGatewayRunFastPath( { addGatewayRunCommand }, { VERSION }, { emitCliBanner }, - { resolveCliStartupPolicy }, { ensureCliExecutionBootstrap }, { defaultRuntime }, ] = await startupTrace.measure("gateway-run-imports", () => @@ -181,13 +180,12 @@ async function tryRunGatewayRunFastPath( import("./gateway-cli/run-command.js"), import("../version.js"), import("./banner.js"), - import("./command-startup-policy.js"), import("./command-execution-startup.js"), import("../runtime.js"), ]), ); const commandPath = resolveGatewayCatalogCommandPath(argv) ?? ["gateway"]; - const startupPolicy = resolveCliStartupPolicy({ + const startupPolicy = resolveCliStartupPolicyForArgv({ argv, commandPath, jsonOutputMode: hasJsonOutputFlag(argv), @@ -633,12 +631,10 @@ async function resolveLocalGatewayProbeTargets( config: OpenClawConfig, ): Promise<{ targets: GatewayProbeTarget[]; auth: GatewayProbeAuth }> { const [ - { resolveGatewayPort }, { resolveControlUiLinks }, { resolveGatewayClientBootstrap }, { readActiveGatewayLockPort }, ] = await Promise.all([ - import("../config/paths.js"), import("../gateway/control-ui-links.js"), import("../gateway/client-bootstrap.js"), import("../infra/gateway-lock.js"), @@ -1617,9 +1613,9 @@ async function runCliWithPreparedOutputMode( }); if (!shouldSkipPluginRegistration) { const config = await startupTrace.measure("register-plugin-commands", async () => { - const [{ registerPluginCliCommandsFromValidatedConfig }, { resolveCliStartupPolicy }] = - await Promise.all([import("../plugins/cli.js"), import("./command-startup-policy.js")]); - const startupPolicy = resolveCliStartupPolicy({ + const { registerPluginCliCommandsFromValidatedConfig } = + await import("../plugins/cli.js"); + const startupPolicy = resolveCliStartupPolicyForArgv({ argv: parseArgv, commandPath: invocation.commandPath, jsonOutputMode: suppressStartupProgress,