Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(dev): 开发版启动时清掉 Terminal 残留的隔离环境变量

Dash451ebf418194
diff --git a/scripts/__tests__/restart-desktop-remote.test.mjs b/scripts/__tests__/restart-desktop-remote.test.mjs
index 456272cce8..ea48c8c71b 100644
--- a/scripts/__tests__/restart-desktop-remote.test.mjs
+++ b/scripts/__tests__/restart-desktop-remote.test.mjs
@@ -15,6 +15,7 @@ import {
defaultIsolatedUserDataDir,
desktopDevCacheDirs,
devEnvPrefix,
+ darwinStaleIsolationUnset,
hasIsolationIntent,
isTrustedIsolatedAuthUserDataDir,
ISOLATED_AUTH_LAUNCH_PROOF_FILE,
@@ -1384,3 +1385,22 @@ test('Linux readiness binds the reported renderer to a live descendant in the sa
assert.equal(applyLinuxRendererEvidence(scanned, records, processes, 'darwin')[0].ready, false);
assert.equal(applyLinuxRendererEvidence(scanned, records, processes, 'win32')[0].ready, false);
});
+
+test("darwinStaleIsolationUnset clears isolation vars a long-lived Terminal may still carry", () => {
+ assert.equal(
+ darwinStaleIsolationUnset({}),
+ "unset XDT_ISOLATED XDT_ISOLATED_NAME XDT_USER_DATA_DIR XDT_DEVICE_ID_OVERRIDE XDT_ISOLATED_AUTH XDT_ISOLATED_AUTH_PROOF; ",
+ );
+ // 本次显式设了的隔离变量由 devEnvPrefix 转发,不能被清掉。
+ assert.equal(
+ darwinStaleIsolationUnset({
+ XDT_ISOLATED: "1",
+ XDT_ISOLATED_NAME: "dev",
+ XDT_USER_DATA_DIR: "/tmp/x",
+ XDT_DEVICE_ID_OVERRIDE: "d",
+ XDT_ISOLATED_AUTH: "1",
+ XDT_ISOLATED_AUTH_PROOF: "p",
+ }),
+ "",
+ );
+});
diff --git a/scripts/restart-desktop-remote.mjs b/scripts/restart-desktop-remote.mjs
index e46e0da592..6a863a17e5 100644
--- a/scripts/restart-desktop-remote.mjs
+++ b/scripts/restart-desktop-remote.mjs
@@ -853,6 +853,26 @@ function darwinEnvPrefix() {
return `export PATH=${shellSingleQuote([...new Set(preferredPathParts)].join(path.delimiter))}:"$PATH":${shellSingleQuote([...new Set(fallbackPathParts)].join(path.delimiter))}; `;
}
+/**
+ * 数据目录 / 隔离身份类变量:本次调用没设值时必须在 Terminal 命令里显式清掉。
+ * 长驻的 Terminal.app 会保留更早一次 isolated 启动留下的这些变量,而 devEnvPrefix 只
+ * 转发有值的项 —— 于是 `--shared` / `--preserve-running` 预览会悄悄落进别的 worktree
+ * 的沙箱(新 deviceId、别人的库),而不是共享正式 profile。
+ */
+const STALE_TERMINAL_ISOLATION_ENV_KEYS = Object.freeze([
+ 'XDT_ISOLATED',
+ 'XDT_ISOLATED_NAME',
+ 'XDT_USER_DATA_DIR',
+ 'XDT_DEVICE_ID_OVERRIDE',
+ 'XDT_ISOLATED_AUTH',
+ 'XDT_ISOLATED_AUTH_PROOF',
+]);
+
+export function darwinStaleIsolationUnset(env = process.env) {
+ const keys = STALE_TERMINAL_ISOLATION_ENV_KEYS.filter((key) => !env[key]);
+ return keys.length > 0 ? `unset ${keys.join(' ')}; ` : '';
+}
+
export function devEnvPrefix(env = process.env, platform = process.platform) {
const envEntries = [
// --region 经 CINDY_AUTH_REGION 注入 dev-remote-env / Forge / Vite,同一个值
@@ -940,7 +960,7 @@ function launchInSystemTerminal(mode) {
}
if (process.platform === 'darwin') {
- const command = `${darwinEnvPrefix()}cd ${shellSingleQuote(rootDir)} && ${devEnvPrefix()}${packageManagerCommand(mode)}; exitCode=$?; exit $exitCode`;
+ const command = `${darwinEnvPrefix()}${darwinStaleIsolationUnset()}cd ${shellSingleQuote(rootDir)} && ${devEnvPrefix()}${packageManagerCommand(mode)}; exitCode=$?; exit $exitCode`;
const child = spawn('osascript', osascriptLaunchDarwinTerminalArgs(command), {
detached: true,
stdio: 'ignore',