?
Unknown Status unknown.
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 tor greet { name: string }
| greeted string
~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")
Expected output
PASS: budget tracking works, used: 10
Flows
flow ~register click a branch to expand · @labels scroll to their anchor
register (scope: "test", source: greet(10) // costs 10 tokens per call)
flow ~run click a branch to expand · @labels scroll to their anchor
run (source: TEST_SOURCE, scope: "test", budget: 100)
Test Configuration
MUST_RUN