import { Effect } from "effect";
import { describe, expect, test } from "vitest";

import {
  decodeGitConnectionInput,
  decodeWorkAttemptExecutionResult,
} from "./execution-runtime";

describe("execution runtime contracts", () => {
  test("accepts one authenticated Gitea connection", async () => {
    const decoded = await Effect.runPromise(
      decodeGitConnectionInput({
        credential: "secret",
        credentialKind: "token",
        provider: "gitea",
        serverUrl: "https://git.example.com",
        username: "zopu",
      })
    );
    expect(decoded.provider).toBe("gitea");
  });

  test("requires exact base and candidate revisions", async () => {
    await expect(
      Effect.runPromise(
        decodeWorkAttemptExecutionResult({
          baseRevision: "",
          candidateRevision: "abc123",
          changedFiles: [],
          diff: "",
          environmentId: "workspace-1",
          events: [],
          summary: "done",
        })
      )
    ).rejects.toMatchObject({ reason: "InvalidInput" });
  });
});
