#!/usr/bin/env python3
"""Verify the Claude package hides namespaced skills in favor of bare aliases."""

from __future__ import annotations

import json
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path


ROOT = Path(__file__).resolve().parent.parent
CONFIGURE = ROOT / "scripts" / "configure-claude-plugin-skills.py"


def main() -> int:
    manifest = json.loads((ROOT / ".claude-plugin" / "plugin.json").read_text(encoding="utf-8"))
    assert "mcpServers" not in manifest
    mcp = json.loads((ROOT / ".mcp.json").read_text(encoding="utf-8"))
    assert set(mcp) == {"mcpServers"}
    assert set(mcp["mcpServers"]) == {"carbon"}
    server = mcp["mcpServers"]["carbon"]
    assert server["command"] == "node"
    assert server["cwd"] == "."
    assert server["args"] == ["./server/index.js"]

    with tempfile.TemporaryDirectory(prefix="carbon-claude-package-") as temporary:
        prepared = Path(temporary) / "carbon"
        prepared.mkdir()
        shutil.copytree(ROOT / "skills", prepared / "skills")
        subprocess.run(
            [sys.executable, str(CONFIGURE), str(prepared), "--apply"],
            check=True,
            capture_output=True,
            text=True,
        )
        skills = sorted((prepared / "skills").glob("*/SKILL.md"))
        assert len(skills) == 44
        for skill in skills:
            text = skill.read_text(encoding="utf-8")
            assert text.count("user-invocable: false") == 1
            assert "disable-model-invocation: true" not in text

        canonical = sorted((ROOT / "skills").glob("*/SKILL.md"))
        assert len(canonical) == 44
        assert all("user-invocable: false" not in path.read_text(encoding="utf-8") for path in canonical)

    print(
        "PASS: Claude package uses its root .mcp.json runtime and hides 44 namespaced skills "
        "while canonical Codex skills remain unchanged."
    )
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
