import { describe, expect, it } from "vitest"; import { assertExplicitRepositoryTransfer, assertRepositoryTransferHasNoDeliveryHistory, GiteaRepositoryOwnershipConflictError, GiteaRepositoryTransferBlockedError, } from "../src/integrations/gitea/service.js"; import { integrationError } from "../src/routes/giteaIntegration.js"; describe("Gitea repository ownership", () => { const existing = { projectId: "project-a", project: { name: "Project A" } }; it("blocks a silent move to another project with an HTTP 409 conflict", () => { let conflict: unknown; try { assertExplicitRepositoryTransfer(existing, "project-b", "Acme/platform", false); } catch (error) { conflict = error; } expect(conflict).toBeInstanceOf(GiteaRepositoryOwnershipConflictError); expect(integrationError(conflict)).toMatchObject({ status: 409, code: "GITEA_REPOSITORY_ALREADY_LINKED", }); }); it("allows same-project updates and an explicitly confirmed transfer", () => { expect(() => assertExplicitRepositoryTransfer(existing, "project-a", "Acme/platform", false)).not.toThrow(); expect(() => assertExplicitRepositoryTransfer(existing, "project-b", "Acme/platform", true)).not.toThrow(); }); it("blocks even an explicit transfer when delivery history would cross project boundaries", () => { let conflict: unknown; try { assertRepositoryTransferHasNoDeliveryHistory("Acme/platform", 2); } catch (error) { conflict = error; } expect(conflict).toBeInstanceOf(GiteaRepositoryTransferBlockedError); expect(integrationError(conflict)).toMatchObject({ status: 409, code: "GITEA_REPOSITORY_TRANSFER_BLOCKED", }); expect(() => assertRepositoryTransferHasNoDeliveryHistory("Acme/platform", 0)).not.toThrow(); }); });