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:
Denton Social committed 2026-09-26 00:04:23 -05:00
1 parent ddd2495f81
commit 06ccfb77c6
11 files changed
+192 -152

No files matched your search

+66 -26
View File
@@ -1,19 +1,18 @@
# TESTGEN.md — the contract for skill test artifacts
This file is the authoritative spec for the **testing/mocking** side of a
skill. It is fed verbatim (alongside the finished `skill.py`) to the model that
produces the test artifacts. The runnable body contract lives in `SKILL.md`;
this file is deliberately separate so the body writer never embeds mock data
and the test writer never worries about body semantics.
This file is the authoritative spec for the **testing** side of a skill. It is
fed verbatim (alongside the finished `skill.py`) to the model that produces the
test artifact. The runnable body contract lives in `SKILL.md`; this file is
deliberately separate so the body writer never embeds test data and the test
writer never worries about body semantics.
A finished skill leaf is a folder
`data/skills/<category>/<name>/` containing (among others) three artifacts
`data/skills/<category>/<name>/` containing (among others) two artifacts
produced here:
| File | Meaning |
| ----------------- | ------------------------------------------------------------------ |
| `contract.json` | The skill's data contract: what the runner must provide. |
| `mock_data.json` | Fixture data the auto-run test exercises the skill against. |
| `skill.test.py` | A stdlib-only test, runnable as `python skill.test.py`. |
## contract.json
@@ -32,8 +31,8 @@ This contract exists for exactly two consumers:
Therefore the contract must be flat and semantic. Do NOT put type declarations,
validation logic, or nested data structures in it — the skill body and the test
implement whatever type safety and validation they need on their own. The test
writer consumes `skill.py` in context and keeps the artifacts compatible, so
the contract never has to carry that burden. Convoluted structure here is
writer consumes `skill.py` in context and keeps the artifact compatible, so the
contract never has to carry that burden. Convoluted structure here is
pointless: it only confuses the human and the decision model.
Rules:
@@ -48,37 +47,78 @@ Rules:
the body does not use.
- Do not include keys for purely internal/derived values.
## mock_data.json
Fixture data that satisfies the contract and lets the test exercise the skill
end to end. Any JSON value (object, array, scalar). It is written next to
`skill.test.py` and loaded relative to the script's working directory.
## skill.test.py
A stdlib-only Python script that:
- Runs as `python skill.test.py` from the skill folder (its cwd is the folder,
so `mock_data.json` is reachable at `./mock_data.json`).
- Exercises the skill's `predict` and `act` against `mock_data.json` — call
them directly with a real-ish `ActionContext` (a fake `engine` is acceptable
so the `skill` module is importable at `import skill`).
- Embeds its fixture data **inline** as Python literals — no external files, no
network, no writes outside the folder.
- Exercises the skill's `predict` and `act` against those fixtures — call them
directly with a real-ish `ActionContext` (a fake `engine` is acceptable
**in the test only**; the test is the exception to the no-mocking rule).
- Exits 0 on success and non-zero on failure (use `assert`/`sys.exit(1)` with a
message). No third-party imports, no network, no writes outside the folder.
message). No third-party imports.
- Covers at least the happy path and one edge case (missing input, unclear
request, unreachable target).
## Acceptance criteria
The test artifacts are accepted only if:
The test artifact is accepted only if:
1. `contract.json` is a single flat object of snake_case keys to semantic
descriptions, and every `ctx.config[...]` operational access in `skill.py`
has a matching key.
2. `mock_data.json` is valid JSON satisfying the contract.
3. `skill.test.py` parses as Python, imports only the stdlib and the agent
package, and runs to exit 0 when executed against `mock_data.json`.
2. `skill.test.py` parses as Python, imports only the stdlib and the agent
package, embeds its fixtures inline (no external files), and runs to exit 0
when executed from the skill folder.
Produce the three artifacts in this order: first `contract.json` (derived from
`skill.py`), then `skill.test.py` + `mock_data.json` together (derived from the
same `skill.py` plus the contract, so they stay consistent).
Produce the two artifacts in this order: first `contract.json` (derived from
`skill.py`), then `skill.test.py` (derived from the same `skill.py` plus the
contract, with fixture data embedded inline).
## Worked example
A body that reads `tracking_id` from `ctx.config` and checks a delivery status.
The test embeds its fixtures inline, imports the `skill` module (its cwd is the
skill folder), and runs as `python skill.test.py`:
```python
import json
import sys
from semif_agent.skills import ActionContext, DecisionResult, Request
FIXTURES = {
"tracking_id": "AB123XYZ",
"status": "delivered",
}
class FakeEngine:
def call(self, decision):
return DecisionResult(
state=decision.state,
question=decision.question,
options=decision.options,
predicted_probs=[1.0] + [0.0] * (len(decision.options) - 1),
selected=decision.options[0].id,
)
def main():
ctx = ActionContext(engine=FakeEngine(), config=dict(FIXTURES))
req = Request("track my drone delivery in real time")
skill = __import__("skill")
pred = skill.predict(ctx, req)
assert pred.text, "predict must produce a forecast"
result = skill.act(ctx, req, pred)
assert result.action_log, "act must log what it did"
print(result.action_log)
print("ok")
if __name__ == "__main__":
main()
```