✓
Passing This code compiles and runs correctly.
Code
// Test: Handle pool tracks opened resources
// Resources with [state!] are added to handle pool
// Response includes active handles
~import "$std/runtime"
~import "$std/io"
const std = @import("std");
// Open creates an obligation
~pub event open { path: []const u8 }
| opened { handle: []const u8[opened!] }
~proc open {
return .{ .opened = .{ .handle = "file_1" } };
}
// Close discharges the obligation
~pub event close { handle: []const u8[!opened] }
| closed {}
~proc close {
return .{ .closed = .{} };
}
// Register scope - compiler infers close is discharge for open
~std.runtime:register(scope: "test") {
open(10)
close(1)
}
const TEST_SOURCE = "~open(path: \"test.txt\")\n| opened f |> result { path: \"test.txt\" }";
// Open a file, don't close - should be in handle pool
~std.runtime:run(source: TEST_SOURCE, scope: "test", budget: 100, auto_discharge: false)
| result r |> std.io:print.ln("PASS: handles tracked: {{ r.handles:d }}")
| exhausted _ |> std.io:println(text: "FAIL: should not exhaust")
| parse_error _ |> std.io:println(text: "PARSE ERROR")
| validation_error _ |> std.io:println(text: "VALIDATION ERROR")
| event_denied _ |> std.io:println(text: "EVENT DENIED")
| dispatch_error _ |> std.io:println(text: "DISPATCH ERROR")
| scope_not_found _ |> std.io:println(text: "SCOPE NOT FOUND")
Expected Output
PASS: handles tracked: 1
Test Configuration
MUST_RUN