Skip to content

Commit 3c7157e

Browse files
committed
test(engine): dogfood e2e — oracle gates ship-check (genuine pass ships, reward-hack blocked)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c0094b6 commit 3c7157e

2 files changed

Lines changed: 376 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Oracle Slice-1 DOGFOOD — cross-repo acceptance test
2+
3+
**Date:** 2026-06-16
4+
**Task:** 5.3 — cross-repo DOGFOOD acceptance test (capstone of Slice 1)
5+
**Test:** `tests/core/test_oracle_dogfood.py` (engine worktree)
6+
**Status:** GREEN — 3/3 passed (real podman, real CLI, real ship-check subprocess; no mocks)
7+
8+
## What was proven
9+
10+
The unfakable Atlas oracle gates a real `prd-taskmaster` ship-check end-to-end.
11+
For each DONE task, `skel/ship-check.py` (Gate 5) shells `atlas oracle grade`,
12+
which checks out the submitted commit into a throwaway worktree, **overlays the
13+
operator-held tests over the submitter's tree**, re-executes the card's grading
14+
command inside a digest-pinned podman sandbox, derives `PASS` iff exit 0, and
15+
appends a tamper-evident ledger event.
16+
17+
1. **Genuine pass ships.** Operator-held `grade.sh` = `exit 0`. Ship-check emits
18+
`SHIP_CHECK_OK`, returncode 0, and the ledger records `verdict == "PASS"`.
19+
2. **Reward hack blocked (the acceptance criterion).** The submitter ships a
20+
cheat — a committed `grade.sh` that always `exit 0` — while the operator-held
21+
`grade.sh` is `exit 1`. The cheat does **NOT** ship: the oracle overlays and
22+
re-executes the operator's copy, so the verdict is `FAIL`. `SHIP_CHECK_OK` is
23+
absent, returncode is non-zero, stderr names the oracle FAIL for task 1, and
24+
the ledger records `verdict == "FAIL"`. **Non-vacuous:** the only difference
25+
between case 1 and case 2 is which `grade.sh` the oracle re-runs — the
26+
submitter's committed copy never reaches the verdict.
27+
3. **Ledger integrity.** `atlas ledger verify <dir>` reports
28+
`{"ok": true, "eventCount": 1}` after the genuine pass.
29+
30+
## ATLAS_ORACLE_CMD used
31+
32+
```
33+
ATLAS_ORACLE_CMD="/home/anombyte/Hermes/current-projects/.worktrees/atlas-coin-oracle/node_modules/.bin/tsx /home/anombyte/Hermes/current-projects/.worktrees/atlas-coin-oracle/apps/cli/src/index.ts"
34+
```
35+
36+
`ship-check.py` shlex-splits `ATLAS_ORACLE_CMD` and appends
37+
`oracle grade --repo <root> --commit <HEAD> --card ... --held ... --evidence ... --ledger ...`.
38+
39+
**Why `tsx` on the CLI source and not `node dist/index.js`:** the spine
40+
monorepo's workspace packages (`@atlas-protocol/core|cards|evidence|executor`)
41+
declare `exports: "./src/index.ts"`, so the compiled `apps/cli/dist/index.js`
42+
resolves its workspace deps to TypeScript sources that bare `node` cannot load
43+
(`ERR_MODULE_NOT_FOUND: .../packages/executor/src/grade.js`). The `tsx`
44+
executable runs the identical CLI code path the spine's own vitest suite uses,
45+
with **no edits to the spine repo**. (Building the CLI — `pnpm --filter
46+
@atlas-protocol/cli build`, plus `pnpm -r build` for the workspace deps — was
47+
done as Step 0 and is required so the source resolves; the dist itself is not
48+
the run target.)
49+
50+
## Observed results
51+
52+
### Pass case (operator-held `grade.sh` = `exit 0`)
53+
54+
```
55+
$ ATLAS_ORACLE_CMD="$TSX $SRC" python3 skel/ship-check.py --cwd /tmp/ev_pass
56+
SHIP_CHECK_OK
57+
rc=0
58+
```
59+
60+
Ledger event payload (excerpt):
61+
62+
```json
63+
{
64+
"type": "verification.completed",
65+
"actor": { "kind": "executor", "id": "oracle" },
66+
"lifecycleState": "verification_passed",
67+
"payload": { "verdict": "PASS", "exitCode": 0, "overlayHash": "sha256:..." }
68+
}
69+
```
70+
71+
### Reward-hack case (submitter cheat `exit 0`, operator-held `exit 1`)
72+
73+
```
74+
$ ATLAS_ORACLE_CMD="$TSX $SRC" python3 skel/ship-check.py --cwd /tmp/ev_hack
75+
rc=1
76+
--- stdout (empty — no SHIP_CHECK_OK) ---
77+
--- stderr ---
78+
FAIL: task 1: oracle verdict FAIL
79+
```
80+
81+
The committed cheat (`exit 0`) was overlaid away by the operator-held `exit 1`
82+
and re-executed in the sandbox → verdict `FAIL` → ship blocked.
83+
84+
## pytest
85+
86+
```
87+
$ python3 -m pytest tests/core/test_oracle_dogfood.py -v
88+
tests/core/test_oracle_dogfood.py::test_genuine_pass_ships PASSED [ 33%]
89+
tests/core/test_oracle_dogfood.py::test_reward_hack_blocked PASSED [ 66%]
90+
tests/core/test_oracle_dogfood.py::test_ledger_integrity PASSED [100%]
91+
============================== 3 passed in 13.05s ==============================
92+
```
93+
94+
## Slice-2 hardening note
95+
96+
The Graded Card's `contentHash` is a syntactically valid placeholder.
97+
`gradeSubmission` does not re-verify `contentHash` against the card body in
98+
Slice 1 (it is only echoed into the ledger payload). Slice 2 should recompute
99+
and verify it before grading so a tampered card body cannot be graded under a
100+
stale hash. (Also tracked in the executor's `SLICE-1` deferral comments:
101+
infra-failure exit codes are currently recorded as `FAIL`, and `evidenceRef`
102+
records a path rather than a `sha256:`-prefixed content ref.)

tests/core/test_oracle_dogfood.py

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
"""Cross-repo DOGFOOD acceptance test — the capstone of Slice 1.
2+
3+
This is a REAL end-to-end proof (no mocks) that the unfakable Atlas oracle gates
4+
a genuine `prd-taskmaster` ship-check. For each DONE task, the standalone
5+
`skel/ship-check.py` (Gate 5) shells the `atlas oracle grade` CLI, which:
6+
7+
1. checks out the submitted commit into a throwaway detached worktree,
8+
2. OVERLAYS the operator-held tests over the submitter's tree (the submitter's
9+
own copy of the graded path is REPLACED by the operator's held copy),
10+
3. re-executes the card's grading command inside a digest-pinned podman sandbox,
11+
4. derives PASS iff exit 0, and writes a tamper-evident ledger event.
12+
13+
The acceptance criterion is the reward-hack test: a submitter who ships a
14+
`grade.sh` that always `exit 0` (a cheat that would pass if the submitter
15+
controlled grading) does NOT ship, because the operator-held `grade.sh`
16+
(`exit 1`) is overlaid and re-executed by the oracle. The cheat never touches
17+
the verdict.
18+
19+
────────────────────────────────────────────────────────────────────────────────
20+
ATLAS_ORACLE_CMD
21+
The oracle CLI lives in the SPINE worktree (a separate monorepo). Its
22+
workspace packages declare `exports: "./src/index.ts"`, so the compiled
23+
`apps/cli/dist/index.js` cannot be run by bare `node` — it would resolve the
24+
workspace deps to their TypeScript sources. We therefore invoke the CLI the
25+
same way the spine's own vitest suite does: through the `tsx` executable on
26+
the CLI source entrypoint. This requires NO edits to the spine repo and runs
27+
the identical code path. The resulting command is:
28+
29+
ATLAS_ORACLE_CMD="<spine>/node_modules/.bin/tsx <spine>/apps/cli/src/index.ts"
30+
31+
ship-check.py shlex-splits ATLAS_ORACLE_CMD and appends `oracle grade ...`.
32+
33+
SLICE-2 HARDENING NOTE
34+
The Graded Card's `contentHash` is a syntactically valid placeholder here.
35+
`gradeSubmission` does NOT re-verify the contentHash against the card body in
36+
Slice 1 (it is only echoed into the ledger payload), so a placeholder is
37+
accepted. Slice 2 should recompute and verify the contentHash before grading
38+
so a tampered card body cannot be graded under a stale hash.
39+
"""
40+
from __future__ import annotations
41+
42+
import hashlib
43+
import json
44+
import os
45+
import shutil
46+
import subprocess
47+
from pathlib import Path
48+
49+
import pytest
50+
51+
# ── Repo paths ────────────────────────────────────────────────────────────────
52+
ENGINE_ROOT = Path(__file__).resolve().parents[2]
53+
SKEL_SHIP_CHECK = ENGINE_ROOT / "skel" / "ship-check.py"
54+
55+
# ── Spine (oracle CLI) paths ──────────────────────────────────────────────────
56+
SPINE_ROOT = Path("/home/anombyte/Hermes/current-projects/.worktrees/atlas-coin-oracle")
57+
TSX_BIN = SPINE_ROOT / "node_modules" / ".bin" / "tsx"
58+
CLI_SRC = SPINE_ROOT / "apps" / "cli" / "src" / "index.ts"
59+
# The oracle invocation prefix consumed by ship-check.py via ATLAS_ORACLE_CMD.
60+
CLI_CMD = f"{TSX_BIN} {CLI_SRC}"
61+
62+
ALPINE_REF = "docker.io/library/alpine:3.20"
63+
64+
65+
# ── Capability probes ─────────────────────────────────────────────────────────
66+
def has_podman() -> bool:
67+
return shutil.which("podman") is not None
68+
69+
70+
def has_oracle_cli() -> bool:
71+
return TSX_BIN.exists() and CLI_SRC.exists()
72+
73+
74+
def resolve_alpine_digest() -> str:
75+
"""Pull alpine:3.20 and return its `sha256:...` manifest digest."""
76+
subprocess.run(
77+
["podman", "pull", ALPINE_REF],
78+
check=True, capture_output=True, text=True,
79+
)
80+
proc = subprocess.run(
81+
["podman", "image", "inspect", ALPINE_REF, "--format", "{{.Digest}}"],
82+
check=True, capture_output=True, text=True,
83+
)
84+
digest = proc.stdout.strip()
85+
assert digest.startswith("sha256:"), f"unexpected digest {digest!r}"
86+
return digest
87+
88+
89+
SKIP_REASON = "requires podman + the built atlas oracle CLI (tsx) in the spine worktree"
90+
podman_and_cli = pytest.mark.skipif(
91+
not (has_podman() and has_oracle_cli()), reason=SKIP_REASON
92+
)
93+
94+
95+
# ── Project fixture ───────────────────────────────────────────────────────────
96+
def _git(args: list[str], cwd: Path) -> str:
97+
return subprocess.run(
98+
["git", *args], cwd=cwd, check=True, capture_output=True, text=True
99+
).stdout.strip()
100+
101+
102+
def make_project(tmp_path: Path, *, submitter_grade: str, operator_grade: str):
103+
"""Construct a real mini-project laid out exactly as ship-check's gate_oracle
104+
expects, and return (root, head_sha).
105+
106+
The submitter commits their own `grade.sh` (submitter_grade). The operator's
107+
held copy (operator_grade) lives — uncommitted, on disk only — under
108+
.atlas-ai/held-out/ and is what the oracle overlays + re-executes.
109+
"""
110+
root = tmp_path
111+
digest = resolve_alpine_digest()
112+
113+
# 1. Submitter's working tree: grade.sh committed at root.
114+
(root / "grade.sh").write_text(submitter_grade)
115+
_git(["init", "."], root)
116+
_git(["config", "user.email", "dogfood@atlas.test"], root)
117+
_git(["config", "user.name", "dogfood"], root)
118+
_git(["add", "-A"], root)
119+
# core.hooksPath=/dev/null mirrors the oracle's own git invocations and keeps
120+
# any ambient git hooks out of the committed state.
121+
_git(["-c", "core.hooksPath=/dev/null", "commit", "-m", "work"], root)
122+
head_sha = _git(["rev-parse", "HEAD"], root)
123+
124+
atlas = root / ".atlas-ai"
125+
126+
# 2. Operator-held test bundle (on disk; need not be committed).
127+
held = atlas / "held-out"
128+
held.mkdir(parents=True)
129+
(held / "grade.sh").write_text(operator_grade)
130+
operator_sha256 = hashlib.sha256(operator_grade.encode()).hexdigest()
131+
132+
# 3. Graded Card.
133+
cdd = atlas / "cdd"
134+
cdd.mkdir(parents=True)
135+
card = {
136+
"id": "C-001",
137+
"taskId": 1,
138+
"title": "dogfood",
139+
"given": ["g"],
140+
"when": ["w"],
141+
"then": [{
142+
"index": 1,
143+
"statement": "exit 0",
144+
"evidenceTier": "A",
145+
"evidenceKind": "command-output",
146+
}],
147+
"author": {"kind": "human", "id": "op"},
148+
"createdAt": "2026-06-16T00:00:00.000Z",
149+
# SLICE-2: placeholder contentHash — gradeSubmission does not re-verify it
150+
# in Slice 1 (see module docstring).
151+
"contentHash": "sha256:" + "0" * 64,
152+
"frozenAt": "2026-06-16T00:00:00.000Z",
153+
"grading": {
154+
"command": ["sh", "grade.sh"],
155+
"heldOutTests": [{"path": "grade.sh", "sha256": operator_sha256}],
156+
"gradedPaths": ["grade.sh"],
157+
"baseImage": {"ref": ALPINE_REF, "digest": digest},
158+
"env": {
159+
"LANG": "C", "LC_ALL": "C", "TZ": "UTC",
160+
"SOURCE_DATE_EPOCH": 0, "seed": 0,
161+
"parallelism": 1, "cpuClass": "x86-64-v2",
162+
},
163+
"timeoutMs": 60000,
164+
},
165+
}
166+
(cdd / "task-1.json").write_text(json.dumps(card))
167+
168+
# 4. Gates 1-4 scaffolding so the ORACLE gate (Gate 5) decides the verdict.
169+
state = atlas / "state"
170+
state.mkdir(parents=True)
171+
(state / "pipeline.json").write_text(json.dumps({"current_phase": "EXECUTE"}))
172+
173+
tasks_dir = root / ".taskmaster" / "tasks"
174+
tasks_dir.mkdir(parents=True)
175+
(tasks_dir / "tasks.json").write_text(
176+
json.dumps({"master": {"tasks": [{"id": 1, "status": "done"}]}})
177+
)
178+
docs = root / ".taskmaster" / "docs"
179+
docs.mkdir(parents=True)
180+
(docs / "plan.md").write_text("# Plan\n")
181+
182+
# Oracle output dirs (created by the CLI too, but explicit is clearer).
183+
(atlas / "evidence").mkdir(parents=True, exist_ok=True)
184+
(atlas / "ledger").mkdir(parents=True, exist_ok=True)
185+
186+
return root, head_sha
187+
188+
189+
def run_shipcheck(root: Path) -> subprocess.CompletedProcess:
190+
"""Run the REAL skel/ship-check.py as a subprocess with ATLAS_ORACLE_CMD set."""
191+
return subprocess.run(
192+
["python3", str(SKEL_SHIP_CHECK), "--cwd", str(root)],
193+
capture_output=True,
194+
text=True,
195+
env={**os.environ, "ATLAS_ORACLE_CMD": CLI_CMD},
196+
)
197+
198+
199+
def _read_ledger_event(root: Path) -> dict:
200+
ledger = root / ".atlas-ai" / "ledger"
201+
events = sorted(ledger.glob("*.json"))
202+
assert events, f"no ledger event written under {ledger}"
203+
return json.loads(events[-1].read_text())
204+
205+
206+
# ── Test 1: genuine pass ships ────────────────────────────────────────────────
207+
@podman_and_cli
208+
def test_genuine_pass_ships(tmp_path):
209+
# submitter_grade is irrelevant — the operator-held grade.sh is overlaid.
210+
root, _head = make_project(tmp_path, submitter_grade="exit 1\n", operator_grade="exit 0\n")
211+
212+
proc = run_shipcheck(root)
213+
214+
assert "SHIP_CHECK_OK" in proc.stdout, (
215+
f"expected SHIP_CHECK_OK; rc={proc.returncode}\nSTDOUT:\n{proc.stdout}\nSTDERR:\n{proc.stderr}"
216+
)
217+
assert proc.returncode == 0, f"rc={proc.returncode}\nSTDERR:\n{proc.stderr}"
218+
219+
# The oracle recorded a PASS verdict in the tamper-evident ledger.
220+
event = _read_ledger_event(root)
221+
assert event["type"] == "verification.completed"
222+
assert event["payload"]["verdict"] == "PASS", event["payload"]
223+
224+
225+
# ── Test 2: reward hack blocked (THE acceptance criterion) ────────────────────
226+
@podman_and_cli
227+
def test_reward_hack_blocked(tmp_path):
228+
# The submitter ships a cheat: grade.sh that always passes. The operator-held
229+
# grade.sh fails. Because the oracle overlays + re-executes the operator copy,
230+
# the cheat does NOT ship.
231+
root, _head = make_project(tmp_path, submitter_grade="exit 0\n", operator_grade="exit 1\n")
232+
233+
proc = run_shipcheck(root)
234+
235+
assert "SHIP_CHECK_OK" not in proc.stdout, (
236+
f"REWARD HACK SHIPPED — cheat was not blocked!\nSTDOUT:\n{proc.stdout}"
237+
)
238+
assert proc.returncode != 0, "cheat must produce a non-zero exit"
239+
# The blocked-FAIL is surfaced on stderr for task 1.
240+
assert "oracle" in proc.stderr.lower() and "1" in proc.stderr, (
241+
f"expected an oracle FAIL for task 1 on stderr\nSTDERR:\n{proc.stderr}"
242+
)
243+
244+
# And the ledger records the FAIL verdict — the operator-held test was run.
245+
event = _read_ledger_event(root)
246+
assert event["payload"]["verdict"] == "FAIL", event["payload"]
247+
248+
249+
# ── Test 3: ledger integrity ──────────────────────────────────────────────────
250+
@podman_and_cli
251+
def test_ledger_integrity(tmp_path):
252+
"""After a genuine PASS, the tamper-evident ledger verifies clean.
253+
254+
The spine CLI exposes `ledger verify <dir>` (positional arg). If that
255+
subcommand is unavailable we fall back to re-parsing the event file.
256+
"""
257+
root, _head = make_project(tmp_path, submitter_grade="exit 1\n", operator_grade="exit 0\n")
258+
proc = run_shipcheck(root)
259+
assert "SHIP_CHECK_OK" in proc.stdout, proc.stderr
260+
261+
ledger_dir = root / ".atlas-ai" / "ledger"
262+
verify = subprocess.run(
263+
[str(TSX_BIN), str(CLI_SRC), "ledger", "verify", str(ledger_dir)],
264+
capture_output=True, text=True,
265+
)
266+
if verify.returncode == 0 and verify.stdout.strip():
267+
result = json.loads(verify.stdout)
268+
assert result.get("ok") is True, f"ledger verify reported {result!r}"
269+
assert result.get("eventCount", 0) >= 1, result
270+
else:
271+
# No usable `ledger verify` subcommand — don't fail the task over it;
272+
# confirm the event file at least parses and records the PASS.
273+
event = _read_ledger_event(root)
274+
assert event["payload"]["verdict"] == "PASS", event["payload"]

0 commit comments

Comments
 (0)