The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { assert, describe, it } from "@effect/vitest"; |
| 2 | import * as Schema from "effect/Schema"; |
| 3 | |
| 4 | import { |
| 5 | ForgejoComment, |
| 6 | ForgejoPullRequest, |
| 7 | ForgejoReview, |
| 8 | forgejoChangeRequest, |
| 9 | forgejoComment, |
| 10 | forgejoReview, |
| 11 | } from "./forgejoPullRequestJson.ts"; |
| 12 | |
| 13 | const decodeForgejoComment = Schema.decodeSync(ForgejoComment); |
| 14 | const decodeForgejoPullRequest = Schema.decodeSync(ForgejoPullRequest); |
| 15 | const decodeForgejoReview = Schema.decodeSync(ForgejoReview); |
| 16 | |
| 17 | describe("forgejoComment", () => { |
| 18 | const createdAt = "2026-10-10T19:52:40Z"; |
| 19 | const comment = (updatedAt: string | null | undefined) => |
| 20 | forgejoComment( |
| 21 | decodeForgejoComment({ |
| 22 | id: 29061, |
| 23 | body: "Performance: five rounds complete", |
| 24 | user: { login: "forgejo-actions" }, |
| 25 | created_at: createdAt, |
| 26 | ...(updatedAt === undefined ? {} : { updated_at: updatedAt }), |
| 27 | }), |
| 28 | ); |
| 29 | |
| 30 | it.each([undefined, null, createdAt, "2026-10-10T19:52:40.000Z"])( |
| 31 | "reads no edit from an updated_at of %s", |
| 32 | (updatedAt) => { |
| 33 | const mapped = comment(updatedAt); |
| 34 | assert.strictEqual(mapped.createdAt, "2026-10-10T19:52:40.000Z"); |
| 35 | assert.isUndefined(mapped.editedAt); |
| 36 | }, |
| 37 | ); |
| 38 | |
| 39 | it("reads a later updated_at as an edit, in UTC milliseconds", () => { |
| 40 | const mapped = comment("2026-10-10T20:04:50Z"); |
| 41 | assert.strictEqual(mapped.id, "29061"); |
| 42 | assert.strictEqual(mapped.author?.login, "forgejo-actions"); |
| 43 | assert.strictEqual(mapped.editedAt, "2026-10-10T20:04:50.000Z"); |
| 44 | }); |
| 45 | }); |
| 46 | |
| 47 | describe("forgejoChangeRequest", () => { |
| 48 | const headBranch = ( |
| 49 | head: { ref: string; label?: string; repo: { full_name: string } | null }, |
| 50 | flow?: number, |
| 51 | ) => |
| 52 | forgejoChangeRequest( |
| 53 | decodeForgejoPullRequest({ |
| 54 | number: 7, |
| 55 | title: "Merged feature", |
| 56 | body: null, |
| 57 | html_url: "https://forgejo.test/maria/project/pulls/7", |
| 58 | user: null, |
| 59 | state: "closed", |
| 60 | merged: true, |
| 61 | ...(flow === undefined ? {} : { flow }), |
| 62 | head: { ...head, sha: "head" }, |
| 63 | base: { ref: "main", label: "main", sha: "base", repo: null }, |
| 64 | created_at: "2026-10-10T19:52:40Z", |
| 65 | updated_at: "2026-10-12T00:00:00Z", |
| 66 | closed_at: "2026-10-12T00:00:00Z", |
| 67 | merged_at: "2026-10-12T00:00:00Z", |
| 68 | labels: null, |
| 69 | }), |
| 70 | ).headBranch; |
| 71 | |
| 72 | it("reads a deleted head branch from its label", () => { |
| 73 | const head = { ref: "refs/pull/7/head", label: "feature" }; |
| 74 | const repo = { full_name: "maria/project" }; |
| 75 | assert.strictEqual(headBranch({ ...head, repo }, 0), "feature"); |
| 76 | // A deleted fork leaves no repository to say whose `feature` that was. |
| 77 | assert.strictEqual(headBranch({ ...head, repo: null }), "refs/pull/7/head"); |
| 78 | // An AGit label is a `user/topic` name, not a branch. |
| 79 | assert.strictEqual(headBranch({ ...head, label: "alice/topic", repo }, 1), "refs/pull/7/head"); |
| 80 | }); |
| 81 | |
| 82 | it("keeps the ref when the server sends no label", () => { |
| 83 | assert.strictEqual(headBranch({ ref: "feature", repo: null }), "feature"); |
| 84 | }); |
| 85 | }); |
| 86 | |
| 87 | describe("forgejoReview", () => { |
| 88 | it.each([ |
| 89 | ["REQUEST_CHANGES", false, "CHANGES_REQUESTED"], |
| 90 | ["REQUEST_CHANGES", true, "DISMISSED"], |
| 91 | ["APPROVED", true, "DISMISSED"], |
| 92 | ])("reads %s with dismissed %s as %s", (state, dismissed, reviewState) => { |
| 93 | const mapped = forgejoReview( |
| 94 | decodeForgejoReview({ |
| 95 | id: 8, |
| 96 | body: "", |
| 97 | user: { login: "maria" }, |
| 98 | state, |
| 99 | dismissed, |
| 100 | submitted_at: "2026-10-10T19:52:40Z", |
| 101 | comments_count: 0, |
| 102 | }), |
| 103 | ); |
| 104 | assert.strictEqual(mapped.reviewState, reviewState); |
| 105 | }); |
| 106 | }); |