11import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
2- import { captureFullEnv } from "../../test-utils/env.js" ;
32import type { DaemonActionResponse } from "./response.js" ;
3+ import { captureFullEnv } from "../../test-utils/env.js" ;
44
5- const resolveAutoNodeExtraCaCertsMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
5+ const resolveNodeStartupTlsEnvironmentMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
66const loadConfigMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
77const readConfigFileSnapshotMock = vi . hoisted ( ( ) => vi . fn ( ) ) ;
88const resolveGatewayPortMock = vi . hoisted ( ( ) => vi . fn ( ( ) => 18789 ) ) ;
@@ -51,8 +51,8 @@ const service = vi.hoisted(() => ({
5151 readRuntime : vi . fn ( async ( ) => ( { status : "stopped" as const } ) ) ,
5252} ) ) ;
5353
54- vi . mock ( "../../bootstrap/node-extra-ca-certs .js" , ( ) => ( {
55- resolveAutoNodeExtraCaCerts : resolveAutoNodeExtraCaCertsMock ,
54+ vi . mock ( "../../bootstrap/node-startup-env .js" , ( ) => ( {
55+ resolveNodeStartupTlsEnvironment : resolveNodeStartupTlsEnvironmentMock ,
5656} ) ) ;
5757
5858vi . mock ( "../../config/config.js" , ( ) => ( {
@@ -156,7 +156,7 @@ const envSnapshot = captureFullEnv();
156156describe ( "runDaemonInstall" , ( ) => {
157157 beforeEach ( ( ) => {
158158 loadConfigMock . mockReset ( ) ;
159- resolveAutoNodeExtraCaCertsMock . mockReset ( ) ;
159+ resolveNodeStartupTlsEnvironmentMock . mockReset ( ) ;
160160 readConfigFileSnapshotMock . mockReset ( ) ;
161161 resolveGatewayPortMock . mockClear ( ) ;
162162 writeConfigFileMock . mockReset ( ) ;
@@ -198,7 +198,10 @@ describe("runDaemonInstall", () => {
198198 installDaemonServiceAndEmitMock . mockResolvedValue ( undefined ) ;
199199 service . isLoaded . mockResolvedValue ( false ) ;
200200 service . readCommand . mockResolvedValue ( null ) ;
201- resolveAutoNodeExtraCaCertsMock . mockReturnValue ( undefined ) ;
201+ resolveNodeStartupTlsEnvironmentMock . mockReturnValue ( {
202+ NODE_EXTRA_CA_CERTS : undefined ,
203+ NODE_USE_SYSTEM_CA : undefined ,
204+ } ) ;
202205 delete process . env . OPENCLAW_GATEWAY_TOKEN ;
203206 delete process . env . CLAWDBOT_GATEWAY_TOKEN ;
204207 } ) ;
@@ -300,7 +303,10 @@ describe("runDaemonInstall", () => {
300303
301304 it ( "returns already-installed when the service already has the expected TLS env" , async ( ) => {
302305 service . isLoaded . mockResolvedValue ( true ) ;
303- resolveAutoNodeExtraCaCertsMock . mockReturnValue ( "/etc/ssl/certs/ca-certificates.crt" ) ;
306+ resolveNodeStartupTlsEnvironmentMock . mockReturnValue ( {
307+ NODE_EXTRA_CA_CERTS : "/etc/ssl/certs/ca-certificates.crt" ,
308+ NODE_USE_SYSTEM_CA : undefined ,
309+ } ) ;
304310 service . readCommand . mockResolvedValue ( {
305311 programArguments : [ "openclaw" , "gateway" , "run" ] ,
306312 environment : {
@@ -316,7 +322,10 @@ describe("runDaemonInstall", () => {
316322
317323 it ( "reinstalls when an existing service is missing the nvm TLS CA bundle" , async ( ) => {
318324 service . isLoaded . mockResolvedValue ( true ) ;
319- resolveAutoNodeExtraCaCertsMock . mockReturnValue ( "/etc/ssl/certs/ca-certificates.crt" ) ;
325+ resolveNodeStartupTlsEnvironmentMock . mockReturnValue ( {
326+ NODE_EXTRA_CA_CERTS : "/etc/ssl/certs/ca-certificates.crt" ,
327+ NODE_USE_SYSTEM_CA : undefined ,
328+ } ) ;
320329 service . readCommand . mockResolvedValue ( {
321330 programArguments : [ "openclaw" , "gateway" , "run" ] ,
322331 environment : { } ,
@@ -329,11 +338,13 @@ describe("runDaemonInstall", () => {
329338
330339 it ( "reinstalls when the installed service still runs from nvm even if the installer runtime does not" , async ( ) => {
331340 service . isLoaded . mockResolvedValue ( true ) ;
332- resolveAutoNodeExtraCaCertsMock . mockImplementation ( ( { execPath } ) =>
333- typeof execPath === "string" && execPath . includes ( "/.nvm/" )
334- ? "/etc/ssl/certs/ca-certificates.crt"
335- : undefined ,
336- ) ;
341+ resolveNodeStartupTlsEnvironmentMock . mockImplementation ( ( { execPath } ) => ( {
342+ NODE_EXTRA_CA_CERTS :
343+ typeof execPath === "string" && execPath . includes ( "/.nvm/" )
344+ ? "/etc/ssl/certs/ca-certificates.crt"
345+ : undefined ,
346+ NODE_USE_SYSTEM_CA : undefined ,
347+ } ) ) ;
337348 service . readCommand . mockResolvedValue ( {
338349 programArguments : [ "/home/test/.nvm/versions/node/v22.18.0/bin/node" , "dist/entry.js" ] ,
339350 environment : { } ,
@@ -342,7 +353,7 @@ describe("runDaemonInstall", () => {
342353 await runDaemonInstall ( { json : true } ) ;
343354
344355 expect ( installDaemonServiceAndEmitMock ) . toHaveBeenCalledTimes ( 1 ) ;
345- expect ( resolveAutoNodeExtraCaCertsMock ) . toHaveBeenCalledWith (
356+ expect ( resolveNodeStartupTlsEnvironmentMock ) . toHaveBeenCalledWith (
346357 expect . objectContaining ( {
347358 execPath : "/home/test/.nvm/versions/node/v22.18.0/bin/node" ,
348359 } ) ,
0 commit comments