40bb6ff579
- swarm.el: coordinator running fan-out/converge on El NATIVE threads (thread.el spawn/join) in bounded concurrency waves, order-preserving; convergence strategies collect/merge/vote/reduce; integer per-mille failure threshold (El float division is unreliable — avoided deliberately). - ccr.el: per-worker Compiled Context Routing — retrieval/scoping/compaction into a bounded, minimal package; the compiled-context boundary is the security boundary (a worker cannot receive or leak sibling inputs). - containment.el: the three Swarm containment rules enforced via scope tokens (Rule 1 no join, Rule 2 no open, Rule 3 no lateral edge) + execution-tree lateral-edge check. - primitives.el: attend/think/intend/act/learn seam the swarm composes over, with engram-backed fallbacks and an explicit binding point for the reshape. - prototype json_array_push in el_runtime.h (defined but unprototyped). test_swarm: 12/12 — native fan-out/converge, bounded concurrency, durable tracking, CCR bounding + non-leak, and all three containment rules.
76 lines
3.8 KiB
EmacsLisp
76 lines
3.8 KiB
EmacsLisp
// test_swarm.el — end-to-end proof of the swarm capability on native El threads.
|
|
//
|
|
// Proves: native-thread fan-out/converge, bounded concurrency, per-worker CCR
|
|
// bounded context (with the security-boundary property), containment Rule 2
|
|
// enforcement, and durable work-tracking.
|
|
|
|
fn assert_true(label: String, cond: Bool, fails: Int) -> Int {
|
|
if cond {
|
|
print(" ok " + label)
|
|
return fails
|
|
}
|
|
print(" FAIL " + label)
|
|
return fails + 1
|
|
}
|
|
|
|
fn main() -> Int {
|
|
let fails = 0
|
|
|
|
// ── 1) fan-out / converge (collect) over native threads ──
|
|
let inputs: String = "[\"alpha\",\"bravo\",\"charlie\",\"delta\",\"echo\"]"
|
|
let refs: String = "[]"
|
|
let cfg: String = "{\"concurrency\":\"2\",\"strategy\":\"collect\",\"min_success_ratio\":\"1.0\"}"
|
|
let res: String = swarm_run("analyze_item", refs, inputs, cfg)
|
|
let status: String = json_get_string(res, "status")
|
|
let fails = assert_true("swarm completed", str_eq(status, "completed"), fails)
|
|
|
|
let merged: String = json_get_raw(res, "merged")
|
|
let count: Int = json_array_len(merged)
|
|
let fails = assert_true("collect returned 5 results (bounded concurrency=2)", count == 5, fails)
|
|
|
|
// ── 2) work-tracking is durable + complete ──
|
|
let corr: String = json_get_string(res, "corr_id")
|
|
let started: Int = worktrack_count_kind(corr, "worker.started")
|
|
let completed: Int = worktrack_count_kind(corr, "worker.completed")
|
|
let created: Int = worktrack_count_kind(corr, "swarm.created")
|
|
let done: Int = worktrack_count_kind(corr, "swarm.completed")
|
|
let fails = assert_true("tracked 5 worker.started", started == 5, fails)
|
|
let fails = assert_true("tracked 5 worker.completed", completed == 5, fails)
|
|
let fails = assert_true("tracked swarm.created + swarm.completed", (created == 1) && (done == 1), fails)
|
|
|
|
// ── 3) CCR: bounded, minimal, non-leaking per-worker context ──
|
|
let wtoken: String = containment_worker_token(corr, corr + "/worker-0")
|
|
let ctx: String = ccr_compile("analyze_item", refs, "alpha", corr, corr + "/worker-0", wtoken)
|
|
let in_budget: Bool = ccr_within_budget(ctx)
|
|
let fails = assert_true("CCR context within token budget", in_budget, fails)
|
|
let this_input: String = json_get_string(ctx, "input")
|
|
let fails = assert_true("CCR context contains THIS worker's input", str_eq(this_input, "alpha"), fails)
|
|
// security boundary: a worker's compiled context must not carry a sibling input
|
|
let leaks_sibling: Bool = str_contains(ctx, "charlie")
|
|
let fails = assert_true("CCR context does NOT leak sibling inputs", !leaks_sibling, fails)
|
|
|
|
// ── 4) containment Rule 2: a worker may not open a swarm ──
|
|
let worker_caller_cfg: String = json_set(cfg, "caller_token", wtoken)
|
|
let denied: String = swarm_run("analyze_item", refs, inputs, worker_caller_cfg)
|
|
let dstatus: String = json_get_string(denied, "status")
|
|
let fails = assert_true("worker-token caller denied opening a swarm (Rule 2)", str_eq(dstatus, "denied"), fails)
|
|
|
|
// coordinator token IS allowed
|
|
let coord: String = containment_coordinator_token("some-corr")
|
|
let allow_reason: String = containment_check_open(coord)
|
|
let fails = assert_true("coordinator token allowed to open a swarm", str_eq(allow_reason, ""), fails)
|
|
|
|
// ── 5) containment Rule 3: no lateral worker->worker edge ──
|
|
let lateral: String = containment_check_lateral(wtoken, "some-sibling")
|
|
let fails = assert_true("lateral worker->worker edge rejected (Rule 3)", !str_eq(lateral, ""), fails)
|
|
let vertical: String = containment_check_lateral(wtoken, "")
|
|
let fails = assert_true("vertical worker->coordinator edge allowed", str_eq(vertical, ""), fails)
|
|
|
|
if fails == 0 {
|
|
print("PASS test_swarm")
|
|
return 0
|
|
}
|
|
print("FAIL test_swarm (" + int_to_str(fails) + " failures)")
|
|
return 1
|
|
}
|