Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

test(timeline): cover the branch #249 was actually about

EtienneLescota198cf647bf3
diff --git a/electron/ai-edition/document-service.test.ts b/electron/ai-edition/document-service.test.ts
index 43abada37..6cbdb97c9 100644
--- a/electron/ai-edition/document-service.test.ts
+++ b/electron/ai-edition/document-service.test.ts
@@ -367,6 +367,23 @@ describe("DocumentService", () => {
const created = await service.createProject("P");
const withA = await service.addAsset(created.project.id, { path: "/tmp/a.mp4" });
const withB = await service.addAsset(created.project.id, { path: "/tmp/b.mp4" });
+ // Four clips that differ only in id / asset / four numbers.
+ const clip = (
+ id: string,
+ assetId: string,
+ [sourceStartSec, sourceEndSec]: [number, number],
+ [timelineStartSec, timelineEndSec]: [number, number],
+ ) => ({
+ id,
+ assetId,
+ sourceStartSec,
+ sourceEndSec,
+ timelineStartSec,
+ timelineEndSec,
+ wordRefs: [],
+ origin: "user" as const,
+ reason: "test",
+ });
const assetA = withA.assets[0]?.id ?? "";
const assetB = withB.assets[1]?.id ?? "";
expect(assetA).toBeTruthy();
@@ -377,50 +394,10 @@ describe("DocumentService", () => {
timeline: {
...withB.timeline,
clips: [
- {
- id: "a_1",
- assetId: assetA,
- sourceStartSec: 0,
- sourceEndSec: 2,
- timelineStartSec: 0,
- timelineEndSec: 2,
- wordRefs: [],
- origin: "user",
- reason: "test",
- },
- {
- id: "b_1",
- assetId: assetB,
- sourceStartSec: 10,
- sourceEndSec: 14,
- timelineStartSec: 2,
- timelineEndSec: 6,
- wordRefs: [],
- origin: "user",
- reason: "test",
- },
- {
- id: "a_2",
- assetId: assetA,
- sourceStartSec: 2,
- sourceEndSec: 3,
- timelineStartSec: 6,
- timelineEndSec: 7,
- wordRefs: [],
- origin: "user",
- reason: "test",
- },
- {
- id: "b_2",
- assetId: assetB,
- sourceStartSec: 20,
- sourceEndSec: 22,
- timelineStartSec: 7,
- timelineEndSec: 9,
- wordRefs: [],
- origin: "user",
- reason: "test",
- },
+ clip("a_1", assetA, [0, 2], [0, 2]),
+ clip("b_1", assetB, [10, 14], [2, 6]),
+ clip("a_2", assetA, [2, 3], [6, 7]),
+ clip("b_2", assetB, [20, 22], [7, 9]),
],
},
zoomRanges: [
@@ -434,6 +411,18 @@ describe("DocumentService", () => {
depth: 3,
focus: { cx: 0.5, cy: 0.5 },
},
+ // Bare `clipId`, no source range: not an anchor, so removing the asset that owns
+ // `a_2` must NOT take it. This is what routes #249's fix through `removeAsset`
+ // -- the fully-anchored zoom above survives either way, so on its own it pins
+ // nothing about the predicate.
+ {
+ id: "zoom_partial_a_2",
+ clipId: "a_2",
+ startMs: 6000,
+ endMs: 7000,
+ depth: 3,
+ focus: { cx: 0.5, cy: 0.5 },
+ },
],
});
@@ -445,6 +434,9 @@ describe("DocumentService", () => {
]);
expect(after.zoomRanges).toEqual([
expect.objectContaining({ id: "zoom_b_2", startMs: 4500, endMs: 5500 }),
+ // Survives, and keeps its raw ms untouched -- now past the end of a 6s timeline.
+ // That is the documented trade-off in `removeClip`: unreachable beats deleted.
+ expect.objectContaining({ id: "zoom_partial_a_2", startMs: 6000, endMs: 7000 }),
]);
});
diff --git a/src/lib/ai-edition/document/timeline.test.ts b/src/lib/ai-edition/document/timeline.test.ts
index 420d571ef..e33d82662 100644
--- a/src/lib/ai-edition/document/timeline.test.ts
+++ b/src/lib/ai-edition/document/timeline.test.ts
@@ -1409,6 +1409,37 @@ describe("removeClip — delete a clip, close the gap, drop its pills", () => {
sourceStartSec: undefined,
sourceEndSec: undefined,
}),
+ // #249, and the branch nothing pinned: with no clip left, `removeClip` skips
+ // `rederiveRegionMs` entirely, so this filter is the only thing deciding. A bare
+ // `clipId` is not an anchor -- the region is still placed by its raw ms, so the
+ // clip going away must not take it. Without this case the ternary can be
+ // refactored back to the old semantics with a green suite.
+ makeZoom({
+ id: "partial_zoom",
+ clipId: "clip_a",
+ sourceStartSec: undefined,
+ sourceEndSec: undefined,
+ }),
+ // The same region after an in-memory edit that never round-tripped through zod:
+ // `null`, not `undefined`. The document layer used to call this one anchored
+ // (`!== undefined`) while the export path called it unanchored (`typeof`), and
+ // the two answers moved it to two different places -- `rederiveAnchoredRegion`
+ // slid it to `Math.max(null, ...)`, i.e. the clip start, while the exporter kept
+ // using its raw ms. One predicate now. Both halves get a case, because a single
+ // region carrying two `null`s still reads unanchored if only one check is
+ // loosened, and would pin neither.
+ makeZoom({
+ id: "null_start_zoom",
+ clipId: "clip_a",
+ sourceStartSec: null as unknown as undefined,
+ sourceEndSec: 1,
+ }),
+ makeZoom({
+ id: "null_end_zoom",
+ clipId: "clip_a",
+ sourceStartSec: 0,
+ sourceEndSec: null as unknown as undefined,
+ }),
],
annotations: [
{
@@ -1465,7 +1496,12 @@ describe("removeClip — delete a clip, close the gap, drop its pills", () => {
const next = removeClip(before, "clip_a");
expect(next.timeline.clips).toEqual([]);
- expect(next.zoomRanges.map((region) => region.id)).toEqual(["legacy_zoom"]);
+ expect(next.zoomRanges.map((region) => region.id)).toEqual([
+ "legacy_zoom",
+ "partial_zoom",
+ "null_start_zoom",
+ "null_end_zoom",
+ ]);
expect(next.annotations).toEqual([]);
expect((next.legacyEditor as { speedRegions: Array<{ id: string }> }).speedRegions).toEqual([
expect.objectContaining({ id: "legacy_speed" }),