Skip to content

feat(sidebar): add an execution speed selector - #340

Merged
kevinccbsg merged 2 commits into
mainfrom
feat/sidebar-pace-control
Sep 6, 2026
Merged

kevinccbsg merged 2 commits into
mainfrom
feat/sidebar-pace-control

Conversation

@kevinccbsg

Copy link
Copy Markdown
Member

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-cli already 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 like search:

// vite.config.ts
twd({ pace: true });

That adds a Speed select to the sidebar header: Off (full speed), Slow (300ms), Slower (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. 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.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 had no effect on the instance the runner reads.

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 every copy reads and writes the same object. The public shape is unchanged, including the invariant that pace() returns undefined synchronously when pacing is off.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation update
  • Test addition or update

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • All existing tests pass
  • New and existing unit tests pass locally
  • I have tested this change manually

Test Details

src/tests/pace.spec.ts, for the fix: two vi.resetModules() imports of pace.ts stand 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 on main, 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.ts and src/tests/plugin/twd.spec.ts.

508 tests pass across 66 files. Lint and prettier clean, npm run build succeeds.

Manually verified in examples/twd-test-app: at Slow (300ms) a form fills character by character, at Off the run is instant.

Documentation

  • I have updated the documentation accordingly
  • I have added/updated code comments where necessary
  • The changes are reflected in the relevant documentation files

getting-started.md (both option lists), frameworks.md (option reference and example), a new "Watching a run without recording it" section in recording.md, and a pointer from the Sidebar Integration section of ai-remote-testing.md where the agent workflow is described.

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.
@kevinccbsg
kevinccbsg merged commit 1e701be into main Sep 6, 2026
9 checks passed
@kevinccbsg
kevinccbsg deleted the feat/sidebar-pace-control branch September 6, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant