030 taps with auto discharge

✓ Passing This code compiles and runs correctly.

Code

// TEST: Taps with auto-discharge interaction
//
// This test verifies that:
// 1. Taps can observe phantom-tracked events
// 2. Auto-discharge still works after tap transformation
// 3. Tap observation happens BEFORE auto-discharge cleanup
//
// The tap observes the `opened` branch and logs. After the tap returns,
// auto-discharge inserts the close() call since the obligation wasn't consumed.
//
// Expected: Compiles successfully with:
// - Tap observing open event
// - Auto-discharge inserting close() after the tap
//
// NOTE: Using binding in taps that reference payload data requires
// binding substitution in the tap transform (tracked separately).

~import "$std/taps"
~import "$app/fs"

// Tap that observes file opens (no binding access, just observation)
~tap(app.fs:open -> *)
| opened |> app.fs:log_open(handle: 42)
    | done |> _

// Main flow: open a file and discard with auto-discharge
// The tap fires first, then auto-discharge inserts close()
~app.fs:open(path: "test.txt")
| opened _ |> _

pub fn main() void {}
input.kz

Expected Output

Opening file
TAP: Observed file open!
Closing file (auto-discharged)

Imported Files

// Library module: fs
// Phantom-tracked file operations for testing taps + auto-discharge

const std = @import("std");

const File = struct { handle: i32 };

// Open a file - returns opened! state (requires cleanup)
~pub event open { path: []const u8 }
| opened { file: *File[opened!] }

~proc open {
    std.debug.print("Opening file\n", .{});
    const f = std.heap.page_allocator.create(File) catch unreachable;
    f.* = File{ .handle = 42 };
    return .{ .opened = .{ .file = f } };
}

// Close - the ONLY consumer of [!opened]
~pub event close { file: *File[!opened] }
| closed {}

~proc close {
    std.debug.print("Closing file (auto-discharged)\n", .{});
    return .{ .closed = .{} };
}

// A logging event for taps - can observe file handle from the tap binding
// The tap passes in the handle it observed from the opened event
~pub event log_open { handle: i32 }
| done {}

~proc log_open {
    // Note: Procs receive input via generated code, we just print a static message
    std.debug.print("TAP: Observed file open!\n", .{});
    return .{ .done = .{} };
}
fs.kz

Test Configuration

MUST_RUN