Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
62 lines
3.0 KiB
Python
62 lines
3.0 KiB
Python
"""Wrapped-call precheck parity against the original structural walk."""
|
|
import itertools
|
|
import random
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from serve import frontend
|
|
|
|
|
|
class ReferenceParser(frontend.OutputParser):
|
|
def _wrapped_call_end(self):
|
|
return frontend.call_end(self.buf)
|
|
|
|
|
|
def events_without_ids(events):
|
|
return [(e.kind, e.text, (e.call.name, e.call.arguments) if e.call else None) for e in events]
|
|
|
|
|
|
class CallScanTests(unittest.TestCase):
|
|
def test_chunk_boundaries_literal_tags_multiple_calls_and_recovery(self):
|
|
def call(value):
|
|
return "<tool_call><function=write><parameter=text>" + value + "</parameter></function></tool_call>"
|
|
bodies = [call("ordinary"), call("literal </tool_call> text </function> here"),
|
|
call("literal </parameter> prose"), call("a") + call("b"),
|
|
call("unfinished")[:-5], call("incomplete </tool_call> prose")[:-30],
|
|
"<tool_call><function=write></function></tool_call>",
|
|
"<function=write><parameter=text>bare</parameter></function>",
|
|
"<tool_call><function=write><parameter=text>a</parameter></function>"
|
|
"<parameter=write><parameter=text>b</parameter></function></tool_call>"]
|
|
tools = [{"name": "write", "parameters": {"properties": {"text": {"type": "string"}}}}]
|
|
rng = random.Random(1030)
|
|
for text, stream, recover in itertools.product(bodies, (False, True), (False, True)):
|
|
# Every fixed chunk width, plus random partitions; compare after EACH feed.
|
|
for width in range(1, 16):
|
|
a = frontend.OutputParser(thinking=False, tools=tools, stream_tools=stream, recover=recover)
|
|
b = ReferenceParser(thinking=False, tools=tools, stream_tools=stream, recover=recover)
|
|
pos = 0
|
|
while pos < len(text):
|
|
end = pos + (rng.randint(1, 20) if width == 15 else width)
|
|
delta = text[pos:end]
|
|
self.assertEqual(events_without_ids(a.feed(delta)), events_without_ids(b.feed(delta)))
|
|
pos = end
|
|
self.assertEqual(events_without_ids(a.finish()), events_without_ids(b.finish()))
|
|
|
|
def test_no_structural_rescans_until_closer_and_reset_for_next_call(self):
|
|
parser = frontend.OutputParser(thinking=False)
|
|
with patch.object(frontend, "call_end", wraps=frontend.call_end) as walk:
|
|
for _ in range(2):
|
|
parser.feed("<tool_call><function=write><parameter=text>")
|
|
before = walk.call_count
|
|
for _ in range(100):
|
|
parser.feed("abcdefgh")
|
|
self.assertEqual(walk.call_count, before)
|
|
for char in "</parameter></function></tool_call>":
|
|
parser.feed(char)
|
|
self.assertEqual(walk.call_count, before + 1)
|
|
self.assertEqual(parser._call_end_checked, 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|