import { writeFile } from "node:fs/promises";
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Inline Claude plugin skills appear in both composer pickers", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("Release notes", {
    "acme-plugin/.claude-plugin/plugin.json": JSON.stringify({ name: "acme", version: "1.0.0" }),
    "acme-plugin/skills/release-notes/SKILL.md": "---\nname: release-notes\ndescription: Draft Acme release notes\n---\nWrite concise release notes.\n",
    "claude-config/skills/control-skill/SKILL.md": "---\nname: control-skill\ndescription: Personal control skill\n---\nSummarise the changes.\n",
  });
  await writeFile(`${project}/claude-config/settings.json`, JSON.stringify({ env: { CLAUDE_CODE_PLUGIN_DIRS: `${project}/acme-plugin` } }));
  const thread = await t3.thread({ project, title: "Inline plugin skill proof", messages: ["Start"] });
  await t3.open("/settings/providers");
  await screen.getByRole("button", "Select Claude").tap();
  await screen.getByRole("switch", "Enable Claude").tap();
  await screen.getByRole("textbox", "CLAUDE_CONFIG_DIR path").fill(`${project}/claude-config`);
  await screen.getByRole("textbox", "CLAUDE_CONFIG_DIR path").press("Tab");
  await t3.open(thread);
  await screen.getByRole("button", "Multi turn").tap();
  await screen.getByRole("button", "Claude").tap();
  await screen.getByRole("option", /Claude Haiku 5.5/).tap();
  await browser.keyboard.press("Escape");
  const composer = screen.getByRole("textbox");
  await composer.tap();
  await composer.pressSequentially("Summarise this, then run /");
  await screen.getByRole("option", /control-skill/).waitFor();
  await app.screenshot("mid-prompt-slash");
  // Capture both pickers before asserting so the base records both missing entries.
  await composer.fill("Draft notes with $");
  await screen.getByRole("option", /control-skill/).waitFor();
  await app.screenshot("dollar-skill-picker");
  await expect(screen.getByRole("option", /acme:release-notes/)).toBeVisible();
  await composer.fill("Summarise this, then run /");
  await expect(screen.getByRole("option", /acme:release-notes/)).toBeVisible();
});
