From ab1a6d016a88341bfa8b0455e798cb746c111bd2 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 7 Sep 2026 07:16:53 -0700 Subject: [PATCH] test(display): encode provenance contract in tilde assertions Two tests still encoded the pre-PR behaviour that the PR removes: - tests/test_tui_gateway_server.py: the mirrored fixture carries no `context_estimated` flag, so under the PR's rule it is provider-reported usage and must render without `~`. The old expectation asserted the unconditional tilde main used to emit. Assert the flag-less case is unmarked and, in the same test, flip `context_estimated` both ways to pin that only the estimate carries `~` in the count and the percent. - ui-tui appChromeStatusRule.test.tsx: `text.includes('~')` matched the `~/repo` cwd label, so the "not estimated" arm was always true. Extract the rendered context token and assert the tilde on that token only. --- tests/test_tui_gateway_server.py | 12 +++++++++++- ui-tui/src/__tests__/appChromeStatusRule.test.tsx | 5 ++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py index 0fca69f3e8..4c758cca36 100644 --- a/tests/test_tui_gateway_server.py +++ b/tests/test_tui_gateway_server.py @@ -10868,7 +10868,7 @@ def test_slash_exec_r7_read_commands_use_metadata_mirror_flag_on(monkeypatch): "history": "live question from state db", "prompt": "host system prompt", "status": "Tokens: 140", - "context": "Context usage: ~80 / 1,000 tokens", + "context": "Context usage: 80 / 1,000 tokens", "tools": "terminal", "help": "/status", } @@ -10886,6 +10886,16 @@ def test_slash_exec_r7_read_commands_use_metadata_mirror_flag_on(monkeypatch): assert expected in resp["result"]["output"] assert "stale parent mirror" not in resp["result"]["output"] assert "(._.)" not in resp["result"]["output"] + mirrored_usage = server._sessions["sid"]["_metadata_mirror"]["usage"] + for estimated in (True, False): + mirrored_usage["context_estimated"] = estimated + mirrored_usage["context_source"] = "local_estimate" if estimated else "provider_usage" + response = server.handle_request({ + "id": "context-provenance", "method": "slash.exec", + "params": {"command": "context", "session_id": "sid"}, + }) + mark = "~" if estimated else "" + assert f"Context usage: {mark}80 / 1,000 tokens ({mark}8.0%)" in response["result"]["output"] finally: server._sessions.pop("sid", None) diff --git a/ui-tui/src/__tests__/appChromeStatusRule.test.tsx b/ui-tui/src/__tests__/appChromeStatusRule.test.tsx index 500e5924dc..06a6883c5a 100644 --- a/ui-tui/src/__tests__/appChromeStatusRule.test.tsx +++ b/ui-tui/src/__tests__/appChromeStatusRule.test.tsx @@ -114,7 +114,10 @@ describe('StatusRule session title', () => { usage: { ...baseProps.usage, context_estimated: estimated } })) - expect(text.includes('~')).toBe(estimated) + const context = text.match(/(~?\d+(?:\.\d+)?k(?:\/\d+k| tok))/)?.[1] + + expect(context, `context must render at ${cols} columns`).toBeTruthy() + expect(context?.startsWith('~')).toBe(estimated) } } })