Skip to content

Add headless tests for response, feedback and sound items - #842

Merged
smathot merged 3 commits into
open-cogsci:nightingalefrom
hieudoanm:add-headless-response-tests
Dec 1, 2026
Merged

smathot merged 3 commits into
open-cogsci:nightingalefrom
hieudoanm:add-headless-response-tests

Conversation

@hieudoanm

@hieudoanm hieudoanm commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Several recent bug fixes (#836 tree crash, #777 form flush, #838 embedded browser help commands, #840 General tab booleans) shipped without regression tests, largely because the test suite only exercised the experiment model and the legacy canvas backend — not the runtime paths those bugs lived in. Overall coverage is ~27%, and whole item types (mouse_response, feedback, sampler, synth, the form_* plugins, sketchpad response collection, and loop break-if conditions) had 0% coverage.

Solution

Add seven self-asserting experiments to tests/data/, run by the existing headless suite in tests/headless/test_headless.py (six through the shared runner, plus form_consent_test.osexp through a dedicated test that stubs Form._exec to simulate the participant accepting the form):

  • mouse_response_test.osexp — mouseclick and mouserelease collection, cursor position/ROI variables, allowed/correct responses, linked sketchpad
  • feedback_test.osexp — feedback item execution and reset_variables, keypress and keyrelease keyboard responses
  • sampler_test.osexp — synth (generated tone) and sampler (pool sample __pool__/test.wav) playback plus a keypress response
  • form_test.osexp — form_text_display, form_multiple_choice and form_text_input widget construction and timeout handling through FormBase/widgets/_form.py, plus an advanced_delay item
  • sketchpad_response_test.osexp — sketchpad used as a response item (duration mouseclick), covering BaseResponseItem response collection, cursor variables and timeout behaviour
  • loop_break_if_test.osexp — a loop whose break_if condition exits early, verifying conditional loop termination
  • form_consent_test.osexp — consent form widget construction and the accept/decline loop in FormConsent.run(); Form._exec is stubbed to simulate checking the box and clicking accept, since the loop never exits without a real response

Each experiment ends with an inline_script item asserting the expected runtime variables (response_time_*, correct_*, cursor_*, delay_*, loop variables), following the pattern already used by response_test.osexp and loop_test.osexp. Responses and forms time out deterministically because no input devices exist headless. SDL_AUDIODRIVER=dummy is set so the sound items do not require audio hardware.

Why headless?

  • It runs the real runtime path: item prepare/run/coroutine, response collection, the response store, canvas drawing, form widget execution, loop condition evaluation, and the logger — the same code a participant's experiment executes, just offscreen.
  • It's deterministic: SDL_VIDEODRIVER=dummy / SDL_AUDIODRIVER=dummy / QT_QPA_PLATFORM=offscreen mean no display, no audio device, and no real input — timeouts make responses reproducible.
  • It's fast: the whole suite runs in seconds, so it fits CI's existing matrix without new infrastructure.

Coverage impact

  • libopensesame/mouse_response.py 0% → 71%
  • libopensesame/feedback.py 0% → 84%
  • libopensesame/sampler.py 0% → 73%
  • libopensesame/synth.py 0% → 82%
  • openexp/_mouse/legacy.py 0% → 61%
  • openexp/_sampler/legacy.py 0% → 60%
  • openexp/_keyboard/legacy.py 71% → 72% (keyrelease path)
  • libopensesame/widgets/_form.py 0% → 69%
  • opensesame_plugins/core/form_base/form_base.py 0% → 78%
  • opensesame_plugins/core/form_multiple_choice/form_multiple_choice.py 0% → 75%
  • opensesame_plugins/core/form_text_input/form_text_input.py 0% → 82%
  • opensesame_plugins/core/form_text_display/form_text_display.py 0% → 92%
  • opensesame_plugins/core/form_consent/form_consent.py 0% → 74%
  • libopensesame/loop.py break-if path and libopensesame/sketchpad.py response collection now exercised end-to-end

Test plan

  • pytest tests/headless tests/basic — 16 passed locally
  • New fixtures verified to fail when assertions are wrong (asserts were debugged against actual runtime values)

Extend the headless suite with three self-asserting experiments that
exercise runtime paths that were previously untested:

- mouse_response_test.osexp: mouseclick and mouserelease collection,
  cursor position/ROI variables, allowed/correct responses
- feedback_test.osexp: feedback item execution and reset_variables,
  keypress and keyrelease keyboard responses
- sampler_test.osexp: synth (generated tone) and sampler (pool sample)
  playback plus a keypress response

Responses time out deterministically headless (no input devices), and
each experiment ends with an inline_script item asserting the expected
response variables. SDL_AUDIODRIVER=dummy is set so the sound items do
not require audio hardware.
@smathot
smathot merged commit 66df30f into open-cogsci:nightingale Dec 1, 2026
5 checks passed
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.

2 participants