From bf01c170ee0a867f0cc576d964ab759f1050d5e7 Mon Sep 17 00:00:00 2001 From: Shane Jaroch Date: Fri, 16 Jan 2026 21:32:05 -0500 Subject: [PATCH] update tests --- Makefile | 12 +-- git-remote-gcrypt | 13 ++- tests/{test-gc.sh => broken-test-gc.sh} | 0 tests/coverage_report.py | 26 +++++- ...tions.sh => installer-test-completions.sh} | 0 ...stall-logic.sh => installer-test-logic.sh} | 0 ...em-install.sh => installer-test-verify.sh} | 0 tests/system-test-clean-cmd.sh | 84 ------------------- ...ommand.sh => system-test-clean-command.sh} | 16 ++-- ...-leaks.sh => system-test-privacy-leaks.sh} | 1 + ..._simple.sh => system-test-rsync-simple.sh} | 0 ...y-check.sh => system-test-safety-check.sh} | 0 12 files changed, 52 insertions(+), 100 deletions(-) rename tests/{test-gc.sh => broken-test-gc.sh} (100%) rename tests/{test-completions.sh => installer-test-completions.sh} (100%) rename tests/{test-install-logic.sh => installer-test-logic.sh} (100%) rename tests/{verify-system-install.sh => installer-test-verify.sh} (100%) delete mode 100644 tests/system-test-clean-cmd.sh rename tests/{test-clean-command.sh => system-test-clean-command.sh} (92%) rename tests/{test-privacy-leaks.sh => system-test-privacy-leaks.sh} (99%) rename tests/{test_rsync_simple.sh => system-test-rsync-simple.sh} (100%) rename tests/{test-safety-check.sh => system-test-safety-check.sh} (100%) diff --git a/Makefile b/Makefile index 230644d..0ba4d0a 100644 --- a/Makefile +++ b/Makefile @@ -110,11 +110,13 @@ test/installer: ##H Test installer logic @rm -rf $(COV_INSTALL) @mkdir -p $(COV_INSTALL) @export COV_DIR=$(COV_INSTALL); \ - kcov --bash-dont-parse-binary-dir \ - --include-pattern=install.sh \ - --exclude-path=$(PWD)/.git,$(PWD)/tests \ - $(COV_INSTALL) \ - ./tests/test-install-logic.sh 2>&1 | tee .tmp/kcov.log; \ + for test_script in tests/installer-test*.sh; do \ + kcov --bash-dont-parse-binary-dir \ + --include-pattern=install.sh \ + --exclude-path=$(PWD)/.git,$(PWD)/tests \ + $(COV_INSTALL) \ + "$$test_script" 2>&1 | tee -a .tmp/kcov.log; \ + done; \ if grep -q 'kcov: error:' .tmp/kcov.log; then \ echo "FAIL: kcov errors detected (see above)"; exit 1; \ fi diff --git a/git-remote-gcrypt b/git-remote-gcrypt index 9490aeb..91e526b 100755 --- a/git-remote-gcrypt +++ b/git-remote-gcrypt @@ -792,7 +792,9 @@ early_safety_check() return 0 fi - if [ "$(git config --bool gcrypt.allow-unencrypted-remote)" = "true" ]; then + + if [ "$(git config --bool remote."$NAME".gcrypt-allow-unencrypted-remote)" = "true" ] || \ + [ "$(git config --bool gcrypt.allow-unencrypted-remote)" = "true" ]; then return 0 fi @@ -823,7 +825,9 @@ early_safety_check() return 0 fi - if [ "$(git config --bool gcrypt.allow-unencrypted-remote)" = "true" ]; then + + if [ "$(git config --bool remote."$NAME".gcrypt-allow-unencrypted-remote)" = "true" ] || \ + [ "$(git config --bool gcrypt.allow-unencrypted-remote)" = "true" ]; then return 0 fi @@ -1153,9 +1157,10 @@ check_safety() if [ "$(line_count "$bad_files")" -gt 5 ]; then echo_info " ... (and others)" fi - + # Check config to see if we should ignore - if [ "$(git config --bool gcrypt.allow-unencrypted-remote)" = "true" ]; then + if [ "$(git config --bool remote."$NAME".gcrypt-allow-unencrypted-remote)" = "true" ] || \ + [ "$(git config --bool gcrypt.allow-unencrypted-remote)" = "true" ]; then echo_info "WARNING: Proceeding because gcrypt.allow-unencrypted-remote is set." return 0 fi diff --git a/tests/test-gc.sh b/tests/broken-test-gc.sh similarity index 100% rename from tests/test-gc.sh rename to tests/broken-test-gc.sh diff --git a/tests/coverage_report.py b/tests/coverage_report.py index 0dc8978..3a0234b 100644 --- a/tests/coverage_report.py +++ b/tests/coverage_report.py @@ -51,11 +51,33 @@ else: if missed: - missed.sort(key=int) # Sort for deterministic output + missed.sort(key=int) + # Group consecutive lines + ranges = [] + if missed: + start = int(missed[0]) + prev = start + for x in missed[1:]: + curr = int(x) + if curr == prev + 1: + prev = curr + else: + if start == prev: + ranges.append(str(start)) + else: + ranges.append(f"{start}-{prev}") + start = curr + prev = curr + # Append the last range + if start == prev: + ranges.append(str(start)) + else: + ranges.append(f"{start}-{prev}") + print(f"\033[31;1m{len(missed)} missing lines\033[0m in {patt}:") print( textwrap.fill( - ", ".join(missed), width=72, initial_indent=" ", subsequent_indent=" " + ", ".join(ranges), width=72, initial_indent=" ", subsequent_indent=" " ) ) diff --git a/tests/test-completions.sh b/tests/installer-test-completions.sh similarity index 100% rename from tests/test-completions.sh rename to tests/installer-test-completions.sh diff --git a/tests/test-install-logic.sh b/tests/installer-test-logic.sh similarity index 100% rename from tests/test-install-logic.sh rename to tests/installer-test-logic.sh diff --git a/tests/verify-system-install.sh b/tests/installer-test-verify.sh similarity index 100% rename from tests/verify-system-install.sh rename to tests/installer-test-verify.sh diff --git a/tests/system-test-clean-cmd.sh b/tests/system-test-clean-cmd.sh deleted file mode 100644 index 930bd3e..0000000 --- a/tests/system-test-clean-cmd.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash -# tests/test-clean-complex.sh -# Verifies clean command on filenames with spaces and parentheses. - -TEST_DIR=$(dirname "$0") -BIN="$TEST_DIR/../git-remote-gcrypt" -git_remote_gcrypt() { - bash "$BIN" "$@" -} - -# Setup temp environment -TMPDIR=$(mktemp -d) -trap 'rm -rf "$TMPDIR"' EXIT - -# Create a "remote" bare repo to simulate git backend -REMOTE_REPO="$TMPDIR/remote.git" -git init --bare "$REMOTE_REPO" >/dev/null - -# Create a commit in the remote with "garbage" files -# We need to simulate how git-remote-gcrypt stores files (in refs/gcrypt/...) -# or just in master if it's a raw repo being cleaned? -# If we run clean --init, we are cleaning a raw repo. So files are in HEAD (or master/main). - -# Helper to create commit -( - cd "$TMPDIR" || exit 1 - mkdir worktree - cd worktree || exit 1 - git init >/dev/null - git remote add origin "$REMOTE_REPO" - - # Create files with spaces and parens - mkdir -p ".csv" - touch ".csv/sheet-shanes-secondary-sheets-Univ Grades (OU).csv" - touch "normal.txt" - - git add . - git commit -m "Initial commit with garbage" >/dev/null - git push origin master >/dev/null -) - -URL="file://$REMOTE_REPO" - -echo "--- Status before clean ---" -# We can use git ls-tree on remote to verify -git --git-dir="$REMOTE_REPO" ls-tree -r master --name-only - -echo "--- Running clean --init --force ---" -OUTPUT=$(git_remote_gcrypt clean --init --force "$URL" 2>&1) -EXIT_CODE=$? -echo "$OUTPUT" - -if [ $EXIT_CODE -ne 0 ]; then - echo "FAIL: clean command failed." - exit 1 -fi - -echo "--- Status after clean ---" -FILES=$(git --git-dir="$REMOTE_REPO" ls-tree -r master --name-only) -echo "$FILES" - -if [[ $FILES == *".csv"* ]]; then - # We expect the file to be GONE. - # Note: clean --init --force deletes ALL files (because map is not found) - # So if there are ANY files left, it's a fail. - # But clean command actually updates the refs (typically master or refs/gcrypt/...). - # Wait, git-remote-gcrypt clean cleans "refs/heads/master" or "refs/heads/main" if mapped? - # No, it checks what files are there. - # If standard remote, it might be cleaning HEAD? - - # Let's check if the file persists. - if echo "$FILES" | grep -q "Univ Grades"; then - echo "FAIL: The complex filename was NOT removed." - exit 1 - fi -fi - -if [ -z "$FILES" ]; then - echo "PASS: All files removed." -else - # It might leave an empty tree or commit? - echo "FAIL: Files persist: $FILES" - exit 1 -fi diff --git a/tests/test-clean-command.sh b/tests/system-test-clean-command.sh similarity index 92% rename from tests/test-clean-command.sh rename to tests/system-test-clean-command.sh index 84de92b..7b486de 100755 --- a/tests/test-clean-command.sh +++ b/tests/system-test-clean-command.sh @@ -22,6 +22,7 @@ export PATH="$SCRIPT_DIR:$PATH" # Isolate git config from user environment export GIT_CONFIG_SYSTEM=/dev/null export GIT_CONFIG_GLOBAL=/dev/null +unset GIT_CONFIG_PARAMETERS # Suppress git advice messages # Note: git-remote-gcrypt reads actual config files, not just CLI -c options @@ -84,11 +85,13 @@ mkdir -p "$tempdir/subdir" echo "NESTED=123" >"$tempdir/subdir/nested.txt" echo "SPACE=789" >"$tempdir/Has Space.txt" +echo "PARENS=ABC" >"$tempdir/Has (Parens).txt" BLOB1=$($GIT hash-object -w "$tempdir/secret1.txt") BLOB2=$($GIT hash-object -w "$tempdir/secret2.txt") BLOB3=$($GIT hash-object -w "$tempdir/subdir/nested.txt") BLOB4=$($GIT hash-object -w "$tempdir/Has Space.txt") +BLOB5=$($GIT hash-object -w "$tempdir/Has (Parens).txt") # Create root tree using index export GIT_INDEX_FILE=index.dirty @@ -96,6 +99,7 @@ $GIT update-index --add --cacheinfo 100644 "$BLOB1" "secret1.txt" $GIT update-index --add --cacheinfo 100644 "$BLOB2" "secret2.txt" $GIT update-index --add --cacheinfo 100644 "$BLOB3" "subdir/nested.txt" $GIT update-index --add --cacheinfo 100644 "$BLOB4" "Has Space.txt" +$GIT update-index --add --cacheinfo 100644 "$BLOB5" "Has (Parens).txt" TREE=$($GIT write-tree) rm index.dirty @@ -129,10 +133,10 @@ assert_grep "Usage: git-remote-gcrypt clean" "$output" "clean shows usage when n # -------------------------------------------------- # Test 2: Safety Check (Abort on non-gcrypt) # -------------------------------------------------- -print_info "Test 2: Safety Check (Abort on non-gcrypt)..." +print_info "Test 2: Safety Check (Abort on non-gcrypt --force)..." cd "$tempdir/remote.git" -output=$("$SCRIPT_DIR/git-remote-gcrypt" clean "$tempdir/remote.git" 2>&1 || :) -assert_grep "Error: No gcrypt manifest found" "$output" "clean aborts on non-gcrypt repo" +output=$("$SCRIPT_DIR/git-remote-gcrypt" clean --force "$tempdir/remote.git" 2>&1 || :) +assert_grep "Error: No gcrypt manifest found" "$output" "clean --force aborts on non-gcrypt repo" if $GIT ls-tree HEAD | grep -q "secret1.txt"; then print_success "Files preserved (Safety check passed)" @@ -249,9 +253,10 @@ print_info "Test 7: clean --init (Bypass manifest check)..." # Reuse the dirty remote from earlier ($tempdir/remote.git) which has secret1.txt and secret2.txt -# 1. Standard clean should fail (as tested in Test 2) +# 2. Standard clean should warn and list files (dry-run) output=$("$SCRIPT_DIR/git-remote-gcrypt" clean "gcrypt::$tempdir/remote.git" 2>&1 || :) -assert_grep "Error: No gcrypt manifest found" "$output" "standard clean fails on dirty remote" +assert_grep "WARNING: No gcrypt manifest found" "$output" "clean warns on dirty remote" +assert_grep "Listing all files as potential garbage" "$output" "clean lists files on dirty remote" # 2. Clean with --init should succeed (scan only) output=$("$SCRIPT_DIR/git-remote-gcrypt" clean --init "gcrypt::$tempdir/remote.git" 2>&1 || :) @@ -260,6 +265,7 @@ assert_grep "Found the following files to remove" "$output" "--init scan found f assert_grep "secret1.txt" "$output" "--init found secret1.txt" assert_grep "subdir/nested.txt" "$output" "--init found nested file in subdir" assert_grep "Has Space.txt" "$output" "--init found file with spaces" +assert_grep "Has (Parens).txt" "$output" "--init found file with parens" # 3. Clean with --init --force should remove files "$SCRIPT_DIR/git-remote-gcrypt" clean --init --force "gcrypt::$tempdir/remote.git" >/dev/null 2>&1 diff --git a/tests/test-privacy-leaks.sh b/tests/system-test-privacy-leaks.sh similarity index 99% rename from tests/test-privacy-leaks.sh rename to tests/system-test-privacy-leaks.sh index 9fce029..1d79295 100755 --- a/tests/test-privacy-leaks.sh +++ b/tests/system-test-privacy-leaks.sh @@ -48,6 +48,7 @@ gpg --batch --generate-key "${tempdir}/key_params" >/dev/null 2>&1 # Git config export GIT_CONFIG_SYSTEM=/dev/null export GIT_CONFIG_GLOBAL="${tempdir}/gitconfig" +unset GIT_CONFIG_PARAMETERS git config --global user.name "Test User" git config --global user.email "test@example.com" git config --global init.defaultBranch "master" diff --git a/tests/test_rsync_simple.sh b/tests/system-test-rsync-simple.sh similarity index 100% rename from tests/test_rsync_simple.sh rename to tests/system-test-rsync-simple.sh diff --git a/tests/test-safety-check.sh b/tests/system-test-safety-check.sh similarity index 100% rename from tests/test-safety-check.sh rename to tests/system-test-safety-check.sh -- 2.52.0