real seed skills: replace fake email/tracking built-ins with calendar.next_event
email.compose and tracking.check were hardcoded fakes (draft files / local JSON, no real service) that shadowed the authoring path for real skills. Remove them, delete their data fixtures and config keys, and ship a real starter integration instead: seeds/calendar/next_event, a Nextcloud CalDAV body in the SKILL.md folder format (PROPFIND calendar discovery + SemIf calendar choice, calendar-query REPORT with server-side recurrence expansion, all-day/TZID parsing, honest failures) with a hermetic skill.test.py. merge_seed_store loads seeds into every tree at startup; recorded config lands in gitignored data/skills/, and generated bodies replace seeds of the same name. Only service-free response.reject stays built-in.
This commit is contained in:
1 parent
dde034f1b4
commit
b66d1e325a
19 files changed
+877
-101
No files matched your search
@@ -8,7 +8,6 @@ local LLM endpoint. If either is unavailable this fails loudly — no mocking.
|
||||
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -57,16 +56,46 @@ def require_real(config: dict):
|
||||
pytest.fail(f"real engine unavailable: {exc}")
|
||||
|
||||
|
||||
def _install_tracking_fixture(scheduler):
|
||||
"""A deterministic runnable leaf for end-to-end runs.
|
||||
|
||||
The pipeline tests need a target whose flow is stable; the hardcoded
|
||||
email/tracking examples were removed because they faked their integrations.
|
||||
This injects a runnable tracking leaf instead — the decision engine, the
|
||||
self-assessment LLM, and the decision log all remain real.
|
||||
"""
|
||||
|
||||
def predict(ctx, request):
|
||||
return Prediction(text="", decisions=[])
|
||||
|
||||
def act(ctx, request, prediction):
|
||||
return ActionResult(
|
||||
action_log="tracking fixture: checked the package status",
|
||||
new_state="package status checked",
|
||||
)
|
||||
|
||||
scheduler.tree["tracking"] = [
|
||||
Skill(
|
||||
name="tracking.check",
|
||||
category="tracking",
|
||||
description="Check the delivery status of a package.",
|
||||
predict=predict,
|
||||
act=act,
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def test_pipeline_end_to_end(tmp_path):
|
||||
config = load_config()
|
||||
require_real(config)
|
||||
config["log"] = str(tmp_path / "decisions.jsonl")
|
||||
config["trace"] = str(tmp_path / "runs.jsonl")
|
||||
scheduler, config = build_scheduler(config)
|
||||
_install_tracking_fixture(scheduler)
|
||||
|
||||
inputs = [
|
||||
"send my girlfriend an email that says I'm going to be late to the party",
|
||||
"tell me if my package was delivered",
|
||||
"what is the delivery status of my parcel",
|
||||
]
|
||||
for text in inputs:
|
||||
status, detail = scheduler.submit(text)
|
||||
@@ -95,9 +124,6 @@ def test_pipeline_end_to_end(tmp_path):
|
||||
skills = scheduler.status()
|
||||
assert "queue:" in skills
|
||||
|
||||
contacts_path = Path(config.get("skills", {}).get("contacts", "data/contacts.json"))
|
||||
assert contacts_path.is_file()
|
||||
|
||||
|
||||
def test_busy_choice_path(tmp_path):
|
||||
config = load_config()
|
||||
@@ -105,9 +131,10 @@ def test_busy_choice_path(tmp_path):
|
||||
config["log"] = str(tmp_path / "decisions.jsonl")
|
||||
config["trace"] = str(tmp_path / "runs.jsonl")
|
||||
scheduler, config = build_scheduler(config)
|
||||
_install_tracking_fixture(scheduler)
|
||||
|
||||
scheduler.busy("driving on the freeway", skill="driving")
|
||||
status, detail = scheduler.submit("send my girlfriend an email that says I'm going to be late")
|
||||
status, detail = scheduler.submit("tell me if my package was delivered")
|
||||
print(f"[{status}] {detail}")
|
||||
assert status in ("preempted", "queued", "dropped")
|
||||
scheduler.idle()
|
||||
|
||||
@@ -44,6 +44,7 @@ from semif_agent.codegen import (
|
||||
)
|
||||
from semif_agent.decisions import Request
|
||||
from semif_agent.skills import (
|
||||
Skill,
|
||||
SkillDraft,
|
||||
SkillStore,
|
||||
build_skills,
|
||||
@@ -155,6 +156,13 @@ def test_testgen_contract_embeds_fixtures_inline():
|
||||
|
||||
def test_build_skill_body_prompt_includes_contract_request_and_draft():
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
tree["tracking"] = [
|
||||
Skill(
|
||||
name="tracking.check",
|
||||
category="tracking",
|
||||
description="Check the delivery status of a package.",
|
||||
)
|
||||
]
|
||||
draft = SkillDraft(name="probe", description="Probe the service.")
|
||||
messages = build_skill_body_prompt(
|
||||
Request("check if the service is up"), "tracking", draft, tree, "THE CONTRACT"
|
||||
|
||||
@@ -34,11 +34,11 @@ def test_result_selected_and_probs():
|
||||
|
||||
def test_request_requeue_preserves_state():
|
||||
original = Request(text="t", priority=0.7)
|
||||
original.resume["from_skill"] = "email.compose"
|
||||
original.resume["from_skill"] = "response.reject"
|
||||
updated = original.copy_for_requeue()
|
||||
assert updated.id == original.id
|
||||
assert updated.priority == original.priority
|
||||
assert updated.resume["from_skill"] == "email.compose"
|
||||
assert updated.resume["from_skill"] == "response.reject"
|
||||
assert updated.reentries == original.reentries + 1
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ def build_scheduler(tmp_path):
|
||||
engine=engine,
|
||||
llm=llm,
|
||||
log=log,
|
||||
config={"skills": {}},
|
||||
config={"skills": {}, "skill_seeds": str(tmp_path / "seeds")},
|
||||
trace=trace,
|
||||
)
|
||||
return scheduler
|
||||
@@ -81,8 +81,8 @@ def test_tree_endpoint(tmp_path):
|
||||
try:
|
||||
status, payload = server.get("/api/tree")
|
||||
assert status == 200
|
||||
assert "email" in payload["categories"]
|
||||
assert any(s["name"] == "email.compose" for s in payload["categories"]["email"])
|
||||
assert "response" in payload["categories"]
|
||||
assert any(s["name"] == "response.reject" for s in payload["categories"]["response"])
|
||||
finally:
|
||||
server.close()
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ def build_scheduler(tmp_path):
|
||||
engine=engine,
|
||||
llm=llm,
|
||||
log=log,
|
||||
config={"skills": {}},
|
||||
config={"skills": {}, "skill_seeds": str(tmp_path / "seeds")},
|
||||
trace=trace,
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
"""The committed seed skills are real, inspectable, and hermetically tested.
|
||||
|
||||
A seed is a starter integration shipped in the repo in the SKILL.md folder
|
||||
format. These tests keep it honest: the declared integration must match the
|
||||
code, the contract must cover what the body reads, and the hermetic mechanics
|
||||
test must pass. They are not proof of the live integration — only a real run
|
||||
against the user's service is (see AGENTS.md).
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from semif_agent.codegen import integration_findings, parse_integration, run_skill_test
|
||||
|
||||
SEED = Path(__file__).resolve().parent.parent / "seeds" / "calendar" / "next_event"
|
||||
|
||||
|
||||
def test_seed_declares_a_real_integration():
|
||||
code = (SEED / "skill.py").read_text()
|
||||
integration = parse_integration(code)
|
||||
assert integration["service"] == "nextcloud_calendar"
|
||||
assert integration["transport"] == "caldav"
|
||||
assert integration_findings(integration, "declared", code) == []
|
||||
|
||||
|
||||
def test_seed_contract_is_flat_and_covered_by_declaration():
|
||||
code = (SEED / "skill.py").read_text()
|
||||
contract = json.loads((SEED / "contract.json").read_text())
|
||||
assert contract, "the seed must carry a data contract"
|
||||
for name, description in contract.items():
|
||||
assert name.islower() and " " not in name, name
|
||||
assert isinstance(description, str) and description.strip()
|
||||
integration = parse_integration(code)
|
||||
assert set(integration["config_vars"]) == set(contract)
|
||||
|
||||
|
||||
def test_seed_has_manifest_description():
|
||||
manifest = json.loads((SEED / "manifest.json").read_text())
|
||||
assert manifest["description"].strip()
|
||||
|
||||
|
||||
def test_seed_hermetic_test_passes(monkeypatch):
|
||||
root = str(SEED.parents[2])
|
||||
existing = os.environ.get("PYTHONPATH", "")
|
||||
monkeypatch.setenv("PYTHONPATH", root + os.pathsep + existing)
|
||||
passed, output = run_skill_test(SEED, timeout=30)
|
||||
assert passed, output
|
||||
+99
-1
@@ -12,6 +12,7 @@ import json
|
||||
import threading
|
||||
import time
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -37,6 +38,8 @@ from semif_agent.skills import (
|
||||
generate_category,
|
||||
generate_skill,
|
||||
merge_registry,
|
||||
merge_seed_store,
|
||||
merge_skill_store,
|
||||
navigate,
|
||||
parse_category_draft,
|
||||
parse_skill_draft,
|
||||
@@ -122,6 +125,7 @@ def _scheduler(tmp_path, codegen=None):
|
||||
"skills": {},
|
||||
"category_registry": str(tmp_path / "categories.json"),
|
||||
"skill_bodies": str(tmp_path / "skills"),
|
||||
"skill_seeds": str(tmp_path / "seeds"),
|
||||
},
|
||||
trace=TraceLog(str(tmp_path / "runs.jsonl")),
|
||||
codegen=codegen,
|
||||
@@ -139,7 +143,14 @@ def test_build_category_prompt_contains_request_and_tree():
|
||||
assert "category" in messages[0]["content"]
|
||||
joined = messages[1]["content"]
|
||||
assert "tracking for my drone delivery" in joined
|
||||
assert "email: email.compose" in joined
|
||||
assert "response: response.reject" in joined
|
||||
|
||||
|
||||
def test_build_skills_is_internal_behaviors_only():
|
||||
"""Real integrations are generated or seeded, never fabricated here: a
|
||||
hardcoded fake shadows the authoring path for a real skill (navigation
|
||||
routes to it). Only service-free behaviors stay built-in."""
|
||||
assert [skill.name for skill in build_skills({"skills": {}})] == ["response.reject"]
|
||||
|
||||
|
||||
def test_parse_category_draft_plain_json():
|
||||
@@ -212,6 +223,13 @@ def test_build_tree_includes_registry_stubs(tmp_path):
|
||||
|
||||
def test_build_skill_prompt_contains_request_category_and_skills():
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
tree["tracking"] = [
|
||||
Skill(
|
||||
name="tracking.check",
|
||||
category="tracking",
|
||||
description="Check the delivery status of a package.",
|
||||
)
|
||||
]
|
||||
messages = build_skill_prompt(Request("tracking for my drone delivery"), "tracking", tree)
|
||||
assert messages[0]["role"] == "system"
|
||||
assert "tracking" in messages[0]["content"]
|
||||
@@ -312,6 +330,71 @@ def test_merge_registry_loads_categories_and_skills(tmp_path):
|
||||
assert tree["delivery"][0].category == "delivery"
|
||||
|
||||
|
||||
def _write_seed(seed_store, category, name, description=""):
|
||||
directory = seed_store.dir(category, name)
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
(directory / "skill.py").write_text(GOOD_BODY)
|
||||
(directory / "contract.json").write_text(json.dumps({"probe_url": "Where to probe."}))
|
||||
if description:
|
||||
(directory / "manifest.json").write_text(json.dumps({"description": description}))
|
||||
|
||||
|
||||
def test_merge_seed_store_loads_skill_with_runtime_config(tmp_path):
|
||||
"""A seed is runnable from the committed folder; recorded config lives in
|
||||
the runtime store, never in the seed folder."""
|
||||
seed_store = SkillStore(str(tmp_path / "seeds"))
|
||||
config_store = SkillStore(str(tmp_path / "skills"))
|
||||
_write_seed(seed_store, "calendar", "probe", description="Probe a service.")
|
||||
config_store.write_config("calendar", "probe", {"probe_url": "https://example.test"})
|
||||
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
loaded = merge_seed_store(tree, seed_store, config_store)
|
||||
assert loaded == 1
|
||||
skill = tree["calendar"][0]
|
||||
assert skill.status == "ready"
|
||||
assert skill.description == "Probe a service."
|
||||
assert skill.contract == {"probe_url": "Where to probe."}
|
||||
assert skill.config == {"probe_url": "https://example.test"}
|
||||
assert skill.integration_source == "declared"
|
||||
|
||||
|
||||
def test_merge_seed_store_falls_back_to_name_and_body_store_wins(tmp_path):
|
||||
seed_store = SkillStore(str(tmp_path / "seeds"))
|
||||
body_store = SkillStore(str(tmp_path / "skills"))
|
||||
_write_seed(seed_store, "calendar", "probe")
|
||||
|
||||
tree = build_tree(build_skills({"skills": {}}))
|
||||
merge_seed_store(tree, seed_store, body_store)
|
||||
assert tree["calendar"][0].description == "probe"
|
||||
|
||||
body_store.write_body("calendar", "probe", GOOD_BODY)
|
||||
merge_skill_store(tree, body_store, {})
|
||||
assert tree["calendar"][0].description == "probe", "the generated body replaces the seed"
|
||||
assert len(tree["calendar"]) == 1
|
||||
|
||||
|
||||
def test_scheduler_loads_committed_seed_skills(tmp_path):
|
||||
"""The real seed package ships in the tree at startup with its manifest
|
||||
description and declared integration."""
|
||||
seed_root = Path(__file__).resolve().parent.parent / "seeds"
|
||||
scheduler = Scheduler(
|
||||
engine=SemIfEngine(EngineConfig()),
|
||||
llm=LLMClient(base_url="http://localhost:1/v1", model="test"),
|
||||
log=DecisionLog(str(tmp_path / "decisions.jsonl")),
|
||||
config={
|
||||
"category_registry": str(tmp_path / "categories.json"),
|
||||
"skill_bodies": str(tmp_path / "skills"),
|
||||
"skill_seeds": str(seed_root),
|
||||
},
|
||||
trace=TraceLog(str(tmp_path / "runs.jsonl")),
|
||||
)
|
||||
calendar = scheduler.tree["calendar"]
|
||||
assert [s.name for s in calendar] == ["next_event"]
|
||||
assert calendar[0].description.startswith("Report the next")
|
||||
assert calendar[0].status == "ready"
|
||||
assert calendar[0].integration["transport"] == "caldav"
|
||||
|
||||
|
||||
def test_navigate_empty_tree_short_circuits(tmp_path):
|
||||
"""An empty tree goes straight to CreateCategory without a SemIf call."""
|
||||
log = DecisionLog(str(tmp_path / "decisions.jsonl"))
|
||||
@@ -335,6 +418,7 @@ def test_dispatch_create_category_without_engine_returns_error(tmp_path):
|
||||
"skills": {},
|
||||
"category_registry": str(tmp_path / "categories.json"),
|
||||
"skill_bodies": str(tmp_path / "skills"),
|
||||
"skill_seeds": str(tmp_path / "seeds"),
|
||||
},
|
||||
trace=trace,
|
||||
)
|
||||
@@ -775,6 +859,18 @@ def _repair_offer(offer_id="r1", selected="repair_skill", skill="tracking.check"
|
||||
)
|
||||
|
||||
|
||||
def _install_tracking_stub(scheduler):
|
||||
"""A repair rewrite needs the leaf to exist in the tree (a real skill that
|
||||
failed), so a runnable body can replace it."""
|
||||
scheduler.tree["tracking"] = [
|
||||
Skill(
|
||||
name="tracking.check",
|
||||
category="tracking",
|
||||
description="Check the delivery status of a package.",
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def test_resolve_repair_no_repair_declines(tmp_path):
|
||||
scheduler = _scheduler(tmp_path)
|
||||
scheduler.repairs.append(_repair_offer())
|
||||
@@ -799,6 +895,7 @@ def test_resolve_repair_ask_user_question_then_answer_starts_repair(tmp_path):
|
||||
tmp_path,
|
||||
codegen=CodegenClient(base_url="http://127.0.0.1:1/v1", model="test", timeout=2),
|
||||
)
|
||||
_install_tracking_stub(scheduler)
|
||||
scheduler.repairs.append(_repair_offer(selected="ask_user"))
|
||||
status, _ = scheduler.resolve_repair("r1")
|
||||
assert status == "needs_input"
|
||||
@@ -819,6 +916,7 @@ def test_repair_budget_is_bounded(tmp_path):
|
||||
tmp_path,
|
||||
codegen=CodegenClient(base_url="http://127.0.0.1:1/v1", model="test", timeout=2),
|
||||
)
|
||||
_install_tracking_stub(scheduler)
|
||||
scheduler.repairs.append(_repair_offer("r1"))
|
||||
assert scheduler.resolve_repair("r1")[0] == "running"
|
||||
scheduler.repairs.append(_repair_offer("r2"))
|
||||
|
||||
Reference in new issue
Block a user