From 1505d3ff101ac9812516550ffbf718e25bf566c9 Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Tue, 4 Aug 2026 12:54:01 -0700 Subject: [PATCH] fix(studio): make automationLaneData reviewable, and evict one entry not all MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cache key held a literal NUL byte instead of its escape, so git classified the whole module as binary: it landed as `Bin 0 -> 2677 bytes` with zero diffable lines, invisible to review, to grep, and to any textual merge. The escape is behaviour-identical. With the file readable, two things in it needed fixing. Eviction cleared the entire map. Clearing changes the identity of every lane's automation at once, and a lane compares its drag draft against that identity — so one unrelated element arriving at the limit would release an in-progress drag and snap the point back. It now drops the oldest entry, and a hit is re-inserted so it counts as recently used. Nothing tested this module, which is what let the binary blob through. Now covered: identity stability, re-parsing when the chain changes but the automation text does not, a hot entry surviving 40 evictions, and an unreadable attribute reading as nothing. The geometry module's exports are ignored for dead-code while its consumer sits one PR upstack, following the convention already used for the fast-capture stack. Co-Authored-By: Claude Opus 5 (1M context) --- .fallowrc.jsonc | 16 +++++ .../components/automationLaneData.test.ts | 66 ++++++++++++++++++ .../player/components/automationLaneData.ts | Bin 2677 -> 3397 bytes 3 files changed, 82 insertions(+) create mode 100644 packages/studio/src/player/components/automationLaneData.test.ts diff --git a/.fallowrc.jsonc b/.fallowrc.jsonc index a54c751de6..104067d479 100644 --- a/.fallowrc.jsonc +++ b/.fallowrc.jsonc @@ -160,6 +160,22 @@ "file": "packages/core/src/audio/audioFxGraph.ts", "exports": ["ensureAudioFxWorklets"], }, + // automationLaneGeometry is the bottom of the audio-automation stack: its + // consumer is the lane component one PR upstack, so a per-PR audit diffing + // against the merge base sees these as unused. Consumed for real once the + // stack merges; safe to drop this entry then. + { + "file": "packages/studio/src/player/components/automationLaneGeometry.ts", + "exports": [ + "POINT_MERGE_SEC", + "GRAB_PX", + "DRAW_SAMPLES", + "PAD_X", + "formatValue", + "laneFor", + "withLane", + ], + }, // drawElementService is the bottom of the fast-capture Graphite stack // (#1917): its consumers (frameCapture in #1919) land two PRs upstack, so // a per-PR audit diffing against the merge base sees these exports as diff --git a/packages/studio/src/player/components/automationLaneData.test.ts b/packages/studio/src/player/components/automationLaneData.test.ts new file mode 100644 index 0000000000..948c926167 --- /dev/null +++ b/packages/studio/src/player/components/automationLaneData.test.ts @@ -0,0 +1,66 @@ +// @vitest-environment happy-dom +import { describe, expect, it } from "vitest"; +import { elementAutomation, elementFxChain } from "./automationLaneData"; +import type { TimelineElement } from "../store/timelineElement"; + +const el = (over: Partial = {}): TimelineElement => ({ + id: "bgm", + key: "bgm", + tag: "audio", + start: 0, + duration: 10, + track: 10, + ...over, +}); + +const CHAIN = JSON.stringify({ + version: 1, + nodes: [{ type: "lowpass", id: "n1", params: { frequency: 400, q: 0.9, poles: "2" } }], +}); +const LANE = JSON.stringify({ + version: 1, + lanes: [{ target: "fx.n1.frequency", points: [{ t: 0, v: 400 }] }], +}); + +describe("automationLaneData", () => { + it("returns the same object for the same attributes", () => { + // The lane compares its drag draft against this identity; a fresh object per + // playhead tick would drop the drag. + const a = elementAutomation(el({ automation: LANE, fxChain: CHAIN })); + const b = elementAutomation(el({ automation: LANE, fxChain: CHAIN })); + expect(a).toBe(b); + expect(elementFxChain(el({ fxChain: CHAIN }))).toBe(elementFxChain(el({ fxChain: CHAIN }))); + }); + + it("re-parses when the chain changes even though the automation text did not", () => { + const withChain = elementAutomation(el({ automation: LANE, fxChain: CHAIN })); + const withoutChain = elementAutomation(el({ automation: LANE })); + expect(withChain.lanes.map((l) => l.target)).toEqual(["fx.n1.frequency"]); + // No chain to resolve against, so the fx lane is dropped rather than drawn. + expect(withoutChain.lanes).toEqual([]); + }); + + it("keeps a hot entry alive when other elements push the cache past its limit", () => { + // Eviction used to clear the whole map, which changed every lane's identity + // at once and released any drag in progress. + const hot = el({ automation: LANE, fxChain: CHAIN }); + const first = elementAutomation(hot); + for (let i = 0; i < 40; i += 1) { + elementAutomation( + el({ + automation: JSON.stringify({ + version: 1, + lanes: [{ target: "volume", points: [{ t: i, v: 0.5 }] }], + }), + }), + ); + elementAutomation(hot); + } + expect(elementAutomation(hot)).toBe(first); + }); + + it("reads an unreadable attribute as nothing rather than throwing", () => { + expect(elementAutomation(el({ automation: "{nope" })).lanes).toEqual([]); + expect(elementFxChain(el({ fxChain: "{nope" }))).toBeNull(); + }); +}); diff --git a/packages/studio/src/player/components/automationLaneData.ts b/packages/studio/src/player/components/automationLaneData.ts index c87b895eae09170881a2ac4ca7effd611d14fcb4..375f891dcd7eeae21dba1a0d131ee3fdfab646a6 100644 GIT binary patch delta 814 zcmY*X!D|P8uVanVCyu4 zV)l04G6Lflp28Bbv916v5rV3vWPX8?*E+UUipIQ%s7vJv4DkEg_Y|*`L(o(=%1hL8 z0OM8B#qUD;6w125lBpQ1L4o6SE;teDbY(SLa*|6;NN7|Ulyu4SYw$|w_*m;eSE&4s zVXc~@+sJ2XD|1UN;dHxRKnuVX3R)!kG=OTEYL(gwrKrpllrwVs6sWB^j3Y$E1Pvag zxyU#S7srx^q zA`7n|eYAwCHM9YZ0LV$0xe)@4<0Y=M=Xb&ZImV_?S{{CQ2h2Za$2%?ify9 zoV+^y^ycjC+4~H7N}A$k2E~tuR)QDCS?*-p;{nqyVEm*{%MCfq{%1A(Nn@vq*tO@q zBY3?X{kh+X1TTrpq^;KlUNtVezY|Y$7sU@XFc?ubsCDxO@*>z+ToE@D#T;qK_eLX`o6^cvpi&FKH cb5awFG&HR@KV|>VG&z%7jgevVRPGIo0HgRAp#T5?