Files
aji/tests/conformance/source/quickref/failure.aji
T
dev 3e2d9b63a7 P6A-8: Source Reference Bundle and harness profile aji_source
- source bundle: a /docs directory with QUICK.md (Quick Reference plus a
  where-to-read table), language/*.md, diagnostics/errors.md and the AIR
  bundle only under air/; built from docs/agent/source-bundle.txt
  (> output files, @manifest includes) by zig build agent-reference
- Quick Reference examples are checked: every aji block must be an
  excerpt of a conformance program in tests/conformance/source/quickref
  (zig build test fails otherwise); QR fixes found by the check
  (mut d = data, region not auto-borrowed, statement/borrow blocks that
  could not verify, io_error match)
- frontend: task.*/channel.*/mutex.* are not-yet-implemented, not E7006
- aji lower --stats: mechanical_air_eliminated_raw and _normalized (each
  byte-string materialization counted as one constant; spec 15 §11)
- harness: profile aji_source (doc_groups), per-file and per-group docs
  metrics on distinctive lines, profile columns (tool calls, lowered AIR
  raw/normalized, docs files read, IR-form and type-mismatch counts),
  dev-echo aji_source variant, scripted run and test, source token report
- plan: P6A-8 done, P6A-9 criteria; Q-021/Q-022 resolved; unsafe block
  deferred
2026-10-05 13:16:51 +03:00

31 lines
1.0 KiB
Rust

// Quick Reference §5: every outcome is a match arm.
// expect: run
// grant: c=fs.read:/data
// grant: listen=net.listen
// grant: connect=net.connect
// vfs: /data/in.txt=abc
// result: 3
// phase: 6
// spec: docs/agent/quick-reference.md
module demo.failure
fn main(c: cap<fs.read>, listen: cap<net.listen>, connect: cap<net.connect>) -> u8
effects [fs.read, net.listen, net.connect, net.read, net.write]
{
var buf: [u8; 8] = zero;
var got: usize = 0;
match fs.open_read(c, b"/data/in.txt") {
ok(f) => { got = fs.read(f, mut buf) or trap; fs.close(move f) or trap; }
err(e) => { return 1u8; }
}
let l = net.listen(listen, b"127.0.0.1:7") or trap;
let peer = net.connect(connect, b"127.0.0.1:7") or trap;
let conn = net.accept(l) or trap;
net.send_all(peer, ref buf[0..got]) or trap;
let n = net.recv(conn, mut buf) or trap; // any non-ok outcome traps
net.close_stream(move conn) or trap;
net.close_stream(move peer) or trap;
net.close_listener(move l) or trap;
n as! u8
}