Files
sausage/userland/git/test.nu
T
surma 4b27e9afd5 userland/git: git-compatible CLI on v2's gix code (T10)
Local workflow, smart-HTTP clone/fetch/push and public HTTPS clone/fetch match
native git in stdout and exit codes. Only WASI imports (wasi:http, exit-with-code).
2026-11-06 16:07:57 +00:00

98 lines
4.7 KiB
Nu

#!/usr/bin/env nu
# Compare a deterministic agent workflow with native Git. Fail on every difference.
def main [component: path] {
let component = ($component | path expand)
let wit = (^wasm-tools component wit $component | complete)
if $wit.exit_code != 0 {error make {msg: $wit.stderr}}
let imports = ($wit.stdout | lines | str trim | where {|line| $line | str starts-with 'import '})
let forbidden = ($imports | where {|line| not ($line | str starts-with 'import wasi:')})
if ($imports | is-empty) or not ($forbidden | is-empty) {error make {msg: $'Unexpected component imports: ($imports)'}}
print 'Component imports: PASS (WASI only)'
print ($imports | str join (char newline))
let root = (mktemp -d -p /tmp/p1-git workflow.XXXXXX)
print $'Fixture: ($root)'
let envs = {GIT_AUTHOR_NAME: 'Agent', GIT_AUTHOR_EMAIL: 'agent@example.test', GIT_COMMITTER_NAME: 'Agent', GIT_COMMITTER_EMAIL: 'agent@example.test', GIT_AUTHOR_DATE: '1700000000 +0000', GIT_COMMITTER_DATE: '1700000000 +0000', GIT_CONFIG_NOSYSTEM: '1', GIT_EDITOR: 'true', HOME: '/tmp/p1-git/empty-home', LC_ALL: 'C', TZ: 'UTC'}
mkdir $envs.HOME
with-env $envs {
for side in [native wasi] { mkdir ($root | path join $side repo) }
let steps = [
{args: [init -b main], compare: false}
{args: [config user.name Agent], compare: true}
{args: [config user.email agent@example.test], compare: true}
{write: 'base\n', file: 'file.txt'}
{args: [add .], compare: true}
{args: [commit -m initial], compare: true}
{args: [status --short], compare: true}
{args: [status], compare: true}
{args: [log -n 1], compare: true}
{args: [show HEAD], compare: true}
{args: [show HEAD:file.txt], compare: true}
{args: [branch topic], compare: true}
{args: [switch topic], compare: true}
{write: 'topic\n', file: 'topic.txt'}
{args: [add .], compare: true}
{args: [commit -m topic], compare: true}
{args: [switch main], compare: true}
{args: [merge topic], compare: true}
{write: 'changed\n', file: 'file.txt'}
{args: [status --short], compare: true}
{args: [diff], compare: true}
{args: [diff --stat], compare: true}
{args: [status], compare: true}
{args: [commit -am changed], compare: true}
{args: [log --oneline], compare: true}
{args: [switch topic], compare: true}
{write: 'conflict\n', file: 'file.txt'}
{args: [commit -am conflict], compare: true}
{args: [switch main], compare: true}
{args: [merge topic], compare: true, exit: 1}
{args: [status --short], compare: true}
{args: [merge --abort], compare: true}
{args: [worktree add -b linked ../linked], compare: true}
{args: [worktree list], compare: false}
{args: [worktree remove ../linked], compare: true}
{args: [switch topic], compare: true}
{args: [rebase main], compare: true, exit: 1}
{write: 'resolved\n', file: 'file.txt'}
{args: [add file.txt], compare: true}
{args: [rebase --continue], compare: true}
{args: [log --oneline], compare: true}
{args: [switch main], compare: true}
{write: 'left\n', file: 'left.txt'}
{args: [add .], compare: true}
{args: [commit -m left], compare: true}
{args: [switch topic], compare: true}
{write: 'right\n', file: 'right.txt'}
{args: [add .], compare: true}
{args: [commit -m right], compare: true}
{args: [switch main], compare: true}
{args: [merge topic], compare: true}
{args: [branch], compare: true}
{args: [rm right.txt], compare: true}
{args: [diff --cached], compare: true}
{args: [status --porcelain], compare: true}
{args: [commit -m removed], compare: true}
{args: [status --bad-option], compare: true, exit: 129}
{args: [not-a-command], compare: true, exit: 1}
]
mut failures = 0
for step in $steps {
if 'write' in $step {
for side in [native wasi] { $step.write | str replace --all '\n' (char newline) | save --force ($root | path join $side repo $step.file) }
continue
}
let args = $step.args
let native = (^git -C ($root | path join native repo) ...$args | complete)
let wasi = (^wasmtime run -S http=y -S cli-exit-with-code=y --dir $'($root)/wasi::/' --env GIT_AUTHOR_NAME --env GIT_AUTHOR_EMAIL --env GIT_COMMITTER_NAME --env GIT_COMMITTER_EMAIL --env GIT_AUTHOR_DATE --env GIT_COMMITTER_DATE $component -C /repo ...$args | complete)
let expected = ($step.exit? | default 0)
let equal = ($native.exit_code == $expected and $wasi.exit_code == $expected and (not $step.compare or $native.stdout == $wasi.stdout))
print $'($args | str join " "): (if $equal {"PASS"} else {"FAIL"}) native=($native.exit_code) wasi=($wasi.exit_code)'
if not $equal {
$failures += 1
print ({native: $native, wasi: $wasi} | to json)
}
}
if $failures > 0 {error make {msg: $'($failures) workflow comparisons failed'}}
}
}