From 1b03087c02c7071cc7fcc7332bd51a19f015db02 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 20 Jul 2025 13:49:08 +1200 Subject: [PATCH] test: Update 13 files --- getpkg/README.md | 15 +++ getpkg/cleanup_test_packages.sh | 98 +++++++++++++++++++ getpkg/debug_test.txt | 1 - getpkg/temp_test.txt | 1 - getpkg/test-uninstall/test-uninstall | 7 -- .../test-uninstall-dir/test-uninstall | 7 -- getpkg/test.sh | 22 +++++ getpkg/test_debug/debug-test | 1 - getpkg/test_debug2/debug-test2 | 1 - getpkg/test_display/test-display | 1 - getpkg/test_multi/test-multi | 1 - getpkg/test_robust/test-robust | 1 - getpkg/test_upload.txt | 1 - gp/gp | 72 ++++++++++++-- test_gp_1752976117 | 1 + test_gp_deleted_files.sh | 49 ++++++++++ 16 files changed, 250 insertions(+), 29 deletions(-) create mode 100755 getpkg/cleanup_test_packages.sh delete mode 100644 getpkg/debug_test.txt delete mode 100644 getpkg/temp_test.txt delete mode 100755 getpkg/test-uninstall/test-uninstall delete mode 100755 getpkg/test-uninstall/test-uninstall-dir/test-uninstall delete mode 100755 getpkg/test_debug/debug-test delete mode 100755 getpkg/test_debug2/debug-test2 delete mode 100755 getpkg/test_display/test-display delete mode 100755 getpkg/test_multi/test-multi delete mode 100755 getpkg/test_robust/test-robust delete mode 100644 getpkg/test_upload.txt create mode 160000 test_gp_1752976117 create mode 100755 test_gp_deleted_files.sh diff --git a/getpkg/README.md b/getpkg/README.md index 2a4f084..82c655a 100644 --- a/getpkg/README.md +++ b/getpkg/README.md @@ -189,4 +189,19 @@ When creating tools for getpkg: 3. The tool should support `version` and `autocomplete` subcommands 4. Use `getpkg publish` to upload to the registry +### Testing + +The test script creates all temporary files and directories in `test_temp/` to keep the main directory clean: + +```bash +# Run tests +./test.sh + +# Clean up orphaned test files from old test runs (one-time) +bash cleanup_old_test_files.sh + +# Clean up orphaned test packages from getpkg.xyz +bash cleanup_test_packages.sh +``` + For more details, see the development documentation in each tool's directory. diff --git a/getpkg/cleanup_test_packages.sh b/getpkg/cleanup_test_packages.sh new file mode 100755 index 0000000..55f4e35 --- /dev/null +++ b/getpkg/cleanup_test_packages.sh @@ -0,0 +1,98 @@ +#!/bin/bash + +# Cleanup script for orphaned test packages from getpkg testing +# This script removes test packages that start with "test-" from getpkg.xyz +# Run from the getpkg directory: bash cleanup_test_packages.sh + +set -euo pipefail + +GETPKG="./output/getpkg" + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${YELLOW}Cleaning up orphaned test packages...${NC}" + +# Check if getpkg binary exists +if [ ! -f "$GETPKG" ]; then + echo -e "${RED}Error: getpkg binary not found at $GETPKG${NC}" + echo "Please run ./build.sh first to build getpkg" + exit 1 +fi + +# Check if SOS_WRITE_TOKEN is set +if [ -z "${SOS_WRITE_TOKEN:-}" ]; then + echo -e "${RED}Error: SOS_WRITE_TOKEN environment variable is not set${NC}" + echo "This token is required to unpublish packages from getpkg.xyz" + exit 1 +fi + +echo "Using getpkg binary: $GETPKG" +echo "SOS_WRITE_TOKEN is set (${#SOS_WRITE_TOKEN} characters)" + +# Get list of all packages from /dir endpoint +echo "Fetching package list from getpkg.xyz/dir..." +DIR_RESPONSE=$(curl -s "https://getpkg.xyz/dir" 2>/dev/null || echo "") + +if [ -z "$DIR_RESPONSE" ]; then + echo -e "${RED}Failed to fetch package list from server${NC}" + exit 1 +fi + +# Extract test package labeltags from JSON response +# Try with jq first, fallback to grep/sed if jq is not available +if command -v jq >/dev/null 2>&1; then + TEST_PACKAGES=$(echo "$DIR_RESPONSE" | jq -r '.entries[]?.labeltags[]? // empty' 2>/dev/null | grep "^test-" | sort -u || echo "") +else + # Fallback: extract labeltags using grep and sed (less reliable but works without jq) + TEST_PACKAGES=$(echo "$DIR_RESPONSE" | grep -o '"test-[^"]*"' | sed 's/"//g' | sort -u || echo "") +fi + +if [ -z "$TEST_PACKAGES" ]; then + echo -e "${GREEN}No test packages found to clean up${NC}" + exit 0 +fi + +echo -e "\n${YELLOW}Found test packages to clean up:${NC}" +echo "$TEST_PACKAGES" | while read -r package; do + echo " - $package" +done + +echo -e "\n${YELLOW}Cleaning up test packages...${NC}" + +CLEANED_COUNT=0 +FAILED_COUNT=0 + +# Use process substitution to avoid subshell issues +while IFS= read -r package; do + if [ -n "$package" ]; then + echo -n "Cleaning up $package... " + + # Try to unpublish the package (temporarily disable set -e) + set +e + $GETPKG unpublish "$package" >/dev/null 2>&1 + UNPUBLISH_RESULT=$? + set -e + + if [ $UNPUBLISH_RESULT -eq 0 ]; then + echo -e "${GREEN}OK${NC}" + ((CLEANED_COUNT++)) + else + echo -e "${RED}FAILED${NC}" + ((FAILED_COUNT++)) + fi + fi +done <<< "$TEST_PACKAGES" + +echo -e "\n${YELLOW}Cleanup Summary:${NC}" +echo "Packages cleaned: $CLEANED_COUNT" +echo "Failed cleanups: $FAILED_COUNT" + +if [ $FAILED_COUNT -eq 0 ]; then + echo -e "${GREEN}All test packages cleaned up successfully!${NC}" +else + echo -e "${YELLOW}Some packages failed to clean up. They may need manual removal.${NC}" +fi \ No newline at end of file diff --git a/getpkg/debug_test.txt b/getpkg/debug_test.txt deleted file mode 100644 index b373e77..0000000 --- a/getpkg/debug_test.txt +++ /dev/null @@ -1 +0,0 @@ -Debug content diff --git a/getpkg/temp_test.txt b/getpkg/temp_test.txt deleted file mode 100644 index 9daeafb..0000000 --- a/getpkg/temp_test.txt +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/getpkg/test-uninstall/test-uninstall b/getpkg/test-uninstall/test-uninstall deleted file mode 100755 index f48f6f1..0000000 --- a/getpkg/test-uninstall/test-uninstall +++ /dev/null @@ -1,7 +0,0 @@ -#\!/bin/bash -if [ "$1" = "version" ]; then - echo "1.0.0" -elif [ "$1" = "autocomplete" ]; then - echo "help" - echo "version" -fi diff --git a/getpkg/test-uninstall/test-uninstall-dir/test-uninstall b/getpkg/test-uninstall/test-uninstall-dir/test-uninstall deleted file mode 100755 index f48f6f1..0000000 --- a/getpkg/test-uninstall/test-uninstall-dir/test-uninstall +++ /dev/null @@ -1,7 +0,0 @@ -#\!/bin/bash -if [ "$1" = "version" ]; then - echo "1.0.0" -elif [ "$1" = "autocomplete" ]; then - echo "help" - echo "version" -fi diff --git a/getpkg/test.sh b/getpkg/test.sh index a455691..cb23399 100755 --- a/getpkg/test.sh +++ b/getpkg/test.sh @@ -68,6 +68,28 @@ cleanup() { # Clean up noarch variant $GETPKG unpublish "${TEST_TOOL_NAME}-noarch:universal" 2>/dev/null || true + # Clean up any remaining test packages that start with "test-" + echo "Cleaning up any remaining test packages..." + DIR_RESPONSE=$(curl -s "https://getpkg.xyz/dir" 2>/dev/null || echo "") + if [ -n "$DIR_RESPONSE" ]; then + # Extract test package labeltags from JSON response + if command -v jq >/dev/null 2>&1; then + TEST_PACKAGES=$(echo "$DIR_RESPONSE" | jq -r '.entries[]?.labeltags[]? // empty' 2>/dev/null | grep "^test-" | sort -u || echo "") + else + # Fallback: extract labeltags using grep and sed + TEST_PACKAGES=$(echo "$DIR_RESPONSE" | grep -o '"test-[^"]*"' | sed 's/"//g' | sort -u || echo "") + fi + + if [ -n "$TEST_PACKAGES" ]; then + echo "$TEST_PACKAGES" | while read -r package; do + if [ -n "$package" ]; then + echo " Cleaning up orphaned test package: $package" + $GETPKG unpublish "$package" 2>/dev/null || true + fi + done + fi + fi + echo "Cleaned up test tools from getpkg.xyz" else echo "Note: SOS_WRITE_TOKEN not set, cannot clean up remote test objects" diff --git a/getpkg/test_debug/debug-test b/getpkg/test_debug/debug-test deleted file mode 100755 index 25c92a3..0000000 --- a/getpkg/test_debug/debug-test +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash\necho debug diff --git a/getpkg/test_debug2/debug-test2 b/getpkg/test_debug2/debug-test2 deleted file mode 100755 index 6b478e2..0000000 --- a/getpkg/test_debug2/debug-test2 +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash\necho debug2 diff --git a/getpkg/test_display/test-display b/getpkg/test_display/test-display deleted file mode 100755 index d31b42e..0000000 --- a/getpkg/test_display/test-display +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash\necho display test diff --git a/getpkg/test_multi/test-multi b/getpkg/test_multi/test-multi deleted file mode 100755 index fa15ed5..0000000 --- a/getpkg/test_multi/test-multi +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash\necho multi arch diff --git a/getpkg/test_robust/test-robust b/getpkg/test_robust/test-robust deleted file mode 100755 index 8f679a0..0000000 --- a/getpkg/test_robust/test-robust +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash\necho robust test diff --git a/getpkg/test_upload.txt b/getpkg/test_upload.txt deleted file mode 100644 index d670460..0000000 --- a/getpkg/test_upload.txt +++ /dev/null @@ -1 +0,0 @@ -test content diff --git a/gp/gp b/gp/gp index 6d159aa..dccbe67 100755 --- a/gp/gp +++ b/gp/gp @@ -225,19 +225,77 @@ show_status_and_confirm() { # Show staged changes if ! git diff --cached --quiet; then - print_info "Staged changes:" - git diff --cached --name-only -- | while IFS= read -r line; do echo " $line"; done + local staged_modified="" + local staged_deleted="" + local staged_added="" + + # Get staged file status and categorize + while IFS=$'\t' read -r status file; do + [ -z "$status" ] && continue + case "${status:0:1}" in + A) staged_added="${staged_added}${file}\n" ;; + M) staged_modified="${staged_modified}${file}\n" ;; + D) staged_deleted="${staged_deleted}${file}\n" ;; + *) staged_modified="${staged_modified}${file}\n" ;; # Default to modified for other statuses + esac + done < <(git diff --cached --name-status) + + # Show staged added files + if [ -n "$staged_added" ]; then + print_info "Staged new files:" + echo -e "$staged_added" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done + fi + + # Show staged modified files + if [ -n "$staged_modified" ]; then + print_info "Staged modified files:" + echo -e "$staged_modified" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done + fi + + # Show staged deleted files + if [ -n "$staged_deleted" ]; then + print_info "Staged deleted files:" + echo -e "$staged_deleted" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done + fi + has_staged_changes=true fi # Show unstaged changes if ! git diff --quiet; then - if [ "$ADD_ALL" = true ]; then - print_info "Modified files (will be added):" - else - print_info "Modified files (unstaged, will NOT be included):" + local modified_files="" + local deleted_files="" + + # Get file status and categorize + while IFS=$'\t' read -r status file; do + [ -z "$status" ] && continue + case "${status:0:1}" in + M) modified_files="${modified_files}${file}\n" ;; + D) deleted_files="${deleted_files}${file}\n" ;; + *) modified_files="${modified_files}${file}\n" ;; # Default to modified for other statuses + esac + done < <(git diff --name-status) + + # Show modified files + if [ -n "$modified_files" ]; then + if [ "$ADD_ALL" = true ]; then + print_info "Modified files (will be added):" + else + print_info "Modified files (unstaged, will NOT be included):" + fi + echo -e "$modified_files" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done fi - git diff --name-only -- | while IFS= read -r line; do echo " $line"; done + + # Show deleted files + if [ -n "$deleted_files" ]; then + if [ "$ADD_ALL" = true ]; then + print_info "Deleted files (will be removed):" + else + print_info "Deleted files (unstaged, will NOT be included):" + fi + echo -e "$deleted_files" | grep -v '^$' | while IFS= read -r line; do echo " $line"; done + fi + has_unstaged_changes=true fi diff --git a/test_gp_1752976117 b/test_gp_1752976117 new file mode 160000 index 0000000..df17a83 --- /dev/null +++ b/test_gp_1752976117 @@ -0,0 +1 @@ +Subproject commit df17a838892e220803c784f8ea2313e8dc18b5ed diff --git a/test_gp_deleted_files.sh b/test_gp_deleted_files.sh new file mode 100755 index 0000000..7fbaa3c --- /dev/null +++ b/test_gp_deleted_files.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# Test script to verify gp properly shows deleted files as deleted + +set -euo pipefail + +echo "Testing gp deleted files functionality..." + +# Create a temporary test directory +TEST_DIR="test_gp_$(date +%s)" +mkdir "$TEST_DIR" +cd "$TEST_DIR" + +# Initialize git repo +git init +git config user.email "test@example.com" +git config user.name "Test User" + +# Create some test files +echo "content1" > file1.txt +echo "content2" > file2.txt +echo "content3" > file3.txt +mkdir test_dir +echo "test content" > test_dir/test_file.txt + +# Add and commit initial files +git add . +git commit -m "Initial commit" + +# Now delete some files to simulate the scenario +rm file2.txt +rm -rf test_dir +echo "modified content" > file1.txt +echo "new content" > new_file.txt + +# Test the gp script with dry-run to see the output +echo "" +echo "=== Testing gp --dry-run output ===" +echo "" + +# Run gp with dry-run to see how it categorizes the files +../gp/gp --dry-run + +# Cleanup +cd .. +rm -rf "$TEST_DIR" + +echo "" +echo "Test completed!" \ No newline at end of file