Repository navigation
test(dashboard): add a real-HTTP harness and tests for the server current behaviour - #5
Merged
Merged
Conversation
…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]>
Owner
|
Hi @KiloMusician, Thank you so much for the thorough audits, bug fixes, and extensive test suites across PRs #3, #4, and #5! Really appreciate your valuable contributions to TenAgent! |
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.
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.pystarts the realThreadedSwarmServeron127.0.0.1with 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:urlopenfails the test, and the shell/agent runners and the key verifier are replaced by recorders. SettingTENAGENT_TEST_ROOTruns the same tests against another checkout'sserve.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.pypins what the server does today (the routes, blocked paths, the Host check, the session-token and origin gate on every POST,/api/commandrouting,/api/log, how/api/configand/api/modelstreat 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.pyexits on non-Windows) and in a new Windows job that runs them for real. The compile check covers the wholedashboard/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.ymlwas 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 ofmain's guards in a scratch copy (Host check, token check, origin check, key popping, traversal checks, the.pyblocklist) 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.