001 basic budget tracking

✓ Passing This code compiles and runs correctly.

Code

// Test: Basic budget tracking
// Events have costs, budget is deducted on each call
// Response includes used budget

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

const std = @import("std");

// Simple event with no resources
~pub event greet { name: []const u8 }
| greeted { message: []const u8 }

~proc greet {
    var buf: [256]u8 = undefined;
    const msg = std.fmt.bufPrint(&buf, "Hello, {s}!", .{name}) catch "Hello!";
    return .{ .greeted = .{ .message = msg } };
}

// Register scope with costs
~std.runtime:register(scope: "test") {
    greet(10)  // costs 10 tokens per call
}

const TEST_SOURCE = "~greet(name: \"World\")\n| greeted g |> result { g.message }";

// Run with budget of 100
~std.runtime:run(source: TEST_SOURCE, scope: "test", budget: 100)
| result r |> std.io:print.ln("PASS: budget tracking works, used: {{ r.used:d }}")
| exhausted _ |> std.io:println(text: "FAIL: should not exhaust with budget 100")
| 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: budget tracking works, used: 10

Test Configuration

MUST_RUN