import * as fs from "node:fs/promises";
import * as path from "node:path";
import { expect } from "e2e";
import { T3_HOME } from "../e2e.config.ts";
import { test, WEB } from "./t3.ts";

test("Antigravity skill manifest filters match literally", WEB, async ({ t3, app, screen, browser }) => {
  const skill = (name: string) => `---\nname: ${name}\ndescription: Synthetic ${name} skill\n---\nDo the synthetic task.\n`;
  await t3.project("skill-manifest-demo", {
    "tools/skills/load-test/SKILL.md": skill("load-test"),
    "tools/skills/seed-data/SKILL.md": skill("seed-data"),
    "deploy-skills/deploy-staging/SKILL.md": skill("deploy-staging"),
    "release-skills/release-v2/SKILL.md": skill("release-v2"),
    ".agents/skills.json": JSON.stringify({entries:[
      {path:"tools/skills",exclude:["load-.*"]},
      {path:"deploy-skills",include_only:["deploy-.*"]},
      {path:"release-skills",include_only:["release.v2"]}
    ]}),
  });
  const settingsPath = path.join(T3_HOME, "userdata/settings.json");
  const settings = JSON.parse(await fs.readFile(settingsPath, "utf8"));
  settings.providerInstances.antigravity = { driver: "antigravity", enabled: true, config: { authMethod: "gemini-api-key", apiKey: "scenario-key" } };
  settings.defaultModelSelection = { instanceId: "antigravity", model: "gemini-3.8-flash" };
  await fs.writeFile(settingsPath, JSON.stringify(settings));
  await browser.setViewport({width:1280,height:900});
  await t3.open();
  await screen.getByRole("textbox").fill("$");
  await screen.getByRole("listbox").waitFor({state:"visible"});
  await app.screenshot("skill-picker");
  await expect(screen.getByRole("listbox")).toContainText("load-test");
  await expect(screen.getByRole("listbox")).toContainText("seed-data");
  await expect(screen.getByRole("listbox")).not.toContainText("deploy-staging");
  await expect(screen.getByRole("listbox")).not.toContainText("release-v2");
});
