mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-10 07:11:25 +03:00
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import { createRoot } from "solid-js"
|
|
import { ModelSelectionSchema } from "@/providers/models/selection"
|
|
import { flushPersisted } from "@/runtime/persistence/persist"
|
|
import { persisted } from "@/runtime/persistence/storage"
|
|
|
|
test("persisted model selection hydrates, updates and serializes the schema shape", () => {
|
|
const key = `consumer-model-selection-${crypto.randomUUID()}`
|
|
localStorage.setItem(
|
|
key,
|
|
JSON.stringify({ pick: { session1: { agent: "plan" }, __workspace__: { agent: "build" } } }),
|
|
)
|
|
createRoot((dispose) => {
|
|
try {
|
|
const [state, setState] = persisted(
|
|
key,
|
|
ModelSelectionSchema,
|
|
{ session: {} },
|
|
{
|
|
platform: "web",
|
|
openExternal: () => {},
|
|
restart: async () => {},
|
|
notify: async () => {},
|
|
},
|
|
)
|
|
|
|
expect(state.session.session1?.agent).toBe("plan")
|
|
const choice = { providerID: "provider", modelID: "model", variant: { type: "default" as const } }
|
|
setState("session", "session1", { agent: "build", choice })
|
|
expect(state.session.session1?.agent).toBe("build")
|
|
flushPersisted()
|
|
expect(JSON.parse(localStorage.getItem(key) ?? "null")).toEqual({
|
|
session: { session1: { agent: "build", choice } },
|
|
})
|
|
} finally {
|
|
dispose()
|
|
localStorage.removeItem(key)
|
|
}
|
|
})
|
|
})
|