@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,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `deriveStoryTimeline` — the collapsed-story-projection
|
|
3
|
+
* (`SceneView[]`) → world-model-timeline mapper (Platform Restructure R8.1).
|
|
4
|
+
*
|
|
5
|
+
* Coverage:
|
|
6
|
+
* - empty SceneView[] → [] (defensive contract, no throw)
|
|
7
|
+
* - 3 timed scenes → 3 beats, proportional chunks, first pinned to 0,
|
|
8
|
+
* monotonically increasing, clamped to maxChunks - 1
|
|
9
|
+
* - prompt contains the scene summary + featured-character names + location
|
|
10
|
+
* - styleHint prepended with a single space, no trailing punctuation
|
|
11
|
+
* - label carries the scene-id provenance tag
|
|
12
|
+
* - sourceStart/sourceEnd from startTime/endTime; null times omitted
|
|
13
|
+
* - maxChunks <= 0 → []
|
|
14
|
+
* - shares the SAME chunk distribution as mapEnrichmentToTimeline (untimed
|
|
15
|
+
* scenes → even distribution)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
deriveStoryTimeline,
|
|
20
|
+
type StoryTimelineOptions,
|
|
21
|
+
} from '../../reactor/storyTimeline';
|
|
22
|
+
import type { TimelineBeat } from '../../reactor/scenesFromEnrichment';
|
|
23
|
+
import { deriveScenes, type SceneView } from '../../storyGraph';
|
|
24
|
+
import type { VideoGraphResponse } from '../../api';
|
|
25
|
+
|
|
26
|
+
function makeScene(overrides: Partial<SceneView> = {}): SceneView {
|
|
27
|
+
return {
|
|
28
|
+
nodeId: 'n-scene',
|
|
29
|
+
sceneId: 'sc-1',
|
|
30
|
+
title: 'A Scene',
|
|
31
|
+
index: 1,
|
|
32
|
+
startTime: 0,
|
|
33
|
+
endTime: 10,
|
|
34
|
+
summary: 'Something happens.',
|
|
35
|
+
actNodeId: 'n-act',
|
|
36
|
+
actTitle: 'Act One',
|
|
37
|
+
actIndex: 1,
|
|
38
|
+
featuredCharacters: [],
|
|
39
|
+
location: null,
|
|
40
|
+
shots: [],
|
|
41
|
+
...overrides,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe('deriveStoryTimeline', () => {
|
|
46
|
+
it('returns [] for an empty scene list (no throw)', () => {
|
|
47
|
+
expect(deriveStoryTimeline([])).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('returns [] when maxChunks is non-positive', () => {
|
|
51
|
+
const scenes = [makeScene()];
|
|
52
|
+
expect(deriveStoryTimeline(scenes, { maxChunks: 0 })).toEqual([]);
|
|
53
|
+
expect(deriveStoryTimeline(scenes, { maxChunks: -5 })).toEqual([]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('maps 3 timed scenes to 3 monotonically-increasing beats, first pinned to chunk 0', () => {
|
|
57
|
+
const scenes: SceneView[] = [
|
|
58
|
+
makeScene({ sceneId: 'sc-1', index: 1, startTime: 0, endTime: 30, summary: 'Opening.' }),
|
|
59
|
+
makeScene({ sceneId: 'sc-2', index: 2, startTime: 30, endTime: 60, summary: 'Middle.' }),
|
|
60
|
+
makeScene({ sceneId: 'sc-3', index: 3, startTime: 60, endTime: 90, summary: 'Climax.' }),
|
|
61
|
+
];
|
|
62
|
+
const beats = deriveStoryTimeline(scenes, { maxChunks: 30 });
|
|
63
|
+
expect(beats).toHaveLength(3);
|
|
64
|
+
expect(beats[0].chunk).toBe(0);
|
|
65
|
+
// monotonically increasing
|
|
66
|
+
expect(beats[1].chunk).toBeGreaterThan(beats[0].chunk);
|
|
67
|
+
expect(beats[2].chunk).toBeGreaterThan(beats[1].chunk);
|
|
68
|
+
// clamped to maxChunks - 1
|
|
69
|
+
for (const b of beats) {
|
|
70
|
+
expect(b.chunk).toBeGreaterThanOrEqual(0);
|
|
71
|
+
expect(b.chunk).toBeLessThanOrEqual(29);
|
|
72
|
+
}
|
|
73
|
+
// Proportional placement by scene START over the 0..90 span (same rule as
|
|
74
|
+
// mapEnrichmentToTimeline): scene-3 starts at 60 → round(60/90 * 29) = 19.
|
|
75
|
+
expect(beats[1].chunk).toBe(10);
|
|
76
|
+
expect(beats[2].chunk).toBe(19);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('grounds each prompt in the scene summary + featured-character names + location', () => {
|
|
80
|
+
const scenes: SceneView[] = [
|
|
81
|
+
makeScene({
|
|
82
|
+
sceneId: 'sc-1',
|
|
83
|
+
summary: 'Alice confronts Bob in the bunker.',
|
|
84
|
+
featuredCharacters: [
|
|
85
|
+
{ nodeId: 'n-a', entityId: 'c-alice', name: 'Alice' },
|
|
86
|
+
{ nodeId: 'n-b', entityId: 'c-bob', name: 'Bob' },
|
|
87
|
+
],
|
|
88
|
+
location: { nodeId: 'n-l', entityId: 'l-bunker', name: 'The Bunker' },
|
|
89
|
+
}),
|
|
90
|
+
];
|
|
91
|
+
const [beat] = deriveStoryTimeline(scenes);
|
|
92
|
+
expect(beat.prompt).toContain('Alice confronts Bob in the bunker.');
|
|
93
|
+
expect(beat.prompt).toContain('Alice');
|
|
94
|
+
expect(beat.prompt).toContain('Bob');
|
|
95
|
+
expect(beat.prompt).toContain('The Bunker');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('prepends styleHint with a single space and no trailing punctuation', () => {
|
|
99
|
+
const scenes = [makeScene({ summary: 'A quiet morning.' })];
|
|
100
|
+
const opts: StoryTimelineOptions = { styleHint: 'cinematic 16:9, golden hour' };
|
|
101
|
+
const [beat] = deriveStoryTimeline(scenes, opts);
|
|
102
|
+
expect(beat.prompt.startsWith('cinematic 16:9, golden hour A quiet morning.')).toBe(true);
|
|
103
|
+
// exactly one space between hint and body
|
|
104
|
+
expect(beat.prompt).not.toContain('golden hour A');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('trims a styleHint and ignores a blank one', () => {
|
|
108
|
+
const scenes = [makeScene({ summary: 'Body.' })];
|
|
109
|
+
expect(deriveStoryTimeline(scenes, { styleHint: ' ' })[0].prompt).toBe('Body.');
|
|
110
|
+
expect(deriveStoryTimeline(scenes, { styleHint: ' neon ' })[0].prompt).toBe('neon Body.');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('falls back to the scene title when the summary is empty', () => {
|
|
114
|
+
const scenes = [makeScene({ title: 'The Reckoning', summary: null, featuredCharacters: [] })];
|
|
115
|
+
expect(deriveStoryTimeline(scenes)[0].prompt).toContain('The Reckoning');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('tags the beat label with the scene-id provenance', () => {
|
|
119
|
+
const scenes = [makeScene({ sceneId: 'sc-42', title: 'Finale' })];
|
|
120
|
+
expect(deriveStoryTimeline(scenes)[0].label).toBe('Finale (sc-42)');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('carries sourceStart/sourceEnd from scene times; omits them when null', () => {
|
|
124
|
+
const timed = deriveStoryTimeline([makeScene({ startTime: 5, endTime: 15 })])[0];
|
|
125
|
+
expect(timed.sourceStart).toBe(5);
|
|
126
|
+
expect(timed.sourceEnd).toBe(15);
|
|
127
|
+
|
|
128
|
+
const untimed = deriveStoryTimeline([makeScene({ startTime: null, endTime: null })])[0];
|
|
129
|
+
expect(untimed.sourceStart).toBeUndefined();
|
|
130
|
+
expect(untimed.sourceEnd).toBeUndefined();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('distributes untimed scenes evenly (shared distribution with mapEnrichmentToTimeline)', () => {
|
|
134
|
+
const scenes: SceneView[] = [
|
|
135
|
+
makeScene({ sceneId: 'a', startTime: null, endTime: null }),
|
|
136
|
+
makeScene({ sceneId: 'b', startTime: null, endTime: null }),
|
|
137
|
+
makeScene({ sceneId: 'c', startTime: null, endTime: null }),
|
|
138
|
+
];
|
|
139
|
+
const beats = deriveStoryTimeline(scenes, { maxChunks: 30, minChunkSpacing: 1 });
|
|
140
|
+
expect(beats.map((b) => b.chunk)).toEqual([0, 15, 29]);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('enforces minChunkSpacing — beats too close are dropped', () => {
|
|
144
|
+
// Two scenes whose proportional chunks would land within minChunkSpacing.
|
|
145
|
+
const scenes: SceneView[] = [
|
|
146
|
+
makeScene({ sceneId: 'a', startTime: 0, endTime: 1 }),
|
|
147
|
+
makeScene({ sceneId: 'b', startTime: 0.1, endTime: 1 }),
|
|
148
|
+
makeScene({ sceneId: 'c', startTime: 100, endTime: 110 }),
|
|
149
|
+
];
|
|
150
|
+
const beats = deriveStoryTimeline(scenes, { maxChunks: 30, minChunkSpacing: 5 });
|
|
151
|
+
// First pinned, second too close to first → dropped, third kept.
|
|
152
|
+
expect(beats.map((b) => b.label)).toEqual(['A Scene (a)', 'A Scene (c)']);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('produces a TimelineBeat[] assignable to the existing beat type', () => {
|
|
156
|
+
const beats: TimelineBeat[] = deriveStoryTimeline([makeScene()]);
|
|
157
|
+
expect(beats[0]).toHaveProperty('chunk');
|
|
158
|
+
expect(beats[0]).toHaveProperty('prompt');
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('end-to-end: a t0/t1 story graph → proportional, time-carrying beats', () => {
|
|
162
|
+
// The production path: get_video_graph(detail=story) Scene nodes carry
|
|
163
|
+
// t0/t1, deriveScenes reads them, deriveStoryTimeline places proportionally
|
|
164
|
+
// and carries sourceStart/sourceEnd. Regression for codex R8.1 P2 — before
|
|
165
|
+
// the t0/t1 fix this fell back to even distribution with no source times.
|
|
166
|
+
const graph: VideoGraphResponse = {
|
|
167
|
+
traceId: 't',
|
|
168
|
+
videoId: 'v',
|
|
169
|
+
nodes: [
|
|
170
|
+
{ id: 'n-a', label: 'Act', properties: { actId: 'a1', title: 'Act', index: 1 } },
|
|
171
|
+
{ id: 'n-s1', label: 'Scene', properties: { sceneId: 's1', title: 'One', index: 1, t0: 0, t1: 30 } },
|
|
172
|
+
{ id: 'n-s2', label: 'Scene', properties: { sceneId: 's2', title: 'Two', index: 2, t0: 60, t1: 90 } },
|
|
173
|
+
],
|
|
174
|
+
edges: [
|
|
175
|
+
{ id: 'e1', source: 'n-a', target: 'n-s1', type: 'CONTAINS', properties: {} },
|
|
176
|
+
{ id: 'e2', source: 'n-a', target: 'n-s2', type: 'CONTAINS', properties: {} },
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
const beats = deriveStoryTimeline(deriveScenes(graph), { maxChunks: 30 });
|
|
180
|
+
expect(beats).toHaveLength(2);
|
|
181
|
+
expect(beats[0]).toMatchObject({ chunk: 0, sourceStart: 0, sourceEnd: 30 });
|
|
182
|
+
// scene-2 starts at 60 over a 0..90 span → round(60/90 * 29) = 19 (NOT the
|
|
183
|
+
// even-distribution 29 the broken null-times path would have produced).
|
|
184
|
+
expect(beats[1]).toMatchObject({ chunk: 19, sourceStart: 60, sourceEnd: 90 });
|
|
185
|
+
});
|
|
186
|
+
});
|
|
@@ -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
|
+
});
|