Skip to content

test(tui_gateway): accept include_ancestors kwarg in test_session_resume mock#16683

Closed
briandevans wants to merge 1 commit into
NousResearch:mainfrom
briandevans:test/tui-gateway-protocol-include-ancestors-mock
Closed

test(tui_gateway): accept include_ancestors kwarg in test_session_resume mock#16683
briandevans wants to merge 1 commit into
NousResearch:mainfrom
briandevans:test/tui-gateway-protocol-include-ancestors-mock

Conversation

@briandevans

Copy link
Copy Markdown
Contributor

Summary

  • The inline _DB stub in test_session_resume_returns_hydrated_messages only declared get_messages_as_conversation(self, _sid), so when tui_gateway/server.py started calling it with include_ancestors=True (in d4dde6b5f), the call raised TypeError, the handler returned a JSON-RPC error, and the test failed on clean origin/main.
  • This is purely a test stub fix — accept the new kwarg with a default of False, matching the sibling stub in tests/test_tui_gateway_server.py.

The bug

tui_gateway/server.py:1807 (added in d4dde6b5f — "fix(tui): restore resumed transcript lineage") calls:

display_history = db.get_messages_as_conversation(
    target, include_ancestors=True
)

But the test stub was still:

def get_messages_as_conversation(self, _sid):
    return [...]

The handler wraps the body in try: ... except Exception as e: return _err(rid, 5000, f\"resume failed: {e}\"), which absorbed the TypeError and returned a JSON-RPC error envelope:

assert 'error' not in {'error': {'code': 5000,
  'message': "resume failed: ...get_messages_as_conversation()
  got an unexpected keyword argument 'include_ancestors'"}, ...}

So the test fails on origin/main (ef41d3bd4) for everyone.

The fix

Add include_ancestors=False to the stub. The two production calls (db.get_messages_as_conversation(target) for the agent-init history, and db.get_messages_as_conversation(target, include_ancestors=True) for the display payload) both return the same canned list under the stub, which is exactly what the existing assertions expect — message_count == 3 and the three filtered hydrated messages. No production change.

The sibling stub in tests/test_tui_gateway_server.py:101 already uses the include_ancestors=False default — this just brings the protocol-level test stub in line.

Test plan

  • Reproduced the failure on clean origin/main (ef41d3bd4):
    uv run --with pytest --with pytest-xdist python3 -m pytest tests/tui_gateway/test_protocol.py::test_session_resume_returns_hydrated_messages -v
    → 1 failed (assert 'error' not in {... 'unexpected keyword argument include_ancestors' ...})
    
  • With the fix applied, tests/tui_gateway/test_protocol.py runs 40 passed (full file, including the previously failing test).
  • Regression guard: stashed the fix → reproduced the same TypeError-driven JSON-RPC error; popped the stash → green again.

Related

  • d4dde6b introduced the include_ancestors=True call without updating this stub.
  • tests/test_tui_gateway_server.py:101 already had the matching signature, so this just aligns the second mock.

…ume mock

The session.resume handler in tui_gateway/server.py:1807 was updated in
d4dde6b ("fix(tui): restore resumed transcript lineage") to call
db.get_messages_as_conversation(target, include_ancestors=True) for the
display history, but the inline _DB stub in test_session_resume_returns_
hydrated_messages still defined the method with a single positional arg.

That signature mismatch makes the call raise TypeError, which the handler
catches and returns as a JSON-RPC error, breaking the test on origin/main:

    assert 'error' not in {'error': {'code': 5000,
      'message': "resume failed: ...get_messages_as_conversation()
      got an unexpected keyword argument 'include_ancestors'"}, ...}

The sibling stub in tests/test_tui_gateway_server.py already accepts
include_ancestors=False; align this one with the same default. No
production change — just unblocks the existing test of the expected
hydrated-message shape.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 27, 2026 19:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a failing TUI gateway protocol test by updating an inline DB stub to match the production get_messages_as_conversation(..., include_ancestors=...) call signature used by session.resume.

Changes:

  • Update the _DB.get_messages_as_conversation test stub to accept include_ancestors=False, aligning with current server behavior and an existing sibling stub.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@briandevans

Copy link
Copy Markdown
Contributor Author

Closing — already fixed on main. The same 1-line stub update ( default) landed via fc7f55f (#17661) on 2026-04-29. The test now passes on origin/main without this PR. Thanks @Brooklynbb!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants