✓
Passing This code compiles and runs correctly.
Code
// Test 168: Import Registers Taps Automatically
//
// Tests that importing a module automatically registers any taps defined in it.
// This is the mechanism that makes `~[profile]import "std/profiler"` work -
// the import adds the module's universal taps to the tap registry, enabling
// full-program instrumentation with a single line.
//
// Structure:
// test_lib/
// logger.kz → Defines a universal tap ~tap(* -> *) that logs all events
//
// Expected: The logger's tap fires for ALL events, even though we didn't
// explicitly write the tap pattern in this file.
//
// This demonstrates "ambient" behavior - importing makes taps active.
const std = @import("std");
// Import the logger module (which defines universal taps)
~import app/test_lib/logger
// Define some events to test with
~tor compute { x: i32 } -> i32
~tor format { value: i32 } -> string
~tor display { text: string }
~proc compute|zig {
std.debug.print("compute({d})\n", .{x});
return x * 2;
}
~proc format|zig {
std.debug.print("format({d})\n", .{value});
// Allocate temporary string for testing
const text = "formatted";
return text;
}
~proc display|zig {
std.debug.print("Final: {s}\n", .{text});
}
// Call events - the logger's universal tap should intercept them!
~compute(x: 42): r |> format(value: r): f |> display(text: f)
Actual
compute(42)
[TAP] Intercepted event: compute
format(84)
[TAP] Intercepted event: format
Final: formatted
Expected output
compute(42)
[TAP] Intercepted event: compute
format(84)
[TAP] Intercepted event: format
Final: formatted
Flows
flow ~compute click a branch to expand · @labels scroll to their anchor
compute (x: 42)
Imported Files
// Logger module with event-specific taps
// When imported, these taps automatically register and intercept matching events
const std = @import("std");
~import std/taps
// Define a logging event
~pub tor log { event_name: string }
~proc log|zig {
std.debug.print("[TAP] Intercepted event: {s}\n", .{event_name});
}
// Tap: Observe transitions from compute (any destination)
// When main.kz calls compute(), this tap fires automatically!
// Note: 'input:' is the canonical namespace for entry module events
~tap(input:compute -> *): v |> log(event_name: "compute")
// Tap: Observe transitions from format (any destination)
// When main.kz calls format(), this tap fires automatically!
// Note: 'input:' is the canonical namespace for entry module events
~tap(input:format -> *): v |> log(event_name: "format")
Test Configuration
MUST_RUN