@escapeaihq/client-core 0.8.0 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -4
- package/dist/adapters/capabilities.d.ts +10 -0
- package/dist/adapters/capabilities.d.ts.map +1 -0
- package/dist/adapters/capabilities.js +2 -0
- package/dist/adapters/capabilities.js.map +1 -0
- package/dist/adapters/chatAdapter.d.ts +38 -0
- package/dist/adapters/chatAdapter.d.ts.map +1 -0
- package/dist/adapters/chatAdapter.js +88 -0
- package/dist/adapters/chatAdapter.js.map +1 -0
- package/dist/adapters/directorAdapter.d.ts +62 -0
- package/dist/adapters/directorAdapter.d.ts.map +1 -0
- package/dist/adapters/directorAdapter.js +71 -0
- package/dist/adapters/directorAdapter.js.map +1 -0
- package/dist/adapters/imageAdapter.d.ts +44 -0
- package/dist/adapters/imageAdapter.d.ts.map +1 -0
- package/dist/adapters/imageAdapter.js +73 -0
- package/dist/adapters/imageAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +47 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +41 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/registry.d.ts +98 -0
- package/dist/adapters/registry.d.ts.map +1 -0
- package/dist/adapters/registry.js +106 -0
- package/dist/adapters/registry.js.map +1 -0
- package/dist/adapters/worldAdapter.d.ts +142 -0
- package/dist/adapters/worldAdapter.d.ts.map +1 -0
- package/dist/adapters/worldAdapter.js +164 -0
- package/dist/adapters/worldAdapter.js.map +1 -0
- package/dist/admin.d.ts +200 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +124 -0
- package/dist/admin.js.map +1 -0
- package/dist/api.d.ts +1299 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +683 -95
- package/dist/api.js.map +1 -1
- package/dist/audio.d.ts +33 -1
- package/dist/audio.d.ts.map +1 -1
- package/dist/audio.js +4 -1
- package/dist/audio.js.map +1 -1
- package/dist/castProjection.d.ts +35 -0
- package/dist/castProjection.d.ts.map +1 -0
- package/dist/castProjection.js +80 -0
- package/dist/castProjection.js.map +1 -0
- package/dist/conversation/binding.d.ts +62 -0
- package/dist/conversation/binding.d.ts.map +1 -0
- package/dist/conversation/binding.js +51 -0
- package/dist/conversation/binding.js.map +1 -0
- package/dist/conversation/controller.d.ts +209 -0
- package/dist/conversation/controller.d.ts.map +1 -0
- package/dist/conversation/controller.js +342 -0
- package/dist/conversation/controller.js.map +1 -0
- package/dist/conversation/effectiveModel.d.ts +62 -0
- package/dist/conversation/effectiveModel.d.ts.map +1 -0
- package/dist/conversation/effectiveModel.js +73 -0
- package/dist/conversation/effectiveModel.js.map +1 -0
- package/dist/conversation/index.d.ts +27 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +27 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/participant.d.ts +66 -0
- package/dist/conversation/participant.d.ts.map +1 -0
- package/dist/conversation/participant.js +36 -0
- package/dist/conversation/participant.js.map +1 -0
- package/dist/conversation/presence.d.ts +56 -0
- package/dist/conversation/presence.d.ts.map +1 -0
- package/dist/conversation/presence.js +34 -0
- package/dist/conversation/presence.js.map +1 -0
- package/dist/conversation/presenceBus.d.ts +42 -0
- package/dist/conversation/presenceBus.d.ts.map +1 -0
- package/dist/conversation/presenceBus.js +81 -0
- package/dist/conversation/presenceBus.js.map +1 -0
- package/dist/conversation/presenceRegistry.d.ts +49 -0
- package/dist/conversation/presenceRegistry.d.ts.map +1 -0
- package/dist/conversation/presenceRegistry.js +59 -0
- package/dist/conversation/presenceRegistry.js.map +1 -0
- package/dist/conversation/roster.d.ts +72 -0
- package/dist/conversation/roster.d.ts.map +1 -0
- package/dist/conversation/roster.js +69 -0
- package/dist/conversation/roster.js.map +1 -0
- package/dist/conversation/rosterProjection.d.ts +52 -0
- package/dist/conversation/rosterProjection.d.ts.map +1 -0
- package/dist/conversation/rosterProjection.js +74 -0
- package/dist/conversation/rosterProjection.js.map +1 -0
- package/dist/conversation/router.d.ts +74 -0
- package/dist/conversation/router.d.ts.map +1 -0
- package/dist/conversation/router.js +58 -0
- package/dist/conversation/router.js.map +1 -0
- package/dist/conversation/runtime.d.ts +64 -0
- package/dist/conversation/runtime.d.ts.map +1 -0
- package/dist/conversation/runtime.js +172 -0
- package/dist/conversation/runtime.js.map +1 -0
- package/dist/conversation/types.d.ts +99 -0
- package/dist/conversation/types.d.ts.map +1 -0
- package/dist/conversation/types.js +13 -0
- package/dist/conversation/types.js.map +1 -0
- package/dist/conversation/voice.d.ts +185 -0
- package/dist/conversation/voice.d.ts.map +1 -0
- package/dist/conversation/voice.js +307 -0
- package/dist/conversation/voice.js.map +1 -0
- package/dist/graphSchema.d.ts +260 -0
- package/dist/graphSchema.d.ts.map +1 -0
- package/dist/graphSchema.js +354 -0
- package/dist/graphSchema.js.map +1 -0
- package/dist/http.d.ts +20 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +57 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -1
- package/dist/platformAssistant.d.ts +155 -0
- package/dist/platformAssistant.d.ts.map +1 -0
- package/dist/platformAssistant.js +256 -0
- package/dist/platformAssistant.js.map +1 -0
- package/dist/reactor/abortUtils.d.ts +16 -0
- package/dist/reactor/abortUtils.d.ts.map +1 -0
- package/dist/reactor/abortUtils.js +26 -0
- package/dist/reactor/abortUtils.js.map +1 -0
- package/dist/reactor/applyScenePrompt.d.ts +75 -0
- package/dist/reactor/applyScenePrompt.d.ts.map +1 -0
- package/dist/reactor/applyScenePrompt.js +60 -0
- package/dist/reactor/applyScenePrompt.js.map +1 -0
- package/dist/reactor/chunkDistribution.d.ts +43 -0
- package/dist/reactor/chunkDistribution.d.ts.map +1 -0
- package/dist/reactor/chunkDistribution.js +85 -0
- package/dist/reactor/chunkDistribution.js.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
- package/dist/reactor/heliosCommandDispatcher.js +10 -15
- package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
- package/dist/reactor/index.d.ts +4 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +7 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
- package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
- package/dist/reactor/longLiveCommandDispatcher.js +87 -0
- package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
- package/dist/reactor/sceneEntry.d.ts +40 -6
- package/dist/reactor/sceneEntry.d.ts.map +1 -1
- package/dist/reactor/sceneEntry.js +63 -24
- package/dist/reactor/sceneEntry.js.map +1 -1
- package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
- package/dist/reactor/scenesFromEnrichment.js +2 -66
- package/dist/reactor/scenesFromEnrichment.js.map +1 -1
- package/dist/reactor/seedImageOrchestrator.d.ts +42 -2
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +173 -4
- package/dist/reactor/seedImageOrchestrator.js.map +1 -1
- package/dist/reactor/storyTimeline.d.ts +44 -0
- package/dist/reactor/storyTimeline.d.ts.map +1 -0
- package/dist/reactor/storyTimeline.js +95 -0
- package/dist/reactor/storyTimeline.js.map +1 -0
- package/dist/storyGraph.d.ts +70 -0
- package/dist/storyGraph.d.ts.map +1 -0
- package/dist/storyGraph.js +178 -0
- package/dist/storyGraph.js.map +1 -0
- package/dist/timeFormat.d.ts +10 -0
- package/dist/timeFormat.d.ts.map +1 -1
- package/dist/timeFormat.js +12 -0
- package/dist/timeFormat.js.map +1 -1
- package/dist/toolSchemas.d.ts +370 -0
- package/dist/toolSchemas.d.ts.map +1 -0
- package/dist/toolSchemas.js +182 -0
- package/dist/toolSchemas.js.map +1 -0
- package/dist/vision/VisionPublisher.d.ts +115 -0
- package/dist/vision/VisionPublisher.d.ts.map +1 -0
- package/dist/vision/VisionPublisher.js +475 -0
- package/dist/vision/VisionPublisher.js.map +1 -0
- package/dist/vision/VisionSourceController.d.ts +127 -0
- package/dist/vision/VisionSourceController.d.ts.map +1 -0
- package/dist/vision/VisionSourceController.js +284 -0
- package/dist/vision/VisionSourceController.js.map +1 -0
- package/dist/vision/credentials.d.ts +22 -0
- package/dist/vision/credentials.d.ts.map +1 -0
- package/dist/vision/credentials.js +34 -0
- package/dist/vision/credentials.js.map +1 -0
- package/dist/vision/index.d.ts +18 -0
- package/dist/vision/index.d.ts.map +1 -0
- package/dist/vision/index.js +13 -0
- package/dist/vision/index.js.map +1 -0
- package/dist/vision/sourceKinds.d.ts +65 -0
- package/dist/vision/sourceKinds.d.ts.map +1 -0
- package/dist/vision/sourceKinds.js +26 -0
- package/dist/vision/sourceKinds.js.map +1 -0
- package/dist/vision/startVisionPublisher.d.ts +38 -0
- package/dist/vision/startVisionPublisher.d.ts.map +1 -0
- package/dist/vision/startVisionPublisher.js +44 -0
- package/dist/vision/startVisionPublisher.js.map +1 -0
- package/dist/vision/types.d.ts +95 -0
- package/dist/vision/types.d.ts.map +1 -0
- package/dist/vision/types.js +12 -0
- package/dist/vision/types.js.map +1 -0
- package/dist/vision/visionScheduler.d.ts +63 -0
- package/dist/vision/visionScheduler.d.ts.map +1 -0
- package/dist/vision/visionScheduler.js +67 -0
- package/dist/vision/visionScheduler.js.map +1 -0
- package/dist/websocket.d.ts +195 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +179 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +11 -1
- package/src/__tests__/adapters-capabilities.test.ts +46 -0
- package/src/__tests__/adapters-chat.test.ts +172 -0
- package/src/__tests__/adapters-director.test.ts +95 -0
- package/src/__tests__/adapters-image.test.ts +133 -0
- package/src/__tests__/adapters-platform.test.ts +95 -0
- package/src/__tests__/adapters-registry.test.ts +189 -0
- package/src/__tests__/adapters-world.test.ts +296 -0
- package/src/__tests__/admin.test.ts +312 -0
- package/src/__tests__/adventures-party.test.ts +219 -0
- package/src/__tests__/adventures.test.ts +282 -0
- package/src/__tests__/api-pollers.test.ts +104 -0
- package/src/__tests__/api.clip-lookup.test.ts +64 -0
- package/src/__tests__/api.list-images-filters.test.ts +103 -0
- package/src/__tests__/api.test.ts +470 -0
- package/src/__tests__/audio.test.ts +65 -0
- package/src/__tests__/cast.test.ts +95 -0
- package/src/__tests__/castProjection.test.ts +167 -0
- package/src/__tests__/chat-auth.test.ts +91 -0
- package/src/__tests__/conversation/controller.test.ts +697 -0
- package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
- package/src/__tests__/conversation/headlessRenderer.ts +46 -0
- package/src/__tests__/conversation/presenceBus.test.ts +236 -0
- package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
- package/src/__tests__/conversation/roster.test.ts +100 -0
- package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
- package/src/__tests__/conversation/router.test.ts +81 -0
- package/src/__tests__/conversation/runtime.test.ts +206 -0
- package/src/__tests__/conversation/voice.test.ts +440 -0
- package/src/__tests__/documents.test.ts +360 -0
- package/src/__tests__/graphSchema.test.ts +326 -0
- package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
- package/src/__tests__/platformAssistant.test.ts +484 -0
- package/src/__tests__/reactor/applyScenePrompt.test.ts +192 -0
- package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +4 -3
- package/src/__tests__/reactor/sceneEntry.test.ts +134 -10
- package/src/__tests__/reactor/seedImageOrchestrator.test.ts +51 -16
- package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
- package/src/__tests__/regeneration.test.ts +486 -0
- package/src/__tests__/stories.test.ts +171 -0
- package/src/__tests__/storyGraph.test.ts +134 -0
- package/src/__tests__/timeFormat.test.ts +22 -1
- package/src/__tests__/toolSchemas.test.ts +57 -0
- package/src/__tests__/tools-wrappers.test.ts +272 -0
- package/src/__tests__/videoGraph.test.ts +94 -0
- package/src/__tests__/websocket-vision.test.ts +265 -0
- package/src/__tests__/websocket.test.ts +213 -0
- package/src/adapters/capabilities.ts +24 -0
- package/src/adapters/chatAdapter.ts +114 -0
- package/src/adapters/directorAdapter.ts +126 -0
- package/src/adapters/imageAdapter.ts +100 -0
- package/src/adapters/index.ts +67 -0
- package/src/adapters/registry.ts +159 -0
- package/src/adapters/worldAdapter.ts +272 -0
- package/src/admin.ts +310 -0
- package/src/api.ts +1890 -162
- package/src/audio.ts +35 -0
- package/src/castProjection.ts +95 -0
- package/src/conversation/binding.ts +81 -0
- package/src/conversation/controller.ts +439 -0
- package/src/conversation/effectiveModel.ts +111 -0
- package/src/conversation/index.ts +27 -0
- package/src/conversation/participant.ts +71 -0
- package/src/conversation/presence.ts +60 -0
- package/src/conversation/presenceBus.ts +109 -0
- package/src/conversation/presenceRegistry.ts +83 -0
- package/src/conversation/roster.ts +111 -0
- package/src/conversation/rosterProjection.ts +98 -0
- package/src/conversation/router.ts +96 -0
- package/src/conversation/runtime.ts +188 -0
- package/src/conversation/types.ts +100 -0
- package/src/conversation/voice.ts +402 -0
- package/src/graphSchema.ts +532 -0
- package/src/http.ts +72 -0
- package/src/index.ts +12 -0
- package/src/platformAssistant.ts +347 -0
- package/src/reactor/abortUtils.ts +22 -0
- package/src/reactor/applyScenePrompt.ts +136 -0
- package/src/reactor/chunkDistribution.ts +98 -0
- package/src/reactor/heliosCommandDispatcher.ts +10 -18
- package/src/reactor/index.ts +7 -0
- package/src/reactor/longLiveCommandDispatcher.ts +156 -0
- package/src/reactor/sceneEntry.ts +104 -33
- package/src/reactor/scenesFromEnrichment.ts +11 -76
- package/src/reactor/seedImageOrchestrator.ts +200 -4
- package/src/reactor/storyTimeline.ts +127 -0
- package/src/storyGraph.ts +298 -0
- package/src/timeFormat.ts +13 -0
- package/src/toolSchemas.ts +225 -0
- package/src/vision/VisionPublisher.ts +553 -0
- package/src/vision/VisionSourceController.ts +354 -0
- package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
- package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
- package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
- package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
- package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
- package/src/vision/__tests__/visionScheduler.test.ts +149 -0
- package/src/vision/credentials.ts +39 -0
- package/src/vision/index.ts +44 -0
- package/src/vision/sourceKinds.ts +75 -0
- package/src/vision/startVisionPublisher.ts +64 -0
- package/src/vision/types.ts +101 -0
- package/src/vision/visionScheduler.ts +102 -0
- package/src/websocket.ts +334 -4
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the M10 Story Engine Phase 9a (multi-persona scene orchestrator)
|
|
3
|
+
* party-mutation API client methods on `ApiClient`: `addPartyMember` /
|
|
4
|
+
* `removePartyMember`, plus `startAdventure` forwarding `partyPersonaIds`.
|
|
5
|
+
*
|
|
6
|
+
* Contract (PLAN_9A_CONTRACT §2f/§2h): the party PATCH hits
|
|
7
|
+
* `PATCH /api/v1/adventures/{sessionId}/party` with
|
|
8
|
+
* `{ action: 'add' | 'remove', personaId }` and returns the updated
|
|
9
|
+
* `GetAdventureResponse` (the same 200 shape as `GET adventure`). camelCase
|
|
10
|
+
* keys verbatim; the session id segment is percent-encoded like the other
|
|
11
|
+
* adventure methods.
|
|
12
|
+
*/
|
|
13
|
+
import { ApiClient, PARTY_ACTION } from '../api';
|
|
14
|
+
import type {
|
|
15
|
+
AdventureState,
|
|
16
|
+
GetAdventureResponse,
|
|
17
|
+
PartyUpdateRequest,
|
|
18
|
+
StartAdventureRequest,
|
|
19
|
+
} from '../api';
|
|
20
|
+
|
|
21
|
+
describe('ApiClient party methods (M10 Phase 9a)', () => {
|
|
22
|
+
let client: ApiClient;
|
|
23
|
+
let fetchMock: jest.Mock;
|
|
24
|
+
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
client = new ApiClient(
|
|
27
|
+
'https://api.example.com',
|
|
28
|
+
'test-token',
|
|
29
|
+
'https://api.example.com/chat',
|
|
30
|
+
);
|
|
31
|
+
fetchMock = jest.fn();
|
|
32
|
+
global.fetch = fetchMock as unknown as typeof fetch;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
jest.restoreAllMocks();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
function mockJsonResponse(body: unknown, status = 200): Response {
|
|
40
|
+
return {
|
|
41
|
+
ok: status >= 200 && status < 300,
|
|
42
|
+
status,
|
|
43
|
+
statusText: 'OK',
|
|
44
|
+
headers: {
|
|
45
|
+
get: (name: string) =>
|
|
46
|
+
name.toLowerCase() === 'content-type' ? 'application/json' : null,
|
|
47
|
+
},
|
|
48
|
+
json: async () => body,
|
|
49
|
+
} as unknown as Response;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const sampleState: AdventureState = {
|
|
53
|
+
sessionId: 'adv-1',
|
|
54
|
+
ownerUserId: 'user-1',
|
|
55
|
+
storyId: 'those-who-remain',
|
|
56
|
+
videoId: 'those-who-remain',
|
|
57
|
+
dmPersonaId: 'dm-1',
|
|
58
|
+
partyPersonaIds: [],
|
|
59
|
+
currentBeatId: null,
|
|
60
|
+
visitedBeatIds: [],
|
|
61
|
+
flags: {},
|
|
62
|
+
inventory: [],
|
|
63
|
+
turnHistory: [],
|
|
64
|
+
createdAt: '2026-06-03T12:00:00+00:00',
|
|
65
|
+
updatedAt: '2026-06-03T12:00:00+00:00',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
it('PARTY_ACTION exposes the add/remove wire literals', () => {
|
|
69
|
+
expect(PARTY_ACTION.ADD).toBe('add');
|
|
70
|
+
expect(PARTY_ACTION.REMOVE).toBe('remove');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('addPartyMember PATCHes party with action=add and returns the updated state', async () => {
|
|
74
|
+
const body: GetAdventureResponse = {
|
|
75
|
+
traceId: 'trace-add',
|
|
76
|
+
state: { ...sampleState, partyPersonaIds: ['aragorn'] },
|
|
77
|
+
};
|
|
78
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
79
|
+
|
|
80
|
+
const result = await client.addPartyMember('adv-1', 'aragorn');
|
|
81
|
+
|
|
82
|
+
expect(result.traceId).toBe('trace-add');
|
|
83
|
+
expect(result.state.partyPersonaIds).toEqual(['aragorn']);
|
|
84
|
+
|
|
85
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
86
|
+
const [calledUrl, calledInit] = fetchMock.mock.calls[0] as [
|
|
87
|
+
string,
|
|
88
|
+
RequestInit,
|
|
89
|
+
];
|
|
90
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/adv-1/party');
|
|
91
|
+
expect(calledInit.method).toBe('PATCH');
|
|
92
|
+
const sentBody = JSON.parse(calledInit.body as string) as PartyUpdateRequest;
|
|
93
|
+
expect(sentBody).toEqual({ action: 'add', personaId: 'aragorn' });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('removePartyMember PATCHes party with action=remove and returns the updated state', async () => {
|
|
97
|
+
const body: GetAdventureResponse = {
|
|
98
|
+
traceId: 'trace-remove',
|
|
99
|
+
state: { ...sampleState, partyPersonaIds: [] },
|
|
100
|
+
};
|
|
101
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
102
|
+
|
|
103
|
+
const result = await client.removePartyMember('adv-1', 'aragorn');
|
|
104
|
+
|
|
105
|
+
expect(result.traceId).toBe('trace-remove');
|
|
106
|
+
expect(result.state.partyPersonaIds).toEqual([]);
|
|
107
|
+
|
|
108
|
+
const [calledUrl, calledInit] = fetchMock.mock.calls[0] as [
|
|
109
|
+
string,
|
|
110
|
+
RequestInit,
|
|
111
|
+
];
|
|
112
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/adv-1/party');
|
|
113
|
+
expect(calledInit.method).toBe('PATCH');
|
|
114
|
+
const sentBody = JSON.parse(calledInit.body as string) as PartyUpdateRequest;
|
|
115
|
+
expect(sentBody).toEqual({ action: 'remove', personaId: 'aragorn' });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('percent-encodes the session id segment in the party path', async () => {
|
|
119
|
+
fetchMock.mockResolvedValueOnce(
|
|
120
|
+
mockJsonResponse({ traceId: 't', state: sampleState }),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
await client.addPartyMember('a b/c', 'p-1');
|
|
124
|
+
|
|
125
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
126
|
+
expect(calledUrl).toBe(
|
|
127
|
+
'https://api.example.com/api/v1/adventures/a%20b%2Fc/party',
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('addPartyMember surfaces a 422 (persona is a DM) as a thrown error', async () => {
|
|
132
|
+
fetchMock.mockResolvedValueOnce(
|
|
133
|
+
mockJsonResponse({ detail: 'Persona is a Dungeon Master' }, 422),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
await expect(
|
|
137
|
+
client.addPartyMember('adv-1', 'dm-1'),
|
|
138
|
+
).rejects.toThrow('Persona is a Dungeon Master');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('addPartyMember surfaces a 404 (adventure not found) as a thrown error', async () => {
|
|
142
|
+
fetchMock.mockResolvedValueOnce(
|
|
143
|
+
mockJsonResponse({ detail: 'Adventure not found' }, 404),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
await expect(
|
|
147
|
+
client.addPartyMember('missing', 'p-1'),
|
|
148
|
+
).rejects.toThrow('Adventure not found');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('removePartyMember is idempotent on the client (200 no-op returns current state)', async () => {
|
|
152
|
+
const body: GetAdventureResponse = {
|
|
153
|
+
traceId: 'trace-noop',
|
|
154
|
+
state: { ...sampleState, partyPersonaIds: ['legolas'] },
|
|
155
|
+
};
|
|
156
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
157
|
+
|
|
158
|
+
const result = await client.removePartyMember('adv-1', 'absent-member');
|
|
159
|
+
|
|
160
|
+
expect(result.state.partyPersonaIds).toEqual(['legolas']);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('threads an AbortSignal into the underlying fetch for the party methods', async () => {
|
|
164
|
+
const controller = new AbortController();
|
|
165
|
+
fetchMock.mockResolvedValue(
|
|
166
|
+
mockJsonResponse({ traceId: 't', state: sampleState }),
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
await client.addPartyMember('adv-1', 'p-1', { signal: controller.signal });
|
|
170
|
+
|
|
171
|
+
const calledInit = fetchMock.mock.calls[0][1] as RequestInit;
|
|
172
|
+
expect(calledInit.signal).toBe(controller.signal);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('startAdventure forwards partyPersonaIds when provided (M10 9a)', async () => {
|
|
176
|
+
const request: StartAdventureRequest = {
|
|
177
|
+
storyId: 's1',
|
|
178
|
+
videoId: 's1',
|
|
179
|
+
dmPersonaId: 'dm-1',
|
|
180
|
+
partyPersonaIds: ['aragorn', 'legolas'],
|
|
181
|
+
};
|
|
182
|
+
fetchMock.mockResolvedValueOnce(
|
|
183
|
+
mockJsonResponse(
|
|
184
|
+
{
|
|
185
|
+
traceId: 't',
|
|
186
|
+
sessionId: 'adv-2',
|
|
187
|
+
state: { ...sampleState, partyPersonaIds: ['aragorn', 'legolas'] },
|
|
188
|
+
},
|
|
189
|
+
201,
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
await client.startAdventure(request);
|
|
194
|
+
|
|
195
|
+
const calledInit = fetchMock.mock.calls[0][1] as RequestInit;
|
|
196
|
+
expect(JSON.parse(calledInit.body as string)).toEqual(request);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('startAdventure omits partyPersonaIds when not provided (land-dark)', async () => {
|
|
200
|
+
const request: StartAdventureRequest = {
|
|
201
|
+
storyId: 's1',
|
|
202
|
+
videoId: 's1',
|
|
203
|
+
dmPersonaId: 'dm-1',
|
|
204
|
+
};
|
|
205
|
+
fetchMock.mockResolvedValueOnce(
|
|
206
|
+
mockJsonResponse(
|
|
207
|
+
{ traceId: 't', sessionId: 'adv-3', state: sampleState },
|
|
208
|
+
201,
|
|
209
|
+
),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
await client.startAdventure(request);
|
|
213
|
+
|
|
214
|
+
const sentBody = JSON.parse(
|
|
215
|
+
fetchMock.mock.calls[0][1].body as string,
|
|
216
|
+
) as Record<string, unknown>;
|
|
217
|
+
expect(sentBody).not.toHaveProperty('partyPersonaIds');
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the M9 Story Engine Phase 8a (Adventure Runtime) API client
|
|
3
|
+
* methods on `ApiClient`.
|
|
4
|
+
*
|
|
5
|
+
* Contract: the backend emits camelCase JSON keys verbatim (no remapping in
|
|
6
|
+
* client-core), so the parsed objects match the AdventureState / AdventureResponse
|
|
7
|
+
* interfaces field-for-field. `startAdventure` POSTs the request body and yields
|
|
8
|
+
* a 201 envelope; `getAdventure` GETs the current state; `deleteAdventure` is a
|
|
9
|
+
* 204 that resolves to `undefined`.
|
|
10
|
+
*/
|
|
11
|
+
import { ApiClient } from '../api';
|
|
12
|
+
import type {
|
|
13
|
+
AdventureResponse,
|
|
14
|
+
AdventureState,
|
|
15
|
+
GetAdventureResponse,
|
|
16
|
+
ListAdventuresResponse,
|
|
17
|
+
StartAdventureRequest,
|
|
18
|
+
} from '../api';
|
|
19
|
+
|
|
20
|
+
describe('ApiClient adventure methods (M9 Phase 8a)', () => {
|
|
21
|
+
let client: ApiClient;
|
|
22
|
+
let fetchMock: jest.Mock;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
client = new ApiClient(
|
|
26
|
+
'https://api.example.com',
|
|
27
|
+
'test-token',
|
|
28
|
+
'https://api.example.com/chat',
|
|
29
|
+
);
|
|
30
|
+
fetchMock = jest.fn();
|
|
31
|
+
global.fetch = fetchMock as unknown as typeof fetch;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
jest.restoreAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function mockJsonResponse(body: unknown, status = 200): Response {
|
|
39
|
+
return {
|
|
40
|
+
ok: status >= 200 && status < 300,
|
|
41
|
+
status,
|
|
42
|
+
statusText: 'OK',
|
|
43
|
+
headers: {
|
|
44
|
+
get: (name: string) =>
|
|
45
|
+
name.toLowerCase() === 'content-type' ? 'application/json' : null,
|
|
46
|
+
},
|
|
47
|
+
json: async () => body,
|
|
48
|
+
} as unknown as Response;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function mockNoContentResponse(): Response {
|
|
52
|
+
return {
|
|
53
|
+
ok: true,
|
|
54
|
+
status: 204,
|
|
55
|
+
statusText: 'No Content',
|
|
56
|
+
headers: { get: () => null },
|
|
57
|
+
json: async () => {
|
|
58
|
+
throw new Error('204 has no body');
|
|
59
|
+
},
|
|
60
|
+
} as unknown as Response;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const sampleState: AdventureState = {
|
|
64
|
+
sessionId: 'adv-1',
|
|
65
|
+
ownerUserId: 'user-1',
|
|
66
|
+
storyId: 'those-who-remain',
|
|
67
|
+
videoId: 'those-who-remain',
|
|
68
|
+
dmPersonaId: 'dm-1',
|
|
69
|
+
partyPersonaIds: [],
|
|
70
|
+
currentBeatId: null,
|
|
71
|
+
visitedBeatIds: [],
|
|
72
|
+
flags: {},
|
|
73
|
+
inventory: [],
|
|
74
|
+
turnHistory: [],
|
|
75
|
+
createdAt: '2026-06-03T12:00:00+00:00',
|
|
76
|
+
updatedAt: '2026-06-03T12:00:00+00:00',
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
it('startAdventure POSTs the request body to /api/v1/adventures and returns the 201 envelope', async () => {
|
|
80
|
+
const request: StartAdventureRequest = {
|
|
81
|
+
storyId: 'those-who-remain',
|
|
82
|
+
videoId: 'those-who-remain',
|
|
83
|
+
dmPersonaId: 'dm-1',
|
|
84
|
+
};
|
|
85
|
+
const body: AdventureResponse = {
|
|
86
|
+
traceId: 'trace-start',
|
|
87
|
+
sessionId: 'adv-1',
|
|
88
|
+
state: sampleState,
|
|
89
|
+
};
|
|
90
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body, 201));
|
|
91
|
+
|
|
92
|
+
const result = await client.startAdventure(request);
|
|
93
|
+
|
|
94
|
+
expect(result.traceId).toBe('trace-start');
|
|
95
|
+
expect(result.sessionId).toBe('adv-1');
|
|
96
|
+
expect(result.state.dmPersonaId).toBe('dm-1');
|
|
97
|
+
expect(result.state.currentBeatId).toBeNull();
|
|
98
|
+
|
|
99
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
100
|
+
const [calledUrl, calledInit] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
101
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/adventures');
|
|
102
|
+
expect(calledInit.method).toBe('POST');
|
|
103
|
+
expect(JSON.parse(calledInit.body as string)).toEqual(request);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('startAdventure forwards initialBeatId when provided', async () => {
|
|
107
|
+
const request: StartAdventureRequest = {
|
|
108
|
+
storyId: 's1',
|
|
109
|
+
videoId: 's1',
|
|
110
|
+
dmPersonaId: 'dm-1',
|
|
111
|
+
initialBeatId: 'beat-0',
|
|
112
|
+
};
|
|
113
|
+
fetchMock.mockResolvedValueOnce(
|
|
114
|
+
mockJsonResponse(
|
|
115
|
+
{ traceId: 't', sessionId: 'adv-2', state: sampleState },
|
|
116
|
+
201,
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
await client.startAdventure(request);
|
|
121
|
+
|
|
122
|
+
const calledInit = fetchMock.mock.calls[0][1] as RequestInit;
|
|
123
|
+
expect(JSON.parse(calledInit.body as string)).toEqual(request);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('startAdventure surfaces a 422 (persona is not a DM) as a thrown error', async () => {
|
|
127
|
+
fetchMock.mockResolvedValueOnce(
|
|
128
|
+
mockJsonResponse({ detail: 'Persona is not a Dungeon Master' }, 422),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
await expect(
|
|
132
|
+
client.startAdventure({ storyId: 's', videoId: 's', dmPersonaId: 'p' }),
|
|
133
|
+
).rejects.toThrow('Persona is not a Dungeon Master');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('getAdventure GETs /api/v1/adventures/{sessionId} and returns the parsed state', async () => {
|
|
137
|
+
const body: GetAdventureResponse = {
|
|
138
|
+
traceId: 'trace-get',
|
|
139
|
+
state: {
|
|
140
|
+
...sampleState,
|
|
141
|
+
currentBeatId: 'beat-3',
|
|
142
|
+
visitedBeatIds: ['beat-0', 'beat-3'],
|
|
143
|
+
flags: { door: 'open' },
|
|
144
|
+
inventory: ['torch'],
|
|
145
|
+
turnHistory: [{ turn: 1, beatId: 'beat-3', summary: 'opened the door' }],
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
149
|
+
|
|
150
|
+
const result = await client.getAdventure('adv-1');
|
|
151
|
+
|
|
152
|
+
expect(result.traceId).toBe('trace-get');
|
|
153
|
+
expect(result.state.currentBeatId).toBe('beat-3');
|
|
154
|
+
expect(result.state.visitedBeatIds).toEqual(['beat-0', 'beat-3']);
|
|
155
|
+
expect(result.state.flags).toEqual({ door: 'open' });
|
|
156
|
+
expect(result.state.inventory).toEqual(['torch']);
|
|
157
|
+
expect(result.state.turnHistory[0]).toEqual({
|
|
158
|
+
turn: 1,
|
|
159
|
+
beatId: 'beat-3',
|
|
160
|
+
summary: 'opened the door',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
164
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
165
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/adv-1');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('getAdventure percent-encodes the session id segment', async () => {
|
|
169
|
+
fetchMock.mockResolvedValueOnce(
|
|
170
|
+
mockJsonResponse({ traceId: 't', state: sampleState }),
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
await client.getAdventure('a b/c');
|
|
174
|
+
|
|
175
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
176
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/a%20b%2Fc');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('getAdventure surfaces a 404 as a thrown error', async () => {
|
|
180
|
+
fetchMock.mockResolvedValueOnce(
|
|
181
|
+
mockJsonResponse({ detail: 'Adventure not found' }, 404),
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
await expect(client.getAdventure('missing')).rejects.toThrow(
|
|
185
|
+
'Adventure not found',
|
|
186
|
+
);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('deleteAdventure DELETEs the session and resolves (204 → undefined)', async () => {
|
|
190
|
+
fetchMock.mockResolvedValueOnce(mockNoContentResponse());
|
|
191
|
+
|
|
192
|
+
const result = await client.deleteAdventure('adv-1');
|
|
193
|
+
|
|
194
|
+
expect(result).toBeUndefined();
|
|
195
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
196
|
+
const [calledUrl, calledInit] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
197
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/adventures/adv-1');
|
|
198
|
+
expect(calledInit.method).toBe('DELETE');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('deleteAdventure surfaces a 404 as a thrown error', async () => {
|
|
202
|
+
fetchMock.mockResolvedValueOnce(
|
|
203
|
+
mockJsonResponse({ detail: 'Adventure not found' }, 404),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
await expect(client.deleteAdventure('missing')).rejects.toThrow(
|
|
207
|
+
'Adventure not found',
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('listAdventures GETs /api/v1/adventures with no query and returns the parsed adventures', async () => {
|
|
212
|
+
const body: ListAdventuresResponse = {
|
|
213
|
+
traceId: 'trace-list',
|
|
214
|
+
adventures: [
|
|
215
|
+
sampleState,
|
|
216
|
+
{ ...sampleState, sessionId: 'adv-2', currentBeatId: 'beat-3' },
|
|
217
|
+
],
|
|
218
|
+
};
|
|
219
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
220
|
+
|
|
221
|
+
const result = await client.listAdventures();
|
|
222
|
+
|
|
223
|
+
expect(result.traceId).toBe('trace-list');
|
|
224
|
+
expect(result.adventures).toHaveLength(2);
|
|
225
|
+
expect(result.adventures[0].sessionId).toBe('adv-1');
|
|
226
|
+
expect(result.adventures[1].sessionId).toBe('adv-2');
|
|
227
|
+
expect(result.adventures[1].currentBeatId).toBe('beat-3');
|
|
228
|
+
|
|
229
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
230
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
231
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/adventures');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('listAdventures forwards and encodes storyId when provided', async () => {
|
|
235
|
+
fetchMock.mockResolvedValueOnce(
|
|
236
|
+
mockJsonResponse({ traceId: 't', adventures: [] }),
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
await client.listAdventures('a b/c');
|
|
240
|
+
|
|
241
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
242
|
+
expect(calledUrl).toBe(
|
|
243
|
+
'https://api.example.com/api/v1/adventures?storyId=a+b%2Fc',
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('listAdventures surfaces an error response as a thrown error', async () => {
|
|
248
|
+
fetchMock.mockResolvedValueOnce(
|
|
249
|
+
mockJsonResponse({ detail: 'Unauthorized' }, 401),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
await expect(client.listAdventures()).rejects.toThrow('Unauthorized');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('listAdventures handles an empty adventures array', async () => {
|
|
256
|
+
fetchMock.mockResolvedValueOnce(
|
|
257
|
+
mockJsonResponse({ traceId: 'trace-empty', adventures: [] }),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const result = await client.listAdventures('those-who-remain');
|
|
261
|
+
|
|
262
|
+
expect(result.traceId).toBe('trace-empty');
|
|
263
|
+
expect(result.adventures).toEqual([]);
|
|
264
|
+
|
|
265
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
266
|
+
expect(calledUrl).toBe(
|
|
267
|
+
'https://api.example.com/api/v1/adventures?storyId=those-who-remain',
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('threads an AbortSignal into the underlying fetch for each method', async () => {
|
|
272
|
+
const controller = new AbortController();
|
|
273
|
+
fetchMock.mockResolvedValue(
|
|
274
|
+
mockJsonResponse({ traceId: 't', state: sampleState }),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
await client.getAdventure('adv-1', { signal: controller.signal });
|
|
278
|
+
|
|
279
|
+
const calledInit = fetchMock.mock.calls[0][1] as RequestInit;
|
|
280
|
+
expect(calledInit.signal).toBe(controller.signal);
|
|
281
|
+
});
|
|
282
|
+
});
|
|
@@ -158,6 +158,40 @@ describe('pollImageUntilDone', () => {
|
|
|
158
158
|
await client.pollImageUntilDone('img-1', { signal: controller.signal });
|
|
159
159
|
expect(spy).toHaveBeenCalledWith('img-1', { signal: controller.signal });
|
|
160
160
|
});
|
|
161
|
+
|
|
162
|
+
it('removes the abort listener from the signal when the sleep resolves normally (no leak)', async () => {
|
|
163
|
+
// Regression: abortableSleep previously used { once: true } which only
|
|
164
|
+
// removes the listener after it *fires* (i.e. only on abort). On the
|
|
165
|
+
// normal timer path the listener was never removed, leaking one listener
|
|
166
|
+
// per polling interval onto the same AbortSignal.
|
|
167
|
+
const client = makeClient();
|
|
168
|
+
const controller = new AbortController();
|
|
169
|
+
|
|
170
|
+
// Drive through one pending → complete cycle so abortableSleep is called
|
|
171
|
+
// once and resolves normally via the timer (not abort).
|
|
172
|
+
jest
|
|
173
|
+
.spyOn(client, 'getImage')
|
|
174
|
+
.mockResolvedValueOnce(buildImageRecord({ status: 'pending' }))
|
|
175
|
+
.mockResolvedValueOnce(buildImageRecord({ status: 'complete' }));
|
|
176
|
+
|
|
177
|
+
const removeListenerSpy = jest.spyOn(
|
|
178
|
+
controller.signal,
|
|
179
|
+
'removeEventListener',
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
const promise = client.pollImageUntilDone('img-1', {
|
|
183
|
+
signal: controller.signal,
|
|
184
|
+
intervalMs: 1000,
|
|
185
|
+
timeoutMs: 60_000,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Advance past the sleep so the timer fires normally (not via abort).
|
|
189
|
+
await jest.advanceTimersByTimeAsync(1100);
|
|
190
|
+
await expect(promise).resolves.toBeDefined();
|
|
191
|
+
|
|
192
|
+
// The abort listener must have been removed when the timer resolved.
|
|
193
|
+
expect(removeListenerSpy).toHaveBeenCalledWith('abort', expect.any(Function));
|
|
194
|
+
});
|
|
161
195
|
});
|
|
162
196
|
|
|
163
197
|
describe('pollVisemeBundleUntilDone', () => {
|
|
@@ -404,6 +438,7 @@ describe('extractImage / regenerateImage', () => {
|
|
|
404
438
|
|
|
405
439
|
const buildRegenerateResponse = () => ({
|
|
406
440
|
...buildExtractResponse(),
|
|
441
|
+
imageId: 'img-regen-1',
|
|
407
442
|
imageUrl: 'https://s3.example/regen.png?sig=def',
|
|
408
443
|
imageS3Key: 'regenerated/def.png',
|
|
409
444
|
prompt: 'cyberpunk style',
|
|
@@ -482,6 +517,9 @@ describe('extractImage / regenerateImage', () => {
|
|
|
482
517
|
model: 'gemini-2.5-flash-image',
|
|
483
518
|
});
|
|
484
519
|
expect(result.prompt).toBe('cyberpunk style');
|
|
520
|
+
// R8.4 / tech-debt #110: the response carries the new ImageRecord id so
|
|
521
|
+
// /interactive can auto-select the regenerated seed (was absent pre-R8.4).
|
|
522
|
+
expect(result.imageId).toBe('img-regen-1');
|
|
485
523
|
});
|
|
486
524
|
|
|
487
525
|
it('forwards an AbortSignal to fetch for both wrappers', async () => {
|
|
@@ -522,3 +560,69 @@ describe('extractImage / regenerateImage', () => {
|
|
|
522
560
|
).rejects.toThrow(/entity not found/);
|
|
523
561
|
});
|
|
524
562
|
});
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Regression: the old narrow isAbortError copy in api.ts only checked
|
|
566
|
+
* `DOMException { name: 'AbortError' }` and `Error { name: 'AbortError' }`.
|
|
567
|
+
* It missed `Error { code: 'ABORT_ERR' }`, so loadBundleManifest would
|
|
568
|
+
* console.warn on that shape instead of staying silent. After the fix,
|
|
569
|
+
* api.ts imports the canonical abortUtils version which accepts all three
|
|
570
|
+
* shapes — this test would FAIL against the old narrow copy and passes now.
|
|
571
|
+
*/
|
|
572
|
+
describe('loadBundleManifest — isAbortError regression (code ABORT_ERR)', () => {
|
|
573
|
+
const originalFetch = (globalThis as { fetch?: typeof fetch }).fetch;
|
|
574
|
+
|
|
575
|
+
beforeEach(() => {
|
|
576
|
+
jest.useRealTimers();
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
afterEach(() => {
|
|
580
|
+
if (originalFetch === undefined) {
|
|
581
|
+
delete (globalThis as { fetch?: typeof fetch }).fetch;
|
|
582
|
+
} else {
|
|
583
|
+
(globalThis as { fetch?: typeof fetch }).fetch = originalFetch;
|
|
584
|
+
}
|
|
585
|
+
jest.restoreAllMocks();
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it('does NOT console.warn when getVisemeBundle throws Error { code: ABORT_ERR }', async () => {
|
|
589
|
+
const client = makeClient();
|
|
590
|
+
// Simulates a library/polyfill that signals abort via `code` rather than
|
|
591
|
+
// `name`. The old narrow copy did NOT recognise this shape, so it would
|
|
592
|
+
// call console.warn — the canonical abortUtils version does.
|
|
593
|
+
const abortLikeError = Object.assign(new Error('boom'), { code: 'ABORT_ERR' });
|
|
594
|
+
jest.spyOn(client, 'getVisemeBundle').mockRejectedValue(abortLikeError);
|
|
595
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
596
|
+
|
|
597
|
+
const result = await client.loadBundleManifest({
|
|
598
|
+
persona_id: 'persona-1',
|
|
599
|
+
viseme_bundle_id: 'bundle-1',
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
// loadBundleManifest returns null on any catch — verify that.
|
|
603
|
+
expect(result).toBeNull();
|
|
604
|
+
// With the canonical isAbortError, this error is treated as an abort
|
|
605
|
+
// and console.warn must NOT be called.
|
|
606
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
it('DOES console.warn when getVisemeBundle throws a genuine non-abort error', async () => {
|
|
610
|
+
const client = makeClient();
|
|
611
|
+
const realError = new Error('Network failure: 503');
|
|
612
|
+
jest.spyOn(client, 'getVisemeBundle').mockRejectedValue(realError);
|
|
613
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
614
|
+
|
|
615
|
+
const result = await client.loadBundleManifest({
|
|
616
|
+
persona_id: 'persona-1',
|
|
617
|
+
viseme_bundle_id: 'bundle-1',
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
expect(result).toBeNull();
|
|
621
|
+
// A genuine error must still surface via console.warn.
|
|
622
|
+
expect(warnSpy).toHaveBeenCalledTimes(1);
|
|
623
|
+
expect(warnSpy).toHaveBeenCalledWith(
|
|
624
|
+
expect.stringContaining('loadBundleManifest'),
|
|
625
|
+
realError,
|
|
626
|
+
);
|
|
627
|
+
});
|
|
628
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* clip-lookup client binding tests (M7 P7 — studio Scene inspector). The backend
|
|
3
|
+
* `ClipLookupRequest`/`ClipLookupResponse` use camelCase wire keys (BaseSchema
|
|
4
|
+
* `# noqa: N815` literal fields), but the request body the client sends mirrors
|
|
5
|
+
* the backend request model field names. This suite asserts the method POSTs to
|
|
6
|
+
* the existing tools endpoint and returns the parsed response.
|
|
7
|
+
*
|
|
8
|
+
* Runner: jest (client-core uses jest, not vitest).
|
|
9
|
+
*/
|
|
10
|
+
import { ApiClient } from '../api';
|
|
11
|
+
|
|
12
|
+
describe('ApiClient clipLookup (M7 P7)', () => {
|
|
13
|
+
let client: ApiClient;
|
|
14
|
+
let fetchMock: jest.Mock;
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
client = new ApiClient(
|
|
18
|
+
'https://api.example.com',
|
|
19
|
+
'test-token',
|
|
20
|
+
'https://api.example.com/chat',
|
|
21
|
+
);
|
|
22
|
+
fetchMock = jest.fn();
|
|
23
|
+
global.fetch = fetchMock as unknown as typeof fetch;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
jest.restoreAllMocks();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
function mockJsonResponse(body: unknown, status = 200): Response {
|
|
31
|
+
return {
|
|
32
|
+
ok: status >= 200 && status < 300,
|
|
33
|
+
status,
|
|
34
|
+
headers: {
|
|
35
|
+
get: (name: string) =>
|
|
36
|
+
name.toLowerCase() === 'content-type' ? 'application/json' : null,
|
|
37
|
+
},
|
|
38
|
+
json: async () => body,
|
|
39
|
+
} as unknown as Response;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
it('POSTs /api/v1/tools/clip-lookup and returns the parsed clip url', async () => {
|
|
43
|
+
const body = {
|
|
44
|
+
traceId: 't1',
|
|
45
|
+
url: 'https://signed/clip.mp4',
|
|
46
|
+
expiresIn: 3600,
|
|
47
|
+
citation: { videoId: 'v1', t0: 0, t1: 30 },
|
|
48
|
+
source: { system: 'tools' },
|
|
49
|
+
};
|
|
50
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
51
|
+
|
|
52
|
+
const res = await client.clipLookup({ videoId: 'v1', t0: 0, t1: 30 });
|
|
53
|
+
|
|
54
|
+
expect(res.url).toBe('https://signed/clip.mp4');
|
|
55
|
+
expect(res.expiresIn).toBe(3600);
|
|
56
|
+
expect(res.traceId).toBe('t1');
|
|
57
|
+
|
|
58
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
59
|
+
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
60
|
+
expect(url).toBe('https://api.example.com/api/v1/tools/clip-lookup');
|
|
61
|
+
expect(init.method).toBe('POST');
|
|
62
|
+
expect(JSON.parse(init.body as string)).toEqual({ videoId: 'v1', t0: 0, t1: 30 });
|
|
63
|
+
});
|
|
64
|
+
});
|