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, 03:37 UTC
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { |
| 4 | issueAssigneesAfterPicks, |
| 5 | issueLabelsAfterPicks, |
| 6 | issuePicksAfterFailedWrite, |
| 7 | issuePicksFor, |
| 8 | issueWriteAfterPicks, |
| 9 | noIssuePicks, |
| 10 | type IssuePicks, |
| 11 | } from "./issueSelection.ts"; |
| 12 | import { emptySelection, toggleSelection } from "./pullRequestSelection.ts"; |
| 13 | |
| 14 | const label = (name: string) => ({ name, color: null, description: null }); |
| 15 | const person = (login: string, id: string) => ({ login, id, name: null, avatarUrl: null }); |
| 16 | |
| 17 | describe("issue picker picks", () => { |
| 18 | it("writes the whole label set once, and nothing when the picks cancel out", () => { |
| 19 | const detail = { labels: [label("bug"), label("ui")] }; |
| 20 | let draft = emptySelection<ReturnType<typeof label>>(); |
| 21 | draft = toggleSelection(draft, "docs", label("docs"), false); |
| 22 | draft = toggleSelection(draft, "bug", label("bug"), true); |
| 23 | expect(issueLabelsAfterPicks(detail, draft)).toEqual(["ui", "docs"]); |
| 24 | draft = toggleSelection(draft, "docs", label("docs"), false); |
| 25 | draft = toggleSelection(draft, "bug", label("bug"), true); |
| 26 | expect(issueLabelsAfterPicks(detail, draft)).toBeNull(); |
| 27 | }); |
| 28 | |
| 29 | it("keeps assignees by login and adds new ones by the tracker's id", () => { |
| 30 | const detail = { assignees: [person("Julius", "u1"), person("theo", "u2")] }; |
| 31 | let draft = emptySelection<ReturnType<typeof person>>(); |
| 32 | draft = toggleSelection(draft, "u1", person("julius", "u1"), true); |
| 33 | draft = toggleSelection(draft, "u3", person("mark", "u3"), false); |
| 34 | expect(issueAssigneesAfterPicks(detail, draft)).toEqual(["theo", "u3"]); |
| 35 | }); |
| 36 | |
| 37 | it("builds a second write on the first while the detail has not caught up", () => { |
| 38 | type Label = ReturnType<typeof label>; |
| 39 | const stale = { labels: [label("bug")] }; |
| 40 | const names = (detail: typeof stale) => detail.labels.map((entry) => entry.name); |
| 41 | const pick = (picks: IssuePicks<Label>, detail: typeof stale, name: string) => { |
| 42 | const current = issuePicksFor(picks, detail, true); |
| 43 | const held = names(detail).includes(name); |
| 44 | return { ...current, draft: toggleSelection(current.draft, name, label(name), held) }; |
| 45 | }; |
| 46 | const close = (picks: IssuePicks<Label>, detail: typeof stale) => { |
| 47 | const current = issuePicksFor(picks, detail, true); |
| 48 | const write = issueWriteAfterPicks( |
| 49 | issueLabelsAfterPicks(detail, current.draft), |
| 50 | names(detail), |
| 51 | current.written, |
| 52 | ); |
| 53 | return { write, picks: write === null ? current : { ...current, written: write } }; |
| 54 | }; |
| 55 | |
| 56 | const first = close(pick(noIssuePicks<Label>(), stale, "docs"), stale); |
| 57 | expect(first.write).toEqual(["bug", "docs"]); |
| 58 | // Reopened before the refreshed detail arrives: the second pick keeps the first. |
| 59 | const second = close(pick(first.picks, stale, "ui"), stale); |
| 60 | expect(second.write).toEqual(["bug", "docs", "ui"]); |
| 61 | expect(close(second.picks, stale).write).toBeNull(); |
| 62 | // Taking both back writes the set the stale detail still shows. |
| 63 | const undone = close(pick(pick(second.picks, stale, "docs"), stale, "ui"), stale); |
| 64 | expect(undone.write).toEqual(["bug"]); |
| 65 | |
| 66 | const fresh = { labels: [label("bug"), label("docs"), label("ui")] }; |
| 67 | expect(issuePicksFor(second.picks, fresh, false).draft.size).toBe(0); |
| 68 | // A picker still open over the refresh keeps its picks, which the fresh detail now confirms. |
| 69 | expect(close(pick(second.picks, fresh, "p1"), fresh).write).toEqual([ |
| 70 | "bug", |
| 71 | "docs", |
| 72 | "ui", |
| 73 | "p1", |
| 74 | ]); |
| 75 | }); |
| 76 | |
| 77 | it("keeps picks made after a write that then fails, and forgets the failed ones otherwise", () => { |
| 78 | const detail = { labels: [label("bug")] }; |
| 79 | const picked = issuePicksFor(noIssuePicks<ReturnType<typeof label>>(), detail, true); |
| 80 | const sent = { |
| 81 | ...picked, |
| 82 | draft: toggleSelection(picked.draft, "docs", label("docs"), false), |
| 83 | written: ["bug", "docs"], |
| 84 | }; |
| 85 | expect(issuePicksAfterFailedWrite(sent, sent).draft.size).toBe(0); |
| 86 | |
| 87 | const later = { ...sent, draft: toggleSelection(sent.draft, "ui", label("ui"), false) }; |
| 88 | const kept = issuePicksAfterFailedWrite(later, sent); |
| 89 | expect(kept.written).toBeNull(); |
| 90 | expect(issueLabelsAfterPicks(detail, kept.draft)).toEqual(["bug", "docs", "ui"]); |
| 91 | |
| 92 | const rewritten = { ...later, written: ["bug", "docs", "ui"] }; |
| 93 | expect(issuePicksAfterFailedWrite(rewritten, sent)).toBe(rewritten); |
| 94 | }); |
| 95 | }); |