// Admin-seat authoring-skill gate (Task 516).
//
// Locks the pure decision helpers that make content-producer-owned
// authoring skills unreachable from the admin seat via `skill-load` and
// `plugin-read`. The MCP handlers in index.ts are thin glue over these —
// they emit the dispatch-hint text and the `[admin-skill-gate]` line — so
// the decision logic is tested here in isolation, mirroring the
// loadSkill / findSkillOwners test convention (no stdio transport).
import { describe, it, expect } from "vitest";
import { CONTENT_PRODUCER_AUTHORING_SKILLS, isAdminSeat, skillSlugFromReadArgs, adminAuthoringSkillBlock, } from "../skill-resolution.js";
const ADMIN = { MAXY_SESSION_ROLE: "admin", MAXY_SPECIALIST: "" };
const CONTENT_PRODUCER = { MAXY_SESSION_ROLE: "admin", MAXY_SPECIALIST: "content-producer" };
const PUBLIC = { MAXY_SESSION_ROLE: "public", MAXY_SPECIALIST: "" };
describe("isAdminSeat", () => {
    it("true only when role is admin and no specialist is set", () => {
        expect(isAdminSeat(ADMIN)).toBe(true);
        expect(isAdminSeat({ MAXY_SESSION_ROLE: "admin" })).toBe(true); // specialist undefined
    });
    it("false for a specialist seat even when role is admin", () => {
        expect(isAdminSeat(CONTENT_PRODUCER)).toBe(false);
    });
    it("false for the public seat", () => {
        expect(isAdminSeat(PUBLIC)).toBe(false);
    });
    it("false when role is unknown (fail-open — never block an unidentified seat)", () => {
        expect(isAdminSeat({})).toBe(false);
    });
});
describe("CONTENT_PRODUCER_AUTHORING_SKILLS", () => {
    it("is exactly the three content-producer-invoked authoring/render/publish skills", () => {
        expect([...CONTENT_PRODUCER_AUTHORING_SKILLS].sort()).toEqual(["a4-print-documents", "professional-document", "publish-site"].sort());
    });
    it("excludes admin-invoked skills (unzip-attachment, deck-pages)", () => {
        // unzip-attachment SKILL.md: "Invoked by the admin agent directly".
        // deck-pages is admin-owned (a content-producer refusal target).
        expect(CONTENT_PRODUCER_AUTHORING_SKILLS.has("unzip-attachment")).toBe(false);
        expect(CONTENT_PRODUCER_AUTHORING_SKILLS.has("deck-pages")).toBe(false);
    });
});
describe("skillSlugFromReadArgs", () => {
    it("extracts the slug from a skills/<slug>/SKILL.md file path", () => {
        expect(skillSlugFromReadArgs("admin", "skills/professional-document/SKILL.md")).toBe("professional-document");
    });
    it("extracts the slug from a reference under the skill dir", () => {
        expect(skillSlugFromReadArgs("admin", "skills/professional-document/references/x.md")).toBe("professional-document");
    });
    it("extracts the slug when buried in pluginName", () => {
        expect(skillSlugFromReadArgs("admin/skills/publish-site", "PLUGIN.md")).toBe("publish-site");
    });
    it("returns undefined for PLUGIN.md and plain reference reads", () => {
        expect(skillSlugFromReadArgs("admin", "PLUGIN.md")).toBeUndefined();
        expect(skillSlugFromReadArgs("sales", "references/pricing.md")).toBeUndefined();
    });
});
describe("adminAuthoringSkillBlock", () => {
    it("blocks every content-producer-owned authoring skill from the admin seat", () => {
        for (const slug of CONTENT_PRODUCER_AUTHORING_SKILLS) {
            expect(adminAuthoringSkillBlock(slug, ADMIN)).toBe(true);
        }
    });
    it("does not block the admin's own / admin-invoked skills", () => {
        // unzip-attachment is admin-invoked (admin unzips then routes); deck-pages
        // is admin-owned. plainly/voice-mirror/datetime are admin operational skills.
        for (const slug of ["plainly", "voice-mirror", "datetime", "deck-pages", "unzip-attachment"]) {
            expect(adminAuthoringSkillBlock(slug, ADMIN)).toBe(false);
        }
    });
    it("never blocks the content-producer seat (it owns these skills)", () => {
        expect(adminAuthoringSkillBlock("professional-document", CONTENT_PRODUCER)).toBe(false);
    });
    it("never blocks the public seat (out of scope)", () => {
        expect(adminAuthoringSkillBlock("professional-document", PUBLIC)).toBe(false);
    });
    it("fail-open on an undefined slug or unidentified seat", () => {
        expect(adminAuthoringSkillBlock(undefined, ADMIN)).toBe(false);
        expect(adminAuthoringSkillBlock("professional-document", {})).toBe(false);
    });
});
//# sourceMappingURL=admin-authoring-skill-gate.test.js.map