diff --git a/web/tests/settings-unified-draft.spec.tsx b/web/tests/settings-unified-draft.spec.tsx index 18a272783..8549e8a41 100644 --- a/web/tests/settings-unified-draft.spec.tsx +++ b/web/tests/settings-unified-draft.spec.tsx @@ -89,13 +89,16 @@ function Capture() { function Editor({ name }: { name: string }) { const [liveValue, setLiveValue] = useState(resources[name]); const [draft, edit] = useStagedSettings(name, liveValue, setLiveValue); + const isSubagent = name.startsWith("subagent:"); return ( edit( - name === "workspace" + isSubagent + ? { model: e.target.value } + : name === "workspace" ? { path: e.target.value } : { provider: e.target.value }, ) @@ -277,6 +280,37 @@ it("applies a restored draft while its editor is mounted without reverting the d expect(screen.getByLabelText("workspace")).toHaveValue("/restored"); }); +it("persists a restored subagent draft before clearing it", async () => { + const subagent = { enabled: true, model: "restored-model", effort: "high" }; + resources["subagent:opencode"] = {}; + stored = { + catalog: live, + extensions: { "subagent:opencode": subagent }, + }; + render(); + await ready(); + + await waitFor(() => + expect(screen.getByLabelText("subagent:opencode")).toHaveValue( + "restored-model", + ), + ); + await act(() => settings.applyCatalog()); + + const subagentWriteIndex = mocks.fetch.mock.calls.findIndex( + ([url, init]) => + url === "/api/subagents/settings" && init?.method === "PUT", + ); + const catalogApplyIndex = mocks.fetch.mock.calls.findIndex( + ([url, init]) => url === "/api/settings/apply" && init?.method === "POST", + ); + expect(JSON.parse(String(mocks.fetch.mock.calls[subagentWriteIndex][1]?.body))) + .toEqual({ backends: { opencode: subagent } }); + expect(subagentWriteIndex).toBeLessThan(catalogApplyIndex); + expect(settings.draftState).toBe("clean"); + expect(stored).toBeNull(); +}); + it("keeps the toolbar available when reverting an already saved draft", async () => { render(); await ready();