011 registry scope composition

✗ Failing This test is currently failing.

Failed: backend-exec

Error Details

install

Failure Output

Showing last 10 of 53 lines
error: the following command failed with 4 compilation errors:
/opt/homebrew/Cellar/zig/0.15.2_1/bin/zig build-exe -ODebug --dep koru_parser --dep koru_ast=ast --dep koru_errors=errors --dep ast --dep flow_parser --dep liquid -Mroot=/Users/larsde/src/koru/tests/regression/400_RUNTIME_FEATURES/430_RUNTIME/430_011_registry_scope_composition/output_emitted.zig -ODebug --dep ast --dep lexer --dep errors --dep type_registry --dep expression_parser --dep union_collector --dep module_resolver -Mkoru_parser=/usr/local/lib/koru/src/parser.zig -ODebug --dep errors -Mast=/usr/local/lib/koru/src/ast.zig -ODebug -Merrors=/usr/local/lib/koru/src/errors.zig -ODebug --dep ast --dep lexer --dep errors --dep expression_parser -Mflow_parser=/usr/local/lib/koru/src/flow_parser.zig -ODebug -Mliquid=/usr/local/lib/koru/src/liquid.zig -ODebug -Mlexer=/usr/local/lib/koru/src/lexer.zig -ODebug --dep ast --dep log -Mtype_registry=/usr/local/lib/koru/src/type_registry.zig -ODebug --dep lexer --dep ast -Mexpression_parser=/usr/local/lib/koru/src/expression_parser.zig -ODebug --dep ast -Munion_collector=/usr/local/lib/koru/src/union_collector.zig -ODebug --dep config --dep log -Mmodule_resolver=/usr/local/lib/koru/src/module_resolver.zig -ODebug -Mlog=/usr/local/lib/koru/src/log.zig -ODebug --dep log -Mconfig=/usr/local/lib/koru/src/config.zig --cache-dir .zig-cache --global-cache-dir /Users/larsde/.cache/zig --name output --zig-lib-dir /opt/homebrew/Cellar/zig/0.15.2_1/lib/zig/ --listen=-

Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
+- install output transitive failure
   +- compile exe output Debug native 4 errors

error: the following build command failed with exit code 1:
.zig-cache/o/9f352e812f5cbfd4848798cc73a02bda/build /opt/homebrew/Cellar/zig/0.15.2_1/bin/zig /opt/homebrew/Cellar/zig/0.15.2_1/lib/zig /Users/larsde/src/koru/tests/regression/400_RUNTIME_FEATURES/430_RUNTIME/430_011_registry_scope_composition .zig-cache /Users/larsde/.cache/zig --seed 0xeb0ea2dd -Z97d3aae2b28aea32

Code

// DESIGN: Registry Scope - Composition and Globs
//
// Advanced registry features:
// - Glob patterns: module:* includes all events from a module
// - Scope composition: scope(other) includes another scope
// - Compiler flags: [debug]event only included with --debug

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

const std = @import("std");

// User management events
~pub event users.get { id: u64 }
| found []const u8
| not_found

~pub event users.list {}
| listed usize

~pub event users.create { name: []const u8 }
| created u64

// Admin events (restricted)
~pub event admin.delete_user { id: u64 }
| deleted

~pub event admin.reset_db {}
| reset

// Debug events (only in debug builds)
~pub event debug.dump_state {}
| dumped []const u8

~pub event debug.trace { message: []const u8 }
| traced

// =============================================================================
// REGISTRY SCOPES
// =============================================================================

// Internal scope - basic operations
~[registry:scope(internal)]std.runtime:register {
    std.io:println
}

// User scope - all user events via glob
~[registry:scope(user)]std.runtime:register {
    scope(internal)     // Compose: include internal scope
    users:*             // Glob: all events under users.*
}

// Admin scope - includes user scope + admin events
~[registry:scope(admin)]std.runtime:register {
    scope(user)         // Compose: include user scope
    admin:*             // Glob: all admin events
    [debug]debug:*      // Conditional: only with --debug flag
}

// =============================================================================
// TEST: Scope hierarchy
// =============================================================================

// User code - should work with "user" scope
const USER_CODE =
    \\~users.get(id: 42)
    \\| found |> std.io:println(text: "Found")
    \\| not_found |> std.io:println(text: "Not found")
;

// Admin code - should work with "admin" scope, fail with "user" scope
const ADMIN_CODE =
    \\~admin.delete_user(id: 42)
    \\| deleted |> std.io:println(text: "User deleted")
;

// Debug code - should only work with "admin" scope AND --debug flag
const DEBUG_CODE =
    \\~debug.dump_state()
    \\| dumped |> std.io:println(text: "State")
;

// Test user scope
~std.runtime:parse.source(source: USER_CODE, file_name: "user.kz", allocator: std.heap.page_allocator)
| parsed p |> std.runtime:eval(ast: p.ast, scope: "user")
    | result _ |> std.io:print.ln("User code OK")
    | event_denied e |> std.io:print.ln("User denied: {{e.name:s}}")
    | exhausted _ |> std.io:print.ln("User exhausted")
    | validation_error _ |> std.io:print.ln("User validation error")
    | dispatch_error _ |> std.io:print.ln("User dispatch error")
    | scope_not_found _ |> std.io:print.ln("User scope missing")
| parse_error e |> std.io:print.ln("Parse error: {{e.message:s}}")

// Test debug scope in non-debug builds (should be denied)
~std.runtime:parse.source(source: DEBUG_CODE, file_name: "debug.kz", allocator: std.heap.page_allocator)
| parsed p |> std.runtime:eval(ast: p.ast, scope: "admin")
    | result _ |> std.io:print.ln("UNEXPECTED: Debug code ran without --debug")
    | event_denied e |> std.io:print.ln("Debug denied: {{e.name:s}}")
    | exhausted _ |> std.io:print.ln("Debug exhausted")
    | validation_error _ |> std.io:print.ln("Debug validation error")
    | dispatch_error _ |> std.io:print.ln("Debug dispatch error")
    | scope_not_found _ |> std.io:print.ln("Debug scope missing")
| parse_error e |> std.io:print.ln("Parse error: {{e.message:s}}")

// Test admin scope with user code (should work - admin includes user)
~std.runtime:parse.source(source: USER_CODE, file_name: "user2.kz", allocator: std.heap.page_allocator)
| parsed p |> std.runtime:eval(ast: p.ast, scope: "admin")
    | result _ |> std.io:print.ln("User code with admin scope OK")
    | event_denied e |> std.io:print.ln("Unexpected denial: {{e.name:s}}")
    | exhausted _ |> std.io:print.ln("Admin exhausted")
    | validation_error _ |> std.io:print.ln("Admin validation error")
    | dispatch_error _ |> std.io:print.ln("Admin dispatch error")
    | scope_not_found _ |> std.io:print.ln("Admin scope missing")
| parse_error e |> std.io:print.ln("Parse error: {{e.message:s}}")

// Test admin code with user scope (should fail)
~std.runtime:parse.source(source: ADMIN_CODE, file_name: "admin.kz", allocator: std.heap.page_allocator)
| parsed p |> std.runtime:eval(ast: p.ast, scope: "user")
    | result _ |> std.io:print.ln("UNEXPECTED: Admin code ran with user scope!")
    | event_denied e |> std.io:print.ln("Correctly denied admin event: {{e.name:s}}")
    | exhausted _ |> std.io:print.ln("Admin code exhausted")
    | validation_error _ |> std.io:print.ln("Admin code validation error")
    | dispatch_error _ |> std.io:print.ln("Admin code dispatch error")
    | scope_not_found _ |> std.io:print.ln("Admin code scope missing")
| parse_error e |> std.io:print.ln("Parse error: {{e.message:s}}")
input.kz

Test Configuration

MUST_RUN