refactor(tui): extract shared frontend helpers (#37868)

This commit is contained in:
Simon Klee 2026-07-20 10:43:02 +02:00 committed by GitHub
commit 0eb71d0fc7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 1655 additions and 1614 deletions

View file

@ -13,6 +13,7 @@ export default defineScript({
const registration = await serviceRegistration(artifacts)
const root = path.resolve(import.meta.dir, "../../../..")
const preload = Bun.resolveSync("@opentui/solid/preload", path.join(root, "packages/cli"))
const session = `mini-stage2-${process.pid}`
const snapshots = path.join(artifacts, "mini-stage2")
await mkdir(snapshots, { recursive: true })
@ -56,7 +57,7 @@ export default defineScript({
"OPENCODE_DIRECT_TRACE=1",
process.execPath,
"--conditions=browser",
"--preload=@opentui/solid/preload",
`--preload=${preload}`,
path.join(root, "packages/cli/src/index.ts"),
"mini",
"--server",

View file

@ -159,37 +159,19 @@ describe("Mini CLI host", () => {
expect(typeof input.startup.now()).toBe("number")
})
test("merges, clears, and repairs persisted model variants", async () => {
test("delegates model variant preferences", async () => {
const directory = await root()
const input = host({ stdin: stream(true), cleanup() {} }, directory)
const file = path.join(directory, "model.json")
await Bun.write(
file,
JSON.stringify({
recent: [{ providerID: "anthropic", modelID: "sonnet" }],
variant: { "openai/gpt-4.1": "low", invalid: 42 },
}),
)
await input.preferences.saveVariant(model, "high")
expect(await input.preferences.resolveVariant(model)).toBe("high")
expect(await Bun.file(file).json()).toEqual({
recent: [{ providerID: "anthropic", modelID: "sonnet" }],
variant: { "openai/gpt-4.1": "low", "openai/gpt-5": "high" },
})
await input.preferences.saveVariant(model, undefined)
expect(await input.preferences.resolveVariant(model)).toBeUndefined()
expect(await Bun.file(file).json()).toEqual({
recent: [{ providerID: "anthropic", modelID: "sonnet" }],
variant: { "openai/gpt-4.1": "low" },
})
await Bun.write(file, JSON.stringify({ variant: { "openai/gpt-5": "default" } }))
await input.preferences.saveVariant(model, "default")
expect(await input.preferences.resolveVariant(model)).toBeUndefined()
await Bun.write(file, "{")
await input.preferences.saveVariant(model, "high")
expect(await Bun.file(file).json()).toEqual({ variant: { "openai/gpt-5": "high" } })
expect(await input.preferences.resolveVariant(model)).toBe("high")
})
})