@nodaro/shared 3.13.0 → 3.16.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 +1293 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1502 -30
- package/dist/index.d.ts +1502 -30
- package/dist/index.js +1134 -56
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/camera-switch-contract.test.ts +98 -0
- package/src/__tests__/competitors.test.ts +49 -0
- package/src/__tests__/content-recipe-ideas.test.ts +96 -0
- package/src/__tests__/edl-multicam.test.ts +192 -0
- package/src/__tests__/llm-models.test.ts +5 -2
- package/src/__tests__/music-provider.test.ts +17 -0
- package/src/__tests__/node-runtime-keys.test.ts +10 -0
- package/src/__tests__/parameter-node-value.test.ts +2 -1
- package/src/__tests__/per-unit-video-pricing.test.ts +97 -0
- package/src/__tests__/producer-types.test.ts +35 -0
- package/src/__tests__/saved-posts.test.ts +37 -0
- package/src/__tests__/script-settings.test.ts +61 -0
- package/src/__tests__/settings-input.test.ts +252 -0
- package/src/__tests__/social-search.test.ts +243 -0
- package/src/__tests__/studio-take-voice.test.ts +200 -0
- package/src/__tests__/studio-transient.test.ts +37 -0
- package/src/__tests__/sub-gates.test.ts +21 -0
- package/src/__tests__/telegram-account-trigger.test.ts +120 -0
- package/src/__tests__/video-analysis-pricing.test.ts +27 -13
- package/src/__tests__/video-link.test.ts +2 -2
- package/src/__tests__/video-utils.test.ts +89 -83
- package/src/__tests__/workflow-export-strip.test.ts +37 -0
- package/src/camera-switch-contract.ts +166 -0
- package/src/catalog-projection.ts +27 -0
- package/src/competitors.ts +430 -0
- package/src/content-recipe-ideas.ts +69 -0
- package/src/credit-estimators/index.ts +14 -0
- package/src/credit-estimators/ltx-extend.ts +33 -0
- package/src/credit-estimators/ltx-retake.ts +30 -0
- package/src/credit-estimators/video-sfx.ts +41 -0
- package/src/credit-estimators/video-utils.ts +38 -24
- package/src/credit-identifiers.ts +10 -0
- package/src/edl-multicam.ts +220 -0
- package/src/fan-out-rows.ts +7 -2
- package/src/i18n/action-fx.ko.ts +18 -18
- package/src/i18n/action-fx.pt-BR.ts +66 -66
- package/src/i18n/aesthetic.ko.ts +49 -49
- package/src/i18n/aesthetic.pt-BR.ts +14 -14
- package/src/i18n/animals.ko.ts +126 -126
- package/src/i18n/animals.pt-BR.ts +33 -33
- package/src/i18n/atmosphere.ko.ts +37 -37
- package/src/i18n/atmosphere.pt-BR.ts +29 -29
- package/src/i18n/backdrop.ko.ts +40 -40
- package/src/i18n/backdrop.pt-BR.ts +38 -38
- package/src/i18n/camera-format.ko.ts +31 -31
- package/src/i18n/camera-format.pt-BR.ts +12 -12
- package/src/i18n/camera-motions.ko.ts +66 -66
- package/src/i18n/camera-motions.pt-BR.ts +51 -51
- package/src/i18n/character-fx.ko.ts +19 -19
- package/src/i18n/character-fx.pt-BR.ts +64 -52
- package/src/i18n/character-motion.ko.ts +164 -164
- package/src/i18n/character-motion.pt-BR.ts +867 -858
- package/src/i18n/color-look.ko.ts +41 -41
- package/src/i18n/color-look.pt-BR.ts +23 -23
- package/src/i18n/composition-effects.ko.ts +18 -18
- package/src/i18n/composition-effects.pt-BR.ts +17 -17
- package/src/i18n/era.ko.ts +28 -28
- package/src/i18n/era.pt-BR.ts +20 -20
- package/src/i18n/exposure-settings.ko.ts +20 -20
- package/src/i18n/exposure-settings.pt-BR.ts +3 -3
- package/src/i18n/framing.ko.ts +66 -66
- package/src/i18n/framing.pt-BR.ts +50 -50
- package/src/i18n/furniture.ko.ts +78 -78
- package/src/i18n/furniture.pt-BR.ts +46 -46
- package/src/i18n/held-prop.ko.ts +60 -60
- package/src/i18n/held-prop.pt-BR.ts +30 -30
- package/src/i18n/instrumentation.ko.ts +62 -62
- package/src/i18n/instrumentation.pt-BR.ts +64 -64
- package/src/i18n/lens.ko.ts +16 -16
- package/src/i18n/lens.pt-BR.ts +5 -5
- package/src/i18n/lighting.ko.ts +68 -68
- package/src/i18n/lighting.pt-BR.ts +43 -43
- package/src/i18n/loop-subject.ko.ts +1 -1
- package/src/i18n/loop-subject.pt-BR.ts +31 -31
- package/src/i18n/materials.ko.ts +66 -66
- package/src/i18n/materials.pt-BR.ts +22 -22
- package/src/i18n/mood.ko.ts +50 -50
- package/src/i18n/mood.pt-BR.ts +12 -12
- package/src/i18n/music-genre.ko.ts +28 -28
- package/src/i18n/music-genre.pt-BR.ts +50 -50
- package/src/i18n/music-mood.ko.ts +27 -27
- package/src/i18n/music-mood.pt-BR.ts +20 -20
- package/src/i18n/person.ko.ts +396 -396
- package/src/i18n/person.pt-BR.ts +237 -237
- package/src/i18n/photo-genre.ko.ts +46 -46
- package/src/i18n/photo-genre.pt-BR.ts +32 -32
- package/src/i18n/photographer.ko.ts +63 -63
- package/src/i18n/photographer.pt-BR.ts +15 -15
- package/src/i18n/pose.ko.ts +81 -81
- package/src/i18n/pose.pt-BR.ts +65 -65
- package/src/i18n/post-process-effects.ko.ts +18 -18
- package/src/i18n/post-process-effects.pt-BR.ts +18 -18
- package/src/i18n/render-quality.ko.ts +24 -24
- package/src/i18n/render-quality.pt-BR.ts +12 -12
- package/src/i18n/setting.ko.ts +64 -64
- package/src/i18n/setting.pt-BR.ts +41 -41
- package/src/i18n/style.ko.ts +49 -49
- package/src/i18n/style.pt-BR.ts +19 -19
- package/src/i18n/styling.ko.ts +265 -265
- package/src/i18n/styling.pt-BR.ts +141 -141
- package/src/i18n/temporal.ko.ts +18 -18
- package/src/i18n/temporal.pt-BR.ts +12 -12
- package/src/i18n/transitions.ko.ts +14 -14
- package/src/i18n/transitions.pt-BR.ts +83 -71
- package/src/i18n/vehicles.ko.ts +107 -107
- package/src/i18n/vehicles.pt-BR.ts +55 -55
- package/src/i18n/voice-character.ko.ts +19 -19
- package/src/i18n/voice-character.pt-BR.ts +19 -19
- package/src/i18n/voice-delivery.ko.ts +22 -22
- package/src/i18n/voice-delivery.pt-BR.ts +22 -22
- package/src/i18n/weapons.ko.ts +85 -85
- package/src/i18n/weapons.pt-BR.ts +46 -46
- package/src/index.ts +202 -1
- package/src/llm-models.ts +11 -0
- package/src/model-catalog.ts +30 -14
- package/src/model-constants.ts +28 -0
- package/src/node-mappable-fields.ts +21 -5
- package/src/node-runtime-keys.ts +33 -0
- package/src/oauth-scopes.ts +28 -0
- package/src/parameter-node-value.ts +13 -5
- package/src/pipeline-defaults.ts +14 -0
- package/src/pipeline-state-types.ts +14 -0
- package/src/producer-types.ts +85 -0
- package/src/recast-segment-packs.ts +13 -0
- package/src/resolve-field-mappings.ts +15 -5
- package/src/saved-posts.ts +106 -0
- package/src/script-settings.ts +70 -0
- package/src/settings-input.ts +366 -0
- package/src/social-search.ts +467 -0
- package/src/studio-transient.ts +176 -5
- package/src/telegram-account-send.ts +32 -0
- package/src/telegram-account-trigger.ts +108 -0
- package/src/video-analysis-pricing.ts +17 -6
- package/src/video-link.ts +16 -4
- package/src/workflow-export.ts +7 -0
|
@@ -3,6 +3,10 @@ import {
|
|
|
3
3
|
AUDIO_PRODUCER_TYPES,
|
|
4
4
|
VIDEO_PRODUCER_TYPES,
|
|
5
5
|
DYNAMIC_PRODUCER_TYPES,
|
|
6
|
+
FAN_OUT_EACH_TYPES,
|
|
7
|
+
FAN_OUT_EACH_HANDLES,
|
|
8
|
+
defaultEdgeOutputMode,
|
|
9
|
+
listResultsServeHandle,
|
|
6
10
|
} from "../producer-types.js"
|
|
7
11
|
import { getOutputType } from "../presentation-utils.js"
|
|
8
12
|
|
|
@@ -102,3 +106,34 @@ describe("producer-types", () => {
|
|
|
102
106
|
expect(VIDEO_PRODUCER_TYPES.has("video-overlay")).toBe(true)
|
|
103
107
|
})
|
|
104
108
|
})
|
|
109
|
+
|
|
110
|
+
// Per-handle "each" defaults (decided 2026-10-04): Camera Switch run once per
|
|
111
|
+
// clip fans its EDL out to one render per clip, while its transcript — the same
|
|
112
|
+
// for every clip — stays one value, in every mode.
|
|
113
|
+
describe("defaultEdgeOutputMode / listResultsServeHandle", () => {
|
|
114
|
+
it("a FAN_OUT_EACH_TYPES source defaults to each on every handle; anything else to last", () => {
|
|
115
|
+
expect(defaultEdgeOutputMode("edit-plan", "edl")).toBe("each")
|
|
116
|
+
expect(defaultEdgeOutputMode("list", undefined)).toBe("each")
|
|
117
|
+
expect(defaultEdgeOutputMode("transcribe", "json")).toBe("last")
|
|
118
|
+
expect(defaultEdgeOutputMode(undefined, "edl")).toBe("last")
|
|
119
|
+
})
|
|
120
|
+
it("Camera Switch: the EDL handle (and no handle = its primary, the EDL) is each; the transcript is last", () => {
|
|
121
|
+
expect(defaultEdgeOutputMode("camera-switch", "edl")).toBe("each")
|
|
122
|
+
expect(defaultEdgeOutputMode("camera-switch", undefined)).toBe("each")
|
|
123
|
+
expect(defaultEdgeOutputMode("camera-switch", null)).toBe("each")
|
|
124
|
+
expect(defaultEdgeOutputMode("camera-switch", "transcript")).toBe("last")
|
|
125
|
+
})
|
|
126
|
+
it("only the each handles read the per-iteration results", () => {
|
|
127
|
+
expect(listResultsServeHandle("camera-switch", "edl")).toBe(true)
|
|
128
|
+
expect(listResultsServeHandle("camera-switch", undefined)).toBe(true)
|
|
129
|
+
expect(listResultsServeHandle("camera-switch", "transcript")).toBe(false)
|
|
130
|
+
expect(listResultsServeHandle("generate-image", "image")).toBe(true)
|
|
131
|
+
})
|
|
132
|
+
it("every per-handle entry names a primary and is not also a whole-node each type", () => {
|
|
133
|
+
for (const [type, entry] of Object.entries(FAN_OUT_EACH_HANDLES)) {
|
|
134
|
+
expect(entry.each.length, type).toBeGreaterThan(0)
|
|
135
|
+
expect(entry.primary, type).toBeTruthy()
|
|
136
|
+
expect(FAN_OUT_EACH_TYPES.has(type), type).toBe(false)
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { SAVED_POST_MAX_TAGS, SAVED_POST_TAG_MAX, normalizeSavedPostTags } from "../index.js"
|
|
3
|
+
|
|
4
|
+
describe("normalizeSavedPostTags", () => {
|
|
5
|
+
it("trims, lower-cases, drops a leading # and collapses inner spaces", () => {
|
|
6
|
+
expect(normalizeSavedPostTags([" #Hooks ", "Cold Open"])).toEqual(["hooks", "cold open"])
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it("drops empty tags, repeats and anything that is not text", () => {
|
|
10
|
+
expect(normalizeSavedPostTags(["a", "A", "#a", "", " ", 7, null, "b"])).toEqual(["a", "b"])
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it("caps each tag and the number of tags", () => {
|
|
14
|
+
const many = Array.from({ length: SAVED_POST_MAX_TAGS + 5 }, (_, i) => `tag${i}`)
|
|
15
|
+
expect(normalizeSavedPostTags(many)).toHaveLength(SAVED_POST_MAX_TAGS)
|
|
16
|
+
expect(normalizeSavedPostTags(["x".repeat(100)])[0]).toHaveLength(SAVED_POST_TAG_MAX)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it("reads anything that is not a list as no tags", () => {
|
|
20
|
+
expect(normalizeSavedPostTags("hooks")).toEqual([])
|
|
21
|
+
expect(normalizeSavedPostTags(undefined)).toEqual([])
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it("keeps tags in other scripts", () => {
|
|
25
|
+
expect(normalizeSavedPostTags(["#פתיחה", "フック"])).toEqual(["פתיחה", "フック"])
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it("splits on commas in any script, so one typed line can hold several tags", () => {
|
|
29
|
+
expect(normalizeSavedPostTags(["hooks, openers"])).toEqual(["hooks", "openers"])
|
|
30
|
+
expect(normalizeSavedPostTags(["フック、書き出し"])).toEqual(["フック", "書き出し"])
|
|
31
|
+
expect(normalizeSavedPostTags(["훅,오프닝"])).toEqual(["훅", "오프닝"])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("removes the characters that would change a tag filter's meaning", () => {
|
|
35
|
+
expect(normalizeSavedPostTags(['ho}o{ks', 'say "hi"', "back\\slash"])).toEqual(["hooks", "say hi", "backslash"])
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
readScriptSettings,
|
|
4
|
+
SCRIPT_SCENE_COUNT_RANGE,
|
|
5
|
+
SCRIPT_TARGET_DURATION_RANGE,
|
|
6
|
+
SCRIPT_TONE_MAX_LENGTH,
|
|
7
|
+
} from "../script-settings.js"
|
|
8
|
+
|
|
9
|
+
describe("readScriptSettings", () => {
|
|
10
|
+
it("passes typed values through", () => {
|
|
11
|
+
expect(readScriptSettings({ sceneCount: 4, tone: "dramatic", targetLength: 90, styleGuide: "noir" })).toEqual({
|
|
12
|
+
sceneCount: 4,
|
|
13
|
+
tone: "dramatic",
|
|
14
|
+
targetDuration: 90,
|
|
15
|
+
styleGuide: "noir",
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it("turns a number given as text into a whole number (a mapped Scene Count / Duration node)", () => {
|
|
20
|
+
const s = readScriptSettings({ sceneCount: "7", targetLength: "44.6" })
|
|
21
|
+
expect(s.sceneCount).toBe(7)
|
|
22
|
+
expect(s.targetDuration).toBe(45)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it("clamps numbers to the route's ranges", () => {
|
|
26
|
+
expect(readScriptSettings({ sceneCount: 0, targetLength: 1 })).toMatchObject({
|
|
27
|
+
sceneCount: SCRIPT_SCENE_COUNT_RANGE.min,
|
|
28
|
+
targetDuration: SCRIPT_TARGET_DURATION_RANGE.min,
|
|
29
|
+
})
|
|
30
|
+
expect(readScriptSettings({ sceneCount: 500, targetLength: 99999 })).toMatchObject({
|
|
31
|
+
sceneCount: SCRIPT_SCENE_COUNT_RANGE.max,
|
|
32
|
+
targetDuration: SCRIPT_TARGET_DURATION_RANGE.max,
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it("drops a value it cannot use, so the generator's default applies", () => {
|
|
37
|
+
const s = readScriptSettings({ sceneCount: "many", targetLength: "", tone: " ", styleGuide: 42 })
|
|
38
|
+
expect(s).toEqual({ sceneCount: undefined, tone: undefined, targetDuration: undefined, styleGuide: undefined })
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it("trims text and cuts the tone to its limit", () => {
|
|
42
|
+
const s = readScriptSettings({ tone: ` ${"a".repeat(SCRIPT_TONE_MAX_LENGTH + 50)} `, styleGuide: " warm " })
|
|
43
|
+
expect(s.tone).toHaveLength(SCRIPT_TONE_MAX_LENGTH)
|
|
44
|
+
expect(s.styleGuide).toBe("warm")
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it("reads the older keys only when the panel's field is absent", () => {
|
|
48
|
+
expect(readScriptSettings({ style: "somber", targetDuration: 30 })).toMatchObject({ tone: "somber", targetDuration: 30 })
|
|
49
|
+
expect(readScriptSettings({ tone: "bright", style: "somber", targetLength: 20, targetDuration: 30 })).toMatchObject({
|
|
50
|
+
tone: "bright",
|
|
51
|
+
targetDuration: 20,
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it("resolves {Node Label} references in the style guide only", () => {
|
|
56
|
+
const refMap = new Map([["Brand", "teal and coral, rounded type"]])
|
|
57
|
+
const s = readScriptSettings({ styleGuide: "Use {Brand}. Keep {Missing} as typed.", tone: "{Brand}" }, refMap)
|
|
58
|
+
expect(s.styleGuide).toBe("Use teal and coral, rounded type. Keep {Missing} as typed.")
|
|
59
|
+
expect(s.tone).toBe("{Brand}")
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
SETTINGS_INPUT_CONSUMERS,
|
|
4
|
+
SETTINGS_INPUT_HANDLE,
|
|
5
|
+
applySettingsInput,
|
|
6
|
+
connectedSettingsSources,
|
|
7
|
+
resolveWiredSettings,
|
|
8
|
+
settingsInputAccepts,
|
|
9
|
+
settingsInputFields,
|
|
10
|
+
settingsProviderModels,
|
|
11
|
+
settingsSourceForField,
|
|
12
|
+
snapToModelDuration,
|
|
13
|
+
withWiredSettings,
|
|
14
|
+
isSettingsHintEdge,
|
|
15
|
+
} from "../settings-input.js"
|
|
16
|
+
import { NODE_MAPPABLE_FIELDS } from "../node-mappable-fields.js"
|
|
17
|
+
import { DEFAULT_VIDEO_PROVIDER, GVP_SUPPORTED_PROVIDERS, IMAGE_GEN_PROVIDERS, VIDEO_GEN_PROVIDERS } from "../model-constants.js"
|
|
18
|
+
import { fitAspectRatioToModel, normalizeVideoRequestParams } from "../model-catalog.js"
|
|
19
|
+
|
|
20
|
+
const nodes = [
|
|
21
|
+
{ id: "gv", type: "generate-video", data: { provider: "seedance-2", duration: 8, aspectRatio: "16:9" } },
|
|
22
|
+
{ id: "gi", type: "generate-image", data: { provider: "nano-banana-pro", providers: ["nano-banana-pro", "seedream"], aspectRatio: "16:9" } },
|
|
23
|
+
{ id: "nb", type: "provider", data: { label: "Image model", category: "image", provider: "nano-banana" } },
|
|
24
|
+
{ id: "gvp", type: "generate-video-pro", data: { provider: "seedance-2", duration: 30 } },
|
|
25
|
+
{ id: "ratio", type: "aspect-ratio", data: { label: "Aspect Ratio", ratio: "9:16" } },
|
|
26
|
+
{ id: "len", type: "duration", data: { label: "Duration", seconds: 60 } },
|
|
27
|
+
{ id: "len2", type: "duration", data: { label: "Short", seconds: 5 } },
|
|
28
|
+
{ id: "veo", type: "provider", data: { label: "Provider", category: "video", provider: "veo3" } },
|
|
29
|
+
{ id: "img", type: "provider", data: { label: "Image model", category: "image", provider: "nano-banana" } },
|
|
30
|
+
{ id: "tone", type: "tone", data: { label: "Tone", tone: "calm" } },
|
|
31
|
+
]
|
|
32
|
+
const typeOf = (id: string) => nodes.find((n) => n.id === id)?.type
|
|
33
|
+
const wire = (source: string, target = "gv", targetHandle: string = SETTINGS_INPUT_HANDLE) => ({ source, target, targetHandle })
|
|
34
|
+
|
|
35
|
+
describe("Settings input consumers", () => {
|
|
36
|
+
it("takes Aspect Ratio, Duration and Provider on Generate Video", () => {
|
|
37
|
+
for (const t of ["aspect-ratio", "duration", "provider"]) expect(settingsInputAccepts("generate-video", t)).toBe(true)
|
|
38
|
+
expect(settingsInputAccepts("generate-video", "tone")).toBe(false)
|
|
39
|
+
expect(settingsInputAccepts("generate-image", "duration")).toBe(false)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Generate Video Pro re-exports Generate Video's handle validator, which asks
|
|
43
|
+
// for "generate-video"'s list — so the two lists must be the same.
|
|
44
|
+
it("gives Generate Video Pro exactly Generate Video's settings", () => {
|
|
45
|
+
expect(SETTINGS_INPUT_CONSUMERS["generate-video-pro"]).toEqual(SETTINGS_INPUT_CONSUMERS["generate-video"])
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it("lists every field it sets as mappable, so both engines resolve it", () => {
|
|
49
|
+
for (const consumer of Object.keys(SETTINGS_INPUT_CONSUMERS)) {
|
|
50
|
+
for (const field of settingsInputFields(consumer)) expect(NODE_MAPPABLE_FIELDS[consumer]).toContain(field)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it("accepts each consumer's own models", () => {
|
|
55
|
+
expect(settingsProviderModels("generate-video")).toEqual(VIDEO_GEN_PROVIDERS)
|
|
56
|
+
expect(settingsProviderModels("generate-video-pro")).toEqual(GVP_SUPPORTED_PROVIDERS)
|
|
57
|
+
expect(settingsProviderModels("generate-image")).toEqual(IMAGE_GEN_PROVIDERS)
|
|
58
|
+
expect(settingsProviderModels("llm-chat")).toEqual([])
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it("takes Aspect Ratio and Provider on Generate Image, and no Duration", () => {
|
|
62
|
+
expect(settingsInputAccepts("generate-image", "aspect-ratio")).toBe(true)
|
|
63
|
+
expect(settingsInputAccepts("generate-image", "provider")).toBe(true)
|
|
64
|
+
expect(settingsInputAccepts("generate-image", "duration")).toBe(false)
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
describe("settingsSourceForField", () => {
|
|
69
|
+
it("finds the node that sets a field, and the last edge of a kind wins", () => {
|
|
70
|
+
const edges = [wire("len"), wire("len2")]
|
|
71
|
+
expect(settingsSourceForField("gv", "generate-video", "duration", edges, typeOf)).toBe("len2")
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it("ignores other handles, other targets and nodes the input does not take", () => {
|
|
75
|
+
const edges = [wire("len", "gv", "prompt"), wire("len", "other"), wire("tone")]
|
|
76
|
+
expect(settingsSourceForField("gv", "generate-video", "duration", edges, typeOf)).toBeUndefined()
|
|
77
|
+
expect(connectedSettingsSources("gv", "generate-video", edges, typeOf)).toEqual([])
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it("lists one source per kind, in the consumer's order", () => {
|
|
81
|
+
const edges = [wire("veo"), wire("len"), wire("ratio")]
|
|
82
|
+
expect(connectedSettingsSources("gv", "generate-video", edges, typeOf).map((c) => c.field)).toEqual(["aspectRatio", "duration", "provider"])
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe("snapToModelDuration", () => {
|
|
87
|
+
it("fits a length to the nearest one the model renders", () => {
|
|
88
|
+
expect(snapToModelDuration("seedance-2", 60)).toBe(15)
|
|
89
|
+
expect(snapToModelDuration("seedance-2", 1)).toBe(4)
|
|
90
|
+
expect(snapToModelDuration("veo3", 8)).toBe(8)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it("breaks a tie toward the shorter length, as the provider does", () => {
|
|
94
|
+
expect(snapToModelDuration("veo3", 7)).toBe(6)
|
|
95
|
+
expect(snapToModelDuration("grok-i2v", 8)).toBe(6)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it("keeps the value for a model without a duration list", () => {
|
|
99
|
+
expect(snapToModelDuration("not-a-model", 42)).toBe(42)
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
describe("applySettingsInput", () => {
|
|
104
|
+
const data = { provider: "veo3", duration: "60", aspectRatio: "4:5" }
|
|
105
|
+
|
|
106
|
+
it("changes nothing when no setting is wired", () => {
|
|
107
|
+
expect(applySettingsInput("generate-video", "gv", data, [], typeOf)).toEqual({ data })
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it("fits a wired Duration and Aspect Ratio to the model", () => {
|
|
111
|
+
const edges = [wire("len"), wire("ratio"), wire("veo")]
|
|
112
|
+
expect(applySettingsInput("generate-video", "gv", data, edges, typeOf).data).toMatchObject({ duration: 8, aspectRatio: "9:16" })
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it("fits to the node's default model when no model is set", () => {
|
|
116
|
+
const edges = [wire("len")]
|
|
117
|
+
const fitted = applySettingsInput("generate-video", "gv", { duration: "60" }, edges, typeOf).data
|
|
118
|
+
expect(fitted.duration).toBe(snapToModelDuration(DEFAULT_VIDEO_PROVIDER, 60))
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it("keeps Generate Video Pro's total length — its engine stitches and clamps it", () => {
|
|
122
|
+
const edges = [wire("len", "gvp")]
|
|
123
|
+
expect(applySettingsInput("generate-video-pro", "gvp", { provider: "seedance-2", duration: "60" }, edges, typeOf).data.duration).toBe("60")
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it("refuses a wired Provider naming a model the node does not run", () => {
|
|
127
|
+
const edges = [wire("img")]
|
|
128
|
+
const result = applySettingsInput("generate-video", "gv", { provider: "nano-banana" }, edges, typeOf)
|
|
129
|
+
expect(result.problem).toEqual({ kind: "provider-not-accepted", sourceId: "img", value: "nano-banana" })
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it("refuses a video model outside Generate Video Pro's models", () => {
|
|
133
|
+
const edges = [wire("veo", "gvp")]
|
|
134
|
+
const result = applySettingsInput("generate-video-pro", "gvp", { provider: "veo3" }, edges, typeOf)
|
|
135
|
+
expect(result.problem?.sourceId).toBe("veo")
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
describe("Generate Image", () => {
|
|
140
|
+
const wireImage = (source: string) => wire(source, "gi")
|
|
141
|
+
|
|
142
|
+
it("a wired Provider makes a several-model node one model", () => {
|
|
143
|
+
const resolved = resolveWiredSettings("gi", "generate-image", nodes[1]!.data, nodes, [wireImage("nb")])
|
|
144
|
+
expect(resolved.data).toMatchObject({ provider: "nano-banana", providers: ["nano-banana"] })
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it("refuses a video model", () => {
|
|
148
|
+
expect(resolveWiredSettings("gi", "generate-image", nodes[1]!.data, nodes, [wireImage("veo")]).problem?.value).toBe("veo3")
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it("fits a wired ratio to the image model", () => {
|
|
152
|
+
const resolved = resolveWiredSettings("gi", "generate-image", nodes[1]!.data, nodes, [wireImage("ratio")])
|
|
153
|
+
expect(resolved.data.aspectRatio).toBe(fitAspectRatioToModel("nano-banana-pro", "9:16"))
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it("leaves the model list alone when no Provider is wired", () => {
|
|
157
|
+
const resolved = resolveWiredSettings("gi", "generate-image", nodes[1]!.data, nodes, [wireImage("ratio")])
|
|
158
|
+
expect(resolved.data.providers).toEqual(["nano-banana-pro", "seedream"])
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
describe("fitAspectRatioToModel", () => {
|
|
163
|
+
it("keeps a ratio the model lists, in the catalog's spelling", () => {
|
|
164
|
+
expect(fitAspectRatioToModel("seedance-2", "16:9")).toBe("16:9")
|
|
165
|
+
expect(fitAspectRatioToModel("seedance-2", "ADAPTIVE")).toBe("ADAPTIVE")
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it("fits an unlisted ratio to the nearest listed one, keeping its orientation", () => {
|
|
169
|
+
expect(fitAspectRatioToModel("seedance-2", "4:5")).toBe("3:4")
|
|
170
|
+
expect(fitAspectRatioToModel("veo3", "4:5")).toBe("9:16")
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
it("passes through for a model without a ratio list or an unknown model", () => {
|
|
174
|
+
expect(fitAspectRatioToModel("kling-3.0", "4:5")).toBe("4:5")
|
|
175
|
+
expect(fitAspectRatioToModel("not-a-model", "4:5")).toBe("4:5")
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
// The video lane's normalizer applies the same rule — one implementation.
|
|
179
|
+
it("agrees with the video lane's normalizer", () => {
|
|
180
|
+
for (const ratio of ["4:5", "21:9", "1:1", "5:4", "2:3"]) {
|
|
181
|
+
expect(normalizeVideoRequestParams("seedance-2", { aspectRatio: ratio }).aspectRatio).toBe(fitAspectRatioToModel("seedance-2", ratio))
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
describe("withWiredSettings", () => {
|
|
187
|
+
it("returns the node as it runs, and the node itself without the graph", () => {
|
|
188
|
+
const image = nodes[1]!
|
|
189
|
+
expect(withWiredSettings(image, nodes, [wire("nb", "gi")]).data).toMatchObject({ providers: ["nano-banana"] })
|
|
190
|
+
expect(withWiredSettings(image)).toBe(image)
|
|
191
|
+
expect(withWiredSettings({ id: "t", type: "tone", data: {} }, nodes, [])).toEqual({ id: "t", type: "tone", data: {} })
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
describe("Motion (a prompt-clause setting)", () => {
|
|
196
|
+
const motion = { id: "mo", type: "motion", data: { label: "Motion", motion: "subtle" } }
|
|
197
|
+
const motion2 = { id: "mo2", type: "motion", data: { label: "Motion 2", motion: "dynamic" } }
|
|
198
|
+
const graph = [...nodes, motion, motion2]
|
|
199
|
+
const typeOfGraph = (id: string) => graph.find((n) => n.id === id)?.type
|
|
200
|
+
|
|
201
|
+
it("is taken by the video nodes, not by Generate Image, and sets no field", () => {
|
|
202
|
+
expect(settingsInputAccepts("generate-video", "motion")).toBe(true)
|
|
203
|
+
expect(settingsInputAccepts("generate-video-pro", "motion")).toBe(true)
|
|
204
|
+
expect(settingsInputAccepts("generate-image", "motion")).toBe(false)
|
|
205
|
+
expect(settingsInputFields("generate-video")).toEqual(["aspectRatio", "duration", "provider"])
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
it("is listed as wired, without a field, and writes nothing into the data", () => {
|
|
209
|
+
const resolved = resolveWiredSettings("gv", "generate-video", nodes[0]!.data, graph, [wire("mo")])
|
|
210
|
+
expect(resolved.wired).toEqual([{ sourceType: "motion", sourceId: "mo", value: "subtle" }])
|
|
211
|
+
expect(resolved.data).toEqual(nodes[0]!.data)
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
it("brings its clause only from the last Motion wired", () => {
|
|
215
|
+
const edges = [wire("mo"), wire("mo2")]
|
|
216
|
+
expect(isSettingsHintEdge(edges[0]!, "generate-video", edges, typeOfGraph)).toBe(false)
|
|
217
|
+
expect(isSettingsHintEdge(edges[1]!, "generate-video", edges, typeOfGraph)).toBe(true)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it("brings no clause into a node that does not take it, or through another handle", () => {
|
|
221
|
+
expect(isSettingsHintEdge(wire("mo", "gi"), "generate-image", [wire("mo", "gi")], typeOfGraph)).toBe(false)
|
|
222
|
+
expect(isSettingsHintEdge(wire("mo", "gv", "look"), "generate-video", [wire("mo", "gv", "look")], typeOfGraph)).toBe(false)
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it("does not count as the field setting of its kind", () => {
|
|
226
|
+
expect(settingsSourceForField("gv", "generate-video", "duration", [wire("mo")], typeOfGraph)).toBeUndefined()
|
|
227
|
+
})
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
describe("resolveWiredSettings", () => {
|
|
231
|
+
it("writes each wired value in and fits it, as the engines do", () => {
|
|
232
|
+
const edges = [wire("len"), wire("ratio"), wire("veo")]
|
|
233
|
+
const resolved = resolveWiredSettings("gv", "generate-video", nodes[0]!.data, nodes, edges)
|
|
234
|
+
expect(resolved.data).toMatchObject({ provider: "veo3", duration: 8, aspectRatio: "9:16" })
|
|
235
|
+
expect(resolved.wired.map((w) => [w.field, w.value])).toEqual([
|
|
236
|
+
["aspectRatio", "9:16"],
|
|
237
|
+
["duration", "60"],
|
|
238
|
+
["provider", "veo3"],
|
|
239
|
+
])
|
|
240
|
+
expect(resolved.problem).toBeUndefined()
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it("reports a Provider the node cannot run", () => {
|
|
244
|
+
const resolved = resolveWiredSettings("gv", "generate-video", nodes[0]!.data, nodes, [wire("img")])
|
|
245
|
+
expect(resolved.problem?.value).toBe("nano-banana")
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it("returns the node's own data when nothing is wired", () => {
|
|
249
|
+
const resolved = resolveWiredSettings("gv", "generate-video", nodes[0]!.data, nodes, [])
|
|
250
|
+
expect(resolved).toEqual({ data: nodes[0]!.data, wired: [] })
|
|
251
|
+
})
|
|
252
|
+
})
|
|
@@ -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
|
+
})
|