2026-02-21 02:24:43 +09:00
|
|
|
import { describe, expect, test, mock, afterEach } from "bun:test"
|
2025-12-24 02:08:01 +09:00
|
|
|
|
2026-03-06 10:59:41 +09:00
|
|
|
import { getPluginNameWithVersion, fetchNpmDistTags, generateOmoConfig } from "./config-manager"
|
2026-01-14 19:11:28 +09:00
|
|
|
import type { InstallConfig } from "./types"
|
2026-01-11 12:53:41 +08:00
|
|
|
|
|
|
|
|
describe("getPluginNameWithVersion", () => {
|
|
|
|
|
const originalFetch = globalThis.fetch
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
globalThis.fetch = originalFetch
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("returns @latest when current version matches latest tag", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given npm dist-tags with latest=2.14.0
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() =>
|
|
|
|
|
Promise.resolve({
|
|
|
|
|
ok: true,
|
|
|
|
|
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3" }),
|
|
|
|
|
} as Response)
|
|
|
|
|
) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when current version is 2.14.0
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await getPluginNameWithVersion("2.14.0")
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then should use @latest tag
|
2026-01-11 12:53:41 +08:00
|
|
|
expect(result).toBe("oh-my-opencode@latest")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("returns @beta when current version matches beta tag", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given npm dist-tags with beta=3.0.0-beta.3
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() =>
|
|
|
|
|
Promise.resolve({
|
|
|
|
|
ok: true,
|
|
|
|
|
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3" }),
|
|
|
|
|
} as Response)
|
|
|
|
|
) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when current version is 3.0.0-beta.3
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await getPluginNameWithVersion("3.0.0-beta.3")
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then should use @beta tag
|
2026-01-11 12:53:41 +08:00
|
|
|
expect(result).toBe("oh-my-opencode@beta")
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("returns @next when current version matches next tag", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given npm dist-tags with next=3.1.0-next.1
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() =>
|
|
|
|
|
Promise.resolve({
|
|
|
|
|
ok: true,
|
|
|
|
|
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3", next: "3.1.0-next.1" }),
|
|
|
|
|
} as Response)
|
|
|
|
|
) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when current version is 3.1.0-next.1
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await getPluginNameWithVersion("3.1.0-next.1")
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then should use @next tag
|
2026-01-11 12:53:41 +08:00
|
|
|
expect(result).toBe("oh-my-opencode@next")
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-21 02:24:43 +09:00
|
|
|
test("returns prerelease channel tag when no dist-tag matches prerelease version", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given npm dist-tags with beta=3.0.0-beta.3
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() =>
|
|
|
|
|
Promise.resolve({
|
|
|
|
|
ok: true,
|
|
|
|
|
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3" }),
|
|
|
|
|
} as Response)
|
|
|
|
|
) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when current version is old beta 3.0.0-beta.2
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await getPluginNameWithVersion("3.0.0-beta.2")
|
|
|
|
|
|
2026-02-21 02:24:43 +09:00
|
|
|
// #then should preserve prerelease channel
|
|
|
|
|
expect(result).toBe("oh-my-opencode@beta")
|
2026-01-11 12:53:41 +08:00
|
|
|
})
|
|
|
|
|
|
2026-02-21 02:24:43 +09:00
|
|
|
test("returns prerelease channel tag when fetch fails", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given network failure
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() => Promise.reject(new Error("Network error"))) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when current version is 3.0.0-beta.3
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await getPluginNameWithVersion("3.0.0-beta.3")
|
|
|
|
|
|
2026-02-21 02:24:43 +09:00
|
|
|
// #then should preserve prerelease channel
|
|
|
|
|
expect(result).toBe("oh-my-opencode@beta")
|
2026-01-11 12:53:41 +08:00
|
|
|
})
|
|
|
|
|
|
2026-02-21 02:24:43 +09:00
|
|
|
test("returns bare package name when npm returns non-ok response for stable version", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given npm returns 404
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() =>
|
|
|
|
|
Promise.resolve({
|
|
|
|
|
ok: false,
|
|
|
|
|
status: 404,
|
|
|
|
|
} as Response)
|
|
|
|
|
) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when current version is 2.14.0
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await getPluginNameWithVersion("2.14.0")
|
|
|
|
|
|
2026-02-21 02:24:43 +09:00
|
|
|
// #then should fall back to bare package entry
|
|
|
|
|
expect(result).toBe("oh-my-opencode")
|
2026-01-11 12:53:41 +08:00
|
|
|
})
|
2026-01-15 06:02:25 +08:00
|
|
|
|
|
|
|
|
test("prioritizes latest over other tags when version matches multiple", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given version matches both latest and beta (during release promotion)
|
2026-01-15 06:02:25 +08:00
|
|
|
globalThis.fetch = mock(() =>
|
|
|
|
|
Promise.resolve({
|
|
|
|
|
ok: true,
|
|
|
|
|
json: () => Promise.resolve({ beta: "3.0.0", latest: "3.0.0", next: "3.1.0-alpha.1" }),
|
|
|
|
|
} as Response)
|
|
|
|
|
) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when current version matches both
|
2026-01-15 06:02:25 +08:00
|
|
|
const result = await getPluginNameWithVersion("3.0.0")
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then should prioritize @latest
|
2026-01-15 06:02:25 +08:00
|
|
|
expect(result).toBe("oh-my-opencode@latest")
|
|
|
|
|
})
|
2026-01-11 12:53:41 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe("fetchNpmDistTags", () => {
|
|
|
|
|
const originalFetch = globalThis.fetch
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
globalThis.fetch = originalFetch
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("returns dist-tags on success", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given npm returns dist-tags
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() =>
|
|
|
|
|
Promise.resolve({
|
|
|
|
|
ok: true,
|
|
|
|
|
json: () => Promise.resolve({ latest: "2.14.0", beta: "3.0.0-beta.3" }),
|
|
|
|
|
} as Response)
|
|
|
|
|
) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when fetching dist-tags
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await fetchNpmDistTags("oh-my-opencode")
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then should return the tags
|
2026-01-11 12:53:41 +08:00
|
|
|
expect(result).toEqual({ latest: "2.14.0", beta: "3.0.0-beta.3" })
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("returns null on network failure", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given network failure
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() => Promise.reject(new Error("Network error"))) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when fetching dist-tags
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await fetchNpmDistTags("oh-my-opencode")
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then should return null
|
2026-01-11 12:53:41 +08:00
|
|
|
expect(result).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("returns null on non-ok response", async () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given npm returns 404
|
2026-01-11 12:53:41 +08:00
|
|
|
globalThis.fetch = mock(() =>
|
|
|
|
|
Promise.resolve({
|
|
|
|
|
ok: false,
|
|
|
|
|
status: 404,
|
|
|
|
|
} as Response)
|
|
|
|
|
) as unknown as typeof fetch
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when fetching dist-tags
|
2026-01-11 12:53:41 +08:00
|
|
|
const result = await fetchNpmDistTags("oh-my-opencode")
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then should return null
|
2026-01-11 12:53:41 +08:00
|
|
|
expect(result).toBeNull()
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-12-24 02:08:01 +09:00
|
|
|
|
2026-01-21 00:05:51 +09:00
|
|
|
describe("generateOmoConfig - model fallback system", () => {
|
2026-01-21 11:14:00 +09:00
|
|
|
test("uses github-copilot sonnet fallback when only copilot available", () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given user has only copilot (no max plan)
|
2026-01-14 19:11:28 +09:00
|
|
|
const config: InstallConfig = {
|
2026-01-21 00:05:51 +09:00
|
|
|
hasClaude: false,
|
|
|
|
|
isMax20: false,
|
2026-01-21 11:14:00 +09:00
|
|
|
hasOpenAI: false,
|
2026-01-21 00:05:51 +09:00
|
|
|
hasGemini: false,
|
2026-01-14 19:11:28 +09:00
|
|
|
hasCopilot: true,
|
2026-01-21 00:05:51 +09:00
|
|
|
hasOpencodeZen: false,
|
|
|
|
|
hasZaiCodingPlan: false,
|
2026-01-30 15:08:26 +09:00
|
|
|
hasKimiForCoding: false,
|
2026-01-14 19:11:28 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when generating config
|
2026-01-14 19:11:28 +09:00
|
|
|
const result = generateOmoConfig(config)
|
|
|
|
|
|
2026-02-06 14:21:15 +09:00
|
|
|
// #then Sisyphus uses Copilot (OR logic - copilot is in claude-opus-4-6 providers)
|
|
|
|
|
expect((result.agents as Record<string, { model: string }>).sisyphus.model).toBe("github-copilot/claude-opus-4.6")
|
2026-01-14 19:11:28 +09:00
|
|
|
})
|
|
|
|
|
|
2026-01-21 00:05:51 +09:00
|
|
|
test("uses ultimate fallback when no providers configured", () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given user has no providers
|
2026-01-14 19:11:28 +09:00
|
|
|
const config: InstallConfig = {
|
|
|
|
|
hasClaude: false,
|
|
|
|
|
isMax20: false,
|
2026-01-21 11:14:00 +09:00
|
|
|
hasOpenAI: false,
|
2026-01-14 19:11:28 +09:00
|
|
|
hasGemini: false,
|
2026-01-17 12:51:03 -05:00
|
|
|
hasCopilot: false,
|
2026-01-21 00:05:51 +09:00
|
|
|
hasOpencodeZen: false,
|
|
|
|
|
hasZaiCodingPlan: false,
|
2026-01-30 15:08:26 +09:00
|
|
|
hasKimiForCoding: false,
|
2026-01-14 19:11:28 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when generating config
|
2026-01-14 19:11:28 +09:00
|
|
|
const result = generateOmoConfig(config)
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then Sisyphus is omitted (requires all fallback providers)
|
2026-02-27 00:49:53 +09:00
|
|
|
expect(result.$schema).toBe("https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/dev/assets/oh-my-opencode.schema.json")
|
2026-02-01 19:26:57 +09:00
|
|
|
expect((result.agents as Record<string, { model: string }>).sisyphus).toBeUndefined()
|
2026-01-21 00:05:51 +09:00
|
|
|
})
|
|
|
|
|
|
2026-02-21 03:10:29 +09:00
|
|
|
test("uses ZAI model for librarian when Z.ai is available", () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given user has Z.ai and Claude max20
|
2026-01-21 00:05:51 +09:00
|
|
|
const config: InstallConfig = {
|
|
|
|
|
hasClaude: true,
|
2026-01-21 11:14:00 +09:00
|
|
|
isMax20: true,
|
|
|
|
|
hasOpenAI: false,
|
2026-01-21 00:05:51 +09:00
|
|
|
hasGemini: false,
|
|
|
|
|
hasCopilot: false,
|
|
|
|
|
hasOpencodeZen: false,
|
|
|
|
|
hasZaiCodingPlan: true,
|
2026-01-30 15:08:26 +09:00
|
|
|
hasKimiForCoding: false,
|
2026-01-21 00:05:51 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when generating config
|
2026-01-21 00:05:51 +09:00
|
|
|
const result = generateOmoConfig(config)
|
|
|
|
|
|
2026-02-21 03:10:29 +09:00
|
|
|
// #then librarian should use ZAI model
|
|
|
|
|
expect((result.agents as Record<string, { model: string }>).librarian.model).toBe("zai-coding-plan/glm-4.7")
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then Sisyphus uses Claude (OR logic)
|
2026-02-06 03:31:55 +09:00
|
|
|
expect((result.agents as Record<string, { model: string }>).sisyphus.model).toBe("anthropic/claude-opus-4-6")
|
2026-01-14 19:11:28 +09:00
|
|
|
})
|
2026-01-21 11:14:00 +09:00
|
|
|
|
|
|
|
|
test("uses native OpenAI models when only ChatGPT available", () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given user has only ChatGPT subscription
|
2026-01-21 11:14:00 +09:00
|
|
|
const config: InstallConfig = {
|
|
|
|
|
hasClaude: false,
|
|
|
|
|
isMax20: false,
|
|
|
|
|
hasOpenAI: true,
|
|
|
|
|
hasGemini: false,
|
|
|
|
|
hasCopilot: false,
|
|
|
|
|
hasOpencodeZen: false,
|
|
|
|
|
hasZaiCodingPlan: false,
|
2026-01-30 15:08:26 +09:00
|
|
|
hasKimiForCoding: false,
|
2026-01-21 11:14:00 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when generating config
|
2026-01-21 11:14:00 +09:00
|
|
|
const result = generateOmoConfig(config)
|
|
|
|
|
|
2026-03-07 19:23:08 +09:00
|
|
|
// #then Sisyphus resolves to gpt-5.4 medium (openai is now in sisyphus chain)
|
|
|
|
|
expect((result.agents as Record<string, { model: string; variant?: string }>).sisyphus.model).toBe("openai/gpt-5.4")
|
|
|
|
|
expect((result.agents as Record<string, { model: string; variant?: string }>).sisyphus.variant).toBe("medium")
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then Oracle should use native OpenAI (first fallback entry)
|
2026-03-07 02:33:32 +09:00
|
|
|
expect((result.agents as Record<string, { model: string }>).oracle.model).toBe("openai/gpt-5.4")
|
2026-03-08 01:53:30 +09:00
|
|
|
// #then multimodal-looker should use native OpenAI (first fallback entry is gpt-5.4)
|
|
|
|
|
expect((result.agents as Record<string, { model: string }>)["multimodal-looker"].model).toBe("openai/gpt-5.4")
|
2026-01-21 11:14:00 +09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("uses haiku for explore when Claude max20", () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given user has Claude max20
|
2026-01-21 11:14:00 +09:00
|
|
|
const config: InstallConfig = {
|
|
|
|
|
hasClaude: true,
|
|
|
|
|
isMax20: true,
|
|
|
|
|
hasOpenAI: false,
|
|
|
|
|
hasGemini: false,
|
|
|
|
|
hasCopilot: false,
|
|
|
|
|
hasOpencodeZen: false,
|
|
|
|
|
hasZaiCodingPlan: false,
|
2026-01-30 15:08:26 +09:00
|
|
|
hasKimiForCoding: false,
|
2026-01-21 11:14:00 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when generating config
|
2026-01-21 11:14:00 +09:00
|
|
|
const result = generateOmoConfig(config)
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then explore should use haiku (max20 plan uses Claude quota)
|
2026-01-21 11:14:00 +09:00
|
|
|
expect((result.agents as Record<string, { model: string }>).explore.model).toBe("anthropic/claude-haiku-4-5")
|
|
|
|
|
})
|
|
|
|
|
|
2026-01-23 15:07:58 +09:00
|
|
|
test("uses haiku for explore regardless of max20 flag", () => {
|
2026-02-01 19:26:57 +09:00
|
|
|
// #given user has Claude but not max20
|
2026-01-21 11:14:00 +09:00
|
|
|
const config: InstallConfig = {
|
|
|
|
|
hasClaude: true,
|
|
|
|
|
isMax20: false,
|
|
|
|
|
hasOpenAI: false,
|
|
|
|
|
hasGemini: false,
|
|
|
|
|
hasCopilot: false,
|
|
|
|
|
hasOpencodeZen: false,
|
|
|
|
|
hasZaiCodingPlan: false,
|
2026-01-30 15:08:26 +09:00
|
|
|
hasKimiForCoding: false,
|
2026-01-21 11:14:00 +09:00
|
|
|
}
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #when generating config
|
2026-01-21 11:14:00 +09:00
|
|
|
const result = generateOmoConfig(config)
|
|
|
|
|
|
2026-02-01 19:26:57 +09:00
|
|
|
// #then explore should use haiku (isMax20 doesn't affect explore anymore)
|
2026-01-23 15:07:58 +09:00
|
|
|
expect((result.agents as Record<string, { model: string }>).explore.model).toBe("anthropic/claude-haiku-4-5")
|
2026-01-21 11:14:00 +09:00
|
|
|
})
|
2026-01-14 19:11:28 +09:00
|
|
|
})
|