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
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as neptunegraph from "@distilled.cloud/aws/neptune-graph"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as HttpClient from "effect/http/HttpClient"; |
| 7 | import * as HttpClientRequest from "effect/http/HttpClientRequest"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | import NeptuneGraphTestFunctionLive, { FixtureGraph, NeptuneGraphTestFunction } from "./handler.ts"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: AWS.providers() }); |
| 12 | |
| 13 | // Ungated typed-error probe: proves the distilled error union carries the |
| 14 | // not-found tag this provider's read/delete/wait paths depend on. Runs in |
| 15 | // every CI pass at near-zero cost, unlike the gated lifecycle below. |
| 16 | test.provider( |
| 17 | "getGraph on a nonexistent graph fails with ResourceNotFoundException", |
| 18 | () => |
| 19 | Effect.gen(function* () { |
| 20 | const error = yield* Effect.flip( |
| 21 | // Well-formed but nonexistent graph id (g-<10 alphanumerics>). |
| 22 | neptunegraph.getGraph({ graphIdentifier: "g-0123456789" }), |
| 23 | ); |
| 24 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 25 | }), |
| 26 | { tags: ["provider:aws", "provider:aws:neptunegraph", "live"] }, |
| 27 | ); |
| 28 | |
| 29 | // The snapshot / import-task / export-task bindings address resources by |
| 30 | // server-generated ids that only exist at runtime — probe their typed |
| 31 | // not-found tags so the account-level grants and error unions stay proven |
| 32 | // without provisioning a graph. |
| 33 | test.provider( |
| 34 | "getGraphSnapshot on a nonexistent snapshot fails with ResourceNotFoundException", |
| 35 | () => |
| 36 | Effect.gen(function* () { |
| 37 | const error = yield* Effect.flip( |
| 38 | // Well-formed but nonexistent snapshot id (gs-<10 alphanumerics>). |
| 39 | neptunegraph.getGraphSnapshot({ snapshotIdentifier: "gs-0123456789" }), |
| 40 | ); |
| 41 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 42 | }), |
| 43 | { tags: ["provider:aws", "provider:aws:neptunegraph", "live"] }, |
| 44 | ); |
| 45 | |
| 46 | test.provider( |
| 47 | "getImportTask on a nonexistent task fails with ResourceNotFoundException", |
| 48 | () => |
| 49 | Effect.gen(function* () { |
| 50 | const error = yield* Effect.flip( |
| 51 | neptunegraph.getImportTask({ taskIdentifier: "t-0123456789" }), |
| 52 | ); |
| 53 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 54 | }), |
| 55 | { tags: ["provider:aws", "provider:aws:neptunegraph", "live"] }, |
| 56 | ); |
| 57 | |
| 58 | test.provider( |
| 59 | "getExportTask on a nonexistent task fails with ResourceNotFoundException", |
| 60 | () => |
| 61 | Effect.gen(function* () { |
| 62 | const error = yield* Effect.flip( |
| 63 | neptunegraph.getExportTask({ taskIdentifier: "t-0123456789" }), |
| 64 | ); |
| 65 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 66 | }), |
| 67 | { tags: ["provider:aws", "provider:aws:neptunegraph", "live"] }, |
| 68 | ); |
| 69 | |
| 70 | const assertGraphGone = (graphId: string) => |
| 71 | neptunegraph.getGraph({ graphIdentifier: graphId }).pipe( |
| 72 | Effect.flatMap((graph) => |
| 73 | Effect.fail(new Error(`graph '${graphId}' still exists (status: ${graph.status})`)), |
| 74 | ), |
| 75 | Effect.catchTag("ResourceNotFoundException", () => Effect.void), |
| 76 | Effect.retry({ schedule: Schedule.max([Schedule.fixed("10 seconds"), Schedule.recurs(30)]) }), |
| 77 | ); |
| 78 | |
| 79 | // A Neptune Analytics graph takes ~5-10 minutes to provision and bills per |
| 80 | // m-NCU-hour (16 m-NCUs here) while it exists. The full lifecycle — graph + |
| 81 | // Lambda running openCypher through the ExecuteQuery binding — is skipped |
| 82 | // under `--fast` and always destroys what it created. |
| 83 | test.provider.skipIf(!!process.env.FAST)( |
| 84 | "create graph, query it from Lambda via ExecuteQuery, destroy", |
| 85 | (stack) => |
| 86 | Effect.gen(function* () { |
| 87 | // Clean slate in case a previous run died mid-flight. |
| 88 | yield* stack.destroy(); |
| 89 | |
| 90 | const { graph, fn } = yield* stack.deploy( |
| 91 | Effect.gen(function* () { |
| 92 | const { graph } = yield* FixtureGraph; |
| 93 | const fn = yield* NeptuneGraphTestFunction; |
| 94 | return { graph, fn }; |
| 95 | }).pipe(Effect.provide(NeptuneGraphTestFunctionLive)), |
| 96 | ); |
| 97 | |
| 98 | expect(graph.graphId).toMatch(/^g-/); |
| 99 | expect(graph.graphArn).toContain(":graph/"); |
| 100 | expect(graph.status).toBe("AVAILABLE"); |
| 101 | expect(graph.provisionedMemory).toBe(16); |
| 102 | expect(graph.publicConnectivity).toBe(true); |
| 103 | expect(graph.replicaCount).toBe(0); |
| 104 | expect(graph.deletionProtection).toBe(false); |
| 105 | expect(graph.endpoint).toContain("neptune-graph"); |
| 106 | |
| 107 | // Out-of-band verification via distilled. |
| 108 | const observed = yield* neptunegraph.getGraph({ graphIdentifier: graph.graphId }); |
| 109 | expect(observed.status).toBe("AVAILABLE"); |
| 110 | expect(observed.name).toBe(graph.graphName); |
| 111 | |
| 112 | // Drive the deployed Lambda. First request rides URL propagation — |
| 113 | // bounded retry. |
| 114 | const baseUrl = fn.functionUrl!.replace(/\/+$/, ""); |
| 115 | |
| 116 | const graphInfo = yield* HttpClient.get(`${baseUrl}/graph`).pipe( |
| 117 | Effect.flatMap((res) => |
| 118 | res.status === 200 ? res.json : Effect.fail(new Error(`/graph returned ${res.status}`)), |
| 119 | ), |
| 120 | Effect.retry({ |
| 121 | schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(40)]), |
| 122 | }), |
| 123 | ); |
| 124 | expect((graphInfo as { graphId: string }).graphId).toBe(graph.graphId); |
| 125 | |
| 126 | // openCypher through the ExecuteQuery binding: write a node, read it |
| 127 | // back. |
| 128 | const query = (body: { query: string; parameters?: Record<string, unknown> }) => |
| 129 | HttpClient.execute( |
| 130 | HttpClientRequest.post(`${baseUrl}/query`).pipe(HttpClientRequest.bodyJsonUnsafe(body)), |
| 131 | ).pipe( |
| 132 | Effect.flatMap((res) => |
| 133 | res.status === 200 |
| 134 | ? res.json |
| 135 | : res.text.pipe( |
| 136 | Effect.flatMap((text) => |
| 137 | Effect.fail(new Error(`/query returned ${res.status}: ${text}`)), |
| 138 | ), |
| 139 | ), |
| 140 | ), |
| 141 | Effect.retry({ |
| 142 | schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(10)]), |
| 143 | }), |
| 144 | ); |
| 145 | |
| 146 | yield* query({ query: "CREATE (n:Person {name: $name})", parameters: { name: "Ada" } }); |
| 147 | const read = (yield* query({ query: "MATCH (n:Person) RETURN n.name AS name" })) as { |
| 148 | results: Array<{ name: string }>; |
| 149 | }; |
| 150 | expect(read.results).toEqual([{ name: "Ada" }]); |
| 151 | |
| 152 | const getJson = (path: string) => |
| 153 | HttpClient.get(`${baseUrl}${path}`).pipe( |
| 154 | Effect.flatMap((res) => |
| 155 | res.status === 200 |
| 156 | ? res.json |
| 157 | : res.text.pipe( |
| 158 | Effect.flatMap((text) => |
| 159 | Effect.fail(new Error(`${path} returned ${res.status}: ${text}`)), |
| 160 | ), |
| 161 | ), |
| 162 | ), |
| 163 | Effect.retry({ |
| 164 | schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(10)]), |
| 165 | }), |
| 166 | ); |
| 167 | |
| 168 | // GetGraphSummary binding: the summary document reflects the graph. |
| 169 | const summary = (yield* getJson("/summary")) as { graphSummary?: { numNodes?: number } }; |
| 170 | expect(summary.graphSummary).toBeDefined(); |
| 171 | |
| 172 | // ListQueries binding: returns a well-formed (usually empty) list. |
| 173 | const queries = (yield* getJson("/queries")) as { queries: unknown[] }; |
| 174 | expect(Array.isArray(queries.queries)).toBe(true); |
| 175 | |
| 176 | // ListGraphSnapshots binding: fresh graph has no snapshots. |
| 177 | const snapshots = (yield* getJson("/snapshots")) as { graphSnapshots: unknown[] }; |
| 178 | expect(Array.isArray(snapshots.graphSnapshots)).toBe(true); |
| 179 | |
| 180 | // Destroy immediately — the graph bills while it exists — and verify |
| 181 | // it is fully gone out-of-band. |
| 182 | yield* stack.destroy(); |
| 183 | yield* assertGraphGone(graph.graphId); |
| 184 | }), |
| 185 | // graph create (~5-10 min) + lambda deploy + delete-until-gone, one test. |
| 186 | { |
| 187 | tags: ["provider:aws", "provider:aws:lambda", "provider:aws:neptunegraph", "live"], |
| 188 | timeout: 1_500_000, |
| 189 | }, |
| 190 | ); |