#!/usr/bin/env nu # Compare SSH clone, fetch, and push contents and refs with native Git. use std/assert def wasi [component: path, root: path, args: list] { let ready = (open ($root | path join ready.json)) let result = (^wasmtime run -S inherit-network -S allow-ip-name-lookup -S http -S cli-exit-with-code=y --dir $'($root)/guest::/' --env HOME=/home --env $'SAUSAGE_HOST_API=http://127.0.0.1:($ready.api)' --env GIT_AUTHOR_NAME=Agent --env GIT_AUTHOR_EMAIL=agent@example.test --env GIT_COMMITTER_NAME=Agent --env GIT_COMMITTER_EMAIL=agent@example.test $component ...$args | complete) if $result.exit_code != 0 {error make {msg: ($result | to json)}} $result } def native [args: list] { let result = (^git ...$args | complete) if $result.exit_code != 0 {error make {msg: ($result | to json)}} $result } def main [component: path, ssh_component: path, root: path] { let component = ($component | path expand) let ssh_component = ($ssh_component | path expand) let root = ($root | path expand) let ready = (open ($root | path join ready.json)) let wit = (^wasm-tools component wit $component | complete) assert equal $wit.exit_code 0 let imports = ($wit.stdout | lines | str trim | where {|line| $line | str starts-with 'import '}) assert (not ($imports | is-empty)) assert ($imports | all {|line| $line | str starts-with 'import wasi:'}) print 'Git component imports: PASS (WASI only)' print ($imports | str join (char newline)) wasi $ssh_component $root [-o StrictHostKeyChecking=accept-new -p $ready.ssh $'($ready.user)@127.0.0.1' true] | ignore let seed = ($root | path join host/seed) let bare = ($root | path join host/bare.git) let clone = ($root | path join guest/clone) let comparison = ($root | path join host/native-clone) native [init -b main $seed] | ignore native [-C $seed config user.name Agent] | ignore native [-C $seed config user.email agent@example.test] | ignore $"base\n" | save ($seed | path join file.txt) native [-C $seed add .] | ignore native [-C $seed commit --no-gpg-sign -m base] | ignore native [clone --bare $seed $bare] | ignore let url = $'ssh://($ready.user)@127.0.0.1:($ready.ssh)($bare)' let ssh_command = $"ssh -F /dev/null -o IdentityAgent=none -o BatchMode=yes -i '($root)/host/client_key' -p ($ready.ssh) -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile='($root)/host/native_known_hosts'" with-env {GIT_SSH_COMMAND: $ssh_command} { native [clone $url $comparison] | ignore wasi $component $root [clone $url /clone] | ignore assert equal (open --raw ($clone | path join file.txt)) (open --raw ($comparison | path join file.txt)) assert equal (native [-C $clone show-ref] | get stdout) (native [-C $comparison show-ref] | get stdout) print 'SSH clone: contents and refs match native Git: PASS' $"fetch\n" | save --force ($seed | path join file.txt) native [-C $seed commit --no-gpg-sign -am fetch] | ignore native [-C $seed push $bare main] | ignore native [-C $comparison fetch] | ignore wasi $component $root [-C /clone fetch] | ignore assert equal (native [-C $clone show-ref] | get stdout) (native [-C $comparison show-ref] | get stdout) assert equal (native [-C $clone show origin/main:file.txt] | get stdout) $"fetch\n" print 'SSH fetch: contents and refs match native Git: PASS' wasi $component $root [-C /clone config user.name Agent] | ignore wasi $component $root [-C /clone config user.email agent@example.test] | ignore $"pushed\n" | save ($clone | path join pushed.txt) wasi $component $root [-C /clone add pushed.txt] | ignore wasi $component $root [-C /clone commit -m pushed] | ignore wasi $component $root [-C /clone push origin HEAD:wasi] | ignore native [-C $comparison fetch] | ignore assert equal (native [-C $bare rev-parse wasi] | get stdout) (native [-C $clone rev-parse HEAD] | get stdout) assert equal (native [-C $comparison show origin/wasi:pushed.txt] | get stdout) $"pushed\n" print 'SSH push: remote contents and refs match native Git: PASS' let scp = $'($ready.user)@127.0.0.1:($bare)' wasi $component $root [-C /clone remote add scp $scp] | ignore assert equal (wasi $component $root [-C /clone remote get-url scp] | get stdout | str trim) $scp print 'SCP-style remote URL: PASS' } print $'Fixture: ($root)' }