t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/Bedrock/KnowledgeBase.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

109 lines
3.8 KiB
TypeScript

import * as AWS from "@/AWS";
import * as Test from "@/Test/Alchemy";
import * as bedrock from "@distilled.cloud/aws/bedrock-agent";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
const { test } = Test.make({ providers: AWS.providers() });
// Ungated typed-error probes. The full KnowledgeBase + DataSource + Retrieve
// lifecycle is gated behind a vector store (see KnowledgeBase.slow.test.ts);
// these cheap probes prove the distilled error union that the reconcilers'
// observe/read/delete catch paths depend on, at near-zero cost.
test.provider(
"getKnowledgeBase on a missing id returns a typed ResourceNotFoundException",
(_stack) =>
Effect.gen(function* () {
const result = yield* bedrock
.getKnowledgeBase({ knowledgeBaseId: "AAAAAAAAAA" })
.pipe(
Effect.map(() => "found" as const),
// Compiles only if ResourceNotFoundException is in the typed union.
Effect.catchTag("ResourceNotFoundException", () =>
Effect.succeed("not-found" as const),
),
);
expect(result).toBe("not-found");
}),
{ tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 },
);
test.provider(
"getDataSource on a missing id returns a typed ResourceNotFoundException",
(_stack) =>
Effect.gen(function* () {
const result = yield* bedrock
.getDataSource({
knowledgeBaseId: "AAAAAAAAAA",
dataSourceId: "BBBBBBBBBB",
})
.pipe(
Effect.map(() => "found" as const),
Effect.catchTag("ResourceNotFoundException", () =>
Effect.succeed("not-found" as const),
),
);
expect(result).toBe("not-found");
}),
{ tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 },
);
test.provider(
"getAgent on a missing id returns a typed ResourceNotFoundException",
(_stack) =>
Effect.gen(function* () {
const result = yield* bedrock.getAgent({ agentId: "AAAAAAAAAA" }).pipe(
Effect.map(() => "found" as const),
Effect.catchTag("ResourceNotFoundException", () =>
Effect.succeed("not-found" as const),
),
);
expect(result).toBe("not-found");
}),
{ tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 },
);
test.provider(
"listIngestionJobs on a missing data source returns a typed ResourceNotFoundException",
(_stack) =>
Effect.gen(function* () {
const result = yield* bedrock
.listIngestionJobs({
knowledgeBaseId: "AAAAAAAAAA",
dataSourceId: "BBBBBBBBBB",
})
.pipe(
Effect.map(() => "found" as const),
// Compiles only if ResourceNotFoundException is in the typed union
// — the error path the ingestion-job bindings depend on.
Effect.catchTag("ResourceNotFoundException", () =>
Effect.succeed("not-found" as const),
),
);
expect(result).toBe("not-found");
}),
{ tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 },
);
test.provider(
"listKnowledgeBaseDocuments on a missing data source returns a typed ResourceNotFoundException",
(_stack) =>
Effect.gen(function* () {
const result = yield* bedrock
.listKnowledgeBaseDocuments({
knowledgeBaseId: "AAAAAAAAAA",
dataSourceId: "BBBBBBBBBB",
})
.pipe(
Effect.map(() => "found" as const),
// Compiles only if ResourceNotFoundException is in the typed union
// — the error path the document bindings depend on.
Effect.catchTag("ResourceNotFoundException", () =>
Effect.succeed("not-found" as const),
),
);
expect(result).toBe("not-found");
}),
{ tags: ["provider:aws", "provider:aws:bedrock", "live"], timeout: 60_000 },
);