The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { assert, describe, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { checksState, originCheck, originFilesPatch, pullReference } from "./originPullRequests.ts"; |
| 4 | |
| 5 | const run = (status: string, conclusion?: string) => |
| 6 | originCheck({ name: `${status}-${conclusion ?? ""}`, status, conclusion }); |
| 7 | |
| 8 | describe("checksState", () => { |
| 9 | it("rolls up Origin check runs", () => { |
| 10 | assert.strictEqual(checksState([]), null); |
| 11 | assert.strictEqual( |
| 12 | checksState([run("completed", "success"), run("completed", "skipped")]), |
| 13 | "passing", |
| 14 | ); |
| 15 | assert.strictEqual(checksState([run("completed", "success"), run("in_progress")]), "pending"); |
| 16 | assert.strictEqual( |
| 17 | checksState([run("completed", "success"), run("completed", "cancelled")]), |
| 18 | "failing", |
| 19 | ); |
| 20 | assert.strictEqual( |
| 21 | checksState([run("in_progress"), run("completed", "action_required")]), |
| 22 | "failing", |
| 23 | ); |
| 24 | }); |
| 25 | }); |
| 26 | |
| 27 | describe("originFilesPatch", () => { |
| 28 | const header = (file: Parameters<typeof originFilesPatch>[0][number]) => |
| 29 | originFilesPatch([file]).split("\n").slice(0, 4); |
| 30 | |
| 31 | it("keeps rename and copy metadata", () => { |
| 32 | assert.deepStrictEqual( |
| 33 | header({ filename: "b.ts", previousFilename: "a.ts", status: "renamed" }), |
| 34 | ["diff --git a/a.ts b/b.ts", "similarity index 100%", "rename from a.ts", "rename to b.ts"], |
| 35 | ); |
| 36 | // Origin leaves out the hunks of large files, which must not read as a pure rename. |
| 37 | assert.strictEqual( |
| 38 | header({ filename: "b.ts", previousFilename: "a.ts", status: "renamed", changes: 4 })[1], |
| 39 | "similarity index 0%", |
| 40 | ); |
| 41 | assert.deepStrictEqual( |
| 42 | header({ |
| 43 | filename: "b.ts", |
| 44 | previousFilename: "a.ts", |
| 45 | status: "copied", |
| 46 | patch: "@@ -1 +1 @@\n-a\n+b", |
| 47 | }).slice(1), |
| 48 | ["similarity index 0%", "copy from a.ts", "copy to b.ts"], |
| 49 | ); |
| 50 | }); |
| 51 | }); |
| 52 | |
| 53 | describe("pullReference", () => { |
| 54 | it("separates pull request numbers, Origin links, and branches", () => { |
| 55 | assert.deepStrictEqual(pullReference("42"), { repository: null, number: 42 }); |
| 56 | assert.deepStrictEqual(pullReference(" #42 "), { repository: null, number: 42 }); |
| 57 | assert.deepStrictEqual(pullReference("https://cursor.com/codebase/Acme/Web/pull/7"), { |
| 58 | repository: "acme/web", |
| 59 | number: 7, |
| 60 | }); |
| 61 | for (const branch of ["123/fix", "feature/pull/42", "https://github.com/acme/web/pull/7"]) |
| 62 | assert.deepStrictEqual(pullReference(branch), { repository: null, number: null }); |
| 63 | }); |
| 64 | }); |