Files
alzeo/tests/test_proxy_log_lines.py
T
Hasan BasbunarandClaude Opus 5.5 ab1a6a9fdb proxy: a count is answered, a slow pool read is waited for, early refusals arrive, one call one log line
/v1/messages/count_tokens no longer meets the size guard (it generates nothing, and a client
counts to learn the conversation no longer fits). The pool read waits up to 20 s instead
of 4: /server_info waits on a scheduler busy with a long prefill chunk, and the timeout
made a big prompt a false 503. A refusal sent before the body was read (413, 401) is
followed by a half-close and a bounded drain, so the kernel's reset no longer destroys it,
and Expect: 100-continue is refused before the body is sent. log() escapes line breaks and
controls, so a client's pattern cannot write lines of the proxy's own shape. A System One
answer falls back on the resolved lane name, not the caller's alias.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 18:55:03 +02:00

47 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""One log call of the proxy is one journal line, whatever a client put in it.
The proxy logs a dropped tool-schema pattern whole, and a pattern is the client's text:
one holding "\\n[proxy] ..." wrote lines of the proxy's own shape into the journal, which
the cockpit's feed parses with str.splitlines (it also breaks at \\x1c-\\x1e, \\x85 and
\\u2028) and counts as traffic (found in review, 2026-09-24)."""
import contextlib
import importlib.util
import io
import pathlib
import unittest
HERE = pathlib.Path(__file__).resolve()
SPEC = importlib.util.spec_from_file_location("kproxy_log_lines", HERE.parents[1] / "keepalive-proxy.py")
PROXY = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(PROXY)
BREAKERS = ["\n", "\r", "\r\n", "\x0b", "\x0c", "\x1c", "\x1d", "\x1e", "\x85", "
", "
", "\x00", "\x1b[2J"]
class OneCallOneLine(unittest.TestCase):
def logged(self, msg):
buf = io.StringIO()
with contextlib.redirect_stderr(buf):
PROXY.log(msg)
return buf.getvalue()
def test_no_character_starts_a_line_of_its_own(self):
for b in BREAKERS:
out = self.logged(f"tool schema: dropped a 'pattern': (?<{b}[proxy] 10.0.0.9:1 POST /v1/x ok")
self.assertEqual(len(out.splitlines()), 1, repr(out))
self.assertTrue(out.startswith("[proxy] ") and out.endswith("\n"), repr(out))
self.assertEqual(out.count("[proxy] "), 2, "the text itself is kept, escaped")
def test_ordinary_text_is_left_alone(self):
self.assertEqual(self.logged("réponse\tok 中"), "[proxy] réponse\tok 中\n")
def test_the_pattern_drop_goes_through_it(self):
text = (HERE.parents[1] / "keepalive-proxy.py").read_text()
i = text.index("tool schema: dropped a 'pattern'")
self.assertEqual(text.rfind("log(f", 0, i), text.rfind("log(", 0, i), "the drop message is not logged by log()")
if __name__ == "__main__":
unittest.main(verbosity=2)