@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 73 lines 2.36 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
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 BackendHttpLambda from "./fixtures/backend-http-lambda.ts";
11 import { backendBranch } from "./fixtures/backend-resources.ts";
12
13 const { test } = Test.make({
14 providers: Layer.mergeAll(Neon.providers(), AWS.providers()),
15 });
16
17 test.provider(
18 "Lambda HTTP bindings expose only public URLs and a scoped gateway token",
19 (stack) =>
20 Effect.gen(function* () {
21 yield* stack.destroy();
22 const deployed = yield* stack.deploy(
23 Effect.gen(function* () {
24 const branch = yield* backendBranch;
25 const api = yield* BackendHttpLambda;
26 return { branch, url: api.functionUrl };
27 }),
28 );
29 const http = 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({ hasToken: true });
38 const request = {
39 project_id: deployed.branch.projectId,
40 branch_id: deployed.branch.branchId,
41 };
42 const credentials = (yield* SDK.listCredentials(request)).credentials.filter(
43 (item) =>
44 item.principal_type === "user" &&
45 item.branch_id === deployed.branch.branchId &&
46 !item.revoked_at,
47 );
48 expect(credentials).toHaveLength(1);
49 expect(credentials[0].scopes).toContain("ai_gateway:invoke");
50 yield* stack.destroy();
51 expect(
52 yield* SDK.getProjectBranch(request).pipe(
53 Effect.as(false),
54 Effect.catchTag("NotFound", () => Effect.succeed(true)),
55 ),
56 ).toBe(true);
57 yield* stack.destroy();
58 }),
59 {
60 tags: [
61 "provider:aws",
62 "provider:aws:lambda",
63 "provider:neon",
64 "provider:neon:aigateway",
65 "provider:neon:auth",
66 "provider:neon:branch",
67 "provider:neon:dataapi",
68 "provider:neon:project",
69 "live",
70 ],
71 timeout: 240_000,
72 },
73 );