@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,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the M7 Phase 4 document CRUD additions on `ApiClient`:
|
|
3
|
+
* `uploadDocument` (multipart XHR, mirrors `uploadVideo`), `listDocuments`,
|
|
4
|
+
* `getDocument`, `acceptSuggestion`, `rejectSuggestion` (204), and
|
|
5
|
+
* `deleteDocument`. JSON methods go through `request` → `makeRequest` →
|
|
6
|
+
* fetch (same global-fetch-mock pattern as `tools-wrappers.test.ts`);
|
|
7
|
+
* `uploadDocument` uses a mocked `XMLHttpRequest`.
|
|
8
|
+
*
|
|
9
|
+
* Endpoints live on the tools/ingestion API (baseURL), NOT the chat API.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { ApiClient } from '../api';
|
|
13
|
+
import {
|
|
14
|
+
DOC_STATUS_PENDING,
|
|
15
|
+
DOC_STATUS_READY,
|
|
16
|
+
DOC_STATUS_FAILED,
|
|
17
|
+
SUGGESTION_STATUS_PENDING,
|
|
18
|
+
SUGGESTION_STATUS_ACCEPTED,
|
|
19
|
+
} from '../api';
|
|
20
|
+
|
|
21
|
+
const TEST_BASE_URL = 'http://test.local';
|
|
22
|
+
const TEST_CHAT_BASE_URL = 'http://test.local/chat';
|
|
23
|
+
|
|
24
|
+
const makeClient = (sessionToken: string = 'test-token') =>
|
|
25
|
+
new ApiClient(TEST_BASE_URL, sessionToken, TEST_CHAT_BASE_URL);
|
|
26
|
+
|
|
27
|
+
const originalFetch = (globalThis as { fetch?: typeof fetch }).fetch;
|
|
28
|
+
const originalXHR = (globalThis as { XMLHttpRequest?: typeof XMLHttpRequest }).XMLHttpRequest;
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
if (originalFetch === undefined) {
|
|
32
|
+
delete (globalThis as { fetch?: typeof fetch }).fetch;
|
|
33
|
+
} else {
|
|
34
|
+
(globalThis as { fetch?: typeof fetch }).fetch = originalFetch;
|
|
35
|
+
}
|
|
36
|
+
if (originalXHR === undefined) {
|
|
37
|
+
delete (globalThis as { XMLHttpRequest?: typeof XMLHttpRequest }).XMLHttpRequest;
|
|
38
|
+
} else {
|
|
39
|
+
(globalThis as { XMLHttpRequest?: typeof XMLHttpRequest }).XMLHttpRequest = originalXHR;
|
|
40
|
+
}
|
|
41
|
+
jest.restoreAllMocks();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('document status / suggestion-status constants', () => {
|
|
45
|
+
it('exposes the canonical string values mirrored from shared/models.py', () => {
|
|
46
|
+
expect(DOC_STATUS_PENDING).toBe('pending');
|
|
47
|
+
expect(DOC_STATUS_READY).toBe('ready');
|
|
48
|
+
expect(DOC_STATUS_FAILED).toBe('failed');
|
|
49
|
+
expect(SUGGESTION_STATUS_PENDING).toBe('pending');
|
|
50
|
+
expect(SUGGESTION_STATUS_ACCEPTED).toBe('accepted');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('listDocuments', () => {
|
|
55
|
+
// Mirrors the backend ListDocumentsResponse: { traceId, results, nextToken }
|
|
56
|
+
// where each result is a DocumentResponse. The list endpoint omits suggestion
|
|
57
|
+
// CONTENT but the field is always present (empty array) for a stable contract.
|
|
58
|
+
const buildResponse = () => ({
|
|
59
|
+
traceId: 'trace-list',
|
|
60
|
+
results: [
|
|
61
|
+
{
|
|
62
|
+
docId: 'doc-1',
|
|
63
|
+
status: DOC_STATUS_READY,
|
|
64
|
+
videoId: 'video-1',
|
|
65
|
+
seriesId: null,
|
|
66
|
+
kind: 'script',
|
|
67
|
+
title: 'Pilot Script',
|
|
68
|
+
pageCount: 42,
|
|
69
|
+
parseError: null,
|
|
70
|
+
parseWarning: null,
|
|
71
|
+
suggestions: [],
|
|
72
|
+
createdAt: '2026-05-30T00:00:00Z',
|
|
73
|
+
updatedAt: '2026-05-30T00:01:00Z',
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
nextToken: null,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('GETs /api/v1/ingestion/documents with no query when params omitted', async () => {
|
|
80
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
81
|
+
ok: true,
|
|
82
|
+
status: 200,
|
|
83
|
+
json: async () => buildResponse(),
|
|
84
|
+
});
|
|
85
|
+
(globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
|
|
86
|
+
|
|
87
|
+
const result = await makeClient().listDocuments({});
|
|
88
|
+
|
|
89
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
90
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
91
|
+
expect(url).toBe(`${TEST_BASE_URL}/api/v1/ingestion/documents`);
|
|
92
|
+
expect(init.method ?? 'GET').toBe('GET');
|
|
93
|
+
expect(result.results).toHaveLength(1);
|
|
94
|
+
expect(result.results[0].docId).toBe('doc-1');
|
|
95
|
+
expect(result.traceId).toBe('trace-list');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('appends videoId / seriesId / limit / nextToken query params', async () => {
|
|
99
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
100
|
+
ok: true,
|
|
101
|
+
status: 200,
|
|
102
|
+
json: async () => ({ traceId: 't', results: [], nextToken: null }),
|
|
103
|
+
});
|
|
104
|
+
(globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
|
|
105
|
+
|
|
106
|
+
await makeClient().listDocuments({
|
|
107
|
+
videoId: 'video-1',
|
|
108
|
+
seriesId: 'series-9',
|
|
109
|
+
limit: 25,
|
|
110
|
+
nextToken: 'tok-2',
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const [url] = fetchMock.mock.calls[0];
|
|
114
|
+
const parsed = new URL(url as string);
|
|
115
|
+
expect(parsed.pathname).toBe('/api/v1/ingestion/documents');
|
|
116
|
+
expect(parsed.searchParams.get('videoId')).toBe('video-1');
|
|
117
|
+
expect(parsed.searchParams.get('seriesId')).toBe('series-9');
|
|
118
|
+
expect(parsed.searchParams.get('limit')).toBe('25');
|
|
119
|
+
expect(parsed.searchParams.get('nextToken')).toBe('tok-2');
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('getDocument', () => {
|
|
124
|
+
it('GETs /api/v1/ingestion/documents/{docId} and returns document with nested suggestions', async () => {
|
|
125
|
+
// Mirrors the backend DocumentDetailResponse: { traceId, document } where
|
|
126
|
+
// suggestions are NESTED inside document (there is NO top-level suggestions).
|
|
127
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
128
|
+
ok: true,
|
|
129
|
+
status: 200,
|
|
130
|
+
json: async () => ({
|
|
131
|
+
traceId: 'trace-get',
|
|
132
|
+
document: {
|
|
133
|
+
docId: 'doc-1',
|
|
134
|
+
status: DOC_STATUS_PENDING,
|
|
135
|
+
videoId: 'video-1',
|
|
136
|
+
seriesId: null,
|
|
137
|
+
kind: 'notes',
|
|
138
|
+
title: 'Director Notes',
|
|
139
|
+
pageCount: 3,
|
|
140
|
+
parseError: null,
|
|
141
|
+
parseWarning: null,
|
|
142
|
+
suggestions: [
|
|
143
|
+
{
|
|
144
|
+
suggestionId: 'sug-1',
|
|
145
|
+
status: SUGGESTION_STATUS_PENDING,
|
|
146
|
+
kind: 'node',
|
|
147
|
+
payload: { label: 'Scene', properties: {} },
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
createdAt: '2026-05-30T00:00:00Z',
|
|
151
|
+
updatedAt: '2026-05-30T00:00:00Z',
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
});
|
|
155
|
+
(globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
|
|
156
|
+
|
|
157
|
+
const result = await makeClient().getDocument('doc-1');
|
|
158
|
+
|
|
159
|
+
const [url] = fetchMock.mock.calls[0];
|
|
160
|
+
expect(url).toBe(`${TEST_BASE_URL}/api/v1/ingestion/documents/doc-1`);
|
|
161
|
+
expect(result.document.docId).toBe('doc-1');
|
|
162
|
+
expect(result.document.suggestions).toHaveLength(1);
|
|
163
|
+
expect(result.document.suggestions[0].kind).toBe('node');
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('acceptSuggestion', () => {
|
|
168
|
+
it('POSTs the accept endpoint and returns suggestionId/graphId', async () => {
|
|
169
|
+
// Mirrors the backend AcceptSuggestionResponse: { traceId, suggestionId, graphId }
|
|
170
|
+
// (one graphId regardless of node vs edge — no nodeId/edgeId split).
|
|
171
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
172
|
+
ok: true,
|
|
173
|
+
status: 201,
|
|
174
|
+
json: async () => ({
|
|
175
|
+
traceId: 'trace-acc',
|
|
176
|
+
suggestionId: 'sug-1',
|
|
177
|
+
graphId: 'Scene:sceneId:s-1',
|
|
178
|
+
}),
|
|
179
|
+
});
|
|
180
|
+
(globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
|
|
181
|
+
|
|
182
|
+
const result = await makeClient().acceptSuggestion('doc-1', 'sug-1');
|
|
183
|
+
|
|
184
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
185
|
+
expect(url).toBe(
|
|
186
|
+
`${TEST_BASE_URL}/api/v1/ingestion/documents/doc-1/suggestions/sug-1/accept`,
|
|
187
|
+
);
|
|
188
|
+
expect(init.method).toBe('POST');
|
|
189
|
+
expect(result.suggestionId).toBe('sug-1');
|
|
190
|
+
expect(result.graphId).toBe('Scene:sceneId:s-1');
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('surfaces a 422 FastAPI detail as a thrown Error', async () => {
|
|
194
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
195
|
+
ok: false,
|
|
196
|
+
status: 422,
|
|
197
|
+
statusText: 'Unprocessable Entity',
|
|
198
|
+
json: async () => ({ detail: 'Suggestion already resolved' }),
|
|
199
|
+
});
|
|
200
|
+
(globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
|
|
201
|
+
|
|
202
|
+
await expect(
|
|
203
|
+
makeClient().acceptSuggestion('doc-1', 'sug-1'),
|
|
204
|
+
).rejects.toThrow('Suggestion already resolved');
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('rejectSuggestion (204)', () => {
|
|
209
|
+
it('POSTs the reject endpoint and resolves to undefined on 204', async () => {
|
|
210
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
211
|
+
ok: true,
|
|
212
|
+
status: 204,
|
|
213
|
+
json: async () => {
|
|
214
|
+
throw new Error('204 has no body');
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
(globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
|
|
218
|
+
|
|
219
|
+
const result = await makeClient().rejectSuggestion('doc-1', 'sug-1');
|
|
220
|
+
|
|
221
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
222
|
+
expect(url).toBe(
|
|
223
|
+
`${TEST_BASE_URL}/api/v1/ingestion/documents/doc-1/suggestions/sug-1/reject`,
|
|
224
|
+
);
|
|
225
|
+
expect(init.method).toBe('POST');
|
|
226
|
+
expect(result).toBeUndefined();
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
describe('deleteDocument', () => {
|
|
231
|
+
it('DELETEs /api/v1/ingestion/documents/{docId} and resolves on 204', async () => {
|
|
232
|
+
const fetchMock = jest.fn().mockResolvedValue({
|
|
233
|
+
ok: true,
|
|
234
|
+
status: 204,
|
|
235
|
+
json: async () => {
|
|
236
|
+
throw new Error('204 has no body');
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
(globalThis as { fetch?: typeof fetch }).fetch = fetchMock as unknown as typeof fetch;
|
|
240
|
+
|
|
241
|
+
const result = await makeClient().deleteDocument('doc-1');
|
|
242
|
+
|
|
243
|
+
const [url, init] = fetchMock.mock.calls[0];
|
|
244
|
+
expect(url).toBe(`${TEST_BASE_URL}/api/v1/ingestion/documents/doc-1`);
|
|
245
|
+
expect(init.method).toBe('DELETE');
|
|
246
|
+
expect(result).toBeUndefined();
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe('uploadDocument (multipart XHR, mirrors uploadVideo)', () => {
|
|
251
|
+
// Minimal XHR test double capturing the multipart send + auth header and
|
|
252
|
+
// letting the test drive the load/error/progress lifecycle.
|
|
253
|
+
class MockXHR {
|
|
254
|
+
static instances: MockXHR[] = [];
|
|
255
|
+
upload = { listeners: {} as Record<string, (e: unknown) => void> };
|
|
256
|
+
listeners: Record<string, () => void> = {};
|
|
257
|
+
method = '';
|
|
258
|
+
url = '';
|
|
259
|
+
headers: Record<string, string> = {};
|
|
260
|
+
body: unknown = undefined;
|
|
261
|
+
status = 0;
|
|
262
|
+
statusText = '';
|
|
263
|
+
responseText = '';
|
|
264
|
+
|
|
265
|
+
constructor() {
|
|
266
|
+
MockXHR.instances.push(this);
|
|
267
|
+
}
|
|
268
|
+
open(method: string, url: string) {
|
|
269
|
+
this.method = method;
|
|
270
|
+
this.url = url;
|
|
271
|
+
}
|
|
272
|
+
setRequestHeader(k: string, v: string) {
|
|
273
|
+
this.headers[k] = v;
|
|
274
|
+
}
|
|
275
|
+
addEventListener(event: string, cb: () => void) {
|
|
276
|
+
this.listeners[event] = cb;
|
|
277
|
+
}
|
|
278
|
+
send(body: unknown) {
|
|
279
|
+
this.body = body;
|
|
280
|
+
}
|
|
281
|
+
// Test helper: drive the load lifecycle.
|
|
282
|
+
fireLoad(status: number, responseText: string) {
|
|
283
|
+
this.status = status;
|
|
284
|
+
this.responseText = responseText;
|
|
285
|
+
this.listeners['load']?.();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
beforeEach(() => {
|
|
290
|
+
MockXHR.instances = [];
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('POSTs multipart to /api/v1/ingestion/documents with auth + meta and parses the 202 body', async () => {
|
|
294
|
+
(globalThis as { XMLHttpRequest?: unknown }).XMLHttpRequest =
|
|
295
|
+
MockXHR as unknown as typeof XMLHttpRequest;
|
|
296
|
+
|
|
297
|
+
const file = new File(['%PDF-1.4 fake'], 'pilot.pdf', { type: 'application/pdf' });
|
|
298
|
+
const promise = makeClient('tok-xyz').uploadDocument(file, {
|
|
299
|
+
videoId: 'video-1',
|
|
300
|
+
kind: 'script',
|
|
301
|
+
title: 'Pilot Script',
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// Drive the lifecycle.
|
|
305
|
+
const xhr = MockXHR.instances[0];
|
|
306
|
+
expect(xhr).toBeDefined();
|
|
307
|
+
expect(xhr.method).toBe('POST');
|
|
308
|
+
expect(xhr.url).toBe(`${TEST_BASE_URL}/api/v1/ingestion/documents`);
|
|
309
|
+
expect(xhr.headers['Authorization']).toBe('Bearer tok-xyz');
|
|
310
|
+
expect(xhr.body).toBeInstanceOf(FormData);
|
|
311
|
+
// The file part MUST be sent under the field name `upload` — the backend
|
|
312
|
+
// UploadFile param is `upload` (matching the video-upload convention).
|
|
313
|
+
const form = xhr.body as FormData;
|
|
314
|
+
expect(form.get('upload')).toBe(file);
|
|
315
|
+
expect(typeof form.get('payload')).toBe('string');
|
|
316
|
+
|
|
317
|
+
// Mirrors the backend DocumentUploadResponse: { traceId, document } where
|
|
318
|
+
// document is the DocumentResponse wire shape (202 for a fresh upload).
|
|
319
|
+
xhr.fireLoad(
|
|
320
|
+
202,
|
|
321
|
+
JSON.stringify({
|
|
322
|
+
traceId: 'trace-up',
|
|
323
|
+
document: {
|
|
324
|
+
docId: 'doc-new',
|
|
325
|
+
status: DOC_STATUS_PENDING,
|
|
326
|
+
videoId: 'video-1',
|
|
327
|
+
seriesId: null,
|
|
328
|
+
kind: 'script',
|
|
329
|
+
title: 'Pilot Script',
|
|
330
|
+
pageCount: 0,
|
|
331
|
+
parseError: null,
|
|
332
|
+
parseWarning: null,
|
|
333
|
+
suggestions: [],
|
|
334
|
+
createdAt: '2026-05-30T00:00:00Z',
|
|
335
|
+
updatedAt: '2026-05-30T00:00:00Z',
|
|
336
|
+
},
|
|
337
|
+
}),
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
const result = await promise;
|
|
341
|
+
expect(result.document.docId).toBe('doc-new');
|
|
342
|
+
expect(result.document.status).toBe(DOC_STATUS_PENDING);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it('rejects with the backend detail on a non-2xx upload', async () => {
|
|
346
|
+
(globalThis as { XMLHttpRequest?: unknown }).XMLHttpRequest =
|
|
347
|
+
MockXHR as unknown as typeof XMLHttpRequest;
|
|
348
|
+
|
|
349
|
+
const file = new File(['x'], 'bad.pdf', { type: 'application/pdf' });
|
|
350
|
+
const promise = makeClient().uploadDocument(file, {
|
|
351
|
+
kind: 'notes',
|
|
352
|
+
title: 'Bad',
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const xhr = MockXHR.instances[0];
|
|
356
|
+
xhr.fireLoad(415, JSON.stringify({ detail: 'Unsupported document kind' }));
|
|
357
|
+
|
|
358
|
+
await expect(promise).rejects.toThrow('Unsupported document kind');
|
|
359
|
+
});
|
|
360
|
+
});
|
|
@@ -10,6 +10,11 @@ import {
|
|
|
10
10
|
AUTHORED_MEMORY_PROVENANCE,
|
|
11
11
|
isStoryGraphProvenance,
|
|
12
12
|
isMemoryFactProvenance,
|
|
13
|
+
fetchGraphSchema,
|
|
14
|
+
__resetGraphSchemaCache,
|
|
15
|
+
userCreatableLabels,
|
|
16
|
+
userCreatableEdges,
|
|
17
|
+
allowedPairs,
|
|
13
18
|
} from '../graphSchema';
|
|
14
19
|
import type {
|
|
15
20
|
GraphNodeLabel,
|
|
@@ -17,20 +22,91 @@ import type {
|
|
|
17
22
|
StoryGraphProvenance,
|
|
18
23
|
MemoryFactProvenance,
|
|
19
24
|
} from '../graphSchema';
|
|
25
|
+
import type { GraphSchemaResponse } from '../api';
|
|
20
26
|
|
|
21
27
|
describe('graphSchema — node + relationship vocabulary', () => {
|
|
22
|
-
it('exports the exact node labels
|
|
28
|
+
it('exports the exact node labels including the M7 P3a story + P5 Persona labels', () => {
|
|
23
29
|
expect([...GRAPH_NODE_LABELS].sort()).toEqual(
|
|
24
|
-
[
|
|
30
|
+
[
|
|
31
|
+
// M7 Phase 1b: pipeline narrative Act node (read/validate + regeneratable).
|
|
32
|
+
'Act',
|
|
33
|
+
'CharacterArc',
|
|
34
|
+
'DialogLine',
|
|
35
|
+
'Entity',
|
|
36
|
+
'Event',
|
|
37
|
+
// M7 Phase 5: pipeline-only Persona node (read/validate vocabulary).
|
|
38
|
+
'Persona',
|
|
39
|
+
'PlotBeat',
|
|
40
|
+
'Scene',
|
|
41
|
+
'Shot',
|
|
42
|
+
// M7 Phase 4: pipeline SourceDoc node (document ingestion).
|
|
43
|
+
'SourceDoc',
|
|
44
|
+
'Video',
|
|
45
|
+
].sort(),
|
|
25
46
|
);
|
|
26
47
|
});
|
|
27
48
|
|
|
28
|
-
it('exports the
|
|
49
|
+
it('exports the full READ-SURFACE relationship vocabulary (superset, additive)', () => {
|
|
50
|
+
// GRAPH_RELATIONSHIP_TYPES is the read-surface: every edge type a viewer can
|
|
51
|
+
// encounter on getVideoGraph edges. It is a SUPERSET of the original pipeline
|
|
52
|
+
// union (HAS_SHOT/MENTIONS/HAS_EVENT/HAS_DIALOG/SPOKEN_BY/NEXT) plus the M7
|
|
53
|
+
// narrative-structural (HAS_ACT/IN_ACT/CONTAINS/INCLUDES) and the six story
|
|
54
|
+
// edges. The create-surface is the strict subset `userCreatableEdges`.
|
|
29
55
|
expect([...GRAPH_RELATIONSHIP_TYPES].sort()).toEqual(
|
|
30
|
-
[
|
|
56
|
+
[
|
|
57
|
+
// M7 Phase 4: pipeline SourceDoc-[:ANNOTATES]->(Entity|Scene) edge.
|
|
58
|
+
'ANNOTATES',
|
|
59
|
+
'CAUSES',
|
|
60
|
+
'CONTAINS',
|
|
61
|
+
'FEATURES',
|
|
62
|
+
'HAS_ACT',
|
|
63
|
+
'HAS_DIALOG',
|
|
64
|
+
'HAS_EVENT',
|
|
65
|
+
'HAS_SHOT',
|
|
66
|
+
'INCLUDES',
|
|
67
|
+
'IN_ACT',
|
|
68
|
+
'LEADS_TO',
|
|
69
|
+
'MENTIONS',
|
|
70
|
+
'NEXT',
|
|
71
|
+
'ON_ARC',
|
|
72
|
+
// M7 Phase 5: pipeline-only persona↔character edge (read-surface).
|
|
73
|
+
'PORTRAYS',
|
|
74
|
+
'RELATES_TO',
|
|
75
|
+
'SET_IN',
|
|
76
|
+
'SPOKEN_BY',
|
|
77
|
+
].sort(),
|
|
31
78
|
);
|
|
32
79
|
});
|
|
33
80
|
|
|
81
|
+
it('keeps the original pipeline edges (additive-only: no public export removed)', () => {
|
|
82
|
+
// Regression guard for the additive-only contract: the sibling Vue Web-App
|
|
83
|
+
// pins @escapeaihq/client-core, and the read-surface must never DROP an edge
|
|
84
|
+
// the pipeline still emits. P3a must only ADD to this union.
|
|
85
|
+
const ORIGINAL_PIPELINE_EDGES: readonly GraphRelationshipType[] = [
|
|
86
|
+
'HAS_SHOT',
|
|
87
|
+
'MENTIONS',
|
|
88
|
+
'HAS_EVENT',
|
|
89
|
+
'HAS_DIALOG',
|
|
90
|
+
'SPOKEN_BY',
|
|
91
|
+
'NEXT',
|
|
92
|
+
];
|
|
93
|
+
const surface = new Set<string>(GRAPH_RELATIONSHIP_TYPES);
|
|
94
|
+
for (const edge of ORIGINAL_PIPELINE_EDGES) {
|
|
95
|
+
expect(surface.has(edge)).toBe(true);
|
|
96
|
+
}
|
|
97
|
+
// The read-surface is a STRICT superset — it carries more than the original six.
|
|
98
|
+
expect(GRAPH_RELATIONSHIP_TYPES.length).toBeGreaterThan(ORIGINAL_PIPELINE_EDGES.length);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('read-surface (GRAPH_RELATIONSHIP_TYPES) is a superset of the create-surface (userCreatableEdges)', () => {
|
|
102
|
+
const readSurface = new Set<string>(GRAPH_RELATIONSHIP_TYPES);
|
|
103
|
+
for (const creatable of userCreatableEdges) {
|
|
104
|
+
expect(readSurface.has(creatable)).toBe(true);
|
|
105
|
+
}
|
|
106
|
+
// ...and the read-surface carries read-only edges the create-surface omits.
|
|
107
|
+
expect(GRAPH_RELATIONSHIP_TYPES.length).toBeGreaterThan(userCreatableEdges.length);
|
|
108
|
+
});
|
|
109
|
+
|
|
34
110
|
it('maps every node label to a primary key', () => {
|
|
35
111
|
expect(GRAPH_PRIMARY_KEY).toEqual({
|
|
36
112
|
Video: 'videoId',
|
|
@@ -38,6 +114,15 @@ describe('graphSchema — node + relationship vocabulary', () => {
|
|
|
38
114
|
Entity: 'entityId',
|
|
39
115
|
Event: 'eventId',
|
|
40
116
|
DialogLine: 'dialogId',
|
|
117
|
+
// M7 Phase 1b: pipeline narrative Act node.
|
|
118
|
+
Act: 'actId',
|
|
119
|
+
Scene: 'sceneId',
|
|
120
|
+
PlotBeat: 'beatId',
|
|
121
|
+
CharacterArc: 'arcId',
|
|
122
|
+
// M7 Phase 4: pipeline SourceDoc node.
|
|
123
|
+
SourceDoc: 'docId',
|
|
124
|
+
// M7 Phase 5: pipeline-only Persona node.
|
|
125
|
+
Persona: 'personaId',
|
|
41
126
|
});
|
|
42
127
|
for (const label of GRAPH_NODE_LABELS) {
|
|
43
128
|
expect(GRAPH_PRIMARY_KEY[label]).toBeDefined();
|
|
@@ -48,11 +133,21 @@ describe('graphSchema — node + relationship vocabulary', () => {
|
|
|
48
133
|
// Order-insensitive: the Python source is a frozenset (unordered), so the
|
|
49
134
|
// TS arrays carry no ordering contract — compare as sorted sets.
|
|
50
135
|
const expected: Record<string, string[]> = {
|
|
51
|
-
Video
|
|
136
|
+
// M7 Phase 1b added `themes` to the editable Video narrative props.
|
|
137
|
+
Video: ['fileName', 'episodeTitle', 'themes'],
|
|
52
138
|
Shot: ['caption'],
|
|
53
139
|
Entity: ['name', 'type'],
|
|
54
140
|
Event: ['label', 'category'],
|
|
55
141
|
DialogLine: ['text', 'speaker'],
|
|
142
|
+
// M7 Phase 1b: Act title/summary editable.
|
|
143
|
+
Act: ['title', 'summary'],
|
|
144
|
+
Scene: ['title', 'summary'],
|
|
145
|
+
PlotBeat: ['label', 'summary'],
|
|
146
|
+
CharacterArc: ['label', 'summary'],
|
|
147
|
+
// M7 Phase 4: only the SourceDoc title is editable.
|
|
148
|
+
SourceDoc: ['title'],
|
|
149
|
+
// M7 Phase 5: Persona is pipeline-only — never editable, no props.
|
|
150
|
+
Persona: [],
|
|
56
151
|
};
|
|
57
152
|
const actualKeys = Object.keys(GRAPH_EDITABLE_NODE_PROPERTIES).sort();
|
|
58
153
|
expect(actualKeys).toEqual(Object.keys(expected).sort());
|
|
@@ -65,6 +160,46 @@ describe('graphSchema — node + relationship vocabulary', () => {
|
|
|
65
160
|
});
|
|
66
161
|
});
|
|
67
162
|
|
|
163
|
+
describe('graphSchema — M7 P3a user-creation vocabulary', () => {
|
|
164
|
+
it('exposes exactly the three user-creatable node labels (excludes Act/Video/Shot)', () => {
|
|
165
|
+
expect([...userCreatableLabels].sort()).toEqual(
|
|
166
|
+
['CharacterArc', 'PlotBeat', 'Scene'].sort(),
|
|
167
|
+
);
|
|
168
|
+
// Pipeline-only labels are never creatable.
|
|
169
|
+
const creatable = new Set<string>(userCreatableLabels);
|
|
170
|
+
for (const pipelineLabel of ['Video', 'Shot', 'Entity', 'Event', 'DialogLine']) {
|
|
171
|
+
expect(creatable.has(pipelineLabel)).toBe(false);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('exposes exactly the six user-creatable edges (excludes pipeline edges)', () => {
|
|
176
|
+
expect([...userCreatableEdges].sort()).toEqual(
|
|
177
|
+
['CAUSES', 'FEATURES', 'LEADS_TO', 'ON_ARC', 'RELATES_TO', 'SET_IN'].sort(),
|
|
178
|
+
);
|
|
179
|
+
const creatable = new Set<string>(userCreatableEdges);
|
|
180
|
+
for (const pipelineEdge of ['CONTAINS', 'INCLUDES', 'MENTIONS', 'HAS_SHOT', 'HAS_ACT']) {
|
|
181
|
+
expect(creatable.has(pipelineEdge)).toBe(false);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('mirrors the backend _VALID_EDGE_PAIRS exactly', () => {
|
|
186
|
+
// Compile-time mirror of shared/graph_schema.py:_VALID_EDGE_PAIRS. Keep in
|
|
187
|
+
// lockstep with the Python test that locks the same table.
|
|
188
|
+
expect(allowedPairs).toEqual({
|
|
189
|
+
RELATES_TO: [['Entity', 'Entity']],
|
|
190
|
+
CAUSES: [['Event', 'Event']],
|
|
191
|
+
SET_IN: [['Scene', 'Entity']],
|
|
192
|
+
FEATURES: [['Scene', 'Entity']],
|
|
193
|
+
ON_ARC: [['PlotBeat', 'CharacterArc']],
|
|
194
|
+
LEADS_TO: [['PlotBeat', 'PlotBeat']],
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('keys allowedPairs by exactly the user-creatable edges', () => {
|
|
199
|
+
expect(Object.keys(allowedPairs).sort()).toEqual([...userCreatableEdges].sort());
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
68
203
|
describe('graphSchema — two separate provenance unions', () => {
|
|
69
204
|
it('story-graph provenance values are exact', () => {
|
|
70
205
|
expect([...STORY_GRAPH_PROVENANCE_VALUES].sort()).toEqual(
|
|
@@ -88,12 +223,12 @@ describe('graphSchema — two separate provenance unions', () => {
|
|
|
88
223
|
});
|
|
89
224
|
|
|
90
225
|
it('type-checks the unions (compile-time assertions)', () => {
|
|
91
|
-
const label: GraphNodeLabel = '
|
|
92
|
-
const rel: GraphRelationshipType = '
|
|
226
|
+
const label: GraphNodeLabel = 'Scene';
|
|
227
|
+
const rel: GraphRelationshipType = 'RELATES_TO';
|
|
93
228
|
const sp: StoryGraphProvenance = 'pegasus';
|
|
94
229
|
const mp: MemoryFactProvenance = 'chat';
|
|
95
|
-
expect(label).toBe('
|
|
96
|
-
expect(rel).toBe('
|
|
230
|
+
expect(label).toBe('Scene');
|
|
231
|
+
expect(rel).toBe('RELATES_TO');
|
|
97
232
|
expect(sp).toBe('pegasus');
|
|
98
233
|
expect(mp).toBe('chat');
|
|
99
234
|
});
|
|
@@ -115,3 +250,77 @@ describe('graphSchema — two separate provenance unions', () => {
|
|
|
115
250
|
expect(isMemoryFactProvenance('nope')).toBe(false);
|
|
116
251
|
});
|
|
117
252
|
});
|
|
253
|
+
|
|
254
|
+
describe('fetchGraphSchema — session-scoped memoized fetch', () => {
|
|
255
|
+
const buildSchema = (): GraphSchemaResponse => ({
|
|
256
|
+
traceId: 'trace-schema-1',
|
|
257
|
+
labels: {
|
|
258
|
+
Video: { pk: 'videoId', editable: ['episodeTitle', 'fileName'] },
|
|
259
|
+
Shot: { pk: 'shotId', editable: ['caption'] },
|
|
260
|
+
Entity: { pk: 'entityId', editable: ['name', 'type'] },
|
|
261
|
+
Event: { pk: 'eventId', editable: ['category', 'label'] },
|
|
262
|
+
DialogLine: { pk: 'dialogId', editable: ['speaker', 'text'] },
|
|
263
|
+
},
|
|
264
|
+
edges: {
|
|
265
|
+
MENTIONS: { editable: ['confidence'] },
|
|
266
|
+
HAS_SHOT: { editable: ['confidence'] },
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
/** Minimal client surface the wrapper depends on. */
|
|
271
|
+
const makeFakeClient = (
|
|
272
|
+
impl: () => Promise<GraphSchemaResponse>,
|
|
273
|
+
): { getGraphSchema: jest.Mock<Promise<GraphSchemaResponse>, []> } => ({
|
|
274
|
+
getGraphSchema: jest.fn(impl),
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
beforeEach(() => {
|
|
278
|
+
__resetGraphSchemaCache();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
afterEach(() => {
|
|
282
|
+
__resetGraphSchemaCache();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('calls the client exactly once across multiple awaits (cache hit)', async () => {
|
|
286
|
+
const client = makeFakeClient(async () => buildSchema());
|
|
287
|
+
|
|
288
|
+
const first = await fetchGraphSchema(client);
|
|
289
|
+
const second = await fetchGraphSchema(client);
|
|
290
|
+
const third = await fetchGraphSchema(client);
|
|
291
|
+
|
|
292
|
+
expect(client.getGraphSchema).toHaveBeenCalledTimes(1);
|
|
293
|
+
expect(first).toEqual(buildSchema());
|
|
294
|
+
// Same memoized object identity is returned each call.
|
|
295
|
+
expect(second).toBe(first);
|
|
296
|
+
expect(third).toBe(first);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('dedupes concurrent in-flight calls into a single fetch', async () => {
|
|
300
|
+
const client = makeFakeClient(async () => buildSchema());
|
|
301
|
+
|
|
302
|
+
const [a, b] = await Promise.all([
|
|
303
|
+
fetchGraphSchema(client),
|
|
304
|
+
fetchGraphSchema(client),
|
|
305
|
+
]);
|
|
306
|
+
|
|
307
|
+
expect(client.getGraphSchema).toHaveBeenCalledTimes(1);
|
|
308
|
+
expect(a).toBe(b);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('resets the cache on rejection so a subsequent call refetches', async () => {
|
|
312
|
+
const failing = makeFakeClient(async () => {
|
|
313
|
+
throw new Error('schema fetch failed');
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
await expect(fetchGraphSchema(failing)).rejects.toThrow('schema fetch failed');
|
|
317
|
+
expect(failing.getGraphSchema).toHaveBeenCalledTimes(1);
|
|
318
|
+
|
|
319
|
+
// A failed fetch must NOT poison the cache — the next call retries.
|
|
320
|
+
const succeeding = makeFakeClient(async () => buildSchema());
|
|
321
|
+
const result = await fetchGraphSchema(succeeding);
|
|
322
|
+
|
|
323
|
+
expect(succeeding.getGraphSchema).toHaveBeenCalledTimes(1);
|
|
324
|
+
expect(result).toEqual(buildSchema());
|
|
325
|
+
});
|
|
326
|
+
});
|