| 1 | import { readFileSync } from "node:fs"; |
| 2 | import { describe, expect, it } from "vitest"; |
| 3 | import { getHome } from "../i18n/dictionaries"; |
| 4 | import type { CapabilityContext } from "../capabilities"; |
| 5 | import type { DesktopReleaseFact } from "../desktop-release"; |
| 6 | import type { Feature } from "../features"; |
| 7 | import { PRODUCT_MAP_IDS, PRODUCT_MAP_STATE_KEY, PRODUCT_MAP_TEXT_KEYS, productMap } from "./product-map"; |
| 8 | |
| 9 | const feature = (id: string, since: string | null): Feature => ({ |
| 10 | id, name: id, summary: id, status: "stable", surfaces: { tui: "stable" }, since, flag: null, docs: null, registryLine: 1, |
| 11 | }); |
| 12 | |
| 13 | const FEATURES = [feature("subagents", "0.1.0"), feature("fleet", "0.9.0"), feature("workflows", "0.9.0")]; |
| 14 | |
| 15 | const released: CapabilityContext = { release: { tag: "v0.10.2", version: "0.10.2" }, baseline: null }; |
| 16 | |
| 17 | const desktopRelease: DesktopReleaseFact = { |
| 18 | tag: "v1.2.3", |
| 19 | version: "1.2.3", |
| 20 | publishedAt: "2026-12-01T10:00:00Z", |
| 21 | readAt: "2026-12-01T11:00:00Z", |
| 22 | url: "https://github.com/codewhale-hq/codewhale-app/releases/tag/v1.2.3", |
| 23 | assets: [ |
| 24 | { |
| 25 | name: "Codewhale-1.2.3-arm64.dmg", |
| 26 | platform: "macos", |
| 27 | size: 123_456_789, |
| 28 | sha256: "a".repeat(64), |
| 29 | signed: true, |
| 30 | notarized: true, |
| 31 | url: "https://github.com/codewhale-hq/codewhale-app/releases/download/v1.2.3/Codewhale-1.2.3-arm64.dmg", |
| 32 | }, |
| 33 | ], |
| 34 | }; |
| 35 | |
| 36 | const states = (rows: ReturnType<typeof productMap>) => Object.fromEntries(rows.map((row) => [row.id, row.state])); |
| 37 | |
| 38 | describe("the labelled product map", () => { |
| 39 | it("lists the six parts in order with today's states, and drops the desktop sentence written before its release", () => { |
| 40 | const rows = productMap({ capabilities: released, features: FEATURES }); |
| 41 | expect(rows.map((row) => row.id)).toEqual([...PRODUCT_MAP_IDS]); |
| 42 | expect(states(rows)).toEqual({ |
| 43 | terminal: "released", |
| 44 | localBrowser: "released", |
| 45 | manyAgents: "released", |
| 46 | desktop: "released", |
| 47 | cloud: "inviteOnly", |
| 48 | oneSession: "beingBuilt", |
| 49 | }); |
| 50 | expect(rows.filter((row) => !row.sentenceHolds).map((row) => row.id)).toEqual(["desktop"]); |
| 51 | }); |
| 52 | |
| 53 | it("turns only the desktop row to released when a desktop release object is valid", () => { |
| 54 | const before = productMap({ capabilities: released, features: FEATURES }); |
| 55 | const after = productMap({ capabilities: released, features: FEATURES, surface: { desktopRelease } }); |
| 56 | expect(states(after)).toEqual({ ...states(before), desktop: "released" }); |
| 57 | expect(after.find((row) => row.id === "desktop")!.sentenceHolds).toBe(false); |
| 58 | }); |
| 59 | |
| 60 | it("keeps the desktop row in development for an invalid release object", () => { |
| 61 | const invalid = { ...desktopRelease, assets: [] }; |
| 62 | expect(states(productMap({ capabilities: released, features: FEATURES, surface: { desktopRelease: invalid } })).desktop).toBe("developing"); |
| 63 | }); |
| 64 | |
| 65 | it("reads many agents as released only when sub-agents, Fleets and workflows are all in the published release", () => { |
| 66 | const older: CapabilityContext = { release: { tag: "v0.8.0", version: "0.8.0" }, baseline: null }; |
| 67 | expect(states(productMap({ capabilities: older, features: FEATURES })).manyAgents).toBe("developing"); |
| 68 | expect(states(productMap({ capabilities: { release: null, baseline: null }, features: FEATURES })).manyAgents).toBe("beingBuilt"); |
| 69 | expect(states(productMap({ capabilities: released, features: FEATURES.slice(0, 2) })).manyAgents).toBe("beingBuilt"); |
| 70 | }); |
| 71 | |
| 72 | it("never reads one session as released, whatever else is released", () => { |
| 73 | const rows = productMap({ capabilities: released, features: FEATURES, surface: { desktopRelease } }); |
| 74 | expect(states(rows).oneSession).toBe("beingBuilt"); |
| 75 | }); |
| 76 | |
| 77 | it("has no state typed into a row", () => { |
| 78 | const source = readFileSync(new URL("./product-map.ts", import.meta.url), "utf8"); |
| 79 | expect(source).not.toMatch(/state:\s*"/); |
| 80 | }); |
| 81 | |
| 82 | it("maps every part and state onto a dictionary string in every locale", () => { |
| 83 | for (const locale of ["en", "zh", "ar"]) { |
| 84 | const home = getHome(locale); |
| 85 | for (const id of PRODUCT_MAP_IDS) { |
| 86 | expect(home[PRODUCT_MAP_TEXT_KEYS[id].name].length, `${locale} ${id}`).toBeGreaterThan(0); |
| 87 | expect(home[PRODUCT_MAP_TEXT_KEYS[id].sentence].length, `${locale} ${id}`).toBeGreaterThan(0); |
| 88 | } |
| 89 | for (const key of Object.values(PRODUCT_MAP_STATE_KEY)) expect(home[key].length).toBeGreaterThan(0); |
| 90 | } |
| 91 | }); |
| 92 | }); |
| 93 |