feat: harden seat intent and expand HIL coverage

This commit is contained in:
vee
2026-08-02 05:20:38 +08:00
parent 4aded5c21d
commit 55d0d400cb
62 changed files with 53112 additions and 1748 deletions
+46
View File
@@ -0,0 +1,46 @@
from __future__ import annotations
import os
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from cognitive_agent.config_loader import load_local_env
class LocalEnvironmentLoaderTests(unittest.TestCase):
def test_file_replaces_blank_inherited_value_but_preserves_non_blank_override(self) -> None:
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / ".env"
path.write_text(
"OPENAI_MODEL=gpt-5.6-sol\nOPENAI_BASE_URL=https://configured.example/v1\n",
encoding="utf-8",
)
with patch.dict(
os.environ,
{
"OPENAI_MODEL": "",
"OPENAI_BASE_URL": "https://explicit.example/v1",
},
clear=True,
):
load_local_env(path)
self.assertEqual(os.environ["OPENAI_MODEL"], "gpt-5.6-sol")
self.assertEqual(
os.environ["OPENAI_BASE_URL"], "https://explicit.example/v1"
)
def test_explicit_override_replaces_stale_non_blank_launcher_value(self) -> None:
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / ".env"
path.write_text("OPENAI_MODEL=gpt-5.6-sol\n", encoding="utf-8")
with patch.dict(
os.environ, {"OPENAI_MODEL": "gpt-5-mini"}, clear=True
):
load_local_env(path, override=True)
self.assertEqual(os.environ["OPENAI_MODEL"], "gpt-5.6-sol")
if __name__ == "__main__":
unittest.main()
+36 -1
View File
@@ -6,7 +6,10 @@ import unittest
import urllib.error
from unittest.mock import patch
from cognitive_agent.infrastructure.llm.openai_responses import OpenAIIntentInterpreter
from cognitive_agent.infrastructure.llm.openai_responses import (
SYSTEM_PROMPT,
OpenAIIntentInterpreter,
)
INTENT = {
@@ -45,10 +48,37 @@ class FakeResponse:
class OpenAIResponsesTests(unittest.TestCase):
def test_blank_model_and_base_url_use_documented_defaults(self) -> None:
with patch.dict(
os.environ,
{
"OPENAI_API_KEY": " test-key ",
"OPENAI_MODEL": " ",
"OPENAI_BASE_URL": "",
"OPENAI_REASONING_EFFORT": " ",
},
clear=True,
):
interpreter = OpenAIIntentInterpreter()
self.assertEqual(interpreter.api_key, "test-key")
self.assertEqual(interpreter.model, "gpt-5.6-sol")
self.assertEqual(interpreter.responses_endpoint, "https://api.openai.com/v1/responses")
self.assertEqual(interpreter.reasoning_effort, "medium")
def test_fuzzy_front_cabin_goal_has_deterministic_ergonomic_policy(self) -> None:
normalized = " ".join(SYSTEM_PROMPT.split())
self.assertIn("front cabin is cramped", normalized)
self.assertIn("longitudinal 80%", normalized)
self.assertIn("backrest recline 35%", normalized)
self.assertIn("do not manufacture a driver-seat target", normalized)
def test_non_streaming_structured_output(self) -> None:
response_body = json.dumps({"output_text": json.dumps(INTENT)})
environment = {
"OPENAI_API_KEY": "test-key",
"OPENAI_MODEL": "gpt-5.6-sol",
"OPENAI_BASE_URL": "https://api.openai.com/v1",
"OPENAI_STREAM": "false",
}
@@ -73,6 +103,11 @@ class OpenAIResponsesTests(unittest.TestCase):
request_payload = json.loads(urlopen.call_args.args[0].data.decode("utf-8"))
self.assertEqual(result, INTENT)
self.assertNotIn("stream", request_payload)
self.assertEqual(request_payload["model"], "gpt-5.6-sol")
self.assertEqual(
urlopen.call_args.args[0].full_url,
"https://api.openai.com/v1/responses",
)
self.assertIn("capability registry", request_payload["input"][1]["content"][0]["text"])
self.assertIn('"level": 1', request_payload["input"][2]["content"][0]["text"])