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(desktop): 正式 profile 从 appData 派生,不跟当前 userData 覆走

Dashd0abdb78e030
diff --git a/apps/desktop/src/main/__tests__/devCliFlags.test.ts b/apps/desktop/src/main/__tests__/devCliFlags.test.ts
index a12582586e..5a14e293f1 100644
--- a/apps/desktop/src/main/__tests__/devCliFlags.test.ts
+++ b/apps/desktop/src/main/__tests__/devCliFlags.test.ts
@@ -34,6 +34,7 @@ const base = {
isPackaged: false,
envUserDataDir: undefined as string | undefined,
defaultUserDataDir: '/AppData/Cindy',
+ appDataDir: '/AppData',
envIsolated: undefined as string | undefined,
envIsolationName: undefined as string | undefined,
envUserDataDirEpoch: undefined as string | undefined,
@@ -68,6 +69,21 @@ describe('resolveDevCliFlags', () => {
expect(flags.userDataDirOverride).toBeNull();
});
+ it('原生 --user-data-dir 自定义默认 + XDT_USER_DATA_DIR 指向正式目录,仍判正式 profile',
+ () => {
+ const flags = resolveDevCliFlags({
+ ...base,
+ defaultUserDataDir: '/tmp/custom-profile',
+ appDataDir: '/AppData',
+ argv: [...base.argv, '--isolated'],
+ envUserDataDir: '/AppData/Cindy',
+ });
+ expect(flags.profileKind).toBe('production-shared');
+ expect(flags.isolatedOnProductionProfile).toBe(true);
+ expect(flags.needsIsolatedDeviceId).toBe(true);
+ },
+ );
+
it('--passive 只开被动,不动 userData / 设备标识', () => {
const flags = resolveDevCliFlags({ ...base, argv: [...base.argv, '--passive'] });
expect(flags.schedulerPassive).toBe(true);
diff --git a/apps/desktop/src/main/__tests__/isolatedOnProductionProfileStartup.test.ts b/apps/desktop/src/main/__tests__/isolatedOnProductionProfileStartup.test.ts
index 7dcff15828..fcbd4cb13b 100644
--- a/apps/desktop/src/main/__tests__/isolatedOnProductionProfileStartup.test.ts
+++ b/apps/desktop/src/main/__tests__/isolatedOnProductionProfileStartup.test.ts
@@ -20,6 +20,7 @@ describe('isolated-on-production-profile startup refuse', () => {
expect(refuseIdx).toBeGreaterThan(-1);
expect(setPathIdx).toBeGreaterThan(refuseIdx);
expect(deviceIdx).toBeGreaterThan(refuseIdx);
+ expect(indexSource).toContain("appDataDir: app.getPath('appData')");
expect(indexSource).toContain("isolated: devFlags.profileKind === 'isolated-sandbox'");
expect(indexSource).toContain('isolationIntent: devFlags.isolated');
expect(indexSource).toContain('profileKind: devFlags.profileKind');
diff --git a/apps/desktop/src/main/devCliFlags.ts b/apps/desktop/src/main/devCliFlags.ts
index 01c30de2e1..1557e527d5 100644
--- a/apps/desktop/src/main/devCliFlags.ts
+++ b/apps/desktop/src/main/devCliFlags.ts
@@ -131,6 +131,12 @@ export interface DevCliFlagsInput {
canonicalizePath?: (p: string) => string;
/** app.getPath('userData') 的默认值;隔离模式在其后缀 '-dev2[-<名字>]' 生成沙箱目录。 */
defaultUserDataDir: string;
+ /**
+ * Electron app.getPath('appData')。正式 profile 只从这里派生 Cindy /
+ * CindyGlobal / CindyDev,不得用当前 userData 覆写的父目录猜。
+ * 缺省回落到 dirname(defaultUserDataDir),仅给旧测试。
+ */
+ appDataDir?: string;
/**
* XDT_ISOLATED 环境变量:严格 '1' = 隔离开关开,其它任何值(含 '0'/'false'/名字)
* 一律视为关。名字**不**挤在这个变量里——否则名叫 "1" 的沙箱会和开关标记值撞车
@@ -254,12 +260,11 @@ export function shouldEnforcePassiveMigrationCompatibility(input: {
return !input.isPackaged && input.schedulerPassive && input.profileKind !== 'isolated-sandbox';
}
-export function resolveOfficialUserDataDirs(defaultUserDataDir: string): string[] {
- const parent = dirname(defaultUserDataDir);
- // 只认已知正式目录名。不能把运行时 defaultUserDataDir 无条件算进去:
- // 原生 `--user-data-dir=/tmp/custom` 会让 app.getPath('userData') 变成自定义
- // 目录,再把它标成 production-shared 会误拦 pending migration。
- return OFFICIAL_USER_DATA_DIR_NAMES.map((name) => join(parent, name));
+export function resolveOfficialUserDataDirs(appDataDir: string): string[] {
+ // 正式集合永远从 appData 派生。不能用当前 userData 覆写的父目录猜:
+ // `--user-data-dir=/tmp/custom` + `XDT_USER_DATA_DIR=$HOME/.../Cindy` 时,
+ // 用 /tmp 当父目录会把真正的 Cindy 目录判成 custom。
+ return OFFICIAL_USER_DATA_DIR_NAMES.map((name) => join(appDataDir, name));
}
function isOfficialUserDataDir(
@@ -271,32 +276,46 @@ function isOfficialUserDataDir(
return officialDirs.some((official) => canonicalize(official) === target);
}
+function officialDirsFromInput(input: {
+ officialUserDataDirs?: readonly string[];
+ appDataDir?: string;
+ productionUserDataDir?: string;
+ effectiveUserDataDir?: string;
+}): readonly string[] {
+ if (input.officialUserDataDirs) return input.officialUserDataDirs;
+ const appDataDir =
+ input.appDataDir ??
+ dirname(input.productionUserDataDir ?? input.effectiveUserDataDir ?? '');
+ return resolveOfficialUserDataDirs(appDataDir);
+}
+
export function isIsolatedIdentityOnProductionProfile(input: {
isolated: boolean;
effectiveUserDataDir: string;
productionUserDataDir?: string;
+ appDataDir?: string;
officialUserDataDirs?: readonly string[];
canonicalizePath?: (value: string) => string;
}): boolean {
if (!input.isolated) return false;
const canonicalize = input.canonicalizePath ?? defaultCanonicalizePath;
- const officialDirs =
- input.officialUserDataDirs ??
- resolveOfficialUserDataDirs(input.productionUserDataDir ?? input.effectiveUserDataDir);
- return isOfficialUserDataDir(input.effectiveUserDataDir, officialDirs, canonicalize);
+ return isOfficialUserDataDir(
+ input.effectiveUserDataDir,
+ officialDirsFromInput(input),
+ canonicalize,
+ );
}
export function resolveDevProfileKind(input: {
isolatedDirIsEpochDerived: boolean;
effectiveUserDataDir: string;
productionUserDataDir?: string;
+ appDataDir?: string;
officialUserDataDirs?: readonly string[];
canonicalizePath?: (value: string) => string;
}): DevProfileKind {
const canonicalize = input.canonicalizePath ?? defaultCanonicalizePath;
- const officialDirs =
- input.officialUserDataDirs ??
- resolveOfficialUserDataDirs(input.productionUserDataDir ?? input.effectiveUserDataDir);
+ const officialDirs = officialDirsFromInput(input);
if (isOfficialUserDataDir(input.effectiveUserDataDir, officialDirs, canonicalize)) {
return 'production-shared';
}
@@ -379,7 +398,9 @@ export function resolveDevCliFlags(input: DevCliFlagsInput): DevCliFlags {
userDataDirOverride !== null &&
canonicalize(userDataDirOverride) === canonicalize(epochDerivedDir);
const effectiveUserDataDir = userDataDirOverride ?? input.defaultUserDataDir;
- const officialUserDataDirs = resolveOfficialUserDataDirs(input.defaultUserDataDir);
+ const officialUserDataDirs = resolveOfficialUserDataDirs(
+ input.appDataDir ?? dirname(input.defaultUserDataDir),
+ );
const isolatedOnProductionProfile = isIsolatedIdentityOnProductionProfile({
isolated,
effectiveUserDataDir,
diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.ts
index 2c4ef8fad5..9e65172c0b 100644
--- a/apps/desktop/src/main/index.ts
+++ b/apps/desktop/src/main/index.ts
@@ -94,6 +94,7 @@ const devFlags = resolveDevCliFlags({
isPackaged: app.isPackaged,
envUserDataDir: process.env.XDT_USER_DATA_DIR,
defaultUserDataDir: app.getPath('userData'),
+ appDataDir: app.getPath('appData'),
envIsolated: process.env.XDT_ISOLATED,
envIsolationName: process.env.XDT_ISOLATED_NAME,
envUserDataDirEpoch: process.env.XDT_USER_DATA_DIR_EPOCH,