Files
sausage/userland/git/http-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

53 lines
2.7 KiB
Nu

#!/usr/bin/env nu
# The HTTP server serves server-root through native git http-backend.
use std/assert
def main [component: path, server_root: path, url: string] {
let component = ($component | path expand)
let server_root = ($server_root | path expand)
let fixture = (mktemp -d -p /tmp/p1-git https.XXXXXX)
let seed = ($fixture | path join seed)
mkdir $seed
let envs = {HOME: '/tmp/p1-git/empty-home', GIT_CONFIG_NOSYSTEM: '1', 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'}
with-env $envs {
run-native [init -b main $seed]
run-native [-C $seed config user.name Agent]
run-native [-C $seed config user.email agent@example.test]
'base' | save ($seed | path join file)
run-native [-C $seed add .]
run-native [-C $seed commit -m base]
let remote = ($server_root | path join ($url | url parse | get path | path basename))
run-native [clone --bare $seed $remote]
run-native [-C $remote config http.receivepack 'true']
wasi $component $fixture [clone $url /clone]
wasi $component $fixture [-C /clone config user.name Agent]
wasi $component $fixture [-C /clone config user.email agent@example.test]
let clone = ($fixture | path join clone)
assert ((open --raw ($clone | path join file)) == 'base')
'native' | save --force ($seed | path join file)
run-native [-C $seed commit -am native]
run-native [-C $seed push $remote main]
wasi $component $fixture [-C /clone fetch]
let expected = (^git -C $remote rev-parse main | str trim)
let actual = (^git -C $clone rev-parse origin/main | str trim)
assert ($expected == $actual)
wasi $component $fixture [-C /clone merge origin/main]
'guest' | save --force ($clone | path join guest)
wasi $component $fixture [-C /clone add .]
wasi $component $fixture [-C /clone commit -m guest]
wasi $component $fixture [-C /clone push origin main]
let expected = (^git -C $clone rev-parse HEAD | str trim)
let actual = (^git -C $remote rev-parse main | str trim)
assert ($expected == $actual)
print 'Local smart-HTTP clone, fetch, and push: PASS'
print $'Fixture: ($fixture)'
}
}
def run-native [args: list<string>] {
let result = (^git ...$args | complete)
if $result.exit_code != 0 {error make {msg: ($result | to json)}}
}
def wasi [component: path, fixture: path, args: list<string>] {
let result = (^wasmtime run -S http=y -S cli-exit-with-code=y --dir $'($fixture)::/' --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 ...$args | complete)
if $result.exit_code != 0 {error make {msg: ($result | to json)}}
}