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>
67 lines
3.0 KiB
Python
67 lines
3.0 KiB
Python
"""Config "env_to_user": opencode's <env> block (working directory, date) leaves the system message for the first user
|
|
message, so the system turn is the same in every session and the prefix cache keeps it. Off (the default), nothing moves."""
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
|
|
import serve.frontend as fe # noqa: E402
|
|
|
|
SYS = ("You are opencode.\n"
|
|
"Here is some useful information about the environment you are running in:\n"
|
|
"<env>\n"
|
|
" Working directory: C:/a\n"
|
|
" Today's date: Mon Oct 12 2026\n"
|
|
"</env>\n"
|
|
"Instructions that never change.")
|
|
|
|
|
|
class EnvBlockToUser(unittest.TestCase):
|
|
def setUp(self):
|
|
self.addCleanup(setattr, fe, "ENV_TO_USER", fe.ENV_TO_USER)
|
|
|
|
def convert(self, on, system=SYS, user="hi"):
|
|
fe.ENV_TO_USER = on
|
|
msgs, _, _ = fe.openai_to_messages({"messages": [{"role": "system", "content": system},
|
|
{"role": "user", "content": user}]})
|
|
return msgs
|
|
|
|
def test_moved_to_the_first_user_message(self):
|
|
msgs = self.convert(True)
|
|
self.assertEqual(msgs[0]["content"], "You are opencode.\nInstructions that never change.")
|
|
self.assertTrue(msgs[1]["content"].startswith(
|
|
"Here is some useful information about the environment you are running in:\n<env>\n Working directory: C:/a"))
|
|
self.assertTrue(msgs[1]["content"].endswith("</env>\n\nhi"))
|
|
|
|
def test_two_folders_share_the_system_turn(self):
|
|
a = self.convert(True)[0]["content"]
|
|
b = self.convert(True, system=SYS.replace("C:/a", "D:/b"))[0]["content"]
|
|
self.assertEqual(a, b)
|
|
|
|
def test_content_parts_get_a_leading_text_part(self):
|
|
fe.ENV_TO_USER = True
|
|
out = fe._env_to_user([{"role": "system", "content": SYS},
|
|
{"role": "user", "content": [{"type": "image", "image": "x.png"}, {"type": "text", "text": "hi"}]}])
|
|
self.assertEqual(out[1]["content"][0]["type"], "text")
|
|
self.assertIn("<env>", out[1]["content"][0]["text"])
|
|
self.assertEqual(out[1]["content"][1:], [{"type": "image", "image": "x.png"}, {"type": "text", "text": "hi"}])
|
|
|
|
def test_text_parts_are_read_as_one_text(self):
|
|
msgs = self.convert(True, user=[{"type": "text", "text": "hi"}])
|
|
self.assertIn("<env>", msgs[1]["content"] if isinstance(msgs[1]["content"], str) else msgs[1]["content"][0]["text"])
|
|
|
|
def test_anthropic_requests_too(self):
|
|
fe.ENV_TO_USER = True
|
|
msgs, _, _ = fe.anthropic_to_messages({"system": SYS, "messages": [{"role": "user", "content": "hi"}]})
|
|
self.assertNotIn("<env>", msgs[0]["content"])
|
|
self.assertIn("<env>", msgs[1]["content"])
|
|
|
|
def test_off_and_no_block_change_nothing(self):
|
|
self.assertEqual(self.convert(False)[0]["content"], SYS)
|
|
self.assertEqual(self.convert(True, system="Plain system prompt.")[0]["content"], "Plain system prompt.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|