✓
Passing This code compiles and runs correctly.
Code
// Pins: a world-mounted bridge keeps the custody ledger — one
// tab-separated line per custody event in <world>/holds.log:
//
// session-open t=<ms> session=<id>
// mint t=<ms> session=<id> handle=<tok> verb=<event> type=<T> subject=<args>
// release t=<ms> session=<id> handle=<tok> by=<discharge event>
// session-closed t=<ms> session=<id>
//
// The log is the successor's read of custody: a mint inside a closed
// span with no release was released at hang-up; a mint with no
// session-closed after it died holding. Minted tokens are seeded hex
// and never printed — post.sh pins the FIELD SHAPE (tab names, digit
// timestamps, h:Res:<6hex>, mint/release carrying the same handle).
import std/io
import std/bridge
import std/runtime
import reslib/res
std/runtime:register(scope: "res") {
reslib.res:mint -> mint(1)
reslib.res:grab -> grab(1)
reslib.res:release -> release(1)
}
tor step-quiet { br: *std/bridge:Bridge<session>, source: string<*>, tag: string }
step-quiet = std/bridge:run(br, source)
| result r |> std/io:print.ln("{{ tag:s }}: ok (holds {{ r.handles:d }})")
| unhandled-branch ub |> std/io:print.ln("{{ tag:s }} FAIL unhandled {{ ub.branch:s }}")
| defined d |> std/io:print.ln("{{ tag:s }} FAIL defined {{ d:s }}")
| error runerr |> std/bridge:error-decode(e: runerr)
| dispatch-error e |> std/io:print.ln("{{ tag:s }} FAIL dispatch {{ e.message:s }}")
| event-denied ev |> std/io:print.ln("{{ tag:s }} FAIL denied {{ ev:s }}")
| parse-error p |> std/io:print.ln("{{ tag:s }} FAIL parse {{ p.message:s }}")
| validation-error v |> std/io:print.ln("{{ tag:s }} FAIL invalid {{ v:s }}")
| shape-error sh |> std/io:print.ln("{{ tag:s }} FAIL shape {{ sh.message:s }}")
| exhausted _ |> std/io:print.ln("{{ tag:s }} FAIL exhausted")
| scope-not-found s2 |> std/io:print.ln("{{ tag:s }} FAIL noscope {{ s2:s }}")
| residue _ |> std/io:print.ln("{{ tag:s }} FAIL residue outcome")
| partial p |> std/io:print.ln("{{ tag:s }} FAIL unexpected partial")
[with]std/bridge:create(id: "w1", scope: "res", world: "tests/regression/400_RUNTIME_FEATURES/440_RESOURCE_BRIDGE/440_052_holds_log_records_the_custody_arc/world"): br
|> std/io:print.ln("--- session w1 open")
|> step-quiet(br, source: "mint() | ok h |>", tag: "mint")
|> step-quiet(br, source: "release(r: r1)", tag: "release")
|> std/bridge:close(br)
|> std/io:print.ln("--- session w1 closed")
// A worldless bridge keeps no ledger — post.sh also pins that nothing
// lands in the test dir from this span.
[with]std/bridge:create(id: "w2", scope: "res"): br2
|> step-quiet(br: br2, source: "mint() | ok h |>", tag: "w2-mint")
|> step-quiet(br: br2, source: "release(r: r1)", tag: "w2-release")
|> std/bridge:close(br: br2)
Supporting Files
// A `*T` resource module for the token-dispatch pin: the wire never sees
// a pointer — mint() produces a *Res that packs as "h:Res:N", use()
// resolves the token back to the live struct, release() discharges it.
pub const Res = struct { v: u32 };
~pub tor mint {} -> *Res<opened!>
~proc mint|zig {
const r = @import("std").heap.page_allocator.create(Res) catch unreachable;
r.* = .{ .v = 42 };
return r;
}
~pub tor grab { r: *Res<opened> }
~proc grab|zig {
var buf: [32]u8 = undefined;
const s = @import("std").fmt.bufPrint(&buf, "used v={d}\n", .{r.v}) catch unreachable;
_ = @import("std").posix.write(1, s) catch {};
}
~pub tor release { r: *Res<!opened> }
~proc release|zig {
@import("std").heap.page_allocator.destroy(r);
}
Actual
--- session w1 open
mint: ok (holds 1)
release: ok (holds 0)
--- session w1 closed
w2-mint: ok (holds 1)
w2-release: ok (holds 0)
Expected output
--- session w1 open
mint: ok (holds 1)
release: ok (holds 0)
--- session w1 closed
w2-mint: ok (holds 1)
w2-release: ok (holds 0)
Flows
flow ~register click a branch to expand · @labels scroll to their anchor
register (scope: "res", source: reslib.res:mint -> mint(1)
reslib.res:grab -> grab(1)
reslib.res:release -> release(1))
subflow ~step-quiet click a branch to expand · @labels scroll to their anchor
run (br, source)
flow ~create click a branch to expand · @labels scroll to their anchor
create (id: "w1", scope: "res", world: "tests/regression/400_RUNTIME_FEATURES/440_RESOURCE_BRIDGE/440_052_holds_log_records_the_custody_arc/world")
flow ~create click a branch to expand · @labels scroll to their anchor
create (id: "w2", scope: "res")
Test Configuration
MUST_RUN
koru.json:
{
"paths": {
"std": "../../../../../koru_std",
"app": "{{ ENTRY }}",
"reslib": "{{ ENTRY }}/reslib"
}
}Post-validation Script:
#!/bin/bash
# Pins the holds.log FORMAT — the custody ledger a successor session
# reads. Field names and ordering are the contract; the minted hex and
# the millisecond timestamps are the parts a pin must not spell.
#
# holds.log is append-only across program runs into the same world, so
# the pin is written against accumulation: every line must be one of
# the four custody shapes, opens pair with closes, and the trailing
# session block shows mint and release naming the same handle.
set -u
cd "$(dirname "$0")"
fail() { echo "FAIL: $1"; rm -rf world; exit 1; }
log=world/holds.log
[ -f "$log" ] || fail "world/holds.log was not written"
# Every line is one of the four shapes — no field drift anywhere in
# the file, however many runs have appended to it.
bad=$(grep -vx 'session-open t=[0-9]* session=w1\|session-closed t=[0-9]* session=w1\|mint t=[0-9]* session=w1 handle=h:Res:[0-9a-f]\{6\} verb=mint type=Res subject=.*\|release t=[0-9]* session=w1 handle=h:Res:[0-9a-f]\{6\} by=release' "$log" | head -1 || true)
[ -z "$bad" ] || fail "non-custody or malformed line: $bad"
opens=$(grep -c 'session-open' "$log")
closes=$(grep -c 'session-closed' "$log")
[ "$opens" -eq "$closes" ] || fail "unpaired session markers: $opens opens, $closes closes"
# The trailing block is this run's session: open, mint, release,
# closed — and release names the token mint minted.
block=$(tail -4 "$log")
echo "$block" | sed -n '1p' | grep -qx 'session-open t=[0-9]* session=w1' \
|| fail "block head is not session-open: $(echo "$block" | sed -n '1p')"
echo "$block" | sed -n '4p' | grep -qx 'session-closed t=[0-9]* session=w1' \
|| fail "block tail is not session-closed: $(echo "$block" | sed -n '4p')"
minted=$(echo "$block" | sed -n '2p' | grep -o 'handle=[^ ]*' | cut -d= -f2)
freed=$(echo "$block" | sed -n '3p' | grep -o 'handle=[^ ]*' | cut -d= -f2)
[ -n "$minted" ] || fail "block mint line carries no handle"
[ "$minted" = "$freed" ] || fail "release handle '$freed' != minted '$minted'"
# The worldless session (w2) writes nothing anywhere the test can see.
[ ! -e holds.log ] || fail "worldless session wrote a holds.log into the test dir"
rm -rf world