From ab1ed65e3d9c4777b36346a99ef3b991e445ef6d Mon Sep 17 00:00:00 2001 From: bymyself Date: Sun, 1 Nov 2026 06:36:30 +0000 Subject: [PATCH 1/5] test: unedited saved workflows reopen as saved after a reload Switching tabs writes a draft for the outgoing workflow even when it is unedited. After a reload that draft equals the saved file, yet loading it marks the workflow modified. --- .../tests/workflowPersistence.spec.ts | 53 +++++++++++++++++++ .../management/stores/workflowStore.test.ts | 50 +++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/browser_tests/tests/workflowPersistence.spec.ts b/browser_tests/tests/workflowPersistence.spec.ts index 978a7cc8b20..4dfd0e61b79 100644 --- a/browser_tests/tests/workflowPersistence.spec.ts +++ b/browser_tests/tests/workflowPersistence.spec.ts @@ -1014,6 +1014,59 @@ test.describe('Workflow Persistence', () => { await expect(comfyPage.toast.toastErrors).toHaveCount(0) }) + test('Unedited saved workflows reopen as saved after a reload', async ({ + comfyPage + }) => { + test.info().annotations.push({ + type: 'regression', + description: + 'Switching tabs leaves a draft equal to the saved file; after a reload that draft marked the workflow unsaved' + }) + test.setTimeout(45_000) + + await comfyPage.settings.setSetting('Comfy.UseNewMenu', 'Top') + await comfyPage.settings.setSetting('Comfy.Workflow.Persist', true) + await comfyPage.settings.setSetting( + 'Comfy.Workflow.WorkflowTabsPosition', + 'Topbar' + ) + + const names = [ + generateUniqueFilename(), + generateUniqueFilename(), + generateUniqueFilename() + ] + await comfyPage.menu.topbar.saveWorkflow(names[0]) + for (const name of names.slice(1)) { + await comfyPage.menu.topbar.triggerTopbarCommand(['New']) + await comfyPage.menu.topbar.saveWorkflow(name) + } + + // Visit every tab without editing: each switch writes the outgoing + // tab's draft. + for (const name of names) { + await comfyPage.menu.topbar.getWorkflowTab(name).click() + await comfyPage.workflow.waitForWorkflowIdle() + expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) + } + await waitForWorkflowTabState(comfyPage, names.length) + await expect + .poll(async () => (await comfyPage.workflow.getDraftWorkflows()).length) + .toBeGreaterThanOrEqual(2) + + await comfyPage.workflow.reloadAndWaitForApp() + + for (const name of names.slice(0, 2)) { + await comfyPage.menu.topbar.getWorkflowTab(name).click() + await comfyPage.workflow.waitForWorkflowIdle() + await expect + .poll(() => comfyPage.menu.topbar.getActiveTabName()) + .toBe(name) + expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) + await expect.poll(() => comfyPage.page.title()).not.toMatch(/^\*/) + } + }) + test('Flushes a pending draft edit before an immediate reload', async ({ comfyPage }) => { diff --git a/src/platform/workflow/management/stores/workflowStore.test.ts b/src/platform/workflow/management/stores/workflowStore.test.ts index 11e33c44ef8..5e7b2425cdb 100644 --- a/src/platform/workflow/management/stores/workflowStore.test.ts +++ b/src/platform/workflow/management/stores/workflowStore.test.ts @@ -503,6 +503,56 @@ describe('useWorkflowStore', () => { expect(workflow.isModified).toBe(true) }) + // Switching tabs writes a draft for every open workflow, edited or not, + // so after a reload an unedited saved workflow has a draft equal to its + // file. That draft must not mark the workflow unsaved. + it('does not mark a saved workflow modified when its draft matches the file', async () => { + enableWorkflowPersistence() + await syncRemoteWorkflowsWithMeta([ + { path: 'a.json', modified: 100, size: 1 } + ]) + const workflow = store.getWorkflowByPath('workflows/a.json')! + saveV2Draft(workflow.path, { data: defaultGraphJSON, name: 'a.json' }) + vi.mocked(api.getUserData).mockResolvedValue({ + status: 200, + text: () => Promise.resolve(defaultGraphJSON) + } as Response) + + await workflow.load() + + expect(workflow.activeState).toEqual(defaultGraph) + expect(workflow.isModified).toBe(false) + }) + + it('keeps the draft viewport without marking the workflow modified', async () => { + enableWorkflowPersistence() + await syncRemoteWorkflowsWithMeta([ + { path: 'a.json', modified: 100, size: 1 } + ]) + const workflow = store.getWorkflowByPath('workflows/a.json')! + const draftGraph = JSON.parse(defaultGraphJSON) + draftGraph.extra = { + ...draftGraph.extra, + ds: { scale: 2.5, offset: [40, -80] } + } + saveV2Draft(workflow.path, { + data: JSON.stringify(draftGraph), + name: 'a.json' + }) + vi.mocked(api.getUserData).mockResolvedValue({ + status: 200, + text: () => Promise.resolve(defaultGraphJSON) + } as Response) + + await workflow.load() + + expect(workflow.activeState?.extra?.ds).toEqual({ + scale: 2.5, + offset: [40, -80] + }) + expect(workflow.isModified).toBe(false) + }) + it('should discard a stale V2 draft when the remote workflow is newer', async () => { enableWorkflowPersistence() const remoteModifiedAt = Date.now() + 60_000 From c72a6371df8fb97252c65d439e87f027c2e19827 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sun, 1 Nov 2026 06:46:29 +0000 Subject: [PATCH 2/5] fix: do not mark a saved workflow unsaved when its draft matches the file ComfyWorkflow.load() set isModified whenever a draft existed. Tab switches write drafts for unedited workflows, so after a reload those workflows showed the unsaved dot, a * title, a save prompt on close and the leave-site prompt. Compare the draft with the saved file using the change tracker's graphEqual, the same check that decides unsaved changes for live edits (it ignores the viewport, so a draft that only moved the view still restores that view). Tests: a draft that only changes app mode still marks the workflow modified; the browser test also checks the tab that was active at the reload, and test comments became step names. --- .../tests/workflowPersistence.spec.ts | 41 +++++++++++-------- .../management/stores/comfyWorkflow.ts | 6 +-- .../management/stores/workflowStore.test.ts | 23 +++++++++++ .../management/stores/workflowStore.ts | 1 + src/scripts/changeTrackerAccess.ts | 4 ++ 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/browser_tests/tests/workflowPersistence.spec.ts b/browser_tests/tests/workflowPersistence.spec.ts index 4dfd0e61b79..aa70eb4a678 100644 --- a/browser_tests/tests/workflowPersistence.spec.ts +++ b/browser_tests/tests/workflowPersistence.spec.ts @@ -1042,28 +1042,37 @@ test.describe('Workflow Persistence', () => { await comfyPage.menu.topbar.saveWorkflow(name) } - // Visit every tab without editing: each switch writes the outgoing - // tab's draft. - for (const name of names) { - await comfyPage.menu.topbar.getWorkflowTab(name).click() - await comfyPage.workflow.waitForWorkflowIdle() - expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) - } - await waitForWorkflowTabState(comfyPage, names.length) - await expect - .poll(async () => (await comfyPage.workflow.getDraftWorkflows()).length) - .toBeGreaterThanOrEqual(2) + await test.step('visit every tab without editing, leaving drafts behind', async () => { + for (const name of names) { + await comfyPage.menu.topbar.getWorkflowTab(name).click() + await comfyPage.workflow.waitForWorkflowIdle() + expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) + } + await waitForWorkflowTabState(comfyPage, names.length) + await expect + .poll(async () => (await comfyPage.workflow.getDraftWorkflows()).length) + .toBeGreaterThanOrEqual(2) + }) await comfyPage.workflow.reloadAndWaitForApp() - for (const name of names.slice(0, 2)) { - await comfyPage.menu.topbar.getWorkflowTab(name).click() - await comfyPage.workflow.waitForWorkflowIdle() + await test.step('the tab active at reload is restored as saved', async () => { await expect .poll(() => comfyPage.menu.topbar.getActiveTabName()) - .toBe(name) + .toBe(names[2]) expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) - await expect.poll(() => comfyPage.page.title()).not.toMatch(/^\*/) + }) + + for (const name of names.slice(0, 2)) { + await test.step(`restored tab ${name} reopens as saved`, async () => { + await comfyPage.menu.topbar.getWorkflowTab(name).click() + await comfyPage.workflow.waitForWorkflowIdle() + await expect + .poll(() => comfyPage.menu.topbar.getActiveTabName()) + .toBe(name) + expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) + expect(await comfyPage.page.title()).not.toMatch(/^\*/) + }) } }) diff --git a/src/platform/workflow/management/stores/comfyWorkflow.ts b/src/platform/workflow/management/stores/comfyWorkflow.ts index 4b25bc33ab3..6b91b0928c8 100644 --- a/src/platform/workflow/management/stores/comfyWorkflow.ts +++ b/src/platform/workflow/management/stores/comfyWorkflow.ts @@ -82,6 +82,8 @@ export interface WorkflowRuntime { workflow: ComfyWorkflow, initialState: ComfyWorkflowJSON ): WorkflowChangeTracker + /** `ChangeTracker.graphEqual`: the comparison that decides unsaved changes. */ + graphEqual(a: ComfyWorkflowJSON, b: ComfyWorkflowJSON): boolean getDraft(path: string): WorkflowDraft | null removeDraft(path: string): void markDraftUsed(path: string): void @@ -365,9 +367,7 @@ export class ComfyWorkflow extends UserFile { if (draft?.state && draft.content) { this.changeTracker.activeState = draft.state this.content = draft.content - this._isModified = true - // Saved-workflow draft overlay path; direct persisted-draft restores - // are touched in workflowDraftStoreV2.loadDraft(). + this._isModified = !runtime.graphEqual(initialState, draft.state) runtime.markDraftUsed(this.path) } return this as this & LoadedComfyWorkflow diff --git a/src/platform/workflow/management/stores/workflowStore.test.ts b/src/platform/workflow/management/stores/workflowStore.test.ts index 5e7b2425cdb..17d53f79679 100644 --- a/src/platform/workflow/management/stores/workflowStore.test.ts +++ b/src/platform/workflow/management/stores/workflowStore.test.ts @@ -553,6 +553,29 @@ describe('useWorkflowStore', () => { expect(workflow.isModified).toBe(false) }) + it('marks a saved workflow modified when its draft only changes app mode', async () => { + enableWorkflowPersistence() + await syncRemoteWorkflowsWithMeta([ + { path: 'a.json', modified: 100, size: 1 } + ]) + const workflow = store.getWorkflowByPath('workflows/a.json')! + const draftGraph = JSON.parse(defaultGraphJSON) + draftGraph.extra = { ...draftGraph.extra, linearMode: true } + saveV2Draft(workflow.path, { + data: JSON.stringify(draftGraph), + name: 'a.json' + }) + vi.mocked(api.getUserData).mockResolvedValue({ + status: 200, + text: () => Promise.resolve(defaultGraphJSON) + } as Response) + + await workflow.load() + + expect(workflow.activeState?.extra?.linearMode).toBe(true) + expect(workflow.isModified).toBe(true) + }) + it('should discard a stale V2 draft when the remote workflow is newer', async () => { enableWorkflowPersistence() const remoteModifiedAt = Date.now() + 60_000 diff --git a/src/platform/workflow/management/stores/workflowStore.ts b/src/platform/workflow/management/stores/workflowStore.ts index 13b2c62b345..a1d636ed939 100644 --- a/src/platform/workflow/management/stores/workflowStore.ts +++ b/src/platform/workflow/management/stores/workflowStore.ts @@ -55,6 +55,7 @@ export { ComfyWorkflow, type LoadedComfyWorkflow } registerWorkflowRuntime({ createChangeTracker: (workflow, initialState) => new ChangeTrackerAccess(workflow, initialState), + graphEqual: (a, b) => ChangeTrackerAccess.graphEqual(a, b), getDraft: (path) => useWorkflowDraftStoreV2().getDraft(path), removeDraft: (path) => useWorkflowDraftStoreV2().removeDraft(path), markDraftUsed: (path) => useWorkflowDraftStoreV2().markDraftUsed(path), diff --git a/src/scripts/changeTrackerAccess.ts b/src/scripts/changeTrackerAccess.ts index 4f7e2119df2..a9802a41c57 100644 --- a/src/scripts/changeTrackerAccess.ts +++ b/src/scripts/changeTrackerAccess.ts @@ -10,6 +10,10 @@ interface ChangeTrackerClass { initialState: ComfyWorkflowJSON ): WorkflowChangeTracker readonly isLoadingGraph: boolean + graphEqual( + a: ComfyWorkflowJSON | null | undefined, + b: ComfyWorkflowJSON | null | undefined + ): boolean } /** `ChangeTracker` for the stores it imports, which cannot import it back. */ From b7d807eac8e7fdf9aeefe8aac8212db2c2599942 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sun, 1 Nov 2026 07:00:22 +0000 Subject: [PATCH 3/5] test: explicit steps and real Responses in the unedited-draft tests Address review: drop the remaining test comment, replace loops in the browser test with explicit steps through a small helper, and stub getUserData with real Response objects. --- .../tests/workflowPersistence.spec.ts | 50 ++++++++++--------- .../management/stores/workflowStore.test.ts | 26 ++++------ 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/browser_tests/tests/workflowPersistence.spec.ts b/browser_tests/tests/workflowPersistence.spec.ts index aa70eb4a678..5ba124343c1 100644 --- a/browser_tests/tests/workflowPersistence.spec.ts +++ b/browser_tests/tests/workflowPersistence.spec.ts @@ -43,6 +43,14 @@ const waitForWorkflowTabState = async (comfyPage: ComfyPage, minPaths = 2) => { }, minPaths) } +const expectTabOpensAsSaved = async (comfyPage: ComfyPage, name: string) => { + await comfyPage.menu.topbar.getWorkflowTab(name).click() + await comfyPage.workflow.waitForWorkflowIdle() + await expect.poll(() => comfyPage.menu.topbar.getActiveTabName()).toBe(name) + expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) + expect(await comfyPage.page.title()).not.toMatch(/^\*/) +} + type NodeRef = NonNullable< Awaited> > @@ -1031,24 +1039,22 @@ test.describe('Workflow Persistence', () => { 'Topbar' ) - const names = [ + const [first, second, third] = [ generateUniqueFilename(), generateUniqueFilename(), generateUniqueFilename() ] - await comfyPage.menu.topbar.saveWorkflow(names[0]) - for (const name of names.slice(1)) { - await comfyPage.menu.topbar.triggerTopbarCommand(['New']) - await comfyPage.menu.topbar.saveWorkflow(name) - } + await comfyPage.menu.topbar.saveWorkflow(first) + await comfyPage.menu.topbar.triggerTopbarCommand(['New']) + await comfyPage.menu.topbar.saveWorkflow(second) + await comfyPage.menu.topbar.triggerTopbarCommand(['New']) + await comfyPage.menu.topbar.saveWorkflow(third) await test.step('visit every tab without editing, leaving drafts behind', async () => { - for (const name of names) { - await comfyPage.menu.topbar.getWorkflowTab(name).click() - await comfyPage.workflow.waitForWorkflowIdle() - expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) - } - await waitForWorkflowTabState(comfyPage, names.length) + await expectTabOpensAsSaved(comfyPage, first) + await expectTabOpensAsSaved(comfyPage, second) + await expectTabOpensAsSaved(comfyPage, third) + await waitForWorkflowTabState(comfyPage, 3) await expect .poll(async () => (await comfyPage.workflow.getDraftWorkflows()).length) .toBeGreaterThanOrEqual(2) @@ -1059,21 +1065,17 @@ test.describe('Workflow Persistence', () => { await test.step('the tab active at reload is restored as saved', async () => { await expect .poll(() => comfyPage.menu.topbar.getActiveTabName()) - .toBe(names[2]) + .toBe(third) expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) }) - for (const name of names.slice(0, 2)) { - await test.step(`restored tab ${name} reopens as saved`, async () => { - await comfyPage.menu.topbar.getWorkflowTab(name).click() - await comfyPage.workflow.waitForWorkflowIdle() - await expect - .poll(() => comfyPage.menu.topbar.getActiveTabName()) - .toBe(name) - expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) - expect(await comfyPage.page.title()).not.toMatch(/^\*/) - }) - } + await test.step('the first restored tab reopens as saved', async () => { + await expectTabOpensAsSaved(comfyPage, first) + }) + + await test.step('the second restored tab reopens as saved', async () => { + await expectTabOpensAsSaved(comfyPage, second) + }) }) test('Flushes a pending draft edit before an immediate reload', async ({ diff --git a/src/platform/workflow/management/stores/workflowStore.test.ts b/src/platform/workflow/management/stores/workflowStore.test.ts index 17d53f79679..be5132a3c18 100644 --- a/src/platform/workflow/management/stores/workflowStore.test.ts +++ b/src/platform/workflow/management/stores/workflowStore.test.ts @@ -503,20 +503,16 @@ describe('useWorkflowStore', () => { expect(workflow.isModified).toBe(true) }) - // Switching tabs writes a draft for every open workflow, edited or not, - // so after a reload an unedited saved workflow has a draft equal to its - // file. That draft must not mark the workflow unsaved. - it('does not mark a saved workflow modified when its draft matches the file', async () => { + it('does not mark a saved workflow modified when the draft a tab switch left matches the file', async () => { enableWorkflowPersistence() await syncRemoteWorkflowsWithMeta([ { path: 'a.json', modified: 100, size: 1 } ]) const workflow = store.getWorkflowByPath('workflows/a.json')! saveV2Draft(workflow.path, { data: defaultGraphJSON, name: 'a.json' }) - vi.mocked(api.getUserData).mockResolvedValue({ - status: 200, - text: () => Promise.resolve(defaultGraphJSON) - } as Response) + vi.mocked(api.getUserData).mockResolvedValue( + new Response(defaultGraphJSON, { status: 200 }) + ) await workflow.load() @@ -539,10 +535,9 @@ describe('useWorkflowStore', () => { data: JSON.stringify(draftGraph), name: 'a.json' }) - vi.mocked(api.getUserData).mockResolvedValue({ - status: 200, - text: () => Promise.resolve(defaultGraphJSON) - } as Response) + vi.mocked(api.getUserData).mockResolvedValue( + new Response(defaultGraphJSON, { status: 200 }) + ) await workflow.load() @@ -565,10 +560,9 @@ describe('useWorkflowStore', () => { data: JSON.stringify(draftGraph), name: 'a.json' }) - vi.mocked(api.getUserData).mockResolvedValue({ - status: 200, - text: () => Promise.resolve(defaultGraphJSON) - } as Response) + vi.mocked(api.getUserData).mockResolvedValue( + new Response(defaultGraphJSON, { status: 200 }) + ) await workflow.load() From 9cef341ba20bec96b26112f83fca4d5ace4c86dc Mon Sep 17 00:00:00 2001 From: bymyself Date: Sun, 1 Nov 2026 07:27:54 +0000 Subject: [PATCH 4/5] fix: keep a draft marked unsaved when either state has no node list graphEqual maps over nodes, so a draft or saved file without a nodes array made load() throw after the draft was installed. Compare only when both states have a node list; otherwise keep the draft marked modified, as before. Tests: share one loadWithDraft setup across the restore cases, move the tab check into WorkflowHelper, and poll the title and modified state. --- .../fixtures/helpers/WorkflowHelper.ts | 10 ++ .../tests/workflowPersistence.spec.ts | 23 ++-- .../management/stores/comfyWorkflow.ts | 18 ++- .../management/stores/workflowStore.test.ts | 108 +++++++++--------- 4 files changed, 90 insertions(+), 69 deletions(-) diff --git a/browser_tests/fixtures/helpers/WorkflowHelper.ts b/browser_tests/fixtures/helpers/WorkflowHelper.ts index 4657e723bb1..7ca3c40d017 100644 --- a/browser_tests/fixtures/helpers/WorkflowHelper.ts +++ b/browser_tests/fixtures/helpers/WorkflowHelper.ts @@ -288,6 +288,16 @@ export class WorkflowHelper { await this.waitForWorkflowIdle() } + /** A saved workflow's tab, opened and confirmed unmodified with no `*` title. */ + async expectTabOpensAsSaved(tabName: string): Promise { + await this.switchToTab(tabName) + await expect + .poll(() => this.comfyPage.menu.topbar.getActiveTabName()) + .toBe(tabName) + await expect.poll(() => this.isCurrentWorkflowModified()).toBe(false) + await expect.poll(() => this.comfyPage.page.title()).not.toMatch(/^\*/) + } + /** Node ids on the live graph, read from LiteGraph rather than the DOM. */ getGraphNodeIds(): Promise { return this.comfyPage.page.evaluate(() => diff --git a/browser_tests/tests/workflowPersistence.spec.ts b/browser_tests/tests/workflowPersistence.spec.ts index 5ba124343c1..97e1fb3cfe3 100644 --- a/browser_tests/tests/workflowPersistence.spec.ts +++ b/browser_tests/tests/workflowPersistence.spec.ts @@ -43,14 +43,6 @@ const waitForWorkflowTabState = async (comfyPage: ComfyPage, minPaths = 2) => { }, minPaths) } -const expectTabOpensAsSaved = async (comfyPage: ComfyPage, name: string) => { - await comfyPage.menu.topbar.getWorkflowTab(name).click() - await comfyPage.workflow.waitForWorkflowIdle() - await expect.poll(() => comfyPage.menu.topbar.getActiveTabName()).toBe(name) - expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) - expect(await comfyPage.page.title()).not.toMatch(/^\*/) -} - type NodeRef = NonNullable< Awaited> > @@ -1051,9 +1043,9 @@ test.describe('Workflow Persistence', () => { await comfyPage.menu.topbar.saveWorkflow(third) await test.step('visit every tab without editing, leaving drafts behind', async () => { - await expectTabOpensAsSaved(comfyPage, first) - await expectTabOpensAsSaved(comfyPage, second) - await expectTabOpensAsSaved(comfyPage, third) + await comfyPage.workflow.expectTabOpensAsSaved(first) + await comfyPage.workflow.expectTabOpensAsSaved(second) + await comfyPage.workflow.expectTabOpensAsSaved(third) await waitForWorkflowTabState(comfyPage, 3) await expect .poll(async () => (await comfyPage.workflow.getDraftWorkflows()).length) @@ -1066,15 +1058,18 @@ test.describe('Workflow Persistence', () => { await expect .poll(() => comfyPage.menu.topbar.getActiveTabName()) .toBe(third) - expect(await comfyPage.workflow.isCurrentWorkflowModified()).toBe(false) + await expect + .poll(() => comfyPage.workflow.isCurrentWorkflowModified()) + .toBe(false) + await expect.poll(() => comfyPage.page.title()).not.toMatch(/^\*/) }) await test.step('the first restored tab reopens as saved', async () => { - await expectTabOpensAsSaved(comfyPage, first) + await comfyPage.workflow.expectTabOpensAsSaved(first) }) await test.step('the second restored tab reopens as saved', async () => { - await expectTabOpensAsSaved(comfyPage, second) + await comfyPage.workflow.expectTabOpensAsSaved(second) }) }) diff --git a/src/platform/workflow/management/stores/comfyWorkflow.ts b/src/platform/workflow/management/stores/comfyWorkflow.ts index 6b91b0928c8..b06a610fec7 100644 --- a/src/platform/workflow/management/stores/comfyWorkflow.ts +++ b/src/platform/workflow/management/stores/comfyWorkflow.ts @@ -221,6 +221,18 @@ function readUsableDraft( } } +function draftMatchesSavedFile( + runtime: WorkflowRuntime, + saved: ComfyWorkflowJSON, + draft: ComfyWorkflowJSON +): boolean { + return ( + Array.isArray(saved.nodes) && + Array.isArray(draft.nodes) && + runtime.graphEqual(saved, draft) + ) +} + /** * The workflow object parsed from the stored text. Anything else (nothing * stored, empty text, JSON `null`, a number, an array) cannot back a change @@ -367,7 +379,11 @@ export class ComfyWorkflow extends UserFile { if (draft?.state && draft.content) { this.changeTracker.activeState = draft.state this.content = draft.content - this._isModified = !runtime.graphEqual(initialState, draft.state) + this._isModified = !draftMatchesSavedFile( + runtime, + initialState, + draft.state + ) runtime.markDraftUsed(this.path) } return this as this & LoadedComfyWorkflow diff --git a/src/platform/workflow/management/stores/workflowStore.test.ts b/src/platform/workflow/management/stores/workflowStore.test.ts index be5132a3c18..6ec0fd83bd6 100644 --- a/src/platform/workflow/management/stores/workflowStore.test.ts +++ b/src/platform/workflow/management/stores/workflowStore.test.ts @@ -503,71 +503,71 @@ describe('useWorkflowStore', () => { expect(workflow.isModified).toBe(true) }) - it('does not mark a saved workflow modified when the draft a tab switch left matches the file', async () => { - enableWorkflowPersistence() - await syncRemoteWorkflowsWithMeta([ - { path: 'a.json', modified: 100, size: 1 } - ]) - const workflow = store.getWorkflowByPath('workflows/a.json')! - saveV2Draft(workflow.path, { data: defaultGraphJSON, name: 'a.json' }) - vi.mocked(api.getUserData).mockResolvedValue( - new Response(defaultGraphJSON, { status: 200 }) - ) + describe('restoring a saved workflow over its draft', () => { + const loadWithDraft = async ( + draftData: string, + fileData = defaultGraphJSON + ) => { + enableWorkflowPersistence() + await syncRemoteWorkflowsWithMeta([ + { path: 'a.json', modified: 100, size: 1 } + ]) + const workflow = store.getWorkflowByPath('workflows/a.json')! + saveV2Draft(workflow.path, { data: draftData, name: 'a.json' }) + vi.mocked(api.getUserData).mockResolvedValue( + new Response(fileData, { status: 200 }) + ) + await workflow.load() + return workflow + } - await workflow.load() + const draftWithExtra = (extra: Record) => { + const draftGraph = JSON.parse(defaultGraphJSON) + draftGraph.extra = { ...draftGraph.extra, ...extra } + return JSON.stringify(draftGraph) + } - expect(workflow.activeState).toEqual(defaultGraph) - expect(workflow.isModified).toBe(false) - }) + it('does not mark it modified when the draft a tab switch left matches the file', async () => { + const workflow = await loadWithDraft(defaultGraphJSON) - it('keeps the draft viewport without marking the workflow modified', async () => { - enableWorkflowPersistence() - await syncRemoteWorkflowsWithMeta([ - { path: 'a.json', modified: 100, size: 1 } - ]) - const workflow = store.getWorkflowByPath('workflows/a.json')! - const draftGraph = JSON.parse(defaultGraphJSON) - draftGraph.extra = { - ...draftGraph.extra, - ds: { scale: 2.5, offset: [40, -80] } - } - saveV2Draft(workflow.path, { - data: JSON.stringify(draftGraph), - name: 'a.json' + expect(workflow.activeState).toEqual(defaultGraph) + expect(workflow.isModified).toBe(false) }) - vi.mocked(api.getUserData).mockResolvedValue( - new Response(defaultGraphJSON, { status: 200 }) - ) - await workflow.load() + it('keeps the draft viewport without marking it modified', async () => { + const workflow = await loadWithDraft( + draftWithExtra({ ds: { scale: 2.5, offset: [40, -80] } }) + ) - expect(workflow.activeState?.extra?.ds).toEqual({ - scale: 2.5, - offset: [40, -80] + expect(workflow.activeState?.extra?.ds).toEqual({ + scale: 2.5, + offset: [40, -80] + }) + expect(workflow.isModified).toBe(false) }) - expect(workflow.isModified).toBe(false) - }) - it('marks a saved workflow modified when its draft only changes app mode', async () => { - enableWorkflowPersistence() - await syncRemoteWorkflowsWithMeta([ - { path: 'a.json', modified: 100, size: 1 } - ]) - const workflow = store.getWorkflowByPath('workflows/a.json')! - const draftGraph = JSON.parse(defaultGraphJSON) - draftGraph.extra = { ...draftGraph.extra, linearMode: true } - saveV2Draft(workflow.path, { - data: JSON.stringify(draftGraph), - name: 'a.json' + it('marks it modified when the draft only changes app mode', async () => { + const workflow = await loadWithDraft( + draftWithExtra({ linearMode: true }) + ) + + expect(workflow.activeState?.extra?.linearMode).toBe(true) + expect(workflow.isModified).toBe(true) }) - vi.mocked(api.getUserData).mockResolvedValue( - new Response(defaultGraphJSON, { status: 200 }) - ) - await workflow.load() + it('marks it modified when the draft has no node list to compare', async () => { + const workflow = await loadWithDraft('{"links":[]}') - expect(workflow.activeState?.extra?.linearMode).toBe(true) - expect(workflow.isModified).toBe(true) + expect(workflow.activeState).toEqual({ links: [] }) + expect(workflow.isModified).toBe(true) + }) + + it('marks it modified when the saved file has no node list to compare', async () => { + const workflow = await loadWithDraft(defaultGraphJSON, '{"links":[]}') + + expect(workflow.activeState).toEqual(defaultGraph) + expect(workflow.isModified).toBe(true) + }) }) it('should discard a stale V2 draft when the remote workflow is newer', async () => { From 5990d6f7750646b80d714c586a2f8948d2b0f505 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sun, 1 Nov 2026 07:41:53 +0000 Subject: [PATCH 5/5] test: build the valid draft fixture from the typed default graph --- src/platform/workflow/management/stores/workflowStore.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/workflow/management/stores/workflowStore.test.ts b/src/platform/workflow/management/stores/workflowStore.test.ts index 6ec0fd83bd6..8eccba45f99 100644 --- a/src/platform/workflow/management/stores/workflowStore.test.ts +++ b/src/platform/workflow/management/stores/workflowStore.test.ts @@ -521,8 +521,8 @@ describe('useWorkflowStore', () => { return workflow } - const draftWithExtra = (extra: Record) => { - const draftGraph = JSON.parse(defaultGraphJSON) + const draftWithExtra = (extra: ComfyWorkflowJSON['extra']) => { + const draftGraph: ComfyWorkflowJSON = structuredClone(defaultGraph) draftGraph.extra = { ...draftGraph.extra, ...extra } return JSON.stringify(draftGraph) }