native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
10 kB · 322 lines
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323import Foundationimport Testing
@testable import supacode
struct GithubBatchPullRequestsTests { @Test func mapsGraphQLAliasesToBranches() throws { let json = """ { "data": { "repository": { "branch0": { "nodes": [ { "number": 1, "title": "Fork PR", "state": "OPEN", "additions": 1, "deletions": 0, "isDraft": false, "reviewDecision": null, "updatedAt": "2025-01-03T00:00:00Z", "url": "https://github.com/other/repo/pull/1", "headRefName": "feature-a", "headRepository": { "name": "repo", "owner": { "login": "other" } } }, { "number": 2, "title": "Primary PR", "state": "OPEN", "additions": 2, "deletions": 1, "isDraft": false, "reviewDecision": "APPROVED", "updatedAt": "2025-01-02T00:00:00Z", "url": "https://github.com/octo/repo/pull/2", "headRefName": "feature-a", "headRepository": { "name": "repo", "owner": { "login": "octo" } } } ] }, "branch1": { "nodes": [] } } } } """ let data = Data(json.utf8) let decoder = JSONDecoder() decoder.dateDecodingStrategy = .iso8601 let response = try decoder.decode(GithubGraphQLPullRequestResponse.self, from: data) let prs = response.pullRequestsByBranch( aliasMap: ["branch0": "feature-a", "branch1": "feature-b"], owner: "octo", repo: "repo" ) #expect(prs["feature-a"]?.number == 2) #expect(prs["feature-a"]?.title == "Primary PR") #expect(prs["feature-b"] == nil) }
@Test func ignoresForkOnlyMatches() throws { let json = """ { "data": { "repository": { "branch0": { "nodes": [ { "number": 9, "title": "Fork PR", "state": "OPEN", "additions": 1, "deletions": 0, "isDraft": false, "reviewDecision": null, "updatedAt": "2025-01-01T00:00:00Z", "url": "https://github.com/fork/repo/pull/9", "headRefName": "feature-a", "headRepository": { "name": "repo", "owner": { "login": "fork" } } } ] } } } } """ let data = Data(json.utf8) let decoder = JSONDecoder() decoder.dateDecodingStrategy = .iso8601 let response = try decoder.decode(GithubGraphQLPullRequestResponse.self, from: data) let prs = response.pullRequestsByBranch( aliasMap: ["branch0": "feature-a"], owner: "octo", repo: "repo" ) #expect(prs["feature-a"] == nil) }
@Test func ignoresPullRequestWithUnknownHeadRepository() throws { let json = """ { "data": { "repository": { "branch0": { "nodes": [ { "number": 7, "title": "Deleted Fork", "state": "MERGED", "additions": 1, "deletions": 0, "isDraft": false, "reviewDecision": null, "updatedAt": "2025-01-02T00:00:00Z", "url": "https://github.com/octo/repo/pull/7", "headRefName": "feature-a", "headRepository": null } ] } } } } """ let data = Data(json.utf8) let decoder = JSONDecoder() decoder.dateDecodingStrategy = .iso8601 let response = try decoder.decode(GithubGraphQLPullRequestResponse.self, from: data) let prs = response.pullRequestsByBranch( aliasMap: ["branch0": "feature-a"], owner: "octo", repo: "repo" ) #expect(prs["feature-a"] == nil) }
@Test func ignoresForkEvenWhenBaseBranchDiffers() throws { let json = """ { "data": { "repository": { "branch0": { "nodes": [ { "number": 12, "title": "Same Branch Candidate", "state": "OPEN", "additions": 1, "deletions": 0, "isDraft": false, "reviewDecision": null, "updatedAt": "2025-01-03T00:00:00Z", "url": "https://github.com/fork/repo/pull/12", "headRefName": "feature-a", "baseRefName": "feature-a", "headRepository": { "name": "repo", "owner": { "login": "fork" } } }, { "number": 13, "title": "Fork PR From Feature", "state": "OPEN", "additions": 1, "deletions": 0, "isDraft": false, "reviewDecision": null, "updatedAt": "2025-01-01T00:00:00Z", "url": "https://github.com/fork/repo/pull/13", "headRefName": "feature-a", "baseRefName": "main", "headRepository": { "name": "repo", "owner": { "login": "fork" } } } ] } } } } """ let data = Data(json.utf8) let decoder = JSONDecoder() decoder.dateDecodingStrategy = .iso8601 let response = try decoder.decode(GithubGraphQLPullRequestResponse.self, from: data) let prs = response.pullRequestsByBranch( aliasMap: ["branch0": "feature-a"], owner: "octo", repo: "repo" ) #expect(prs["feature-a"] == nil) }
@Test func prefersOpenOverMergedEvenIfOlder() throws { let json = """ { "data": { "repository": { "branch0": { "nodes": [ { "number": 10, "title": "Merged PR", "state": "MERGED", "additions": 1, "deletions": 0, "isDraft": false, "reviewDecision": null, "updatedAt": "2026-01-02T00:00:00Z", "url": "https://github.com/octo/repo/pull/10", "headRefName": "feature-a", "headRepository": { "name": "repo", "owner": { "login": "octo" } } }, { "number": 11, "title": "Open PR", "state": "OPEN", "additions": 2, "deletions": 1, "isDraft": false, "reviewDecision": null, "updatedAt": "2026-01-01T00:00:00Z", "url": "https://github.com/octo/repo/pull/11", "headRefName": "feature-a", "headRepository": { "name": "repo", "owner": { "login": "octo" } } } ] } } } } """ let data = Data(json.utf8) let decoder = JSONDecoder() decoder.dateDecodingStrategy = .iso8601 let response = try decoder.decode(GithubGraphQLPullRequestResponse.self, from: data) let prs = response.pullRequestsByBranch( aliasMap: ["branch0": "feature-a"], owner: "octo", repo: "repo" ) #expect(prs["feature-a"]?.number == 11) #expect(prs["feature-a"]?.title == "Open PR") }
@Test func fallsBackToLatestMerged() throws { let json = """ { "data": { "repository": { "branch0": { "nodes": [ { "number": 20, "title": "Merged Older", "state": "MERGED", "additions": 1, "deletions": 0, "isDraft": false, "reviewDecision": null, "updatedAt": "2026-01-01T00:00:00Z", "url": "https://github.com/octo/repo/pull/20", "headRefName": "feature-a", "headRepository": { "name": "repo", "owner": { "login": "octo" } } }, { "number": 21, "title": "Merged Newer", "state": "MERGED", "additions": 2, "deletions": 1, "isDraft": false, "reviewDecision": null, "updatedAt": "2026-01-03T00:00:00Z", "url": "https://github.com/octo/repo/pull/21", "headRefName": "feature-a", "headRepository": { "name": "repo", "owner": { "login": "octo" } } } ] } } } } """ let data = Data(json.utf8) let decoder = JSONDecoder() decoder.dateDecodingStrategy = .iso8601 let response = try decoder.decode(GithubGraphQLPullRequestResponse.self, from: data) let prs = response.pullRequestsByBranch( aliasMap: ["branch0": "feature-a"], owner: "octo", repo: "repo" ) #expect(prs["feature-a"]?.number == 21) #expect(prs["feature-a"]?.title == "Merged Newer") }}