import { readFile } from "node:fs/promises";
import path from "node:path";

import { describe, expect, it } from "vitest";

const HELPER_PATH = path.join(import.meta.dirname, "manual-verification-session.js");
const HUMAN_PATH = path.join(import.meta.dirname, "human.js");

describe("manual verification session helper", () => {
  it("opens a headed persistent context with the resolved 1688 profile", async () => {
    const source = await readFile(HELPER_PATH, "utf8");

    expect(source).toContain("launch1688PersistentContext(profileDir");
    expect(source).toContain("headless: false");
    expect(source).toContain("resolve1688ProfileDir");
    expect(source).toContain("manual_intervention_resolved");
  });

  it("headless human handoff emits the shared sentinel instead of launching a search retry", async () => {
    const source = await readFile(HUMAN_PATH, "utf8");

    expect(source).toContain("HEADLESS_MANUAL_VERIFICATION_HANDOFF");
    expect(source).toContain("requires a visible verification helper");
    expect(source).not.toContain("HEADLESS_MANUAL_VERIFICATION_RETRY");
  });
});
