import { describe, expect, it } from "vitest";
import { renderLiveProject } from "../../apps/web/src/live.js";

describe("live tool log and rendered diff", () => {
  it("renders named tool calls and semantic added/removed diff lines", () => {
    const html = renderLiveProject({
      acceptance: { checked: 14, total: 30 },
      project: {
        id: "project-tool-diff",
        name: "Tool and diff evidence",
        repositoryUrl: "https://example.test/repository.git",
        status: "active",
      },
      goals: [],
      plans: [],
      tasks: [],
      factoryRuns: [{ id: "factory-tool-diff", taskId: "task-tool-diff", status: "running" }],
      agentRuns: [
        {
          id: "agent-tool-diff",
          taskId: "task-tool-diff",
          status: "completed",
        },
      ],
      attempts: [
        {
          id: "attempt-tool-diff",
          agentRunId: "agent-tool-diff",
          status: "terminal",
          selection: { kind: "initial", reason: "initial dispatch" },
          toolCalls: [
            {
              name: "write_patch",
              summary: "Updated the implementation and tests",
            },
          ],
        },
      ],
      changeSets: [
        {
          id: "changeset-tool-diff",
          status: "candidate-ready",
          diff: [
            "diff --git a/example.txt b/example.txt",
            "--- a/example.txt",
            "+++ b/example.txt",
            "@@ -1 +1 @@",
            "-old <value>",
            "+new <value>",
          ].join("\n"),
        },
      ],
      reviews: [],
    });

    expect(html).toContain("<strong data-golive-fraction>14 / 30</strong>");
    expect(html).toContain('data-factory-run-id="factory-tool-diff"');
    expect(html).toContain('data-tool-call="write_patch"');
    expect(html).toContain("Updated the implementation and tests");
    expect(html).toContain(
      '<span class="diff-line removed"><code>-old &lt;value&gt;</code></span>',
    );
    expect(html).toContain('<span class="diff-line added"><code>+new &lt;value&gt;</code></span>');
    expect(html).not.toContain("<pre>");
  });
});
