Skip to content

Commit ba820bc

Browse files
committed
fix(release): strip isolated Windows service identity
1 parent 74fff8d commit ba820bc

2 files changed

Lines changed: 43 additions & 14 deletions

File tree

‎scripts/lib/cross-os-release-checks/lanes.ts‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export async function runInstallerFreshSuite(
397397
const usesManagedGateway = shouldUseManagedGatewayService();
398398
const useManagedGatewayAfterInstall = shouldUseManagedGatewayForInstallerRuntime();
399399
const manualGateway: { current: GatewayHandle | null } = { current: null };
400-
let managedHostLease: ManagedGatewayInstallerHostLease | null = null;
400+
const managedHostLease: { current: ManagedGatewayInstallerHostLease | null } = { current: null };
401401
let managedHostOwned = false;
402402
let managedHostEnv: NodeJS.ProcessEnv | null = null;
403403
let managedHostCliPath = "";
@@ -453,7 +453,7 @@ export async function runInstallerFreshSuite(
453453
if (!accountHome) {
454454
throw new Error("Managed installer service checks require the host account home.");
455455
}
456-
managedHostLease = acquireManagedGatewayInstallerHostLease(accountHome);
456+
managedHostLease.current = acquireManagedGatewayInstallerHostLease(accountHome);
457457
assertManagedGatewayInstallerHostAvailable({
458458
accountHome,
459459
serviceInstalled: false,
@@ -615,12 +615,13 @@ export async function runInstallerFreshSuite(
615615
}
616616

617617
let managedCleanupError: Error | undefined;
618-
if (managedHostLease) {
618+
const acquiredManagedHostLease = managedHostLease.current;
619+
if (acquiredManagedHostLease) {
619620
let hostCleanupError: Error | undefined;
620621
try {
621622
if (managedHostOwned && managedHostEnv && managedHostCliPath) {
622623
await cleanupManagedGatewayInstallerHost({
623-
accountHome: managedHostLease.accountHome,
624+
accountHome: acquiredManagedHostLease.accountHome,
624625
cliPath: managedHostCliPath,
625626
env: managedHostEnv,
626627
lane,
@@ -633,7 +634,7 @@ export async function runInstallerFreshSuite(
633634
}
634635
let leaseReleaseError: Error | undefined;
635636
try {
636-
managedHostLease.release();
637+
acquiredManagedHostLease.release();
637638
} catch (error) {
638639
leaseReleaseError = error instanceof Error ? error : new Error(formatError(error));
639640
}
@@ -927,21 +928,33 @@ export function resolveManagedGatewayInstallerEnv(params: {
927928
}
928929
const accountHome = params.accountHome ?? userInfo().homedir;
929930
const hostEnv = params.hostEnv ?? process.env;
930-
return {
931+
const env: NodeJS.ProcessEnv = {
931932
...params.env,
932933
HOME: accountHome,
933934
USERPROFILE: accountHome,
934935
APPDATA: hostEnv.APPDATA,
935936
LOCALAPPDATA: hostEnv.LOCALAPPDATA,
936-
OPENCLAW_HOME: undefined,
937-
OPENCLAW_PROFILE: undefined,
938-
OPENCLAW_STATE_DIR: undefined,
939-
OPENCLAW_CONFIG_PATH: undefined,
940-
OPENCLAW_WINDOWS_TASK_NAME: undefined,
941-
OPENCLAW_TASK_SCRIPT_NAME: undefined,
942-
OPENCLAW_TASK_SCRIPT: undefined,
943-
OPENCLAW_SERVICE_KIND: undefined,
944937
};
938+
const isolatedIdentityKeys = new Set(
939+
[
940+
"OPENCLAW_HOME",
941+
"OPENCLAW_PROFILE",
942+
"OPENCLAW_STATE_DIR",
943+
"OPENCLAW_CONFIG_PATH",
944+
"OPENCLAW_WINDOWS_TASK_NAME",
945+
"OPENCLAW_TASK_SCRIPT_NAME",
946+
"OPENCLAW_TASK_SCRIPT",
947+
"OPENCLAW_SERVICE_KIND",
948+
].map((key) => key.toUpperCase()),
949+
);
950+
// Windows environment keys are case-insensitive. Remove every casing variant
951+
// so the installed CLI cannot inherit the isolated lane identity.
952+
for (const key of Object.keys(env)) {
953+
if (isolatedIdentityKeys.has(key.toUpperCase())) {
954+
delete env[key];
955+
}
956+
}
957+
return env;
945958
}
946959

947960
export function parseManagedGatewayServiceInstalled(result: CommandResult): boolean {

‎test/scripts/openclaw-cross-os-release-checks.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ describe("scripts/openclaw-cross-os-release-checks", () => {
197197
OPENCLAW_TASK_SCRIPT_NAME: "work.cmd",
198198
OPENCLAW_TASK_SCRIPT: "C:\\temp\\work.cmd",
199199
OPENCLAW_SERVICE_KIND: "node",
200+
OpenClaw_Home: "C:\\temp\\case-variant",
201+
openclaw_config_path: "C:\\temp\\case-variant\\openclaw.json",
200202
OPENAI_API_KEY: "secret",
201203
},
202204
enabled: true,
@@ -222,6 +224,20 @@ describe("scripts/openclaw-cross-os-release-checks", () => {
222224
expect(env.OPENCLAW_TASK_SCRIPT_NAME).toBeUndefined();
223225
expect(env.OPENCLAW_TASK_SCRIPT).toBeUndefined();
224226
expect(env.OPENCLAW_SERVICE_KIND).toBeUndefined();
227+
expect(
228+
Object.keys(env).filter((key) =>
229+
[
230+
"OPENCLAW_HOME",
231+
"OPENCLAW_PROFILE",
232+
"OPENCLAW_STATE_DIR",
233+
"OPENCLAW_CONFIG_PATH",
234+
"OPENCLAW_WINDOWS_TASK_NAME",
235+
"OPENCLAW_TASK_SCRIPT_NAME",
236+
"OPENCLAW_TASK_SCRIPT",
237+
"OPENCLAW_SERVICE_KIND",
238+
].includes(key.toUpperCase()),
239+
),
240+
).toEqual([]);
225241
});
226242

227243
it("keeps isolated installer state when no managed service is used", () => {

0 commit comments

Comments
 (0)