@@ -2,12 +2,23 @@ import { describe, expect, test } from "bun:test";
22import { buildWinswXml , ensureWinswBinary , parseWinswStatus , probeScmRegistration , sha256Hex , installWinswService , statusWinswRaw , WINSW_SHA256 , WINSW_SERVICE_ID } from "../src/lib/winsw" ;
33import { parseServiceArgs , serviceReinstallArgs } from "../src/service" ;
44import { loadServiceTokenFromFile } from "../src/lib/service-secrets" ;
5+ import { getConfigDir } from "../src/config" ;
56import { mkdtempSync , readFileSync , writeFileSync , rmSync } from "node:fs" ;
67import { tmpdir } from "node:os" ;
78import { join } from "node:path" ;
89
910const entry = { bun : "C:\\OpenCodex\\bun.exe" , cli : "C:\\Open Codex\\cli & co\\index.ts" } ;
1011
12+ function winswEnvValue ( xml : string , name : string ) : string | null {
13+ const match = xml . match ( new RegExp ( `<env name="${ name } " value="([^"]*)"/>` ) ) ;
14+ if ( ! match ) return null ;
15+ return match [ 1 ] !
16+ . replace ( / & a m p ; / g, "&" )
17+ . replace ( / & l t ; / g, "<" )
18+ . replace ( / & g t ; / g, ">" )
19+ . replace ( / & q u o t ; / g, '"' ) ;
20+ }
21+
1122describe ( "winsw xml" , ( ) => {
1223 const env = { USERDOMAIN : "WORKGROUP" , USERNAME : "jun" , PATH : "C:\\bin;C:\\tools & more" } as NodeJS . ProcessEnv ;
1324
@@ -30,7 +41,7 @@ describe("winsw xml", () => {
3041 expect ( xml ) . toContain ( '<env name="OCX_SERVICE" value="1"/>' ) ;
3142 expect ( xml ) . toContain ( '<env name="OCX_API_TOKEN_FILE"' ) ;
3243 expect ( xml ) . toContain ( '<env name="PATH" value="C:\\bin;C:\\tools & more"/>' ) ;
33- expect ( xml ) . toContain ( '<env name= "OPENCODEX_HOME"' ) ;
44+ expect ( winswEnvValue ( xml , "OPENCODEX_HOME" ) ) . toBe ( getConfigDir ( ) ) ;
3445 // Token VALUES never land in the XML — only file pointers / non-secret budgets.
3546 expect ( xml ) . not . toContain ( "OPENCODEX_API_AUTH_TOKEN" ) ;
3647 expect ( xml ) . not . toContain ( "OPENCODEX_ADMIN_AUTH_TOKEN" ) ;
@@ -39,14 +50,17 @@ describe("winsw xml", () => {
3950 test ( "bakes install-time ACL timeout and never embeds the admin token (#764)" , ( ) => {
4051 const xml = buildWinswXml ( entry , {
4152 ...env ,
53+ OPENCODEX_API_AUTH_TOKEN : "api-secret-value" ,
4254 OPENCODEX_ADMIN_AUTH_TOKEN : "admin-secret & more" ,
4355 OPENCODEX_ACL_TIMEOUT_MS : "10000" ,
4456 } ) ;
4557
4658 expect ( xml ) . toContain ( '<env name="OPENCODEX_ACL_TIMEOUT_MS" value="10000"/>' ) ;
47- expect ( xml ) . toContain ( '<env name= "OPENCODEX_HOME"' ) ;
59+ expect ( winswEnvValue ( xml , "OPENCODEX_HOME" ) ) . toBe ( getConfigDir ( ) ) ;
4860 expect ( xml ) . not . toContain ( "OPENCODEX_ADMIN_AUTH_TOKEN" ) ;
61+ expect ( xml ) . not . toContain ( "OPENCODEX_API_AUTH_TOKEN" ) ;
4962 expect ( xml ) . not . toContain ( "admin-secret" ) ;
63+ expect ( xml ) . not . toContain ( "api-secret-value" ) ;
5064 } ) ;
5165
5266 test ( "escapes executable/arguments and configures restart + graceful stop" , ( ) => {
0 commit comments