makecindy / makecindy/cindy

fix(desktop): 补回随 #441 回退一起丢掉的两处正交加固(isolated userData 绝对路径 / passive 只读 skip)

Open
#450 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2.7k
Forks
395
Avg merge
21h 48m
Merged PRs (30d)
776

Description

## 背景

PR #441(squash `43cf161`)完整回退了 #409。回退是按「不扩大范围」执行的,因此 #409 里两处
**与「是否阻断共享 primary dev」正交**的加固也被一起退掉了。这两条与本次架构决策(#446)无关,
应单独补回。

## 待修 1:isolated userData 目录可能落到相对路径

`scripts/restart-desktop-remote.mjs` 的 `defaultIsolatedUserDataDir` 回到了「env 缺失时 `|| ''`」的写法:

- Windows:`APPDATA` 与 `USERPROFILE` 都缺 → `path.join('', 'AppData', 'Roaming', dirName)` = 相对路径
- macOS:`HOME` 缺 → `Library/Application Support/` 相对路径
- Linux:`XDG_CONFIG_HOME` 与 `HOME` 都缺 → `.config/` 相对路径

随后该值被 `mkdirSync` 创建并导出为 `XDT_USER_DATA_DIR`,于是**登录态与用户数据可能被写到当前工作目录
(可能就是仓库内)**。#409 曾用 `resolveDesktopUserDataRoot()` 收敛:回退到 `os.homedir()`,仍非绝对路径则抛错。

**建议**:把绝对路径保证(`os.homedir()` fallback + 非绝对即抛错)单独补回,并覆盖三平台缺 env 的单测。
风险等级参照 `docs/dev-rules/credentials-and-local-storage.md`(凭证/用户数据落盘位置)。

## 待修 2:passive 共库预览的只读契约在 legacy 迁移这一环失效

`apps/desktop/src/main/legacyUserDataMigration.ts` 的 `shouldSkipLegacyMigrationForDevSandbox` 不再读
`XDT_PASSIVE_SHARED_USER_DATA`,但 `apps/desktop/src/main/index.ts` 仍在 passive 时设置该 env
(`shouldEnforcePassiveMigrationCompatibility` 路径)。即:**env 还在设,消费方没了**。

后果:非 packaged 的 `--passive` / `--preserve-running` 共用默认 userData、该 profile 尚无 `mToc` marker
且存在 legacy `xdt-maker` 数据时,passive 实例会弹确认窗并复制主库 / cindy-media / dialogues /
浏览器 profile 并写 marker —— 直接改动本应只读的共享数据,且此时可能有另一个 Cindy 实例正在运行。

**建议**:把 `envPassiveSharedUserData === '1'` 的 skip 分支单独补回(或显式确认不再需要该 env 并一并清掉
`index.ts` 的设置,避免"半截"状态),并补回对应单测。

## 不在本 issue 范围

「共享库 migration 安全约束」的整体重建(#446 讨论的那部分)不在这里 —— 那需要以「对齐已安装 release 的
migration 历史」为设计前提,并统一覆盖 `dev:desktop:remote` 等所有 dev entry point,应单独设计。

---
关联:#409(原加固)、#441(回退)、#446(架构决策)。

Contributor guide

Open the contributing guide

Research direction

Start with scripts/restart-desktop-remote.mjs and the tests covering defaultIsolatedUserDataDir on Windows, macOS, and Linux; verify the fallback remains absolute when environment variables are missing. Then read apps/desktop/src/main/legacyUserDataMigration.ts alongside index.ts and its migration tests, and confirm passive shared profiles skip legacy migration without changing shared data.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, typescript
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.