The best way to control Claude Code, Codex and more from any computer or phone

main
ts 48 lines 1.68 KB
Raw
1 import { describe, expect, it } from "@effect/vitest";
2
3 import {
4 changeBatches,
5 emptySelection,
6 isSelected,
7 selectionChanges,
8 toggleSelection,
9 type SelectionDraft,
10 } from "./pullRequestSelection.ts";
11
12 const host = new Set(["bug"]);
13 const hostSelected = (key: string) => host.has(key);
14
15 function pick(draft: SelectionDraft<string>, key: string) {
16 return toggleSelection(draft, key, key, hostSelected(key));
17 }
18
19 describe("pull request selection draft", () => {
20 it("collapses several picks into one add and one remove", () => {
21 let draft = emptySelection<string>();
22 for (const key of ["docs", "bug", "feature", "chore", "chore"]) draft = pick(draft, key);
23 expect(isSelected(draft, "bug", true)).toBe(false);
24 expect(isSelected(draft, "docs", false)).toBe(true);
25 expect(selectionChanges(draft, hostSelected)).toEqual({
26 add: ["docs", "feature"],
27 remove: ["bug"],
28 });
29 });
30
31 it("sends nothing for a pick toggled back", () => {
32 const draft = pick(pick(emptySelection(), "bug"), "bug");
33 expect(draft.size).toBe(0);
34 expect(selectionChanges(draft, hostSelected)).toEqual({ add: [], remove: [] });
35 });
36
37 it("diffs against the host's state at close, not at the pick", () => {
38 const draft = pick(pick(emptySelection(), "docs"), "bug");
39 const refreshed = new Set(["docs"]);
40 expect(selectionChanges(draft, (key) => refreshed.has(key))).toEqual({ add: [], remove: [] });
41 });
42
43 it("splits a change into writes the contract accepts", () => {
44 const labels = Array.from({ length: 26 }, (_, index) => `label-${index}`);
45 expect(changeBatches(labels).map((batch) => batch.length)).toEqual([25, 1]);
46 expect(changeBatches([])).toEqual([]);
47 });
48 });