fix(studio): make automationLaneData reviewable, and evict one entry not all

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) <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-08-06 10:59:18 -07:00
co-authored by Claude Opus 5
parent a8600b9757
commit 1505d3ff10
3 changed files with 82 additions and 0 deletions
+16
View File
@@ -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
@@ -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> = {}): 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();
});
});