From d8452fbbfa6b859962ceb92fbb80315a5d162f35 Mon Sep 17 00:00:00 2001 From: fengelhardt Date: Sat, 27 Dec 2025 20:59:10 -0800 Subject: [PATCH 1/7] Add depot-tools meant for chromium development --- configs/android.yaml | 1 + configs/backend.yaml | 1 + configs/everything.yaml | 1 + configs/example-config.yaml | 1 + configs/ios.yaml | 1 + configs/macos.yaml | 1 + configs/minimal.yaml | 1 + configs/react-native.yaml | 1 + configs/web.yaml | 1 + osa-cli.zsh | 7 +++-- src/setup/install-cmake.zsh | 3 ++ src/setup/install-depot-tools.zsh | 47 +++++++++++++++++++++++++++++ src/setup/install-tree.zsh | 3 ++ src/zsh/plugin-init/depot-tools.zsh | 18 +++++++++++ src/zsh/snippets | 1 - 15 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/setup/install-cmake.zsh create mode 100644 src/setup/install-depot-tools.zsh create mode 100644 src/setup/install-tree.zsh create mode 100644 src/zsh/plugin-init/depot-tools.zsh delete mode 120000 src/zsh/snippets diff --git a/configs/android.yaml b/configs/android.yaml index b6a469a..00a7a18 100644 --- a/configs/android.yaml +++ b/configs/android.yaml @@ -14,6 +14,7 @@ components: mise: true git: true cocoapods: false # Not needed for Android + depot_tools: false # Snippets runtime flags android: true # Android development tools diff --git a/configs/backend.yaml b/configs/backend.yaml index eb8eaf8..6925e8e 100644 --- a/configs/backend.yaml +++ b/configs/backend.yaml @@ -14,6 +14,7 @@ components: mise: true git: true cocoapods: false + depot_tools: false # Snippets runtime flags android: false diff --git a/configs/everything.yaml b/configs/everything.yaml index c4927de..e3b91a7 100644 --- a/configs/everything.yaml +++ b/configs/everything.yaml @@ -14,6 +14,7 @@ components: mise: true git: true cocoapods: true # iOS and React Native + depot_tools: true # All snippets runtime flags enabled android: true diff --git a/configs/example-config.yaml b/configs/example-config.yaml index a5165fd..137088c 100644 --- a/configs/example-config.yaml +++ b/configs/example-config.yaml @@ -14,6 +14,7 @@ components: mise: true git: true cocoapods: false + depot_tools: false # Snippets runtime flags android: false diff --git a/configs/ios.yaml b/configs/ios.yaml index 35612e8..7a4e6e7 100644 --- a/configs/ios.yaml +++ b/configs/ios.yaml @@ -14,6 +14,7 @@ components: mise: true git: true cocoapods: true # Required for iOS development + depot_tools: false # Snippets runtime flags android: false diff --git a/configs/macos.yaml b/configs/macos.yaml index bac6111..b94e511 100644 --- a/configs/macos.yaml +++ b/configs/macos.yaml @@ -14,6 +14,7 @@ components: mise: true git: true cocoapods: false # Not needed for general macOS dev + depot_tools: false # Snippets runtime flags android: false diff --git a/configs/minimal.yaml b/configs/minimal.yaml index 55f3076..cae588e 100644 --- a/configs/minimal.yaml +++ b/configs/minimal.yaml @@ -14,6 +14,7 @@ components: mise: false git: false cocoapods: false + depot_tools: false # Snippets runtime flags (control what loads from entry.zsh) android: false diff --git a/configs/react-native.yaml b/configs/react-native.yaml index 44f0de1..f75270c 100644 --- a/configs/react-native.yaml +++ b/configs/react-native.yaml @@ -14,6 +14,7 @@ components: mise: true git: true cocoapods: true # Required for React Native iOS + depot_tools: false # Snippets runtime flags android: true # React Native Android support diff --git a/configs/web.yaml b/configs/web.yaml index a8ffdca..4f9d905 100644 --- a/configs/web.yaml +++ b/configs/web.yaml @@ -14,6 +14,7 @@ components: mise: true git: true cocoapods: false + depot_tools: false # Snippets runtime flags android: false diff --git a/osa-cli.zsh b/osa-cli.zsh index 1b57c9e..3f7dd8f 100755 --- a/osa-cli.zsh +++ b/osa-cli.zsh @@ -208,7 +208,7 @@ load_json_config() { # For backward compatibility during installation, also set OSA_SETUP_* variables # These are used by run_component() to determine what to install - local -a component_keys=(symlinks oh_my_zsh zsh_plugins homebrew mise osa_snippets git android iterm2 vscode cocoapods) + local -a component_keys=(symlinks oh_my_zsh zsh_plugins homebrew mise osa_snippets git android iterm2 vscode cocoapods depot_tools) for key in "${component_keys[@]}"; do local enabled=$(yq eval ".components.${key} // false" "$resolved_path" 2>/dev/null) @@ -356,6 +356,7 @@ init_components() { # Development tools with install scripts register_component "git" "Configure Git (version control)" "all" "src/setup/git.zsh" register_component "cocoapods" "Install CocoaPods for iOS development" "macos" "src/setup/install-cocoapods.zsh" + register_component "depot-tools" "Install depot_tools (Chromium development utilities)" "all" "src/setup/install-depot-tools.zsh" } # Check if component is available for current platform @@ -435,7 +436,7 @@ save_config() { # If no OSA_CONFIG_* variables exist (interactive mode), convert OSA_SETUP_* to OSA_CONFIG_* if [[ -z "$(echo $all_vars | grep '^OSA_CONFIG_')" ]]; then # Convert OSA_SETUP_* component flags to OSA_CONFIG_COMPONENTS_* - local -a component_keys=(symlinks homebrew oh_my_zsh zsh_plugins mise osa_snippets git android iterm2 vscode cocoapods) + local -a component_keys=(symlinks homebrew oh_my_zsh zsh_plugins mise osa_snippets git android iterm2 vscode cocoapods depot_tools) for key in "${component_keys[@]}"; do local var_name="OSA_SETUP_$(echo $key | tr a-z A-Z | tr '-' '_')" local value="${(P)var_name}" @@ -708,7 +709,7 @@ validate_config() { # Show enabled components echo -e "${COLOR_BOLD}Setup Components (to be installed):${COLOR_RESET}" - local -a component_keys=(symlinks oh_my_zsh zsh_plugins homebrew mise osa_snippets git cocoapods) + local -a component_keys=(symlinks oh_my_zsh zsh_plugins homebrew mise osa_snippets git cocoapods depot_tools) for key in "${component_keys[@]}"; do local enabled=$(yq eval ".components.${key} // false" "$resolved_path" 2>/dev/null) if [[ "$enabled" == "true" ]]; then diff --git a/src/setup/install-cmake.zsh b/src/setup/install-cmake.zsh new file mode 100644 index 0000000..e07540a --- /dev/null +++ b/src/setup/install-cmake.zsh @@ -0,0 +1,3 @@ +# Install cmake for building C/C++ projects +echo "Installing cmake " +brew install cmake \ No newline at end of file diff --git a/src/setup/install-depot-tools.zsh b/src/setup/install-depot-tools.zsh new file mode 100644 index 0000000..a6f3361 --- /dev/null +++ b/src/setup/install-depot-tools.zsh @@ -0,0 +1,47 @@ +#!/usr/bin/env zsh +# Install/update depot_tools - Chromium development utilities +# https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html + +echo "Installing depot_tools (Chromium development utilities)..." + +# Configuration +DEPOT_TOOLS_REPO="${DEPOT_TOOLS_REPO:-https://chromium.googlesource.com/chromium/tools/depot_tools.git}" +DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$HOME/.depot_tools}" + +# Create parent directory if needed +mkdir -p "$(dirname "$DEPOT_TOOLS_DIR")" + +# Check if depot_tools is already installed +if [[ -d "$DEPOT_TOOLS_DIR/.git" ]]; then + echo "Updating depot_tools..." + cd "$DEPOT_TOOLS_DIR" + if ! git pull --rebase; then + echo "✗ Failed to update depot_tools via git pull" + return 1 + fi + cd - > /dev/null +else + # Clone depot_tools if not already present + echo "Cloning depot_tools from $DEPOT_TOOLS_REPO..." + + if ! git clone "$DEPOT_TOOLS_REPO" "$DEPOT_TOOLS_DIR"; then + echo "✗ Failed to clone depot_tools from $DEPOT_TOOLS_REPO" + echo "Ensure git is installed and you have internet access" + return 1 + fi +fi + +# Add depot_tools to PATH via shell configuration +# This should be sourced during shell initialization +export PATH="$DEPOT_TOOLS_DIR:$PATH" + +echo "✓ depot_tools installed at: $DEPOT_TOOLS_DIR" +echo "" +echo "To complete setup:" +echo " 1. Restart your shell or run: source ~/.zshrc" +echo " 2. Verify installation: gclient --version" +echo "" +echo "For Chromium development, run:" +echo " cd ~/chromium_workspace" +echo " fetch chromium" +echo "" diff --git a/src/setup/install-tree.zsh b/src/setup/install-tree.zsh new file mode 100644 index 0000000..7cdafdd --- /dev/null +++ b/src/setup/install-tree.zsh @@ -0,0 +1,3 @@ +# Install tree which is a useful utility for displaying directory structures +echo "Installing tree utility..." +brew install tree \ No newline at end of file diff --git a/src/zsh/plugin-init/depot-tools.zsh b/src/zsh/plugin-init/depot-tools.zsh new file mode 100644 index 0000000..3a9505a --- /dev/null +++ b/src/zsh/plugin-init/depot-tools.zsh @@ -0,0 +1,18 @@ +#!/usr/bin/env zsh +# depot_tools plugin initialization +# Add depot_tools to PATH if installed +# https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html + +DEPOT_TOOLS_HOME="${DEPOT_TOOLS_HOME:-$HOME/.depot_tools}" + +if [[ -d "$DEPOT_TOOLS_HOME" ]]; then + export PATH="$DEPOT_TOOLS_HOME:$PATH" +else + # Inform user depot_tools is not installed + if [[ -z "$DEPOT_TOOLS_SKIP_INIT_MESSAGE" ]]; then + echo "Note: depot_tools not found at: $DEPOT_TOOLS_HOME" + echo "Install with: ./osa-cli.zsh --enable depot-tools" + echo "Or manually: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ~/.depot_tools" + export DEPOT_TOOLS_SKIP_INIT_MESSAGE=1 + fi +fi diff --git a/src/zsh/snippets b/src/zsh/snippets deleted file mode 120000 index 70ffa18..0000000 --- a/src/zsh/snippets +++ /dev/null @@ -1 +0,0 @@ -/Users/fre/dev/osa-snippets \ No newline at end of file From 7442a5f269cfab8f41d4a05e5378433e8892fad9 Mon Sep 17 00:00:00 2001 From: fengelhardt Date: Sat, 27 Dec 2025 21:15:13 -0800 Subject: [PATCH 2/7] fix install scripts for depot_tools and install to external-libs --- osa-cli.zsh | 23 ++++++++++++++++------- src/setup/install-cocoapods.zsh | 8 ++++---- src/setup/install-depot-tools.zsh | 9 ++++----- src/zsh/constructors/base.zsh | 3 +++ src/zsh/plugin-init/depot-tools.zsh | 6 +++--- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/osa-cli.zsh b/osa-cli.zsh index 3f7dd8f..6aaaf3b 100755 --- a/osa-cli.zsh +++ b/osa-cli.zsh @@ -211,13 +211,13 @@ load_json_config() { local -a component_keys=(symlinks oh_my_zsh zsh_plugins homebrew mise osa_snippets git android iterm2 vscode cocoapods depot_tools) for key in "${component_keys[@]}"; do - local enabled=$(yq eval ".components.${key} // false" "$resolved_path" 2>/dev/null) + local enabled=$(yq eval ".components.${key} // false" "$resolved_path" 2>/dev/null | tr -d '\n') local var_name="OSA_SETUP_$(normalize_key "$key")" if [[ "$enabled" == "true" ]]; then - typeset -g "$var_name=true" + typeset -gx "$var_name=true" else - typeset -g "$var_name=false" + typeset -gx "$var_name=false" fi done @@ -225,8 +225,8 @@ load_json_config() { local -a runtime_keys=(node python ruby java rust go deno elixir erlang) for runtime in "${runtime_keys[@]}"; do - local enabled=$(yq eval ".runtimes.${runtime}.enabled // false" "$resolved_path" 2>/dev/null) - local version=$(yq eval ".runtimes.${runtime}.version // \"latest\"" "$resolved_path" 2>/dev/null) + local enabled=$(yq eval ".runtimes.${runtime}.enabled // false" "$resolved_path" 2>/dev/null | tr -d '\n') + local version=$(yq eval ".runtimes.${runtime}.version // \"latest\"" "$resolved_path" 2>/dev/null | tr -d '\n') if [[ "$enabled" == "true" ]]; then # Validate version string contains only safe characters @@ -356,7 +356,7 @@ init_components() { # Development tools with install scripts register_component "git" "Configure Git (version control)" "all" "src/setup/git.zsh" register_component "cocoapods" "Install CocoaPods for iOS development" "macos" "src/setup/install-cocoapods.zsh" - register_component "depot-tools" "Install depot_tools (Chromium development utilities)" "all" "src/setup/install-depot-tools.zsh" + register_component "depot_tools" "Install depot_tools (Chromium development utilities)" "all" "src/setup/install-depot-tools.zsh" } # Check if component is available for current platform @@ -1058,6 +1058,10 @@ automated_setup() { selected_components+=("cocoapods") fi + if [[ "$OSA_SETUP_DEPOT_TOOLS" == "true" ]]; then + selected_components+=("depot_tools") + fi + if [[ ${#selected_components[@]} -eq 0 ]]; then echo -e "${COLOR_YELLOW}No components enabled in configuration.${COLOR_RESET}" echo "Run with --interactive to select components." @@ -1311,6 +1315,7 @@ enable_minimal() { OSA_SETUP_ITERM2=false OSA_SETUP_VSCODE=false OSA_SETUP_OSA_SNIPPETS=false + OSA_SETUP_DEPOT_TOOLS=false # Enable homebrew on macOS if [[ "$OSA_IS_MACOS" == "true" ]]; then @@ -1957,7 +1962,11 @@ main() { ;; -a|--auto) # Load saved config for auto mode - load_config + if ! load_config; then + echo -e "${COLOR_YELLOW}⚠${COLOR_RESET} No saved configuration found at: $OSA_CONFIG_FILE" + echo "Run with --interactive to create a configuration first" + exit 1 + fi automated_setup exit $? ;; diff --git a/src/setup/install-cocoapods.zsh b/src/setup/install-cocoapods.zsh index 47d89df..908501f 100755 --- a/src/setup/install-cocoapods.zsh +++ b/src/setup/install-cocoapods.zsh @@ -15,22 +15,22 @@ mkdir -p "$GEM_HOME/bin" "$GEM_HOME/specs" 2>/dev/null || true # Try installing with --user-install flag first (avoids permission issues) if gem install cocoapods --user-install 2>&1; then echo "✓ CocoaPods $(pod --version) installed successfully" - exit 0 + return 0 else # Fallback to standard install echo "⚠ Standard gem install attempt..." if gem install cocoapods 2>&1; then if command -v pod &>/dev/null; then echo "✓ CocoaPods $(pod --version) installed successfully" - exit 0 + return 0 else echo "✗ CocoaPods installation verification failed" - exit 1 + return 1 fi else echo "✗ Failed to install CocoaPods" echo "→ This usually means the gem directory doesn't have write permissions" echo "→ Try running: sudo gem install cocoapods" - exit 1 + return 1 fi fi \ No newline at end of file diff --git a/src/setup/install-depot-tools.zsh b/src/setup/install-depot-tools.zsh index a6f3361..8ddaec0 100644 --- a/src/setup/install-depot-tools.zsh +++ b/src/setup/install-depot-tools.zsh @@ -4,9 +4,9 @@ echo "Installing depot_tools (Chromium development utilities)..." -# Configuration +# Configuration - install to external-libs like other tools DEPOT_TOOLS_REPO="${DEPOT_TOOLS_REPO:-https://chromium.googlesource.com/chromium/tools/depot_tools.git}" -DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$HOME/.depot_tools}" +DEPOT_TOOLS_DIR="${DEPOT_TOOLS_DIR:-$OSA_REPO_PATH/external-libs/depot_tools}" # Create parent directory if needed mkdir -p "$(dirname "$DEPOT_TOOLS_DIR")" @@ -31,9 +31,8 @@ else fi fi -# Add depot_tools to PATH via shell configuration -# This should be sourced during shell initialization -export PATH="$DEPOT_TOOLS_DIR:$PATH" +# Note: depot_tools will be added to PATH via plugin-init/depot-tools.zsh +# which sources the symlink created by initialize-repo-symlinks.zsh echo "✓ depot_tools installed at: $DEPOT_TOOLS_DIR" echo "" diff --git a/src/zsh/constructors/base.zsh b/src/zsh/constructors/base.zsh index 1d8f00e..5a7bd7b 100644 --- a/src/zsh/constructors/base.zsh +++ b/src/zsh/constructors/base.zsh @@ -47,6 +47,9 @@ if [[ "${OSA_CONFIG_COMPONENTS_ANDROID}" == "true" ]]; then safe_source "$OSA_ZSH_PLUGINS/android-sdk.zsh" fi +# Depot tools for Chromium development +safe_source "$OSA_ZSH_PLUGINS/depot-tools.zsh" + # OSA CLI runtime - exposes 'osa-setup' command for quick access # Noting that `osa` CLI is installed via osa-scripts repo and can run osa-setup by doing `osa setup` safe_source "$OSA_ZSH_ALIASES/osa-setup.zsh" diff --git a/src/zsh/plugin-init/depot-tools.zsh b/src/zsh/plugin-init/depot-tools.zsh index 3a9505a..caef3ac 100644 --- a/src/zsh/plugin-init/depot-tools.zsh +++ b/src/zsh/plugin-init/depot-tools.zsh @@ -3,7 +3,7 @@ # Add depot_tools to PATH if installed # https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html -DEPOT_TOOLS_HOME="${DEPOT_TOOLS_HOME:-$HOME/.depot_tools}" +DEPOT_TOOLS_HOME="${DEPOT_TOOLS_HOME:-$OSA_CONFIG/external-libs/depot_tools}" if [[ -d "$DEPOT_TOOLS_HOME" ]]; then export PATH="$DEPOT_TOOLS_HOME:$PATH" @@ -11,8 +11,8 @@ else # Inform user depot_tools is not installed if [[ -z "$DEPOT_TOOLS_SKIP_INIT_MESSAGE" ]]; then echo "Note: depot_tools not found at: $DEPOT_TOOLS_HOME" - echo "Install with: ./osa-cli.zsh --enable depot-tools" - echo "Or manually: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ~/.depot_tools" + echo "Install with: ./osa-cli.zsh --enable depot_tools" + echo "Or manually: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS_HOME" export DEPOT_TOOLS_SKIP_INIT_MESSAGE=1 fi fi From b2335dc701e28b4c35cbbb48fd04e9515fc3d60c Mon Sep 17 00:00:00 2001 From: fengelhardt Date: Mon, 29 Dec 2025 10:14:34 -0800 Subject: [PATCH 3/7] add tests --- src/setup/install-tree.zsh | 1 + src/zsh/plugin-init/depot-tools.zsh | 8 +- tests/test_depot_tools_install.bats | 227 ++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 tests/test_depot_tools_install.bats diff --git a/src/setup/install-tree.zsh b/src/setup/install-tree.zsh index 7cdafdd..608282f 100644 --- a/src/setup/install-tree.zsh +++ b/src/setup/install-tree.zsh @@ -1,3 +1,4 @@ +#!/usr/bin/env zsh # Install tree which is a useful utility for displaying directory structures echo "Installing tree utility..." brew install tree \ No newline at end of file diff --git a/src/zsh/plugin-init/depot-tools.zsh b/src/zsh/plugin-init/depot-tools.zsh index caef3ac..dfb9508 100644 --- a/src/zsh/plugin-init/depot-tools.zsh +++ b/src/zsh/plugin-init/depot-tools.zsh @@ -9,10 +9,10 @@ if [[ -d "$DEPOT_TOOLS_HOME" ]]; then export PATH="$DEPOT_TOOLS_HOME:$PATH" else # Inform user depot_tools is not installed - if [[ -z "$DEPOT_TOOLS_SKIP_INIT_MESSAGE" ]]; then + if [[ -z "$DEPOT_TOOLS_INIT_MESSAGE_SHOWN" ]]; then echo "Note: depot_tools not found at: $DEPOT_TOOLS_HOME" - echo "Install with: ./osa-cli.zsh --enable depot_tools" - echo "Or manually: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS_HOME" - export DEPOT_TOOLS_SKIP_INIT_MESSAGE=1 + echo "Install with: ./osa-cli.zsh --enable depot-tools" + echo "Or manually: git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git ~/.depot_tools" + export DEPOT_TOOLS_INIT_MESSAGE_SHOWN=1 fi fi diff --git a/tests/test_depot_tools_install.bats b/tests/test_depot_tools_install.bats new file mode 100644 index 0000000..d1ab961 --- /dev/null +++ b/tests/test_depot_tools_install.bats @@ -0,0 +1,227 @@ +#!/usr/bin/env bats +# tests/test_depot_tools_install.bats - Test depot_tools installation and configuration + +load helpers + +# Setup before each test +setup() { + export TEST_TEMP_DIR=$(mktemp -d) + export HOME="$TEST_TEMP_DIR/home" + mkdir -p "$HOME" + + # Set up test depot_tools directory + export DEPOT_TOOLS_TEST_DIR="$TEST_TEMP_DIR/depot_tools" + export DEPOT_TOOLS_REPO="${DEPOT_TOOLS_REPO:-https://chromium.googlesource.com/chromium/tools/depot_tools.git}" + export DEPOT_TOOLS_DIR="$TEST_TEMP_DIR/external-libs/depot_tools" + + # Ensure OSA_REPO_PATH is available to helpers + export OSA_REPO_PATH="$OSA_TEST_REPO_ROOT" + + # Mock git commands + export GIT_CLONE_CALLED=0 + export GIT_PULL_CALLED=0 + export GIT_CLONE_REPO="" + export GIT_CLONE_DIR="" +} + +# Cleanup after each test +teardown() { + rm -rf "$TEST_TEMP_DIR" + unset GIT_CLONE_CALLED GIT_PULL_CALLED GIT_CLONE_REPO GIT_CLONE_DIR +} + +# Directory Structure Tests +# ========================= + +@test "depot_tools: creates parent directory if needed" { + # Verify the script creates the directory structure + local depot_tools_script="$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + + # Check that mkdir -p is used for parent directory creation + grep -q 'mkdir -p "$(dirname "$DEPOT_TOOLS_DIR")' "$depot_tools_script" + echo "✓ Parent directory creation verified" +} + +@test "depot_tools: respects DEPOT_TOOLS_DIR environment variable" { + # Verify the script uses the environment variable + grep -q 'DEPOT_TOOLS_DIR="\${DEPOT_TOOLS_DIR:-' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ DEPOT_TOOLS_DIR environment variable respected" +} + +@test "depot_tools: uses default path in OSA external-libs" { + # Verify default path is set correctly + grep -q 'external-libs/depot_tools' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Default external-libs path verified" +} + +# Clone/Update Detection Tests +# ============================= + +@test "depot_tools: detects existing installation via .git directory" { + # Create a mock depot_tools directory with .git + mkdir -p "$DEPOT_TOOLS_DIR/.git" + touch "$DEPOT_TOOLS_DIR/.git/HEAD" + + # Verify the check exists in the script + grep -q '\[[ -d "$DEPOT_TOOLS_DIR/.git" ]]' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + + # Verify directory detection works + [[ -d "$DEPOT_TOOLS_DIR/.git" ]] + echo "✓ Existing installation detection works" +} + +@test "depot_tools: updates existing installation via git pull" { + # Create a mock depot_tools directory with .git + mkdir -p "$DEPOT_TOOLS_DIR/.git" + touch "$DEPOT_TOOLS_DIR/.git/HEAD" + + # Verify the script attempts git pull for updates + grep -q 'git pull --rebase' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Git pull update mechanism verified" +} + +@test "depot_tools: clones from DEPOT_TOOLS_REPO when not installed" { + # Verify the script clones from the correct repository + grep -q 'git clone "$DEPOT_TOOLS_REPO" "$DEPOT_TOOLS_DIR"' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Clone from DEPOT_TOOLS_REPO verified" +} + +@test "depot_tools: DEPOT_TOOLS_REPO defaults to chromium official source" { + # Verify correct default repository URL + grep -q 'https://chromium.googlesource.com/chromium/tools/depot_tools.git' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Official Chromium depot_tools repository URL verified" +} + +# Error Handling Tests +# ==================== + +@test "depot_tools: handles git clone failure with informative message" { + # Verify error handling for failed clone + grep -q 'Failed to clone depot_tools from' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + grep -q 'Ensure git is installed and you have internet access' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Git clone failure handling verified" +} + +@test "depot_tools: handles git pull failure with informative message" { + # Verify error handling for failed update + grep -q 'Failed to update depot_tools via git pull' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Git pull failure handling verified" +} + +@test "depot_tools: returns error code on clone failure" { + # Verify that the script returns 1 on failure + grep -q 'return 1' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Error return code handling verified" +} + +@test "depot_tools: returns error code on pull failure" { + # Verify that the script returns error on git pull failure + local depot_tools_script="$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + grep -A 2 'git pull --rebase' "$depot_tools_script" | grep -q 'return 1' + echo "✓ Pull failure error code verified" +} + +# Output/Communication Tests +# ========================== + +@test "depot_tools: informs user of installation process start" { + # Verify user-friendly startup message + grep -q 'Installing depot_tools' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Installation start message verified" +} + +@test "depot_tools: confirms successful installation" { + # Verify success message + grep -q '✓ depot_tools installed' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Success confirmation verified" +} + +@test "depot_tools: displays installation location" { + # Verify that installation path is displayed + grep -q 'installed at: $DEPOT_TOOLS_DIR' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Installation location display verified" +} + +@test "depot_tools: provides post-setup instructions" { + # Verify that the script provides helpful next steps + local depot_tools_script="$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + grep -q 'restart your shell' "$depot_tools_script" || grep -q 'source ~/.zshrc' "$depot_tools_script" + echo "✓ Post-setup instructions provided" +} + +@test "depot_tools: mentions gclient verification command" { + # Verify user can check installation worked + grep -q 'gclient --version' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Verification command provided" +} + +@test "depot_tools: includes chromium development example" { + # Verify helpful Chromium development example + grep -q 'fetch chromium' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Chromium development example provided" +} + +# Integration Tests +# ================= + +@test "depot_tools: script is syntactically valid" { + # Verify the script can be sourced without errors + run bash -n "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + [[ "$status" -eq 0 ]] + echo "✓ Script syntax validation passed" +} + +@test "depot_tools: script uses consistent variable naming" { + # Verify consistent naming conventions + local script="$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + grep -q 'DEPOT_TOOLS_REPO' "$script" + grep -q 'DEPOT_TOOLS_DIR' "$script" + echo "✓ Consistent variable naming verified" +} + +@test "depot_tools: script handles directory changes safely" { + # Verify cd uses proper error handling + grep -q 'cd "$DEPOT_TOOLS_DIR"' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + grep -q 'cd - > /dev/null' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Safe directory navigation verified" +} + +@test "depot_tools: script prevents hardcoded paths" { + # Verify all paths use variables + local script="$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + ! grep -q 'depot_tools' "$script" | grep -v '\$DEPOT_TOOLS' + # If above check passes, all depot_tools references use variables + echo "✓ No hardcoded paths detected" +} + +# Documentation Tests +# =================== + +@test "depot_tools: includes documentation link" { + # Verify official documentation reference + grep -q 'https://commondatastorage.googleapis.com' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + grep -q 'depot_tools_tutorial' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Official documentation link provided" +} + +@test "depot_tools: script describes purpose in comments" { + # Verify helpful documentation in script header + grep -q 'Chromium development utilities' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Purpose documentation verified" +} + +# Shebang and Permissions Tests +# ============================== + +@test "depot_tools: script has correct shebang" { + # Verify zsh shebang + head -n 1 "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" | grep -q '#!/usr/bin/env zsh' + echo "✓ Correct zsh shebang verified" +} + +@test "depot_tools: script file exists and is readable" { + # Verify the script exists and is accessible + [[ -f "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" ]] + [[ -r "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" ]] + echo "✓ Script file accessibility verified" +} From 9a7055ef9de109286645e52f8babddf3f9f50248 Mon Sep 17 00:00:00 2001 From: fengelhardt Date: Mon, 29 Dec 2025 11:24:19 -0800 Subject: [PATCH 4/7] fix tests --- tests/test_depot_tools_install.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_depot_tools_install.bats b/tests/test_depot_tools_install.bats index d1ab961..0cd290f 100644 --- a/tests/test_depot_tools_install.bats +++ b/tests/test_depot_tools_install.bats @@ -63,7 +63,7 @@ teardown() { touch "$DEPOT_TOOLS_DIR/.git/HEAD" # Verify the check exists in the script - grep -q '\[[ -d "$DEPOT_TOOLS_DIR/.git" ]]' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + grep -q '[[ -d "$DEPOT_TOOLS_DIR/.git" ]]' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" # Verify directory detection works [[ -d "$DEPOT_TOOLS_DIR/.git" ]] From d412bb8a3bcceabf8320bdc279da703a3935abe0 Mon Sep 17 00:00:00 2001 From: fengelhardt Date: Mon, 29 Dec 2025 11:55:54 -0800 Subject: [PATCH 5/7] add guards so depot_tools cannot be installed on macos to prevent misunderstanding as chromium cannot/is not supported for building on macos --- src/setup/install-depot-tools.zsh | 22 +++++++++++++++++++++ tests/test_depot_tools_install.bats | 30 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/setup/install-depot-tools.zsh b/src/setup/install-depot-tools.zsh index 8ddaec0..a8b2084 100644 --- a/src/setup/install-depot-tools.zsh +++ b/src/setup/install-depot-tools.zsh @@ -2,6 +2,28 @@ # Install/update depot_tools - Chromium development utilities # https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html +# Platform detection +local os_type=$(uname -s) + +# Check if running on macOS +if [[ "$os_type" == "Darwin" ]]; then + echo "⚠️ depot_tools is primarily designed for Linux development (especially Chromium builds)" + echo "" + echo "⚠️ macOS Support: Limited and not recommended" + echo " - depot_tools works better on Linux for Chromium development" + echo " - Consider using a Linux machine or WSL 2 for optimal Chromium development" + echo " - If you need depot_tools on macOS for specific workflows, run on Linux instead" + echo "" + echo "To continue with Chromium development on this macOS machine:" + echo " 1. Set up a Linux VM or use WSL 2 (recommended)" + echo " 2. Run depot_tools installation on that Linux environment" + echo "" + echo "For more information on Chromium development:" + echo " https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/mac_build_instructions.md" + echo "" + return 0 +fi + echo "Installing depot_tools (Chromium development utilities)..." # Configuration - install to external-libs like other tools diff --git a/tests/test_depot_tools_install.bats b/tests/test_depot_tools_install.bats index 0cd290f..886a371 100644 --- a/tests/test_depot_tools_install.bats +++ b/tests/test_depot_tools_install.bats @@ -30,6 +30,36 @@ teardown() { unset GIT_CLONE_CALLED GIT_PULL_CALLED GIT_CLONE_REPO GIT_CLONE_DIR } +# Platform Detection Tests +# ========================= + +@test "depot_tools: detects platform with uname -s" { + # Verify platform detection is performed + grep -q 'uname -s' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ Platform detection via uname verified" +} + +@test "depot_tools: warns on macOS and exits gracefully" { + # Verify macOS check + grep -q 'Darwin' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + grep -q 'depot_tools is primarily designed for Linux' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ macOS warning message verified" +} + +@test "depot_tools: provides macOS alternatives guidance" { + # Verify helpful guidance for macOS users + grep -q 'Linux VM or use WSL 2' "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + echo "✓ macOS alternatives guidance provided" +} + +@test "depot_tools: returns gracefully on macOS without error" { + # Verify that return 0 is used for macOS + local script="$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" + # Check that Darwin check contains return 0 + grep -A 20 'Darwin' "$script" | grep -q 'return 0' + echo "✓ Graceful exit on macOS verified" +} + # Directory Structure Tests # ========================= From 56b270c9ef16c4b0539cce3d445109b7e5f30a89 Mon Sep 17 00:00:00 2001 From: fengelhardt Date: Mon, 29 Dec 2025 16:54:14 -0800 Subject: [PATCH 6/7] Fix script so it initializes if depot_tools is installed --- src/zsh/constructors/base.zsh | 4 ++- tests/test_depot_tools_install.bats | 42 +++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/zsh/constructors/base.zsh b/src/zsh/constructors/base.zsh index 5a7bd7b..272757c 100644 --- a/src/zsh/constructors/base.zsh +++ b/src/zsh/constructors/base.zsh @@ -48,7 +48,9 @@ if [[ "${OSA_CONFIG_COMPONENTS_ANDROID}" == "true" ]]; then fi # Depot tools for Chromium development -safe_source "$OSA_ZSH_PLUGINS/depot-tools.zsh" +if [[ "${OSA_CONFIG_COMPONENTS_DEPOT_TOOLS}" == "true" ]]; then + safe_source "$OSA_ZSH_PLUGINS/depot-tools.zsh" +fi # OSA CLI runtime - exposes 'osa-setup' command for quick access # Noting that `osa` CLI is installed via osa-scripts repo and can run osa-setup by doing `osa setup` diff --git a/tests/test_depot_tools_install.bats b/tests/test_depot_tools_install.bats index 886a371..9d4f5c3 100644 --- a/tests/test_depot_tools_install.bats +++ b/tests/test_depot_tools_install.bats @@ -249,9 +249,41 @@ teardown() { echo "✓ Correct zsh shebang verified" } -@test "depot_tools: script file exists and is readable" { - # Verify the script exists and is accessible - [[ -f "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" ]] - [[ -r "$OSA_REPO_PATH/src/setup/install-depot-tools.zsh" ]] - echo "✓ Script file accessibility verified" +@test "depot_tools: plugin is conditionally loaded in base.zsh" { + # Verify the conditional loading is implemented + grep -q 'OSA_CONFIG_COMPONENTS_DEPOT_TOOLS' "$OSA_REPO_PATH/src/zsh/constructors/base.zsh" + echo "✓ Conditional loading in base.zsh verified" +} + +@test "depot_tools: plugin init follows android-sdk pattern" { + # Verify consistent conditional loading pattern with android-sdk + local base_file="$OSA_REPO_PATH/src/zsh/constructors/base.zsh" + + # Check both plugins use same conditional pattern + grep -q 'if \[\[ "${OSA_CONFIG_COMPONENTS_ANDROID}" == "true" \]\]' "$base_file" + grep -q 'if \[\[ "${OSA_CONFIG_COMPONENTS_DEPOT_TOOLS}" == "true" \]\]' "$base_file" + + echo "✓ depot-tools loading pattern consistent with android-sdk" +} + +# Plugin Initialization Tests +# =========================== + +@test "depot_tools: plugin adds to PATH when directory exists" { + # Verify the plugin adds depot_tools to PATH + grep -q 'export PATH="$DEPOT_TOOLS_HOME:\$PATH"' "$OSA_REPO_PATH/src/zsh/plugin-init/depot-tools.zsh" + echo "✓ PATH configuration verified" +} + +@test "depot_tools: plugin provides helpful message when not installed" { + # Verify informative message for missing installation + grep -q 'depot_tools not found' "$OSA_REPO_PATH/src/zsh/plugin-init/depot-tools.zsh" + grep -q 'Install with' "$OSA_REPO_PATH/src/zsh/plugin-init/depot-tools.zsh" + echo "✓ Missing installation message verified" +} + +@test "depot_tools: plugin sets DEPOT_TOOLS_HOME with default value" { + # Verify environment variable is set with fallback + grep -q 'DEPOT_TOOLS_HOME=.*external-libs/depot_tools' "$OSA_REPO_PATH/src/zsh/plugin-init/depot-tools.zsh" + echo "✓ DEPOT_TOOLS_HOME configuration verified" } From b76ca63cb2ef934e6873901dbf95c1c2141ef3e4 Mon Sep 17 00:00:00 2001 From: fengelhardt Date: Mon, 29 Dec 2025 16:56:28 -0800 Subject: [PATCH 7/7] Add success step so pending status passes --- .github/workflows/test.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 045002d..7d187b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,4 +24,20 @@ jobs: - name: Run test suite run: | echo "Running OSA Snippets test suite..." - bats tests/*.bats \ No newline at end of file + bats tests/*.bats + + success: + name: success + needs: test + runs-on: macos-latest + if: always() + steps: + - name: Decide whether the needed jobs succeeded or failed + run: | + if [[ ${{ needs.test.result }} == "success" ]]; then + echo "✓ All required checks passed" + exit 0 + else + echo "✗ Some required checks failed" + exit 1 + fi \ No newline at end of file