Repository navigation
test: cover turnstate hook ledger writes - #57
Merged
Merged
Conversation
tonydzi
reviewed
Oct 21, 2026
tonydzi
left a comment
Owner
There was a problem hiding this comment.
Mycroft here, Anton's synthetic AI co-founder, disclosing in the first line because the regulation asks. Thanks @Khushbu677, this is the test #15 asked for.
I checked it against the PR head (333803f) instead of the description:
python -m pytest -q tests/test_turnstate_hook.pygives 4 passed, and the fullpython -m pytest -qgives 168 passed.- I broke the hook on purpose, twice, to see whether the tests notice.
- Turning the
INSERT INTO turnscall into a no-op makestest_main_writes_extracted_turn_to_ledgerandtest_main_does_not_write_again_without_new_transcript_bytesfail (ProgrammingErroratturnstate_hook.py:229). - Changing the final
sys.exit(0)tosys.exit(1)makes bothtest_module_wrapper_*tests fail.
So each of the four tests goes red on the break it is meant to catch, and none of them passes by accident.
- Turning the
- Standard library plus pytest only, no new dependency, and the README sentence that claimed the hook has no test is gone.
One thing I would not change but want on record: the two wrapper tests only assert exit code 0, so they pin the "never break a session" contract, not that a bad payload writes nothing. That matches case (3) of the issue, so it is fine as scoped.
Merging now.
tonydzi
approved these changes
Oct 21, 2026
tonydzi
left a comment
Owner
There was a problem hiding this comment.
Approving on the evidence in the review above (4 tests, each red on its own break; full suite 168 passed).
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.
What
Added
tests/test_turnstate_hook.pywith four tests covering ledger field extraction, duplicate-byte skipping, malformed input, and a missing transcript. Updated the README to reflect the new test coverage.Why
The hook silently handles errors, so a regression in its SQLite write path could cause ledger entries to stop being recorded without failing the session. Tests make these failures detectable.
Closes #15
How to verify
Command:
Actual output: 4 passed.
Red-green verification: In an isolated copy with the SQLite insert disabled, the write-path and duplicate-byte tests failed as expected.
Command:
Actual output: 167 passed, 1 failed. The unrelated failure is
tests/test_star_prompt.py::test_tilde_in_config_dir_expands, which also fails when run independently.Command:
Actual output: no output; passed.
What this does NOT include
turnstate_hook.pyimplementation.test_tilde_in_config_dir_expandsfailure is not addressed by this PR.