mirror of
https://github.com/boshu2/agentops.git
synced 2026-09-14 15:08:13 +08:00
566f7bd69f
P2 agentops-core fix. 15 script-test bats files re-derive the same fixture boilerplate (mktemp, git init + identity, bin-stubbing) → setup-drift bugs. Centralized. - lib/bats-common.bash (NEW): bats_repo_root, bats_init_repo, bats_stub_bin — functions only, no top-level shell opts - tests/scripts/bats-common.bats (NEW): 5 self-tests - verified-rebase.bats: refactored to use the lib (proof-of-adoption) Bounded: lib + self-test + 1 adoption. Broader adoption (~14 files) is incremental follow-up. How tested: shellcheck clean; bats 5/5 + 4/4 under CI-like env (EDITOR unset). Caught + fixed the worktree-.git-is-a-file gotcha locally. NOTE: claude-review infra-red (weekly limit, resets May 25) — operator-authorized bypass when sole red. Closes-scenario: soc-jhq6#bats-common-helpers Bounded-context: BC5-Runtime Evidence: lib/bats-common.bash
47 lines
1.2 KiB
Bash
47 lines
1.2 KiB
Bash
#!/usr/bin/env bats
|
|
# Self-test for lib/bats-common.bash (soc-jhq6) — the shared bats fixture helpers.
|
|
|
|
setup() {
|
|
source "$(git rev-parse --show-toplevel)/lib/bats-common.bash"
|
|
TMP="$(mktemp -d)"
|
|
}
|
|
|
|
teardown() { rm -rf "$TMP"; }
|
|
|
|
@test "bats_repo_root returns the git toplevel directory" {
|
|
run bats_repo_root
|
|
[ "$status" -eq 0 ]
|
|
[ -d "$output" ]
|
|
# .git is a dir in a normal checkout, a file in a worktree — -e matches both.
|
|
[ -e "$output/.git" ]
|
|
}
|
|
|
|
@test "bats_init_repo makes a committable repo with an identity" {
|
|
bats_init_repo "$TMP"
|
|
[ "$PWD" = "$TMP" ]
|
|
[ -d "$TMP/.git" ]
|
|
[ "$(git config user.email)" = "bats@test.local" ]
|
|
echo x > f && git add f
|
|
run git commit -qm "commit works without prompting"
|
|
[ "$status" -eq 0 ]
|
|
}
|
|
|
|
@test "bats_init_repo fails clearly on a missing dir arg" {
|
|
run bats_init_repo
|
|
[ "$status" -ne 0 ]
|
|
}
|
|
|
|
@test "bats_stub_bin creates an executable stub that runs" {
|
|
bats_stub_bin "$TMP/bin" faketool 'echo stubbed-output; exit 0'
|
|
[ -x "$TMP/bin/faketool" ]
|
|
run "$TMP/bin/faketool"
|
|
[ "$status" -eq 0 ]
|
|
[ "$output" = "stubbed-output" ]
|
|
}
|
|
|
|
@test "bats_stub_bin honors a non-zero exit body" {
|
|
bats_stub_bin "$TMP/bin" failtool 'exit 3'
|
|
run "$TMP/bin/failtool"
|
|
[ "$status" -eq 3 ]
|
|
}
|