The best way to control Claude Code, Codex and more from any computer or phone

main
ts 125 lines 4.09 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 = (leaderboardId: string) =>
12 gamesConfiguration.getLeaderboardConfigurations({ leaderboardId }).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 "getLeaderboardConfigurations on a missing leaderboard fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 yield* stack.destroy();
27
28 const error = yield* Effect.flip(
29 gamesConfiguration.getLeaderboardConfigurations({
30 leaderboardId: "alchemy-missing-leaderboard",
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 "insertLeaderboardConfigurations 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.insertLeaderboardConfigurations({
51 applicationId: probeApplicationId,
52 body: {
53 scoreOrder: "LARGER_IS_BETTER",
54 draft: {
55 name: {
56 translations: [{ locale: "en-US", value: "Alchemy Probe" }],
57 },
58 scoreFormat: { numberFormatType: "NUMERIC", numDecimalPlaces: 0 },
59 },
60 },
61 }),
62 );
63 expect(error._tag).toEqual("Forbidden");
64
65 yield* stack.destroy();
66 }).pipe(logLevel),
67 {
68 tags: ["provider:gcp", "provider:gcp:gamesconfiguration", "live"],
69 timeout: 90_000,
70 },
71 );
72
73 // Needs a Play Games Services application the credentials administer; without
74 // one the API rejects inserts with Forbidden (probe above).
75 // Set GCP_GAMESCONFIGURATION_APPLICATION_ID to run the lifecycle.
76 test.provider.skipIf(!applicationId)(
77 "create, update, and delete a leaderboard configuration",
78 (stack) =>
79 Effect.gen(function* () {
80 yield* stack.destroy();
81
82 const created = yield* stack.deploy(
83 Effect.gen(function* () {
84 return yield* GCP.GamesConfiguration.LeaderboardConfiguration("HighScore", {
85 applicationId: applicationId!,
86 name: "High Score",
87 scoreOrder: "LARGER_IS_BETTER",
88 });
89 }),
90 );
91
92 expect(created.leaderboardId.length).toBeGreaterThan(0);
93 expect(created.applicationId).toEqual(applicationId);
94 expect(created.name).toEqual("High Score");
95
96 const fetched = yield* gamesConfiguration.getLeaderboardConfigurations({
97 leaderboardId: created.leaderboardId,
98 });
99 expect(fetched.id).toEqual(created.leaderboardId);
100 expect(fetched.draft?.name?.translations?.[0]?.value).toEqual("High Score");
101
102 const updated = yield* stack.deploy(
103 Effect.gen(function* () {
104 return yield* GCP.GamesConfiguration.LeaderboardConfiguration("HighScore", {
105 applicationId: created.applicationId,
106 leaderboardId: created.leaderboardId,
107 name: "All-time High Score",
108 scoreOrder: "LARGER_IS_BETTER",
109 });
110 }),
111 );
112
113 expect(updated.leaderboardId).toEqual(created.leaderboardId);
114 expect(updated.name).toEqual("All-time High Score");
115
116 yield* stack.destroy();
117
118 const gone = yield* waitUntilGone(created.leaderboardId);
119 expect(gone).toEqual("gone");
120 }).pipe(logLevel),
121 {
122 tags: ["provider:gcp", "provider:gcp:gamesconfiguration", "live"],
123 timeout: 90_000,
124 },
125 );