@nodaro/shared 3.21.0 → 3.23.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.
Files changed (84) hide show
  1. package/dist/index.cjs +2284 -195
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1915 -75
  4. package/dist/index.d.ts +1915 -75
  5. package/dist/index.js +2117 -196
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/add-captions-plan.test.ts +33 -0
  9. package/src/__tests__/caption-plan-parse.test.ts +23 -0
  10. package/src/__tests__/caption-segment-schema.test.ts +30 -0
  11. package/src/__tests__/collections.test.ts +253 -0
  12. package/src/__tests__/dialogue-capabilities.test.ts +157 -0
  13. package/src/__tests__/edit-plan-review.test.ts +70 -0
  14. package/src/__tests__/edl-clocks.test.ts +97 -0
  15. package/src/__tests__/edl.test.ts +34 -0
  16. package/src/__tests__/execution-outcome.test.ts +44 -0
  17. package/src/__tests__/fan-out-meta.test.ts +23 -0
  18. package/src/__tests__/fan-out-rows.test.ts +36 -0
  19. package/src/__tests__/fan-out-url-item.test.ts +44 -0
  20. package/src/__tests__/fixtures/speaker-tracks.fixtures.json +622 -0
  21. package/src/__tests__/input-field-extra-keys.test.ts +34 -0
  22. package/src/__tests__/list-consumers-fan-in.test.ts +40 -0
  23. package/src/__tests__/model-tree.test.ts +7 -0
  24. package/src/__tests__/node-pass-through.test.ts +23 -0
  25. package/src/__tests__/node-runtime-keys.test.ts +1 -0
  26. package/src/__tests__/picker-restrictions.test.ts +36 -0
  27. package/src/__tests__/preview-gate.test.ts +305 -0
  28. package/src/__tests__/render-basis.test.ts +176 -0
  29. package/src/__tests__/render-nodes.test.ts +73 -0
  30. package/src/__tests__/render-output.test.ts +392 -0
  31. package/src/__tests__/run-continuation.test.ts +32 -0
  32. package/src/__tests__/speaker-tracks.test.ts +474 -0
  33. package/src/__tests__/speech-pricing.test.ts +69 -0
  34. package/src/__tests__/telegram-channel.test.ts +91 -0
  35. package/src/__tests__/tts-capabilities.test.ts +81 -4
  36. package/src/__tests__/tts-neighbour-text.test.ts +19 -0
  37. package/src/__tests__/ugc-call-body.test.ts +38 -0
  38. package/src/__tests__/ugc-run-state.test.ts +68 -0
  39. package/src/__tests__/video-character-refs.test.ts +213 -0
  40. package/src/__tests__/video-overlay-layer-plan.test.ts +94 -0
  41. package/src/add-captions-plan.ts +50 -0
  42. package/src/caption-plan.ts +45 -0
  43. package/src/caption-segment-schema.ts +82 -0
  44. package/src/collections.ts +462 -0
  45. package/src/competitors.ts +77 -0
  46. package/src/credit-estimators/index.ts +9 -0
  47. package/src/credit-estimators/speech.ts +51 -0
  48. package/src/dialogue-capabilities.ts +48 -0
  49. package/src/edit-plan-contract.ts +20 -9
  50. package/src/edit-plan-review.ts +40 -1
  51. package/src/edl.ts +27 -1
  52. package/src/execution-outcome.ts +41 -0
  53. package/src/fan-out-meta.ts +23 -0
  54. package/src/fan-out-rows.ts +74 -5
  55. package/src/gemini-omni-voices.ts +59 -0
  56. package/src/handle-aliases.ts +295 -0
  57. package/src/i18n/camera-motions.pt-BR.ts +14 -14
  58. package/src/i18n/transitions.pt-BR.ts +13 -13
  59. package/src/index.ts +179 -1
  60. package/src/model-catalog.ts +122 -13
  61. package/src/model-constants.ts +24 -4
  62. package/src/model-tree.ts +5 -1
  63. package/src/node-execution-state.ts +13 -0
  64. package/src/node-mappable-fields.ts +7 -1
  65. package/src/node-pass-through.ts +37 -0
  66. package/src/node-runtime-keys.ts +14 -0
  67. package/src/picker-restrictions.ts +49 -0
  68. package/src/presentation-types.ts +26 -2
  69. package/src/presentation-utils.ts +25 -7
  70. package/src/preview-gate.ts +279 -0
  71. package/src/producer-types.ts +58 -0
  72. package/src/render-final.ts +20 -0
  73. package/src/render-nodes.ts +92 -0
  74. package/src/render-output.ts +565 -0
  75. package/src/run-continuation.ts +39 -0
  76. package/src/speaker-tracks.ts +638 -0
  77. package/src/telegram-channel.ts +140 -0
  78. package/src/transcribe-preflight.ts +8 -4
  79. package/src/tts-capabilities.ts +19 -5
  80. package/src/tts-neighbour-text.ts +46 -0
  81. package/src/ugc-call-body.ts +86 -0
  82. package/src/ugc-run-state.ts +64 -0
  83. package/src/video-character-refs.ts +233 -0
  84. package/src/video-overlay.ts +78 -21
@@ -0,0 +1,73 @@
1
+ import { describe, it, expect } from "vitest"
2
+ // Through the package index: the registry is the surface both engines and the
3
+ // editor read "is this a render, and how does it behave?" from (SV18).
4
+ import {
5
+ RENDER_NODE_TYPES,
6
+ RENDER_NODE_TYPE_IDS,
7
+ OWNER_ONLY_LISTING_RENDER_TYPES,
8
+ PREVIEW_RENDER_NODE_TYPES,
9
+ applyEdlCreditId,
10
+ isRenderNodeType,
11
+ renderNodeOf,
12
+ rendersLatestBatch,
13
+ rendersTranscriptJson,
14
+ } from "../index.js"
15
+
16
+ describe("RENDER_NODE_TYPES — one render-node registry (SV18)", () => {
17
+ it("holds Apply EDL, and only it, until Speaker View registers", () => {
18
+ expect(Object.keys(RENDER_NODE_TYPES)).toEqual(["apply-edl"])
19
+ expect(RENDER_NODE_TYPE_IDS).toEqual(["apply-edl"])
20
+ })
21
+
22
+ it("describes Apply EDL exactly as its hard-coded sites behaved", () => {
23
+ const d = renderNodeOf("apply-edl")!
24
+ expect(d).toBeDefined()
25
+ expect(d.clockMapFrom).toBe("input")
26
+ expect(d.ownerOnlyListing).toBe(true)
27
+ expect(d.latestBatch).toBe(true)
28
+ expect(d.jsonKind).toBe("transcript")
29
+ })
30
+
31
+ it("prices through the existing credit-id function, for any quality and output", () => {
32
+ const d = renderNodeOf("apply-edl")!
33
+ for (const quality of ["proxy", "final", undefined, null, "", "high", 3]) {
34
+ for (const output of ["video", "audio", undefined]) {
35
+ expect(d.creditId(quality, output)).toBe(applyEdlCreditId(quality))
36
+ }
37
+ }
38
+ })
39
+
40
+ it("reads the medium the order asks for: its `output`, video when absent", () => {
41
+ const d = renderNodeOf("apply-edl")!
42
+ expect(d.mediumOf({ output: "audio" })).toBe("audio")
43
+ expect(d.mediumOf({ output: "video" })).toBe("video")
44
+ expect(d.mediumOf({})).toBe("video")
45
+ expect(d.mediumOf({ output: "AUDIO" })).toBe("video")
46
+ })
47
+
48
+ it("answers membership by own key only (no prototype keys, no non-strings)", () => {
49
+ expect(isRenderNodeType("apply-edl")).toBe(true)
50
+ for (const t of ["camera-switch", "edit-plan", "apply-edl:proxy", "", "constructor", "__proto__", "toString"]) {
51
+ expect(isRenderNodeType(t)).toBe(false)
52
+ expect(renderNodeOf(t)).toBeUndefined()
53
+ }
54
+ for (const t of [undefined, null, 1, {}]) expect(isRenderNodeType(t)).toBe(false)
55
+ })
56
+
57
+ it("derives every per-behaviour set from the descriptors", () => {
58
+ const ids = Object.keys(RENDER_NODE_TYPES)
59
+ expect([...PREVIEW_RENDER_NODE_TYPES].sort()).toEqual([...ids].sort())
60
+ expect([...OWNER_ONLY_LISTING_RENDER_TYPES].sort()).toEqual(ids.filter((t) => RENDER_NODE_TYPES[t]!.ownerOnlyListing).sort())
61
+ for (const t of ids) {
62
+ expect(rendersLatestBatch(t)).toBe(RENDER_NODE_TYPES[t]!.latestBatch)
63
+ expect(rendersTranscriptJson(t)).toBe(RENDER_NODE_TYPES[t]!.jsonKind === "transcript")
64
+ }
65
+ expect(rendersLatestBatch("camera-switch")).toBe(false)
66
+ expect(rendersTranscriptJson("transcribe")).toBe(false)
67
+ })
68
+
69
+ it("is frozen: no consumer can register a render at run time", () => {
70
+ expect(Object.isFrozen(RENDER_NODE_TYPES)).toBe(true)
71
+ for (const d of Object.values(RENDER_NODE_TYPES)) expect(Object.isFrozen(d)).toBe(true)
72
+ })
73
+ })
@@ -0,0 +1,392 @@
1
+ import { describe, it, expect } from "vitest"
2
+ // Through the package index: both engines and SDK users read a saved render
3
+ // through these.
4
+ import {
5
+ edlSpanKey,
6
+ planClipKeyAt,
7
+ renderClipKey,
8
+ renderPlanClipKey,
9
+ renderPlanNodeId,
10
+ renderPlanPath,
11
+ renderPlanRowClipKeys,
12
+ renderResultStamp,
13
+ renderRunQuality,
14
+ renderSentRowStamps,
15
+ savedRenderBatch,
16
+ savedRenderBatchUrls,
17
+ savedRenderOutput,
18
+ } from "../index.js"
19
+
20
+ const take = (url: string, extra: Record<string, unknown> = {}) => ({ url, jobId: `job-${url}`, timestamp: "2026-10-05T00:00:00.000Z", ...extra })
21
+
22
+ describe("renderResultStamp — what a finished render says about itself", () => {
23
+ it("keeps a known quality and a non-empty clip key", () => {
24
+ expect(renderResultStamp({ videoUrl: "v", quality: "proxy", clipKey: "1000-9000" })).toEqual({ quality: "proxy", clipKey: "1000-9000" })
25
+ expect(renderResultStamp({ quality: "final" })).toEqual({ quality: "final" })
26
+ })
27
+
28
+ it("drops anything that is not one of the two qualities, and an empty or non-string key", () => {
29
+ expect(renderResultStamp({ quality: "PROXY", clipKey: "" })).toEqual({})
30
+ expect(renderResultStamp({ quality: "high", clipKey: 12 })).toEqual({})
31
+ expect(renderResultStamp(undefined)).toEqual({})
32
+ expect(renderResultStamp(null)).toEqual({})
33
+ })
34
+ })
35
+
36
+ describe("savedRenderOutput — the one result a saved render hands on", () => {
37
+ it("is the active result, routed by the node's output", () => {
38
+ const data = {
39
+ output: "video",
40
+ generatedResults: [take("new", { quality: "proxy" }), take("old", { quality: "final", thumbnailUrl: "t-old" })],
41
+ activeResultIndex: 1,
42
+ generatedVideoUrl: "old",
43
+ }
44
+ expect(savedRenderOutput(data)).toEqual({
45
+ url: "old", medium: "video", jobId: "job-old", thumbnailUrl: "t-old", quality: "final",
46
+ })
47
+ })
48
+
49
+ it("an audio render is an audio result", () => {
50
+ const data = { output: "audio", generatedResults: [take("a1")], generatedAudioUrl: "a1" }
51
+ expect(savedRenderOutput(data)).toMatchObject({ url: "a1", medium: "audio" })
52
+ })
53
+
54
+ it("repairs a pick saved before the results gallery wrote the right field: the picked take wins", () => {
55
+ // The gallery wrote the picked take to generatedImageUrl and left
56
+ // generatedVideoUrl on the newest one; activeResultIndex names the pick.
57
+ const data = {
58
+ generatedResults: [take("newest"), take("picked")],
59
+ activeResultIndex: 1,
60
+ generatedVideoUrl: "newest",
61
+ generatedImageUrl: "picked",
62
+ }
63
+ expect(savedRenderOutput(data)?.url).toBe("picked")
64
+ })
65
+
66
+ it("falls back to the saved field of the node's medium, then the other one", () => {
67
+ expect(savedRenderOutput({ generatedVideoUrl: "v" })).toEqual({ url: "v", medium: "video" })
68
+ expect(savedRenderOutput({ output: "audio", generatedAudioUrl: "a", generatedVideoUrl: "v" })).toEqual({ url: "a", medium: "audio" })
69
+ expect(savedRenderOutput({ output: "audio", generatedVideoUrl: "v" })).toEqual({ url: "v", medium: "video" })
70
+ expect(savedRenderOutput({ generatedAudioUrl: "a" })).toEqual({ url: "a", medium: "audio" })
71
+ })
72
+
73
+ it("an out-of-range index reads the first result, and nothing saved is undefined", () => {
74
+ expect(savedRenderOutput({ generatedResults: [take("only")], activeResultIndex: 7 })?.url).toBe("only")
75
+ expect(savedRenderOutput({})).toBeUndefined()
76
+ expect(savedRenderOutput({ generatedResults: [] })).toBeUndefined()
77
+ })
78
+ })
79
+
80
+ describe("savedRenderBatch — the LATEST batch a saved render hands an each edge (TA6)", () => {
81
+ // History: a preview batch (the newest run) on top of a final batch, with the
82
+ // active result toggled back to a final take.
83
+ const data = {
84
+ output: "video",
85
+ generatedResults: [
86
+ take("p0", { quality: "proxy", clipKey: "0-1000" }),
87
+ take("p2", { quality: "proxy", clipKey: "4000-5000" }),
88
+ take("f0", { quality: "final", clipKey: "0-1000" }),
89
+ take("f1", { quality: "final", clipKey: "2000-3000" }),
90
+ take("f2", { quality: "final", clipKey: "4000-5000" }),
91
+ ],
92
+ activeResultIndex: 3,
93
+ __listResults: ["p0", "", "p2"],
94
+ }
95
+
96
+ it("is the last batch, row-aligned (a failed row stays a hole), never the history", () => {
97
+ expect(savedRenderBatch(data)).toEqual([
98
+ { url: "p0", medium: "video", jobId: "job-p0", quality: "proxy", clipKey: "0-1000" },
99
+ null,
100
+ { url: "p2", medium: "video", jobId: "job-p2", quality: "proxy", clipKey: "4000-5000" },
101
+ ])
102
+ expect(savedRenderBatchUrls(data)).toEqual(["p0", "", "p2"])
103
+ })
104
+
105
+ it("does not follow the toggled active result — that is the scalar's", () => {
106
+ expect(savedRenderOutput(data)?.url).toBe("f1")
107
+ })
108
+
109
+ it("a render that ran once has no batch (an each edge then reads the one result)", () => {
110
+ expect(savedRenderBatch({ generatedResults: [take("a"), take("b")] })).toBeUndefined()
111
+ expect(savedRenderBatch({ __listResults: [] })).toBeUndefined()
112
+ expect(savedRenderBatchUrls({ __listResults: ["", ""] })).toEqual(["", ""])
113
+ })
114
+
115
+ it("a batch URL with no result entry still lists, with nothing stamped", () => {
116
+ expect(savedRenderBatch({ output: "audio", __listResults: ["x"] })).toEqual([{ url: "x", medium: "audio" }])
117
+ })
118
+ })
119
+
120
+ describe("edlSpanKey / planClipKeyAt — a plan clip's identity", () => {
121
+ const clip = (segments: Array<[number, number]>) => ({
122
+ version: 1, clock: "master", sources: [{ id: "s", url: "u", kind: "video" }],
123
+ segments: segments.map(([inMs, outMs], i) => ({ id: `seg-${i}`, inMs, outMs, video: "s" })),
124
+ })
125
+
126
+ it("is the outer span of the clip's kept segments on the master clock", () => {
127
+ expect(edlSpanKey(clip([[5000, 9000], [1200, 3000], [12000, 15000.4]]))).toBe("1200-15000")
128
+ })
129
+
130
+ it("is undefined for something that is not an EDL with segments", () => {
131
+ expect(edlSpanKey(clip([]))).toBeUndefined()
132
+ expect(edlSpanKey("nope")).toBeUndefined()
133
+ expect(edlSpanKey(null)).toBeUndefined()
134
+ })
135
+
136
+ it("reads a clips plan's row (objects or JSON strings), and nothing for a single-EDL plan", () => {
137
+ const plan = [clip([[0, 1000]]), JSON.stringify(clip([[2000, 3000]]))]
138
+ expect(planClipKeyAt(plan, 0)).toBe("0-1000")
139
+ expect(planClipKeyAt(plan, 1)).toBe("2000-3000")
140
+ expect(planClipKeyAt(plan, 2)).toBeUndefined()
141
+ expect(planClipKeyAt(clip([[0, 1000]]), 0)).toBeUndefined()
142
+ expect(planClipKeyAt(["", "{bad"], 1)).toBeUndefined()
143
+ })
144
+ })
145
+
146
+ describe("renderPlanNodeId / renderClipKey — the plan clip a render iteration reads", () => {
147
+ const nodes = [
148
+ { id: "plan", type: "edit-plan" },
149
+ { id: "tp-send", type: "teleport-send" },
150
+ { id: "tp-recv", type: "teleport-receive" },
151
+ { id: "switch", type: "camera-switch" },
152
+ { id: "render", type: "apply-edl" },
153
+ { id: "other", type: "text-prompt" },
154
+ ]
155
+
156
+ it("walks the render's edl wire up through teleports and Camera Switch to the plan", () => {
157
+ const edges = [
158
+ { source: "plan", target: "tp-send", targetHandle: "in" },
159
+ { source: "tp-send", target: "tp-recv" },
160
+ { source: "tp-recv", target: "switch", targetHandle: "edl" },
161
+ { source: "other", target: "switch", targetHandle: "transcript" },
162
+ { source: "switch", target: "render", targetHandle: "edl" },
163
+ ]
164
+ expect(renderPlanNodeId("render", nodes, edges)).toBe("plan")
165
+ })
166
+
167
+ it("reads the LAST wire on the edl handle (both engines keep the last value)", () => {
168
+ const edges = [
169
+ { source: "other", target: "render", targetHandle: "edl" },
170
+ { source: "plan", target: "render", targetHandle: "edl" },
171
+ ]
172
+ expect(renderPlanNodeId("render", nodes, edges)).toBe("plan")
173
+ expect(renderPlanNodeId("render", nodes, [...edges].reverse())).toBeUndefined()
174
+ })
175
+
176
+ it("no plan upstream, or a loop, is undefined", () => {
177
+ expect(renderPlanNodeId("render", nodes, [])).toBeUndefined()
178
+ expect(renderPlanNodeId("render", nodes, [
179
+ { source: "tp-recv", target: "render", targetHandle: "edl" },
180
+ { source: "tp-send", target: "tp-recv" },
181
+ { source: "tp-recv", target: "tp-send" },
182
+ ])).toBeUndefined()
183
+ })
184
+
185
+ it("an iteration reads its row; a run of no row reads a one-clip plan's clip, and nothing of a larger one", () => {
186
+ const one = { version: 1, clock: "master", sources: [], segments: [{ id: "a", inMs: 10, outMs: 20 }] }
187
+ const two = { ...one, segments: [{ id: "b", inMs: 30, outMs: 40 }] }
188
+ expect(renderClipKey([one, two], 1)).toBe("30-40")
189
+ expect(renderClipKey([one], undefined)).toBe("10-20")
190
+ expect(renderClipKey([one, two], undefined)).toBeUndefined()
191
+ expect(renderClipKey(one, undefined)).toBeUndefined()
192
+ expect(renderClipKey(undefined, 0)).toBeUndefined()
193
+ })
194
+ })
195
+
196
+ describe("renderPlanClipKey — the clip a row reads is picked by every selector on the way", () => {
197
+ const span = (inMs: number, outMs: number) =>
198
+ JSON.stringify({ version: 1, clock: "master", sources: [], segments: [{ id: `s${inMs}`, inMs, outMs }] })
199
+ const PLAN = [span(0, 1000), span(2000, 3000), span(4000, 5000), span(6000, 7000)]
200
+ const nodes = [
201
+ { id: "plan", type: "edit-plan" },
202
+ { id: "tp-send", type: "teleport-send" },
203
+ { id: "tp-recv", type: "teleport-receive" },
204
+ { id: "switch", type: "camera-switch" },
205
+ { id: "render", type: "apply-edl" },
206
+ ]
207
+ const planList = () => PLAN
208
+ /** A render-only run (no pass-through node ran with it). */
209
+ const ranRender: ReadonlySet<string> = new Set(["render"])
210
+ const pick = (listExpression: string) => ({ selectorMode: "list" as const, listExpression })
211
+
212
+ it("a selector on the render's edl wire: row k is row k of the SELECTED clips, not of the plan", () => {
213
+ const edges = [{ source: "plan", sourceHandle: "edl", target: "render", targetHandle: "edl", data: pick("3,4") }]
214
+ expect(renderPlanClipKey("render", nodes, edges, planList, 0)).toBe("4000-5000")
215
+ expect(renderPlanClipKey("render", nodes, edges, planList, 1)).toBe("6000-7000")
216
+ })
217
+
218
+ it("a selector on the plan to Camera Switch wire: Camera Switch's row k is row k of ITS selected clips", () => {
219
+ const edges = [
220
+ { source: "plan", sourceHandle: "edl", target: "switch", targetHandle: "edl", data: { rangeFrom: "2", rangeTo: "last", rangeStep: 2 } },
221
+ { source: "switch", sourceHandle: "edl", target: "render", targetHandle: "edl" },
222
+ ]
223
+ expect(renderPlanClipKey("render", nodes, edges, planList, 0)).toBe("2000-3000")
224
+ expect(renderPlanClipKey("render", nodes, edges, planList, 1)).toBe("6000-7000")
225
+ })
226
+
227
+ it("both selectors compose, plan down to the render, and a teleport hands the consumer wire's selector on", () => {
228
+ const edges = [
229
+ { source: "plan", sourceHandle: "edl", target: "tp-send", targetHandle: "in" },
230
+ { source: "tp-send", target: "tp-recv" },
231
+ { source: "tp-recv", target: "switch", targetHandle: "edl", data: pick("2,3,4") },
232
+ { source: "switch", sourceHandle: "edl", target: "render", targetHandle: "edl", data: pick("2") },
233
+ ]
234
+ expect(renderPlanPath("render", nodes, edges)?.planId).toBe("plan")
235
+ expect(renderPlanClipKey("render", nodes, edges, planList, 0)).toBe("4000-5000")
236
+ })
237
+
238
+ it("renderPlanRowClipKeys keys every iteration of a fan-out by its list row, the key renderPlanClipKey gives that row", () => {
239
+ const edges = [{ source: "plan", sourceHandle: "edl", target: "render", targetHandle: "edl", data: pick("2,3,4") }]
240
+ const rows = [0, 1, 2]
241
+ expect(renderPlanRowClipKeys("render", nodes, edges, planList, rows, ranRender)).toEqual(["2000-3000", "4000-5000", "6000-7000"])
242
+ for (const row of rows) {
243
+ expect(renderPlanRowClipKeys("render", nodes, edges, planList, [row], ranRender)[0]).toBe(renderPlanClipKey("render", nodes, edges, planList, row))
244
+ }
245
+ // A dropped clip (a hole in the plan's list) has no iteration: the rows skip it.
246
+ const holed = [PLAN[0], "", PLAN[2], PLAN[3]]
247
+ const direct = [{ source: "plan", sourceHandle: "edl", target: "render", targetHandle: "edl" }]
248
+ expect(renderPlanRowClipKeys("render", nodes, direct, () => holed, [0, 2, 3], ranRender)).toEqual(["0-1000", "4000-5000", "6000-7000"])
249
+ })
250
+
251
+ it("renderPlanRowClipKeys names nothing for a render no Edit Plan feeds, one key slot per row", () => {
252
+ expect(renderPlanRowClipKeys("render", nodes, [], planList, [0, 1], ranRender)).toEqual([undefined, undefined])
253
+ })
254
+
255
+ // The same-run rule (renderPlanBasis): the switch's SAVED batch was made under
256
+ // the review as it was then. Here it ran with all four clips kept; the person
257
+ // has dropped clip 1 since, and only the render runs. Its rows are the four
258
+ // the switch saved, so the review as it is now (three kept clips) would key
259
+ // row 1, which cut clip 1, as clip 2 — and wrap row 3 onto clip 0.
260
+ it("renderPlanRowClipKeys behind a Camera Switch that did not run in this run names no row", () => {
261
+ const switched = [
262
+ { source: "plan", sourceHandle: "edl", target: "switch", targetHandle: "edl" },
263
+ { source: "switch", sourceHandle: "edl", target: "render", targetHandle: "edl" },
264
+ ]
265
+ const reviewedNow = () => [PLAN[0], "", PLAN[2], PLAN[3]]
266
+ const rows = [0, 1, 2, 3]
267
+ expect(renderPlanRowClipKeys("render", nodes, switched, reviewedNow, rows, ranRender)).toEqual([undefined, undefined, undefined, undefined])
268
+ // With the switch in the run, its batch is the review as it is now.
269
+ expect(renderPlanRowClipKeys("render", nodes, switched, reviewedNow, [0, 1, 2], new Set(["switch", "render"]))).toEqual([
270
+ "0-1000",
271
+ "4000-5000",
272
+ "6000-7000",
273
+ ])
274
+ })
275
+
276
+ it("renderSentRowStamps stamps every row with the run's quality, and its clip when the run names one", () => {
277
+ expect(renderSentRowStamps("proxy", ["0-1000", undefined])).toEqual([{ quality: "proxy", clipKey: "0-1000" }, { quality: "proxy" }])
278
+ expect(renderRunQuality({ quality: "proxy" })).toBe("proxy")
279
+ for (const data of [{ quality: "final" }, {}, { quality: "PROXY" }, undefined]) expect(renderRunQuality(data)).toBe("final")
280
+ })
281
+
282
+ it("a row past the clips starts over from the first, as both input resolvers read it", () => {
283
+ const one = [span(10, 20)]
284
+ const edges = [{ source: "plan", sourceHandle: "edl", target: "render", targetHandle: "edl" }]
285
+ expect(renderPlanClipKey("render", nodes, edges, () => one, 3)).toBe("10-20")
286
+ expect(renderClipKey(one, 2)).toBe("10-20")
287
+ })
288
+
289
+ // A wire that hands on ONE value names the clip that value is, as both input
290
+ // resolvers pick it (decided 2026-10-05). "last" is the UI's "Selected": the
291
+ // plan's own output, its FIRST clip — not the last clip of the list.
292
+ const wire = (data: Record<string, unknown>) => [{ source: "plan", sourceHandle: "edl", target: "render", targetHandle: "edl", data }]
293
+
294
+ it("a Selected (\"last\") wire from an Edit Plan names the plan's own output, its first clip", () => {
295
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "last" }), planList, undefined)).toBe("0-1000")
296
+ // A row another list drives does not index a wire that hands on one value.
297
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "last" }), planList, 1)).toBe("0-1000")
298
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "last" }), () => [PLAN[2]], 1)).toBe("4000-5000")
299
+ })
300
+
301
+ it("an item wire names the clip at its index; its range / list selector does not apply", () => {
302
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "item", itemIndex: "2" }), planList, undefined)).toBe("2000-3000")
303
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "item", itemIndex: "last" }), planList, undefined)).toBe("6000-7000")
304
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "item", itemIndex: "9" }), planList, undefined)).toBe("6000-7000")
305
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "item", itemIndex: "1", ...pick("3,4") }), planList, undefined)).toBe("0-1000")
306
+ // Legacy item:N — 0-based, past the end reads the first.
307
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "item:1" }), planList, undefined)).toBe("2000-3000")
308
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "item:9" }), planList, undefined)).toBe("0-1000")
309
+ })
310
+
311
+ it("an all wire names a clip only when its selector leaves exactly one", () => {
312
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "all", ...pick("3") }), planList, undefined)).toBe("4000-5000")
313
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "all", ...pick("3,4") }), planList, undefined)).toBeUndefined()
314
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "all" }), planList, undefined)).toBeUndefined()
315
+ })
316
+
317
+ it("a teleport hands the consumer wire's single pick on", () => {
318
+ const edges = [
319
+ { source: "plan", sourceHandle: "edl", target: "tp-send", targetHandle: "in" },
320
+ { source: "tp-send", target: "tp-recv" },
321
+ { source: "tp-recv", target: "render", targetHandle: "edl", data: { outputMode: "item", itemIndex: "3" } },
322
+ ]
323
+ expect(renderPlanClipKey("render", nodes, edges, planList, undefined)).toBe("4000-5000")
324
+ })
325
+
326
+ it("a single pick into Camera Switch names that clip on the render after it", () => {
327
+ const edges = [
328
+ { source: "plan", sourceHandle: "edl", target: "switch", targetHandle: "edl", data: { outputMode: "item", itemIndex: "4" } },
329
+ { source: "switch", sourceHandle: "edl", target: "render", targetHandle: "edl" },
330
+ ]
331
+ expect(renderPlanClipKey("render", nodes, edges, planList, undefined)).toBe("6000-7000")
332
+ })
333
+
334
+ it("a Selected wire out of a Camera Switch that ran per clip names no clip (the engines keep different clips)", () => {
335
+ const edges = [
336
+ { source: "plan", sourceHandle: "edl", target: "switch", targetHandle: "edl" },
337
+ { source: "switch", sourceHandle: "edl", target: "render", targetHandle: "edl", data: { outputMode: "last" } },
338
+ ]
339
+ expect(renderPlanClipKey("render", nodes, edges, planList, undefined)).toBeUndefined()
340
+ expect(renderPlanClipKey("render", nodes, edges, () => [PLAN[1]], undefined)).toBe("2000-3000")
341
+ })
342
+
343
+ it("no plan behind the edl wire stamps nothing", () => {
344
+ expect(renderPlanClipKey("render", nodes, [], planList, 0)).toBeUndefined()
345
+ })
346
+
347
+ // A person's review drops clips: the plan's list keeps its rows, with a hole
348
+ // ("" — or null) at each dropped clip (TA16). Clips may be objects as well as
349
+ // JSON text, so a hole is only "" / null, never "not a string".
350
+ describe("a plan with dropped clips", () => {
351
+ const clip = (inMs: number, outMs: number) => ({ version: 1, clock: "master", sources: [], segments: [{ id: `s${inMs}`, inMs, outMs }] })
352
+ const B = clip(2000, 3000)
353
+ const C = clip(4000, 5000)
354
+ const viaSwitch = (renderWire?: Record<string, unknown>) => [
355
+ { source: "plan", sourceHandle: "edl", target: "switch", targetHandle: "edl" },
356
+ { source: "switch", sourceHandle: "edl", target: "render", targetHandle: "edl", ...(renderWire ? { data: renderWire } : {}) },
357
+ ]
358
+
359
+ it("behind Camera Switch, row k is the k-th KEPT clip: the switch ran once per kept row and hands on its batch by iteration", () => {
360
+ for (const holes of [["", B, C], [null, B, C], ["", B, null, C], [" ", JSON.stringify(B), C]]) {
361
+ expect(renderPlanClipKey("render", nodes, viaSwitch(), () => holes, 0), JSON.stringify(holes)).toBe("2000-3000")
362
+ expect(renderPlanClipKey("render", nodes, viaSwitch(), () => holes, 1), JSON.stringify(holes)).toBe("4000-5000")
363
+ }
364
+ // The render's own selector picks from the switch's batch.
365
+ expect(renderPlanClipKey("render", nodes, viaSwitch(pick("2")), () => ["", B, C], 0)).toBe("4000-5000")
366
+ })
367
+
368
+ it("wired straight to the plan, a row is the plan's row, holes included", () => {
369
+ const edges = [{ source: "plan", sourceHandle: "edl", target: "render", targetHandle: "edl" }]
370
+ expect(renderPlanClipKey("render", nodes, edges, () => ["", B, C], 1)).toBe("2000-3000")
371
+ expect(renderPlanClipKey("render", nodes, edges, () => ["", B, C], 2)).toBe("4000-5000")
372
+ expect(renderPlanClipKey("render", nodes, edges, () => ["", B, C], 0)).toBeUndefined()
373
+ })
374
+
375
+ it("one kept clip: the render that runs once names it, straight from the plan or behind Camera Switch", () => {
376
+ const edges = [{ source: "plan", sourceHandle: "edl", target: "render", targetHandle: "edl" }]
377
+ expect(renderPlanClipKey("render", nodes, edges, () => ["", B, null], undefined)).toBe("2000-3000")
378
+ expect(renderPlanClipKey("render", nodes, viaSwitch(), () => ["", B, ""], undefined)).toBe("2000-3000")
379
+ expect(renderPlanClipKey("render", nodes, viaSwitch({ outputMode: "last" }), () => ["", B, ""], undefined)).toBe("2000-3000")
380
+ expect(renderPlanClipKey("render", nodes, edges, () => ["", null], undefined)).toBeUndefined()
381
+ })
382
+
383
+ it("a Selected wire from the plan names its first KEPT clip, as the scalar read hands it on", () => {
384
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "last" }), () => ["", B, C], undefined)).toBe("2000-3000")
385
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "last" }), () => [null, "", C], undefined)).toBe("4000-5000")
386
+ })
387
+
388
+ it("an item wire on a dropped clip names nothing (it hands on nothing)", () => {
389
+ expect(renderPlanClipKey("render", nodes, wire({ outputMode: "item", itemIndex: "1" }), () => ["", B, C], undefined)).toBeUndefined()
390
+ })
391
+ })
392
+ })
@@ -0,0 +1,32 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import {
3
+ CONTINUATION_NOT_COMPLETED,
4
+ CONTINUATION_NOT_FOUND,
5
+ CONTINUATION_SUBSET_REQUIRED,
6
+ CONTINUATION_VERSION_MISMATCH,
7
+ CONTINUATION_WORKFLOW_MISMATCH,
8
+ RUN_CONTINUATION_CODES,
9
+ } from "../index.js"
10
+
11
+ describe("run continuation refusal codes", () => {
12
+ it("are the stable strings clients branch on", () => {
13
+ expect(CONTINUATION_NOT_FOUND).toBe("continuation_not_found")
14
+ expect(CONTINUATION_WORKFLOW_MISMATCH).toBe("continuation_workflow_mismatch")
15
+ expect(CONTINUATION_VERSION_MISMATCH).toBe("continuation_version_mismatch")
16
+ expect(CONTINUATION_NOT_COMPLETED).toBe("continuation_not_completed")
17
+ expect(CONTINUATION_SUBSET_REQUIRED).toBe("continuation_subset_required")
18
+ })
19
+
20
+ it("lists every code once", () => {
21
+ expect(new Set(RUN_CONTINUATION_CODES).size).toBe(5)
22
+ expect([...RUN_CONTINUATION_CODES].sort()).toEqual(
23
+ [
24
+ CONTINUATION_NOT_COMPLETED,
25
+ CONTINUATION_NOT_FOUND,
26
+ CONTINUATION_SUBSET_REQUIRED,
27
+ CONTINUATION_VERSION_MISMATCH,
28
+ CONTINUATION_WORKFLOW_MISMATCH,
29
+ ].sort(),
30
+ )
31
+ })
32
+ })