@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, 04:45 UTC

main
ts 75 lines 2.66 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Neon from "@alchemy.run/neon";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as SDK from "@distilled.cloud/neon";
6 import * as Effect from "effect/Effect";
7 import * as HttpClient from "effect/http/HttpClient";
8 import * as Layer from "effect/Layer";
9 import * as Schedule from "effect/Schedule";
10 import BackendHttpWorker from "./fixtures/backend-http-worker.ts";
11 import { backendBranch } from "./fixtures/backend-resources.ts";
12
13 const { test } = Test.make({
14 providers: Layer.mergeAll(Neon.providers(), Cloudflare.providers()),
15 });
16
17 test.provider(
18 "Worker HTTP bindings own an AI-scoped credential and revoke it with the host",
19 (stack) =>
20 Effect.gen(function* () {
21 yield* stack.destroy();
22 const application = (includeWorker: boolean) =>
23 Effect.gen(function* () {
24 const branch = yield* backendBranch;
25 const worker = includeWorker ? yield* BackendHttpWorker : undefined;
26 return { branch, url: worker?.url };
27 });
28 const deployed = yield* stack.deploy(application(true));
29 const http = HttpClient.filterStatusOk(yield* HttpClient.HttpClient);
30 const response = yield* http.get(deployed.url!).pipe(
31 Effect.retry({
32 schedule: Schedule.exponential("200 millis"),
33 times: 7,
34 }),
35 );
36 expect(response.status).toBe(200);
37 expect(yield* response.json).toMatchObject({
38 hasToken: true,
39 sharedToken: true,
40 });
41 const request = {
42 project_id: deployed.branch.projectId,
43 branch_id: deployed.branch.branchId,
44 };
45 const credentials = (yield* SDK.listCredentials(request)).credentials.filter(
46 (item) =>
47 item.principal_type === "user" &&
48 item.branch_id === deployed.branch.branchId &&
49 !item.revoked_at,
50 );
51 expect(credentials).toHaveLength(1);
52 expect(credentials[0].scopes).toContain("ai_gateway:invoke");
53 expect(credentials[0].scopes).not.toContain("storage:write");
54 yield* stack.deploy(application(false));
55 const remaining = (yield* SDK.listCredentials(request)).credentials.filter(
56 (item) => item.token_id === credentials[0].token_id && !item.revoked_at,
57 );
58 expect(remaining).toHaveLength(0);
59 yield* stack.destroy();
60 }),
61 {
62 tags: [
63 "provider:cloudflare",
64 "provider:cloudflare:worker",
65 "provider:neon",
66 "provider:neon:aigateway",
67 "provider:neon:auth",
68 "provider:neon:branch",
69 "provider:neon:dataapi",
70 "provider:neon:project",
71 "live",
72 ],
73 timeout: 120_000,
74 },
75 );