import { describe, expect, it } from "vitest"; import { computeDiscoveryItems, countConfiguredIntegrations, discoveryProgress, summarizeProfileSignals, visibleDiscoveryItems, } from "./onboarding-discovery"; import { collectLocalProfileSignals } from "./user-profile-harvest"; describe("onboarding-discovery", () => { it("marks profile basics found when me is loaded", () => { const items = computeDiscoveryItems({ phase: "loading", me: { name: "Ingo", email: "ingo@example.com", needsModel: false, defaultProvider: "openrouter", defaultModel: "gpt-4", computerHost: null, }, }); const profile = items.find((item) => item.id === "profile-basics"); expect(profile?.status).toBe("found"); expect(profile?.detail).toContain("Ingo"); }); it("returns only four visible onboarding steps", () => { const items = computeDiscoveryItems({ phase: "assembly", crewReady: true }); expect(items.map((item) => item.id)).toEqual([ "profile-basics", "model-ready", "connected-tools", "specialist-crew", ]); }); it("reports configured integration count honestly", () => { expect( countConfiguredIntegrations({ canConfigure: true, needsSetup: false, webUrl: "https://example.com", providers: [ { id: "slack", configured: true }, { id: "gmail", configured: false }, ], }), ).toBe(1); }); it("tracks assembly progress for crew and persisted profile", () => { const signals = collectLocalProfileSignals({ name: "Robin", email: "r@example.com", defaultProvider: null, defaultModel: null, computerHost: null, }); const items = computeDiscoveryItems({ phase: "assembly", profileSignals: signals, profilePersisted: true, crewReady: true, me: { name: "Robin", email: "r@example.com", needsModel: false, defaultProvider: null, defaultModel: null, computerHost: null, }, }); expect(items.find((item) => item.id === "specialist-crew")?.status).toBe("found"); const progress = discoveryProgress(items); expect(progress.done).toBeGreaterThanOrEqual(3); }); it("summarizes profile signals without inventing data", () => { const summary = summarizeProfileSignals( collectLocalProfileSignals({ name: "Ingo", email: "a@b.c", defaultProvider: null, defaultModel: null, computerHost: null, }), ); expect(summary).toContain("Ingo"); expect(summary.length).toBeGreaterThan(0); }); it("visibleDiscoveryItems passes through the four onboarding steps", () => { const items = computeDiscoveryItems({ phase: "loading" }); expect(visibleDiscoveryItems(items)).toHaveLength(4); }); });