56 lines
3.9 KiB
Nu
56 lines
3.9 KiB
Nu
#!/usr/bin/env nu
|
|
# Exercise the new commands through the real host and brush shell.
|
|
# The S6 fixture must contain app.tsx and its pinned node_modules.
|
|
def check [ok: bool, message: string] {
|
|
if not $ok { error make {msg: $message} }
|
|
print $'ok - ($message)'
|
|
}
|
|
def main [fixture: path, native_esbuild: path] {
|
|
let target = ($env.CARGO_TARGET_DIR | path expand)
|
|
let root = (^mktemp -d /tmp/t42-world-XXXXXXXX | str trim)
|
|
let bundle = ($root | path join bundle)
|
|
mkdir ($bundle | path join bin) ($bundle | path join src)
|
|
for tool in [du stat id nohup tar gzip gunzip zcat] {
|
|
cp ($target | path join wasm32-wasip2 release $'($tool).wasm') ($bundle | path join bin $'($tool).wasm')
|
|
}
|
|
cp ($target | path join wasm32-wasip2 release brush.wasm) ($bundle | path join bin sh.wasm)
|
|
cp ($target | path join awk.wasm) ($bundle | path join bin awk.wasm)
|
|
cp ($target | path join esbuild.wasm) ($bundle | path join bin esbuild.wasm)
|
|
cp ($env.FILE_PWD | path join .. qjs qjs.wasm) ($bundle | path join bin qjs.wasm)
|
|
cp -r $fixture ($bundle | path join src app)
|
|
let host = ($target | path join debug sausage)
|
|
let world = ($root | path join world)
|
|
let script = 'set -e; id; id -un; printf hello > /payload; du -b /payload; stat -c "%n %s %F %U %G" /payload; printf "2 a\n3 b\n" | awk "{sum += \$1} END {print sum}"; tar -czf /world.tgz -C / payload; qjs -e "console.log(6*7)"; esbuild /src/app/app.tsx --bundle --minify --format=iife --platform=browser --jsx=automatic --jsx-import-source=preact --legal-comments=none --log-level=error --outfile=/app.js'
|
|
let result = (^$host sh $world --userland $bundle -c $script | complete)
|
|
print $result.stdout
|
|
if $result.stderr != '' { print --stderr $result.stderr }
|
|
check ($result.exit_code == 0) 'real world shell and esbuild'
|
|
check ($result.stdout | str contains 'uid=0(root) gid=0(root) groups=0(root)') 'world root identity'
|
|
check ($result.stdout | str contains '/payload 5 regular file root root') 'world portable stat'
|
|
check ($result.stdout | str contains $'5(char tab)/payload') 'world apparent du'
|
|
check ('5' in ($result.stdout | lines)) 'world awk pipeline'
|
|
check ($result.stdout | str contains '42') 'world QuickJS'
|
|
let native_bundle = ($root | path join native.js)
|
|
let native = (do { cd ($bundle | path join src app); ^$native_esbuild app.tsx --bundle --minify --format=iife --platform=browser --jsx=automatic --jsx-import-source=preact --legal-comments=none --log-level=error $'--outfile=($native_bundle)' } | complete)
|
|
let world_bundle = ($world | path join world app.js)
|
|
check ($native.exit_code == 0 and (open --raw $native_bundle) == (open --raw $world_bundle)) 'world esbuild matches native bytes'
|
|
let render = (^node ($world | path join world src app check.mjs) $world_bundle | complete)
|
|
print $render.stdout
|
|
check ($render.exit_code == 0) 'world esbuild bundle renders S6 app'
|
|
let extracted = ($root | path join extracted)
|
|
mkdir $extracted
|
|
^tar -xzf ($world | path join world world.tgz) -C $extracted
|
|
check ($env.LAST_EXIT_CODE == 0 and (open --raw ($extracted | path join payload)) == 'hello') 'native extracts real world archive'
|
|
let native = ($root | path join native)
|
|
mkdir $native
|
|
'from native' | save ($native | path join native-file)
|
|
^tar -czf ($world | path join world native.tgz) -C $native native-file
|
|
let reverse = (^$host sh $world -c 'tar -xzf /native.tgz -C /; qjs --std -e "console.log(std.loadFile(\"/native-file\"))"' | complete)
|
|
check ($reverse.exit_code == 0 and ($reverse.stdout | str trim) == 'from native') 'world extracts native archive'
|
|
let nohup = (^$host sh $world -c 'nohup qjs --std -e "std.exit(7)"' | complete)
|
|
check ($nohup.exit_code == 7) 'nohup preserves child status'
|
|
let missing = (^$host sh $world -c 'nohup t42-missing-command' | complete)
|
|
check ($missing.exit_code == 127) 'nohup missing command status'
|
|
print $'evidence: ($root)'
|
|
}
|