Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions scripts/test-homebrew.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -euo pipefail

# Test the Homebrew formula against a local build of deepwork
# Usage: ./scripts/test-homebrew.sh [path-to-homebrew-tap]

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
HOMEBREW_TAP="${1:-$REPO_DIR/../homebrew-deepwork}"

if [[ ! -f "$HOMEBREW_TAP/Formula/deepwork.rb" ]]; then
echo "Error: homebrew-deepwork tap not found at $HOMEBREW_TAP"
echo "Usage: $0 [path-to-homebrew-tap]"
exit 1
fi

echo "==> Building deepwork from $REPO_DIR"
cd "$REPO_DIR"
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script changes the working directory with cd "$REPO_DIR" but never restores it. If this script is sourced or called from another script expecting the current directory to be preserved, this could cause issues. While this is less critical for a standalone utility script, consider either documenting this behavior or saving and restoring the original directory at the end of the script.

Copilot uses AI. Check for mistakes.

# Clean previous builds
rm -rf dist/

# Build the sdist tarball
uv build --sdist
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script does not verify that the required dependencies (uv, brew, shasum, sed, awk) are installed before attempting to use them. While brew is likely to be present given the script's purpose, uv may not be installed. Consider adding dependency checks at the beginning of the script to provide clear error messages if required tools are missing, similar to how the script checks for the Homebrew tap directory.

Copilot uses AI. Check for mistakes.

# Find the built tarball
TARBALL=$(ls dist/deepwork-*.tar.gz | head -1)
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using ls with glob patterns in a pipeline can fail unexpectedly if no files match or if there are spaces in filenames. If the dist directory is empty or the tarball name has unexpected characters, this command could fail silently or produce incorrect results. Consider using a more robust approach like a find command or using array expansion with proper quoting.

Suggested change
TARBALL=$(ls dist/deepwork-*.tar.gz | head -1)
shopt -s nullglob
tarballs=(dist/deepwork-*.tar.gz)
shopt -u nullglob
TARBALL="${tarballs[0]:-}"

Copilot uses AI. Check for mistakes.
if [[ ! -f "$TARBALL" ]]; then
echo "Error: No tarball found in dist/"
exit 1
fi

VERSION=$(basename "$TARBALL" | sed 's/deepwork-\(.*\)\.tar\.gz/\1/')
SHA256=$(shasum -a 256 "$TARBALL" | awk '{print $1}')
TARBALL_PATH="$(cd "$(dirname "$TARBALL")" && pwd)/$(basename "$TARBALL")"

echo "==> Built deepwork-$VERSION"
echo " Tarball: $TARBALL_PATH"
echo " SHA256: $SHA256"

# Set up a local tap with the modified formula
TAP_NAME="local/deepwork-test"
TAP_DIR="$(brew --repository)/Library/Taps/local/homebrew-deepwork-test"

Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script does not clean up the temporary local tap created for testing. After the script completes (successfully or on error), the local tap local/deepwork-test will remain in the Homebrew installation directory. Consider adding a trap to ensure cleanup happens even if the script fails, similar to the pattern used in nix/claude-code/update.sh which uses trap "rm -rf $TMPDIR" EXIT. Add cleanup at the end or use a trap to remove the tap directory.

Suggested change
# Ensure the local test tap is cleaned up on exit, even on failure
trap 'brew untap "$TAP_NAME" >/dev/null 2>&1 || true; rm -rf "$TAP_DIR"' EXIT

Copilot uses AI. Check for mistakes.
echo "==> Setting up local tap..."
brew untap "$TAP_NAME" 2>/dev/null || true
brew tap-new --no-git "$TAP_NAME"

sed -e "s|url \"https://.*\"|url \"file://$TARBALL_PATH\"|" \
-e "s|sha256 \".*\"|sha256 \"$SHA256\"|" \
"$HOMEBREW_TAP/Formula/deepwork.rb" > "$TAP_DIR/Formula/deepwork.rb"
Comment on lines +49 to +51
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sed command uses unquoted variable substitution within the replacement pattern, which could be vulnerable to injection if the tarball path contains special sed metacharacters like &, /, or \. While this is low-risk since the path is constructed by the script itself, it's a best practice to escape variables used in sed patterns. Consider using a delimiter other than | in the sed command and properly escaping the variables, or use alternative tools like awk or perl for more robust text replacement.

Copilot uses AI. Check for mistakes.

echo "==> Installing from local build..."
brew uninstall deepwork 2>/dev/null || true
brew install --verbose "$TAP_NAME/deepwork"

echo "==> Running brew test..."
brew test "$TAP_NAME/deepwork"

echo "==> Verifying binary..."
deepwork --version
deepwork --help | head -5

echo "==> All tests passed for deepwork-$VERSION (local build)"