@escapeaihq/client-core 0.12.0 → 0.49.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 +32 -7
- 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 +323 -0
- package/dist/admin.d.ts.map +1 -0
- package/dist/admin.js +198 -0
- package/dist/admin.js.map +1 -0
- package/dist/api.d.ts +1512 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +820 -52
- 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 +77 -0
- package/dist/conversation/binding.d.ts.map +1 -0
- package/dist/conversation/binding.js +57 -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 +350 -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 +201 -13
- package/dist/graphSchema.d.ts.map +1 -1
- package/dist/graphSchema.js +258 -9
- package/dist/graphSchema.js.map +1 -1
- 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 +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -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/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/index.d.ts +2 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +5 -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/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 +6 -9
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +12 -13
- 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/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/index.d.ts +4 -0
- package/dist/vision/index.d.ts.map +1 -1
- package/dist/vision/index.js +2 -0
- package/dist/vision/index.js.map +1 -1
- 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/websocket.d.ts +92 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +1 -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 +4 -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 +553 -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__/conversation/binding.test.ts +62 -0
- package/src/__tests__/conversation/controller.test.ts +732 -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 +218 -9
- package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
- package/src/__tests__/monitoring.test.ts +162 -0
- package/src/__tests__/persona-generation.test.ts +352 -0
- package/src/__tests__/platformAssistant.test.ts +484 -0
- 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__/tools-wrappers.test.ts +272 -0
- package/src/__tests__/videoGraph.test.ts +94 -0
- package/src/__tests__/websocket.test.ts +263 -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 +517 -0
- package/src/api.ts +2215 -95
- package/src/audio.ts +35 -0
- package/src/castProjection.ts +95 -0
- package/src/conversation/binding.ts +100 -0
- package/src/conversation/controller.ts +447 -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 +396 -13
- package/src/http.ts +72 -0
- package/src/index.ts +9 -0
- package/src/platformAssistant.ts +347 -0
- package/src/reactor/chunkDistribution.ts +98 -0
- package/src/reactor/index.ts +5 -0
- package/src/reactor/longLiveCommandDispatcher.ts +156 -0
- package/src/reactor/scenesFromEnrichment.ts +11 -76
- package/src/reactor/seedImageOrchestrator.ts +12 -13
- package/src/reactor/storyTimeline.ts +127 -0
- package/src/storyGraph.ts +298 -0
- package/src/vision/VisionSourceController.ts +354 -0
- package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
- package/src/vision/index.ts +13 -0
- package/src/vision/sourceKinds.ts +75 -0
- package/src/websocket.ts +99 -3
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Story Engine Phase 6 (B3) — tests for the regeneration additions on
|
|
3
|
+
* `ApiClient`:
|
|
4
|
+
* - startRegeneration(videoId, request) — POST .../regenerate (202 body).
|
|
5
|
+
* - listRegenerations(videoId, params?) — GET .../regenerations.
|
|
6
|
+
* - getRegeneration(videoId, runId) — GET .../regenerations/{runId}.
|
|
7
|
+
* - pollRegenerationUntilDone(videoId, runId, options?) — polls
|
|
8
|
+
* getRegeneration, watches record.status for the terminal set
|
|
9
|
+
* (complete | cancelled resolve; failed throws), mirroring
|
|
10
|
+
* pollVisemeBundleUntilDone.
|
|
11
|
+
*
|
|
12
|
+
* JSON methods go through `request` → `makeRequest` → fetch (same global-fetch
|
|
13
|
+
* mock pattern as documents.test.ts); the poller uses fake timers + a spy on
|
|
14
|
+
* getRegeneration (same pattern as api-pollers.test.ts).
|
|
15
|
+
*
|
|
16
|
+
* Endpoints live on the tools API (baseURL), NOT the chat API.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { ApiClient } from '../api';
|
|
20
|
+
import {
|
|
21
|
+
REGENERATION_STATUS,
|
|
22
|
+
REGEN_DELTA_KEYS,
|
|
23
|
+
type RegenerationRunResponse,
|
|
24
|
+
type RegenerateRequest,
|
|
25
|
+
buildRegenerationScope,
|
|
26
|
+
parseRegenerationNodeCounts,
|
|
27
|
+
} from '../api';
|
|
28
|
+
|
|
29
|
+
const TEST_BASE_URL = 'http://test.local';
|
|
30
|
+
const TEST_CHAT_BASE_URL = 'http://test.local/chat';
|
|
31
|
+
|
|
32
|
+
const makeClient = (sessionToken: string = 'test-token') =>
|
|
33
|
+
new ApiClient(TEST_BASE_URL, sessionToken, TEST_CHAT_BASE_URL);
|
|
34
|
+
|
|
35
|
+
const originalFetch = (globalThis as { fetch?: typeof fetch }).fetch;
|
|
36
|
+
|
|
37
|
+
const buildRun = (
|
|
38
|
+
overrides: Partial<RegenerationRunResponse> = {},
|
|
39
|
+
): RegenerationRunResponse => ({
|
|
40
|
+
traceId: 'trace-1',
|
|
41
|
+
runId: 'run-1',
|
|
42
|
+
videoId: 'video-1',
|
|
43
|
+
scope: 'acts',
|
|
44
|
+
status: REGENERATION_STATUS.QUEUED,
|
|
45
|
+
statusUrl: '/api/v1/tools/graph/video-1/regenerations/run-1',
|
|
46
|
+
createdAt: '2026-05-31T00:00:00Z',
|
|
47
|
+
promptAddon: null,
|
|
48
|
+
startedAt: null,
|
|
49
|
+
completedAt: null,
|
|
50
|
+
delta: {},
|
|
51
|
+
error: null,
|
|
52
|
+
...overrides,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
if (originalFetch === undefined) {
|
|
57
|
+
delete (globalThis as { fetch?: typeof fetch }).fetch;
|
|
58
|
+
} else {
|
|
59
|
+
(globalThis as { fetch?: typeof fetch }).fetch = originalFetch;
|
|
60
|
+
}
|
|
61
|
+
jest.restoreAllMocks();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('REGENERATION_STATUS const map', () => {
|
|
65
|
+
it('exposes the canonical lifecycle values mirrored from shared/models.py', () => {
|
|
66
|
+
expect(REGENERATION_STATUS.QUEUED).toBe('queued');
|
|
67
|
+
expect(REGENERATION_STATUS.RUNNING).toBe('running');
|
|
68
|
+
expect(REGENERATION_STATUS.MERGING).toBe('merging');
|
|
69
|
+
expect(REGENERATION_STATUS.COMPLETE).toBe('complete');
|
|
70
|
+
expect(REGENERATION_STATUS.FAILED).toBe('failed');
|
|
71
|
+
expect(REGENERATION_STATUS.CANCELLED).toBe('cancelled');
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe('buildRegenerationScope', () => {
|
|
76
|
+
it('returns the bare kind for acts / characters', () => {
|
|
77
|
+
expect(buildRegenerationScope('acts')).toBe('acts');
|
|
78
|
+
expect(buildRegenerationScope('characters')).toBe('characters');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('joins the targeted kind with its id using the separator', () => {
|
|
82
|
+
expect(buildRegenerationScope('scene', 'scene-42')).toBe('scene:scene-42');
|
|
83
|
+
expect(buildRegenerationScope('arc', 'arc-7')).toBe('arc:arc-7');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('throws when a targeted kind is missing its id', () => {
|
|
87
|
+
expect(() => buildRegenerationScope('scene')).toThrow();
|
|
88
|
+
expect(() => buildRegenerationScope('arc', '')).toThrow();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('throws when a bare kind is given a target id', () => {
|
|
92
|
+
expect(() => buildRegenerationScope('acts', 'x')).toThrow();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('parseRegenerationNodeCounts', () => {
|
|
97
|
+
it('extracts the four node count buckets from a merged delta', () => {
|
|
98
|
+
const delta = {
|
|
99
|
+
[REGEN_DELTA_KEYS.nodes]: {
|
|
100
|
+
[REGEN_DELTA_KEYS.added]: 2,
|
|
101
|
+
[REGEN_DELTA_KEYS.updated]: 5,
|
|
102
|
+
[REGEN_DELTA_KEYS.preservedUser]: 3,
|
|
103
|
+
[REGEN_DELTA_KEYS.removed]: 1,
|
|
104
|
+
},
|
|
105
|
+
[REGEN_DELTA_KEYS.edges]: { [REGEN_DELTA_KEYS.added]: 9 },
|
|
106
|
+
};
|
|
107
|
+
expect(parseRegenerationNodeCounts(delta)).toEqual({
|
|
108
|
+
added: 2,
|
|
109
|
+
updated: 5,
|
|
110
|
+
preservedUser: 3,
|
|
111
|
+
removed: 1,
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('returns all-zero counts for an empty (unmerged) delta', () => {
|
|
116
|
+
expect(parseRegenerationNodeCounts({})).toEqual({
|
|
117
|
+
added: 0,
|
|
118
|
+
updated: 0,
|
|
119
|
+
preservedUser: 0,
|
|
120
|
+
removed: 0,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('returns all-zero counts for a null/undefined delta', () => {
|
|
125
|
+
expect(parseRegenerationNodeCounts(null)).toEqual({
|
|
126
|
+
added: 0,
|
|
127
|
+
updated: 0,
|
|
128
|
+
preservedUser: 0,
|
|
129
|
+
removed: 0,
|
|
130
|
+
});
|
|
131
|
+
expect(parseRegenerationNodeCounts(undefined)).toEqual({
|
|
132
|
+
added: 0,
|
|
133
|
+
updated: 0,
|
|
134
|
+
preservedUser: 0,
|
|
135
|
+
removed: 0,
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('coerces missing / non-numeric / negative buckets to 0', () => {
|
|
140
|
+
const delta = {
|
|
141
|
+
[REGEN_DELTA_KEYS.nodes]: {
|
|
142
|
+
[REGEN_DELTA_KEYS.added]: '4', // wrong type
|
|
143
|
+
[REGEN_DELTA_KEYS.updated]: -3, // negative
|
|
144
|
+
// preservedUser absent
|
|
145
|
+
[REGEN_DELTA_KEYS.removed]: 2,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
expect(parseRegenerationNodeCounts(delta)).toEqual({
|
|
149
|
+
added: 0,
|
|
150
|
+
updated: 0,
|
|
151
|
+
preservedUser: 0,
|
|
152
|
+
removed: 2,
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('reads the counts off a real RegenerationRunResponse.delta', () => {
|
|
157
|
+
const run = buildRun({
|
|
158
|
+
status: REGENERATION_STATUS.COMPLETE,
|
|
159
|
+
delta: {
|
|
160
|
+
[REGEN_DELTA_KEYS.nodes]: {
|
|
161
|
+
[REGEN_DELTA_KEYS.added]: 1,
|
|
162
|
+
[REGEN_DELTA_KEYS.updated]: 4,
|
|
163
|
+
[REGEN_DELTA_KEYS.preservedUser]: 2,
|
|
164
|
+
[REGEN_DELTA_KEYS.removed]: 0,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
expect(parseRegenerationNodeCounts(run.delta)).toEqual({
|
|
169
|
+
added: 1,
|
|
170
|
+
updated: 4,
|
|
171
|
+
preservedUser: 2,
|
|
172
|
+
removed: 0,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('startRegeneration', () => {
|
|
178
|
+
it('POSTs the request body to .../regenerate and returns the 202 run', async () => {
|
|
179
|
+
const run = buildRun();
|
|
180
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
181
|
+
ok: true,
|
|
182
|
+
status: 202,
|
|
183
|
+
json: async () => run,
|
|
184
|
+
});
|
|
185
|
+
(globalThis as { fetch?: typeof fetch }).fetch =
|
|
186
|
+
fetchMock as unknown as typeof fetch;
|
|
187
|
+
|
|
188
|
+
const req: RegenerateRequest = { scope: 'acts', promptAddon: 'darker tone' };
|
|
189
|
+
const result = await makeClient().startRegeneration('video-1', req);
|
|
190
|
+
|
|
191
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
192
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
193
|
+
expect(url).toBe(
|
|
194
|
+
'http://test.local/api/v1/tools/graph/video-1/regenerate',
|
|
195
|
+
);
|
|
196
|
+
expect(init.method).toBe('POST');
|
|
197
|
+
expect(JSON.parse(init.body as string)).toEqual({
|
|
198
|
+
scope: 'acts',
|
|
199
|
+
promptAddon: 'darker tone',
|
|
200
|
+
});
|
|
201
|
+
expect(result).toEqual(run);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('forwards appliedDocumentIds in the body and surfaces them on the run (R6d)', async () => {
|
|
205
|
+
const run = buildRun({ appliedDocumentIds: ['doc-1'] });
|
|
206
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
207
|
+
ok: true,
|
|
208
|
+
status: 202,
|
|
209
|
+
json: async () => run,
|
|
210
|
+
});
|
|
211
|
+
(globalThis as { fetch?: typeof fetch }).fetch =
|
|
212
|
+
fetchMock as unknown as typeof fetch;
|
|
213
|
+
|
|
214
|
+
const req: RegenerateRequest = {
|
|
215
|
+
scope: 'acts',
|
|
216
|
+
appliedDocumentIds: ['doc-1', 'doc-1', 'doc-2'],
|
|
217
|
+
};
|
|
218
|
+
const result = await makeClient().startRegeneration('video-1', req);
|
|
219
|
+
|
|
220
|
+
const [, init] = fetchMock.mock.calls[0];
|
|
221
|
+
// The client forwards the ids verbatim — dedup/unknown-drop is server-side.
|
|
222
|
+
expect(JSON.parse(init.body as string)).toEqual({
|
|
223
|
+
scope: 'acts',
|
|
224
|
+
appliedDocumentIds: ['doc-1', 'doc-1', 'doc-2'],
|
|
225
|
+
});
|
|
226
|
+
expect(result.appliedDocumentIds).toEqual(['doc-1']);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('url-encodes the videoId path segment', async () => {
|
|
230
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
231
|
+
ok: true,
|
|
232
|
+
status: 202,
|
|
233
|
+
json: async () => buildRun(),
|
|
234
|
+
});
|
|
235
|
+
(globalThis as { fetch?: typeof fetch }).fetch =
|
|
236
|
+
fetchMock as unknown as typeof fetch;
|
|
237
|
+
|
|
238
|
+
await makeClient().startRegeneration('vid/with space', { scope: 'acts' });
|
|
239
|
+
|
|
240
|
+
const [url] = fetchMock.mock.calls[0];
|
|
241
|
+
expect(url).toBe(
|
|
242
|
+
'http://test.local/api/v1/tools/graph/vid%2Fwith%20space/regenerate',
|
|
243
|
+
);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('propagates a 409 lock conflict as a thrown Error', async () => {
|
|
247
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
248
|
+
ok: false,
|
|
249
|
+
status: 409,
|
|
250
|
+
json: async () => ({ detail: 'A regeneration run is already in flight' }),
|
|
251
|
+
});
|
|
252
|
+
(globalThis as { fetch?: typeof fetch }).fetch =
|
|
253
|
+
fetchMock as unknown as typeof fetch;
|
|
254
|
+
|
|
255
|
+
await expect(
|
|
256
|
+
makeClient().startRegeneration('video-1', { scope: 'acts' }),
|
|
257
|
+
).rejects.toThrow('A regeneration run is already in flight');
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('listRegenerations', () => {
|
|
262
|
+
it('GETs .../regenerations with no query when params omitted', async () => {
|
|
263
|
+
const body = {
|
|
264
|
+
traceId: 'trace-list',
|
|
265
|
+
videoId: 'video-1',
|
|
266
|
+
runs: [buildRun()],
|
|
267
|
+
nextCursor: null,
|
|
268
|
+
};
|
|
269
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
270
|
+
ok: true,
|
|
271
|
+
status: 200,
|
|
272
|
+
json: async () => body,
|
|
273
|
+
});
|
|
274
|
+
(globalThis as { fetch?: typeof fetch }).fetch =
|
|
275
|
+
fetchMock as unknown as typeof fetch;
|
|
276
|
+
|
|
277
|
+
const result = await makeClient().listRegenerations('video-1');
|
|
278
|
+
|
|
279
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
280
|
+
expect(url).toBe(
|
|
281
|
+
'http://test.local/api/v1/tools/graph/video-1/regenerations',
|
|
282
|
+
);
|
|
283
|
+
expect(init.method ?? 'GET').toBe('GET');
|
|
284
|
+
expect(result.runs).toHaveLength(1);
|
|
285
|
+
expect(result.nextCursor).toBeNull();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('appends limit + cursor query params when provided', async () => {
|
|
289
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
290
|
+
ok: true,
|
|
291
|
+
status: 200,
|
|
292
|
+
json: async () => ({
|
|
293
|
+
traceId: 't',
|
|
294
|
+
videoId: 'video-1',
|
|
295
|
+
runs: [],
|
|
296
|
+
nextCursor: null,
|
|
297
|
+
}),
|
|
298
|
+
});
|
|
299
|
+
(globalThis as { fetch?: typeof fetch }).fetch =
|
|
300
|
+
fetchMock as unknown as typeof fetch;
|
|
301
|
+
|
|
302
|
+
await makeClient().listRegenerations('video-1', {
|
|
303
|
+
limit: 5,
|
|
304
|
+
cursor: 'abc',
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const [url] = fetchMock.mock.calls[0];
|
|
308
|
+
expect(url).toContain('limit=5');
|
|
309
|
+
expect(url).toContain('cursor=abc');
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe('getRegeneration', () => {
|
|
314
|
+
it('GETs .../regenerations/{runId} and returns the run', async () => {
|
|
315
|
+
const run = buildRun({ runId: 'run-9', status: REGENERATION_STATUS.RUNNING });
|
|
316
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
317
|
+
ok: true,
|
|
318
|
+
status: 200,
|
|
319
|
+
json: async () => run,
|
|
320
|
+
});
|
|
321
|
+
(globalThis as { fetch?: typeof fetch }).fetch =
|
|
322
|
+
fetchMock as unknown as typeof fetch;
|
|
323
|
+
|
|
324
|
+
const result = await makeClient().getRegeneration('video-1', 'run-9');
|
|
325
|
+
|
|
326
|
+
const [url] = fetchMock.mock.calls[0];
|
|
327
|
+
expect(url).toBe(
|
|
328
|
+
'http://test.local/api/v1/tools/graph/video-1/regenerations/run-9',
|
|
329
|
+
);
|
|
330
|
+
expect(result).toEqual(run);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('propagates a 404 as a thrown Error', async () => {
|
|
334
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
335
|
+
ok: false,
|
|
336
|
+
status: 404,
|
|
337
|
+
json: async () => ({ detail: 'Regeneration run not found' }),
|
|
338
|
+
});
|
|
339
|
+
(globalThis as { fetch?: typeof fetch }).fetch =
|
|
340
|
+
fetchMock as unknown as typeof fetch;
|
|
341
|
+
|
|
342
|
+
await expect(
|
|
343
|
+
makeClient().getRegeneration('video-1', 'missing'),
|
|
344
|
+
).rejects.toThrow('Regeneration run not found');
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe('pollRegenerationUntilDone', () => {
|
|
349
|
+
beforeEach(() => {
|
|
350
|
+
jest.useFakeTimers();
|
|
351
|
+
});
|
|
352
|
+
afterEach(() => {
|
|
353
|
+
jest.useRealTimers();
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('resolves immediately when status is complete on first read', async () => {
|
|
357
|
+
const client = makeClient();
|
|
358
|
+
const record = buildRun({ status: REGENERATION_STATUS.COMPLETE });
|
|
359
|
+
jest.spyOn(client, 'getRegeneration').mockResolvedValue(record);
|
|
360
|
+
|
|
361
|
+
await expect(
|
|
362
|
+
client.pollRegenerationUntilDone('video-1', 'run-1'),
|
|
363
|
+
).resolves.toBe(record);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('resolves when status is cancelled (terminal, not an error)', async () => {
|
|
367
|
+
const client = makeClient();
|
|
368
|
+
const record = buildRun({ status: REGENERATION_STATUS.CANCELLED });
|
|
369
|
+
jest.spyOn(client, 'getRegeneration').mockResolvedValue(record);
|
|
370
|
+
|
|
371
|
+
await expect(
|
|
372
|
+
client.pollRegenerationUntilDone('video-1', 'run-1'),
|
|
373
|
+
).resolves.toBe(record);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it('throws with the run error when status is failed', async () => {
|
|
377
|
+
const client = makeClient();
|
|
378
|
+
const record = buildRun({
|
|
379
|
+
status: REGENERATION_STATUS.FAILED,
|
|
380
|
+
error: 'pegasus invoke failed',
|
|
381
|
+
});
|
|
382
|
+
jest.spyOn(client, 'getRegeneration').mockResolvedValue(record);
|
|
383
|
+
|
|
384
|
+
await expect(
|
|
385
|
+
client.pollRegenerationUntilDone('video-1', 'run-1'),
|
|
386
|
+
).rejects.toThrow('pegasus invoke failed');
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it('throws the fallback message when a failed run carries no error string', async () => {
|
|
390
|
+
// A failed run with error=null must NOT surface "undefined" — the poller
|
|
391
|
+
// falls back to a sensible generic message (record.error ?? fallback).
|
|
392
|
+
const client = makeClient();
|
|
393
|
+
const record = buildRun({
|
|
394
|
+
status: REGENERATION_STATUS.FAILED,
|
|
395
|
+
error: null,
|
|
396
|
+
});
|
|
397
|
+
jest.spyOn(client, 'getRegeneration').mockResolvedValue(record);
|
|
398
|
+
|
|
399
|
+
const rejection = client.pollRegenerationUntilDone('video-1', 'run-1');
|
|
400
|
+
await expect(rejection).rejects.toThrow('Regeneration failed');
|
|
401
|
+
await expect(rejection).rejects.not.toThrow('undefined');
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it('rejects with AbortError when signal is already aborted on entry', async () => {
|
|
405
|
+
const client = makeClient();
|
|
406
|
+
const controller = new AbortController();
|
|
407
|
+
controller.abort();
|
|
408
|
+
const spy = jest.spyOn(client, 'getRegeneration');
|
|
409
|
+
|
|
410
|
+
await expect(
|
|
411
|
+
client.pollRegenerationUntilDone('video-1', 'run-1', {
|
|
412
|
+
signal: controller.signal,
|
|
413
|
+
}),
|
|
414
|
+
).rejects.toThrow('Polling aborted');
|
|
415
|
+
expect(spy).not.toHaveBeenCalled();
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('rejects with AbortError when signal aborts mid-sleep', async () => {
|
|
419
|
+
const client = makeClient();
|
|
420
|
+
jest
|
|
421
|
+
.spyOn(client, 'getRegeneration')
|
|
422
|
+
.mockResolvedValue(buildRun({ status: REGENERATION_STATUS.RUNNING }));
|
|
423
|
+
const controller = new AbortController();
|
|
424
|
+
|
|
425
|
+
const promise = client.pollRegenerationUntilDone('video-1', 'run-1', {
|
|
426
|
+
signal: controller.signal,
|
|
427
|
+
intervalMs: 5000,
|
|
428
|
+
});
|
|
429
|
+
const expected = expect(promise).rejects.toThrow('Polling aborted');
|
|
430
|
+
await Promise.resolve();
|
|
431
|
+
await Promise.resolve();
|
|
432
|
+
controller.abort();
|
|
433
|
+
await expected;
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it('iterates queued → running → merging → complete', async () => {
|
|
437
|
+
const client = makeClient();
|
|
438
|
+
const done = buildRun({ status: REGENERATION_STATUS.COMPLETE });
|
|
439
|
+
const spy = jest
|
|
440
|
+
.spyOn(client, 'getRegeneration')
|
|
441
|
+
.mockResolvedValueOnce(buildRun({ status: REGENERATION_STATUS.QUEUED }))
|
|
442
|
+
.mockResolvedValueOnce(buildRun({ status: REGENERATION_STATUS.RUNNING }))
|
|
443
|
+
.mockResolvedValueOnce(buildRun({ status: REGENERATION_STATUS.MERGING }))
|
|
444
|
+
.mockResolvedValueOnce(done);
|
|
445
|
+
|
|
446
|
+
const promise = client.pollRegenerationUntilDone('video-1', 'run-1', {
|
|
447
|
+
intervalMs: 1000,
|
|
448
|
+
timeoutMs: 60_000,
|
|
449
|
+
});
|
|
450
|
+
await jest.advanceTimersByTimeAsync(1100);
|
|
451
|
+
await jest.advanceTimersByTimeAsync(1100);
|
|
452
|
+
await jest.advanceTimersByTimeAsync(1100);
|
|
453
|
+
await expect(promise).resolves.toBe(done);
|
|
454
|
+
expect(spy).toHaveBeenCalledTimes(4);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('rejects with a timeout error after the deadline elapses', async () => {
|
|
458
|
+
const client = makeClient();
|
|
459
|
+
jest
|
|
460
|
+
.spyOn(client, 'getRegeneration')
|
|
461
|
+
.mockResolvedValue(buildRun({ status: REGENERATION_STATUS.RUNNING }));
|
|
462
|
+
|
|
463
|
+
const promise = client.pollRegenerationUntilDone('video-1', 'run-1', {
|
|
464
|
+
intervalMs: 1000,
|
|
465
|
+
timeoutMs: 100,
|
|
466
|
+
});
|
|
467
|
+
const rejected = expect(promise).rejects.toThrow(/timed out after/);
|
|
468
|
+
await jest.advanceTimersByTimeAsync(1100);
|
|
469
|
+
await rejected;
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it('forwards the signal to getRegeneration so an in-flight fetch can cancel', async () => {
|
|
473
|
+
const client = makeClient();
|
|
474
|
+
const spy = jest
|
|
475
|
+
.spyOn(client, 'getRegeneration')
|
|
476
|
+
.mockResolvedValue(buildRun({ status: REGENERATION_STATUS.COMPLETE }));
|
|
477
|
+
const controller = new AbortController();
|
|
478
|
+
|
|
479
|
+
await client.pollRegenerationUntilDone('video-1', 'run-1', {
|
|
480
|
+
signal: controller.signal,
|
|
481
|
+
});
|
|
482
|
+
expect(spy).toHaveBeenCalledWith('video-1', 'run-1', {
|
|
483
|
+
signal: controller.signal,
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
});
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the M7 Phase 7 (Creator Studio) Story API client methods.
|
|
3
|
+
*
|
|
4
|
+
* Contract: the backend emits camelCase JSON keys verbatim (no remapping in
|
|
5
|
+
* client-core), so the parsed objects match the StorySummary / StoryDetail
|
|
6
|
+
* interfaces field-for-field. storyId === videoId (1:1) in P7, and posterUrl
|
|
7
|
+
* is always null today (optional + nullable in the type).
|
|
8
|
+
*/
|
|
9
|
+
import { ApiClient } from '../api';
|
|
10
|
+
import type {
|
|
11
|
+
GetStoryResponse,
|
|
12
|
+
ListStoriesResponse,
|
|
13
|
+
} from '../api';
|
|
14
|
+
|
|
15
|
+
describe('ApiClient story methods (M7 P7)', () => {
|
|
16
|
+
let client: ApiClient;
|
|
17
|
+
let fetchMock: jest.Mock;
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
client = new ApiClient(
|
|
21
|
+
'https://api.example.com',
|
|
22
|
+
'test-token',
|
|
23
|
+
'https://api.example.com/chat',
|
|
24
|
+
);
|
|
25
|
+
fetchMock = jest.fn();
|
|
26
|
+
global.fetch = fetchMock as unknown as typeof fetch;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
jest.restoreAllMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function mockJsonResponse(body: unknown, status = 200): Response {
|
|
34
|
+
return {
|
|
35
|
+
ok: status >= 200 && status < 300,
|
|
36
|
+
status,
|
|
37
|
+
headers: {
|
|
38
|
+
get: (name: string) =>
|
|
39
|
+
name.toLowerCase() === 'content-type' ? 'application/json' : null,
|
|
40
|
+
},
|
|
41
|
+
json: async () => body,
|
|
42
|
+
} as unknown as Response;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
it('listStories hits /api/v1/stories and returns parsed stories', async () => {
|
|
46
|
+
const body: ListStoriesResponse = {
|
|
47
|
+
traceId: 'trace-list',
|
|
48
|
+
stories: [
|
|
49
|
+
{
|
|
50
|
+
storyId: 'those-who-remain',
|
|
51
|
+
videoId: 'those-who-remain',
|
|
52
|
+
title: 'Those Who Remain',
|
|
53
|
+
updatedAt: '2026-05-20T18:04:11+00:00',
|
|
54
|
+
posterUrl: null,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
59
|
+
|
|
60
|
+
const result = await client.listStories();
|
|
61
|
+
|
|
62
|
+
expect(result.traceId).toBe('trace-list');
|
|
63
|
+
expect(result.stories).toHaveLength(1);
|
|
64
|
+
const story = result.stories[0];
|
|
65
|
+
// storyId === videoId (1:1) in P7.
|
|
66
|
+
expect(story.storyId).toBe('those-who-remain');
|
|
67
|
+
expect(story.videoId).toBe('those-who-remain');
|
|
68
|
+
expect(story.storyId).toBe(story.videoId);
|
|
69
|
+
expect(story.title).toBe('Those Who Remain');
|
|
70
|
+
expect(story.updatedAt).toBe('2026-05-20T18:04:11+00:00');
|
|
71
|
+
expect(story.posterUrl).toBeNull();
|
|
72
|
+
|
|
73
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
74
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
75
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/stories');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('listStories returns an empty array when there are no stories', async () => {
|
|
79
|
+
const body: ListStoriesResponse = { traceId: 'trace-empty', stories: [] };
|
|
80
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
81
|
+
|
|
82
|
+
const result = await client.listStories();
|
|
83
|
+
|
|
84
|
+
expect(result.traceId).toBe('trace-empty');
|
|
85
|
+
expect(result.stories).toEqual([]);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('getStory hits /api/v1/stories/{storyId} and returns the detail + counts', async () => {
|
|
89
|
+
const body: GetStoryResponse = {
|
|
90
|
+
traceId: 'trace-detail',
|
|
91
|
+
story: {
|
|
92
|
+
storyId: 'those-who-remain',
|
|
93
|
+
videoId: 'those-who-remain',
|
|
94
|
+
title: 'Those Who Remain',
|
|
95
|
+
updatedAt: '2026-05-20T18:04:11+00:00',
|
|
96
|
+
posterUrl: null,
|
|
97
|
+
counts: { acts: 3, scenes: 12, characters: 5, documents: 2 },
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
101
|
+
|
|
102
|
+
const result = await client.getStory('those-who-remain');
|
|
103
|
+
|
|
104
|
+
expect(result.traceId).toBe('trace-detail');
|
|
105
|
+
const story = result.story;
|
|
106
|
+
expect(story.storyId).toBe('those-who-remain');
|
|
107
|
+
expect(story.videoId).toBe('those-who-remain');
|
|
108
|
+
expect(story.title).toBe('Those Who Remain');
|
|
109
|
+
expect(story.updatedAt).toBe('2026-05-20T18:04:11+00:00');
|
|
110
|
+
expect(story.posterUrl).toBeNull();
|
|
111
|
+
expect(story.counts).toEqual({
|
|
112
|
+
acts: 3,
|
|
113
|
+
scenes: 12,
|
|
114
|
+
characters: 5,
|
|
115
|
+
documents: 2,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
119
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
120
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/stories/those-who-remain');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('getStory percent-encodes the id segment', async () => {
|
|
124
|
+
const body: GetStoryResponse = {
|
|
125
|
+
traceId: 'trace-enc',
|
|
126
|
+
story: {
|
|
127
|
+
storyId: 'a b/c',
|
|
128
|
+
videoId: 'a b/c',
|
|
129
|
+
title: 'a b/c',
|
|
130
|
+
updatedAt: '2026-05-20T18:04:11+00:00',
|
|
131
|
+
posterUrl: null,
|
|
132
|
+
counts: { acts: 0, scenes: 0, characters: 0, documents: 0 },
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
136
|
+
|
|
137
|
+
await client.getStory('a b/c');
|
|
138
|
+
|
|
139
|
+
const calledUrl = fetchMock.mock.calls[0][0] as string;
|
|
140
|
+
expect(calledUrl).toBe('https://api.example.com/api/v1/stories/a%20b%2Fc');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('getStory surfaces a 404 as a thrown error', async () => {
|
|
144
|
+
fetchMock.mockResolvedValueOnce(
|
|
145
|
+
mockJsonResponse({ detail: 'Story not found' }, 404),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
await expect(client.getStory('missing')).rejects.toThrow('Story not found');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('tolerates posterUrl being absent (optional) in the parsed shape', async () => {
|
|
152
|
+
// The backend always emits posterUrl=null today, but the type is
|
|
153
|
+
// optional too. A payload that omits it must still type-check and parse.
|
|
154
|
+
const body = {
|
|
155
|
+
traceId: 'trace-noposter',
|
|
156
|
+
stories: [
|
|
157
|
+
{
|
|
158
|
+
storyId: 'v1',
|
|
159
|
+
videoId: 'v1',
|
|
160
|
+
title: 'v1',
|
|
161
|
+
updatedAt: '2026-05-20T18:04:11+00:00',
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
} as ListStoriesResponse;
|
|
165
|
+
fetchMock.mockResolvedValueOnce(mockJsonResponse(body));
|
|
166
|
+
|
|
167
|
+
const result = await client.listStories();
|
|
168
|
+
|
|
169
|
+
expect(result.stories[0].posterUrl).toBeUndefined();
|
|
170
|
+
});
|
|
171
|
+
});
|