@nodaro/shared 3.18.0 → 3.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +203 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +202 -2
- package/dist/index.d.ts +202 -2
- package/dist/index.js +195 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/caption-plan.test.ts +27 -0
- package/src/__tests__/edit-plan-review.test.ts +379 -0
- package/src/__tests__/node-preset-extract.test.ts +62 -0
- package/src/caption-plan.ts +27 -0
- package/src/competitors.ts +40 -0
- package/src/edit-plan-review.ts +323 -0
- package/src/index.ts +10 -1
- package/src/node-preset-extract.ts +33 -1
- package/src/node-runtime-keys.ts +5 -0
- package/src/producer-types.ts +15 -0
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// packages/shared/src/__tests__/caption-plan.test.ts
|
|
2
|
+
import { describe, it, expect, expectTypeOf } from "vitest"
|
|
3
|
+
import type { CaptionPlan, CaptionWordTiming } from "../index.js"
|
|
4
|
+
|
|
5
|
+
describe("CaptionPlan", () => {
|
|
6
|
+
it("is exported from the package barrel with the documented fields", () => {
|
|
7
|
+
const plan: CaptionPlan = {
|
|
8
|
+
v: 1,
|
|
9
|
+
hookText: "Saved 3 hours a week",
|
|
10
|
+
hookEndMs: 1600,
|
|
11
|
+
bodyEndMs: 4300,
|
|
12
|
+
captions: [{ text: "so", startMs: 1600, endMs: 1900 }],
|
|
13
|
+
videoDurationMs: 8000,
|
|
14
|
+
language: "en",
|
|
15
|
+
}
|
|
16
|
+
expect(plan.v).toBe(1)
|
|
17
|
+
expectTypeOf<CaptionWordTiming>().toEqualTypeOf<{ readonly text: string; readonly startMs: number; readonly endMs: number }>()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it("requires its version and carries no styling", () => {
|
|
21
|
+
// @ts-expect-error — `v` is required
|
|
22
|
+
const noVersion: CaptionPlan = { hookText: "", hookEndMs: 0, bodyEndMs: 0, captions: [] }
|
|
23
|
+
// @ts-expect-error — a plan carries times and words only
|
|
24
|
+
const styled: CaptionPlan = { v: 1, hookText: "", hookEndMs: 0, bodyEndMs: 0, captions: [], look: "clean" }
|
|
25
|
+
expect([noVersion, styled]).toHaveLength(2)
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
EDITED_EDL_VERSION,
|
|
4
|
+
editPlanBasis,
|
|
5
|
+
editPlanSavedOutput,
|
|
6
|
+
resolveEditPlanOutput,
|
|
7
|
+
validateEditedEdl,
|
|
8
|
+
type EditedEdl,
|
|
9
|
+
} from "../edit-plan-review.js"
|
|
10
|
+
import { EXECUTION_DATA_KEYS, TRANSIENT_RUNTIME_KEYS } from "../node-runtime-keys.js"
|
|
11
|
+
import type { Edl } from "../edl.js"
|
|
12
|
+
|
|
13
|
+
// ── fixtures ────────────────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
const SOURCES = [{ id: "cam", kind: "video", url: "https://media.example/ep.mp4", role: "master-audio" }]
|
|
16
|
+
|
|
17
|
+
const TIGHTEN: Edl = {
|
|
18
|
+
version: 1,
|
|
19
|
+
clock: "master",
|
|
20
|
+
sources: SOURCES,
|
|
21
|
+
segments: [
|
|
22
|
+
{ id: "seg-0", inMs: 0, outMs: 4000, video: "cam" },
|
|
23
|
+
{ id: "seg-1", inMs: 6000, outMs: 9000, video: "cam" },
|
|
24
|
+
],
|
|
25
|
+
dropped: [{ inMs: 4000, outMs: 6000, reason: "silence" }],
|
|
26
|
+
meta: { title: "Episode 12" },
|
|
27
|
+
} as unknown as Edl
|
|
28
|
+
|
|
29
|
+
const clip = (inMs: number, outMs: number, title: string, hook: string): Edl =>
|
|
30
|
+
({
|
|
31
|
+
version: 1,
|
|
32
|
+
clock: "master",
|
|
33
|
+
sources: SOURCES,
|
|
34
|
+
segments: [{ id: "seg-0", inMs, outMs, video: "cam" }],
|
|
35
|
+
dropped: [],
|
|
36
|
+
meta: { title, hook },
|
|
37
|
+
}) as unknown as Edl
|
|
38
|
+
|
|
39
|
+
const CLIPS: Edl[] = [
|
|
40
|
+
clip(1000, 60000, "Why remote teams fail", "Nobody tells you this"),
|
|
41
|
+
clip(70000, 128000, "The pricing myth", "We charged half"),
|
|
42
|
+
clip(130000, 221000, "Our first hire", "We hired wrong"),
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
const CHAPTERS = { version: 1, chapters: [{ startMs: 0, title: "Intro" }] }
|
|
46
|
+
|
|
47
|
+
const cutEdit = (plan: unknown, edl: { segments: unknown[]; dropped: unknown[] }): EditedEdl =>
|
|
48
|
+
({ v: EDITED_EDL_VERSION, kind: "edl", basis: editPlanBasis(plan), edl }) as EditedEdl
|
|
49
|
+
|
|
50
|
+
const clipsEdit = (plan: unknown, clips: Array<{ keep: boolean; hook?: string }>): EditedEdl =>
|
|
51
|
+
({ v: EDITED_EDL_VERSION, kind: "clips", basis: editPlanBasis(plan), clips }) as EditedEdl
|
|
52
|
+
|
|
53
|
+
/** Rebuild a JSON value with every object's keys in REVERSE order, at every
|
|
54
|
+
* depth — what a JSONB round trip may do to `workflows.nodes`. */
|
|
55
|
+
function reverseKeysDeep(value: unknown): unknown {
|
|
56
|
+
if (Array.isArray(value)) return value.map(reverseKeysDeep)
|
|
57
|
+
if (value && typeof value === "object") {
|
|
58
|
+
const out: Record<string, unknown> = {}
|
|
59
|
+
for (const key of Object.keys(value).reverse()) out[key] = reverseKeysDeep((value as Record<string, unknown>)[key])
|
|
60
|
+
return out
|
|
61
|
+
}
|
|
62
|
+
return value
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ── editPlanBasis ───────────────────────────────────────────────────────────
|
|
66
|
+
|
|
67
|
+
describe("editPlanBasis — FNV-1a-64 over key-sorted JSON (TA13)", () => {
|
|
68
|
+
it("is 16 lowercase hex digits", () => {
|
|
69
|
+
expect(editPlanBasis(TIGHTEN)).toMatch(/^[0-9a-f]{16}$/)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it("is FNV-1a-64 of the UTF-8 bytes of the canonical JSON (standard vectors)", () => {
|
|
73
|
+
// A JSON string canonicalizes to its JSON text, so the hashed bytes are the
|
|
74
|
+
// quoted string: `""` and `"a"` and `"foobar"` WITH the quotes.
|
|
75
|
+
// Reference values from the published FNV-1a-64 test vectors, computed on
|
|
76
|
+
// the quoted texts.
|
|
77
|
+
expect(editPlanBasis("")).toBe(fnv1a64Reference('""'))
|
|
78
|
+
expect(editPlanBasis("a")).toBe(fnv1a64Reference('"a"'))
|
|
79
|
+
// Non-ASCII hashes its UTF-8 bytes (é = C3 A9; 😀 = F0 9F 98 80), not UTF-16 units.
|
|
80
|
+
expect(editPlanBasis("é😀")).toBe(fnv1a64Reference('"é😀"'))
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it("the reference implementation matches the published vectors", () => {
|
|
84
|
+
expect(fnv1a64Reference("")).toBe("cbf29ce484222325")
|
|
85
|
+
expect(fnv1a64Reference("a")).toBe("af63dc4c8601ec8c")
|
|
86
|
+
expect(fnv1a64Reference("foobar")).toBe("85944171f73967e8")
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it("survives a JSONB round trip that reorders keys at every depth", () => {
|
|
90
|
+
for (const plan of [TIGHTEN, CLIPS, CHAPTERS]) {
|
|
91
|
+
const reordered = reverseKeysDeep(JSON.parse(JSON.stringify(plan)))
|
|
92
|
+
expect(JSON.stringify(reordered)).not.toBe(JSON.stringify(plan))
|
|
93
|
+
expect(editPlanBasis(reordered)).toBe(editPlanBasis(plan))
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it("changes when any value changes, at any depth", () => {
|
|
98
|
+
const moved = JSON.parse(JSON.stringify(CLIPS))
|
|
99
|
+
moved[2].segments[0].inMs += 1
|
|
100
|
+
expect(editPlanBasis(moved)).not.toBe(editPlanBasis(CLIPS))
|
|
101
|
+
const retitled = { ...TIGHTEN, meta: { title: "Episode 13" } }
|
|
102
|
+
expect(editPlanBasis(retitled)).not.toBe(editPlanBasis(TIGHTEN))
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it("keeps array order significant", () => {
|
|
106
|
+
expect(editPlanBasis([CLIPS[1], CLIPS[0], CLIPS[2]])).not.toBe(editPlanBasis(CLIPS))
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it("ignores undefined-valued keys, as the stored JSON does", () => {
|
|
110
|
+
expect(editPlanBasis({ ...TIGHTEN, derivedFrom: undefined })).toBe(editPlanBasis(TIGHTEN))
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
// ── editPlanSavedOutput: unedited parity ────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
describe("editPlanSavedOutput — no edit: today's saved output, unchanged", () => {
|
|
117
|
+
it("tighten and chapters: { json } only", () => {
|
|
118
|
+
expect(editPlanSavedOutput({ generatedJson: TIGHTEN })).toEqual({ json: TIGHTEN })
|
|
119
|
+
expect(editPlanSavedOutput({ generatedJson: CHAPTERS })).toEqual({ json: CHAPTERS })
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it("clips: { json, listResults } with one JSON string per clip", () => {
|
|
123
|
+
expect(editPlanSavedOutput({ generatedJson: CLIPS })).toEqual({
|
|
124
|
+
json: CLIPS,
|
|
125
|
+
listResults: CLIPS.map((c) => JSON.stringify(c)),
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it("no plan: undefined", () => {
|
|
130
|
+
expect(editPlanSavedOutput({})).toBeUndefined()
|
|
131
|
+
expect(editPlanSavedOutput({ editedEdl: cutEdit(TIGHTEN, { segments: [], dropped: [] }) })).toBeUndefined()
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it("ignores the generic result history (a plan is not read from generatedResults)", () => {
|
|
135
|
+
const out = editPlanSavedOutput({ generatedJson: TIGHTEN, generatedResults: [{ url: "x" }] })
|
|
136
|
+
expect(out).toEqual({ json: TIGHTEN })
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
// ── Tighten ─────────────────────────────────────────────────────────────────
|
|
141
|
+
|
|
142
|
+
describe("resolveEditPlanOutput — Tighten (kind: edl)", () => {
|
|
143
|
+
const restored = {
|
|
144
|
+
segments: [{ id: "seg-0", inMs: 0, outMs: 9000, video: "cam" }],
|
|
145
|
+
dropped: [],
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
it("an edit on this plan wins: its segments and dropped, the plan's sources, clock and meta", () => {
|
|
149
|
+
const r = resolveEditPlanOutput(TIGHTEN, cutEdit(TIGHTEN, restored))
|
|
150
|
+
expect(r.status).toBe("applied")
|
|
151
|
+
expect(r.json).toEqual({ ...TIGHTEN, segments: restored.segments, dropped: [] })
|
|
152
|
+
expect(r.listResults).toBeUndefined()
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it("an edit survives the plan's keys being reordered by JSONB", () => {
|
|
156
|
+
const stored = reverseKeysDeep(JSON.parse(JSON.stringify(TIGHTEN)))
|
|
157
|
+
const r = resolveEditPlanOutput(stored, cutEdit(TIGHTEN, restored))
|
|
158
|
+
expect(r.status).toBe("applied")
|
|
159
|
+
expect((r.json as Edl).segments).toEqual(restored.segments)
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it("an edit made against another plan is ignored (stale): the plan as planned", () => {
|
|
163
|
+
const replanned = { ...TIGHTEN, segments: [{ id: "seg-0", inMs: 0, outMs: 3000, video: "cam" }] }
|
|
164
|
+
const r = resolveEditPlanOutput(replanned, cutEdit(TIGHTEN, restored))
|
|
165
|
+
expect(r.status).toBe("stale")
|
|
166
|
+
expect(r.json).toBe(replanned)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it("never stores sources: an edit's own sources are not read", () => {
|
|
170
|
+
const edit = { ...cutEdit(TIGHTEN, restored), edl: { ...restored, sources: [{ id: "evil", kind: "video", url: "https://x" }] } }
|
|
171
|
+
const r = resolveEditPlanOutput(TIGHTEN, edit)
|
|
172
|
+
expect((r.json as Edl).sources).toEqual(TIGHTEN.sources)
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it("an edit that is structurally broken still applies — the render refuses it, the planner's cut never returns silently", () => {
|
|
176
|
+
const broken = { segments: [{ id: "seg-0", inMs: 5000, outMs: 1000, video: "cam" }], dropped: [] }
|
|
177
|
+
const r = resolveEditPlanOutput(TIGHTEN, cutEdit(TIGHTEN, broken))
|
|
178
|
+
expect(r.status).toBe("applied")
|
|
179
|
+
expect((r.json as Edl).segments).toEqual(broken.segments)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it("a clips edit on a Tighten plan is invalid and ignored", () => {
|
|
183
|
+
const r = resolveEditPlanOutput(TIGHTEN, clipsEdit(TIGHTEN, [{ keep: false }]))
|
|
184
|
+
expect(r.status).toBe("invalid")
|
|
185
|
+
expect(r.json).toBe(TIGHTEN)
|
|
186
|
+
})
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
// ── Clips ───────────────────────────────────────────────────────────────────
|
|
190
|
+
|
|
191
|
+
describe("resolveEditPlanOutput — Clips (kind: clips, TA15/TA16)", () => {
|
|
192
|
+
it("the list is row-aligned on the PLAN's indices, with '' at each dropped clip", () => {
|
|
193
|
+
const r = resolveEditPlanOutput(CLIPS, clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true }]))
|
|
194
|
+
expect(r.status).toBe("applied")
|
|
195
|
+
expect(r.listResults).toEqual([JSON.stringify(CLIPS[0]), "", JSON.stringify(CLIPS[2])])
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it("json holds the kept clips only, so the scalar path (json[0]) is the first KEPT clip", () => {
|
|
199
|
+
const r = resolveEditPlanOutput(CLIPS, clipsEdit(CLIPS, [{ keep: false }, { keep: true }, { keep: false }]))
|
|
200
|
+
expect(r.json).toEqual([CLIPS[1]])
|
|
201
|
+
expect(r.listResults).toEqual(["", JSON.stringify(CLIPS[1]), ""])
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it("nothing kept: json is empty and every row is a hole", () => {
|
|
205
|
+
const r = resolveEditPlanOutput(CLIPS, clipsEdit(CLIPS, [{ keep: false }, { keep: false }, { keep: false }]))
|
|
206
|
+
expect(r.json).toEqual([])
|
|
207
|
+
expect(r.listResults).toEqual(["", "", ""])
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it("holes are '' — never null, which would read as the text \"null\"", () => {
|
|
211
|
+
const r = resolveEditPlanOutput(CLIPS, clipsEdit(CLIPS, [{ keep: false }, { keep: true }, { keep: true }]))
|
|
212
|
+
for (const row of r.listResults ?? []) expect(typeof row).toBe("string")
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it("an edited hook travels as meta.hook (text only, TA20); the title is untouched", () => {
|
|
216
|
+
const r = resolveEditPlanOutput(CLIPS, clipsEdit(CLIPS, [{ keep: true, hook: "Nobody warns you" }, { keep: true }, { keep: true }]))
|
|
217
|
+
const first = (r.json as Edl[])[0]!
|
|
218
|
+
expect(first.meta).toEqual({ title: "Why remote teams fail", hook: "Nobody warns you" })
|
|
219
|
+
expect(JSON.parse(r.listResults![0]!).meta.hook).toBe("Nobody warns you")
|
|
220
|
+
expect((r.json as Edl[])[1]).toEqual(CLIPS[1])
|
|
221
|
+
// The plan itself is never mutated.
|
|
222
|
+
expect(CLIPS[0]!.meta?.hook).toBe("Nobody tells you this")
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it("a hook on a dropped clip changes nothing", () => {
|
|
226
|
+
const r = resolveEditPlanOutput(CLIPS, clipsEdit(CLIPS, [{ keep: false, hook: "x" }, { keep: true }, { keep: true }]))
|
|
227
|
+
expect(r.listResults![0]).toBe("")
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it("decisions that do not line up with the plan's clips are invalid and ignored", () => {
|
|
231
|
+
const r = resolveEditPlanOutput(CLIPS, clipsEdit(CLIPS, [{ keep: true }, { keep: false }]))
|
|
232
|
+
expect(r.status).toBe("invalid")
|
|
233
|
+
expect(r.json).toBe(CLIPS)
|
|
234
|
+
expect(r.listResults).toEqual(CLIPS.map((c) => JSON.stringify(c)))
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it("a re-planned clip set leaves the decisions stale", () => {
|
|
238
|
+
const replanned = [CLIPS[0], CLIPS[2]]
|
|
239
|
+
const r = resolveEditPlanOutput(replanned, clipsEdit(CLIPS, [{ keep: true }, { keep: false }]))
|
|
240
|
+
expect(r.status).toBe("stale")
|
|
241
|
+
expect(r.json).toBe(replanned)
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
it("a re-plan with fewer clips leaves a full decision list stale, not invalid (the basis is checked first)", () => {
|
|
245
|
+
const replanned = [CLIPS[0], CLIPS[2]]
|
|
246
|
+
const r = resolveEditPlanOutput(replanned, clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true }]))
|
|
247
|
+
expect(r.status).toBe("stale")
|
|
248
|
+
expect(r.json).toBe(replanned)
|
|
249
|
+
expect(r.listResults).toEqual(replanned.map((c) => JSON.stringify(c)))
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
it("a clips edit meeting a plan re-run as Tighten is stale, not invalid", () => {
|
|
253
|
+
const r = resolveEditPlanOutput(TIGHTEN, clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true }]))
|
|
254
|
+
expect(r.status).toBe("stale")
|
|
255
|
+
expect(r.json).toBe(TIGHTEN)
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
it("an edl edit meeting a plan re-run as a clip set is stale, not invalid", () => {
|
|
259
|
+
const r = resolveEditPlanOutput(CLIPS, cutEdit(TIGHTEN, { segments: [], dropped: [] }))
|
|
260
|
+
expect(r.status).toBe("stale")
|
|
261
|
+
expect(r.json).toBe(CLIPS)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it("an edl edit on a clip set is invalid and ignored", () => {
|
|
265
|
+
const r = resolveEditPlanOutput(CLIPS, cutEdit(CLIPS, { segments: [], dropped: [] }))
|
|
266
|
+
expect(r.status).toBe("invalid")
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
it("editPlanSavedOutput applies the edit stored beside the plan", () => {
|
|
270
|
+
const editedEdl = clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true }])
|
|
271
|
+
expect(editPlanSavedOutput({ generatedJson: CLIPS, editedEdl })).toEqual({
|
|
272
|
+
json: [CLIPS[0], CLIPS[2]],
|
|
273
|
+
listResults: [JSON.stringify(CLIPS[0]), "", JSON.stringify(CLIPS[2])],
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
// ── Chapters and junk ───────────────────────────────────────────────────────
|
|
279
|
+
|
|
280
|
+
describe("resolveEditPlanOutput — what an edit never touches", () => {
|
|
281
|
+
it("chapters have no review: any edit is ignored", () => {
|
|
282
|
+
expect(resolveEditPlanOutput(CHAPTERS, cutEdit(CHAPTERS, { segments: [], dropped: [] })).status).toBe("invalid")
|
|
283
|
+
expect(resolveEditPlanOutput(CHAPTERS, undefined)).toEqual({ status: "none", json: CHAPTERS })
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it.each([
|
|
287
|
+
["null", null],
|
|
288
|
+
["a string", "edl"],
|
|
289
|
+
["a future version", { v: 2, kind: "edl", basis: editPlanBasis(TIGHTEN), edl: { segments: [], dropped: [] } }],
|
|
290
|
+
["an unknown kind", { v: 1, kind: "trim", basis: editPlanBasis(TIGHTEN) }],
|
|
291
|
+
["no basis", { v: 1, kind: "edl", edl: { segments: [], dropped: [] } }],
|
|
292
|
+
["no segments", { v: 1, kind: "edl", basis: editPlanBasis(TIGHTEN), edl: { dropped: [] } }],
|
|
293
|
+
["no dropped", { v: 1, kind: "edl", basis: editPlanBasis(TIGHTEN), edl: { segments: [] } }],
|
|
294
|
+
])("%s is invalid and ignored", (_label, edit) => {
|
|
295
|
+
const r = resolveEditPlanOutput(TIGHTEN, edit)
|
|
296
|
+
expect(r.status).toBe(edit === null ? "none" : "invalid")
|
|
297
|
+
expect(r.json).toBe(TIGHTEN)
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
it("a clip decision with a non-boolean keep or a non-string hook is invalid", () => {
|
|
301
|
+
expect(resolveEditPlanOutput(CLIPS, { ...clipsEdit(CLIPS, []), clips: [{ keep: "yes" }, { keep: true }, { keep: true }] }).status).toBe("invalid")
|
|
302
|
+
expect(resolveEditPlanOutput(CLIPS, { ...clipsEdit(CLIPS, []), clips: [{ keep: true, hook: 3 }, { keep: true }, { keep: true }] }).status).toBe("invalid")
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
// ── validateEditedEdl ───────────────────────────────────────────────────────
|
|
307
|
+
|
|
308
|
+
describe("validateEditedEdl — what a writer checks before saving an edit", () => {
|
|
309
|
+
it("a well-formed edit on this plan passes", () => {
|
|
310
|
+
const edit = cutEdit(TIGHTEN, { segments: [{ id: "seg-0", inMs: 0, outMs: 9000, video: "cam" }], dropped: [] })
|
|
311
|
+
expect(validateEditedEdl(edit, TIGHTEN)).toEqual({ ok: true, issues: [], warnings: [] })
|
|
312
|
+
expect(validateEditedEdl(clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true, hook: "h" }]), CLIPS).ok).toBe(true)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
it("names a stale basis", () => {
|
|
316
|
+
const r = validateEditedEdl(cutEdit(CHAPTERS, { segments: [], dropped: [] }), TIGHTEN)
|
|
317
|
+
expect(r.ok).toBe(false)
|
|
318
|
+
expect(r.issues.join(" ")).toMatch(/basis/)
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
it("adds the structural EDL issues of the edited cut (TA1 a: well-formed)", () => {
|
|
322
|
+
const edit = cutEdit(TIGHTEN, {
|
|
323
|
+
segments: [{ id: "seg-0", inMs: 0, outMs: 5000, video: "cam" }],
|
|
324
|
+
dropped: [{ inMs: 4000, outMs: 6000, reason: "silence" }],
|
|
325
|
+
})
|
|
326
|
+
const r = validateEditedEdl(edit, TIGHTEN)
|
|
327
|
+
expect(r.ok).toBe(false)
|
|
328
|
+
expect(r.issues.join(" ")).toMatch(/overlaps kept segment/)
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
it("names the basis, not the clip count, when the plan was re-run with fewer clips", () => {
|
|
332
|
+
const r = validateEditedEdl(clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true }]), [CLIPS[0], CLIPS[2]])
|
|
333
|
+
expect(r.ok).toBe(false)
|
|
334
|
+
expect(r.issues.join(" ")).toMatch(/basis/)
|
|
335
|
+
expect(r.issues.join(" ")).not.toMatch(/decisions/)
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
it("names the basis, not the plan's kind, when a clip set was re-run as Tighten", () => {
|
|
339
|
+
const r = validateEditedEdl(clipsEdit(CLIPS, [{ keep: true }, { keep: false }, { keep: true }]), TIGHTEN)
|
|
340
|
+
expect(r.ok).toBe(false)
|
|
341
|
+
expect(r.issues.join(" ")).toMatch(/basis/)
|
|
342
|
+
expect(r.issues.join(" ")).not.toMatch(/needs a clip set/)
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
it("names a misaligned clip decision list", () => {
|
|
346
|
+
const r = validateEditedEdl(clipsEdit(CLIPS, [{ keep: true }]), CLIPS)
|
|
347
|
+
expect(r.ok).toBe(false)
|
|
348
|
+
expect(r.issues.join(" ")).toMatch(/3 clips/)
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
it("names the envelope problem of a junk value", () => {
|
|
352
|
+
expect(validateEditedEdl("nope", TIGHTEN).ok).toBe(false)
|
|
353
|
+
expect(validateEditedEdl({ v: 1, kind: "edl", basis: "x" }, TIGHTEN).issues.length).toBeGreaterThan(0)
|
|
354
|
+
})
|
|
355
|
+
})
|
|
356
|
+
|
|
357
|
+
// ── TA14: a review edit is run-result data ──────────────────────────────────
|
|
358
|
+
|
|
359
|
+
describe("editedEdl is run-result data (TA14)", () => {
|
|
360
|
+
it("is an EXECUTION_DATA_KEYS member: out of undo, presets, templates and exports; wiped by Clear results", () => {
|
|
361
|
+
expect(EXECUTION_DATA_KEYS.has("editedEdl")).toBe(true)
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it("is persisted: not transient run state", () => {
|
|
365
|
+
expect(TRANSIENT_RUNTIME_KEYS.has("editedEdl")).toBe(false)
|
|
366
|
+
})
|
|
367
|
+
})
|
|
368
|
+
|
|
369
|
+
// ── reference FNV-1a-64 (BigInt; the test's own oracle) ─────────────────────
|
|
370
|
+
|
|
371
|
+
function fnv1a64Reference(text: string): string {
|
|
372
|
+
let h = 0xcbf29ce484222325n
|
|
373
|
+
const prime = 0x100000001b3n
|
|
374
|
+
for (const byte of new TextEncoder().encode(text)) {
|
|
375
|
+
h ^= BigInt(byte)
|
|
376
|
+
h = (h * prime) & 0xffffffffffffffffn
|
|
377
|
+
}
|
|
378
|
+
return h.toString(16).padStart(16, "0")
|
|
379
|
+
}
|
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
extractPresetData,
|
|
5
5
|
PRESET_EXCLUDED_KEYS,
|
|
6
6
|
PRESET_APPLY_CLEAR_KEYS,
|
|
7
|
+
PRESET_LEVER_GROUPS,
|
|
7
8
|
presetApplyClearKeys,
|
|
9
|
+
presetLeverClearKeys,
|
|
8
10
|
presetDataMatches,
|
|
9
11
|
} from "../node-preset-extract.js"
|
|
10
12
|
|
|
@@ -234,3 +236,63 @@ describe("Scene3D presets", () => {
|
|
|
234
236
|
expect(presetApplyClearKeys({ scenePrompt: "New scene" })).toContain("promptPrefix")
|
|
235
237
|
})
|
|
236
238
|
})
|
|
239
|
+
|
|
240
|
+
describe("caption lever group (applying a caption preset over another)", () => {
|
|
241
|
+
// The values of the Hook Plate, Body Captions and Clean Subtitles presets in @nodaro/prompts.
|
|
242
|
+
const HOOK_PLATE = { style: "subtitle", look: "clean", position: "top", positionY: 20, fontSize: 32, fontWeight: 800, maxWordsPerLine: 4, color: "#111111", backgroundColor: "#FFFFFF", autoTranscribe: false }
|
|
243
|
+
const BODY = { style: "word-highlight", look: "outline", position: "bottom", positionY: 72, fontSize: 32, maxWordsPerLine: 3, color: "#FFFFFF", autoTranscribe: true }
|
|
244
|
+
const CLEAN = { style: "subtitle", position: "bottom", fontSize: 32, color: "#FFFFFF", autoTranscribe: true }
|
|
245
|
+
const apply = (node: Record<string, unknown>, preset: Record<string, unknown>, nodeType?: string) => ({
|
|
246
|
+
...node,
|
|
247
|
+
...Object.fromEntries(presetApplyClearKeys(preset, nodeType).map((k) => [k, undefined])),
|
|
248
|
+
...preset,
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
it("Body Captions over Hook Plate clears the plate's backgroundColor and fontWeight", () => {
|
|
252
|
+
const after = apply(HOOK_PLATE, BODY, "add-captions")
|
|
253
|
+
expect(after.backgroundColor).toBeUndefined()
|
|
254
|
+
expect(after.fontWeight).toBeUndefined()
|
|
255
|
+
expect(after.look).toBe("outline")
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
it("Clean Subtitles over Hook Plate clears backgroundColor, look, positionY, fontWeight and maxWordsPerLine", () => {
|
|
259
|
+
const after = apply(HOOK_PLATE, CLEAN, "add-captions")
|
|
260
|
+
for (const k of ["backgroundColor", "look", "positionY", "fontWeight", "maxWordsPerLine"]) expect(after[k], k).toBeUndefined()
|
|
261
|
+
expect(after.position).toBe("bottom")
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
it("an existing caption preset over a clean node leaves no lever set", () => {
|
|
265
|
+
const after = apply({ style: "subtitle" }, CLEAN, "add-captions")
|
|
266
|
+
for (const k of PRESET_LEVER_GROUPS["add-captions"]!) expect(after[k], k).toBeUndefined()
|
|
267
|
+
expect(after).toMatchObject(CLEAN)
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it("never clears a lever the preset sets", () => {
|
|
271
|
+
for (const k of presetLeverClearKeys(HOOK_PLATE, "add-captions")) expect(HOOK_PLATE).not.toHaveProperty(k)
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it("empty preset data clears no group member", () => {
|
|
275
|
+
expect(presetLeverClearKeys({}, "add-captions")).toEqual([])
|
|
276
|
+
expect(presetLeverClearKeys({ style: undefined }, "add-captions")).toEqual([])
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
it("a node type with no group, or no node type, behaves as today", () => {
|
|
280
|
+
expect(presetLeverClearKeys(CLEAN, "generate-image")).toEqual([])
|
|
281
|
+
expect(presetLeverClearKeys(CLEAN)).toEqual([])
|
|
282
|
+
expect([...presetApplyClearKeys(CLEAN, "generate-image")].sort()).toEqual([...PRESET_APPLY_CLEAR_KEYS].sort())
|
|
283
|
+
expect([...presetApplyClearKeys(CLEAN)].sort()).toEqual([...PRESET_APPLY_CLEAR_KEYS].sort())
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
it("a hand-set fontFamily is cleared by any caption preset that does not set it (the stated cost)", () => {
|
|
287
|
+
expect(apply({ ...BODY, fontFamily: "Anton" }, CLEAN, "add-captions").fontFamily).toBeUndefined()
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
it("an inherited key name is not a node type", () => {
|
|
291
|
+
expect(presetLeverClearKeys(CLEAN, "constructor")).toEqual([])
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
it("group members stay capture-included, and PRESET_EXCLUDED_KEYS still covers PRESET_APPLY_CLEAR_KEYS", () => {
|
|
295
|
+
for (const k of PRESET_LEVER_GROUPS["add-captions"]!) expect(PRESET_EXCLUDED_KEYS.has(k), k).toBe(false)
|
|
296
|
+
for (const k of PRESET_APPLY_CLEAR_KEYS) expect(PRESET_EXCLUDED_KEYS.has(k), k).toBe(true)
|
|
297
|
+
})
|
|
298
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface CaptionWordTiming {
|
|
2
|
+
readonly text: string
|
|
3
|
+
readonly startMs: number
|
|
4
|
+
readonly endMs: number
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A caption plan: the opening line, where it ends, and the timed words that
|
|
9
|
+
* follow it. Times and words only — no styling travels on a plan; whoever
|
|
10
|
+
* renders it applies the look. Times are milliseconds from the video's start.
|
|
11
|
+
*/
|
|
12
|
+
/** The opening line and the body's words, timed. No styling. */
|
|
13
|
+
export interface CaptionPlan {
|
|
14
|
+
readonly v: 1
|
|
15
|
+
/** The opening line as written; sent as is, never trimmed. */
|
|
16
|
+
readonly hookText: string
|
|
17
|
+
/** Where the opening line ends; the body starts here. */
|
|
18
|
+
readonly hookEndMs: number
|
|
19
|
+
/** Where the body captions end, any tail included (the producer decides it). */
|
|
20
|
+
readonly bodyEndMs: number
|
|
21
|
+
/** The body's words, in milliseconds. */
|
|
22
|
+
readonly captions: readonly CaptionWordTiming[]
|
|
23
|
+
/** When known, the opening line and the body are clamped to it. */
|
|
24
|
+
readonly videoDurationMs?: number
|
|
25
|
+
/** Primary language tag: "en", "he", … */
|
|
26
|
+
readonly language?: string
|
|
27
|
+
}
|
package/src/competitors.ts
CHANGED
|
@@ -34,6 +34,15 @@ export const COMPETITORS_MAX = 50
|
|
|
34
34
|
|
|
35
35
|
export type CompetitorAccounts = Partial<Record<CompetitorAccountKey, string>>
|
|
36
36
|
|
|
37
|
+
/** A search of a brand: its account ("own") or its name ("about"). */
|
|
38
|
+
export type CompetitorSearchKind = "own" | "about"
|
|
39
|
+
|
|
40
|
+
/** One search a scan runs. */
|
|
41
|
+
export interface CompetitorSearch {
|
|
42
|
+
readonly kind: CompetitorSearchKind
|
|
43
|
+
readonly platform: SocialPlatform
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
export interface TrackedCompetitor {
|
|
38
47
|
readonly id: string
|
|
39
48
|
readonly brand: string
|
|
@@ -52,10 +61,37 @@ export interface TrackedCompetitor {
|
|
|
52
61
|
readonly scanning: boolean
|
|
53
62
|
/** Searches one scan runs; a scan costs this many Social Search pages. */
|
|
54
63
|
readonly searches: number
|
|
64
|
+
/** What the next scan searches. Absent from a server older than this field. */
|
|
65
|
+
readonly searchPlan?: readonly CompetitorSearch[]
|
|
55
66
|
readonly createdAt: string
|
|
56
67
|
readonly updatedAt: string
|
|
57
68
|
}
|
|
58
69
|
|
|
70
|
+
/** What a brand's latest scan found on one platform, and what works for it there. */
|
|
71
|
+
export interface CompetitorPlatformTally {
|
|
72
|
+
readonly platform: SocialPlatform
|
|
73
|
+
/** The brand's own posts the scan kept there. */
|
|
74
|
+
readonly own: number
|
|
75
|
+
/** Posts about the brand the scan kept there. */
|
|
76
|
+
readonly about: number
|
|
77
|
+
/** The searches the scan ran there. */
|
|
78
|
+
readonly searched: readonly CompetitorSearchKind[]
|
|
79
|
+
/** Of those, the ones that failed; null when the scan cannot say which (a scan stored before this was kept, that had failures). */
|
|
80
|
+
readonly failed: readonly CompetitorSearchKind[] | null
|
|
81
|
+
/** Its typical reach there, in `unit`; null while too few of its posts, or until its next scan. */
|
|
82
|
+
readonly usual: number | null
|
|
83
|
+
readonly unit: "views" | "points" | "likes" | null
|
|
84
|
+
/** What its best posts there share most strongly; null when nothing stands out, or until its next scan. */
|
|
85
|
+
readonly top: BrandLesson | null
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A brand's latest scan, platform by platform. */
|
|
89
|
+
export interface CompetitorBrandTally {
|
|
90
|
+
readonly scanId: string
|
|
91
|
+
readonly at: string
|
|
92
|
+
readonly platforms: readonly CompetitorPlatformTally[]
|
|
93
|
+
}
|
|
94
|
+
|
|
59
95
|
export const ACTION_CARD_KINDS = [
|
|
60
96
|
"outlier",
|
|
61
97
|
"launch",
|
|
@@ -129,6 +165,8 @@ export interface CompetitorScan {
|
|
|
129
165
|
/** `GET /v1/competitors/:id`. */
|
|
130
166
|
export interface CompetitorDetail extends TrackedCompetitor {
|
|
131
167
|
readonly latestScan: CompetitorScan | null
|
|
168
|
+
/** Its latest scan, platform by platform; null before its first scan. Absent from an older server. */
|
|
169
|
+
readonly platforms?: readonly CompetitorPlatformTally[] | null
|
|
132
170
|
/** Newest first, at most twelve. */
|
|
133
171
|
readonly scans: readonly CompetitorScanSummary[]
|
|
134
172
|
}
|
|
@@ -143,6 +181,8 @@ export interface CompetitorCardsResult {
|
|
|
143
181
|
* order of priorities never changes. Empty until there are verdicts.
|
|
144
182
|
*/
|
|
145
183
|
readonly record?: readonly AdviceRecord[]
|
|
184
|
+
/** Each tracked brand with a scan (by id): its latest scan, platform by platform. Absent from an older server. */
|
|
185
|
+
readonly brands?: Readonly<Record<string, CompetitorBrandTally>>
|
|
146
186
|
}
|
|
147
187
|
|
|
148
188
|
// ── Did it work? ("I did this" on a card) ─────────────────────────────────
|