✓
Passing This code compiles and runs correctly.
Code
// codemod:skip — runtime-eval blocks use internal (snake) names; flow_parser does not normalize.
// Test: Budget exhaustion with open handles triggers auto-discharge
// Even when exhausted, we clean up resources before returning
~import std/runtime
~import std/io
const std = @import("std");
~pub event open { path: []const u8 }
| opened []const u8<opened!>
~proc open|zig {
std.debug.print("opened {s}\n", .{path});
return .{ .opened = "file_1" };
}
~pub event close { handle: []const u8<!opened> }
~proc close|zig {
std.debug.print("auto-closing file\n", .{});
}
~pub event expensive-read { handle: []const u8<opened> }
| read []const u8
~proc expensive-read|zig {
return .{ .read = "file contents" };
}
~std/runtime:register(scope: "test") {
open(10)
close(1)
expensive-read(100) // Very expensive!
}
const TEST_SOURCE = "~open(path: \"x.txt\")\n| opened f |> expensive-read(handle: f.handle)\n| read r |> result { r.data }";
// Open file (10), then try expensive read (100) with only 50 budget
// Should exhaust, but still auto-discharge the open file
~std/runtime:run(source: TEST_SOURCE, scope: "test", budget: 50, auto-discharge: true)
| result _ |> std/io:print.ln("FAIL: should have exhausted")
| exhausted e |> std/io:print.ln("PASS: exhausted with {{ e.used:d }} used, last event: {{ e.last_event:s }}")
| parse-error _ |> std/io:print.ln("PARSE ERROR")
| validation-error _ |> std/io:print.ln("VALIDATION ERROR")
| shape-error _ |> std/io:print.ln("SHAPE ERROR")
| event-denied _ |> std/io:print.ln("EVENT DENIED")
| dispatch-error _ |> std/io:print.ln("DISPATCH ERROR")
| scope-not-found _ |> std/io:print.ln("SCOPE NOT FOUND")
Actual
opened x.txt
auto-closing file
[AUTO-DISCHARGE] Invoked 'close' for handle 'file_1' [main:opened]
PASS: exhausted with 10 used, last event: open
Expected output
opened x.txt
auto-closing file
[AUTO-DISCHARGE] Invoked 'close' for handle 'file_1' [main:opened]
PASS: exhausted with 10 used, last event: open
Test Configuration
MUST_RUN