The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { applyPullRequestDraftFilterChange, parsePullRequestQuery } from "./pullRequestQuery.ts"; |
| 3 | |
| 4 | describe("reading qualifiers out of a typed query", () => { |
| 5 | it("keeps quoted values whole and separates negation", () => { |
| 6 | expect(parsePullRequestQuery('label:"needs design" -label:wip Fix the parser')).toEqual({ |
| 7 | text: "Fix the parser", |
| 8 | filters: { labels: [["needs design"]], excludedLabels: ["wip"] }, |
| 9 | }); |
| 10 | }); |
| 11 | |
| 12 | it("keeps the spaces in a quoted name of a list, and drops an empty part", () => { |
| 13 | expect(parsePullRequestQuery('label:"needs design","wip"').filters.labels).toEqual([ |
| 14 | ["needs design", "wip"], |
| 15 | ]); |
| 16 | expect(parsePullRequestQuery("label:a,,b").filters.labels).toEqual([["a", "b"]]); |
| 17 | }); |
| 18 | |
| 19 | it("makes each label qualifier its own group, so the groups are an AND", () => { |
| 20 | expect(parsePullRequestQuery("label:bug label:a,b").filters.labels).toEqual([ |
| 21 | ["bug"], |
| 22 | ["a", "b"], |
| 23 | ]); |
| 24 | }); |
| 25 | |
| 26 | it("reads the scalar qualifiers in GitHub's own spelling", () => { |
| 27 | expect( |
| 28 | parsePullRequestQuery("author:octocat DRAFT:false review:changes_requested status:failure") |
| 29 | .filters, |
| 30 | ).toEqual({ |
| 31 | author: "octocat", |
| 32 | draft: "hide", |
| 33 | review: "changes-requested", |
| 34 | checks: "failing", |
| 35 | }); |
| 36 | expect(parsePullRequestQuery("-draft:true").filters).toEqual({ draft: "hide" }); |
| 37 | }); |
| 38 | |
| 39 | it("leaves an unknown value and a stray colon as text, and reads an unknown key as a label", () => { |
| 40 | const parsed = parsePullRequestQuery("milestone:v2 draft:maybe status: parser"); |
| 41 | expect(parsed.filters).toEqual({ labels: [["milestone:v2"]] }); |
| 42 | expect(parsed.text).toBe("draft:maybe status: parser"); |
| 43 | expect(parsePullRequestQuery("review:constructor checks:__proto__ Status:toString")).toEqual({ |
| 44 | text: "review:constructor checks:__proto__ Status:toString", |
| 45 | filters: {}, |
| 46 | }); |
| 47 | }); |
| 48 | |
| 49 | it("reads a quoted name holding a comma as the one label it is", () => { |
| 50 | expect(parsePullRequestQuery('label:"needs,triage"').filters.labels).toEqual([ |
| 51 | ["needs,triage"], |
| 52 | ]); |
| 53 | expect(parsePullRequestQuery('label:"needs,triage",wip').filters.labels).toEqual([ |
| 54 | ["needs,triage", "wip"], |
| 55 | ]); |
| 56 | expect(parsePullRequestQuery('-label:"needs,triage"').filters.excludedLabels).toEqual([ |
| 57 | "needs,triage", |
| 58 | ]); |
| 59 | }); |
| 60 | |
| 61 | // regression: #30131 a query pasted from github.com lists nothing |
| 62 | it("ignores GitHub's own search qualifiers instead of reading them as labels", () => { |
| 63 | expect( |
| 64 | parsePullRequestQuery( |
| 65 | "is:pr state:open archived:false repo:org/repo org:org user:alice sort:updated-desc -repo:org/fork -state:closed fix", |
| 66 | ), |
| 67 | ).toEqual({ text: "fix", filters: {} }); |
| 68 | }); |
| 69 | |
| 70 | it("sets no author when the query names more than one", () => { |
| 71 | expect(parsePullRequestQuery("author:alice author:bob").filters).toEqual({}); |
| 72 | expect(parsePullRequestQuery("author:me author:@me").filters).toEqual({ author: "me" }); |
| 73 | }); |
| 74 | |
| 75 | it("cuts a typed query back to what the contract carries", () => { |
| 76 | const many = Array.from({ length: 14 }, (_, index) => `l${index}`).join(","); |
| 77 | const long = "x".repeat(240); |
| 78 | const parsed = parsePullRequestQuery( |
| 79 | `label:${many} label:${long} author:${long} ${"fix ".repeat(80)}`, |
| 80 | ); |
| 81 | expect(parsed.filters.labels?.[0]).toHaveLength(10); |
| 82 | expect(parsed.filters.labels?.[1]).toEqual(["x".repeat(200)]); |
| 83 | expect(parsed.filters.author).toBe("x".repeat(200)); |
| 84 | expect(parsed.text).toBe("fix ".repeat(50).trim()); |
| 85 | }); |
| 86 | }); |
| 87 | |
| 88 | describe("colon-namespaced labels typed as a search", () => { |
| 89 | it("reads an unknown key as the label it almost always is", () => { |
| 90 | expect(parsePullRequestQuery("size:XXL").filters.labels).toEqual([["size:XXL"]]); |
| 91 | expect(parsePullRequestQuery("vouch:trusted").filters.labels).toEqual([["vouch:trusted"]]); |
| 92 | expect(parsePullRequestQuery("size:XXL").text).toBe(""); |
| 93 | }); |
| 94 | |
| 95 | it("reads the key as the namespace of every bare name in its list", () => { |
| 96 | expect(parsePullRequestQuery("size:S,XS").filters.labels).toEqual([["size:S", "size:XS"]]); |
| 97 | }); |
| 98 | |
| 99 | it("leaves a name that already carries its own namespace alone", () => { |
| 100 | expect(parsePullRequestQuery("size:S,size:XS").filters.labels).toEqual([["size:S", "size:XS"]]); |
| 101 | }); |
| 102 | |
| 103 | // regression: #19934 negated key:value qualifiers become namespaced label exclusions |
| 104 | it("excludes one the same way", () => { |
| 105 | expect(parsePullRequestQuery("-size:XXL").filters.excludedLabels).toEqual(["size:XXL"]); |
| 106 | expect(parsePullRequestQuery("-size:S,XS").filters.excludedLabels).toEqual([ |
| 107 | "size:S", |
| 108 | "size:XS", |
| 109 | ]); |
| 110 | }); |
| 111 | |
| 112 | it("keeps a quoted token as text, which is the way back to a literal search", () => { |
| 113 | const parsed = parsePullRequestQuery('"size:XXL"'); |
| 114 | expect(parsed.filters.labels).toBeUndefined(); |
| 115 | expect(parsed.text).toBe('"size:XXL"'); |
| 116 | }); |
| 117 | |
| 118 | it("reads a hyphenated namespace as a label too", () => { |
| 119 | expect(parsePullRequestQuery("priority-1:high").filters.labels).toEqual([["priority-1:high"]]); |
| 120 | expect(parsePullRequestQuery("priority-1:high").text).toBe(""); |
| 121 | }); |
| 122 | |
| 123 | it("leaves a pasted link alone rather than naming a label after its scheme", () => { |
| 124 | const parsed = parsePullRequestQuery("https://github.com/pingdotgg/t3code/pull/1"); |
| 125 | expect(parsed.filters.labels).toBeUndefined(); |
| 126 | expect(parsed.text).toBe("https://github.com/pingdotgg/t3code/pull/1"); |
| 127 | }); |
| 128 | |
| 129 | it("mixes with the keys it does know, and with plain words", () => { |
| 130 | const parsed = parsePullRequestQuery("area:web draft:true wizard label:bug"); |
| 131 | expect(parsed.filters).toEqual({ labels: [["area:web"], ["bug"]], draft: "only" }); |
| 132 | expect(parsed.text).toBe("wizard"); |
| 133 | }); |
| 134 | }); |
| 135 | |
| 136 | describe("changing the draft menu after typing a qualifier", () => { |
| 137 | it("replaces or clears a typed draft qualifier and keeps the rest of the query", () => { |
| 138 | expect( |
| 139 | applyPullRequestDraftFilterChange( |
| 140 | 'draft:false fix label:"needs design"', |
| 141 | {}, |
| 142 | { draft: "only" }, |
| 143 | ), |
| 144 | ).toEqual({ query: 'fix label:"needs design"', filters: { draft: "only" } }); |
| 145 | expect( |
| 146 | applyPullRequestDraftFilterChange('draft:true "draft:false" fix', { draft: "only" }, {}), |
| 147 | ).toEqual({ |
| 148 | query: '"draft:false" fix', |
| 149 | filters: {}, |
| 150 | }); |
| 151 | }); |
| 152 | |
| 153 | it("keeps the typed query and the stored menu draft when another filter changes", () => { |
| 154 | expect( |
| 155 | applyPullRequestDraftFilterChange( |
| 156 | "draft:false fix", |
| 157 | { draft: "only" }, |
| 158 | { draft: "hide", checks: "passing" }, |
| 159 | ), |
| 160 | ).toEqual({ query: "draft:false fix", filters: { draft: "only", checks: "passing" } }); |
| 161 | }); |
| 162 | }); |