| 1 | import * as AWS from "@/AWS"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as bedrock from "@distilled.cloud/aws/bedrock-agent"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | |
| 7 | const { test } = Test.make({ providers: AWS.providers() }); |
| 8 | |
| 9 | // Ungated typed-error probes. The full KnowledgeBase + DataSource + Retrieve |
| 10 | // lifecycle is gated behind a vector store (see KnowledgeBase.slow.test.ts); |
| 11 | // these cheap probes prove the distilled error union that the reconcilers' |
| 12 | // observe/read/delete catch paths depend on, at near-zero cost. |
| 13 | |
| 14 | test.provider( |
| 15 | "getKnowledgeBase on a missing id returns a typed ResourceNotFoundException", |
| 16 | (_stack) => |
| 17 | Effect.gen(function* () { |
| 18 | const result = yield* bedrock |
| 19 | .getKnowledgeBase({ knowledgeBaseId: "AAAAAAAAAA" }) |
| 20 | .pipe( |
| 21 | Effect.map(() => "found" as const), |
| 22 | // Compiles only if ResourceNotFoundException is in the typed union. |
| 23 | Effect.catchTag("ResourceNotFoundException", () => |
| 24 | Effect.succeed("not-found" as const), |
| 25 | ), |
| 26 | ); |
| 27 | expect(result).toBe("not-found"); |
| 28 | }), |
| 29 | { tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 }, |
| 30 | ); |
| 31 | |
| 32 | test.provider( |
| 33 | "getDataSource on a missing id returns a typed ResourceNotFoundException", |
| 34 | (_stack) => |
| 35 | Effect.gen(function* () { |
| 36 | const result = yield* bedrock |
| 37 | .getDataSource({ |
| 38 | knowledgeBaseId: "AAAAAAAAAA", |
| 39 | dataSourceId: "BBBBBBBBBB", |
| 40 | }) |
| 41 | .pipe( |
| 42 | Effect.map(() => "found" as const), |
| 43 | Effect.catchTag("ResourceNotFoundException", () => |
| 44 | Effect.succeed("not-found" as const), |
| 45 | ), |
| 46 | ); |
| 47 | expect(result).toBe("not-found"); |
| 48 | }), |
| 49 | { tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 }, |
| 50 | ); |
| 51 | |
| 52 | test.provider( |
| 53 | "getAgent on a missing id returns a typed ResourceNotFoundException", |
| 54 | (_stack) => |
| 55 | Effect.gen(function* () { |
| 56 | const result = yield* bedrock.getAgent({ agentId: "AAAAAAAAAA" }).pipe( |
| 57 | Effect.map(() => "found" as const), |
| 58 | Effect.catchTag("ResourceNotFoundException", () => |
| 59 | Effect.succeed("not-found" as const), |
| 60 | ), |
| 61 | ); |
| 62 | expect(result).toBe("not-found"); |
| 63 | }), |
| 64 | { tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 }, |
| 65 | ); |
| 66 | |
| 67 | test.provider( |
| 68 | "listIngestionJobs on a missing data source returns a typed ResourceNotFoundException", |
| 69 | (_stack) => |
| 70 | Effect.gen(function* () { |
| 71 | const result = yield* bedrock |
| 72 | .listIngestionJobs({ |
| 73 | knowledgeBaseId: "AAAAAAAAAA", |
| 74 | dataSourceId: "BBBBBBBBBB", |
| 75 | }) |
| 76 | .pipe( |
| 77 | Effect.map(() => "found" as const), |
| 78 | // Compiles only if ResourceNotFoundException is in the typed union |
| 79 | // — the error path the ingestion-job bindings depend on. |
| 80 | Effect.catchTag("ResourceNotFoundException", () => |
| 81 | Effect.succeed("not-found" as const), |
| 82 | ), |
| 83 | ); |
| 84 | expect(result).toBe("not-found"); |
| 85 | }), |
| 86 | { tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 }, |
| 87 | ); |
| 88 | |
| 89 | test.provider( |
| 90 | "listKnowledgeBaseDocuments on a missing data source returns a typed ResourceNotFoundException", |
| 91 | (_stack) => |
| 92 | Effect.gen(function* () { |
| 93 | const result = yield* bedrock |
| 94 | .listKnowledgeBaseDocuments({ |
| 95 | knowledgeBaseId: "AAAAAAAAAA", |
| 96 | dataSourceId: "BBBBBBBBBB", |
| 97 | }) |
| 98 | .pipe( |
| 99 | Effect.map(() => "found" as const), |
| 100 | // Compiles only if ResourceNotFoundException is in the typed union |
| 101 | // — the error path the document bindings depend on. |
| 102 | Effect.catchTag("ResourceNotFoundException", () => |
| 103 | Effect.succeed("not-found" as const), |
| 104 | ), |
| 105 | ); |
| 106 | expect(result).toBe("not-found"); |
| 107 | }), |
| 108 | { tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 }, |
| 109 | ); |