open-standards/wai/wai-quantum-cli/smoke.sh
Transaction Science fb230d8a62 wai-quantum: the circuits course as data, each exercise checked by the engine, and wai-quantum learn in English and Chinese
engine::course reads the course from wai-quantum/course/: 21 lessons from a
first circuit through superposition, entanglement, interference, the standard
algorithms, noise and mitigation, error correction and fault tolerance to
resource estimates, each a Markdown text in English and Simplified Chinese and
an exercise.json with a schema. A check runs each case of an exercise (a
generator's inputs) with its intent and the verdict, measures its constraints
(the gates allowed, counts, the T count, the critique's smells, the resource
estimate's counts), and says what went wrong from the diagnostics, the verdict
and the critique, never from the solution. The tests hold every solution to
pass by proof, every known wrong answer to fail for its stated reason, and
every locale to every text and message.

wai-quantum learn shows, starts, checks, hints and explains a lesson, keeps
progress only on this machine, and speaks the language --lang or LANG names;
the command summaries and docs topics have Chinese translations held to the
English they came from. The verdict gains of_diagnostic for a generator's
refusal. llms.txt names the course.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 08:42:54 -04:00

416 lines
24 KiB
Shell

#!/usr/bin/env bash
# smoke.sh: the command line as a reader uses it, every check exact.
#
# bash smoke.sh path/to/wai-quantum [SERVICE_URL]
#
# With SERVICE_URL, `submit` sends one job to the service there and its
# receipt is checked here. Each command's output is written to a file before
# it is read, so no check depends on a pipe closing early.
set -euo pipefail
# The binary as an absolute path, for the steps below that run from another directory.
case "$1" in
*/*) W="$(cd "$(dirname "$1")" && pwd)/$(basename "$1")" ;;
*) W="$1" ;;
esac
SVC="${2:-}"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
export XDG_CONFIG_HOME="$tmp/config"
unset WAI_QUANTUM_KEY
fail() { echo "smoke: $*" >&2; exit 1; }
has() { grep -q -- "$2" "$1" || { echo "--- $1:" >&2; cat "$1" >&2; fail "expected: $2"; }; }
cat > "$tmp/ghz.qasm" <<'EOF'
OPENQASM 3.0;
include "stdgates.inc";
qubit[3] q;
bit[3] c;
h q[0];
cx q[0], q[1];
cx q[1], q[2];
c = measure q;
EOF
"$W" lint "$tmp/ghz.qasm" > "$tmp/lint"
has "$tmp/lint" "ok — 3 qubits, 3 gates, 3 bits measured"
printf 'OPENQASM 3.0;\nqubit[1] q;\nfoo q[0];\n' > "$tmp/bad.qasm"
if "$W" lint "$tmp/bad.qasm" > "$tmp/lint-bad"; then fail "lint passed a program with an unknown gate"; fi
has "$tmp/lint-bad" "bad.qasm:3: unknown gate foo \[Q103\]"
"$W" lint --json "$tmp/bad.qasm" > "$tmp/lint-bad.json" || true
python3 -c 'import json,sys; v=json.load(open(sys.argv[1])); assert (v["code"], v["line"], v["column"], v["length"]) == ("Q103", 3, 1, 3), v' "$tmp/lint-bad.json"
"$W" diagnostics > "$tmp/codes"
has "$tmp/codes" "Q103 refused"
"$W" diagnostics --json > "$tmp/codes.json"
python3 -c 'import json,sys; t=json.load(open(sys.argv[1])); assert any(c["code"]=="Q103" and c["outcome"]=="refused" for c in t["codes"]), t' "$tmp/codes.json"
echo "lint: ok, with codes"
"$W" plan "$tmp/ghz.qasm" --json > "$tmp/plan.json"
python3 -c 'import json,sys; p=json.load(open(sys.argv[1])); assert p["method"]=="stabilizer" and p["qubits"]==3, p' "$tmp/plan.json"
echo "plan: ok, stabilizer"
"$W" run "$tmp/ghz.qasm" --shots 1000 -o "Z0 Z2" --json > "$tmp/job.json" 2> "$tmp/run.err"
has "$tmp/run.err" "made a signing key"
python3 - "$tmp/job.json" <<'EOF'
import json, sys
j = json.load(open(sys.argv[1]))
r = j["result"]
assert j["status"] == "done" and j["method"] == "stabilizer", j
assert set(r["counts"]) <= {"000", "111"} and sum(r["counts"].values()) == 1000, r["counts"]
assert r["expectations"][0]["value"] == 1.0, r["expectations"]
assert r["receipt"]["alg"] == "ed25519" and len(r["receipt"]["key"]) == 64, r["receipt"]
assert j["request"] == {"qasm": j["request"]["qasm"], "shots": 1000, "observables": ["Z0 Z2"]}, j["request"]
assert r["engine"]["name"] == "wai-quantum" and r["schema"] == "wai.quantum.job-result/1", r
EOF
# The versions it reports: its own, the engine's (the one its results name),
# each schema's, and where the policy is.
"$W" version --json > "$tmp/version.json"
python3 - "$tmp/version.json" "$tmp/job.json" <<'EOF'
import json, sys
v = json.load(open(sys.argv[1])); r = json.load(open(sys.argv[2]))["result"]
assert v["schema"] == "wai.quantum.versions/1" and v["host"]["name"] == "wai-quantum-cli", v
assert v["engine"] == r["engine"], (v["engine"], r["engine"])
assert v["schemas"]["job_result"] == r["schema"] and v["policy"].endswith("/VERSIONING.md"), v
EOF
echo "version: ok"
"$W" verify "$tmp/job.json" > "$tmp/verify"
has "$tmp/verify" "^signature VALID"
python3 -c 'import json,sys; j=json.load(open(sys.argv[1])); j["result"]["counts"]={"000":1000}; json.dump(j,open(sys.argv[2],"w"))' "$tmp/job.json" "$tmp/forged.json"
if "$W" verify "$tmp/forged.json" > "$tmp/verify-forged"; then fail "a changed result verified"; fi
has "$tmp/verify-forged" "^signature INVALID"
# The same user, the same key; the signer is the key's did:key.
"$W" key > "$tmp/key" 2> /dev/null
has "$tmp/key" "^did:key:z6Mk"
has "$tmp/verify" "^signer $(cat "$tmp/key")"
echo "run, verify, key: ok, signed by $(cat "$tmp/key")"
"$W" run "$tmp/ghz.qasm" > "$tmp/run-text"
has "$tmp/run-text" "^method stabilizer"
has "$tmp/run-text" "^receipt verifies"
if "$W" run "$tmp/ghz.qasm" --shot 5 > /dev/null 2> "$tmp/typo"; then fail "an unknown flag was accepted"; fi
has "$tmp/typo" "unexpected argument '--shot'"
if "$W" run "$tmp/ghz.qasm" --noise depolarizing=0.1 > /dev/null 2> "$tmp/noise"; then fail "an unknown noise channel was accepted"; fi
has "$tmp/noise" "no such channel"
echo "refusals: ok"
"$W" draw "$tmp/ghz.qasm" > "$tmp/draw"
has "$tmp/draw" "^q0: .*H.*●"
has "$tmp/draw" "^q2: .*⊕.*M2"
"$W" draw "$tmp/ghz.qasm" --svg > "$tmp/ghz.svg"
has "$tmp/ghz.svg" "^<svg"
"$W" draw "$tmp/ghz.qasm" --latex > "$tmp/ghz.tex"
has "$tmp/ghz.tex" 'begin{tikzpicture}'
"$W" draw "$tmp/ghz.qasm" --describe > "$tmp/ghz.txt"
has "$tmp/ghz.txt" "Column 2: CNOT, control qubit 0, target qubit 1"
echo "draw: ok, as text, SVG, LaTeX and words"
# The debugger: a position's state, the branches, and the adapter's first answer.
"$W" debug "$tmp/ghz.qasm" --to 3 > "$tmp/debug"
has "$tmp/debug" "^position 3 of 6; next: measure q0 into bit 0"
has "$tmp/debug" "^entangled across {q0}: 1.000000 bits, Schmidt rank 2"
"$W" debug "$tmp/ghz.qasm" --branches > "$tmp/branches"
has "$tmp/branches" "^branches 1"
msg='{"seq":1,"type":"request","command":"initialize","arguments":{}}'
printf 'Content-Length: %d\r\n\r\n%s' "${#msg}" "$msg" | "$W" dap > "$tmp/dap"
has "$tmp/dap" '"supportsStepBack":true'
echo "debug, dap: ok"
printf 'OPENQASM 3.0;\nqubit[2] q;\nbit[2] c;\nh q[0];\nh q[0];\nh q[0];\ncx q[0], q[1];\nc = measure q;\n' > "$tmp/twice.qasm"
"$W" critique "$tmp/twice.qasm" > "$tmp/critique"
has "$tmp/critique" "2 qubits, 4 gates (3 one-qubit, 1 two-qubit, 0 three-qubit), depth 4"
has "$tmp/critique" "^ cancels: h on qubit 0 twice in a row (lines 4 and 5)"
"$W" improve "$tmp/twice.qasm" > "$tmp/better.qasm" 2> "$tmp/improve"
has "$tmp/improve" "^gates 4 → 2"
"$W" equivalent "$tmp/twice.qasm" "$tmp/better.qasm" > "$tmp/same"
has "$tmp/same" "^equivalent: both are Clifford circuits with the same tableau"
if "$W" equivalent "$tmp/twice.qasm" "$tmp/ghz.qasm" > "$tmp/differ"; then fail "a 2-qubit and a 3-qubit program were the same"; fi
has "$tmp/differ" "^different: one has 2 qubits and the other 3"
echo "critique, improve, equivalent: ok"
"$W" shortcuts "$tmp/ghz.qasm" > "$tmp/shortcuts"
has "$tmp/shortcuts" "^Classically easy at any width"
printf 'OPENQASM 3.0;\nqubit[8] q;\nh q;\ncz q[0], q[1];\ncz q[1], q[2];\ncz q[2], q[3];\ncz q[3], q[4];\ncz q[4], q[5];\ncz q[5], q[6];\ncz q[6], q[7];\ncz q[7], q[0];\nrz(0.3) q;\n' > "$tmp/ring.qasm"
"$W" shortcuts "$tmp/ring.qasm" --json > "$tmp/ring.json"
python3 -c 'import json,sys; v=json.load(open(sys.argv[1])); c=[r for r in v["routes"] if r["route"]=="cutrank"][0]; assert c["applies"] and c["size"]["widest_cut"]==2, c; assert v["cheapest"]["counts"]["route"]=="cutrank", v["cheapest"]' "$tmp/ring.json"
echo "shortcuts: ok"
# compile: Clifford+T within the budget, every pass recorded, the certificate
# signed and checked by verify, and a run that compiles first goes bit-exact.
printf 'OPENQASM 3.0;\nqubit[2] q;\nh q[0];\nrz(0.3) q[0];\ncx q[0], q[1];\nry(1.1) q[1];\n' > "$tmp/angles.qasm"
"$W" compile "$tmp/angles.qasm" --epsilon 1e-4 --certificate "$tmp/cert.json" > "$tmp/compiled.qasm" 2> "$tmp/compile"
has "$tmp/compile" "^approximate"
has "$tmp/compile" "^epsilon budget 1e-4, bound"
has "$tmp/compile" "^certificate verifies"
if grep -q "rz(" "$tmp/compiled.qasm"; then fail "a rotation is left in the Clifford+T output"; fi
python3 -c 'import json,sys; b=json.load(open(sys.argv[1])); c=b["result"]["certificate"]; assert c["verdict"]=="approximate" and 0 < c["epsilon"]["bound"] <= 1e-4 and c["whole"]["distance"] <= c["epsilon"]["bound"], c["epsilon"]' "$tmp/cert.json"
"$W" verify "$tmp/cert.json" > "$tmp/cert-verify"
has "$tmp/cert-verify" "^signature VALID"
"$W" run "$tmp/angles.qasm" --compile 1e-4 --shots 200 > "$tmp/compiled-run" 2> /dev/null
has "$tmp/compiled-run" "^accuracy bit-exact"
has "$tmp/compiled-run" "^compiled clifford_t at level 1: within"
echo "compile: ok"
# estimate: a program's counts (a gate under three controls through an
# ancilla, a rotation at its word's T count), the frontier, the seals checked
# and re-run by verify, the counts exported and estimated again, and lab
# estimate still answering as it did.
printf 'OPENQASM 3.0;\nqubit[4] q;\nh q;\nctrl(3) @ x q[0], q[1], q[2], q[3];\nrz(0.3) q[0];\nt q[1];\n' > "$tmp/est.qasm"
"$W" estimate "$tmp/est.qasm" --budget 1e-3 > "$tmp/estimate"
has "$tmp/estimate" "^counts 5 logical qubits (1 ancilla), 4 measurements, 1 T, 3 Toffolis, 1 rotations"
has "$tmp/estimate" "^estimate ns-e4, surface code (fit: exact matching), d = "
has "$tmp/estimate" "^receipts .* they verify and re-run here"
"$W" estimate "$tmp/est.qasm" --json --demo-key > "$tmp/est.json"
python3 -c 'import json,sys; b=json.load(open(sys.argv[1])); r=b["result"]; assert r["format"]=="wai.quantum.estimate/1" and r["counts"]["ladders"]==1 and r["estimate"]["receipt"]["kind"]=="quantum-resource" and len(r["frontier"])>=1 and r["epsilon"]["bound"]<=r["epsilon"]["synthesis"], r["counts"]' "$tmp/est.json"
"$W" verify "$tmp/est.json" > "$tmp/est-verify"
has "$tmp/est-verify" "^signature VALID"
has "$tmp/est-verify" "^reproduced the request re-run here gives every count and figure"
"$W" estimate "$tmp/est.qasm" --export counts > "$tmp/counts.json" 2> /dev/null
python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d=={"numQubits":5,"tCount":1,"rotationCount":1,"rotationDepth":1,"cczCount":3,"ccixCount":0,"measurementCount":4}, d' "$tmp/counts.json"
"$W" estimate --counts "$tmp/counts.json" > "$tmp/est-counts"
has "$tmp/est-counts" "^program counts, digest"
"$W" estimate "$tmp/est.qasm" --export routine > "$tmp/routine.json" 2> /dev/null
"$W" estimate --routine "$tmp/routine.json" --qubit all > "$tmp/est-all"
has "$tmp/est-all" "^meas-e6 "
"$W" lab estimate factoring --qubit ns-e4 --json > "$tmp/lab-est"
python3 -c 'import json,sys; r=json.load(open(sys.argv[1])); assert r[0]["distance"]==13 and r[0]["factories"]==18, r' "$tmp/lab-est"
echo "estimate: ok"
printf '%s\n' \
'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}' \
'{"jsonrpc":"2.0","method":"notifications/initialized"}' \
'{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
'{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"run_quantum_circuit","arguments":{"qasm":"OPENQASM 3.0; qubit[2] q; h q[0]; cx q[0], q[1];","observables":["Z0 Z1"]}}}' \
> "$tmp/mcp.in"
"$W" mcp < "$tmp/mcp.in" > "$tmp/mcp.out" 2> /dev/null
python3 - "$tmp/mcp.out" <<'EOF'
import json, sys
lines = [json.loads(l) for l in open(sys.argv[1])]
assert [m["id"] for m in lines] == [1, 2, 3], lines
assert lines[0]["result"]["serverInfo"]["name"] == "wai-quantum"
names = [t["name"] for t in lines[1]["result"]["tools"]]
assert {"run_quantum_circuit", "critique_qasm", "check_equivalent", "improve_qasm", "classical_shortcuts", "compile_qasm", "estimate_resources"} <= set(names), names
job = lines[2]["result"]["structuredContent"]
assert job["result"]["expectations"][0]["value"] == 1.0, job
EOF
echo "mcp: ok"
# A host that draws views: each tool names its view, and the view's page reads, within its limit.
printf '%s\n' \
'{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{"extensions":{"io.modelcontextprotocol/ui":{"mimeTypes":["text/html;profile=mcp-app"]}}}}}' \
'{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
'{"jsonrpc":"2.0","id":3,"method":"resources/read","params":{"uri":"ui://wai-quantum/result"}}' \
> "$tmp/mcp-views.in"
"$W" mcp < "$tmp/mcp-views.in" > "$tmp/mcp-views.out" 2> /dev/null
python3 - "$tmp/mcp-views.out" <<'PY'
import json, sys
r = [json.loads(l) for l in open(sys.argv[1])]
tools = {t["name"]: t for t in r[1]["result"]["tools"]}
assert tools["run_quantum_circuit"]["_meta"]["ui"]["resourceUri"] == "ui://wai-quantum/result", tools["run_quantum_circuit"]
c = r[2]["result"]["contents"][0]
assert c["mimeType"] == "text/html;profile=mcp-app" and len(c["text"].encode()) <= 1 << 20 and 'content="result"' in c["text"], c["mimeType"]
PY
echo "mcp views: ok"
# The model harness, the task set's reference programs as a scripted model's answers: every task solved.
python3 -c 'import json,sys; t=json.load(open(sys.argv[1]))["cases"]; print(json.dumps({c["name"]: "```qasm\n" + c["qasm"] + "```" for c in t}))' ../quantum-conformance/eval/tasks.json > "$tmp/eval-answers.json"
"$W" eval run --tasks ../quantum-conformance/eval/tasks.json --scripted "$tmp/eval-answers.json" --out "$tmp/eval-report.json" 2> /dev/null
python3 -c 'import json,sys; s=json.load(open(sys.argv[1]))["summary"]; assert s["tasks"] >= 12 and s["solved"] == s["tasks"] == s["valid"], s' "$tmp/eval-report.json"
echo "eval: ok"
# run --intent: the engine's verdict, sealed by the receipt; the exit status
# says whether the intent holds. repair: the fix on the flagged line alone, and
# a proposal off it rejected.
printf '{"000": 0.5, "111": 0.5}\n' > "$tmp/ghz-dist.json"
"$W" run "$tmp/ghz.qasm" --intent "$tmp/ghz-dist.json" --json > "$tmp/intent.json" 2> /dev/null
python3 -c 'import json,sys; j=json.load(open(sys.argv[1])); v=j["result"]["verdict"]; assert (v["level"], v["holds"]) == ("proof", True), v' "$tmp/intent.json"
"$W" verify "$tmp/intent.json" > "$tmp/intent-verify"
has "$tmp/intent-verify" "^signature VALID"
printf '{"000": 1.0}\n' > "$tmp/wrong-dist.json"
if "$W" run "$tmp/ghz.qasm" --intent "$tmp/wrong-dist.json" > "$tmp/intent-fails" 2> /dev/null; then fail "a failing intent exited 0"; fi
has "$tmp/intent-fails" "^verdict proof: Checked as proof"
"$W" run "$tmp/ghz.qasm" --intent "$tmp/twice.qasm" > "$tmp/intent-shape" 2> /dev/null || true
has "$tmp/intent-shape" "^verdict proof"
printf 'OPENQASM 3.0;\nqubit[2] q\nh q[0];\n' > "$tmp/broken.qasm"
"$W" repair "$tmp/broken.qasm" > "$tmp/repaired.qasm" 2> "$tmp/repair"
has "$tmp/repair" "^repaired Q004"
printf 'OPENQASM 3.0;\nqubit[2] q;\nh q[0];\n' | cmp -s - "$tmp/repaired.qasm" || fail "repair did not add the one ;"
printf 'OPENQASM 3.1;\nqubit[2] q;\nh q[0];\n' > "$tmp/rewrite.qasm"
set +e; "$W" repair "$tmp/broken.qasm" --proposed "$tmp/rewrite.qasm" > /dev/null 2> "$tmp/repair-rejected"; rc=$?; set -e
[ "$rc" = 2 ] || fail "a proposal off the flagged lines exited $rc, not 2"
has "$tmp/repair-rejected" "\[J021\]"
echo "intent, repair: ok"
printf 'OPENQASM 3.0;qubit[2]q;h q[0];cx q[0],q[1];\n' > "$tmp/messy.qasm"
printf 'OPENQASM 3.0;\nqubit[2] q;\nh q[0];\ncx q[0], q[1];\n' > "$tmp/want.qasm"
"$W" fmt "$tmp/messy.qasm" > "$tmp/tidy.qasm"
cmp -s "$tmp/tidy.qasm" "$tmp/want.qasm" || { diff "$tmp/want.qasm" "$tmp/tidy.qasm" >&2 || true; fail "fmt did not give the one layout"; }
"$W" fmt --check "$tmp/tidy.qasm" > "$tmp/fmt-check" || fail "fmt --check refused a formatted program"
if "$W" fmt --check "$tmp/messy.qasm" > "$tmp/fmt-check"; then fail "fmt --check passed an unformatted program"; fi
has "$tmp/fmt-check" "messy.qasm"
printf 'gate g a {\n h a;\n' > "$tmp/open.qasm"
if "$W" fmt "$tmp/open.qasm" > /dev/null 2> "$tmp/fmt-err"; then fail "fmt formatted a program whose brace is not closed"; fi
has "$tmp/fmt-err" 'open.qasm:1: `{` is not closed'
echo "fmt: ok"
# The language server answers initialize, and exits cleanly after shutdown.
python3 - "$W" <<'PY'
import json, subprocess, sys
msgs = [
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"capabilities": {}}},
{"jsonrpc": "2.0", "id": 2, "method": "shutdown"},
{"jsonrpc": "2.0", "method": "exit"},
]
data = b"".join(b"Content-Length: %d\r\n\r\n%s" % (len(b), b) for b in (json.dumps(m).encode() for m in msgs))
p = subprocess.run([sys.argv[1], "lsp", "--demo-key"], input=data, capture_output=True, timeout=60)
assert p.returncode == 0, p
head, rest = p.stdout.split(b"\r\n\r\n", 1)
first = json.loads(rest[: int(head.split(b":")[1])])
assert first["id"] == 1 and first["result"]["capabilities"]["hoverProvider"] is True, first
PY
echo "lsp: ok"
"$W" lab list > "$tmp/lab-list"
has "$tmp/lab-list" "^ghz "
"$W" lab receipt ghz -n 3 > "$tmp/lab-receipt" 2> /dev/null
"$W" verify "$tmp/lab-receipt" > "$tmp/lab-verify"
has "$tmp/lab-verify" "^signature VALID"
has "$tmp/lab-verify" "^signer $(cat "$tmp/key")"
echo "lab: ok"
# Error correction: a code's certified distance sealed and verified, a decode at
# code capacity judged, a circuit-level decode, and lab qec as it was; a
# mitigated run carries its mitigation.
"$W" qec code color:5 --json --demo-key > "$tmp/qec-code.json" 2> /dev/null
python3 -c 'import json,sys; v=json.load(open(sys.argv[1])); c=v["result"]["certificate"]; assert c["distance"]==5 and c["x"]["witness"], c' "$tmp/qec-code.json"
"$W" verify "$tmp/qec-code.json" > "$tmp/qec-verify"
has "$tmp/qec-verify" "VALID"
"$W" qec decode --code surface:3 --error 4 --demo-key > "$tmp/qec-decode" 2> /dev/null
has "$tmp/qec-decode" "the logical state is unharmed"
"$W" qec decode --memory 3,3,0.004 --shots 2000 --decoder correlated --demo-key > "$tmp/qec-shots" 2> /dev/null
has "$tmp/qec-shots" "of 2000 shots"
"$W" lab qec -d 3 --p 0.003 --shots 2000 > "$tmp/lab-qec"
has "$tmp/lab-qec" "^failures"
"$W" run "$tmp/ghz.qasm" -o "Z0 Z1" --noise depolarizing_2q=0.02 --mitigate zne --demo-key > "$tmp/mitigated" 2> /dev/null
has "$tmp/mitigated" "^mitigation zne"
echo "qec and mitigation: ok"
# The front door: a project made, its own test run as made, AGENTS.md left as
# it is by a rerun, the MCP entry, and the server's resources and prompts.
"$W" new "$tmp/proj" --template grover > "$tmp/new"
has "$tmp/new" "next: sh "
WAI_QUANTUM="$W" sh "$tmp/proj/test.sh" > "$tmp/proj-test" 2>&1
has "$tmp/proj-test" "both receipts verify"
"$W" verify "$tmp/proj/receipts/grover.intent.json" > "$tmp/proj-verify"
has "$tmp/proj-verify" "^signature VALID"
"$W" setup-agent "$tmp/proj" > "$tmp/agents"
has "$tmp/agents" "unchanged"
"$W" mcp config > "$tmp/mcp-config.json"
python3 -c 'import json,sys; c=json.load(open(sys.argv[1])); assert c["mcpServers"]["wai-quantum"]=={"command":"wai-quantum","args":["mcp"]}, c' "$tmp/mcp-config.json"
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"resources/list"}' '{"jsonrpc":"2.0","id":2,"method":"prompts/list"}' > "$tmp/mcp2.in"
"$W" mcp < "$tmp/mcp2.in" > "$tmp/mcp2.out" 2> /dev/null
python3 - "$tmp/mcp2.out" <<'EOF'
import json, sys
r = [json.loads(l) for l in open(sys.argv[1])]
uris = [x["uri"] for x in r[0]["result"]["resources"]]
assert "wai-quantum://docs/language" in uris and "wai-quantum://docs/diagnostics" in uris, uris
assert len(r[1]["result"]["prompts"]) == 3, r[1]
EOF
echo "new, test, setup-agent, mcp config, resources and prompts: ok"
# Device targets: the built-in ones listed, a snapshot kept under a name, and
# a run on one placed and simulated as the device would, the target's hash in
# the receipt.
"$W" targets list > "$tmp/targets"
has "$tmp/targets" "synthetic-heavy-hex-27"
"$W" targets show synthetic-line-5 --document > "$tmp/line5.json"
"$W" targets import "$tmp/line5.json" --name my-line > "$tmp/import"
has "$tmp/import" "kept my-line (5 qubits, 4 pairs)"
"$W" targets list > "$tmp/targets2"
has "$tmp/targets2" "^ my-line"
"$W" run "$tmp/ghz.qasm" --target my-line --shots 500 --json > "$tmp/device.json"
python3 - "$tmp/device.json" <<'PY'
import json, sys
j = json.load(open(sys.argv[1])); r = j["result"]
assert j["method"] == "density_matrix" and j["request"]["target"]["name"] == "my-line", j["method"]
assert len(r["target"]["hash"]) == 64 and sum(r["counts"].values()) == 500, r["target"]
assert 0 < r["ideal"]["total_variation_distance"] < 0.3, r["ideal"]
PY
"$W" verify "$tmp/device.json" > "$tmp/device-verify"
has "$tmp/device-verify" "^signature VALID"
"$W" run "$tmp/ghz.qasm" --target synthetic-heavy-hex-27 --shots 200 > "$tmp/device.txt"
has "$tmp/device.txt" "^target synthetic-heavy-hex-27"
has "$tmp/device.txt" "^placed on"
if "$W" run "$tmp/ghz.qasm" --target no-such-device > "$tmp/device-bad" 2>&1; then fail "a run on an unknown target ran"; fi
has "$tmp/device-bad" "no target"
echo "targets: list, show, import, run --target and its receipt: ok"
# A set and a sweep, run here: one result per item, one receipt binding them.
cat > "$tmp/rot.qasm" <<'EOF'
OPENQASM 3.0;
input float theta;
qubit q;
rx(theta) q;
EOF
"$W" run "$tmp/ghz.qasm" --program "$tmp/ghz.qasm" --shots 50 --json > "$tmp/set.json"
"$W" verify "$tmp/set.json" > "$tmp/set-verify"
has "$tmp/set-verify" "^signature VALID"
has "$tmp/set-verify" "its root over 2 items"
"$W" run "$tmp/rot.qasm" --sweep theta=0,0.5,1 -o Z0 > "$tmp/sweep.txt"
has "$tmp/sweep.txt" '^set 3 items, 3 done, 0 failed'
has "$tmp/sweep.txt" '{"theta":0.5}'
has "$tmp/sweep.txt" "^receipt verifies, every item sealed"
"$W" plan "$tmp/rot.qasm" --sweep theta=0,1 -o Z0 > "$tmp/sweep-plan.txt"
has "$tmp/sweep-plan.txt" "^set 2 items"
echo "sets and sweeps: run here, each item sealed, one receipt over them: ok"
# The course: a lesson started, its starter checked and not passed, the
# solution passed and kept on this machine, and the same in Chinese.
(cd "$tmp" && "$W" learn start bell > "$tmp/learn-start")
has "$tmp/learn-start" "wrote bell.qasm"
if "$W" learn check bell "$tmp/bell.qasm" > "$tmp/learn-fail"; then fail "the starter passed its own exercise"; fi
has "$tmp/learn-fail" "^passed not yet"
has "$tmp/learn-fail" "00: your program gives 1, the exercise asks for 0.5"
printf 'OPENQASM 3.0;\nqubit[2] q;\nbit[2] c;\nh q[0];\ncx q[0], q[1];\nc = measure q;\n' > "$tmp/bell.qasm"
"$W" learn check bell "$tmp/bell.qasm" > "$tmp/learn-pass"
has "$tmp/learn-pass" "^passed yes"
python3 -c 'import json,sys; p=json.load(open(sys.argv[1])); assert p["lessons"]["bell"]["passed"] is True and p["lessons"]["bell"]["checks"] == 2, p' "$XDG_CONFIG_HOME/wai/quantum-learn.json"
"$W" learn > "$tmp/learn-list"
has "$tmp/learn-list" "✓ 6. bell"
"$W" learn hint ghz --lang zh-CN > "$tmp/learn-hint"
has "$tmp/learn-hint" "^提示 1/2"
LANG=zh_CN.UTF-8 "$W" learn check bell "$tmp/bell.qasm" > "$tmp/learn-zh"
has "$tmp/learn-zh" "^通过"
LANG=zh_CN.UTF-8 "$W" --help > "$tmp/help-zh"
has "$tmp/help-zh" "量子线路课程"
"$W" docs --lang zh-CN > "$tmp/docs-zh"
has "$tmp/docs-zh" "可离线使用"
echo "learn: started, checked, passed, kept here, and in Chinese: ok"
if [ -n "$SVC" ]; then
"$W" submit "$tmp/ghz.qasm" --shots 500 --service "$SVC" --json > "$tmp/svc.json"
"$W" verify "$tmp/svc.json" > "$tmp/svc-verify"
has "$tmp/svc-verify" "^signature VALID"
echo "submit: ok, the service's receipt verifies here"
# A set over the service, its status followed; a dry run; the task commands.
"$W" submit "$tmp/rot.qasm" --sweep theta=0,0.5 -o Z0 --service "$SVC" --json > "$tmp/svc-set.json" 2> "$tmp/svc-set.err"
has "$tmp/svc-set.err" ": done$"
"$W" verify "$tmp/svc-set.json" > "$tmp/svc-set-verify"
has "$tmp/svc-set-verify" "^signature VALID"
"$W" submit "$tmp/ghz.qasm" --shots 10 --dry-run --service "$SVC" > "$tmp/svc-dry.txt"
has "$tmp/svc-dry.txt" "^would run yes, now"
has "$tmp/svc-dry.txt" "^method stabilizer"
printf '{"qasm": "OPENQASM 3.0; qubit q; bit c; h q; c = measure q;", "shots": 20}' > "$tmp/task.json"
(
cd "$tmp"
"$W" task acquire --service "$SVC" > lease.out
id=$("$W" task start task.json --service "$SVC")
"$W" task wait "$id" --service "$SVC" > wait.out 2> wait.err
"$W" task result "$id" --service "$SVC" > result.json
"$W" task release --service "$SVC" > release.out
)
has "$tmp/wait.out" "^done$"
"$W" verify "$tmp/result.json" > "$tmp/task-verify"
has "$tmp/task-verify" "^signature VALID"
has "$tmp/release.out" "^released: 0 task(s) stopped"
echo "submit sets, dry runs and the task commands: ok"
fi
echo "smoke: every check held"