#!/usr/bin/env nu # Compare the literal subtree archive with native Git, including binary files and links. def main [component: path] { let component = ($component | path expand) let root = (mktemp -d -p /tmp git-archive.XXXXXX) let repo = ($root | path join repo) mkdir ($repo | path join extensions/demo) ($root | path join native) ($root | path join wasi) ^git init -q -b main $repo 'outside' | save ($repo | path join outside.txt) 0x[00 ff 7f 80] | save ($repo | path join 'extensions/demo/payload space.bin') 'executable' | save ($repo | path join extensions/demo/run) ^chmod +x ($repo | path join extensions/demo/run) ^ln -s 'payload space.bin' ($repo | path join extensions/demo/link) ^git -C $repo add . ^git -C $repo -c user.name=Test -c user.email=test@example.com commit --no-gpg-sign -q -m fixture ^git -C $repo archive --format=tar $'--output=($root)/native.tar' HEAD extensions ^wasmtime run -S http -S cli-exit-with-code=y --dir $root $component -C $repo archive --format=tar $'--output=($root)/wasi.tar' HEAD extensions if $env.LAST_EXIT_CODE != 0 { error make {msg: 'WASI archive failed'} } for side in [native wasi] { ^tar -xf $'($root)/($side).tar' -C $'($root)/($side)' } ^diff -r $'($root)/native' $'($root)/wasi' if $env.LAST_EXIT_CODE != 0 { error make {msg: 'Extracted contents differ'} } if ($'($root)/wasi/outside.txt' | path exists) { error make {msg: 'Archive includes unrelated files'} } let native_mode = (^stat -c '%a' $'($root)/native/extensions/demo/run') let wasi_mode = (^stat -c '%a' $'($root)/wasi/extensions/demo/run') if $native_mode != $wasi_mode { error make {msg: 'Executable mode differs'} } if (^readlink $'($root)/wasi/extensions/demo/link') != 'payload space.bin' { error make {msg: 'Symlink differs'} } for args in [[archive bad-revision extensions] [archive HEAD missing] [archive --format=zip HEAD]] { let result = (^wasmtime run -S http -S cli-exit-with-code=y --dir $root $component -C $repo ...$args | complete) if $result.exit_code == 0 { error make {msg: $'Invalid archive succeeded: ($args)'} } } print $'Archive comparison passed: ($root)' }