Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(document): sweep the trims that struck words through without cutting
EtienneLescot90d80b8e9302
diff --git a/src/lib/ai-edition/document/audioTracks.ts b/src/lib/ai-edition/document/audioTracks.tsindex 3ef9088c7..33f25e904 100644--- a/src/lib/ai-edition/document/audioTracks.ts+++ b/src/lib/ai-edition/document/audioTracks.ts@@ -18,11 +18,7 @@// outer edges only.import type { AxcutAudioTrack, AxcutClip, AxcutDocument } from "../schema";-import {- anchorRegionsWithDerivedMs,- clampSpanAgainstNeighbours,- coalesceRegionsForRuler,-} from "../timeline/timelineMap";+import { anchorRegionsWithDerivedMs, clampSpanAgainstNeighbours } from "../timeline/timelineMap";/** Every fragment of one user-visible track shares this key. */export function trackGroupId(track: AxcutAudioTrack): string {@@ -117,11 +113,6 @@ export function collapseTracksToPills(tracks: AxcutAudioTrack[]): AxcutAudioTrac});}-/** Lane pills for the ruler, one per user-visible track. */-export function audioTrackPills(tracks: AxcutAudioTrack[]) {- return coalesceRegionsForRuler(collapseTracksToPills(tracks));-}-/** Drop every fragment of a track, and its asset when nothing else needs it.** An imported audio asset is only ever reachable through its track — audio isdiff --git a/src/lib/ai-edition/document/migrate.test.ts b/src/lib/ai-edition/document/migrate.test.tsindex 49308129d..984faa795 100644--- a/src/lib/ai-edition/document/migrate.test.ts+++ b/src/lib/ai-edition/document/migrate.test.ts@@ -475,3 +475,117 @@ describe("migrateRawDocumentToCurrent", () => {expect(() => documentSchema.parse(upgraded)).not.toThrow();});});++// ─── The ghost trims of b9e0f1ff ─────────────────────────────────────────────+// That build let a cut authored from the voiceover lane be anchored on the AUDIO asset+// the words belonged to. It removed nothing from the film, the preview or the export —+// it only struck the word through. Now that both lanes read one removed set, leaving+// those rows behind would keep striking words through for a cut that never happened.++describe("dropping trims anchored to audio", () => {+ const createdAt = "2024-01-01T00:00:00.000Z";++ function docWith(trimRanges: unknown[], assets?: unknown[]) {+ return {+ schemaVersion: 7,+ project: { id: "p", title: "t", createdAt, updatedAt: createdAt },+ assets: assets ?? [+ { id: "vid", kind: "video", label: "v", originalPath: "/v.mp4", cameraTrack: null },+ { id: "aud", kind: "audio", label: "a", originalPath: "/a.mp3", cameraTrack: null },+ ],+ transcript: null,+ transcripts: [],+ timeline: {+ clips: [+ {+ id: "c1",+ assetId: "vid",+ sourceStartSec: 0,+ sourceEndSec: 10,+ timelineStartSec: 0,+ timelineEndSec: 10,+ wordRefs: [],+ origin: "user",+ reason: "",+ },+ ],+ gaps: [],+ trimRanges,+ muteRanges: [],+ speedRanges: [],+ captionRanges: [],+ },+ annotations: [],+ zoomRanges: [],+ audioTracks: [],+ legacyEditor: null,+ };+ }++ const trims = (raw: unknown) =>+ (+ (raw as Record<string, Record<string, unknown[]>>).timeline.trimRanges as Array<{+ id: string;+ }>+ ).map((t) => t.id);++ const ghost = {+ id: "ghost",+ assetId: "aud",+ clipId: "vo_frag",+ startSec: 1,+ endSec: 2,+ origin: "user",+ reason: "",+ };+ const legacy = {+ id: "legacy",+ assetId: "vid",+ startSec: 1,+ endSec: 2,+ origin: "user",+ reason: "",+ };+ const orphan = {+ id: "orphan",+ assetId: "vid",+ clipId: "deleted",+ startSec: 3,+ endSec: 4,+ origin: "user",+ reason: "",+ };++ it("drops a trim anchored to an audio asset", () => {+ expect(trims(migrateRawDocumentToCurrent(docWith([ghost, legacy])))).toEqual(["legacy"]);+ });++ it("keeps a pre-v7 trim that names no clip, and one whose clip is gone", () => {+ // The first is asset-wide back-compat; the second can still come back through undo.+ expect(trims(migrateRawDocumentToCurrent(docWith([legacy, orphan])))).toEqual([+ "legacy",+ "orphan",+ ]);+ });++ it("is idempotent, and returns the document untouched when there is nothing to sweep", () => {+ const clean = docWith([legacy]);+ expect(migrateRawDocumentToCurrent(clean)).toBe(clean);+ const swept = migrateRawDocumentToCurrent(docWith([ghost, legacy]));+ expect(migrateRawDocumentToCurrent(swept)).toBe(swept);+ });++ it("leaves a project with no audio asset entirely alone", () => {+ const noAudio = docWith(+ [legacy],+ [{ id: "vid", kind: "video", label: "v", originalPath: "/v.mp4", cameraTrack: null }],+ );+ expect(migrateRawDocumentToCurrent(noAudio)).toBe(noAudio);+ });++ it("still parses after the sweep", () => {+ expect(() =>+ documentSchema.parse(migrateRawDocumentToCurrent(docWith([ghost, legacy]))),+ ).not.toThrow();+ });+});diff --git a/src/lib/ai-edition/schema/index.ts b/src/lib/ai-edition/schema/index.tsindex fcfecebd3..8a715ab0e 100644--- a/src/lib/ai-edition/schema/index.ts+++ b/src/lib/ai-edition/schema/index.ts@@ -906,9 +906,59 @@ export function upgradeV6DocumentToV7(raw: unknown): unknown {* (`PROJECT_VERSION`) through the `@/` alias, which `vite-plugin-electron` does* not configure for the main bundle. Keep this module alias-free.*/+/**+ * Drop the ghost trims commit `b9e0f1ff` wrote (issue #560).+ *+ * That build let the transcript pane author a cut from the voiceover lane while still+ * anchoring it on whatever the words belonged to — an AUDIO asset and an audio fragment.+ * `resolvePlaybackSegments` matches no clip for such a row, so it removed nothing from the+ * film, the preview or the export; all it did was strike the word through. Now that both+ * lanes read the same removed set, leaving those rows behind would keep striking words+ * through for a cut that never existed.+ *+ * The test is exact and needs no clip lookup: an audio asset is never a clip's `assetId`+ * (audio is filtered out of the lists that make clips), so a trim naming one can only have+ * come from that build. An un-anchored pre-v7 trim names a VIDEO asset and is untouched;+ * so is a trim whose clip was deleted, which in-session undo can still bring back.+ *+ * No `schemaVersion` bump: nothing about the format changed, and no output moves — these+ * rows were already inert. What changes is that words the user "deleted" on that build+ * come back as kept, which is the correction, and belongs in the release note.+ *+ * Runs on RAW, untrusted input like the rest of the chain, so every read is guarded.+ */+function dropAudioAnchoredTrims(raw: unknown): unknown {+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return raw;+ const doc = raw as Record<string, unknown>;+ const assets = Array.isArray(doc.assets) ? doc.assets : null;+ if (!assets) return raw;+ const audioAssetIds = new Set<string>();+ for (const asset of assets) {+ if (!asset || typeof asset !== "object" || Array.isArray(asset)) continue;+ const entry = asset as Record<string, unknown>;+ if (entry.kind === "audio" && typeof entry.id === "string") audioAssetIds.add(entry.id);+ }+ if (audioAssetIds.size === 0) return raw;++ const timeline =+ doc.timeline && typeof doc.timeline === "object" && !Array.isArray(doc.timeline)+ ? (doc.timeline as Record<string, unknown>)+ : null;+ const trims = timeline && Array.isArray(timeline.trimRanges) ? timeline.trimRanges : null;+ if (!trims) return raw;++ const kept = trims.filter((entry) => {+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) return true;+ const trim = entry as Record<string, unknown>;+ return !(typeof trim.assetId === "string" && audioAssetIds.has(trim.assetId));+ });+ if (kept.length === trims.length) return raw;+ return { ...doc, timeline: { ...timeline, trimRanges: kept } };+}+export function migrateRawDocumentToCurrent(raw: unknown): unknown {- return upgradeV6DocumentToV7(- upgradeV5DocumentToV6(upgradeV4DocumentToV5(upgradeV3DocumentToV4(raw))),+ return dropAudioAnchoredTrims(+ upgradeV6DocumentToV7(upgradeV5DocumentToV6(upgradeV4DocumentToV5(upgradeV3DocumentToV4(raw)))),);}