Skip to content

test(dashboard): add a real-HTTP harness and tests for the server current behaviour - #5

Merged
Yoepan merged 2 commits into
Yoepan:mainfrom
KiloMusician:test/dashboard-http-harness
Oct 25, 2026
Merged

Yoepan merged 2 commits into
Yoepan:mainfrom
KiloMusician:test/dashboard-http-harness

Conversation

@KiloMusician

Copy link
Copy Markdown
Contributor

Second piece of splitting #1: a real-HTTP test harness. Test-only; no server change. It builds on the atomic-state-file PR (the first commit shown here belongs to that one; review only the last).

tests/http_harness.py starts the real ThreadedSwarmServer on 127.0.0.1 with an ephemeral port, against a throw-away copy of the dashboard and assets with planted "must never be served" files. A test cannot reach a provider or start a process: urlopen fails the test, and the shell/agent runners and the key verifier are replaced by recorders. Setting TENAGENT_TEST_ROOT runs the same tests against another checkout's serve.py (for example an export of a parent commit), which is how a test is shown to fail on the defect it targets.

tests/test_dashboard_http.py pins what the server does today (the routes, blocked paths, the Host check, the session-token and origin gate on every POST, /api/command routing, /api/log, how /api/config and /api/models treat stored keys) so a later change to a route or guard has to update a test that says what it is changing.

CI now runs the unittest suite: on Ubuntu (the server tests skip there with a reason, since dashboard/serve.py exits on non-Windows) and in a new Windows job that runs them for real. The compile check covers the whole dashboard/ directory, so a new module there needs no CI edit.

Verification

Head ec09860: Windows 11 / Python 3.13: 64 tests, OK (2 skipped). Linux (Ubuntu, Python 3.12): 24 tests, OK, 3 skipped. ci.yml was parsed with PyYAML on Windows and Linux (two jobs, every step name read back). Because this is test-only I checked the tests by mutation instead: removing each of main's guards in a scratch copy (Host check, token check, origin check, key popping, traversal checks, the .py blocklist) makes the corresponding tests fail (for instance 6 failures without the Host check, 10 without the token check).

Not verified

The new Windows CI job has not run on GitHub; Python 3.11 was checked for syntax only.

Prepared with AI coding assistants (OpenAI GPT and Anthropic Claude) on behalf of @KiloMusician. Commands and counts above were run on the head named. MIT licence untouched.

KiloMusician and others added 2 commits October 24, 2026 16:39
…ter at a time

The dashboard server threads, the provider probe worker, the swarm pipeline
thread and council.py all read-modify-write specs/swarm-status.json and
specs/swarm-config.json.  They shared one "<name>.tmp" scratch file with no
lock.  What goes wrong (each is reproduced by a test in this change):

* two concurrent writers tear the JSON ("Extra data" on the next read) and
  lose each other's updates;
* on Windows os.replace onto a file a reader still has open raises
  PermissionError, which was swallowed, so the update was dropped silently;
* the provider probe worker wrote back the whole config it had read before
  probing (sockets, and HTTP for rate-limited cloud providers), reverting
  anything saved in the meantime;
* a failed replace left a stray swarm-config.json.tmp behind.

* dashboard/statefile.py: atomic_write_json writes a unique temp file in the
  same directory and replaces the target, retrying briefly while a Windows
  reader holds it; an existing file keeps its permissions and a symlink is
  followed rather than replaced.  update_json_file does the read-modify-write
  under a lock that belongs to that one file, so a writer waiting for a reader
  of the status file never delays writers of the config (no code path holds
  two of these locks).  A UTF-8 byte-order mark is accepted when reading.
* serve.py, swarm_pipeline.py and council.py go through it (stream.py, a
  separate process, uses the atomic replace so readers never see a partial
  file).  The duplicate safe_write_json definition is removed.
* The probe worker now merges only the status fields into a fresh read of
  the file.
* POST /api/config writes atomically and reports a failed write instead of
  claiming success.
* Latent, not reproducible on Windows today: GET /api/config probed local
  providers and wrote back the copy it had just stripped of provider keys.
  The old code did that from inside "with open(cfg_file)", where the replace
  is refused on Windows and the error was swallowed, so the keys survived by
  accident; wherever the replace succeeds every stored key would be deleted.
  It now refreshes the statuses through the same merge and serves what is on
  disk.

Tests: tests/test_statefile.py (helpers) and tests/test_dashboard_state.py
(the real serve.py against a temporary tree; skipped off Windows, where
serve.py cannot be imported).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…urrent behaviour

tests/http_harness.py starts the real ThreadedSwarmServer on 127.0.0.1 with an
ephemeral port, against a throw-away copy of the dashboard and assets with
planted "must never be served" files.  Nothing in a test can reach a provider
or start a process: urlopen fails the test, and the shell/agent runners and the
key verifier are replaced by recorders.  Setting TENAGENT_TEST_ROOT runs the
same tests against another checkout's serve.py (for example an export of a
parent commit), which is how a test is shown to fail on the defect it targets.

tests/test_dashboard_http.py pins what the server does today - the routes,
the blocked paths, the Host check, the session-token and origin gate on every
POST, /api/command routing, /api/log, and how /api/config and /api/models
handle stored keys - so that a later change to a route or a guard has to
update a test that says what it is changing.  It needs no server change.

CI now runs the unittest suite: on ubuntu (the server tests skip there with a
reason, since dashboard/serve.py exits on non-Windows) and in a new Windows job
that runs them for real.  The compile check now covers the whole dashboard/
directory, so a new module there needs no CI edit.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@Yoepan

Yoepan commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Hi @KiloMusician,

Thank you so much for the thorough audits, bug fixes, and extensive test suites across PRs #3, #4, and #5!
Splitting them up made the review process very smooth. Spotting the missing subprocess import in the QA runner and ensuring atomic state writes on Windows will make TenAgent significantly more robust. The real-HTTP test harness and Windows CI workflow are fantastic additions as well.

Really appreciate your valuable contributions to TenAgent!

@Yoepan
Yoepan merged commit 04e185c into Yoepan:main Oct 25, 2026
2 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