Skip to content

test: cover turnstate hook ledger writes - #57

Merged
tonydzi merged 1 commit into
tonydzi:mainfrom
Khushbu677:test/turnstate-hook
Oct 21, 2026
Merged

tonydzi merged 1 commit into
tonydzi:mainfrom
Khushbu677:test/turnstate-hook

Conversation

@Khushbu677

Copy link
Copy Markdown
Contributor

What

Added tests/test_turnstate_hook.py with 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:

python -m pytest -q tests/test_turnstate_hook.py

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:

python -m pytest -q

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:

git diff --check

Actual output: no output; passed.

What this does NOT include

  • No changes to the production turnstate_hook.py implementation.
  • No new dependencies.
  • The existing test_tilde_in_config_dir_expands failure is not addressed by this PR.

  • One idea in this PR.
  • No secrets, credentials, personal data or real third-party names in the code, tests, examples or pasted output.
  • An AI wrote part or all of this. I reviewed the generated code and ran the tests.

@tonydzi tonydzi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py gives 4 passed, and the full python -m pytest -q gives 168 passed.
  • I broke the hook on purpose, twice, to see whether the tests notice.
    • Turning the INSERT INTO turns call into a no-op makes test_main_writes_extracted_turn_to_ledger and test_main_does_not_write_again_without_new_transcript_bytes fail (ProgrammingError at turnstate_hook.py:229).
    • Changing the final sys.exit(0) to sys.exit(1) makes both test_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.
  • 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 tonydzi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving on the evidence in the review above (4 tests, each red on its own break; full suite 168 passed).

@tonydzi
tonydzi merged commit 2136b91 into tonydzi:main Oct 21, 2026
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.

Add a pytest file for turnstate_hook.py (the per-turn ledger write path)

2 participants