@nodaro/shared 3.19.0 → 3.21.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 +182 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +182 -8
- package/dist/index.d.ts +182 -8
- package/dist/index.js +175 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/default-tts-provider.test.ts +46 -0
- package/src/__tests__/edit-plan-review.test.ts +379 -0
- package/src/__tests__/tts-capabilities.test.ts +4 -3
- package/src/competitors.ts +40 -0
- package/src/edit-plan-review.ts +323 -0
- package/src/index.ts +9 -0
- package/src/model-catalog.ts +3 -2
- package/src/model-constants.ts +13 -0
- package/src/node-runtime-keys.ts +5 -0
- package/src/producer-types.ts +15 -0
- package/src/voices.ts +11 -7
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_TTS_PROVIDER,
|
|
4
|
+
TTS_PROVIDERS,
|
|
5
|
+
MODEL_CATALOG,
|
|
6
|
+
MODEL_RECOMMENDATIONS,
|
|
7
|
+
getTtsCapabilities,
|
|
8
|
+
getMaxTtsChars,
|
|
9
|
+
} from "../index.js"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The speech model a request runs on when it names none. Every lane reads this one
|
|
13
|
+
* constant — the REST route's credit guard and handler, the workflow engine's
|
|
14
|
+
* text-to-speech dispatch, the worker's defensive default, the MCP `generate_speech`
|
|
15
|
+
* tool, the narration pipeline, the video director and the editor's new-node default —
|
|
16
|
+
* so none of them can run one model and bill another.
|
|
17
|
+
*
|
|
18
|
+
* This file is the ONE place the literal is pinned; every other test asserts against
|
|
19
|
+
* the constant.
|
|
20
|
+
*/
|
|
21
|
+
describe("DEFAULT_TTS_PROVIDER", () => {
|
|
22
|
+
it("is ElevenLabs v4 (the default flip, decided 2026-10-05)", () => {
|
|
23
|
+
expect(DEFAULT_TTS_PROVIDER).toBe("elevenlabs-v4")
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it("is a real text-to-speech model: listed, priced, with a complete capability sheet", () => {
|
|
27
|
+
expect(TTS_PROVIDERS).toContain(DEFAULT_TTS_PROVIDER)
|
|
28
|
+
const entry = MODEL_CATALOG[DEFAULT_TTS_PROVIDER]
|
|
29
|
+
expect(entry?.modes as readonly string[] | undefined).toContain("tts")
|
|
30
|
+
expect(entry?.pricing.map((p) => p.identifier)).toContain(DEFAULT_TTS_PROVIDER)
|
|
31
|
+
expect(getTtsCapabilities(DEFAULT_TTS_PROVIDER).maxChars).toBe(getMaxTtsChars(DEFAULT_TTS_PROVIDER))
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("is not the legacy `elevenlabs` alias (that id runs, and is billed, as turbo)", () => {
|
|
35
|
+
expect(DEFAULT_TTS_PROVIDER).not.toBe("elevenlabs")
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it("is the one featured speech model, and leads the narration recommendation", () => {
|
|
39
|
+
const featuredTts = Object.values(MODEL_CATALOG)
|
|
40
|
+
.filter((m) => (m.modes as readonly string[]).includes("tts") && m.featured === true)
|
|
41
|
+
.map((m) => m.id)
|
|
42
|
+
expect(featuredTts).toEqual([DEFAULT_TTS_PROVIDER])
|
|
43
|
+
const narration = MODEL_RECOMMENDATIONS.find((r) => r.intent === "voice over / narration")
|
|
44
|
+
expect(narration?.modelIds[0]).toBe(DEFAULT_TTS_PROVIDER)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -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
|
+
}
|
|
@@ -224,11 +224,12 @@ describe("elevenlabs-v4 — added beside v3", () => {
|
|
|
224
224
|
expect(getMaxTtsChars("elevenlabs-v3")).toBe(5000)
|
|
225
225
|
})
|
|
226
226
|
|
|
227
|
-
it("costs a flat 30 credits with no per-length note
|
|
227
|
+
it("costs a flat 30 credits with no per-length note — the same as v3 — and, as the default, is the featured model", () => {
|
|
228
228
|
const v4 = MODEL_CATALOG["elevenlabs-v4"]!
|
|
229
229
|
expect(v4.pricing).toEqual([{ identifier: "elevenlabs-v4", credits: 30 }])
|
|
230
|
-
expect(
|
|
231
|
-
expect(
|
|
230
|
+
expect(MODEL_CATALOG["elevenlabs-v3"]!.pricing).toEqual([{ identifier: "elevenlabs-v3", credits: 30 }])
|
|
231
|
+
expect(v4.featured).toBe(true)
|
|
232
|
+
expect(MODEL_CATALOG["elevenlabs-v3"]!.featured).toBeUndefined()
|
|
232
233
|
})
|
|
233
234
|
|
|
234
235
|
it("does not call v3 the latest model any more", () => {
|
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) ─────────────────────────────────
|