Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

52 lines
2.0 KiB
Python

"""
Integration tests for streaming usage extraction.
Tests that the gateway correctly proxies streaming responses and extracts usage data.
Run with: ANTHROPIC_API_KEY=... pytest tests/integration/test_streaming_usage.py -v -s
"""
import os
import pytest
from anthropic import Anthropic
ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY")
pytestmark = [
pytest.mark.skipif(not ANTHROPIC_API_KEY, reason="ANTHROPIC_API_KEY not set"),
pytest.mark.xfail(strict=False, reason="Anthropic may be rate-limited or temporarily unavailable"),
]
class TestStreamingUsageExtraction:
def test_streaming_returns_usage_in_final_message(self, anthropic_client: Anthropic):
"""Verify streaming through gateway returns complete response with usage."""
with anthropic_client.messages.stream(
model="claude-haiku-4-5-20251001",
messages=[{"role": "user", "content": "Say 'hello world' and nothing else."}],
max_tokens=20,
) as stream:
text = stream.get_final_text()
message = stream.get_final_message()
assert text is not None
assert len(text) > 0
assert message.usage is not None
assert message.usage.input_tokens > 0
assert message.usage.output_tokens > 0
print(f"\nStreaming usage: input={message.usage.input_tokens}, output={message.usage.output_tokens}")
def test_non_streaming_returns_usage(self, anthropic_client: Anthropic):
"""Verify non-streaming requests through gateway return usage."""
response = anthropic_client.messages.create(
model="claude-haiku-4-5-20251001",
messages=[{"role": "user", "content": "Say 'test' and nothing else."}],
max_tokens=10,
)
assert response.usage is not None
assert response.usage.input_tokens > 0
assert response.usage.output_tokens > 0
print(f"\nNon-streaming usage: input={response.usage.input_tokens}, output={response.usage.output_tokens}")