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

main
ts 87 lines 3.32 KB
Raw
1 import * as Neon from "@alchemy.run/neon";
2 import { scopeIdentity, usesInjectedCredentials } from "@alchemy.run/neon/CredentialScope";
3 import { expect, test } from "@alchemy.run/test";
4 import * as Output from "alchemy/Output";
5 import * as Effect from "effect/Effect";
6 import * as Layer from "effect/Layer";
7
8 const branch = { projectId: "project", branchId: "branch" };
9 const host = { Type: "Neon.Function", Props: { branch }, Mode: undefined };
10
11 test(
12 "HTTP credentials use injection only for a known same-branch live Function",
13 () => {
14 expect(usesInjectedCredentials(host, { branch }, "live")).toBe(true);
15 expect(usesInjectedCredentials(host, { branch: { ...branch } }, "live")).toBe(true);
16 expect(
17 usesInjectedCredentials(host, { branch: { ...branch, branchId: "other" } }, "live"),
18 ).toBe(false);
19 expect(
20 usesInjectedCredentials(host, { branch: { ...branch, projectId: "other" } }, "live"),
21 ).toBe(false);
22 expect(usesInjectedCredentials(host, { branch }, "local")).toBe(false);
23 expect(usesInjectedCredentials({ ...host, Mode: "live" }, { branch }, "local")).toBe(true);
24 expect(usesInjectedCredentials({ ...host, Mode: "local" }, { branch }, "live")).toBe(false);
25 for (const Type of ["Cloudflare.Worker", "AWS.Lambda.Function"]) {
26 expect(usesInjectedCredentials({ ...host, Type }, { branch }, "live")).toBe(false);
27 }
28 expect(usesInjectedCredentials(undefined, { branch }, "live")).toBe(false);
29 },
30 { tags: ["unit", "provider:neon", "local"] },
31 );
32
33 test(
34 "HTTP credentials preserve project scope and reject ambiguous unresolved identities",
35 () => {
36 const project = { projectId: "project" };
37 expect(
38 usesInjectedCredentials({ ...host, Props: { project } }, { project: { ...project } }, "live"),
39 ).toBe(true);
40 expect(usesInjectedCredentials(host, { project }, "live")).toBe(false);
41 const unresolved = { projectId: Output.literal("project"), branchId: Output.literal("branch") };
42 expect(scopeIdentity({ branch: unresolved })).toBeUndefined();
43 expect(
44 usesInjectedCredentials({ ...host, Props: { branch: unresolved } }, { branch }, "live"),
45 ).toBe(false);
46 expect(
47 usesInjectedCredentials({ ...host, Props: Effect.succeed({ branch }) }, { branch }, "live"),
48 ).toBe(false);
49 expect(usesInjectedCredentials({ ...host, Props: undefined }, { branch }, "live")).toBe(false);
50 expect(
51 usesInjectedCredentials(
52 { ...host, Props: { branch: unresolved } },
53 { branch: unresolved },
54 "live",
55 ),
56 ).toBe(true);
57 },
58 { tags: ["unit", "provider:neon", "local"] },
59 );
60
61 test(
62 "Neon exposes only HTTP implementation layers",
63 () => {
64 expect("ConnectDataApi" in Neon).toBe(false);
65 expect("ConnectDataApiHttp" in Neon).toBe(false);
66 expect("ConnectAIGateway" in Neon).toBe(false);
67 expect("ConnectAIGatewayHttp" in Neon).toBe(false);
68 for (const name of [
69 "Connect",
70 "ConnectAuth",
71 "QueryDataApi",
72 "QueryAIGateway",
73 "ReadBucket",
74 "WriteBucket",
75 "ReadWriteBucket",
76 "ReadObject",
77 "WriteObject",
78 "InvokeFunction",
79 "CronEventSource",
80 "BucketEventSource",
81 ]) {
82 expect(`${name}Binding` in Neon).toBe(false);
83 expect(Layer.isLayer(Reflect.get(Neon, `${name}Http`))).toBe(true);
84 }
85 },
86 { tags: ["unit", "provider:neon", "local"] },
87 );