mirror of
https://github.com/got-feedBack/feedBack.git
synced 2026-08-10 18:59:56 +00:00
* refactor(highway): lift 79 per-instance closure vars into `hwState` (R3c H lift) Collapses createHighway()'s 79 mutable closure `let`s into one per-instance `hwState` object. Scope-resolved rewrite via acorn + eslint-scope: 1059 edits (1057 references + 79 defs - the deleted `let canvas, ctx, ws`), with the four names shadowed in inner scopes (chartTime/ctx/notes/chordTemplates) resolved correctly so only closure-bound refs move. Enables the later module split: extracted renderer/ws modules close over `hwState` as a factory arg, so multi-panel plugins (highway_3d, note_detect, splitscreen) don't share one highway's state. Container is `hwState`, NOT `H` — `H` is already canvas height (70 uses). The frame-time gate caught that collision instantly (0 draws, `H._drawHooks is not iterable` in the shared draw-hook path). PERF (the whole risk): identical to the pre-lift baseline. Draw p50 2.1-2.2 ms, p95 2.7-3.0 ms (pre-lift 2.7-3.2), measured on the Arcturus feedpak, headless. Each closure-slot read became a `hwState.<slot>` monomorphic property load; the hot loop pays nothing. On-device: Byron confirmed the 2D highway plays smoothly. Tests: the ~30 highway JS suites brace-extract functions/patterns from the source; their state references + the monotonic-clock vm sandbox now use `hwState.<slot>` (the const _CHART_MAX_INTERP_MS etc. stay top-level, not lifted). node --test: 1030/1030 green. Two self-inflicted over-replacements caught and reverted (`_lefty` is a prefix of the 3D-local `_leftyCached`; `STRING_COLORS` a suffix of `DEFAULT_STRING_COLORS`) — substring replaces on the brace-extract regexes need word care. Transformer saved at ~/.local/share/feedback-editor/highway-h-lift.mjs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(highway): pin the setNoteStateProvider assertion to hwState._noteStateProvider (CodeRabbit) The [^}]* form matched an unqualified _noteStateProvider =, so a regression to closure-level state could still pass. Require the hwState-qualified assignment. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
69 lines
3.1 KiB
JavaScript
69 lines
3.1 KiB
JavaScript
// Verify static/highway.js handles the `handshapes` WebSocket message:
|
|
// accumulates incoming chunks, time-sorts on `ready`, and exposes the
|
|
// result on the renderer bundle. The 3D arpeggio frame / chord rails
|
|
// pipeline consumes that bundle; if accumulation or sort drifts, those
|
|
// visuals silently render wrong (out-of-order frames, missing hints).
|
|
//
|
|
// Same source-level guard strategy as the other tests/js/ files —
|
|
// extract the relevant case body and assert the wiring.
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const HIGHWAY_JS = path.join(__dirname, '..', '..', 'static', 'highway.js');
|
|
|
|
function getCaseBlock(src, label) {
|
|
const start = src.indexOf(`case '${label}'`);
|
|
assert.ok(start !== -1, `case '${label}' not found in highway.js`);
|
|
const tail = src.slice(start);
|
|
const nextCase = tail.search(/\n\s*case\s+['"]/);
|
|
const nextDefault = tail.search(/\n\s*default\s*:/);
|
|
let end = tail.length;
|
|
if (nextCase > 0) end = Math.min(end, nextCase);
|
|
if (nextDefault > 0) end = Math.min(end, nextDefault);
|
|
return tail.slice(0, end);
|
|
}
|
|
|
|
test('handshapes WS case accumulates incoming chunks into handShapes', () => {
|
|
// Server streams handshapes in chunks; the case must concat rather
|
|
// than replace so multi-chunk sources don't silently truncate.
|
|
const src = fs.readFileSync(HIGHWAY_JS, 'utf8');
|
|
const block = getCaseBlock(src, 'handshapes');
|
|
assert.match(
|
|
block,
|
|
/hwState\.handShapes\s*=\s*hwState\.handShapes\.concat\(\s*msg\.data\s*\)/,
|
|
'handshapes case must concat msg.data into the handShapes accumulator',
|
|
);
|
|
});
|
|
|
|
test('ready case time-sorts handShapes before rendering', () => {
|
|
// Out-of-order chunks would otherwise leave handShapes interleaved,
|
|
// breaking the binary-search lookups the 3D renderer does when
|
|
// probing arpeggio coverage for a chord at time t.
|
|
const src = fs.readFileSync(HIGHWAY_JS, 'utf8');
|
|
const block = getCaseBlock(src, 'ready');
|
|
assert.match(
|
|
block,
|
|
/handShapes\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\.start_time\s*-\s*b\.start_time\s*\)/,
|
|
'ready case must sort handShapes by start_time so the renderer can rely on ordering',
|
|
);
|
|
});
|
|
|
|
test('bundle exposes handShapes to renderers with flat-list fallback', () => {
|
|
// Renderers (highway_3d in particular) read `bundle.handShapes`; if
|
|
// the bundle key gets renamed or dropped, the 3D arp-frame pipeline
|
|
// goes dark without a runtime error. The current shape is a ternary
|
|
// that picks `_filteredHandShapes` when phrase data carries any and
|
|
// falls back to the flat `handShapes` list otherwise (DLC pattern).
|
|
// Pin both sides of the ternary so accidentally dropping the
|
|
// fallback branch fails the test.
|
|
const src = fs.readFileSync(HIGHWAY_JS, 'utf8');
|
|
assert.match(
|
|
src,
|
|
/\bhandShapes\s*[:=]\s*\([^)]*hwState\._filteredHandShapes[^)]*\)\s*\?\s*hwState\._filteredHandShapes\s*:\s*hwState\.handShapes\b/,
|
|
'bundle must expose handShapes with the _filteredHandShapes-vs-handShapes ternary fallback',
|
|
);
|
|
});
|