@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 126 lines 3.92 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as ssm from "@distilled.cloud/gcp/securesourcemanager_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { currentProject, logLevel, missingRepoOf, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 ssm.getProjectsLocationsRepositoriesIssues({ name }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("2 seconds"),
17 until: (status) => status === "gone",
18 times: 10,
19 }),
20 );
21
22 test.provider(
23 "getProjectsLocationsRepositoriesIssues on a missing issue fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 const project = yield* currentProject;
27 const missingRepo = missingRepoOf(project);
28 yield* stack.destroy();
29
30 const error = yield* Effect.flip(
31 ssm.getProjectsLocationsRepositoriesIssues({
32 name: `${missingRepo}/issues/12345`,
33 }),
34 );
35 expect(error._tag).toEqual("NotFound");
36
37 yield* stack.destroy();
38 }).pipe(logLevel),
39 {
40 tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"],
41 timeout: 90_000,
42 },
43 );
44
45 test.provider(
46 "create against a missing repository is rejected with a typed tag",
47 (stack) =>
48 Effect.gen(function* () {
49 const project = yield* currentProject;
50 const missingRepo = missingRepoOf(project);
51 yield* stack.destroy();
52
53 const error = yield* Effect.flip(
54 stack.deploy(
55 Effect.gen(function* () {
56 return yield* GCP.SecureSourceManager.RepositoriesIssue("Bug", {
57 repository: missingRepo,
58 title: "alchemy probe",
59 body: "should not exist",
60 });
61 }),
62 ),
63 );
64 expect(error._tag).toEqual("NotFound");
65
66 yield* stack.destroy();
67 }).pipe(logLevel),
68 {
69 tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"],
70 timeout: 90_000,
71 },
72 );
73
74 test.provider.skipIf(!runLifecycle)(
75 "create, update, and delete an issue",
76 (stack) =>
77 Effect.gen(function* () {
78 const project = yield* currentProject;
79 const missingRepo = missingRepoOf(project);
80 yield* stack.destroy();
81
82 const created = yield* stack.deploy(
83 Effect.gen(function* () {
84 return yield* GCP.SecureSourceManager.RepositoriesIssue("Bug", {
85 repository: process.env.GCP_TEST_SECURE_SOURCE_MANAGER_REPO ?? missingRepo,
86 title: "webhook retries 500s",
87 body: "hooks retry forever on 500",
88 });
89 }),
90 );
91
92 expect(created.name).toContain("/issues/");
93 expect(created.title).toEqual("webhook retries 500s");
94 expect(created.body).toEqual("hooks retry forever on 500");
95
96 const fetched = yield* ssm.getProjectsLocationsRepositoriesIssues({
97 name: created.name,
98 });
99 expect(fetched.name).toEqual(created.name);
100 expect(fetched.body).toEqual("hooks retry forever on 500");
101
102 const updated = yield* stack.deploy(
103 Effect.gen(function* () {
104 return yield* GCP.SecureSourceManager.RepositoriesIssue("Bug", {
105 repository: created.repository,
106 issueId: created.issueId,
107 title: "webhook retries 5xx",
108 body: "cap retries at 8",
109 });
110 }),
111 );
112
113 expect(updated.issueId).toEqual(created.issueId);
114 expect(updated.title).toEqual("webhook retries 5xx");
115 expect(updated.body).toEqual("cap retries at 8");
116
117 yield* stack.destroy();
118
119 const gone = yield* waitUntilGone(created.name);
120 expect(gone).toEqual("gone");
121 }).pipe(logLevel),
122 {
123 tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"],
124 timeout: 120_000,
125 },
126 );