@nodaro/shared 3.16.0 → 3.19.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.
@@ -0,0 +1,356 @@
1
+ import { describe, it, expect } from "vitest"
2
+
3
+ import {
4
+ STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS,
5
+ STUDIO_KEYFRAME_NODE_TRANSIENT_KEYS,
6
+ STUDIO_KEYFRAME_REVIEW_KEYS,
7
+ STUDIO_KEYFRAME_TRANSIENT_KEYS,
8
+ STUDIO_SEQUENCE_PLANNING_KEYS,
9
+ STUDIO_SEQUENCE_POLICY_KEYS,
10
+ STUDIO_SEQUENCE_UNIT_MANIFEST_KEYS,
11
+ STUDIO_SEQUENCE_UNIT_REVIEW_KEYS,
12
+ STUDIO_TAKE_SEQUENCE_KEYS,
13
+ stripStudioDraftSettings,
14
+ stripStudioDraftWorkflow,
15
+ stripStudioTakeVoiceRecords,
16
+ stripStudioTransientSettings,
17
+ } from "../studio-transient.js"
18
+
19
+ /**
20
+ * A LINKED (keyframe / sequence) production's owner state is the owner's
21
+ * (studio ruling T87). The studio codec's own view withholds it from every
22
+ * reader who is not the owner (`toProductionView`, `includeOwnerState:
23
+ * false`); these strips withhold these parts of it from the stored row:
24
+ *
25
+ * - `sequenceEndpoints` on a take's result row (a canvas node's
26
+ * `data.generatedResults`);
27
+ * - `requestManifest` on a unit result row (a unit video node's
28
+ * `data.sequenceUnitResults`);
29
+ * - `keyframePendingImages` on a keyframe image node's `data`;
30
+ * - `settings.studio.sequenceRecommendations`;
31
+ * - the entries of `settings.studio.sequenceGenerationPolicies` — EMPTIED to
32
+ * `{}`, because the reader requires the record on a production with takes;
33
+ * - `continuationAcceptance` on each sequence take's units;
34
+ * - `rejections` on each keyframe entry, and `waivedReason` inside its
35
+ * `acceptance`;
36
+ * - and, in the bin, a deleted keyframe's `pendingImages`, `rejections` and
37
+ * acceptance `waivedReason`.
38
+ *
39
+ * Everything else of a take or a frame stays: the strips drop keys, never
40
+ * rows. Part of it the codec refuses to read a production without — a take's
41
+ * `policy` and `compilation`, the unit result rows its takes select (pin, url
42
+ * and request hash), a frame plan's `id` / `label` / `revision` / `frame` /
43
+ * `requirements` and the result its preview names. The rest (a unit's other
44
+ * results, a frame's other history rows, the rest of its acceptance record,
45
+ * a waived check included) the reader can do without, and it stays too (see
46
+ * `STUDIO_SEQUENCE_PLANNING_KEYS`).
47
+ */
48
+
49
+ const NOW = "2026-09-08T12:00:00.000Z"
50
+ const PIN = (keyframeId: string, key: string) => ({ keyframeId, planRevision: 1, resultKey: key, jobId: key,
51
+ assetId: key, contentHash: "a".repeat(64), width: 10, height: 10 })
52
+ /** A linked clip's submitted endpoint pins. */
53
+ const PINS = { sequenceId: "zoom", sequenceRevision: 1, start: PIN("A", "frame-private-a"), end: PIN("B", "frame-private-b") }
54
+ const POLICY = { conditioning: "video-continue", clipLength: "max", boundaryPolicy: "outer-frames",
55
+ lockedBoundaryKeyframeIds: [], provider: "wan-3", resolution: "480p", aspectRatio: "16:9", referenceAssetIds: [] }
56
+ /** The owner's CURRENT preference for the sequence: set after the take was made with {@link POLICY}. */
57
+ const PREFERENCE = { ...POLICY, provider: "preference-private" }
58
+ const COMPILATION = { compilerVersion: "c1", capabilityFingerprint: "exact", renderPlanHash: "plan-1", ready: true, issues: [],
59
+ units: [{ id: "zoom:u0", coverage: [{ shotId: "AB", fromSec: 0, toSec: 4 }], outputDurationSec: 4, generationDurationSec: 4,
60
+ conditioning: "start-end", startKeyframeId: "A", endKeyframeId: "B", guidanceOnlyKeyframeIds: [], reused: false, prerequisites: [] }] }
61
+ const REVIEW = { resultKey: "result0", acceptedBy: "owner-actor-private", acceptedAt: NOW,
62
+ review: { composition: true, motion: true, subjects: true, continuity: true } }
63
+ const RECOMMENDATION = { id: "rec-1", createdAt: NOW, sequenceId: "zoom", authoringHash: "h1", capabilityFingerprint: "exact",
64
+ priorityHash: "p1", recommendation: { policy: POLICY, reasons: ["a private director reason"], assumptions: [] },
65
+ provenance: { source: "director", jobId: "job-private", analysisRevision: "rev-1", llmModel: "model-x" } }
66
+ /** A unit result's frozen request, as the host writes it when the result lands. */
67
+ const MANIFEST = { version: 1, coverage: [{ shotId: "AB", prompt: "a private compiled prompt" }],
68
+ media: ["https://r2/reference-private.png"], sourceSnapshots: [{ id: "AB", clipSlots: [{ prompt: "a private unsent slot" }] }] }
69
+ const PROVENANCE = { planRevision: 1, attemptId: "attempt-1", resolvedRequestHash: "b".repeat(64), referencePins: [], descriptionPins: [] }
70
+ /** An image run in flight on keyframe A. */
71
+ const FRAME_RUN = { jobId: "frame-run-private", startedAt: 5, frame: { prompt: "a private pending frame" }, provenance: PROVENANCE }
72
+ /** The owner sent one of A's results back for revision. */
73
+ const REJECTION = { result: PIN("A", "kf-a-2"), rejectedBy: "rejector-private", rejectedAt: NOW, reason: "a private rejection reason" }
74
+ const FRAME_RESULTS = [
75
+ { url: "https://r2/a1.png", jobId: "kf-a-1", pin: PIN("A", "kf-a-1"), provenance: PROVENANCE },
76
+ { url: "https://r2/a2.png", jobId: "kf-a-2", pin: PIN("A", "kf-a-2"), provenance: PROVENANCE },
77
+ ]
78
+
79
+ /** A linked scene's clip node; its take carries the pins. */
80
+ const clipNode = (pinned: boolean) => ({ id: "clip-AB", type: "generate-video", position: { x: 0, y: 0 }, data: { prompt: "Approach",
81
+ sequenceBinding: { sequenceId: "zoom", startKeyframeId: "A", endKeyframeId: "B", continuity: "continuous" },
82
+ generatedResults: [{ url: "https://r2/clip.mp4", jobId: "clip-1", ...(pinned ? { sequenceEndpoints: PINS } : {}) }] } })
83
+ /** Keyframe A's image node: its result history stays, its run in flight does not. */
84
+ const frameNode = (running: boolean) => ({ id: "frame-A", type: "generate-image", position: { x: -340, y: 0 }, data: {
85
+ label: "A", keyframeId: "A", requiredCapabilities: ["studio-dependent-frames-v1"], generatedResults: FRAME_RESULTS,
86
+ ...(running ? { keyframePendingImages: [FRAME_RUN] } : {}), activeResultIndex: 0 } })
87
+ /** The take's unit video node: its result row stays, the row's frozen request does not. */
88
+ const unitNode = (frozen: boolean) => ({ id: "owner0", type: "generate-video", position: { x: 680, y: 0 }, data: { sequenceUnitId: "zoom:u0",
89
+ sequenceUnitResults: [{ url: "https://r2/unit0.mp4", requestHash: "request-0",
90
+ pin: { unitId: "zoom:u0", resultKey: "result0", jobId: "result0", assetId: "asset-0", contentHash: "hash-0", durationSec: 4 },
91
+ ...(frozen ? { requestManifest: MANIFEST } : {}) }],
92
+ generatedVideoUrl: "https://r2/unit0.mp4", generatedResults: [{ videoUrl: "https://r2/unit0.mp4", jobId: "result0" }] } })
93
+
94
+ /** A linked production's nodes as the codec writes them. */
95
+ const linkedNodes = (): Array<Record<string, unknown>> => [clipNode(true), frameNode(true), unitNode(true)]
96
+ /** What a reader who is not the owner keeps of {@link linkedNodes}. */
97
+ const readerNodes = (): Array<Record<string, unknown>> => [clipNode(false), frameNode(false), unitNode(false)]
98
+
99
+ /** The owner waived keyframe A's one requirement when accepting it, and said why. */
100
+ const WAIVER = "a private waiver reason"
101
+ /** A's acceptance: the waived check stays, the owner's reason for it does not. */
102
+ const acceptance = (reasoned: boolean) => ({ result: PIN("A", "kf-a-1"), acceptedBy: "acceptor", acceptedAt: NOW,
103
+ requirementChecks: [{ requirementId: "req-1", outcome: "waived" }], ...(reasoned ? { waivedReason: WAIVER } : {}) })
104
+ /** Keyframe A's settings entry: its plan and acceptance stay, its review record and the acceptance's waiver reason do not. */
105
+ const frameEntry = (reviewed: boolean) => ({ imageNodeId: "frame-A",
106
+ plan: { id: "A", label: "A", revision: 1, frame: { prompt: "A" },
107
+ requirements: [{ id: "req-1", text: "Same window light", severity: "required" }] },
108
+ acceptance: acceptance(reviewed),
109
+ ...(reviewed ? { rejections: [REJECTION] } : {}) })
110
+ /** The take as the codec writes it — and, without `continuationAcceptance`, as a reader gets it. */
111
+ const take = (reviewed: boolean) => ({ id: "take1", sequenceId: "zoom", authoringHash: "h1", revision: 2, createdAt: NOW,
112
+ policy: POLICY, compilation: COMPILATION, units: [{ unitId: "zoom:u0", videoNodeId: "owner0", selectedResultKey: "result0",
113
+ ...(reviewed ? { continuationAcceptance: REVIEW } : {}) }] })
114
+
115
+ /** `settings.studio` of a linked production with a take, as the codec writes it. */
116
+ function linkedStudio(): Record<string, unknown> {
117
+ return {
118
+ version: 3,
119
+ shots: [{ id: "AB", sequenceBinding: { sequenceId: "zoom", startKeyframeId: "A", endKeyframeId: "B", continuity: "continuous" } }],
120
+ requiredCapabilities: ["studio-dependent-frames-v1", "studio-sequence-takes-v1"],
121
+ keyframes: [frameEntry(true)],
122
+ sequences: [{ id: "zoom", name: "Zoom", revision: 1, construction: "nested-zoom", shotIds: ["AB"] }],
123
+ sequenceGenerationPolicies: { zoom: PREFERENCE },
124
+ sequenceTakes: [take(true)],
125
+ sequenceUnitVideos: [{ videoNodeId: "owner0", unitId: "zoom:u0" }],
126
+ selectedSequenceTakeIds: { zoom: "take1" },
127
+ sequenceRecommendations: [RECOMMENDATION],
128
+ }
129
+ }
130
+
131
+ /** What a reader who is not the owner keeps of {@link linkedStudio}: all of it but the keys the strips drop, the preferences emptied. */
132
+ function readerStudio(): Record<string, unknown> {
133
+ const { sequenceRecommendations: _recommendations, ...studio } = linkedStudio()
134
+ return { ...studio, keyframes: [frameEntry(false)], sequenceGenerationPolicies: {}, sequenceTakes: [take(false)] }
135
+ }
136
+
137
+ const studioOf = (settings: unknown) => (settings as { studio: Record<string, unknown> }).studio
138
+ /** The owner's state on the nodes, and on the settings. */
139
+ const NODE_PRIVATE = ["frame-private-a", "a private compiled prompt", "reference-private", "a private unsent slot",
140
+ "frame-run-private", "a private pending frame"]
141
+ const SETTINGS_PRIVATE = ["a private director reason", "job-private", "owner-actor-private", "preference-private",
142
+ "rejector-private", "a private rejection reason", WAIVER]
143
+
144
+ /**
145
+ * Productions that each carry ONE kind of the settings' owner state and none
146
+ * of the others, so a strip that skips that kind cannot pass on another kind's
147
+ * account: [the kind, the stored studio, what a reader keeps, a marker only
148
+ * that kind carries].
149
+ */
150
+ const ONE_KIND: ReadonlyArray<readonly [string, () => Record<string, unknown>, () => Record<string, unknown>, string]> = [
151
+ ["the director's recommendations",
152
+ () => ({ version: 3, sequenceRecommendations: [RECOMMENDATION] }),
153
+ () => ({ version: 3 }), "a private director reason"],
154
+ ["the current preferences, before any take",
155
+ () => ({ version: 3, sequenceGenerationPolicies: { zoom: PREFERENCE }, sequenceTakes: [] }),
156
+ () => ({ version: 3, sequenceGenerationPolicies: {}, sequenceTakes: [] }), "preference-private"],
157
+ ["a take's continuation review",
158
+ () => ({ version: 3, sequenceGenerationPolicies: {}, sequenceTakes: [take(true)] }),
159
+ () => ({ version: 3, sequenceGenerationPolicies: {}, sequenceTakes: [take(false)] }), "owner-actor-private"],
160
+ ["a frame's rejections",
161
+ () => ({ version: 3, keyframes: [{ ...frameEntry(false), rejections: [REJECTION] }] }),
162
+ () => ({ version: 3, keyframes: [frameEntry(false)] }), "a private rejection reason"],
163
+ ["a frame's waiver reason",
164
+ () => ({ version: 3, keyframes: [{ ...frameEntry(false), acceptance: acceptance(true) }] }),
165
+ () => ({ version: 3, keyframes: [frameEntry(false)] }), WAIVER],
166
+ ]
167
+
168
+ describe("the T87 lists", () => {
169
+ it("name the owner-only keys at each of their levels", () => {
170
+ expect([...STUDIO_TAKE_SEQUENCE_KEYS]).toEqual(["sequenceEndpoints"])
171
+ expect([...STUDIO_SEQUENCE_UNIT_MANIFEST_KEYS]).toEqual(["requestManifest"])
172
+ expect([...STUDIO_KEYFRAME_NODE_TRANSIENT_KEYS]).toEqual(["keyframePendingImages"])
173
+ expect([...STUDIO_SEQUENCE_PLANNING_KEYS]).toEqual(["sequenceRecommendations"])
174
+ expect([...STUDIO_SEQUENCE_POLICY_KEYS]).toEqual(["sequenceGenerationPolicies"])
175
+ expect([...STUDIO_SEQUENCE_UNIT_REVIEW_KEYS]).toEqual(["continuationAcceptance"])
176
+ expect([...STUDIO_KEYFRAME_REVIEW_KEYS]).toEqual(["rejections"])
177
+ expect([...STUDIO_KEYFRAME_TRANSIENT_KEYS]).toEqual(["pendingImages"])
178
+ expect([...STUDIO_KEYFRAME_ACCEPTANCE_PRIVATE_KEYS]).toEqual(["waivedReason"])
179
+ })
180
+ })
181
+
182
+ describe("stripStudioTakeVoiceRecords — the owner's state on a linked production's nodes (T87)", () => {
183
+ it("drops a take's pins, a unit result's frozen request and a frame's runs, and keeps everything the codec reads", () => {
184
+ const stored = linkedNodes()
185
+ const out = stripStudioTakeVoiceRecords(stored)
186
+ expect(out).toEqual(readerNodes())
187
+ for (const secret of NODE_PRIVATE) expect(JSON.stringify(out)).not.toContain(secret)
188
+ // Copy-on-write.
189
+ expect(stored).toEqual(linkedNodes())
190
+ })
191
+
192
+ it("drops the pins and the voice record together off one row", () => {
193
+ const both = [{ id: "n1", data: { generatedResults: [{ url: "u", voiceMode: "auto", sequenceEndpoints: PINS }] } }]
194
+ expect(stripStudioTakeVoiceRecords(both)).toEqual([{ id: "n1", data: { generatedResults: [{ url: "u" }] } }])
195
+ })
196
+
197
+ it("drops a frame's runs off a node that has no result rows yet", () => {
198
+ const fresh = [{ id: "frame-B", data: { keyframeId: "B", keyframePendingImages: [FRAME_RUN] } }]
199
+ expect(stripStudioTakeVoiceRecords(fresh)).toEqual([{ id: "frame-B", data: { keyframeId: "B" } }])
200
+ })
201
+
202
+ it("hands back the SAME nodes, and the same node, when none carries any of it", () => {
203
+ const clean = readerNodes()
204
+ expect(stripStudioTakeVoiceRecords(clean)).toBe(clean)
205
+ const mixed = [clipNode(true), frameNode(false), unitNode(false)]
206
+ const out = stripStudioTakeVoiceRecords(mixed) as unknown[]
207
+ expect(out[1]).toBe(mixed[1])
208
+ expect(out[2]).toBe(mixed[2])
209
+ })
210
+
211
+ it("lets unit results it cannot read ride through", () => {
212
+ const odd = [{ id: "u", data: { sequenceUnitResults: "nope" } },
213
+ { id: "v", data: { sequenceUnitResults: [null, 4, { url: "u", requestManifest: MANIFEST }] } }]
214
+ const out = stripStudioTakeVoiceRecords(odd) as typeof odd
215
+ expect(out[0]).toBe(odd[0])
216
+ expect(out[1]!.data.sequenceUnitResults).toEqual([null, 4, { url: "u" }])
217
+ })
218
+ })
219
+
220
+ describe.each([
221
+ ["stripStudioDraftSettings (the `view` doors)", stripStudioDraftSettings],
222
+ ["stripStudioTransientSettings (the public share read of an ordinary production)", stripStudioTransientSettings],
223
+ ] as const)("%s — a linked production's owner state is the owner's (T87)", (_name, strip) => {
224
+ it("drops the recommendations, the reviews, the rejections and the waiver reason, empties the preferences, and keeps what the codec's reader requires", () => {
225
+ const stored = { studio: linkedStudio() }
226
+ const out = strip(stored)
227
+ expect(studioOf(out)).toEqual(readerStudio())
228
+ for (const secret of SETTINGS_PRIVATE) expect(JSON.stringify(out)).not.toContain(secret)
229
+ // The take keeps the policy it was made with; only the owner's newer preference goes.
230
+ expect((studioOf(out).sequenceTakes as Array<{ policy: unknown }>)[0]!.policy).toEqual(POLICY)
231
+ // The frame keeps its acceptance and the check it waived; only the owner's reason goes.
232
+ expect((studioOf(out).keyframes as Array<{ acceptance: unknown }>)[0]!.acceptance).toEqual(acceptance(false))
233
+ // Copy-on-write: the stored row keeps all of it.
234
+ expect(stored).toEqual({ studio: linkedStudio() })
235
+ })
236
+
237
+ it.each(ONE_KIND)("withholds %s when it is the only owner state the production carries", (_kind, stored, reader, marker) => {
238
+ const settings = { studio: stored() }
239
+ const out = strip(settings)
240
+ expect(studioOf(out)).toEqual(reader())
241
+ expect(JSON.stringify(out)).not.toContain(marker)
242
+ // Copy-on-write.
243
+ expect(settings).toEqual({ studio: stored() })
244
+ })
245
+
246
+ it("hands back the SAME settings when a linked production carries none of it", () => {
247
+ const clean = { studio: readerStudio() }
248
+ expect(strip(clean)).toBe(clean)
249
+ })
250
+
251
+ it("empties the preferences but never adds them, and lets a value it cannot read ride through", () => {
252
+ // The codec's reader takes the key alone for take state: a production
253
+ // without it must not gain it.
254
+ const { sequenceGenerationPolicies: _preferences, ...without } = linkedStudio()
255
+ expect(studioOf(strip({ studio: without }))).not.toHaveProperty("sequenceGenerationPolicies")
256
+ for (const odd of ["nope", 7, null, ["zoom"]]) {
257
+ const stored = { studio: { version: 3, sequenceGenerationPolicies: odd } }
258
+ expect(strip(stored)).toBe(stored)
259
+ }
260
+ })
261
+
262
+ it("keeps a take that has no review, and a frame that has no rejections or waiver reason, as the very same entries", () => {
263
+ const studio = linkedStudio()
264
+ const reviewed = (studio.sequenceTakes as Array<Record<string, unknown>>)[0]!
265
+ const unreviewed = { ...reviewed, id: "take0", units: [{ unitId: "zoom:u0", videoNodeId: "owner0" }] }
266
+ const unrejected = { imageNodeId: "frame-B", plan: { id: "B", label: "B", revision: 1, frame: { prompt: "B" }, requirements: [] },
267
+ acceptance: { result: PIN("B", "kf-b-1"), acceptedBy: "acceptor", acceptedAt: NOW, requirementChecks: [] } }
268
+ const out = studioOf(strip({ studio: { ...studio, sequenceTakes: [unreviewed, reviewed],
269
+ keyframes: [unrejected, ...(studio.keyframes as unknown[])] } }))
270
+ expect((out.sequenceTakes as unknown[])[0]).toBe(unreviewed)
271
+ expect((out.keyframes as unknown[])[0]).toBe(unrejected)
272
+ expect((out.keyframes as unknown[])[1]).toEqual(frameEntry(false))
273
+ })
274
+
275
+ it("lets a take or a frame list it cannot read ride through", () => {
276
+ const odd = [null, 7, "x", { id: "t" }, { id: "t2", units: "nope" }, { id: "t3", units: [null, 4, { unitId: "u", continuationAcceptance: REVIEW }] }]
277
+ const frames = [null, 7, "x", { imageNodeId: "f" }, { imageNodeId: "g", rejections: [REJECTION] },
278
+ { imageNodeId: "h", acceptance: "nope" }, { imageNodeId: "i", acceptance: null }]
279
+ const out = studioOf(strip({ studio: { version: 3, sequenceTakes: odd, keyframes: frames } }))
280
+ const takes = out.sequenceTakes as unknown[]
281
+ expect(takes.slice(0, 5)).toEqual(odd.slice(0, 5))
282
+ expect((takes[5] as { units: unknown[] }).units).toEqual([null, 4, { unitId: "u" }])
283
+ expect(out.keyframes).toEqual([null, 7, "x", { imageNodeId: "f" }, { imageNodeId: "g" },
284
+ { imageNodeId: "h", acceptance: "nope" }, { imageNodeId: "i", acceptance: null }])
285
+ const notAList = { studio: { version: 3, sequenceTakes: "nope", keyframes: "nope" } }
286
+ expect(strip(notAList)).toBe(notAList)
287
+ })
288
+ })
289
+
290
+ describe("stripStudioDraftSettings — the bin keeps the owner's deleted work, without the owner's state in it", () => {
291
+ /**
292
+ * A deleted take with its pins, a deleted frame with a run in flight, a
293
+ * review and a waiver reason, a deleted linked scene, and two deleted frames
294
+ * that each carry ONE of those: rejections alone, a waiver reason alone.
295
+ */
296
+ const bin = () => [
297
+ { kind: "clip", id: "t-clip", shotId: "AB", index: 0, deletedAt: NOW, clipBase: { nodeId: "clip-AB" },
298
+ result: { url: "https://r2/old.mp4", jobId: "clip-0", sequenceEndpoints: PINS } },
299
+ { kind: "keyframe", id: "t-frame", index: 1, deletedAt: NOW,
300
+ keyframe: { ...frameEntry(true), results: FRAME_RESULTS, pendingImages: [FRAME_RUN] } },
301
+ { kind: "shot", id: "t-shot", shotId: "AB", index: 0, deletedAt: NOW,
302
+ graph: { nodes: linkedNodes(), edges: [], settings: { studio: linkedStudio() } } },
303
+ { kind: "keyframe", id: "t-rejected", index: 2, deletedAt: NOW,
304
+ keyframe: { ...frameEntry(false), results: FRAME_RESULTS, rejections: [REJECTION] } },
305
+ { kind: "keyframe", id: "t-waived", index: 3, deletedAt: NOW,
306
+ keyframe: { ...frameEntry(false), results: FRAME_RESULTS, acceptance: acceptance(true) } },
307
+ ]
308
+
309
+ it("drops a deleted take's pins, a deleted frame's runs, review and waiver reason, and a deleted scene's owner state, and keeps the rest of each", () => {
310
+ const stored = { studio: { version: 3, trash: bin() } }
311
+ const trash = studioOf(stripStudioDraftSettings(stored)).trash as Array<Record<string, unknown>>
312
+ expect(trash.map((entry) => entry.id)).toEqual(["t-clip", "t-frame", "t-shot", "t-rejected", "t-waived"])
313
+ expect(trash[0]!.result).toEqual({ url: "https://r2/old.mp4", jobId: "clip-0" })
314
+ expect(trash[1]!.keyframe).toEqual({ ...frameEntry(false), results: FRAME_RESULTS })
315
+ const graph = trash[2]!.graph as { nodes: unknown; settings: unknown }
316
+ expect(graph.nodes).toEqual(readerNodes())
317
+ expect(studioOf(graph.settings)).toEqual(readerStudio())
318
+ expect(trash[3]!.keyframe).toEqual({ ...frameEntry(false), results: FRAME_RESULTS })
319
+ expect(trash[4]!.keyframe).toEqual({ ...frameEntry(false), results: FRAME_RESULTS })
320
+ for (const secret of [...NODE_PRIVATE, ...SETTINGS_PRIVATE]) expect(JSON.stringify(trash)).not.toContain(secret)
321
+ // Copy-on-write.
322
+ expect(stored).toEqual({ studio: { version: 3, trash: bin() } })
323
+ })
324
+
325
+ it("keeps a deleted frame that carries none of it as the very same bin", () => {
326
+ const quiet = { kind: "keyframe", id: "t-frame", index: 0, deletedAt: NOW, keyframe: { ...frameEntry(false), results: FRAME_RESULTS } }
327
+ const stored = { studio: { version: 3, trash: [quiet] } }
328
+ expect(stripStudioDraftSettings(stored)).toBe(stored)
329
+ })
330
+
331
+ it("lets a deleted frame it cannot read ride through", () => {
332
+ const odd = [{ kind: "keyframe", id: "t-null", keyframe: null }, { kind: "keyframe", id: "t-text", keyframe: "nope" },
333
+ { kind: "keyframe", id: "t-odd", keyframe: { imageNodeId: "f", acceptance: "nope" } }]
334
+ const stored = { studio: { version: 3, trash: odd } }
335
+ expect(stripStudioDraftSettings(stored)).toBe(stored)
336
+ })
337
+ })
338
+
339
+ describe("stripStudioDraftWorkflow — the one strip every `view` door applies", () => {
340
+ it("strips the owner's state off the nodes AND the settings, and keeps the rest of the row", () => {
341
+ const row = { id: "wf-1", name: "Film", edges: [{ id: "e1" }], nodes: linkedNodes(), settings: { studio: linkedStudio() } }
342
+ const out = stripStudioDraftWorkflow(row)
343
+ for (const secret of [...NODE_PRIVATE, ...SETTINGS_PRIVATE]) expect(JSON.stringify(out)).not.toContain(secret)
344
+ expect(out).toMatchObject({ id: "wf-1", name: "Film", edges: [{ id: "e1" }] })
345
+ expect(out.nodes).toEqual(readerNodes())
346
+ expect(studioOf(out.settings)).toEqual(readerStudio())
347
+ // Copy-on-write.
348
+ expect(row.nodes).toEqual(linkedNodes())
349
+ expect(row.settings).toEqual({ studio: linkedStudio() })
350
+ })
351
+
352
+ it("hands back the SAME row when a linked production carries none of it", () => {
353
+ const plain = { nodes: readerNodes(), settings: { studio: readerStudio() } }
354
+ expect(stripStudioDraftWorkflow(plain)).toBe(plain)
355
+ })
356
+ })
@@ -1,6 +1,7 @@
1
1
  import { describe, it, expect } from "vitest"
2
2
 
3
3
  import {
4
+ STUDIO_PREVIZ_RUN_STATE_KEYS,
4
5
  STUDIO_SHOT_DRAFT_KEYS,
5
6
  STUDIO_SHOT_TRANSIENT_KEYS,
6
7
  STUDIO_TRANSIENT_KEYS,
@@ -219,6 +220,37 @@ describe("stripStudioTransientSettings", () => {
219
220
  expect(stripStudioDraftSettings(null)).toBeNull()
220
221
  })
221
222
 
223
+ it("drops a scene's 3D run state — its jobs in flight and its Pro submission — and keeps its finished renders", () => {
224
+ // The studio codec's own non-owner projection (`stripTransientSettings`)
225
+ // drops these two; the public share read must not hand out what the
226
+ // codec withholds. The codec's fixture shape, plus a Pro submission.
227
+ const settings = { studio: { version: 3, shots: [{ id: "s1", previsualization: {
228
+ pendingJobs: [{ jobId: "private-job" }],
229
+ proSubmission: { idempotencyKey: "pro-key-1", body: { kind: "scene", sceneRevisionId: "rev-1" } },
230
+ renders: [{ url: "https://cdn/blockout.mp4" }],
231
+ pendingPlan: { revisionId: "rev-2" },
232
+ sceneNodeId: "scene-node",
233
+ } }] } }
234
+ const before = JSON.stringify(settings)
235
+ expect(stripStudioTransientSettings(settings)).toEqual({ studio: { version: 3, shots: [{ id: "s1", previsualization: {
236
+ renders: [{ url: "https://cdn/blockout.mp4" }],
237
+ pendingPlan: { revisionId: "rev-2" },
238
+ sceneNodeId: "scene-node",
239
+ } }] } })
240
+ expect(JSON.stringify(settings)).toBe(before)
241
+ // Each key on its own is enough to strip.
242
+ const proOnly = { studio: { shots: [{ id: "s1", previsualization: { proSubmission: { idempotencyKey: "k" } } }] } }
243
+ expect(stripStudioTransientSettings(proOnly)).toEqual({ studio: { shots: [{ id: "s1", previsualization: {} }] } })
244
+ // A scene with a previsualization and no run state is handed back as it is.
245
+ const idle = { studio: { shots: [{ id: "s1", previsualization: { renders: [{ url: "u" }] } }] } }
246
+ expect(stripStudioTransientSettings(idle)).toBe(idle)
247
+ })
248
+
249
+ it("a `view` read keeps a scene's 3D run state, as the codec's read-only load does", () => {
250
+ const settings = { studio: { shots: [{ id: "s1", previsualization: { pendingJobs: [{ jobId: "j" }], proSubmission: { idempotencyKey: "k" } } }] } }
251
+ expect(stripStudioDraftSettings(settings)).toBe(settings)
252
+ })
253
+
222
254
  it("pins the two lists — a key added to the type alone strips nothing", () => {
223
255
  // The lists are the contract: the codec's own strip re-exports them, so a
224
256
  // key that falls off here falls off there too, silently, on both sides.
@@ -238,5 +270,7 @@ describe("stripStudioTransientSettings", () => {
238
270
  // The owner's drafts are a list of their own: the export projection reads
239
271
  // the transient list, and the owner's exports keep their slots.
240
272
  expect([...STUDIO_SHOT_DRAFT_KEYS]).toEqual(["stillSlots", "clipSlots"])
273
+ // The 3D run state the codec's non-owner projection drops.
274
+ expect([...STUDIO_PREVIZ_RUN_STATE_KEYS]).toEqual(["pendingJobs", "proSubmission"])
241
275
  })
242
276
  })
@@ -0,0 +1,71 @@
1
+ import { describe, it, expect } from "vitest"
2
+ import {
3
+ TEXT_TO_AUDIO_PRICING,
4
+ TEXT_TO_AUDIO_SFX_CREDIT_IDS,
5
+ textToAudioBilledSeconds,
6
+ textToAudioCreditId,
7
+ } from "../credit-estimators/index.js"
8
+
9
+ describe("textToAudioBilledSeconds — whole seconds, rounded up", () => {
10
+ it.each([
11
+ [0.5, 1],
12
+ [1, 1],
13
+ [1.2, 2],
14
+ [10, 10],
15
+ [22, 22],
16
+ [22.3, 23],
17
+ [30, 30],
18
+ ])("%s s bills %i s", (duration, billed) => {
19
+ expect(textToAudioBilledSeconds(duration)).toBe(billed)
20
+ })
21
+
22
+ it.each([[undefined], [null], [0], [-3], [Number.NaN], [Number.POSITIVE_INFINITY], ["abc"], [""]])(
23
+ "no usable duration (%s) bills the default %i s",
24
+ (duration) => {
25
+ expect(textToAudioBilledSeconds(duration)).toBe(TEXT_TO_AUDIO_PRICING.DEFAULT_BILLED_SEC)
26
+ expect(TEXT_TO_AUDIO_PRICING.DEFAULT_BILLED_SEC).toBe(5)
27
+ },
28
+ )
29
+
30
+ it("reads a numeric string (a field mapping can deliver one)", () => {
31
+ expect(textToAudioBilledSeconds("7.5")).toBe(8)
32
+ })
33
+
34
+ it("never bills past the longest clip the model makes", () => {
35
+ expect(textToAudioBilledSeconds(45)).toBe(30)
36
+ })
37
+ })
38
+
39
+ describe("textToAudioCreditId — the price row a Text to Audio run is charged from", () => {
40
+ it.each([
41
+ [0.5, "elevenlabs-sfx:1s"],
42
+ [6, "elevenlabs-sfx:6s"],
43
+ [10, "elevenlabs-sfx:10s"],
44
+ [22, "elevenlabs-sfx:22s"],
45
+ [30, "elevenlabs-sfx:30s"],
46
+ ])("%s s → %s", (duration, id) => {
47
+ expect(textToAudioCreditId("elevenlabs-sfx", duration)).toBe(id)
48
+ })
49
+
50
+ it("no duration → the 5 s row", () => {
51
+ expect(textToAudioCreditId("elevenlabs-sfx", undefined)).toBe("elevenlabs-sfx:5s")
52
+ })
53
+
54
+ it("no provider → the default engine's row", () => {
55
+ expect(textToAudioCreditId(undefined, 8)).toBe("elevenlabs-sfx:8s")
56
+ expect(textToAudioCreditId("", undefined)).toBe("elevenlabs-sfx:5s")
57
+ })
58
+
59
+ it("an engine not priced per second keeps its own row", () => {
60
+ expect(textToAudioCreditId("tangoflux", 8)).toBe("tangoflux")
61
+ })
62
+
63
+ it("every id it can return is in the published per-second id list (1 s … 30 s)", () => {
64
+ expect(TEXT_TO_AUDIO_SFX_CREDIT_IDS).toHaveLength(30)
65
+ expect(TEXT_TO_AUDIO_SFX_CREDIT_IDS[0]).toBe("elevenlabs-sfx:1s")
66
+ expect(TEXT_TO_AUDIO_SFX_CREDIT_IDS[29]).toBe("elevenlabs-sfx:30s")
67
+ for (const d of [undefined, 0.5, 1, 4.2, 22, 30, 99]) {
68
+ expect(TEXT_TO_AUDIO_SFX_CREDIT_IDS).toContain(textToAudioCreditId("elevenlabs-sfx", d))
69
+ }
70
+ })
71
+ })