|
1 | 1 | import { describe, expect, test } from "bun:test" |
2 | | -import type { Agent } from "@opencode-ai/sdk/v2/client" |
3 | | -import { normalizeAgentList } from "./utils" |
| 2 | +import type { Agent, Project } from "@opencode-ai/sdk/v2/client" |
| 3 | +import { createStore } from "solid-js/store" |
| 4 | +import { normalizeAgentList, sanitizeProject } from "./utils" |
4 | 5 |
|
5 | 6 | const agent = (name = "build") => |
6 | 7 | ({ |
@@ -33,3 +34,57 @@ describe("normalizeAgentList", () => { |
33 | 34 | expect(normalizeAgentList([{ name: "build" }, agent("docs")])).toEqual([agent("docs")]) |
34 | 35 | }) |
35 | 36 | }) |
| 37 | + |
| 38 | +describe("sanitizeProject", () => { |
| 39 | + test("clones nested project data and strips cached icon urls", () => { |
| 40 | + const [store] = createStore({ |
| 41 | + value: { |
| 42 | + id: "proj_1", |
| 43 | + worktree: "/tmp/project", |
| 44 | + name: "Project", |
| 45 | + icon: { |
| 46 | + url: "https://example.com/icon.png", |
| 47 | + override: "data:image/png;base64,abc", |
| 48 | + color: "pink", |
| 49 | + }, |
| 50 | + commands: { |
| 51 | + start: "bun dev", |
| 52 | + }, |
| 53 | + time: { |
| 54 | + created: 1, |
| 55 | + updated: 2, |
| 56 | + }, |
| 57 | + sandboxes: ["/tmp/project-a"], |
| 58 | + } satisfies Project, |
| 59 | + }) |
| 60 | + |
| 61 | + const next = sanitizeProject(store.value) |
| 62 | + |
| 63 | + expect(next).not.toBe(store.value) |
| 64 | + expect(next.time).not.toBe(store.value.time) |
| 65 | + expect(next.sandboxes).not.toBe(store.value.sandboxes) |
| 66 | + expect(next.commands).not.toBe(store.value.commands) |
| 67 | + expect(next.icon).not.toBe(store.value.icon) |
| 68 | + expect(next.icon?.url).toBeUndefined() |
| 69 | + expect(next.icon?.override).toBeUndefined() |
| 70 | + expect(next.icon?.color).toBe("pink") |
| 71 | + |
| 72 | + next.sandboxes.push("/tmp/project-b") |
| 73 | + expect(store.value.sandboxes).toEqual(["/tmp/project-a"]) |
| 74 | + }) |
| 75 | + |
| 76 | + test("returns a detached copy even without icon overrides", () => { |
| 77 | + const project = { |
| 78 | + id: "proj_2", |
| 79 | + worktree: "/tmp/project-2", |
| 80 | + time: { created: 1, updated: 1 }, |
| 81 | + sandboxes: [], |
| 82 | + } satisfies Project |
| 83 | + |
| 84 | + const next = sanitizeProject(project) |
| 85 | + |
| 86 | + expect(next).not.toBe(project) |
| 87 | + expect(next.time).not.toBe(project.time) |
| 88 | + expect(next.sandboxes).not.toBe(project.sandboxes) |
| 89 | + }) |
| 90 | +}) |
0 commit comments