@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 136 lines 4.49 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, missingIssueOf, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (name: string) =>
12 ssm.getProjectsLocationsRepositoriesIssuesIssueComments({ 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 "getProjectsLocationsRepositoriesIssuesIssueComments on a missing comment fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 const project = yield* currentProject;
27 const missingIssue = missingIssueOf(project);
28 yield* stack.destroy();
29
30 const error = yield* Effect.flip(
31 ssm.getProjectsLocationsRepositoriesIssuesIssueComments({
32 name: `${missingIssue}/issueComments/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 issue is rejected with a typed tag",
47 (stack) =>
48 Effect.gen(function* () {
49 const project = yield* currentProject;
50 const missingIssue = missingIssueOf(project);
51 yield* stack.destroy();
52
53 const error = yield* Effect.flip(
54 stack.deploy(
55 Effect.gen(function* () {
56 return yield* GCP.SecureSourceManager.RepositoriesIssuesIssueComment("Note", {
57 issue: missingIssue,
58 body: "reproduced on main",
59 });
60 }),
61 ),
62 );
63 expect(error._tag).toEqual("NotFound");
64
65 yield* stack.destroy();
66 }).pipe(logLevel),
67 {
68 tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"],
69 timeout: 90_000,
70 },
71 );
72
73 test.provider.skipIf(!runLifecycle)(
74 "create, update, and delete an issue comment",
75 (stack) =>
76 Effect.gen(function* () {
77 const project = yield* currentProject;
78 const missingIssue = missingIssueOf(project);
79 yield* stack.destroy();
80
81 const created = yield* stack.deploy(
82 Effect.gen(function* () {
83 const issue = yield* GCP.SecureSourceManager.RepositoriesIssue("Bug", {
84 repository:
85 process.env.GCP_TEST_SECURE_SOURCE_MANAGER_REPO ?? missingIssue.split("/issues/")[0]!,
86 title: "comment parent",
87 body: "parent issue",
88 });
89 const comment = yield* GCP.SecureSourceManager.RepositoriesIssuesIssueComment("Note", {
90 issue: issue.name,
91 body: "reproduced on main",
92 });
93 return { issue, comment };
94 }),
95 );
96
97 expect(created.comment.name).toContain("/issueComments/");
98 expect(created.comment.body).toEqual("reproduced on main");
99 expect(created.comment.issue).toEqual(created.issue.name);
100
101 const fetched = yield* ssm.getProjectsLocationsRepositoriesIssuesIssueComments({
102 name: created.comment.name,
103 });
104 expect(fetched.name).toEqual(created.comment.name);
105 expect(fetched.body).toEqual("reproduced on main");
106
107 const updated = yield* stack.deploy(
108 Effect.gen(function* () {
109 const issue = yield* GCP.SecureSourceManager.RepositoriesIssue("Bug", {
110 repository: created.issue.repository,
111 issueId: created.issue.issueId,
112 title: "comment parent",
113 body: "parent issue",
114 });
115 const comment = yield* GCP.SecureSourceManager.RepositoriesIssuesIssueComment("Note", {
116 issue: issue.name,
117 commentId: created.comment.commentId,
118 body: "reproduced on release",
119 });
120 return { issue, comment };
121 }),
122 );
123
124 expect(updated.comment.commentId).toEqual(created.comment.commentId);
125 expect(updated.comment.body).toEqual("reproduced on release");
126
127 yield* stack.destroy();
128
129 const gone = yield* waitUntilGone(created.comment.name);
130 expect(gone).toEqual("gone");
131 }).pipe(logLevel),
132 {
133 tags: ["provider:gcp", "provider:gcp:securesourcemanager", "live"],
134 timeout: 120_000,
135 },
136 );