Repository navigation
feat(sidebar): add an execution speed selector - #340
Merged
Merged
Conversation
pace.ts held paceMs in module scope, but the module ships inside more than one bundle: the sidebar runs the copy in bundled.es.js while the user's tests import the copy in index.es.js. Setting a pace on one instance therefore had no effect on the instance the runner reads, so anything driving pacing from the sidebar silently did nothing. twd-cli was only working by accident. It calls window.__twdSetPace, which every copy overwrites on load, and the copy the tests use happens to load last because initTWD imports the test files after the sidebar bundle. The state now lives on window.__TWD_PACE__, created once and reused by whichever copy loads next, so all of them read and write the same object. The shared generation counter is a bonus: a pace set by one instance now invalidates the derived user-event setup cached by the others. The public shape is unchanged, including the invariant that pace() returns undefined synchronously when pacing is off.
Tests run in milliseconds, which is the feature until you need to see what
one of them actually does. That is the common case after an agent writes a
test for you: it passes, and you still do not know what it exercised.
twd-cli already paces recorded runs so the video is watchable. This exposes
the same mechanism in the sidebar, without ffmpeg and without producing a
file. New opt-in option, off by default and threaded like search:
twd({ pace: true })
It adds a Speed select to the sidebar header offering full speed, 300ms and
600ms. 300ms is what --record defaults to, and it reads as well live as it
does on video.
The choice is stored per tab in sessionStorage, so it survives the reloads
that come with editing tests, and a stored value that is not one of the
options is ignored rather than trusted. Because pacing lives in shared
state rather than in the sidebar, the selection also applies to runs
triggered over twd-relay, which is the case worth having: an agent runs the
test, you watch it happen.
Enabled in examples/twd-test-app so the control is there while developing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Tests run in milliseconds, which is the feature until you need to see what one of them actually does. That is the common case after an agent writes a test for you: it passes, and you still do not know what flow it exercised.
twd-clialready paces recorded runs so the video is watchable. This exposes the same mechanism in the sidebar, with no ffmpeg and no file produced. New opt-in option, off by default and threaded likesearch:That adds a
Speedselect to the sidebar header:Off (full speed),Slow (300ms),Slower (600ms). 300ms is what--recorddefaults to and it reads as well live as it does on video. The choice is stored per tab in sessionStorage, so it survives the reloads that come with editing tests, and a stored value that is not one of the options is ignored rather than trusted.Because pacing lives in shared state rather than in the sidebar, the selection also applies to runs triggered over
twd-relay. That is the case worth having: an agent writes a test and runs it, and you watch it happen instead of trusting a green tick.Bundled a fix it depends on
The first commit is a real bug, found while verifying this feature by hand: the control appeared to do nothing.
pace.tsheldpaceMsin module scope, but the module ships inside more than one bundle. The sidebar runs the copy inbundled.es.js, while the user's tests import the copy inindex.es.js. Setting a pace on one instance had no effect on the instance the runner reads.twd-cliwas only working by accident: it callswindow.__twdSetPace, which every copy overwrites on load, and the copy the tests use happens to load last becauseinitTWDimports the test files after the sidebar bundle. The state now lives onwindow.__TWD_PACE__, created once and reused by whichever copy loads next, so every copy reads and writes the same object. The public shape is unchanged, including the invariant thatpace()returnsundefinedsynchronously when pacing is off.Type of Change
Testing
Test Details
src/tests/pace.spec.ts, for the fix: twovi.resetModules()imports ofpace.tsstand in for the two shipped bundles. Setting a pace on one instance has to reach the other, and has to bump the generation the other one reads. Both fail onmain, which is exactly the symptom seen in the browser.src/tests/ui/twdSidebar.spec.tsx, for the control: hidden unless the option is set, applies the selected pace to the runner, persists to and restores from sessionStorage, drops the entry on the way back to full speed, ignores a stored value that is not an option, and clears the entry when the option is off. Each was watched failing first, and the stored-value validation was mutated away to confirm its test catches the regression.Option pass-through is covered in
src/tests/bundled/bundled.spec.tsandsrc/tests/plugin/twd.spec.ts.508 tests pass across 66 files. Lint and prettier clean,
npm run buildsucceeds.Manually verified in
examples/twd-test-app: atSlow (300ms)a form fills character by character, atOffthe run is instant.Documentation
getting-started.md(both option lists),frameworks.md(option reference and example), a new "Watching a run without recording it" section inrecording.md, and a pointer from the Sidebar Integration section ofai-remote-testing.mdwhere the agent workflow is described.