|
| 1 | +import { afterEach, describe, expect, test } from "bun:test"; |
| 2 | +import type { ActorSummary, SessionSummary } from "@aws-sdk/client-bedrock-agentcore"; |
| 3 | +import type { MemorySummary } from "@aws-sdk/client-bedrock-agentcore-control"; |
| 4 | +import { |
| 5 | + cleanupScreens, |
| 6 | + renderScreen, |
| 7 | + TestCoreClient, |
| 8 | + waitFor, |
| 9 | + waitForText, |
| 10 | +} from "../../../testing"; |
| 11 | + |
| 12 | +afterEach(cleanupScreens); |
| 13 | + |
| 14 | +function memorySummary(overrides: Partial<MemorySummary> = {}): MemorySummary { |
| 15 | + return { |
| 16 | + arn: "arn:aws:bedrock-agentcore:us-east-1:123456789012:memory/memory-1", |
| 17 | + id: "memory-1", |
| 18 | + status: "ACTIVE", |
| 19 | + createdAt: new Date("2026-07-19T01:02:03.000Z"), |
| 20 | + updatedAt: new Date("2026-07-20T12:34:56.000Z"), |
| 21 | + ...overrides, |
| 22 | + }; |
| 23 | +} |
| 24 | + |
| 25 | +function actor(overrides: Partial<ActorSummary> = {}): ActorSummary { |
| 26 | + return { |
| 27 | + actorId: "actor-1", |
| 28 | + ...overrides, |
| 29 | + }; |
| 30 | +} |
| 31 | + |
| 32 | +function session(overrides: Partial<SessionSummary> = {}): SessionSummary { |
| 33 | + return { |
| 34 | + sessionId: "session-1", |
| 35 | + actorId: "actor-1", |
| 36 | + createdAt: new Date("2026-08-02T10:20:30.000Z"), |
| 37 | + ...overrides, |
| 38 | + }; |
| 39 | +} |
| 40 | + |
| 41 | +describe("Memory actor list flow", () => { |
| 42 | + test("uses the Memory picker, lists actors, then opens the actor's sessions", async () => { |
| 43 | + const memoryId = "memory/blue one"; |
| 44 | + const actorId = "actor/blue one"; |
| 45 | + const core = new TestCoreClient(); |
| 46 | + core.memory.setListResponse({ memories: [memorySummary({ id: memoryId })] }); |
| 47 | + core.memory.setListActorsResponse({ actorSummaries: [actor({ actorId })] }); |
| 48 | + core.memory.setListSessionsResponse({ |
| 49 | + sessionSummaries: [session({ actorId })], |
| 50 | + }); |
| 51 | + const screen = renderScreen("/agentcore/memory/actor/list", { core }); |
| 52 | + |
| 53 | + await waitForText(screen.lastFrame, memoryId); |
| 54 | + await screen.press("return"); |
| 55 | + await waitForText(screen.lastFrame, actorId); |
| 56 | + await screen.press("return"); |
| 57 | + await waitForText(screen.lastFrame, "session-1"); |
| 58 | + |
| 59 | + expect(core.memory.calls.find((call) => call.method === "listActors")).toEqual({ |
| 60 | + method: "listActors", |
| 61 | + args: [ |
| 62 | + { |
| 63 | + memoryId, |
| 64 | + maxResults: expect.any(Number), |
| 65 | + nextToken: undefined, |
| 66 | + }, |
| 67 | + { region: "us-east-1" }, |
| 68 | + ], |
| 69 | + }); |
| 70 | + expect(core.memory.calls.find((call) => call.method === "listSessions")).toEqual({ |
| 71 | + method: "listSessions", |
| 72 | + args: [ |
| 73 | + { |
| 74 | + memoryId, |
| 75 | + actorId, |
| 76 | + maxResults: expect.any(Number), |
| 77 | + nextToken: undefined, |
| 78 | + }, |
| 79 | + { region: "us-east-1" }, |
| 80 | + ], |
| 81 | + }); |
| 82 | + |
| 83 | + await screen.press("escape"); |
| 84 | + await waitForText(screen.lastFrame, "choose an actor to list sessions for"); |
| 85 | + await screen.press("escape"); |
| 86 | + await waitForText(screen.lastFrame, "choose a Memory to list actors for"); |
| 87 | + }); |
| 88 | + |
| 89 | + test("shows empty and retry states for actor lists", async () => { |
| 90 | + const empty = renderScreen("/agentcore/memory/actor/list/memory-1"); |
| 91 | + await waitForText(empty.lastFrame, "No actors found for Memory memory-1."); |
| 92 | + empty.unmount(); |
| 93 | + |
| 94 | + const core = new TestCoreClient(); |
| 95 | + core.memory.setError(new Error("actors unavailable")); |
| 96 | + const failed = renderScreen("/agentcore/memory/actor/list/memory-1", { core }); |
| 97 | + |
| 98 | + await waitForText(failed.lastFrame, "actors unavailable"); |
| 99 | + core.memory.setError(undefined); |
| 100 | + core.memory.setListActorsResponse({ actorSummaries: [actor()] }); |
| 101 | + await failed.write("r"); |
| 102 | + await waitFor(() => failed.lastFrame()?.includes("actor-1") ?? false); |
| 103 | + }); |
| 104 | +}); |
0 commit comments