mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-03 21:10:37 +08:00
fix(desktop): dev writer 不得把正式 profile 升到安装版没有的 schema
已合入 main、但安装包还没带上的 migration 同样会打挂正式版。 unpackaged writer 在正式目录发现 pending 时 fail closed,改走 isolated。 Signed-off-by: Dash <dashhuang@gmail.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
officialProfileWriterMigrationMessage,
|
||||
shouldRefuseOfficialProfileWriterMigration,
|
||||
} from '../localDb/officialProfileMigrationPolicy';
|
||||
|
||||
describe('shouldRefuseOfficialProfileWriterMigration', () => {
|
||||
it('unpackaged writer + 正式 profile + pending 必须拒绝', () => {
|
||||
expect(
|
||||
shouldRefuseOfficialProfileWriterMigration({
|
||||
isPackaged: false,
|
||||
officialSharedProfile: true,
|
||||
pendingCount: 1,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('schema 已对齐时允许打开正式 profile', () => {
|
||||
expect(
|
||||
shouldRefuseOfficialProfileWriterMigration({
|
||||
isPackaged: false,
|
||||
officialSharedProfile: true,
|
||||
pendingCount: 0,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('packaged / 沙箱 / custom 仍可迁', () => {
|
||||
expect(
|
||||
shouldRefuseOfficialProfileWriterMigration({
|
||||
isPackaged: true,
|
||||
officialSharedProfile: true,
|
||||
pendingCount: 3,
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldRefuseOfficialProfileWriterMigration({
|
||||
isPackaged: false,
|
||||
officialSharedProfile: false,
|
||||
pendingCount: 3,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('officialProfileWriterMigrationMessage', () => {
|
||||
it('点名待执行 migration 并指向 isolated', () => {
|
||||
const message = officialProfileWriterMigrationMessage(['0091_amazing_blur.sql']);
|
||||
expect(message).toContain('0091_amazing_blur.sql');
|
||||
expect(message).toContain('--isolated=');
|
||||
});
|
||||
});
|
||||
|
||||
describe('official profile writer wiring', () => {
|
||||
it('index 对正式 profile 落地 XDT_OFFICIAL_SHARED_PROFILE,migrate 在备份前拒绝', () => {
|
||||
const indexSource = readFileSync(resolve(process.cwd(), 'src/main/index.ts'), 'utf8');
|
||||
const migrateSource = readFileSync(
|
||||
resolve(process.cwd(), 'src/main/localDb/migrate.ts'),
|
||||
'utf8',
|
||||
);
|
||||
expect(indexSource).toContain("process.env.XDT_OFFICIAL_SHARED_PROFILE = '1'");
|
||||
const refuseIdx = migrateSource.indexOf('shouldRefuseOfficialProfileWriterMigration');
|
||||
const backupIdx = migrateSource.indexOf('await backupDb(');
|
||||
expect(refuseIdx).toBeGreaterThan(-1);
|
||||
expect(backupIdx).toBeGreaterThan(refuseIdx);
|
||||
});
|
||||
});
|
||||
@@ -112,6 +112,13 @@ if (devFlags.isolatedOnProductionProfile) {
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
if (!app.isPackaged && devFlags.profileKind === 'production-shared') {
|
||||
// 正式 profile 上的 unpackaged writer 不得应用 pending migration。
|
||||
// 已合入 main、但安装包还没带上的序号会把安装版打挂(2026-08-16 schema 91)。
|
||||
process.env.XDT_OFFICIAL_SHARED_PROFILE = '1';
|
||||
} else {
|
||||
delete process.env.XDT_OFFICIAL_SHARED_PROFILE;
|
||||
}
|
||||
if (devFlags.schedulerPassive) {
|
||||
// 统一收敛到 env:scheduler-host 只认 XDT_SCHEDULER_PASSIVE,不重复解析 argv。
|
||||
process.env.XDT_SCHEDULER_PASSIVE = '1';
|
||||
|
||||
@@ -32,6 +32,10 @@ import {
|
||||
readSchemaVersion,
|
||||
runMigrationReplay,
|
||||
} from './migrationRunner';
|
||||
import {
|
||||
officialProfileWriterMigrationMessage,
|
||||
shouldRefuseOfficialProfileWriterMigration,
|
||||
} from './officialProfileMigrationPolicy';
|
||||
|
||||
const log = createLogger('migrate');
|
||||
|
||||
@@ -92,6 +96,17 @@ export async function runMigrations(
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
shouldRefuseOfficialProfileWriterMigration({
|
||||
isPackaged: app.isPackaged,
|
||||
officialSharedProfile: process.env.XDT_OFFICIAL_SHARED_PROFILE === '1',
|
||||
pendingCount: pending.length,
|
||||
})
|
||||
) {
|
||||
throw new Error(
|
||||
officialProfileWriterMigrationMessage(pending.map((migration) => migration.fileName)),
|
||||
);
|
||||
}
|
||||
|
||||
// 备份前先做磁盘侧准备:腾旧备份预算 + 剩余空间预检。
|
||||
// 背景(2026-07 用户现场):旧流程只在迁移成功后清理旧备份——一旦备份把磁盘
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 正式 profile 上的 dev writer 不得应用 pending migration。
|
||||
*
|
||||
* 2026-08-16:含 0091 的 checkout 以 writer 打开正式 Cindy 目录,把安装版
|
||||
* 0.1.50(只到 0090)打挂。`assertSharedDevMigrationPolicy` 只拦「未合入
|
||||
* origin/main」的产物;已合入主干、但安装包还没带上的 migration 照样会写进
|
||||
* 共享库。这一层看真实 profile + pending,不看 isolated 旗标。
|
||||
*/
|
||||
export function shouldRefuseOfficialProfileWriterMigration(input: {
|
||||
isPackaged: boolean;
|
||||
officialSharedProfile: boolean;
|
||||
pendingCount: number;
|
||||
}): boolean {
|
||||
return !input.isPackaged && input.officialSharedProfile && input.pendingCount > 0;
|
||||
}
|
||||
|
||||
export function officialProfileWriterMigrationMessage(pendingNames: readonly string[]): string {
|
||||
const pending = pendingNames.length > 0 ? pendingNames.join(', ') : '(unknown)';
|
||||
return (
|
||||
`开发版不能把正式 Cindy 目录的数据库升到当前 checkout 的 schema(待执行 ${pending})。` +
|
||||
'请改用 --isolated=<名字>,或等包含这些 migration 的正式版发布后再用共享目录。'
|
||||
);
|
||||
}
|
||||
@@ -90,6 +90,10 @@ companion CommonJS 格式和历史 runtime identity 冻结;不能用单独 typ
|
||||
|
||||
- 未进入 `main` 的 migration 禁止连接共享 Cindy userData 运行;否则分支换号或回退后会让
|
||||
本地 `schema_version` 与真实结构永久分叉。
|
||||
- **已合入 `main`、但安装包还没带上的 migration 同样不得写进正式 profile。** unpackaged
|
||||
writer 在 Cindy / CindyGlobal / CindyDev 上发现 pending 就 fail closed(2026-08-16:
|
||||
checkout 带着 0091 把 0.1.50 的共享库升到 91,安装版打不开)。要验证新 schema 必须
|
||||
`--isolated[=<名字>]`;等正式版发布后再用共享目录。
|
||||
- 需要启动验证时,按照 `desktop-development.md` 的参数说明使用显式
|
||||
`--isolated[=<名字>]` 沙箱。migration replay 自身使用临时数据库,不污染用户数据。
|
||||
- 不得为了测试 migration 临时改写、降级或删除用户数据库;需要历史状态时新增最小 fixture。
|
||||
|
||||
@@ -76,6 +76,8 @@ Cindy 内部而拒绝重启,或因目标 userData 被其他 checkout 占用而
|
||||
|
||||
正式版目录保持历史兼容:CN → `Cindy`,Global → `CindyGlobal`,不在启动时改名或搬迁用户数据。
|
||||
非隔离 dev 也使用当前区域对应的正式 profile;`--isolated` 沙箱再按相同区域映射派生目录。
|
||||
**dev writer 不得把正式 profile 升到当前 checkout 比安装版更新的 schema**:有 pending
|
||||
migration 就拒绝启动,改用 `--isolated=<名字>`。`--preserve-running` / 共库 passive 仍只读。
|
||||
跨区域共享、登录态迁移或旧版本回滚应使用显式隔离目录,避免不同构建误用同一 profile。
|
||||
|
||||
### 并行多开 dev
|
||||
|
||||
Reference in New Issue
Block a user