1import * as Alchemy from "alchemy";
2import * as AWS from "alchemy/AWS";
3import * as Test from "alchemy/Test/Bun";
4import { expect } from "bun:test";
5import * as Effect from "effect/Effect";
6import * as Schedule from "effect/Schedule";
7import * as HttpClient from "effect/http/HttpClient";
8import Stack from "../alchemy.run.ts";
9
10const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
11 providers: AWS.providers(),
12 state: Alchemy.localState(),
13});
14
15const stack = beforeAll(deploy(Stack));
16afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack));
17
18test(
19 "generates text through Bedrock",
20 Effect.gen(function* () {
21 const out = (yield* stack) as { url: string };
22 const client = HttpClient.filterStatusOk(yield* HttpClient.HttpClient);
23
24 // Fresh function URLs take a few seconds to start serving 200s.
25 const res = yield* client
26 .get(`${out.url}?prompt=${encodeURIComponent("Say pong.")}`)
27 .pipe(
28 Effect.retry({
29 schedule: Schedule.exponential("1 second"),
30 times: 10,
31 }),
32 );
33 const body = (yield* res.json) as { text: string; finishReason: string };
34 expect(body.text.length).toBeGreaterThan(0);
35 }),
36 { timeout: 300_000 },
37);