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, 06:00 UTC
| 1 | import * as GitHub from "@alchemy.run/github"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Issues from "@distilled.cloud/github/issues"; |
| 5 | import * as Output from "alchemy/Output"; |
| 6 | import * as Provider from "alchemy/Provider"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Stream from "effect/Stream"; |
| 9 | import { scopedToOwner } from "./scope.ts"; |
| 10 | import { gh } from "./scope.ts"; |
| 11 | |
| 12 | const { test } = Test.make({ |
| 13 | providers: GitHub.providers({ baseUrl: "github.com" }), |
| 14 | }); |
| 15 | |
| 16 | const owner = process.env.GITHUB_TEST_OWNER ?? "alchemy-run-test"; |
| 17 | if (!["alchemy-run-test", "alchemy-run-test-2"].includes(owner)) { |
| 18 | throw new Error("GITHUB_TEST_OWNER must be alchemy-run-test or alchemy-run-test-2"); |
| 19 | } |
| 20 | |
| 21 | const repoNameOf = (repo: GitHub.Repository) => |
| 22 | Output.map(repo.fullName, (name) => name.split("/")[1]!); |
| 23 | |
| 24 | test.provider( |
| 25 | "create and update label", |
| 26 | (stack) => |
| 27 | Effect.gen(function* () { |
| 28 | yield* stack.destroy(); |
| 29 | const testId = "label-test"; |
| 30 | const repoName = `test-label-${testId}`; |
| 31 | |
| 32 | // Create a test repository with label |
| 33 | const deploy1 = () => |
| 34 | stack.deploy( |
| 35 | Effect.gen(function* () { |
| 36 | const repo = yield* GitHub.Repository(testId, { |
| 37 | owner, |
| 38 | name: repoName, |
| 39 | autoInit: true, |
| 40 | visibility: "public", |
| 41 | }); |
| 42 | |
| 43 | const label = yield* GitHub.Label("bug", { |
| 44 | owner, |
| 45 | repository: repoNameOf(repo), |
| 46 | name: "bug", |
| 47 | color: "d73a4a", |
| 48 | description: "Something isn't working", |
| 49 | }); |
| 50 | |
| 51 | return { repo, label }; |
| 52 | }), |
| 53 | ); |
| 54 | |
| 55 | const result1 = yield* deploy1(); |
| 56 | expect(result1.label.name).toBe("bug"); |
| 57 | expect(result1.label.color).toBe("d73a4a"); |
| 58 | expect(result1.label.description).toBe("Something isn't working"); |
| 59 | |
| 60 | // Update the label |
| 61 | const deploy2 = () => |
| 62 | stack.deploy( |
| 63 | Effect.gen(function* () { |
| 64 | const repo = yield* GitHub.Repository(testId, { |
| 65 | owner, |
| 66 | name: repoName, |
| 67 | autoInit: true, |
| 68 | visibility: "public", |
| 69 | }); |
| 70 | |
| 71 | const label = yield* GitHub.Label("bug", { |
| 72 | owner, |
| 73 | repository: repoNameOf(repo), |
| 74 | name: "bug", |
| 75 | color: "ff0000", |
| 76 | description: "Updated: Critical bug", |
| 77 | }); |
| 78 | |
| 79 | return { repo, label }; |
| 80 | }), |
| 81 | ); |
| 82 | |
| 83 | const result2 = yield* deploy2(); |
| 84 | expect(result2.label.name).toBe("bug"); |
| 85 | expect(result2.label.color).toBe("ff0000"); |
| 86 | expect(result2.label.description).toBe("Updated: Critical bug"); |
| 87 | expect(result2.label.labelId).toBe(result1.label.labelId); |
| 88 | const observed = yield* gh(Issues.getLabel({ owner, repo: repoName, name: "bug" })); |
| 89 | expect(observed.id).toBe(result1.label.labelId); |
| 90 | expect(observed.color).toBe("ff0000"); |
| 91 | expect(observed.description).toBe("Updated: Critical bug"); |
| 92 | |
| 93 | yield* stack.destroy(); |
| 94 | const remaining = yield* gh( |
| 95 | Stream.runCollect( |
| 96 | Issues.listLabelsForRepo.items({ |
| 97 | owner, |
| 98 | repo: repoName, |
| 99 | }), |
| 100 | ), |
| 101 | ); |
| 102 | expect(remaining.some((label) => label.name === "bug")).toBe(false); |
| 103 | }), |
| 104 | { |
| 105 | tags: ["provider:github", "provider:github:label", "provider:github:repository", "live"], |
| 106 | timeout: 120_000, |
| 107 | }, |
| 108 | ); |
| 109 | |
| 110 | test.provider( |
| 111 | "create multiple labels", |
| 112 | (stack) => |
| 113 | Effect.gen(function* () { |
| 114 | yield* stack.destroy(); |
| 115 | const testId = "label-multi"; |
| 116 | const repoName = `test-label-${testId}`; |
| 117 | |
| 118 | const deploy = () => |
| 119 | stack.deploy( |
| 120 | Effect.gen(function* () { |
| 121 | const repo = yield* GitHub.Repository(testId, { |
| 122 | owner, |
| 123 | name: repoName, |
| 124 | autoInit: true, |
| 125 | visibility: "public", |
| 126 | }); |
| 127 | |
| 128 | const labels = { |
| 129 | bug: yield* GitHub.Label("bug", { |
| 130 | owner, |
| 131 | repository: repoNameOf(repo), |
| 132 | name: "bug", |
| 133 | color: "d73a4a", |
| 134 | description: "Something isn't working", |
| 135 | }), |
| 136 | feature: yield* GitHub.Label("feature", { |
| 137 | owner, |
| 138 | repository: repoNameOf(repo), |
| 139 | name: "feature", |
| 140 | color: "a2eeef", |
| 141 | description: "New feature or request", |
| 142 | }), |
| 143 | documentation: yield* GitHub.Label("docs", { |
| 144 | owner, |
| 145 | repository: repoNameOf(repo), |
| 146 | name: "documentation", |
| 147 | color: "0075ca", |
| 148 | description: "Improvements to documentation", |
| 149 | }), |
| 150 | }; |
| 151 | |
| 152 | return { repo, labels }; |
| 153 | }), |
| 154 | ); |
| 155 | |
| 156 | const result = yield* deploy(); |
| 157 | expect(result.labels.bug.name).toBe("bug"); |
| 158 | expect(result.labels.feature.name).toBe("feature"); |
| 159 | expect(result.labels.documentation.name).toBe("documentation"); |
| 160 | |
| 161 | yield* stack.destroy(); |
| 162 | }), |
| 163 | { |
| 164 | tags: ["provider:github", "provider:github:label", "provider:github:repository", "live"], |
| 165 | timeout: 120_000, |
| 166 | }, |
| 167 | ); |
| 168 | |
| 169 | test.provider( |
| 170 | "replace label when name changes", |
| 171 | (stack) => |
| 172 | Effect.gen(function* () { |
| 173 | yield* stack.destroy(); |
| 174 | const testId = "label-replace"; |
| 175 | const repoName = `test-label-${testId}`; |
| 176 | |
| 177 | // Create label with original name |
| 178 | const deploy1 = () => |
| 179 | stack.deploy( |
| 180 | Effect.gen(function* () { |
| 181 | const repo = yield* GitHub.Repository(testId, { |
| 182 | owner, |
| 183 | name: repoName, |
| 184 | autoInit: true, |
| 185 | visibility: "public", |
| 186 | }); |
| 187 | |
| 188 | const label = yield* GitHub.Label("work", { |
| 189 | owner, |
| 190 | repository: repoNameOf(repo), |
| 191 | name: "wip", |
| 192 | color: "fbca04", |
| 193 | }); |
| 194 | |
| 195 | return { repo, label }; |
| 196 | }), |
| 197 | ); |
| 198 | |
| 199 | const result1 = yield* deploy1(); |
| 200 | expect(result1.label.name).toBe("wip"); |
| 201 | const originalId = result1.label.labelId; |
| 202 | |
| 203 | // Change name (should replace) |
| 204 | const deploy2 = () => |
| 205 | stack.deploy( |
| 206 | Effect.gen(function* () { |
| 207 | const repo = yield* GitHub.Repository(testId, { |
| 208 | owner, |
| 209 | name: repoName, |
| 210 | autoInit: true, |
| 211 | visibility: "public", |
| 212 | }); |
| 213 | |
| 214 | const label = yield* GitHub.Label("work", { |
| 215 | owner, |
| 216 | repository: repoNameOf(repo), |
| 217 | name: "in-progress", |
| 218 | color: "fbca04", |
| 219 | }); |
| 220 | |
| 221 | return { repo, label }; |
| 222 | }), |
| 223 | ); |
| 224 | |
| 225 | const result2 = yield* deploy2(); |
| 226 | expect(result2.label.name).toBe("in-progress"); |
| 227 | expect(result2.label.labelId).not.toBe(originalId); |
| 228 | |
| 229 | yield* stack.destroy(); |
| 230 | }), |
| 231 | { |
| 232 | tags: ["provider:github", "provider:github:label", "provider:github:repository", "live"], |
| 233 | timeout: 120_000, |
| 234 | }, |
| 235 | ); |
| 236 | |
| 237 | test.provider( |
| 238 | "list enumeration includes deployed label", |
| 239 | (stack) => |
| 240 | Effect.gen(function* () { |
| 241 | yield* stack.destroy(); |
| 242 | const testId = "label-list"; |
| 243 | const repoName = `test-label-${testId}`; |
| 244 | |
| 245 | const deploy = () => |
| 246 | stack.deploy( |
| 247 | Effect.gen(function* () { |
| 248 | const repo = yield* GitHub.Repository(testId, { |
| 249 | owner, |
| 250 | name: repoName, |
| 251 | autoInit: true, |
| 252 | visibility: "public", |
| 253 | }); |
| 254 | |
| 255 | const label = yield* GitHub.Label("test", { |
| 256 | owner, |
| 257 | repository: repoNameOf(repo), |
| 258 | name: `test-${testId}`, |
| 259 | color: "ededed", |
| 260 | description: "For list test", |
| 261 | }); |
| 262 | |
| 263 | return { repo, label }; |
| 264 | }), |
| 265 | ); |
| 266 | |
| 267 | const result = yield* deploy(); |
| 268 | |
| 269 | // List all labels and verify ours is included |
| 270 | const provider = yield* Provider.findProvider(GitHub.Label); |
| 271 | const allLabels = yield* provider.list().pipe(scopedToOwner(owner)); |
| 272 | const found = allLabels.find((l) => l.labelId === result.label.labelId); |
| 273 | |
| 274 | expect(found).toBeDefined(); |
| 275 | expect(found?.name).toBe(result.label.name); |
| 276 | |
| 277 | yield* stack.destroy(); |
| 278 | }), |
| 279 | { |
| 280 | tags: ["provider:github", "provider:github:label", "provider:github:repository", "live"], |
| 281 | timeout: 120_000, |
| 282 | }, |
| 283 | ); |
| 284 | |
| 285 | test.provider( |
| 286 | "label with default color", |
| 287 | (stack) => |
| 288 | Effect.gen(function* () { |
| 289 | yield* stack.destroy(); |
| 290 | const testId = "label-default"; |
| 291 | const repoName = `test-label-${testId}`; |
| 292 | |
| 293 | const deploy = () => |
| 294 | stack.deploy( |
| 295 | Effect.gen(function* () { |
| 296 | const repo = yield* GitHub.Repository(testId, { |
| 297 | owner, |
| 298 | name: repoName, |
| 299 | autoInit: true, |
| 300 | visibility: "public", |
| 301 | }); |
| 302 | |
| 303 | const label = yield* GitHub.Label("custom", { |
| 304 | owner, |
| 305 | repository: repoNameOf(repo), |
| 306 | name: "custom-label", |
| 307 | // color omitted, should use default |
| 308 | description: "Uses default color", |
| 309 | }); |
| 310 | |
| 311 | return { repo, label }; |
| 312 | }), |
| 313 | ); |
| 314 | |
| 315 | const result = yield* deploy(); |
| 316 | expect(result.label.name).toBe("custom-label"); |
| 317 | expect(result.label.color).toBeDefined(); |
| 318 | |
| 319 | yield* stack.destroy(); |
| 320 | }), |
| 321 | { |
| 322 | tags: ["provider:github", "provider:github:label", "provider:github:repository", "live"], |
| 323 | timeout: 120_000, |
| 324 | }, |
| 325 | ); |