fix(organize): 同时设为作品季集结构改到执行前检查全部通过后再切换

计划一致、Move 授权、做种义务检查失败时作品结构不变;切换后按作品新结构重算一遍,前后路径与预览不一致按 plan_stale。
补测试:Move 授权不通过 / 做种义务未满足时作品结构不变。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-06 16:42:22 +08:00
1 parent f200ec695f
commit 6e21bda481
3 files changed
+67 -10

No files matched your search

@@ -517,14 +517,6 @@ export async function organizeFiles(
const now = await factsOf(frozen.facts.map((f) => f.path));
const changed = now.find((f, i) => f.size !== frozen.facts[i]!.size || f.mtimeMs !== frozen.facts[i]!.mtimeMs);
if (changed) throw new FilesError("plan_stale", `源文件在预览后发生变化:${changed.path}`);
// 同时设为作品的季集结构:先走作品级切换(单元迁移 + 重算 + 刷新),同一作品的多组只切一次
if (st?.apply && !st.switched) {
await setEpisodeGroup(d.sources(), g.entity, st.groupId, {
type: principal?.kind === "api_key" ? "api_key" : "user",
id: principal?.id ?? null,
}).catch(structureError);
st.switched = true;
}
const again = await planImport(d.ao, importReq(true));
const nowPairs = pairsOf(again).map(({ src, dst }) => ({ src, dst }));
if (hashJson(nowPairs) !== hashJson(frozen.pairs))
@@ -561,6 +553,18 @@ export async function organizeFiles(
`下载任务 ${block.downloadTaskId} 的做种义务${block.hnr === "unknown" ? "未知" : "未满足"},不能移动,也不会自动改为复制。已建待处理事项 ${block.decisionId}`,
);
}
// 同时设为作品的季集结构:所有执行前检查(计划一致、Move 授权、H&R)通过后才切换作品
// (单元迁移 + 重算 + 刷新),同一作品的多组只切一次;切换后按作品(新结构)再算一遍,前后路径须与预览一致
if (st?.apply && !st.switched) {
await setEpisodeGroup(d.sources(), g.entity, st.groupId, {
type: principal?.kind === "api_key" ? "api_key" : "user",
id: principal?.id ?? null,
}).catch(structureError);
st.switched = true;
const after = pairsOf(await planImport(d.ao, importReq(true))).map(({ src, dst }) => ({ src, dst }));
if (hashJson(after) !== hashJson(frozen.pairs))
throw new FilesError("plan_stale", "切换作品季集结构后目标路径与预览不一致。重新预览");
}
await retirePlan(d, planId);
const taskId = await ensureTaskRow(db, {
kind: "verifyAndImport",