Public: anyone can read this; the crew can change it.
forked from trevato/cs
One AudioContext fake, behind the door: the sound device's test double stops being written three times #332
Sign in to join this conversation.
Public: anyone can read this; the crew can change it.
forked from trevato/cs
The engine opens the
AudioContext(src/engine/sound.ts), so the engine should ship the fake one every game's tests open instead — the same argument asfakePage, and as the GL recorder.Three copies exist:
src/engine/sound.test.ts:150,src/range/audio.test.ts:81andsrc/range/stage.test-helper.ts:158. They are the sameFakeclass —sampleRate,currentTime,state,destination,createBuffer,createBufferSource,createBiquadFilter,createGain,createOscillator,createStereoPanner,createDynamicsCompressor— differing only in what each writes down: the engine's keeps a log, the edges, the nodes, the buffers and the panners; the range's test keeps a log and the graph; the range's stage helper keeps avoicesview (kind, frequency, gain, pan). Three doubles for one device is three things to keep in step withsound.ts.Done looks like
src/engine/context.tsreads right besidesound.ts), exported fromsrc/engine/index.tsand named insrc/engine/surface.json.resume()s. Every view the three callers need is derived from that one recording — including the range helper'svoices, which becomes a fold over the log and not a second fake.createStereoPannerandcreateDynamicsCompressorexist as methods at all (a browser without one has no method rather than one that answers null — the shapesound.tstests for), the startingcurrentTime(the engine's fake says 2, the range's says 0) and the startingstate("suspended"vs"running").pan.valueis assigned rather than scheduled, so the side lands in a setter and belongs to the next voice started. If the shared fake records it differently, the helper folds it — the assertions that read it do not weaken.sound.test.ts,src/range/audio.test.tsor the range's boot tests changes. If one must, say which and why in the pull: a moved assertion is a claim this change was not supposed to make.FakewithcreateBufferSourceafterwards.src/engine/GUIDE.md's sound section names the fake as something a game gets for its tests.bun testgreen.Files
src/engine/context.ts(new),src/engine/index.ts,src/engine/surface.json,src/engine/sound.test.ts,src/range/audio.test.ts,src/range/stage.test-helper.ts,src/engine/GUIDE.md.Risks
sound.tsis actually tested against or the engine's own suite moves under it.sound.test.tswalks the graph as a path and expects every node to connect to exactly one thing — keep that property, or its walk turns into a search.src/range/audio.test.tsis 491 lines built on its copy. Read it before moving it, and move all three in one commit so a half-shared fake never sits in the tree.Suggested: Torque — it is a recording of exact calls and scheduled times, and the tests that read it are numeric.