From 15b59dae4bb239ee8f89eae4ba7292b03daafa76 Mon Sep 17 00:00:00 2001 From: Shi Qi Date: Fri, 6 Nov 2026 10:59:42 -0800 Subject: [PATCH 1/2] test: isolate fixture commits from signing configuration --- tests/core_resolve_target.bats | 3 +- tests/fixture_signing.bats | 70 ++++++++++++++++++++++++++++++++++ tests/init.bats | 6 +-- tests/provider.bats | 2 +- tests/resolve_base_dir.bats | 2 +- tests/sparse.bats | 1 + tests/test_helper.bash | 2 + 7 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tests/fixture_signing.bats diff --git a/tests/core_resolve_target.bats b/tests/core_resolve_target.bats index 2b0356c..2e4b610 100644 --- a/tests/core_resolve_target.bats +++ b/tests/core_resolve_target.bats @@ -131,7 +131,8 @@ teardown() { local foreign="$TEST_WORKTREES_DIR/impostor" mkdir -p "$foreign" git -C "$foreign" init --quiet - git -C "$foreign" -c user.name=Test -c user.email=test@example.com commit --allow-empty -m init --quiet + git -C "$foreign" -c user.name=Test -c user.email=test@example.com -c commit.gpgsign=false \ + commit --allow-empty -m init --quiet git -C "$foreign" branch -m foreign-branch run resolve_target "impostor" "$TEST_REPO" "$TEST_WORKTREES_DIR" "" diff --git a/tests/fixture_signing.bats b/tests/fixture_signing.bats new file mode 100644 index 0000000..480746d --- /dev/null +++ b/tests/fixture_signing.bats @@ -0,0 +1,70 @@ +#!/usr/bin/env bats +# Fixture commits must not depend on a developer's signing key or agent. + +load test_helper + +setup() { + export GIT_CONFIG_NOSYSTEM=1 + export GIT_CONFIG_GLOBAL="$BATS_TEST_TMPDIR/global.gitconfig" + export FIXTURE_SIGNER_LOG="$BATS_TEST_TMPDIR/signer.log" + local signer="$BATS_TEST_TMPDIR/failing-signer" + cat > "$signer" <<'SCRIPT' +#!/usr/bin/env bash +printf 'invoked\n' >> "$FIXTURE_SIGNER_LOG" +exit 1 +SCRIPT + chmod +x "$signer" + git config --file "$GIT_CONFIG_GLOBAL" commit.gpgsign true + git config --file "$GIT_CONFIG_GLOBAL" gpg.format openpgp + git config --file "$GIT_CONFIG_GLOBAL" gpg.program "$signer" + git config --file "$GIT_CONFIG_GLOBAL" gpg.openpgp.program "$signer" + git config --file "$GIT_CONFIG_GLOBAL" user.signingkey fixture-only + git config --file "$GIT_CONFIG_GLOBAL" test.inherited preserved + cp "$GIT_CONFIG_GLOBAL" "$BATS_TEST_TMPDIR/global.before" +} + +teardown() { + if [ -n "${TEST_REPO:-}" ]; then + teardown_integration_repo + fi + cmp "$BATS_TEST_TMPDIR/global.before" "$GIT_CONFIG_GLOBAL" +} + +@test "signing control invokes only the harmless failing signer" { + local repo="$BATS_TEST_TMPDIR/control" + git init --quiet "$repo" + + run git -C "$repo" -c user.name=Test -c user.email=test@example.com \ + commit --allow-empty --quiet -m control + + [ "$status" -ne 0 ] + [ "$(cat "$FIXTURE_SIGNER_LOG")" = invoked ] + run git -C "$repo" rev-parse --verify HEAD + [ "$status" -ne 0 ] +} + +@test "integration fixture creates initial and subsequent commits without signing" { + setup_integration_repo + [ "$(git log -1 --format=%s)" = init ] + + git commit --allow-empty --quiet -m subsequent + + [ "$(git rev-list --count HEAD)" -eq 2 ] + [ "$(git log -1 --format=%s)" = subsequent ] + [ "$(git config --global --get commit.gpgsign)" = true ] + [ "$(git config --get test.inherited)" = preserved ] + [ ! -e "$FIXTURE_SIGNER_LOG" ] +} + +@test "linked fixture worktrees inherit unsigned commits" { + setup_integration_repo + source_gtr_libs + create_test_worktree fixture-branch + + git -C "$TEST_WT_PATH" commit --allow-empty --quiet -m linked + + [ "$(git -C "$TEST_WT_PATH" rev-list --count HEAD)" -eq 2 ] + [ "$(git -C "$TEST_WT_PATH" log -1 --format=%s)" = linked ] + [ "$(git rev-list --count HEAD)" -eq 1 ] + [ ! -e "$FIXTURE_SIGNER_LOG" ] +} diff --git a/tests/init.bats b/tests/init.bats index 6b28575..de17f82 100644 --- a/tests/init.bats +++ b/tests/init.bats @@ -125,7 +125,7 @@ trap cleanup EXIT git -C "$repo" init --quiet git -C "$repo" config user.name "Test User" git -C "$repo" config user.email "test@example.com" -git -C "$repo" commit --allow-empty -m "init" --quiet +git -C "$repo" -c commit.gpgsign=false commit --allow-empty -m "init" --quiet git -C "$repo" config --add gtr.hook.postCd 'echo first >> "$REPO_ROOT/order"' git -C "$repo" config --add gtr.hook.postCd 'cat' @@ -153,7 +153,7 @@ run_generated_fish_gtrconfig_post_cd_hooks() { git init --quiet "$repo" git -C "$repo" config user.name "Test User" git -C "$repo" config user.email "test@example.com" - git -C "$repo" commit --allow-empty -m "init" --quiet + git -C "$repo" -c commit.gpgsign=false commit --allow-empty -m "init" --quiet git -C "$repo" worktree add --quiet "$wt" -b feature cat > "$repo/.gtrconfig" <<'CFG' @@ -292,7 +292,7 @@ run_generated_v2_trust_upgrade() ( export XDG_CONFIG_HOME="$fixture/config" XDG_DATA_HOME="$fixture/data" git init --quiet "$REPO_FIXTURE" git -C "$REPO_FIXTURE" -c user.name=Fixture -c user.email=fixture@example.test \ - commit --allow-empty --quiet -m init + -c commit.gpgsign=false commit --allow-empty --quiet -m init git config -f "$REPO_FIXTURE/.gtrconfig" hooks.postCd 'sh "$REPO_ROOT/bootstrap.sh"' printf 'echo original > "$REPO_ROOT/hook-result"\n' > "$REPO_FIXTURE/bootstrap.sh" mark_pr207_commands_trusted "$REPO_FIXTURE/.gtrconfig" diff --git a/tests/provider.bats b/tests/provider.bats index 8f4ab24..a6dbc13 100644 --- a/tests/provider.bats +++ b/tests/provider.bats @@ -86,7 +86,7 @@ assert_gitlab_state() { git -C "$test_repo" init --quiet git -C "$test_repo" config user.name "Test User" git -C "$test_repo" config user.email "test@example.com" - git -C "$test_repo" commit --allow-empty -m init --quiet + git -C "$test_repo" -c commit.gpgsign=false commit --allow-empty -m init --quiet git -C "$test_repo" remote add upstream https://example.com/repo.git git -C "$test_repo" update-ref refs/remotes/upstream/main HEAD diff --git a/tests/resolve_base_dir.bats b/tests/resolve_base_dir.bats index 8a4fede..f3b4b6b 100644 --- a/tests/resolve_base_dir.bats +++ b/tests/resolve_base_dir.bats @@ -9,7 +9,7 @@ setup() { git -C "$TEST_REPO" init --quiet git -C "$TEST_REPO" config user.name "Test User" git -C "$TEST_REPO" config user.email "test@example.com" - git -C "$TEST_REPO" commit --allow-empty -m "init" --quiet + git -C "$TEST_REPO" -c commit.gpgsign=false commit --allow-empty -m "init" --quiet } teardown() { diff --git a/tests/sparse.bats b/tests/sparse.bats index 005e300..1c5f18c 100644 --- a/tests/sparse.bats +++ b/tests/sparse.bats @@ -13,6 +13,7 @@ setup() { git -C "$TEST_REPO" init --quiet git -C "$TEST_REPO" config user.name "Test User" git -C "$TEST_REPO" config user.email "test@example.com" + git -C "$TEST_REPO" config --local commit.gpgsign false mkdir -p "$TEST_REPO/apps/web" "$TEST_REPO/apps/api" "$TEST_REPO/packages" "$TEST_REPO/docs" # Git 2.25 sparse init needs a root file to avoid an empty initial checkout. echo root > "$TEST_REPO/README.md" diff --git a/tests/test_helper.bash b/tests/test_helper.bash index 1f7776d..1489782 100644 --- a/tests/test_helper.bash +++ b/tests/test_helper.bash @@ -30,6 +30,8 @@ setup_integration_repo() { git -C "$TEST_REPO" init --quiet git -C "$TEST_REPO" config user.name "Test User" git -C "$TEST_REPO" config user.email "test@example.com" + # Cover later fixture commits and linked worktrees as well as the initial commit. + git -C "$TEST_REPO" config --local commit.gpgsign false git -C "$TEST_REPO" commit --allow-empty -m "init" --quiet export GTR_DIR="$PROJECT_ROOT" cd "$TEST_REPO" || return 1 From 25f6aa96e09bc84fa95df852c5864540fe33c5bc Mon Sep 17 00:00:00 2001 From: Shi Qi Date: Fri, 6 Nov 2026 13:38:54 -0800 Subject: [PATCH 2/2] test: isolate signing regression on older Git --- tests/fixture_signing.bats | 8 +++++++- tests/init.bats | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/fixture_signing.bats b/tests/fixture_signing.bats index 480746d..5b7661f 100644 --- a/tests/fixture_signing.bats +++ b/tests/fixture_signing.bats @@ -3,9 +3,14 @@ load test_helper +# Isolate the test process's home and signer, including Git before 2.32. setup() { + local fixture_home="$BATS_TEST_TMPDIR/home" + mkdir -p "$fixture_home" export GIT_CONFIG_NOSYSTEM=1 - export GIT_CONFIG_GLOBAL="$BATS_TEST_TMPDIR/global.gitconfig" + export HOME="$fixture_home" + export XDG_CONFIG_HOME="$BATS_TEST_TMPDIR/xdg-config" + export GIT_CONFIG_GLOBAL="$fixture_home/.gitconfig" export FIXTURE_SIGNER_LOG="$BATS_TEST_TMPDIR/signer.log" local signer="$BATS_TEST_TMPDIR/failing-signer" cat > "$signer" <<'SCRIPT' @@ -23,6 +28,7 @@ SCRIPT cp "$GIT_CONFIG_GLOBAL" "$BATS_TEST_TMPDIR/global.before" } +# Remove disposable worktrees and verify that the signing config was preserved. teardown() { if [ -n "${TEST_REPO:-}" ]; then teardown_integration_repo diff --git a/tests/init.bats b/tests/init.bats index de17f82..5ce4794 100644 --- a/tests/init.bats +++ b/tests/init.bats @@ -100,6 +100,7 @@ run_generated_bash_cd_completion() ( [ ! -e completion-backtick-marker ] ) +# Run generated Bash/Zsh postCd hooks and report their execution order. run_generated_post_cd_hooks() { local shell_name="$1" @@ -140,6 +141,7 @@ printf '\n' SCRIPT } +# Exercise generated Fish hooks against a trusted or untrusted shared config. run_generated_fish_gtrconfig_post_cd_hooks() { local trust_state="$1" local root repo wt xdg init_file @@ -283,6 +285,7 @@ mark_pr207_commands_trusted() { printf '%s/.gtrconfig\n' "$repo_root" > "$XDG_CONFIG_HOME/gtr/trusted/$key" } +# Verify that generated shell helpers reject v2 trust and honor fresh approval. run_generated_v2_trust_upgrade() ( set -e local shell_name="$1" fixture