@@ -21,7 +21,7 @@ vi.mock("node:child_process", async () => {
2121} ) ;
2222
2323import { splitArgsPreservingQuotes } from "./arg-split.js" ;
24- import { parseSystemdExecStart } from "./systemd-unit.js" ;
24+ import { parseSystemdEnvAssignments , parseSystemdExecStart } from "./systemd-unit.js" ;
2525import {
2626 installSystemdService ,
2727 isNonFatalSystemdInstallProbeError ,
@@ -608,6 +608,24 @@ describe("splitArgsPreservingQuotes", () => {
608608 } ) ;
609609} ) ;
610610
611+ describe ( "parseSystemdEnvAssignments" , ( ) => {
612+ it ( "parses single-quoted whole assignments" , ( ) => {
613+ expect (
614+ parseSystemdEnvAssignments ( "'OPENCLAW_GATEWAY_TOKEN=single quoted token' FOO=bar" ) ,
615+ ) . toEqual ( [
616+ { key : "OPENCLAW_GATEWAY_TOKEN" , value : "single quoted token" } ,
617+ { key : "FOO" , value : "bar" } ,
618+ ] ) ;
619+ } ) ;
620+
621+ it ( "keeps apostrophes inside unquoted assignment values literal" , ( ) => {
622+ expect ( parseSystemdEnvAssignments ( "FOO=can't OPENCLAW_GATEWAY_TOKEN=token" ) ) . toEqual ( [
623+ { key : "FOO" , value : "can't" } ,
624+ { key : "OPENCLAW_GATEWAY_TOKEN" , value : "token" } ,
625+ ] ) ;
626+ } ) ;
627+ } ) ;
628+
611629describe ( "parseSystemdExecStart" , ( ) => {
612630 it ( "preserves quoted arguments" , ( ) => {
613631 const execStart = '/usr/bin/openclaw gateway start --name "My Bot"' ;
@@ -953,6 +971,7 @@ describe("stageSystemdService", () => {
953971 "ExecStart=/usr/bin/openclaw node run" ,
954972 "Environment=FOO=bar OPENCLAW_GATEWAY_TOKEN=inline-token BAZ=qux" ,
955973 "Environment=OPENCLAW_GATEWAY_TOKEN=token-only-line" ,
974+ "Environment='OPENCLAW_GATEWAY_TOKEN=single-quoted-token' FROM_SINGLE=kept" ,
956975 "Environment=OPENCLAW_GATEWAY_PORT=18789" ,
957976 ] . join ( "\n" ) ,
958977 { encoding : "utf8" , mode : 0o600 } ,
@@ -985,7 +1004,9 @@ describe("stageSystemdService", () => {
9851004 expect ( unit ) . not . toContain ( "Environment=OPENCLAW_GATEWAY_TOKEN=fresh-token" ) ;
9861005 expect ( backupUnit ) . not . toContain ( "Environment=OPENCLAW_GATEWAY_TOKEN=inline-token" ) ;
9871006 expect ( backupUnit ) . not . toContain ( "Environment=OPENCLAW_GATEWAY_TOKEN=token-only-line" ) ;
1007+ expect ( backupUnit ) . not . toContain ( "single-quoted-token" ) ;
9881008 expect ( backupUnit ) . toContain ( "Environment=FOO=bar BAZ=qux" ) ;
1009+ expect ( backupUnit ) . toContain ( "Environment=FROM_SINGLE=kept" ) ;
9891010 expect ( backupUnit ) . toContain ( "Environment=OPENCLAW_GATEWAY_PORT=18789" ) ;
9901011 expect ( backupStat . mode & 0o777 ) . toBe ( 0o600 ) ;
9911012 } ) ;
0 commit comments