002 budget exhaustion

✓ Passing This code compiles and runs correctly.

Code

// Test: Budget exhaustion mid-flow
// When budget runs out, return exhausted branch with what was used

~import "$std/runtime"
~import "$std/io"

const std = @import("std");

~pub event expensive { data: []const u8 }
| processed { result: []const u8 }

~proc expensive {
    return .{ .processed = .{ .result = data } };
}

// Register with high cost
~std.runtime:register(scope: "test") {
    expensive(50)  // costs 50 tokens per call
}

const TEST_SOURCE = "~expensive(data: \"a\")\n| processed p1 |> expensive(data: \"b\")\n| processed p2 |> result { p2.result }";

// Run with budget of 75 - second call should exhaust
~std.runtime:run(source: TEST_SOURCE, scope: "test", budget: 75)
| result _ |> std.io:println(text: "FAIL: should have exhausted")
| exhausted e |> std.io:print.ln("PASS: exhausted after {{ e.used:d }} tokens, last event: {{ e.last_event:s }}")
| 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")
input.kz

Expected Output

PASS: exhausted after 50 tokens, last event: expensive

Test Configuration

MUST_RUN