atagen

monolith

public
Star0
Watch0
d3ea8aacd50c4e342f595db5079c0842344b9534
1
ssh://brewery@pls.lobotomise.me:33/atagen/monolith.git

Blame: scripts/smoke.nu

612b2f27111catagen2026-10-17 05:03 UTC1
# Runs monolith nested on the host session with real clients and checks what
612b2f27111catagen2026-10-17 05:03 UTC2
# they see. Run from the repo root inside `nix develop`, after
612b2f27111catagen2026-10-17 05:03 UTC3
# `cargo build -p monolith && cargo build -p monolith-protocols --example workspaces`.
612b2f27111catagen2026-10-17 05:03 UTC4
612b2f27111catagen2026-10-17 05:03 UTC5
const TOOLS = [foot xterm xwayland lswt grim swaybg swaylock wlrctl]
612b2f27111catagen2026-10-17 05:03 UTC6
612b2f27111catagen2026-10-17 05:03 UTC7
def main [--log: path = /tmp/monolith-smoke.log] {
612b2f27111catagen2026-10-17 05:03 UTC8
    let tools = $TOOLS | each {|t| $"nixpkgs#($t)" }
612b2f27111catagen2026-10-17 05:03 UTC9
    let results = mktemp -t monolith-smoke.XXXXXX
612b2f27111catagen2026-10-17 05:03 UTC10
    let script = $env.CURRENT_FILE
612b2f27111catagen2026-10-17 05:03 UTC11
    let inner = $"nu -n ($script) inner ($results) ($log)"
612b2f27111catagen2026-10-17 05:03 UTC12
    # Some parent shells hand down SIGTERM blocked, so only SIGKILL reliably ends a hung run.
612b2f27111catagen2026-10-17 05:03 UTC13
    do -i { ^nix shell ...$tools -c sh -c $"unset VK_DRIVER_FILES; RUST_LOG=monolith=debug timeout -s KILL 60 target/debug/monolith run --backend nested ($inner) > ($log) 2>&1" }
612b2f27111catagen2026-10-17 05:03 UTC14
    let rows = open --raw $results | lines | where $it != "" | each {|l| $l | from json }
612b2f27111catagen2026-10-17 05:03 UTC15
    rm $results
612b2f27111catagen2026-10-17 05:03 UTC16
    if ($rows | is-empty) {
612b2f27111catagen2026-10-17 05:03 UTC17
        print $"no results, see ($log)"
612b2f27111catagen2026-10-17 05:03 UTC18
        exit 1
612b2f27111catagen2026-10-17 05:03 UTC19
    }
612b2f27111catagen2026-10-17 05:03 UTC20
    print ($rows | table)
612b2f27111catagen2026-10-17 05:03 UTC21
    if ($rows | any {|r| not $r.ok }) { exit 1 }
612b2f27111catagen2026-10-17 05:03 UTC22
}
612b2f27111catagen2026-10-17 05:03 UTC23
612b2f27111catagen2026-10-17 05:03 UTC24
def "main inner" [results: path, log: path] {
612b2f27111catagen2026-10-17 05:03 UTC25
    try { scenarios $results $log } catch {|e| {name: "harness", ok: false, detail: $e.msg} | to json -r | $"($in)\n" | save -a $results }
612b2f27111catagen2026-10-17 05:03 UTC26
    target/debug/monolith msg quit
612b2f27111catagen2026-10-17 05:03 UTC27
}
612b2f27111catagen2026-10-17 05:03 UTC28
612b2f27111catagen2026-10-17 05:03 UTC29
def scenarios [results: path, log: path] {
612b2f27111catagen2026-10-17 05:03 UTC30
    let check = {|name: string, ok: bool, detail: any|
612b2f27111catagen2026-10-17 05:03 UTC31
        {name: $name, ok: $ok, detail: ($detail | to text | str trim)} | to json -r | $"($in)\n" | save -a $results
612b2f27111catagen2026-10-17 05:03 UTC32
    }
612b2f27111catagen2026-10-17 05:03 UTC33
    let windows = {|| target/debug/monolith get state | from json | get windows | length }
612b2f27111catagen2026-10-17 05:03 UTC34
612b2f27111catagen2026-10-17 05:03 UTC35
    job spawn { foot }
612b2f27111catagen2026-10-17 05:03 UTC36
    job spawn { foot }
612b2f27111catagen2026-10-17 05:03 UTC37
    job spawn { xterm -e sleep 60 }
612b2f27111catagen2026-10-17 05:03 UTC38
    let n = wait-until 10sec {|| (do $windows) == 3 }
612b2f27111catagen2026-10-17 05:03 UTC39
    do $check "three windows over ipc" ($n) (do $windows)
612b2f27111catagen2026-10-17 05:03 UTC40
612b2f27111catagen2026-10-17 05:03 UTC41
    let listed = lswt | lines | skip 1 | length
612b2f27111catagen2026-10-17 05:03 UTC42
    do $check "toplevel list shows them" ($listed == 3) $listed
612b2f27111catagen2026-10-17 05:03 UTC43
612b2f27111catagen2026-10-17 05:03 UTC44
    let ws = do { timeout 1 target/debug/examples/workspaces } | complete | get stdout
612b2f27111catagen2026-10-17 05:03 UTC45
    do $check "ext-workspace sends a snapshot" ($ws | str contains "workspace") ($ws | lines | length)
612b2f27111catagen2026-10-17 05:03 UTC46
612b2f27111catagen2026-10-17 05:03 UTC47
    let shot = mktemp -t smoke-XXXXXX.png
612b2f27111catagen2026-10-17 05:03 UTC48
    let full = grim $shot | complete
612b2f27111catagen2026-10-17 05:03 UTC49
    do $check "output capture" ($full.exit_code == 0 and (ls $shot | get 0.size) > 0b) $full.stderr
612b2f27111catagen2026-10-17 05:03 UTC50
    let id = lswt -j | from json | get toplevels.0.identifier
612b2f27111catagen2026-10-17 05:03 UTC51
    let one = grim -T $id $shot | complete
612b2f27111catagen2026-10-17 05:03 UTC52
    do $check "toplevel capture" ($one.exit_code == 0) $one.stderr
612b2f27111catagen2026-10-17 05:03 UTC53
    rm $shot
612b2f27111catagen2026-10-17 05:03 UTC54
612b2f27111catagen2026-10-17 05:03 UTC55
    wlrctl toplevel close app_id:XTerm
612b2f27111catagen2026-10-17 05:03 UTC56
    let closed = wait-until 5sec {|| (do $windows) == 2 }
612b2f27111catagen2026-10-17 05:03 UTC57
    do $check "wlr-foreign-toplevel close" $closed (do $windows)
612b2f27111catagen2026-10-17 05:03 UTC58
612b2f27111catagen2026-10-17 05:03 UTC59
    job spawn { swaybg -c "#336699" }
612b2f27111catagen2026-10-17 05:03 UTC60
    let layer = wait-until 5sec {|| open --raw $log | str contains 'namespace="wallpaper"' }
612b2f27111catagen2026-10-17 05:03 UTC61
    do $check "layer surface mapped" $layer ""
612b2f27111catagen2026-10-17 05:03 UTC62
612b2f27111catagen2026-10-17 05:03 UTC63
    job spawn { swaylock -c 000000 }
612b2f27111catagen2026-10-17 05:03 UTC64
    let locked = wait-until 5sec {|| open --raw $log | str contains "session locked" }
612b2f27111catagen2026-10-17 05:03 UTC65
    do $check "session lock" $locked ""
612b2f27111catagen2026-10-17 05:03 UTC66
}
612b2f27111catagen2026-10-17 05:03 UTC67
612b2f27111catagen2026-10-17 05:03 UTC68
def wait-until [limit: duration, cond: closure] {
612b2f27111catagen2026-10-17 05:03 UTC69
    let until = (date now) + $limit
612b2f27111catagen2026-10-17 05:03 UTC70
    loop {
612b2f27111catagen2026-10-17 05:03 UTC71
        if (do $cond) { return true }
612b2f27111catagen2026-10-17 05:03 UTC72
        if (date now) > $until { return false }
612b2f27111catagen2026-10-17 05:03 UTC73
        sleep 100ms
612b2f27111catagen2026-10-17 05:03 UTC74
    }
612b2f27111catagen2026-10-17 05:03 UTC75
}