Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Keep scene renames out of drafts

Bitti5ec6747c6013
diff --git a/src/lib/sceneHistory.test.ts b/src/lib/sceneHistory.test.ts
index 6d8fdeb..9faa3b7 100644
--- a/src/lib/sceneHistory.test.ts
+++ b/src/lib/sceneHistory.test.ts
@@ -29,6 +29,42 @@ const edit = (config: ProjectConfig, music: string) => saveSceneDrafts({ ...conf
shots: j.shots!.map(shot => ({ ...shot, action: music, speech: `${music} speech` })) })) }, config);
describe("scene generation history", () => {
+ it.each([false, true])("renames a scene without creating a draft, including legacy history %s", legacy => {
+ const config = finish(initial(), "one");
+ if (legacy) delete config.generationJobs[0].generationHistory;
+ const originalTitle = config.generationJobs[0].title;
+ const session = new ProjectSession({ folderPath: "C:/history", config }, vi.fn(async () => {}));
+ session.edit(current => ({ ...current, generationJobs: current.generationJobs.map(job => ({ ...job, title: "Renamed scene" })) }));
+ const renamed = parseProjectConfig(JSON.parse(JSON.stringify(session.getSnapshot().config))).generationJobs[0];
+ expect(renamed.title).toBe("Renamed scene");
+ expect(renamed.generationHistory!.selectedId).toBe(renamed.generationHistory!.primaryId);
+ expect(renamed.generationHistory!.draft).toBeNull();
+ expect(renamed.generationHistory!.versions).toHaveLength(1);
+ expect(session.undo()).toBe(true);
+ expect(session.getSnapshot().config.generationJobs[0].title).toBe(originalTitle);
+ expect(session.redo()).toBe(true);
+ expect(session.getSnapshot().config.generationJobs[0]).toMatchObject({ title: "Renamed scene", generationHistory: { draft: null } });
+ });
+
+ it("keeps the renamed scene title when switching takes and restoring an existing draft", () => {
+ let config = edit(finish(edit(initial(), "First"), "one"), "Pending");
+ const id = config.generationJobs[0].id, draft = config.generationJobs[0].generationHistory!.draft;
+ config = saveSceneDrafts({ ...config, generationJobs: config.generationJobs.map(job => ({ ...job, title: "Renamed scene" })) }, config);
+ expect(config.generationJobs[0].generationHistory!.draft).toBe(draft);
+ config = selectSceneGeneration(config, id, "one");
+ expect(config.generationJobs[0]).toMatchObject({ title: "Renamed scene", music: "First", generationHistory: { selectedId: "one" } });
+ config = selectSceneGeneration(config, id, null);
+ expect(config.generationJobs[0]).toMatchObject({ title: "Renamed scene", music: "Pending", generationHistory: { selectedId: null } });
+ });
+
+ it("selects a completed take without creating a draft after renaming during generation", () => {
+ let config = finish(initial(), "one");
+ const submitted = take(config, "two"), id = config.generationJobs[0].id;
+ config = { ...config, generationJobs: config.generationJobs.map(job => ({ ...job, title: "Renamed while rendering", status: "generating" as const })) };
+ config = completeSceneGeneration(config, id, submitted);
+ expect(config.generationJobs[0]).toMatchObject({ title: "Renamed while rendering", generationHistory: { selectedId: "two", primaryId: "two", draft: null } });
+ });
+
it("removes an unselected take without changing the primary or current draft", () => {
let config = finish(edit(initial(), "First"), "one");
config = edit(finish(edit(config, "Second"), "two"), "Pending");
diff --git a/src/lib/sceneHistory.ts b/src/lib/sceneHistory.ts
index 09bdabe..7e6ebc7 100644
--- a/src/lib/sceneHistory.ts
+++ b/src/lib/sceneHistory.ts
@@ -8,12 +8,14 @@ function canonical(value: unknown): unknown {
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).filter(([, v]) => v != null).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => [k, canonical(v)]));
return value;
}
-export const sameSceneInput = (a: SceneInput, b: SceneInput) => JSON.stringify(canonical(a)) === JSON.stringify(canonical(b));
+// The scene name is metadata shared by all takes, not a generation setting.
+export const sameSceneInput = (a: SceneInput, b: SceneInput) =>
+ JSON.stringify(canonical({ ...a, title: undefined })) === JSON.stringify(canonical({ ...b, title: undefined }));
function applyInput(job: GenerationJob, input: SceneInput): GenerationJob {
// Delete absent optional controls too: a newer take may have added one.
const next = { ...job };
for (const key of Object.keys(sceneInputSchema.shape)) delete (next as unknown as Record<string, unknown>)[key];
- return { ...next, ...structuredClone(input), updatedAt: new Date().toISOString() };
+ return { ...next, ...structuredClone(input), title: job.title, updatedAt: new Date().toISOString() };
}
/** Adopt old projects' existing result before any edit or new generation. */