@nodaro/shared 3.14.0 → 3.18.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 (153) hide show
  1. package/dist/index.cjs +1679 -81
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +1822 -49
  4. package/dist/index.d.ts +1822 -49
  5. package/dist/index.js +1491 -82
  6. package/dist/index.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/__tests__/apply-edl-credit-id.test.ts +25 -0
  9. package/src/__tests__/camera-switch-contract.test.ts +98 -0
  10. package/src/__tests__/competitors.test.ts +49 -0
  11. package/src/__tests__/content-recipe-ideas.test.ts +96 -0
  12. package/src/__tests__/edl-multicam.test.ts +192 -0
  13. package/src/__tests__/exposed-field-keys.test.ts +78 -0
  14. package/src/__tests__/instagram-scrape.test.ts +62 -0
  15. package/src/__tests__/llm-models.test.ts +5 -2
  16. package/src/__tests__/music-provider.test.ts +17 -0
  17. package/src/__tests__/node-runtime-keys.test.ts +11 -0
  18. package/src/__tests__/parameter-node-value.test.ts +2 -1
  19. package/src/__tests__/per-unit-video-pricing.test.ts +97 -0
  20. package/src/__tests__/producer-types.test.ts +35 -0
  21. package/src/__tests__/saved-posts.test.ts +37 -0
  22. package/src/__tests__/script-settings.test.ts +61 -0
  23. package/src/__tests__/settings-input.test.ts +252 -0
  24. package/src/__tests__/social-search.test.ts +243 -0
  25. package/src/__tests__/studio-sequence-owner.test.ts +356 -0
  26. package/src/__tests__/studio-take-voice.test.ts +200 -0
  27. package/src/__tests__/studio-transient.test.ts +71 -0
  28. package/src/__tests__/sub-gates.test.ts +21 -0
  29. package/src/__tests__/telegram-account-trigger.test.ts +120 -0
  30. package/src/__tests__/text-to-audio-pricing.test.ts +71 -0
  31. package/src/__tests__/tts-capabilities.test.ts +237 -0
  32. package/src/__tests__/video-analysis-pricing.test.ts +27 -13
  33. package/src/__tests__/video-link.test.ts +2 -2
  34. package/src/__tests__/video-utils.test.ts +89 -83
  35. package/src/__tests__/workflow-export-strip.test.ts +37 -0
  36. package/src/camera-switch-contract.ts +166 -0
  37. package/src/catalog-projection.ts +7 -0
  38. package/src/competitors.ts +430 -0
  39. package/src/content-recipe-ideas.ts +69 -0
  40. package/src/credit-estimators/index.ts +21 -0
  41. package/src/credit-estimators/ltx-extend.ts +33 -0
  42. package/src/credit-estimators/ltx-retake.ts +30 -0
  43. package/src/credit-estimators/text-to-audio.ts +58 -0
  44. package/src/credit-estimators/video-sfx.ts +41 -0
  45. package/src/credit-estimators/video-utils.ts +38 -24
  46. package/src/credit-identifiers.ts +22 -0
  47. package/src/edl-multicam.ts +220 -0
  48. package/src/exposed-field-keys.ts +49 -0
  49. package/src/fan-out-rows.ts +7 -2
  50. package/src/i18n/action-fx.ko.ts +18 -18
  51. package/src/i18n/action-fx.pt-BR.ts +66 -66
  52. package/src/i18n/aesthetic.ko.ts +49 -49
  53. package/src/i18n/aesthetic.pt-BR.ts +14 -14
  54. package/src/i18n/animals.ko.ts +126 -126
  55. package/src/i18n/animals.pt-BR.ts +33 -33
  56. package/src/i18n/atmosphere.ko.ts +37 -37
  57. package/src/i18n/atmosphere.pt-BR.ts +29 -29
  58. package/src/i18n/backdrop.ko.ts +40 -40
  59. package/src/i18n/backdrop.pt-BR.ts +38 -38
  60. package/src/i18n/camera-format.ko.ts +31 -31
  61. package/src/i18n/camera-format.pt-BR.ts +12 -12
  62. package/src/i18n/camera-motions.ko.ts +66 -66
  63. package/src/i18n/camera-motions.pt-BR.ts +51 -51
  64. package/src/i18n/character-fx.ko.ts +19 -19
  65. package/src/i18n/character-fx.pt-BR.ts +64 -52
  66. package/src/i18n/character-motion.ko.ts +164 -164
  67. package/src/i18n/character-motion.pt-BR.ts +867 -858
  68. package/src/i18n/color-look.ko.ts +41 -41
  69. package/src/i18n/color-look.pt-BR.ts +23 -23
  70. package/src/i18n/composition-effects.ko.ts +18 -18
  71. package/src/i18n/composition-effects.pt-BR.ts +17 -17
  72. package/src/i18n/era.ko.ts +28 -28
  73. package/src/i18n/era.pt-BR.ts +20 -20
  74. package/src/i18n/exposure-settings.ko.ts +20 -20
  75. package/src/i18n/exposure-settings.pt-BR.ts +3 -3
  76. package/src/i18n/framing.ko.ts +66 -66
  77. package/src/i18n/framing.pt-BR.ts +50 -50
  78. package/src/i18n/furniture.ko.ts +78 -78
  79. package/src/i18n/furniture.pt-BR.ts +46 -46
  80. package/src/i18n/held-prop.ko.ts +60 -60
  81. package/src/i18n/held-prop.pt-BR.ts +30 -30
  82. package/src/i18n/instrumentation.ko.ts +62 -62
  83. package/src/i18n/instrumentation.pt-BR.ts +64 -64
  84. package/src/i18n/lens.ko.ts +16 -16
  85. package/src/i18n/lens.pt-BR.ts +5 -5
  86. package/src/i18n/lighting.ko.ts +68 -68
  87. package/src/i18n/lighting.pt-BR.ts +43 -43
  88. package/src/i18n/loop-subject.ko.ts +1 -1
  89. package/src/i18n/loop-subject.pt-BR.ts +31 -31
  90. package/src/i18n/materials.ko.ts +66 -66
  91. package/src/i18n/materials.pt-BR.ts +22 -22
  92. package/src/i18n/mood.ko.ts +50 -50
  93. package/src/i18n/mood.pt-BR.ts +12 -12
  94. package/src/i18n/music-genre.ko.ts +28 -28
  95. package/src/i18n/music-genre.pt-BR.ts +50 -50
  96. package/src/i18n/music-mood.ko.ts +27 -27
  97. package/src/i18n/music-mood.pt-BR.ts +20 -20
  98. package/src/i18n/person.ko.ts +396 -396
  99. package/src/i18n/person.pt-BR.ts +237 -237
  100. package/src/i18n/photo-genre.ko.ts +46 -46
  101. package/src/i18n/photo-genre.pt-BR.ts +32 -32
  102. package/src/i18n/photographer.ko.ts +63 -63
  103. package/src/i18n/photographer.pt-BR.ts +15 -15
  104. package/src/i18n/pose.ko.ts +81 -81
  105. package/src/i18n/pose.pt-BR.ts +65 -65
  106. package/src/i18n/post-process-effects.ko.ts +18 -18
  107. package/src/i18n/post-process-effects.pt-BR.ts +18 -18
  108. package/src/i18n/render-quality.ko.ts +24 -24
  109. package/src/i18n/render-quality.pt-BR.ts +12 -12
  110. package/src/i18n/setting.ko.ts +64 -64
  111. package/src/i18n/setting.pt-BR.ts +41 -41
  112. package/src/i18n/style.ko.ts +49 -49
  113. package/src/i18n/style.pt-BR.ts +19 -19
  114. package/src/i18n/styling.ko.ts +265 -265
  115. package/src/i18n/styling.pt-BR.ts +141 -141
  116. package/src/i18n/temporal.ko.ts +18 -18
  117. package/src/i18n/temporal.pt-BR.ts +12 -12
  118. package/src/i18n/transitions.ko.ts +14 -14
  119. package/src/i18n/transitions.pt-BR.ts +83 -71
  120. package/src/i18n/vehicles.ko.ts +107 -107
  121. package/src/i18n/vehicles.pt-BR.ts +55 -55
  122. package/src/i18n/voice-character.ko.ts +19 -19
  123. package/src/i18n/voice-character.pt-BR.ts +19 -19
  124. package/src/i18n/voice-delivery.ko.ts +22 -22
  125. package/src/i18n/voice-delivery.pt-BR.ts +22 -22
  126. package/src/i18n/weapons.ko.ts +85 -85
  127. package/src/i18n/weapons.pt-BR.ts +46 -46
  128. package/src/index.ts +236 -1
  129. package/src/instagram-scrape.ts +91 -16
  130. package/src/llm-models.ts +11 -0
  131. package/src/model-catalog.ts +151 -16
  132. package/src/model-constants.ts +54 -16
  133. package/src/node-mappable-fields.ts +21 -5
  134. package/src/node-runtime-keys.ts +45 -0
  135. package/src/oauth-scopes.ts +28 -0
  136. package/src/parameter-node-value.ts +13 -5
  137. package/src/pipeline-defaults.ts +14 -0
  138. package/src/pipeline-state-types.ts +14 -0
  139. package/src/presentation-utils.ts +5 -1
  140. package/src/producer-types.ts +85 -0
  141. package/src/recast-segment-packs.ts +13 -0
  142. package/src/resolve-field-mappings.ts +15 -5
  143. package/src/saved-posts.ts +106 -0
  144. package/src/script-settings.ts +70 -0
  145. package/src/settings-input.ts +366 -0
  146. package/src/social-search.ts +467 -0
  147. package/src/studio-transient.ts +479 -7
  148. package/src/telegram-account-send.ts +32 -0
  149. package/src/telegram-account-trigger.ts +108 -0
  150. package/src/tts-capabilities.ts +75 -0
  151. package/src/video-analysis-pricing.ts +17 -6
  152. package/src/video-link.ts +16 -4
  153. package/src/workflow-export.ts +7 -0
@@ -0,0 +1,243 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import {
3
+ SOCIAL_PLATFORMS,
4
+ SOCIAL_SEARCH_CREDIT_COSTS,
5
+ SOCIAL_SEARCH_CREDITS_PER_PAGE,
6
+ SOCIAL_SEARCH_PLATFORM_MODES,
7
+ isSocialPost,
8
+ isSocialSearchPickFrozen,
9
+ pickSocialPosts,
10
+ socialPostsDigest,
11
+ socialPostsFrom,
12
+ socialSearchCreditId,
13
+ socialSearchPostLink,
14
+ socialSearchPostVideo,
15
+ signedLinkExpiresAt,
16
+ socialPostsLongestVideoSec,
17
+ SOCIAL_POST_VIDEO_LINK_MARGIN_MS,
18
+ socialSearchCreditIdFromNode,
19
+ socialSearchMode,
20
+ socialSearchPickTop,
21
+ socialSearchRequestFromNode,
22
+ socialSearchMaxCount,
23
+ socialSearchCountry,
24
+ socialSearchRegion,
25
+ type SocialPost,
26
+ } from "../social-search.js"
27
+
28
+ function post(id: string, over: Partial<SocialPost> = {}): SocialPost {
29
+ return {
30
+ id: `tiktok:${id}`,
31
+ platform: "tiktok",
32
+ url: `https://www.tiktok.com/@maker/video/${id}`,
33
+ text: `post ${id}`,
34
+ author: { handle: "maker", name: "Maker" },
35
+ metrics: {},
36
+ media: { kind: "video" },
37
+ hashtags: [],
38
+ extra: {},
39
+ ...over,
40
+ }
41
+ }
42
+
43
+ describe("the request a node sends", () => {
44
+ it("fills the defaults and keeps only the options that apply to the platform", () => {
45
+ expect(socialSearchRequestFromNode({ platform: "tiktok", query: " ai ads ", region: "us", country: "DE" })).toEqual({
46
+ platform: "tiktok", mode: "keyword", query: "ai ads", count: 20, period: "month", sort: "relevance", region: "US",
47
+ })
48
+ expect(socialSearchRequestFromNode({ platform: "meta_ads", query: "q" })).toMatchObject({ country: "ALL", activeOnly: true })
49
+ expect(socialSearchRequestFromNode({ platform: "meta_ads", query: "q", country: "usa" })).toMatchObject({ country: "ALL" })
50
+ expect(socialSearchRequestFromNode({ platform: "tiktok", query: "q", region: "USA" })).not.toHaveProperty("region")
51
+ expect(socialSearchRequestFromNode({ platform: "youtube", query: "q", videoKind: "shorts" })).toMatchObject({ videoKind: "shorts" })
52
+ expect(socialSearchRequestFromNode({ platform: "reddit", query: "q", subreddit: "videography" })).toMatchObject({ subreddit: "videography" })
53
+ })
54
+
55
+ it("prefers the wired text over the node's own query", () => {
56
+ expect(socialSearchRequestFromNode({ platform: "x", query: "typed" }, " from the wire ").query).toBe("from the wire")
57
+ expect(socialSearchRequestFromNode({ platform: "x", query: "typed" }, " ").query).toBe("typed")
58
+ })
59
+
60
+ it("repairs a mode the platform does not have (switched from Reddit to TikTok)", () => {
61
+ expect(socialSearchMode("tiktok", "community")).toBe("keyword")
62
+ expect(socialSearchMode("reddit", "community")).toBe("community")
63
+ expect(socialSearchRequestFromNode({ platform: "unknown", mode: "account", query: "q" })).toMatchObject({ platform: "tiktok", mode: "account" })
64
+ })
65
+
66
+ it("every platform searches by keyword", () => {
67
+ for (const platform of SOCIAL_PLATFORMS) expect(SOCIAL_SEARCH_PLATFORM_MODES[platform][0]).toBe("keyword")
68
+ })
69
+ })
70
+
71
+ describe("results per search", () => {
72
+ it("caps a search that returns one page at 20, and bills it as one page", () => {
73
+ expect(socialSearchMaxCount("tiktok", "keyword")).toBe(60)
74
+ expect(socialSearchMaxCount("tiktok", "account")).toBe(20)
75
+ expect(socialSearchMaxCount("youtube", "keyword")).toBe(20)
76
+ expect(socialSearchMaxCount("reddit", "keyword")).toBe(20)
77
+ expect(socialSearchMaxCount("reddit", "community")).toBe(60)
78
+ expect(socialSearchRequestFromNode({ platform: "youtube", query: "q", count: 60 }).count).toBe(20)
79
+ expect(socialSearchRequestFromNode({ platform: "x", mode: "account", query: "q", count: 60 }).count).toBe(60)
80
+ expect(socialSearchCreditIdFromNode({ platform: "linkedin", mode: "account", count: 60 })).toBe("social-search:1")
81
+ expect(socialSearchCreditIdFromNode({ platform: "meta_ads", mode: "account", count: 60 })).toBe("social-search:3")
82
+ })
83
+
84
+ it("reads a region and a country only in their real forms", () => {
85
+ expect(socialSearchRegion(" gb ")).toBe("GB")
86
+ expect(socialSearchRegion("GBR")).toBeUndefined()
87
+ expect(socialSearchCountry("all")).toBe("ALL")
88
+ expect(socialSearchCountry("de")).toBe("DE")
89
+ expect(socialSearchCountry(undefined)).toBe("ALL")
90
+ })
91
+ })
92
+
93
+ describe("pricing", () => {
94
+ it("prices by pages of results; every reservable id has a price", () => {
95
+ expect(socialSearchCreditId(20)).toBe("social-search:1")
96
+ expect(socialSearchCreditIdFromNode({ platform: "tiktok", count: 60 })).toBe("social-search:3")
97
+ expect(socialSearchCreditIdFromNode({ count: 33 })).toBe("social-search:1")
98
+ expect(SOCIAL_SEARCH_CREDIT_COSTS).toEqual({
99
+ "social-search": SOCIAL_SEARCH_CREDITS_PER_PAGE,
100
+ "social-search:1": SOCIAL_SEARCH_CREDITS_PER_PAGE,
101
+ "social-search:2": SOCIAL_SEARCH_CREDITS_PER_PAGE * 2,
102
+ "social-search:3": SOCIAL_SEARCH_CREDITS_PER_PAGE * 3,
103
+ })
104
+ })
105
+ })
106
+
107
+ describe("which posts a run passes on", () => {
108
+ const results = ["1", "2", "3", "4", "5", "6"].map((id) => post(id))
109
+
110
+ it("passes on the picks, in picking order", () => {
111
+ expect(pickSocialPosts(results, ["tiktok:4", "tiktok:2"], 5).map((p) => p.id)).toEqual(["tiktok:4", "tiktok:2"])
112
+ })
113
+
114
+ it("falls back to the first few when no pick is among the results (a fresh search)", () => {
115
+ expect(pickSocialPosts(results, ["tiktok:99"], 2).map((p) => p.id)).toEqual(["tiktok:1", "tiktok:2"])
116
+ expect(pickSocialPosts(results, undefined, undefined)).toHaveLength(5)
117
+ expect(socialSearchPickTop(0)).toBe(1)
118
+ expect(socialSearchPickTop(500)).toBe(60)
119
+ })
120
+
121
+ it("keeps picks frozen only when the author asked to and there are picks", () => {
122
+ expect(isSocialSearchPickFrozen("social-search", { keepPicks: true, generatedJson: [post("1")] })).toBe(true)
123
+ expect(isSocialSearchPickFrozen("social-search", { keepPicks: true, generatedJson: [] })).toBe(false)
124
+ expect(isSocialSearchPickFrozen("social-search", { keepPicks: false, generatedJson: [post("1")] })).toBe(false)
125
+ expect(isSocialSearchPickFrozen("web-scrape", { keepPicks: true, generatedJson: [post("1")] })).toBe(false)
126
+ })
127
+ })
128
+
129
+ describe("reading posts back", () => {
130
+ it("keeps only well-formed posts", () => {
131
+ expect(isSocialPost(post("1"))).toBe(true)
132
+ expect(isSocialPost({ ...post("1"), platform: "myspace" })).toBe(false)
133
+ expect(isSocialPost({ ...post("1"), metrics: undefined })).toBe(false)
134
+ expect(isSocialPost({ ...post("1"), text: 7 })).toBe(false)
135
+ expect(isSocialPost({ ...post("1"), hashtags: "x" })).toBe(false)
136
+ expect(socialPostsFrom([post("1"), null, "x", { id: "y" }])).toHaveLength(1)
137
+ expect(socialPostsFrom("not a list")).toEqual([])
138
+ })
139
+
140
+ it("writes a readable digest", () => {
141
+ const text = socialPostsDigest([
142
+ post("1", { publishedAt: "2026-09-30T10:00:00Z", metrics: { views: 1200 }, text: "Hello world" }),
143
+ post("2", { author: { handle: "", name: "" }, container: "r/aivideo", metrics: { score: 40 }, title: "A thread" }),
144
+ ])
145
+ expect(text).toBe(
146
+ "1. @maker · 2026-09-30 · 1200 views\n Hello world\n https://www.tiktok.com/@maker/video/1\n\n" +
147
+ "2. r/aivideo · 40 points\n A thread\n https://www.tiktok.com/@maker/video/2",
148
+ )
149
+ })
150
+ })
151
+
152
+ describe("socialSearchPostLink", () => {
153
+ const post = (url: unknown) => ({ id: "reddit:1", platform: "reddit", url, text: "", author: { handle: "a", name: "A" } })
154
+
155
+ it("reads one post (an Each wire) and the first of a list (any other wire)", () => {
156
+ expect(socialSearchPostLink(JSON.stringify(post("https://www.reddit.com/r/x/comments/1/")))).toBe("https://www.reddit.com/r/x/comments/1/")
157
+ expect(socialSearchPostLink(JSON.stringify([post("https://www.tiktok.com/@a/video/1"), post("https://www.tiktok.com/@a/video/2")]))).toBe("https://www.tiktok.com/@a/video/1")
158
+ })
159
+
160
+ it("reads no link from a digest, an empty list, or a post without an http(s) link", () => {
161
+ expect(socialSearchPostLink("1. @a: something https://x.com/a/status/1")).toBeUndefined()
162
+ expect(socialSearchPostLink("[]")).toBeUndefined()
163
+ expect(socialSearchPostLink(JSON.stringify(post("javascript:alert(1)")))).toBeUndefined()
164
+ expect(socialSearchPostLink(JSON.stringify(post(7)))).toBeUndefined()
165
+ })
166
+ })
167
+
168
+ describe("the video a post hands Video Analysis", () => {
169
+ const NOW = Date.parse("2026-10-04T00:00:00Z")
170
+ const hexSeconds = (ms: number) => Math.floor(ms / 1000).toString(16).toUpperCase()
171
+ const igFile = (endMs: number) => `https://scontent-sjc6-1.cdninstagram.com/o1/v/t2/f2/m86/clip.mp4?_nc_cat=1&oh=00_sig&oe=${hexSeconds(endMs)}`
172
+ const reel = (videoUrl?: string, durationSec?: number) =>
173
+ post("1", { id: "instagram:1", platform: "instagram", url: "https://www.instagram.com/reel/Dav1/", media: { kind: "video", videoUrl, durationSec } })
174
+
175
+ it("reads the post's own video file while its signed link is valid", () => {
176
+ const file = igFile(NOW + 2 * 24 * 3_600_000)
177
+ expect(socialSearchPostVideo(JSON.stringify(reel(file, 27)), NOW)).toEqual({ kind: "file", url: file })
178
+ // The first post of a list (a wire that is not in Each mode).
179
+ expect(socialSearchPostVideo(JSON.stringify([reel(file), post("2")]), NOW)).toEqual({ kind: "file", url: file })
180
+ })
181
+
182
+ it("reports an expired file (or one about to expire) instead of reading the post's page", () => {
183
+ expect(socialSearchPostVideo(JSON.stringify(reel(igFile(NOW - 60_000))), NOW)).toEqual({ kind: "expired" })
184
+ expect(socialSearchPostVideo(JSON.stringify(reel(igFile(NOW + SOCIAL_POST_VIDEO_LINK_MARGIN_MS - 60_000))), NOW)).toEqual({ kind: "expired" })
185
+ })
186
+
187
+ it("hands over no video for an image or a text post", () => {
188
+ expect(socialSearchPostVideo(JSON.stringify(post("5", { media: { kind: "image" } })), NOW)).toEqual({ kind: "none" })
189
+ expect(socialSearchPostVideo(JSON.stringify(post("6", { media: { kind: "text" } })), NOW)).toEqual({ kind: "none" })
190
+ })
191
+
192
+ it("falls back to the post's page when no file came with it", () => {
193
+ expect(socialSearchPostVideo(JSON.stringify(post("7")), NOW)).toEqual({ kind: "page", url: "https://www.tiktok.com/@maker/video/7" })
194
+ })
195
+
196
+ it("reads a streaming playlist (HLS) as no file: the post goes by its page", () => {
197
+ const hls = post("8", {
198
+ platform: "linkedin",
199
+ url: "https://www.linkedin.com/posts/acme_launch-activity-1-abcd",
200
+ media: { kind: "video", videoUrl: "https://dms.licdn.com/playlist/vid/v2/D4E/hls-720p/master.m3u8?e=1791100000&t=s" },
201
+ })
202
+ expect(socialSearchPostVideo(JSON.stringify(hls), NOW)).toEqual({ kind: "page", url: "https://www.linkedin.com/posts/acme_launch-activity-1-abcd" })
203
+ // A LinkedIn progressive file under the same path is a file.
204
+ const mp4 = post("9", {
205
+ platform: "linkedin",
206
+ media: { kind: "video", videoUrl: "https://dms.licdn.com/playlist/vid/v2/D4E/mp4-720p-30fp-crf28/0/1?e=1791100000&t=s" },
207
+ })
208
+ expect(socialSearchPostVideo(JSON.stringify(mp4), NOW)).toMatchObject({ kind: "file" })
209
+ })
210
+
211
+ it("reads nothing from a digest, an empty list, or something that is not a post", () => {
212
+ expect(socialSearchPostVideo("1. @a: something https://x.com/a/status/1", NOW)).toBeUndefined()
213
+ expect(socialSearchPostVideo("[]", NOW)).toBeUndefined()
214
+ expect(socialSearchPostVideo(JSON.stringify({ url: "https://www.tiktok.com/@a/video/1" }), NOW)).toBeUndefined()
215
+ expect(socialSearchPostVideo(JSON.stringify(post("1", { url: "javascript:alert(1)" })), NOW)).toBeUndefined()
216
+ })
217
+
218
+ it("reads each platform's link end, and none from a link that does not expire", () => {
219
+ expect(signedLinkExpiresAt("https://scontent.cdninstagram.com/v.mp4?oe=6AC3520E")).toBe(0x6ac3520e * 1000)
220
+ expect(signedLinkExpiresAt("https://v16-webapp.tiktok.com/v.mp4?x-expires=1791100000&x-signature=s")).toBe(1_791_100_000_000)
221
+ expect(signedLinkExpiresAt("https://d1.cloudfront.net/v.mp4?Expires=1791100000&Signature=s")).toBe(1_791_100_000_000)
222
+ expect(signedLinkExpiresAt("https://dms.licdn.com/playlist/vid/v.mp4?e=1791100000&v=beta&t=s")).toBe(1_791_100_000_000)
223
+ // `e` means an end only on LinkedIn's media host.
224
+ expect(signedLinkExpiresAt("https://cdn.example.com/v.mp4?e=1791100000")).toBeUndefined()
225
+ expect(signedLinkExpiresAt("https://video.twimg.com/ext_tw_video/1/pu/vid/720x1280/a.mp4?tag=12")).toBeUndefined()
226
+ expect(signedLinkExpiresAt("not a link")).toBeUndefined()
227
+ })
228
+ })
229
+
230
+ describe("the length Video Analysis quotes for the posts", () => {
231
+ const clip = (id: string, durationSec?: number) => post(id, { media: { kind: "video", durationSec } })
232
+
233
+ it("is the longest video's", () => {
234
+ expect(socialPostsLongestVideoSec([clip("1", 27), clip("2", 90), clip("3", 24)])).toBe(90)
235
+ })
236
+
237
+ it("leaves out posts without a video, and is unknown when a video's length is", () => {
238
+ expect(socialPostsLongestVideoSec([clip("1", 27), post("2", { media: { kind: "image" } })])).toBe(27)
239
+ expect(socialPostsLongestVideoSec([clip("1", 27), clip("2")])).toBeUndefined()
240
+ expect(socialPostsLongestVideoSec([post("2", { media: { kind: "text" } })])).toBeUndefined()
241
+ expect(socialPostsLongestVideoSec([])).toBeUndefined()
242
+ })
243
+ })
@@ -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
+ })