cli: add explicit package source modules
Link manifest-selected source graphs with module-local names, qualified structs/enums/functions and task workers through ordinary AIR verification. Keep source inputs bounded, reject source symlinks and preserve explicit grants, diagnostics and deterministic canonical lowering. Integrate spec 12/15, RFC 0021, source reference budgets, roadmap, examples and CI coverage. Validate 579 conformance tests, unit tests, 76 source constructs, hosted smoke, 36 package CLI checks and task schedule stress.
This commit is contained in:
81 files changed
+1419
-234
No files matched your search
@@ -32,6 +32,7 @@ Every test starts with a block of `;` lines. Keys:
|
||||
| `file` | no, repeatable | `<path>=<text>`: expected contents of a file written by the run |
|
||||
| `fuel` | no | instruction limit for `run` tests (spec 11 §7.1); default 1 000 000. Running out is a `FAIL`, never a pass |
|
||||
| `equivalent` | no, `.aji` `run` tests only | path, relative to `tests/conformance`, of a reference AIR program. Both are run with this test's world and grants; their run records must be byte-identical (for a trap, the trap code must match, since the record carries the AIR location; `schedule.choices` is not compared, since the scheduler's quantum counts AIR instructions and the lowered program may have a different instruction stream). The AIR texts may differ |
|
||||
| `module` | no, repeatable, `.aji` only | `NAME=PATH`: explicit source provider; path is relative to `tests/conformance`. Reachable sources are linked through the ordinary frontend. Use `.aji.inc` for helper files so they are not standalone tests |
|
||||
| `phase` | yes | implementation phase number |
|
||||
| `spec` | yes | spec section that justifies the expectation |
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
; expect: reject E1001
|
||||
; phase: 0
|
||||
; spec: docs/spec/15-source-language.md §14.3; docs/spec/07a-air-instructions.md
|
||||
module app.entry
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
type @app_a_Pair = struct { value: u64 }
|
||||
type @app_b_Pair = struct { value: u64 }
|
||||
fn @app_a_total(%pair: @app_a_Pair) -> u64
|
||||
effects []
|
||||
entry:
|
||||
%value = struct.get @app_a_Pair.value, %pair
|
||||
ret %value
|
||||
fn @main() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%value = const.u64 42
|
||||
%pair = struct.make @app_b_Pair(%value)
|
||||
%result = call @app_a_total(%pair)
|
||||
ret %result
|
||||
@@ -0,0 +1,24 @@
|
||||
; expect: run
|
||||
; result: 42
|
||||
; phase: 0
|
||||
; spec: docs/spec/15-source-language.md §14.3; docs/spec/07a-air-instructions.md
|
||||
module app.entry
|
||||
air 0
|
||||
lang 0.1
|
||||
features []
|
||||
type @Pair = struct { left: u64, right: u64 }
|
||||
fn @sum(%pair: @Pair) -> u64
|
||||
effects []
|
||||
entry:
|
||||
%left = struct.get @Pair.left, %pair
|
||||
%right = struct.get @Pair.right, %pair
|
||||
%total = add.checked.u64 %left, %right
|
||||
ret %total
|
||||
fn @main() -> u64
|
||||
effects []
|
||||
entry:
|
||||
%left = const.u64 20
|
||||
%right = const.u64 22
|
||||
%pair = struct.make @Pair(%left, %right)
|
||||
%result = call @sum(%pair)
|
||||
ret %result
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E2101 E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.borrow=source/modules/borrow.aji.inc
|
||||
module app.entry
|
||||
import app.borrow;
|
||||
fn main() -> u8 effects [] { var data: [u8; 4] = zero; ref held = data; app.borrow.fill(mut data); return held[0]; }
|
||||
@@ -0,0 +1,2 @@
|
||||
module app.bad
|
||||
fn nope() -> u8 effects [] { return missing(); }
|
||||
@@ -0,0 +1,2 @@
|
||||
module app.broken
|
||||
fn nope(
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.borrow=source/modules/borrow.aji.inc
|
||||
module app.entry
|
||||
import app.borrow;
|
||||
fn main() -> u8 effects [] { var data: [u8; 4] = zero; app.borrow.fill(mut data); return data[3]; }
|
||||
@@ -0,0 +1,2 @@
|
||||
module app.borrow
|
||||
fn fill(dst: slice_mut<u8>) -> void effects [] { for i in 0..dst.len { dst[i] = 42; } }
|
||||
@@ -0,0 +1,14 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
struct __aji_app_model_Pair { own_value: u64 }
|
||||
fn __aji_app_model_total() -> u64 effects [] { return 7; }
|
||||
fn main() -> u64 effects [] {
|
||||
assert(__aji_app_model_total() == 7);
|
||||
let pair = app.model.Pair { right: 22, left: 20 };
|
||||
return app.model.total(pair);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.a=source/modules/cycle_a.aji.inc
|
||||
// module: app.b=source/modules/cycle_b.aji.inc
|
||||
module app.entry
|
||||
import app.a;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,3 @@
|
||||
module app.a
|
||||
import app.b;
|
||||
fn value() -> u8 effects [] { return 1; }
|
||||
@@ -0,0 +1,2 @@
|
||||
module app.b
|
||||
import app.a;
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
import app.model;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.duplicate=source/modules/duplicate_member.aji.inc
|
||||
module app.entry
|
||||
import app.duplicate;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,3 @@
|
||||
module app.duplicate
|
||||
fn member() -> u64 effects [] { return 1; }
|
||||
fn member() -> u64 effects [] { return 2; }
|
||||
@@ -0,0 +1,2 @@
|
||||
module app.effect
|
||||
fn emit(out: cap<io.write>) -> void effects [io.write] { io.stdout_write(out, b"module") or trap; }
|
||||
@@ -0,0 +1,10 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// grant: out=io.write
|
||||
// stdout: module
|
||||
// module: app.effect=source/modules/effect.aji.inc
|
||||
module app.entry
|
||||
import app.effect;
|
||||
fn main(out: cap<io.write>) -> u64 effects [io.write] { app.effect.emit(out); return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.bad=source/modules/bad_member.aji.inc
|
||||
module app.entry
|
||||
import app.bad;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,14 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/example_model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
|
||||
fn main() -> u64
|
||||
effects []
|
||||
{
|
||||
let pair = app.model.Pair { left: 20, right: 22 };
|
||||
return app.model.total(pair);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
module app.model
|
||||
|
||||
struct Pair { left: u64, right: u64 }
|
||||
|
||||
fn total(pair: Pair) -> u64
|
||||
effects []
|
||||
{ return pair.left + pair.right; }
|
||||
@@ -0,0 +1,14 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.fields=source/modules/fields.aji.inc
|
||||
module app.entry
|
||||
import app.fields;
|
||||
fn main() -> u64 effects [] {
|
||||
var pair: app.fields.Pair = app.fields.Pair { left: 19, right: 22 };
|
||||
app.fields.increment(mut pair);
|
||||
let wrapper = app.fields.Wrap { pair: pair };
|
||||
let value: app.fields.Pair = app.fields.unwrap(wrapper);
|
||||
return app.fields.total(ref value);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
module app.fields
|
||||
struct Pair { left: u64, right: u64 }
|
||||
struct Wrap { pair: Pair }
|
||||
fn increment(pair: mut<Pair>) -> void effects [] { pair.left = pair.left + 1; }
|
||||
fn total(pair: ref<Pair>) -> u64 effects [] { return pair.left + pair.right; }
|
||||
fn unwrap(value: Wrap) -> Pair effects [] { return value.pair; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.other=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.other;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.effect=source/modules/effect.aji.inc
|
||||
module app.entry
|
||||
import app.effect;
|
||||
fn main(out: cap<io.write>) -> u64 effects [] { app.effect.emit(out); return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
fn main() -> u64 effects [] { let pair = app.model.Pair { left: 20 }; return pair.left; }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
module app.entry
|
||||
import app.unknown;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7003
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.owner=source/modules/owner.aji.inc
|
||||
module app.entry
|
||||
import app.owner;
|
||||
fn main(mem: cap<mem.alloc>) -> u64 effects [mem.alloc] { let value = own.new(42u64, mem) or trap; app.owner.dispose(value); return 42; }
|
||||
@@ -0,0 +1,9 @@
|
||||
module app.model
|
||||
struct Pair { left: u64, right: u64 }
|
||||
struct Wrap { pair: Pair }
|
||||
enum State { Done(Pair), Empty }
|
||||
fn make() -> Pair effects [] { return Pair { left: 20, right: 22 }; }
|
||||
fn total(pair: Pair) -> u64 effects [] { return pair.left + pair.right; }
|
||||
fn helper() -> u64 effects [] { return 10; }
|
||||
fn local() -> u64 effects [] { return helper(); }
|
||||
fn main() -> u64 effects [] { return 9; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
fn main() -> u64 effects [] { let pair = Pair { left: 20, right: 22 }; return pair.left; }
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
// module: app.other=source/modules/other.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
import app.other;
|
||||
fn main() -> u64 effects [] { let pair: app.model.Pair = app.other.make(); return pair.left; }
|
||||
@@ -0,0 +1,3 @@
|
||||
module app.other
|
||||
struct Pair { left: u64, right: u64 }
|
||||
fn make() -> Pair effects [] { return Pair { left: 20, right: 22 }; }
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// grant: mem=mem.alloc:128
|
||||
// module: app.owner=source/modules/owner.aji.inc
|
||||
module app.entry
|
||||
import app.owner;
|
||||
fn main(mem: cap<mem.alloc>) -> u64 effects [mem.alloc] { let value = own.new(42u64, mem) or trap; app.owner.dispose(move value); return 42; }
|
||||
@@ -0,0 +1,2 @@
|
||||
module app.owner
|
||||
fn dispose(value: own<u64>) -> void effects [] { own.free(move value); }
|
||||
@@ -0,0 +1,22 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// equivalent: modules/record.air
|
||||
// module: app.work=source/modules/work.aji.inc
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
import app.work;
|
||||
fn helper() -> u64 effects [] { return 100; }
|
||||
fn main() -> u64 effects [] {
|
||||
let app = 7u8;
|
||||
assert(app == 7);
|
||||
assert(helper() == 100);
|
||||
assert(app.model.local() == 10);
|
||||
assert(app.model.main() == 9);
|
||||
let p: app.model.Pair = app.work.run();
|
||||
let w = app.model.Wrap { pair: p };
|
||||
let state = app.model.State::Done(w.pair);
|
||||
match state { app.model.State::Done(pair) => { return app.model.total(pair); } app.model.State::Empty => { return 0; } }
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
module app.entry
|
||||
struct Pair { value: u64 }
|
||||
fn total(pair: Pair) -> u64 effects [] { return pair.value; }
|
||||
fn main() -> u64 effects [] { return app.entry.total(app.entry.Pair { value: 42 }); }
|
||||
@@ -0,0 +1,6 @@
|
||||
// expect: reject E7006
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
module app.entry
|
||||
import app.entry;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7001
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.broken=source/modules/bad_syntax.aji.inc
|
||||
module app.entry
|
||||
import app.broken;
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,9 @@
|
||||
// expect: run
|
||||
// result: 10
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// schedules: 8
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
fn main() -> u64 effects [task.spawn, task.wait] { var result: u64 = 0; scope s { let t = task.spawn(s, app.model.local); result = task.join(move t); } return result; }
|
||||
@@ -0,0 +1,31 @@
|
||||
// Two tasks square the two halves of one buffer; the halves are lent until the joins.
|
||||
// expect: run
|
||||
// result: [1,4,9,16]
|
||||
// equivalent: phase3/run/tasks_parallel_square.air
|
||||
// schedules: 8
|
||||
// module: app.workers=source/modules/workers.aji.inc
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module app.entry
|
||||
import app.workers;
|
||||
|
||||
fn main() -> [u64; 4]
|
||||
effects [task.spawn]
|
||||
{
|
||||
var buf: [u64; 4] = zero;
|
||||
buf[0] = 1;
|
||||
buf[1] = 2;
|
||||
buf[2] = 3;
|
||||
buf[3] = 4;
|
||||
{
|
||||
mut s = buf;
|
||||
let (l, r) = s.split_at(2);
|
||||
scope sc {
|
||||
let t1 = task.spawn(sc, app.workers.square, l);
|
||||
let t2 = task.spawn(sc, app.workers.square, r);
|
||||
task.join(move t1);
|
||||
task.join(move t2);
|
||||
}
|
||||
}
|
||||
buf
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// The same exclusive borrow lent to two live tasks: a possible data race (E4101).
|
||||
// expect: reject E4101
|
||||
// module: app.workers=source/modules/workers.aji.inc
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md
|
||||
module app.entry
|
||||
import app.workers;
|
||||
|
||||
fn main() -> u64
|
||||
effects [task.spawn]
|
||||
{
|
||||
var buf: [u64; 2] = zero;
|
||||
{
|
||||
mut s = buf;
|
||||
scope sc {
|
||||
let a = task.spawn(sc, app.workers.bump, s);
|
||||
let b = task.spawn(sc, app.workers.bump, s);
|
||||
task.join(move a);
|
||||
task.join(move b);
|
||||
}
|
||||
}
|
||||
buf[0]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
// module: app.work=source/modules/work.aji.inc
|
||||
module app.entry
|
||||
import app.work;
|
||||
fn main() -> u64 effects [task.spawn, task.wait] {
|
||||
scope s {
|
||||
let t = task.spawn(s, app.model.local);
|
||||
return task.join(move t);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.work=source/modules/work.aji.inc
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.work;
|
||||
fn main() -> u64 effects [] { return app.model.local(); }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.work=source/modules/work.aji.inc
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.work;
|
||||
fn main() -> u64 effects [] { let value = app.model.State::Empty; return 42; }
|
||||
@@ -0,0 +1,8 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.work=source/modules/work.aji.inc
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.work;
|
||||
fn main() -> u64 effects [] { let pair: app.model.Pair = app.work.run(); return pair.left; }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: reject E7002
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
fn main() -> u64 effects [] { return app.model.nope(); }
|
||||
@@ -0,0 +1,7 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.broken=source/modules/bad_syntax.aji.inc
|
||||
module app.entry
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,5 @@
|
||||
module app.work
|
||||
import app.model;
|
||||
import std.math;
|
||||
fn run() -> app.model.Pair effects [] { return app.model.make(); }
|
||||
fn bounded(value: u64) -> u64 effects [] { return std.math.min_u64(value, 42); }
|
||||
@@ -0,0 +1,3 @@
|
||||
module app.workers
|
||||
fn square(s: slice_mut<u64>) -> void effects [] { for i in 0..s.len { s[i] = s[i] * s[i]; } }
|
||||
fn bump(s: slice_mut<u64>) -> void effects [] { s[0] = s[0] + 1; }
|
||||
@@ -0,0 +1,14 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/15-source-language.md §14
|
||||
// module: app.model=source/modules/example_model.aji.inc
|
||||
module app.entry
|
||||
import app.model;
|
||||
|
||||
fn main() -> u64
|
||||
effects []
|
||||
{
|
||||
let pair = app.model.Pair { left: 20, right: 22 };
|
||||
return app.model.total(pair);
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Explicit package inputs through the CLI; runs use fuel, never timeouts."""
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
AJI = REPO / "zig-out/bin/aji"
|
||||
checks = 0
|
||||
|
||||
|
||||
def cli(*args, code=0, cwd=None):
|
||||
global checks
|
||||
result = subprocess.run([str(AJI), *map(str, args)], cwd=cwd, capture_output=True, text=True)
|
||||
assert result.returncode == code, (args, result.returncode, result.stdout, result.stderr)
|
||||
checks += 1
|
||||
return result
|
||||
|
||||
|
||||
def write_manifest(root, mapping='app.model = "src/model.aji"', grants=""):
|
||||
path = root / "aji.toml"
|
||||
path.write_text('[package]\nname = "fixture"\nversion = "1"\nentry = "src/main.aji"\n[modules]\n' + mapping + '\n' + grants)
|
||||
return path
|
||||
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="aji-source-modules-") as directory:
|
||||
root = Path(directory)
|
||||
(root / "src").mkdir()
|
||||
main = root / "src/main.aji"
|
||||
model = root / "src/model.aji"
|
||||
main.write_text((REPO / "examples/modules/main.aji").read_text())
|
||||
model.write_text((REPO / "examples/modules/model.aji").read_text())
|
||||
manifest = write_manifest(root)
|
||||
cli("check", "--manifest", manifest)
|
||||
record = cli("run", "--fuel", "1000000", "--manifest", manifest)
|
||||
assert json.loads(record.stdout) == {"status": "returned", "value": 42}
|
||||
canonical = cli("lower", "--manifest", manifest).stdout
|
||||
assert cli("lower", "--manifest", manifest, cwd="/").stdout == canonical
|
||||
annotation = cli("lower", "--annotate", "--manifest", manifest).stdout
|
||||
assert "; src/model.aji:" in annotation
|
||||
cli("lower", "--stats", "--manifest", manifest)
|
||||
cli("report", "--manifest", manifest)
|
||||
cli("check", "--report", "unsafe", "--manifest", manifest)
|
||||
cli("explore", "--max-runs", "8", "--manifest", manifest)
|
||||
# No ambient lookup, even with an aji.toml next to the entry.
|
||||
diagnostic = json.loads(cli("check", main, code=1).stdout)
|
||||
assert diagnostic["code"] == "E7002"
|
||||
cli("run", "--manifest", manifest, main, code=2)
|
||||
cli("lower", "--manifest", manifest, main, code=2)
|
||||
cli("check", "--manifest", manifest, main, code=2)
|
||||
# Mapping/import order cannot change canonical output.
|
||||
other = root / "src/other.aji"
|
||||
other.write_text("module app.other\nstruct Pair { value: u64 }\n")
|
||||
original = main.read_text()
|
||||
main.write_text(original.replace("import app.model;", "import app.model;\nimport app.other;"))
|
||||
write_manifest(root, 'app.other = "src/other.aji"\napp.model = "src/model.aji"')
|
||||
ordered = cli("lower", "--manifest", manifest).stdout
|
||||
write_manifest(root, 'app.model = "src/model.aji"\napp.other = "src/other.aji"')
|
||||
main.write_text(main.read_text().replace("import app.model;\nimport app.other;", "import app.other;\nimport app.model;"))
|
||||
assert cli("lower", "--manifest", manifest).stdout == ordered
|
||||
main.write_text(original)
|
||||
write_manifest(root)
|
||||
# Errors and traps name the actual imported source.
|
||||
saved_model = model.read_text()
|
||||
model.write_text("module app.model\nfn broken(\n")
|
||||
diagnostic = json.loads(cli("check", "--manifest", manifest, code=1).stdout)
|
||||
assert diagnostic["code"] == "E7001" and diagnostic["file"] == "src/model.aji"
|
||||
assert "expected" in diagnostic and "found" in diagnostic
|
||||
model.write_text("module app.model\nfn total(value: u64) -> u64 effects [] { assert(false); return value; }\n")
|
||||
main.write_text("module app.entry\nimport app.model;\nfn main() -> u64 effects [] { return app.model.total(42); }\n")
|
||||
trapped = json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest, code=4).stdout)
|
||||
assert trapped["source_location"]["file"] == "src/model.aji"
|
||||
main.write_text(original)
|
||||
model.write_text(saved_model)
|
||||
# Imported authority is explicit; checking never instantiates grants.
|
||||
model.write_text('module app.model\nfn emit(out: cap<io.write>) -> void effects [io.write] { io.stdout_write(out, b"module") or trap; }\n')
|
||||
main.write_text("module app.entry\nimport app.model;\nfn main(out: cap<io.write>) -> u64 effects [io.write] { app.model.emit(out); return 42; }\n")
|
||||
cli("check", "--manifest", manifest)
|
||||
missing = cli("run", "--fuel", "1000000", "--manifest", manifest, code=6)
|
||||
assert json.loads(missing.stdout)["status"] == "not_instantiated"
|
||||
write_manifest(root, grants='[capabilities]\nout = "io.write"\n')
|
||||
granted = json.loads(cli("run", "--fuel", "1000000", "--manifest", manifest).stdout)
|
||||
assert granted["stdout"] == "module"
|
||||
overridden = cli("run", "--fuel", "1000000", "--manifest", manifest, "--grant", "out=io.read", code=6)
|
||||
assert json.loads(overridden.stdout)["status"] == "not_instantiated"
|
||||
cli("explore", "--max-runs", "8", "--manifest", manifest)
|
||||
result_file = root / "result.json"
|
||||
hosted = cli("run", "--profile", "hosted", "--fuel", "1000000", "--result-file", result_file, "--manifest", manifest)
|
||||
assert hosted.stdout == "module" and json.loads(result_file.read_text())["value"] == 42
|
||||
main.write_text(original)
|
||||
model.write_text(saved_model)
|
||||
write_manifest(root)
|
||||
# Invalid paths/reserved names reject as manifest errors, without source execution.
|
||||
for mapping in ('app.model = "../outside.aji"', 'app.model = "/outside.aji"',
|
||||
'app.model = "src/./model.aji"', 'std.bytes = "src/model.aji"',
|
||||
'app.model = "src/model.aji"\napp.model = "src/other.aji"'):
|
||||
write_manifest(root, mapping)
|
||||
assert cli("check", "--manifest", manifest, code=2).stdout == ""
|
||||
write_manifest(root, 'app.model = "src/missing.aji"')
|
||||
cli("check", "--manifest", manifest, code=2)
|
||||
# Reject source symlinks and directory symlinks, including entry links.
|
||||
outside = root / "outside.aji"
|
||||
outside.write_text(saved_model)
|
||||
link = root / "src/link.aji"
|
||||
link.symlink_to(outside)
|
||||
write_manifest(root, 'app.model = "src/link.aji"')
|
||||
cli("check", "--manifest", manifest, code=2)
|
||||
alias = root / "alias"
|
||||
alias.symlink_to(root / "src", target_is_directory=True)
|
||||
write_manifest(root, 'app.model = "alias/model.aji"')
|
||||
cli("check", "--manifest", manifest, code=2)
|
||||
entry_link = root / "src/entry-link.aji"
|
||||
entry_link.symlink_to(main)
|
||||
write_manifest(root)
|
||||
manifest.write_text(manifest.read_text().replace('entry = "src/main.aji"', 'entry = "src/entry-link.aji"'))
|
||||
cli("check", "--manifest", manifest, code=2)
|
||||
# Static pipes/directories are rejected without a blocking read.
|
||||
pipe = root / "src/pipe.aji"
|
||||
os.mkfifo(pipe)
|
||||
write_manifest(root, 'app.model = "src/pipe.aji"')
|
||||
cli("check", "--manifest", manifest, code=2)
|
||||
(root / "src/directory.aji").mkdir()
|
||||
write_manifest(root, 'app.model = "src/directory.aji"')
|
||||
cli("check", "--manifest", manifest, code=2)
|
||||
large = root / "src/large.aji"
|
||||
with large.open("wb") as stream:
|
||||
stream.truncate((64 << 20) + 1)
|
||||
write_manifest(root, 'app.model = "src/large.aji"')
|
||||
cli("check", "--manifest", manifest, code=2)
|
||||
# Aggregate budget is enforced before parsing even if each input fits alone.
|
||||
with main.open("wb") as stream:
|
||||
stream.truncate(63 << 20)
|
||||
with large.open("wb") as stream:
|
||||
stream.truncate(2 << 20)
|
||||
cli("check", "--manifest", manifest, code=2)
|
||||
|
||||
print(f"source module CLI integration passed ({checks} checks)")
|
||||
Reference in new issue
Block a user