import { describe, expect, it } from "vitest";
import { join } from "node:path";
import { FLOW_ASSET_MAPPINGS, validateFlowAssetCoverage } from "../../src/docs/index.js";

const FLOW_ROOT = join(process.cwd(), "work/doc/通用机器人项目功能与数据流程图-png");

describe("flow asset coverage", () => {
  it("maps every Mermaid and PNG flow asset to tasks and evidence", () => {
    const result = validateFlowAssetCoverage(FLOW_ROOT);

    expect(result.ok).toBe(true);
    expect(result.assets.map((asset) => asset.id)).toEqual(["flow-01", "flow-02", "flow-03", "flow-04", "flow-05"]);
    expect(result.assets.every((asset) => asset.mermaidBytes > 0 && asset.pngBytes > 0)).toBe(true);
    expect(result.assets.every((asset) => asset.evidence === "EV-211")).toBe(true);
    expect(result.assets.every((asset) => asset.tasks.some((task) => task.startsWith("KW-211")))).toBe(true);
    expect(result.diagnostics).toEqual([]);
  });

  it("keeps the expected coverage contract stable", () => {
    expect(FLOW_ASSET_MAPPINGS).toEqual([
      expect.objectContaining({ id: "flow-01", tasks: expect.arrayContaining(["KW-211.1"]) }),
      expect.objectContaining({ id: "flow-02", tasks: expect.arrayContaining(["KW-211.2"]) }),
      expect.objectContaining({ id: "flow-03", tasks: expect.arrayContaining(["KW-211.3"]) }),
      expect.objectContaining({ id: "flow-04", tasks: expect.arrayContaining(["KW-211.4"]) }),
      expect.objectContaining({ id: "flow-05", tasks: expect.arrayContaining(["KW-211.5"]) })
    ]);
  });
});
