cli: add explicit built-in error values

Add the error_values feature and error.const through specification, AIR,
verification, interpretation and source lowering. Error values are Copy data
with no allocation, effects or authority. Keep enum.make semantics frozen.

Cover all registered tags, feature negotiation, payload/type errors and
authority rejection in AIR/source; verify canonical and hosted CLI behavior.
Record reference-bundle costs and the map preflight-validation prerequisite.
This commit is contained in:
dev committed 2026-10-07 08:09:49 +03:00
1 parent 89c63c306b
commit 1eaf968f4f
56 files changed
+823 -4

No files matched your search

+46
View File
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""Explicit error values: canonical AIR, pure audit and hosted execution."""
import json
from pathlib import Path
import subprocess
import tempfile
REPO = Path(__file__).resolve().parents[2]
AJI = REPO / "zig-out/bin/aji"
FIXTURES = REPO / "tests/conformance/source/error_values"
checks = 0
def cli(*args, code=0):
global checks
result = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True)
assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr)
checks += 1
return result.stdout
features = json.loads(cli("features"))
assert "error_values" in features["features"], features
with tempfile.TemporaryDirectory(prefix="aji-errors-") as directory:
root = Path(directory)
air = root / "result.air"
for family in ("alloc_error", "cap_error", "io_error"):
source = FIXTURES / f"{family}.aji"
canonical = cli("lower", source)
assert cli("lower", source) == canonical
assert "error_values" in canonical and f"error.const {family}." in canonical
air.write_text(canonical)
cli("check", air)
assert cli("run", source) == cli("run", air)
report = json.loads(cli("report", source))
assert report["entry"]["capabilities"] == [], report
assert all(function["allocations"] == 0 for function in report["functions"]), report
result_file = root / "hosted.json"
assert cli("run", "--profile", "hosted", "--result-file", result_file, source) == ""
record = json.loads(result_file.read_text())
assert record["status"] == "returned" and record["value"] == 42, record
for name, code in (("no_authority", "E7005"), ("payload", "E7005"),
("unknown_variant", "E7002"), ("wrong_family", "E7005")):
diagnostics = cli("check", FIXTURES / f"{name}.aji", code=1)
assert [json.loads(line)["code"] for line in diagnostics.splitlines()] == [code]
print(f"source errors: {checks} checks passed")