@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 130 lines 4.25 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 gamesConfiguration from "@distilled.cloud/gcp/gamesConfiguration_v1configuration";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { applicationId, logLevel, missingTag, probeApplicationId } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (achievementId: string) =>
12 gamesConfiguration.getAchievementConfigurations({ achievementId }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("1 second"),
17 until: (status) => status === "gone",
18 times: 10,
19 }),
20 );
21
22 test.provider(
23 "getAchievementConfigurations on a missing achievement fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 yield* stack.destroy();
27
28 const error = yield* Effect.flip(
29 gamesConfiguration.getAchievementConfigurations({
30 achievementId: "alchemy-missing-achievement",
31 }),
32 );
33 expect(error._tag).toEqual(missingTag);
34
35 yield* stack.destroy();
36 }).pipe(logLevel),
37 {
38 tags: ["provider:gcp", "provider:gcp:gamesconfiguration", "live"],
39 timeout: 90_000,
40 },
41 );
42
43 test.provider.skipIf(!!applicationId)(
44 "insertAchievementConfigurations without Play Games access fails with a typed tag",
45 (stack) =>
46 Effect.gen(function* () {
47 yield* stack.destroy();
48
49 const error = yield* Effect.flip(
50 gamesConfiguration.insertAchievementConfigurations({
51 applicationId: probeApplicationId,
52 body: {
53 achievementType: "STANDARD",
54 initialState: "REVEALED",
55 draft: {
56 name: {
57 translations: [{ locale: "en-US", value: "Alchemy Probe" }],
58 },
59 description: {
60 translations: [{ locale: "en-US", value: "probe" }],
61 },
62 pointValue: 5,
63 },
64 },
65 }),
66 );
67 expect(error._tag).toEqual("Forbidden");
68
69 yield* stack.destroy();
70 }).pipe(logLevel),
71 {
72 tags: ["provider:gcp", "provider:gcp:gamesconfiguration", "live"],
73 timeout: 90_000,
74 },
75 );
76
77 // Needs a Play Games Services application the credentials administer; without
78 // one the API rejects inserts with Forbidden (probe above).
79 // Set GCP_GAMESCONFIGURATION_APPLICATION_ID to run the lifecycle.
80 test.provider.skipIf(!applicationId)(
81 "create, update, and delete an achievement configuration",
82 (stack) =>
83 Effect.gen(function* () {
84 yield* stack.destroy();
85
86 const created = yield* stack.deploy(
87 Effect.gen(function* () {
88 return yield* GCP.GamesConfiguration.AchievementConfiguration("FirstWin", {
89 applicationId: applicationId!,
90 name: "First Win",
91 description: "Win your first match",
92 });
93 }),
94 );
95
96 expect(created.achievementId.length).toBeGreaterThan(0);
97 expect(created.applicationId).toEqual(applicationId);
98 expect(created.name).toEqual("First Win");
99 expect(created.description).toEqual("Win your first match");
100
101 const fetched = yield* gamesConfiguration.getAchievementConfigurations({
102 achievementId: created.achievementId,
103 });
104 expect(fetched.id).toEqual(created.achievementId);
105 expect(fetched.draft?.description?.translations?.[0]?.value).toEqual("Win your first match");
106
107 const updated = yield* stack.deploy(
108 Effect.gen(function* () {
109 return yield* GCP.GamesConfiguration.AchievementConfiguration("FirstWin", {
110 applicationId: created.applicationId,
111 achievementId: created.achievementId,
112 name: "First Win",
113 description: "Win a match",
114 });
115 }),
116 );
117
118 expect(updated.achievementId).toEqual(created.achievementId);
119 expect(updated.description).toEqual("Win a match");
120
121 yield* stack.destroy();
122
123 const gone = yield* waitUntilGone(created.achievementId);
124 expect(gone).toEqual("gone");
125 }).pipe(logLevel),
126 {
127 tags: ["provider:gcp", "provider:gcp:gamesconfiguration", "live"],
128 timeout: 90_000,
129 },
130 );