From 84c9907edc56956736ab090a81698dde27a0113a Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 22 Jun 2025 09:16:28 +1200 Subject: [PATCH] 'Generic Commit' --- getpkg/src/main.cpp | 9 +++++++++ getpkg/test.sh | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/getpkg/src/main.cpp b/getpkg/src/main.cpp index f17c335..670bef4 100644 --- a/getpkg/src/main.cpp +++ b/getpkg/src/main.cpp @@ -276,6 +276,15 @@ int publish_tool(int argc, char* argv[]) { // If no ARCH is provided (no colon in labeltag), append ":universal" for cross-platform tools if (labeltag.find(':') == std::string::npos) { labeltag += ":universal"; + } else { + // valid labels are tool_name:ARCH, where ARCH is x86_64 or aarch64 or universal + if (labeltag.find(':') != std::string::npos) { + std::string arch = labeltag.substr(labeltag.find(':') + 1); + if (arch != "x86_64" && arch != "aarch64" && arch != "universal") { + std::cerr << "Invalid architecture: " << arch << std::endl; + return 1; + } + } } std::string home = get_home(); std::filesystem::path archivePath = std::filesystem::path(home) / ".tmp" / (labeltag + ".tgz"); diff --git a/getpkg/test.sh b/getpkg/test.sh index 1174ecc..229fa0a 100755 --- a/getpkg/test.sh +++ b/getpkg/test.sh @@ -105,7 +105,7 @@ fi # Test 2: Help command echo -e "\nTest 2: Help command" HELP_OUTPUT=$(timeout 3 "$GETPKG" help 2>&1) || HELP_OUTPUT="" -if [[ "$HELP_OUTPUT" =~ "Usage: getpkg" ]]; then +if [[ "$HELP_OUTPUT" =~ Usage:\ getpkg ]]; then print_test_result "Help command output" 0 else print_test_result "Help command output" 1 @@ -114,7 +114,7 @@ fi # Test 3: Autocomplete command echo -e "\nTest 3: Autocomplete command" AUTOCOMPLETE_OUTPUT=$(timeout 3 "$GETPKG" autocomplete 2>&1) || AUTOCOMPLETE_OUTPUT="" -if [[ "$AUTOCOMPLETE_OUTPUT" =~ "install" ]] && [[ "$AUTOCOMPLETE_OUTPUT" =~ "publish" ]]; then +if [[ "$AUTOCOMPLETE_OUTPUT" =~ install ]] && [[ "$AUTOCOMPLETE_OUTPUT" =~ publish ]]; then print_test_result "Autocomplete command output" 0 else print_test_result "Autocomplete command output" 1 @@ -183,7 +183,7 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then echo "Publish command failed with no output. Checking for missing dependencies..." ldd "$GETPKG" 2>&1 | grep "not found" || echo "All dependencies found" fi - if [[ "$PUBLISH_OUTPUT" =~ "Published!" ]] && [[ "$PUBLISH_OUTPUT" =~ "URL:" ]] && [[ "$PUBLISH_OUTPUT" =~ "Hash:" ]]; then + if [[ "$PUBLISH_OUTPUT" =~ Published! ]] && [[ "$PUBLISH_OUTPUT" =~ URL: ]] && [[ "$PUBLISH_OUTPUT" =~ Hash: ]]; then print_test_result "Publish tool with ARCH to getpkg.xyz" 0 # Extract hash for later cleanup @@ -202,7 +202,7 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then # Test 8: Install command echo -e "\nTest 8: Install command" INSTALL_OUTPUT=$(timeout 3 "$GETPKG" install "$TEST_TOOL_NAME" 2>&1) || INSTALL_OUTPUT="" - if [[ "$INSTALL_OUTPUT" =~ "Installed ${TEST_TOOL_NAME} successfully" ]] || [[ "$INSTALL_OUTPUT" =~ "${TEST_TOOL_NAME} is already up to date" ]]; then + if [[ "$INSTALL_OUTPUT" =~ Installed\ ${TEST_TOOL_NAME}\ successfully ]] || [[ "$INSTALL_OUTPUT" =~ ${TEST_TOOL_NAME}\ is\ already\ up\ to\ date ]]; then print_test_result "Install tool from getpkg.xyz" 0 # Test 9: Check installed files @@ -228,7 +228,7 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then rm -f ~/.config/getpkg/"${TEST_TOOL_NAME}.json" DIRECT_INSTALL_OUTPUT=$(timeout 3 "$GETPKG" "$TEST_TOOL_NAME" 2>&1) || DIRECT_INSTALL_OUTPUT="" - if [[ "$DIRECT_INSTALL_OUTPUT" =~ "Installed ${TEST_TOOL_NAME} successfully" ]] || [[ "$DIRECT_INSTALL_OUTPUT" =~ "${TEST_TOOL_NAME} is already up to date" ]]; then + if [[ "$DIRECT_INSTALL_OUTPUT" =~ Installed\ ${TEST_TOOL_NAME}\ successfully ]] || [[ "$DIRECT_INSTALL_OUTPUT" =~ ${TEST_TOOL_NAME}\ is\ already\ up\ to\ date ]]; then print_test_result "Direct tool name install syntax" 0 else print_test_result "Direct tool name install syntax" 1 @@ -237,7 +237,7 @@ if [ -n "${SOS_WRITE_TOKEN:-}" ]; then # Test 12: Update already installed tool (should say up to date) echo -e "\nTest 12: Update check for installed tool" UPDATE_OUTPUT=$(timeout 3 "$GETPKG" install "$TEST_TOOL_NAME" 2>&1) || UPDATE_OUTPUT="" - if [[ "$UPDATE_OUTPUT" =~ "${TEST_TOOL_NAME} is already up to date" ]]; then + if [[ "$UPDATE_OUTPUT" =~ ${TEST_TOOL_NAME}\ is\ already\ up\ to\ date ]]; then print_test_result "Update check recognizes up-to-date tool" 0 else print_test_result "Update check recognizes up-to-date tool" 1 @@ -281,7 +281,7 @@ EOF chmod +x "${TEST_DIR}/${TEST_TOOL_NOARCH}/${TEST_TOOL_NOARCH}" PUBLISH_NOARCH_OUTPUT=$(timeout 3 "$GETPKG" publish "${TEST_TOOL_NOARCH}" "${TEST_DIR}/${TEST_TOOL_NOARCH}" 2>&1) || PUBLISH_NOARCH_OUTPUT="" - if [[ "$PUBLISH_NOARCH_OUTPUT" =~ "Published!" ]] && [[ "$PUBLISH_NOARCH_OUTPUT" =~ "URL:" ]] && [[ "$PUBLISH_NOARCH_OUTPUT" =~ "Hash:" ]]; then + if [[ "$PUBLISH_NOARCH_OUTPUT" =~ Published! ]] && [[ "$PUBLISH_NOARCH_OUTPUT" =~ URL: ]] && [[ "$PUBLISH_NOARCH_OUTPUT" =~ Hash: ]]; then print_test_result "Publish tool without ARCH" 0 # Clean up the noarch tool NOARCH_HASH=$(curl -s "https://getpkg.xyz/hash/${TEST_TOOL_NOARCH}" 2>/dev/null || echo "") @@ -297,12 +297,12 @@ EOF echo -e "\nTest 12c: Install universal tool (arch fallback)" rm -rf ~/.config/getpkg/"${TEST_TOOL_NOARCH}.json" ~/.local/bin/getpkg/"${TEST_TOOL_NOARCH}" 2>/dev/null || true FALLBACK_INSTALL_OUTPUT=$(timeout 3 "$GETPKG" install "${TEST_TOOL_NOARCH}" 2>&1) || FALLBACK_INSTALL_OUTPUT="" - if [[ "$FALLBACK_INSTALL_OUTPUT" =~ "Arch-specific version not found, trying universal version" ]] && [[ "$FALLBACK_INSTALL_OUTPUT" =~ "Installed ${TEST_TOOL_NOARCH} successfully" ]]; then + if [[ "$FALLBACK_INSTALL_OUTPUT" =~ Arch-specific\ version\ not\ found,\ trying\ universal\ version ]] && [[ "$FALLBACK_INSTALL_OUTPUT" =~ Installed\ ${TEST_TOOL_NOARCH}\ successfully ]]; then print_test_result "Install universal tool with arch fallback" 0 # Test update check for universal tool UPDATE_UNIVERSAL_OUTPUT=$(timeout 3 "$GETPKG" install "${TEST_TOOL_NOARCH}" 2>&1) || UPDATE_UNIVERSAL_OUTPUT="" - if [[ "$UPDATE_UNIVERSAL_OUTPUT" =~ "${TEST_TOOL_NOARCH} is already up to date" ]]; then + if [[ "$UPDATE_UNIVERSAL_OUTPUT" =~ ${TEST_TOOL_NOARCH}\ is\ already\ up\ to\ date ]]; then print_test_result "Update check for universal tool" 0 else print_test_result "Update check for universal tool" 1 @@ -322,17 +322,17 @@ INVALID_OUTPUT=$(timeout 3 "$GETPKG" install "../evil-tool" 2>&1) INVALID_EXIT_CODE=$? echo "Invalid tool output: $INVALID_OUTPUT" echo "Invalid tool exit code: $INVALID_EXIT_CODE" -if [[ "$INVALID_OUTPUT" =~ "Invalid tool name" ]]; then +if [[ "$INVALID_OUTPUT" =~ Invalid\ tool\ name ]]; then print_test_result "Invalid tool name rejection" 0 else print_test_result "Invalid tool name rejection" 1 fi # Test 14: Update command (if we have tools installed) -if [ -d ~/.config/getpkg ] && [ "$(ls -A ~/.config/getpkg/*.json 2>/dev/null | wc -l)" -gt 0 ]; then +if [ -d ~/.config/getpkg ] && [ "$(find ~/.config/getpkg -name "*.json" -type f 2>/dev/null | wc -l)" -gt 0 ]; then echo -e "\nTest 14: Update command" UPDATE_ALL_OUTPUT=$(timeout 3 "$GETPKG" update 2>&1) || UPDATE_ALL_OUTPUT="" - if [[ "$UPDATE_ALL_OUTPUT" =~ "Update complete" ]]; then + if [[ "$UPDATE_ALL_OUTPUT" =~ Update\ complete ]]; then print_test_result "Update all tools command" 0 else print_test_result "Update all tools command" 1