drop mock_data.json: embed fixtures inline in skill.test.py
The testgen call now replies with plain Python (no JSON envelope), so the model can no longer confuse the envelope with the artifact. skill.test.py carries its fixture data inline as Python literals; the folder layout is now skill.py, skill.test.py, contract.json, config.json. The regen ladder drops the mock option (3-option: code/contract/test) since a fixture fix is a test regen.
This commit is contained in:
1 parent
ddd2495f81
commit
06ccfb77c6
11 files changed
+192
-152
No files matched your search
@@ -156,7 +156,7 @@ def test_generate_skill(tmp_path):
|
||||
|
||||
def test_generate_skill_body_codegen(tmp_path):
|
||||
"""A real OpenAI-compatible model writes a runnable skill body + data
|
||||
contract + test artifacts, and the auto-run test passes.
|
||||
contract + test, and the auto-run test passes.
|
||||
|
||||
Slow: uses the big codegen model (qwen38-iq3s by default). Run this one in
|
||||
the background and poll — long-lived ssh sessions get SIGHUP'd.
|
||||
@@ -187,7 +187,7 @@ def test_generate_skill_body_codegen(tmp_path):
|
||||
client, Request("is my home server reachable right now?"), "tracking", draft, code
|
||||
)
|
||||
print(f"data contract: {contract}")
|
||||
test, mock = generate_skill_tests(
|
||||
test = generate_skill_tests(
|
||||
client,
|
||||
Request("is my home server reachable right now?"),
|
||||
"tracking",
|
||||
@@ -195,18 +195,17 @@ def test_generate_skill_body_codegen(tmp_path):
|
||||
code,
|
||||
contract,
|
||||
)
|
||||
print(f"generated {len(test)} bytes of skill test, mock={mock!r}")
|
||||
print(f"generated {len(test)} bytes of skill test")
|
||||
|
||||
store = SkillStore(str(tmp_path / "skills"))
|
||||
store.write_body("tracking", draft.name, code)
|
||||
store.write_contract("tracking", draft.name, contract)
|
||||
store.write_test("tracking", draft.name, test)
|
||||
store.write_mock("tracking", draft.name, mock)
|
||||
from semif_agent.codegen import run_skill_test
|
||||
|
||||
passed, output = run_skill_test(store.dir("tracking", draft.name), timeout=60)
|
||||
print(f"auto-run test: passed={passed}\n{output[:400]}")
|
||||
assert passed, "the auto-run test must pass against the mock data"
|
||||
assert passed, "the auto-run test must pass"
|
||||
|
||||
draft.code = code
|
||||
skill = materialize_skill(draft, "tracking", store)
|
||||
|
||||
+29
-24
@@ -29,7 +29,7 @@ from semif_agent.codegen import (
|
||||
parse_data_contract,
|
||||
parse_elicitation,
|
||||
parse_skill_body,
|
||||
parse_testgen_bundle,
|
||||
parse_skill_test,
|
||||
read_skill_contract,
|
||||
read_testgen_contract,
|
||||
regenerate_skill_body,
|
||||
@@ -64,16 +64,12 @@ GOOD_CONTRACT = {
|
||||
"tracking_id": "The package tracking number.",
|
||||
}
|
||||
|
||||
GOOD_MOCK = {"sender_address": "agent@example.com", "tracking_id": "AB123"}
|
||||
|
||||
GOOD_TEST = """\
|
||||
import sys
|
||||
print("ok")
|
||||
sys.exit(0)
|
||||
"""
|
||||
|
||||
GOOD_BUNDLE = json.dumps({"test": GOOD_TEST, "mock_data": GOOD_MOCK})
|
||||
|
||||
|
||||
def test_read_skill_contract_loads_contract():
|
||||
text = read_skill_contract()
|
||||
@@ -130,6 +126,18 @@ def test_testgen_contract_owns_mocking():
|
||||
assert "Do NOT put type declarations" in text
|
||||
|
||||
|
||||
def test_testgen_contract_embeds_fixtures_inline():
|
||||
"""TESTGEN.md must make the test self-contained: fixture data embedded
|
||||
inline as Python literals, no external mock_data.json."""
|
||||
text = read_testgen_contract()
|
||||
assert "mock_data.json" not in text
|
||||
assert "inline" in text
|
||||
assert "no external files" in text
|
||||
assert "import skill" in text
|
||||
assert "Worked example" in text
|
||||
assert "FIXTURES" in text
|
||||
|
||||
|
||||
def test_build_skill_body_prompt_includes_contract_request_and_draft():
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
draft = SkillDraft(name="probe", description="Probe the service.")
|
||||
@@ -237,20 +245,17 @@ def test_store_roundtrip_all_deliverables(tmp_path):
|
||||
store = SkillStore(str(tmp_path / "skills"))
|
||||
store.write_body("tracking", "probe", GOOD_BODY)
|
||||
store.write_contract("tracking", "probe", GOOD_CONTRACT)
|
||||
store.write_mock("tracking", "probe", GOOD_MOCK)
|
||||
store.write_test("tracking", "probe", GOOD_TEST)
|
||||
store.write_config("tracking", "probe", {"sender_address": "agent@example.com"})
|
||||
directory = store.dir("tracking", "probe")
|
||||
assert sorted(p.name for p in directory.iterdir()) == [
|
||||
"config.json",
|
||||
"contract.json",
|
||||
"mock_data.json",
|
||||
"skill.py",
|
||||
"skill.test.py",
|
||||
]
|
||||
assert store.read_contract("tracking", "probe") == GOOD_CONTRACT
|
||||
assert store.read_config("tracking", "probe") == {"sender_address": "agent@example.com"}
|
||||
assert store.read_mock("tracking", "probe") == GOOD_MOCK
|
||||
assert store.read_category_config("tracking") == {}
|
||||
|
||||
|
||||
@@ -1539,40 +1544,40 @@ def test_generate_data_contract_exhausts_attempts(tmp_path):
|
||||
|
||||
# ---- test artifacts ----
|
||||
|
||||
def test_parse_testgen_bundle_accepts_forms():
|
||||
test, mock = parse_testgen_bundle(GOOD_BUNDLE)
|
||||
assert test == GOOD_TEST.strip()
|
||||
assert mock == GOOD_MOCK
|
||||
fenced = json.dumps({"test": "```python\n" + GOOD_TEST + "```", "mock_data": GOOD_MOCK})
|
||||
test, mock = parse_testgen_bundle(fenced)
|
||||
assert test == GOOD_TEST.strip()
|
||||
assert mock == GOOD_MOCK
|
||||
def test_parse_skill_test_accepts_forms():
|
||||
assert parse_skill_test(GOOD_TEST) == GOOD_TEST.strip()
|
||||
fenced = "```python\n" + GOOD_TEST + "```"
|
||||
assert parse_skill_test(fenced) == GOOD_TEST.strip()
|
||||
wrapped = json.dumps({"code": GOOD_TEST})
|
||||
assert parse_skill_test(wrapped) == GOOD_TEST.strip()
|
||||
with pytest.raises(ValueError):
|
||||
parse_testgen_bundle('{"test": "def x(:"}')
|
||||
parse_skill_test("def x(:")
|
||||
with pytest.raises(ValueError):
|
||||
parse_testgen_bundle('{"mock_data": {}}')
|
||||
parse_skill_test("")
|
||||
with pytest.raises(ValueError):
|
||||
parse_testgen_bundle('{"test": "", "mock_data": {}}')
|
||||
parse_skill_test("some prose without code")
|
||||
|
||||
|
||||
def test_generate_skill_tests_shares_contract_context(tmp_path):
|
||||
"""Decoupled call: the testgen call shares the contract call's base context
|
||||
and continues it with the accepted contract as the assistant turn."""
|
||||
httpd, base = _sequenced_server([GOOD_BUNDLE])
|
||||
and continues it with the accepted contract as the assistant turn; the reply
|
||||
is plain Python (fixtures embedded inline), not a JSON envelope."""
|
||||
httpd, base = _sequenced_server([GOOD_TEST])
|
||||
try:
|
||||
client = CodegenClient(base_url=base, model="test", timeout=10)
|
||||
draft = SkillDraft(name="probe", description="Probe the service.")
|
||||
test, mock = generate_skill_tests(
|
||||
test = generate_skill_tests(
|
||||
client, Request("is the service up?"), "tracking", draft, GOOD_BODY, GOOD_CONTRACT
|
||||
)
|
||||
assert test == GOOD_TEST.strip()
|
||||
assert mock == GOOD_MOCK
|
||||
messages = httpd.RequestHandlerClass.received[0]["messages"]
|
||||
roles = [m["role"] for m in messages]
|
||||
assert roles == ["system", "user", "assistant", "user"]
|
||||
assert messages[2]["content"] == json.dumps(GOOD_CONTRACT)
|
||||
assert "skill.test.py" in messages[3]["content"]
|
||||
assert "mock_data.json" in messages[3]["content"]
|
||||
assert "valid Python" in messages[3]["content"]
|
||||
assert "no JSON" in messages[3]["content"]
|
||||
assert "mock_data.json" not in messages[3]["content"]
|
||||
finally:
|
||||
httpd.shutdown()
|
||||
httpd.server_close()
|
||||
|
||||
+7
-10
@@ -63,12 +63,10 @@ print("ok")
|
||||
sys.exit(0)
|
||||
"""
|
||||
|
||||
GOOD_BUNDLE = json.dumps({"test": GOOD_TEST, "mock_data": {}})
|
||||
|
||||
|
||||
def _pipeline_codegen_server(replies: list) -> tuple[ThreadingHTTPServer, str]:
|
||||
"""Sequenced OpenAI-compatible SSE server for the full authoring pipeline:
|
||||
codegen body -> data contract -> test artifacts. Also answers `/api/show`
|
||||
codegen body -> data contract -> test. Also answers `/api/show`
|
||||
so the client's context-window probe succeeds (never counted)."""
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
@@ -410,7 +408,7 @@ def test_async_skill_write_materializes_merges_and_requeues(tmp_path):
|
||||
and the single-slot worker runs codegen -> contract -> testgen -> test, then
|
||||
materializes the body, hot-merges it into the tree, and re-queues the
|
||||
original request for re-dispatch."""
|
||||
httpd, base = _pipeline_codegen_server([GOOD_BODY, "{}", GOOD_BUNDLE])
|
||||
httpd, base = _pipeline_codegen_server([GOOD_BODY, "{}", GOOD_TEST])
|
||||
try:
|
||||
scheduler = _scheduler(tmp_path, codegen=CodegenClient(base_url=base, model="test", timeout=10))
|
||||
scheduler.tree["tracking"] = [
|
||||
@@ -450,7 +448,6 @@ def test_async_skill_write_materializes_merges_and_requeues(tmp_path):
|
||||
directory = scheduler.body_store.dir("tracking", "track_live")
|
||||
assert sorted(p.name for p in directory.iterdir() if not p.name.startswith("__")) == [
|
||||
"contract.json",
|
||||
"mock_data.json",
|
||||
"skill.py",
|
||||
"skill.test.py",
|
||||
]
|
||||
@@ -566,7 +563,7 @@ def test_elicit_requirements_asks_and_records(tmp_path):
|
||||
"""Opt-in elicitation asks the product owner refinement questions before
|
||||
the body is written and rides the answers on the draft into the body prompt."""
|
||||
httpd, base = _pipeline_codegen_server(
|
||||
['{"questions": ["Draft or send?"]}', GOOD_BODY, "{}", GOOD_BUNDLE]
|
||||
['{"questions": ["Draft or send?"]}', GOOD_BODY, "{}", GOOD_TEST]
|
||||
)
|
||||
try:
|
||||
scheduler = _scheduler(tmp_path, codegen=CodegenClient(base_url=base, model="test", timeout=10))
|
||||
@@ -584,7 +581,7 @@ def test_elicit_requirements_asks_and_records(tmp_path):
|
||||
|
||||
|
||||
def test_elicit_requirements_disabled_skips(tmp_path):
|
||||
httpd, base = _pipeline_codegen_server([GOOD_BODY, "{}", GOOD_BUNDLE])
|
||||
httpd, base = _pipeline_codegen_server([GOOD_BODY, "{}", GOOD_TEST])
|
||||
try:
|
||||
scheduler = _scheduler(tmp_path, codegen=CodegenClient(base_url=base, model="test", timeout=10))
|
||||
scheduler.elicitation_enabled = False
|
||||
@@ -601,7 +598,7 @@ def test_elicit_requirements_disabled_skips(tmp_path):
|
||||
def test_elicit_requirements_asker_none_stops(tmp_path):
|
||||
"""An asker that stops answering (None) halts collection without error."""
|
||||
httpd, base = _pipeline_codegen_server(
|
||||
['{"questions": ["A?", "B?"]}', GOOD_BODY, "{}", GOOD_BUNDLE]
|
||||
['{"questions": ["A?", "B?"]}', GOOD_BODY, "{}", GOOD_TEST]
|
||||
)
|
||||
try:
|
||||
scheduler = _scheduler(tmp_path, codegen=CodegenClient(base_url=base, model="test", timeout=10))
|
||||
@@ -620,9 +617,9 @@ def test_elicit_requirements_asker_none_stops(tmp_path):
|
||||
def test_async_skill_write_regen_ladder_on_failing_test(tmp_path):
|
||||
"""A failing auto-run test triggers the regen decision (regen_test by
|
||||
default when no factory), regenerating the test until it passes."""
|
||||
failing_bundle = json.dumps({"test": "import sys\nsys.exit(1)", "mock_data": {}})
|
||||
failing_test = "import sys\nsys.exit(1)"
|
||||
httpd, base = _pipeline_codegen_server(
|
||||
[GOOD_BODY, "{}", failing_bundle, GOOD_BUNDLE]
|
||||
[GOOD_BODY, "{}", failing_test, GOOD_TEST]
|
||||
)
|
||||
try:
|
||||
scheduler = _scheduler(tmp_path, codegen=CodegenClient(base_url=base, model="test", timeout=10))
|
||||
|
||||
Reference in new issue
Block a user