import { describe, expect, it } from "vitest"; import { loadUltraSettings, mergeUltraSettings, pickUltra, ULTRA_DEFAULTS, } from "../settings.ts"; describe("ULTRA_DEFAULTS", () => { it("matches the documented defaults", () => { expect(ULTRA_DEFAULTS).toEqual({ enabled: true, autoEnable: false, concurrency: 5, maxRetries: 2, subagentExtensions: "all", subagentSkills: "all", subagentSessionRetention: "all", modelTiers: {}, actionSummarizerModel: null, }); }); }); describe("auto_enable setting", () => { it("defaults to false and accepts booleans", () => { expect(ULTRA_DEFAULTS.autoEnable).toBe(false); expect(pickUltra({ ultra: { auto_enable: true } })).toEqual({ autoEnable: true, }); expect(pickUltra({ ultra: { auto_enable: "true" } })).toEqual({}); }); it("merges later valid values and ignores invalid ones", () => { expect( mergeUltraSettings({ autoEnable: true }, { autoEnable: false }) .autoEnable, ).toBe(false); expect(mergeUltraSettings({ autoEnable: "yes" as never }).autoEnable).toBe( false, ); }); }); describe("subagentExtensions setting", () => { it('defaults to "all"', () => { expect(ULTRA_DEFAULTS.subagentExtensions).toBe("all"); }); it("accepts all, none, or a normalized static name list", () => { expect(pickUltra({ ultra: { subagentExtensions: "none" } })).toEqual({ subagentExtensions: "none", }); expect(pickUltra({ ultra: { subagentExtensions: "all" } })).toEqual({ subagentExtensions: "all", }); expect( pickUltra({ ultra: { subagentExtensions: [" alpha ", "beta", "alpha", 7, ""], }, }), ).toEqual({ subagentExtensions: ["alpha", "beta"] }); expect(pickUltra({ ultra: { subagentExtensions: "lots" } })).toEqual({}); }); it("mergeUltraSettings folds it; later wins, bad ignored", () => { expect( mergeUltraSettings({ subagentExtensions: "none" }).subagentExtensions, ).toBe("none"); expect( mergeUltraSettings( { subagentExtensions: "none" }, { subagentExtensions: ["alpha", "beta"] }, ).subagentExtensions, ).toEqual(["alpha", "beta"]); expect( mergeUltraSettings( { subagentExtensions: ["alpha"] }, { subagentExtensions: "all" }, ).subagentExtensions, ).toBe("all"); expect( mergeUltraSettings({ subagentExtensions: "bogus" as never, }).subagentExtensions, ).toBe("all"); // default kept }); }); describe("subagentSkills setting", () => { it('defaults to "all" and supports explicit opt-out', () => { expect(ULTRA_DEFAULTS.subagentSkills).toBe("all"); expect(pickUltra({ ultra: { subagentSkills: "none" } })).toEqual({ subagentSkills: "none", }); expect(pickUltra({ ultra: { subagentSkills: "all" } })).toEqual({ subagentSkills: "all", }); expect(pickUltra({ ultra: { subagentSkills: true } })).toEqual({}); }); it("merges later valid values and ignores invalid ones", () => { expect( mergeUltraSettings({ subagentSkills: "none" }, { subagentSkills: "all" }) .subagentSkills, ).toBe("all"); expect( mergeUltraSettings({ subagentSkills: false as never }).subagentSkills, ).toBe("all"); }); }); describe("subagentSessionRetention setting", () => { it('defaults to "all" and supports explicit stateless opt-out', () => { expect(ULTRA_DEFAULTS.subagentSessionRetention).toBe("all"); expect(pickUltra({ ultra: { subagentSessionRetention: "none" } })).toEqual({ subagentSessionRetention: "none", }); expect(pickUltra({ ultra: { subagentSessionRetention: "all" } })).toEqual({ subagentSessionRetention: "all", }); expect( pickUltra({ ultra: { subagentSessionRetention: "failures" } }), ).toEqual({}); }); it("merges later valid values and ignores invalid ones", () => { expect( mergeUltraSettings( { subagentSessionRetention: "none" }, { subagentSessionRetention: "all" }, ).subagentSessionRetention, ).toBe("all"); expect( mergeUltraSettings({ subagentSessionRetention: false as never }) .subagentSessionRetention, ).toBe("all"); }); }); describe("pickUltra", () => { it("extracts only correctly-typed known keys from the `ultra` block", () => { expect( pickUltra({ ultra: { concurrency: 8, maxRetries: 1, enabled: false, auto_enable: true, actionSummarizerModel: " openai/gpt-5-mini ", modelTiers: { small: "openai/gpt-5-mini:low", medium: "anthropic/claude-sonnet-4", big: "openai/gpt-5.1:xhigh", bogus: "ignored", }, }, }), ).toEqual({ enabled: false, autoEnable: true, concurrency: 8, maxRetries: 1, actionSummarizerModel: "openai/gpt-5-mini", modelTiers: { small: "openai/gpt-5-mini:low", medium: "anthropic/claude-sonnet-4", big: "openai/gpt-5.1:xhigh", }, }); }); it("ignores wrong-typed values and unknown keys", () => { expect( pickUltra({ ultra: { concurrency: "8", maxRetries: 2, bogus: 1, modelTiers: { small: 7, extra: "ignored" }, }, }), ).toEqual({ maxRetries: 2, modelTiers: {}, }); }); it("returns {} when there is no object `ultra` block", () => { expect(pickUltra({})).toEqual({}); expect(pickUltra({ ultra: 7 })).toEqual({}); expect(pickUltra(null)).toEqual({}); expect(pickUltra("x")).toEqual({}); }); }); describe("mergeUltraSettings", () => { it("folds partials over the defaults, later winning", () => { expect( mergeUltraSettings( { concurrency: 3, modelTiers: { small: "openai/gpt-5-mini" } }, { concurrency: 9, maxRetries: 4, modelTiers: { big: "openai/gpt-5" } }, ), ).toEqual({ enabled: true, autoEnable: false, concurrency: 9, maxRetries: 4, subagentExtensions: "all", subagentSkills: "all", subagentSessionRetention: "all", modelTiers: { small: "openai/gpt-5-mini", big: "openai/gpt-5", }, actionSummarizerModel: null, }); }); it("ignores wrong-typed fields, keeping the prior value", () => { expect( mergeUltraSettings({ concurrency: 7 }, { concurrency: "nope" as any }), ).toEqual({ ...ULTRA_DEFAULTS, concurrency: 7, }); }); }); describe("loadUltraSettings", () => { it("merges global and project Pi settings over defaults", () => { const merged = loadUltraSettings({ global: { ultra: { auto_enable: true, concurrency: 10, actionSummarizerModel: "openai/gpt-5-mini", modelTiers: { small: "openai/gpt-5-mini" }, }, }, project: { ultra: { maxRetries: 9, modelTiers: { big: "openai/gpt-5" }, }, }, }); expect(merged).toEqual({ enabled: true, autoEnable: true, concurrency: 10, maxRetries: 9, subagentExtensions: "all", subagentSkills: "all", subagentSessionRetention: "all", modelTiers: { small: "openai/gpt-5-mini", big: "openai/gpt-5", }, actionSummarizerModel: "openai/gpt-5-mini", }); }); it("allows project null to disable the global action summarizer", () => { expect( loadUltraSettings({ global: { ultra: { actionSummarizerModel: "openai/gpt-5-mini" }, }, project: { ultra: { actionSummarizerModel: null } }, }).actionSummarizerModel, ).toBeNull(); }); it("falls back to defaults when no source provides values", () => { expect(loadUltraSettings({})).toEqual(ULTRA_DEFAULTS); }); });