Skip to content

The open-source full-stack studio for Opus 5.5 motion video. Reverse engineering for any video. Code video with HTML: recreate, edit and render. BYOA + BYOK · Motion.md · Images, Video, Music & Voice.

fix: preserve native history identity across requests

罗高329eb55625c7
diff --git a/shared/workspace-studio.ts b/shared/workspace-studio.ts
index 68afa51e..335c1328 100644
--- a/shared/workspace-studio.ts
+++ b/shared/workspace-studio.ts
@@ -37,9 +37,12 @@ export async function startWorkspaceStudio(runtimeRoot: string, dataDirectory: s
const host = createStudioServer({ projectDir: scoped.projectDirectory, projectName: id,
origin: () => origin, historyRoot });
const openHistory = host.adapter.history;
+ const histories = new WeakMap();
host.adapter.history = async () => {
const history = await openHistory();
- return history && withAvailableHistorySteps(history, historyRoot);
+ // Native window/close requests compare history objects by identity.
+ if (history && !histories.has(history)) histories.set(history, withAvailableHistorySteps(history, historyRoot));
+ return history && histories.get(history);
};
return host;
})().catch(error => { hosts.delete(id); throw error; });
diff --git a/tests/multi-project.test.ts b/tests/multi-project.test.ts
index f48e3fe2..bb246823 100644
--- a/tests/multi-project.test.ts
+++ b/tests/multi-project.test.ts
@@ -51,6 +51,17 @@ test('one native service keeps both projects editable, scoped and recoverable af
for (const id of [a, b]) {
const history = await fetch(`${base()}/api/projects/${id}/history`);
assert.equal(history.status, 200, await history.clone().text());
+ const postHistory = (projectId: string, action: string) => fetch(`${base()}/api/projects/${projectId}/history/${action}`, {
+ method: 'POST', headers: { Origin: base(), 'Content-Type': 'application/json' }, body: JSON.stringify({ label: 'Agent edit', exclusive: true }),
+ });
+ const opened = await postHistory(id, 'window');
+ assert.equal(opened.status, 200, await opened.clone().text());
+ const { windowId } = await opened.json();
+ assert.equal((await postHistory(id === a ? b : a, `window/${windowId}/close`)).status, 409);
+ await writeFile(path.join(store.projectDirectoryFor(id), 'notes.txt'), `Updated by ${id}`);
+ const closed = await postHistory(id, `window/${windowId}/close`);
+ assert.equal(closed.status, 200, await closed.clone().text());
+ assert.ok((await closed.json()).entry, 'a history window must survive separate requests for its own project');
}
for (const id of [crypto.randomUUID(), '..%2Fescape']) {
assert.ok([400, 404].includes((await fetch(`${base()}/api/projects/${id}/files/index.html`)).status));