import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";

const SCRIPT_PATH = join(process.cwd(), "scripts", "record-mothership.sh");

describe("record-mothership.sh (task-121)", () => {
  const content = readFileSync(SCRIPT_PATH, "utf8");

  it("存在且包含 headed 与 codegen 启动", () => {
    expect(content).toContain("RPA_HEADLESS=false");
    expect(content).toContain("playwright");
    expect(content).toContain("codegen");
  });

  it("禁止 GD-15 黑名单 URL", () => {
    expect(content).toContain("dashboard.mothership.com");
    expect(content).toContain("www.mothership.com/quote");
    expect(content).toContain("check_url");
  });

  it("产出录制脚本与 storageState 路径", () => {
    expect(content).toContain(".rpa/recordings");
    expect(content).toContain("mothership-storage.json");
    expect(content).toContain("--save-storage");
  });
});

const TS_SCRIPT_PATH = join(process.cwd(), "scripts", "record-mothership.ts");

describe("record-mothership.ts (Windows 跨平台)", () => {
  const content = readFileSync(TS_SCRIPT_PATH, "utf8");

  it("存在且包含 headed codegen 与 GD-15 校验", () => {
    expect(content).toContain('RPA_HEADLESS: "false"');
    expect(content).toContain("playwright");
    expect(content).toContain("codegen");
    expect(content).toContain("isForbiddenQuoteUrl");
  });

  it("产出录制脚本与 storageState 路径", () => {
    expect(content).toContain(".rpa/recordings");
    expect(content).toContain("mothership-storage.json");
    expect(content).toContain("--save-storage");
  });
});
