✓
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 []const u8
~proc greet|zig {
var buf: [256]u8 = undefined;
const msg = std.fmt.bufPrint(&buf, "Hello, {s}!", .{name}) catch "Hello!";
return .{ .greeted = 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:print.ln("FAIL: should not exhaust with budget 100")
| 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
PASS: budget tracking works, used: 10
Expected output
PASS: budget tracking works, used: 10
Test Configuration
MUST_RUN