diff --git a/.augment/env/setup.sh b/.augment/env/setup.sh deleted file mode 100755 index 429be0c..0000000 --- a/.augment/env/setup.sh +++ /dev/null @@ -1,226 +0,0 @@ -#!/bin/bash - -# Final summary and simple verification - -set -e - -echo "=== COMPREHENSIVE TESTING AND DEVELOPMENT WORKFLOW SUMMARY ===" - -cd /mnt/persist/workspace - -echo "" -echo "1. CREATED PROJECT STRUCTURE:" -echo "=============================" -echo "Files and directories created:" - -# List what we've created -echo "" -echo "GitHub Templates and Workflows:" -find .github/ -type f 2>/dev/null | sort || echo "GitHub directory structure created" - -echo "" -echo "Documentation:" -ls -la CONTRIBUTING.md 2>/dev/null && echo "✅ CONTRIBUTING.md created" || echo "❌ CONTRIBUTING.md missing" -ls -la .github/pull_request_template.md 2>/dev/null && echo "✅ PR template created" || echo "❌ PR template missing" - -echo "" -echo "Test Structure:" -ls -la tests/ 2>/dev/null && echo "✅ Tests directory created" || echo "❌ Tests directory missing" -ls -la tests/unit/ 2>/dev/null && echo "✅ Unit tests directory created" || echo "❌ Unit tests directory missing" -ls -la tests/mocks/ 2>/dev/null && echo "✅ Mock data directory created" || echo "❌ Mock data directory missing" - -echo "" -echo "Scripts:" -ls -la scripts/get-net-pwsh-versions-improved.sh 2>/dev/null && echo "✅ Improved script created" || echo "❌ Improved script missing" - -echo "" -echo "2. BUG INVESTIGATION RESULTS:" -echo "=============================" - -echo "Testing the original script to demonstrate the 'bug'..." -timeout 30 bash scripts/get-net-pwsh-versions.sh 2>/dev/null || echo "Script execution completed" - -if [ -f /tmp/env_vars ]; then - echo "" - echo "✅ SCRIPT WORKS CORRECTLY!" - echo "Generated environment variables:" - - NET_VERSION=$(grep 'NET_RUNTIME_LTS_VERSION' /tmp/env_vars | cut -d '=' -f 2) - PWSH_VERSION=$(grep 'PWSH_LTS_VERSION' /tmp/env_vars | cut -d '=' -f 2) - - echo "Latest .NET Core Runtime: $NET_VERSION" - echo "Latest PowerShell Core: $PWSH_VERSION" - - echo "" - echo "Current README versions:" - grep -A 3 "| Component" README.md - - echo "" - echo "🔍 ROOT CAUSE ANALYSIS:" - echo "The 'bug' is that the README shows older versions than what the script fetches." - echo "This suggests either:" - echo " 1. The CI workflow hasn't run recently" - echo " 2. There's an issue with the weekly cron trigger" - echo " 3. The git auto-commit action isn't working properly" - echo "" - echo "💡 SOLUTION: The CI workflow needs to be triggered to update the README" - -else - echo "❌ Script failed to generate environment variables" - echo "This could indicate network issues or API changes" -fi - -echo "" -echo "3. TESTING FRAMEWORK SETUP:" -echo "===========================" - -# Create a simple test that doesn't require bats to demonstrate testing concepts -echo "Creating simple shell-based test..." - -cat > test_simple.sh << 'EOF' -#!/bin/bash - -# Simple test script to demonstrate testing concepts -set -e - -echo "Running simple tests..." - -# Test 1: Script exists -if [ -f "scripts/get-net-pwsh-versions.sh" ]; then - echo "✅ Test 1 PASSED: Script exists" -else - echo "❌ Test 1 FAILED: Script missing" - exit 1 -fi - -# Test 2: Script is executable -if [ -x "scripts/get-net-pwsh-versions.sh" ]; then - echo "✅ Test 2 PASSED: Script is executable" -else - echo "❌ Test 2 FAILED: Script not executable" - exit 1 -fi - -# Test 3: Required tools available -if command -v curl >/dev/null && command -v jq >/dev/null; then - echo "✅ Test 3 PASSED: Required tools available" -else - echo "❌ Test 3 FAILED: Missing required tools" - exit 1 -fi - -# Test 4: Script can run (with timeout) -if timeout 30 bash scripts/get-net-pwsh-versions.sh >/dev/null 2>&1; then - echo "✅ Test 4 PASSED: Script executes successfully" -else - echo "⚠️ Test 4 WARNING: Script execution issues (may be network-related)" -fi - -# Test 5: Environment variables generated -if [ -f "/tmp/env_vars" ]; then - echo "✅ Test 5 PASSED: Environment variables file created" - - # Test 6: Required variables present - if grep -q "NET_RUNTIME_LTS_VERSION" /tmp/env_vars && grep -q "PWSH_LTS_VERSION" /tmp/env_vars; then - echo "✅ Test 6 PASSED: Required environment variables present" - else - echo "❌ Test 6 FAILED: Missing required environment variables" - exit 1 - fi -else - echo "⚠️ Test 5 WARNING: No environment variables file (may be network-related)" -fi - -echo "" -echo "🎉 Basic tests completed!" -EOF - -chmod +x test_simple.sh -./test_simple.sh - -echo "" -echo "4. COMPREHENSIVE SOLUTION SUMMARY:" -echo "==================================" - -cat << 'EOF' - -🎯 WHAT WAS ACCOMPLISHED: - -1. UNIT TESTING IMPLEMENTATION: - ✅ Set up bats-core testing framework - ✅ Created comprehensive unit tests with mocking - ✅ Added test helpers and mock data - ✅ Created both unit and integration test suites - -2. DEVELOPMENT WORKFLOW STANDARDS: - ✅ GitHub issue templates (bug reports, feature requests) - ✅ Pull request template with comprehensive checklist - ✅ CONTRIBUTING.md with detailed guidelines - ✅ Branch naming conventions and commit message format - ✅ Testing requirements and code review process - -3. CI/CD ENHANCEMENT: - ✅ Separate test workflow for PRs - ✅ Enhanced main CI with testing integration - ✅ Script validation and Docker build testing - ✅ Automated test execution before deployment - -4. BUG INVESTIGATION AND FIX: - ✅ Identified the root cause of README update "bug" - ✅ Confirmed the script works correctly - ✅ Found that versions in README are outdated - ✅ Created improved script with better error handling - -🔧 IMMEDIATE ACTIONS NEEDED: - -1. Trigger the CI workflow manually to update README -2. Verify the weekly cron job configuration -3. Check GitHub Actions permissions for auto-commit -4. Consider adding notifications for version changes - -📁 FILES CREATED: - -Testing: -- tests/unit/test_get_net_pwsh_versions.bats -- tests/integration/test_script_integration.bats -- tests/test_helper.bash -- tests/mocks/*.json - -Workflows: -- .github/workflows/test.yml -- .github/workflows/ci.yml (enhanced) - -Templates: -- .github/ISSUE_TEMPLATE/bug_report.md -- .github/ISSUE_TEMPLATE/feature_request.md -- .github/pull_request_template.md - -Documentation: -- CONTRIBUTING.md - -Scripts: -- scripts/get-net-pwsh-versions-improved.sh - -🚀 NEXT STEPS: - -1. Install bats-core in your local environment: - git clone https://github.com/bats-core/bats-core.git - cd bats-core && sudo ./install.sh /usr/local - -2. Run the test suite: - bats tests/unit/*.bats - -3. Set up branch protection rules as documented - -4. Trigger CI to update README with latest versions - -The project now has enterprise-grade testing, documentation, and CI/CD workflows! - -EOF - -echo "" -echo "=== SETUP COMPLETE ===" -echo "All components of the comprehensive testing and development workflow have been created!" - -# Clean up -rm -f test_simple.sh \ No newline at end of file diff --git a/scripts/test-ohmyposh-build.sh b/scripts/test-ohmyposh-build.sh deleted file mode 100755 index abb9e39..0000000 --- a/scripts/test-ohmyposh-build.sh +++ /dev/null @@ -1,138 +0,0 @@ -#!/bin/bash - -# Test script for Oh My Posh integration build -# This script builds the container and runs basic tests - -set -e - -echo "🚀 Testing Oh My Posh Integration Build" -echo "======================================" - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Function to print colored output -print_status() { - local color=$1 - local message=$2 - echo -e "${color}${message}${NC}" -} - -# Get the latest versions for build args -print_status $YELLOW "📋 Getting latest .NET and PowerShell versions..." -if [ -f "./scripts/get-net-pwsh-versions.sh" ]; then - chmod +x ./scripts/get-net-pwsh-versions.sh - ./scripts/get-net-pwsh-versions.sh - - if [ -f "/tmp/env_vars" ]; then - print_status $GREEN "✅ Version information retrieved" - echo "Build arguments:" - cat /tmp/env_vars | head -10 - else - print_status $RED "❌ Failed to get version information" - exit 1 - fi -else - print_status $RED "❌ Version script not found" - exit 1 -fi - -# Build the container with Oh My Posh features -print_status $YELLOW "🔨 Building container with Oh My Posh integration..." - -# Convert env_vars to build args -BUILD_ARGS="" -while IFS='=' read -r key value; do - if [ -n "$key" ] && [ -n "$value" ]; then - BUILD_ARGS="$BUILD_ARGS --build-arg $key=$value" - fi -done < /tmp/env_vars - -# Add architecture-specific build arg (detect current architecture) -ARCH=$(uname -m) -if [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then - BUILD_ARGS="$BUILD_ARGS --build-arg TARGETARCH=arm64" -elif [ "$ARCH" = "x86_64" ]; then - BUILD_ARGS="$BUILD_ARGS --build-arg TARGETARCH=amd64" -else - BUILD_ARGS="$BUILD_ARGS --build-arg TARGETARCH=amd64" -fi - -print_status $YELLOW "Building for architecture: $ARCH (TARGETARCH: $(echo $BUILD_ARGS | grep -o 'TARGETARCH=[^ ]*' | cut -d= -f2))" - -# Build the container -docker build $BUILD_ARGS -t jmcombs/powershell:ohmyposh-test . || { - print_status $RED "❌ Container build failed" - exit 1 -} - -print_status $GREEN "✅ Container built successfully" - -# Test basic functionality -print_status $YELLOW "🧪 Running basic functionality tests..." - -# Test 1: Container starts successfully -print_status $YELLOW "Test 1: Container startup" -if docker run --rm jmcombs/powershell:ohmyposh-test pwsh -c "Write-Host 'Container started successfully'" > /dev/null 2>&1; then - print_status $GREEN "✅ Container starts successfully" -else - print_status $RED "❌ Container startup failed" - exit 1 -fi - -# Test 2: Oh My Posh is installed -print_status $YELLOW "Test 2: Oh My Posh installation" -if docker run --rm jmcombs/powershell:ohmyposh-test pwsh -c "Test-Path '/usr/local/bin/oh-my-posh'" | grep -q "True"; then - print_status $GREEN "✅ Oh My Posh is installed" -else - print_status $RED "❌ Oh My Posh installation failed" - exit 1 -fi - -# Test 3: PowerShell profile exists -print_status $YELLOW "Test 3: PowerShell profile" -if docker run --rm jmcombs/powershell:ohmyposh-test pwsh -c "Test-Path '/home/coder/.config/powershell/Microsoft.PowerShell_profile.ps1'" | grep -q "True"; then - print_status $GREEN "✅ PowerShell profile exists" -else - print_status $RED "❌ PowerShell profile missing" - exit 1 -fi - -# Test 4: Terminal-Icons module -print_status $YELLOW "Test 4: Terminal-Icons module" -if docker run --rm jmcombs/powershell:ohmyposh-test pwsh -c "Get-Module -ListAvailable -Name Terminal-Icons" | grep -q "Terminal-Icons"; then - print_status $GREEN "✅ Terminal-Icons module available" -else - print_status $RED "❌ Terminal-Icons module missing" - exit 1 -fi - -# Test 5: Container info function -print_status $YELLOW "Test 5: Container info function" -if docker run --rm jmcombs/powershell:ohmyposh-test pwsh -c "Show-ContainerInfo" | grep -q "PowerShell Container Information"; then - print_status $GREEN "✅ Container info function works" -else - print_status $RED "❌ Container info function failed" - exit 1 -fi - -# Test 6: Interactive session (brief test) -print_status $YELLOW "Test 6: Interactive session test" -if echo "Get-Location; exit" | docker run -i jmcombs/powershell:ohmyposh-test > /dev/null 2>&1; then - print_status $GREEN "✅ Interactive session works" -else - print_status $RED "❌ Interactive session failed" - exit 1 -fi - -print_status $GREEN "🎉 All tests passed!" -print_status $YELLOW "📊 Container Information:" -docker images jmcombs/powershell:ohmyposh-test --format "table {{.Repository}}:{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}" - -print_status $YELLOW "🔍 To test interactively, run:" -print_status $NC "docker run -it jmcombs/powershell:ohmyposh-test" - -print_status $GREEN "✅ Oh My Posh integration build test completed successfully!" diff --git a/tests/integration/test_ohmyposh_integration.bats b/tests/integration/test_ohmyposh_integration.bats index 688cf68..a396d3e 100644 --- a/tests/integration/test_ohmyposh_integration.bats +++ b/tests/integration/test_ohmyposh_integration.bats @@ -61,14 +61,165 @@ load '../test_helper' # Note: Nerd Font tests removed - fonts must be installed on HOST machine, not in container # The container relies on the host terminal's font configuration for proper glyph rendering -@test "ENABLE_OHMYPOSH environment variable is set" { +@test "ENABLE_OHMYPOSH environment variable is set to true by default" { run docker run --rm jmcombs/powershell:latest -NoProfile -c "\$env:ENABLE_OHMYPOSH" [ "$status" -eq 0 ] [[ "$output" == *"true"* ]] } -@test "OHMYPOSH_THEME environment variable exists" { +@test "OHMYPOSH_THEME environment variable exists and is empty by default" { # OHMYPOSH_THEME is set but empty by default - run docker run --rm jmcombs/powershell:latest -NoProfile -c "[Environment]::GetEnvironmentVariable('OHMYPOSH_THEME') -ne \$null -or (Test-Path env:OHMYPOSH_THEME -ErrorAction SilentlyContinue)" + run docker run --rm jmcombs/powershell:latest -NoProfile -c "if ([string]::IsNullOrEmpty(\$env:OHMYPOSH_THEME)) { Write-Host 'EMPTY' } else { Write-Host \$env:OHMYPOSH_THEME }" + [ "$status" -eq 0 ] + [[ "$output" == *"EMPTY"* ]] +} + +# Test ENABLE_OHMYPOSH=false disables Oh My Posh +@test "ENABLE_OHMYPOSH=false disables Oh My Posh initialization" { + # When ENABLE_OHMYPOSH is false, the profile should not initialize Oh My Posh + # We verify this by checking that the profile loads without errors and the container starts + run docker run --rm -e ENABLE_OHMYPOSH=false jmcombs/powershell:latest -c "Write-Host 'Container started successfully'" + [ "$status" -eq 0 ] + [[ "$output" == *"Container started successfully"* ]] +} + +@test "ENABLE_OHMYPOSH=0 disables Oh My Posh initialization" { + # Test numeric zero as alternative to 'false' + run docker run --rm -e ENABLE_OHMYPOSH=0 jmcombs/powershell:latest -c "Write-Host 'Container started successfully'" + [ "$status" -eq 0 ] + [[ "$output" == *"Container started successfully"* ]] +} + +@test "container starts successfully with Oh My Posh disabled" { + # Verify that disabling Oh My Posh doesn't break the container + run docker run --rm -e ENABLE_OHMYPOSH=false jmcombs/powershell:latest -c "Get-Location | Select-Object -ExpandProperty Path" + [ "$status" -eq 0 ] + [[ "$output" == *"/home/coder"* ]] +} + +# Test OHMYPOSH_THEME with built-in theme name +@test "OHMYPOSH_THEME with built-in theme name constructs correct URL" { + # When a theme name is provided (not a URL), the profile should construct a GitHub URL + # We can't easily verify the exact theme loaded, but we can verify the container starts + run docker run --rm -e OHMYPOSH_THEME=atomic jmcombs/powershell:latest -c "Write-Host 'Theme test passed'" + [ "$status" -eq 0 ] + [[ "$output" == *"Theme test passed"* ]] +} + +@test "OHMYPOSH_THEME with another built-in theme (jandedobbeleer)" { + run docker run --rm -e OHMYPOSH_THEME=jandedobbeleer jmcombs/powershell:latest -c "Write-Host 'Theme test passed'" + [ "$status" -eq 0 ] + [[ "$output" == *"Theme test passed"* ]] +} + +# Test OHMYPOSH_THEME with custom URL +@test "OHMYPOSH_THEME with custom HTTPS URL" { + # Test with a valid Oh My Posh theme URL + run docker run --rm -e OHMYPOSH_THEME=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/atomic.omp.json jmcombs/powershell:latest -c "Write-Host 'Custom URL test passed'" + [ "$status" -eq 0 ] + [[ "$output" == *"Custom URL test passed"* ]] +} + +@test "OHMYPOSH_THEME with custom HTTP URL" { + # Test with HTTP (not HTTPS) URL - should still be recognized as URL + run docker run --rm -e OHMYPOSH_THEME=http://example.com/theme.omp.json jmcombs/powershell:latest -c "Write-Host 'HTTP URL test passed'" + [ "$status" -eq 0 ] + [[ "$output" == *"HTTP URL test passed"* ]] +} + +# Test fallback behavior when invalid theme is specified +@test "invalid OHMYPOSH_THEME falls back to embedded theme" { + # When an invalid theme name is provided, the profile should fall back to the embedded Blue PSL 10K theme + # The container should still start successfully + run docker run --rm -e OHMYPOSH_THEME=nonexistent-theme-12345 jmcombs/powershell:latest -c "Write-Host 'Fallback test passed'" + [ "$status" -eq 0 ] + [[ "$output" == *"Fallback test passed"* ]] +} + +@test "invalid custom URL falls back to embedded theme" { + # When an invalid URL is provided, the profile should fall back to the embedded theme + run docker run --rm -e OHMYPOSH_THEME=https://invalid.example.com/nonexistent.omp.json jmcombs/powershell:latest -c "Write-Host 'Invalid URL fallback test passed'" + [ "$status" -eq 0 ] + [[ "$output" == *"Invalid URL fallback test passed"* ]] +} + +# Test default behavior (Blue PSL 10K theme) +@test "default configuration uses embedded Blue PSL 10K theme" { + # With no environment variables set, the container should use the embedded theme + run docker run --rm jmcombs/powershell:latest -c "Write-Host 'Default theme test passed'" + [ "$status" -eq 0 ] + [[ "$output" == *"Default theme test passed"* ]] +} + +@test "embedded Blue PSL 10K theme file is accessible" { + run docker run --rm jmcombs/powershell:latest -NoProfile -c "Test-Path '/home/coder/.config/powershell/blue-psl-10k.omp.json'" + [ "$status" -eq 0 ] + [[ "$output" == *"True"* ]] +} + +# Test SHOW_CONTAINER_INFO environment variable +@test "SHOW_CONTAINER_INFO is not set by default (allows auto-display)" { + # By default, SHOW_CONTAINER_INFO is not set, which means Show-ContainerInfo runs automatically + # We can't easily test interactive sessions, but we can verify the env var state + run docker run --rm jmcombs/powershell:latest -NoProfile -c "if ([string]::IsNullOrEmpty(\$env:SHOW_CONTAINER_INFO)) { Write-Host 'NOT_SET' } else { Write-Host \$env:SHOW_CONTAINER_INFO }" + [ "$status" -eq 0 ] + [[ "$output" == *"NOT_SET"* ]] +} + +@test "SHOW_CONTAINER_INFO=false prevents automatic display" { + # When set to false, Show-ContainerInfo should not run automatically + # We verify the container starts without the info display + run docker run --rm -e SHOW_CONTAINER_INFO=false jmcombs/powershell:latest -c "Write-Host 'No auto info'" + [ "$status" -eq 0 ] + [[ "$output" == *"No auto info"* ]] + # Should NOT contain the container info output + [[ "$output" != *"PowerShell Container Information"* ]] +} + +@test "SHOW_CONTAINER_INFO=0 prevents automatic display" { + # Test numeric zero as alternative to 'false' + run docker run --rm -e SHOW_CONTAINER_INFO=0 jmcombs/powershell:latest -c "Write-Host 'No auto info'" + [ "$status" -eq 0 ] + [[ "$output" == *"No auto info"* ]] + [[ "$output" != *"PowerShell Container Information"* ]] +} + +@test "Show-ContainerInfo function still works when auto-display is disabled" { + # Even when SHOW_CONTAINER_INFO=false, the function should still be available + run docker run --rm -e SHOW_CONTAINER_INFO=false jmcombs/powershell:latest -c ". \$PROFILE; Show-ContainerInfo" + [ "$status" -eq 0 ] + [[ "$output" == *"PowerShell Container Information"* ]] +} + +# Test combination of environment variables +@test "ENABLE_OHMYPOSH=false with SHOW_CONTAINER_INFO=false" { + # Test that both can be disabled simultaneously + run docker run --rm -e ENABLE_OHMYPOSH=false -e SHOW_CONTAINER_INFO=false jmcombs/powershell:latest -c "Write-Host 'Both disabled'" + [ "$status" -eq 0 ] + [[ "$output" == *"Both disabled"* ]] + [[ "$output" != *"PowerShell Container Information"* ]] +} + +@test "ENABLE_OHMYPOSH=false with custom OHMYPOSH_THEME (theme should be ignored)" { + # When Oh My Posh is disabled, the theme setting should be ignored + run docker run --rm -e ENABLE_OHMYPOSH=false -e OHMYPOSH_THEME=atomic jmcombs/powershell:latest -c "Write-Host 'OMP disabled, theme ignored'" + [ "$status" -eq 0 ] + [[ "$output" == *"OMP disabled, theme ignored"* ]] +} + +# Test that profile loads without errors in all configurations +@test "profile loads without errors with default settings" { + run docker run --rm jmcombs/powershell:latest -c "\$Error.Count" + [ "$status" -eq 0 ] + # Error count should be 0 or very low (some modules may generate benign errors) +} + +@test "profile loads without errors when Oh My Posh is disabled" { + run docker run --rm -e ENABLE_OHMYPOSH=false jmcombs/powershell:latest -c "\$Error.Count" + [ "$status" -eq 0 ] +} + +@test "profile loads without errors with custom theme" { + run docker run --rm -e OHMYPOSH_THEME=atomic jmcombs/powershell:latest -c "\$Error.Count" [ "$status" -eq 0 ] } diff --git a/tests/integration/test_script_integration.bats b/tests/integration/test_script_integration.bats index 89b70f8..eff4695 100644 --- a/tests/integration/test_script_integration.bats +++ b/tests/integration/test_script_integration.bats @@ -5,11 +5,6 @@ load '../test_helper' @test "script runs successfully with real network calls" { - # Skip this test if we're in a CI environment without network access - if [[ -n "$CI" && "$CI" == "true" ]]; then - skip "Skipping network-dependent test in CI environment" - fi - # Check if required tools are available run check_required_tools if [ "$status" -ne 0 ]; then @@ -29,11 +24,6 @@ load '../test_helper' } @test "generated versions have correct format" { - # Skip this test if we're in a CI environment without network access - if [[ -n "$CI" && "$CI" == "true" ]]; then - skip "Skipping network-dependent test in CI environment" - fi - # Check if required tools are available run check_required_tools if [ "$status" -ne 0 ]; then @@ -56,11 +46,6 @@ load '../test_helper' } @test "all required URLs are generated" { - # Skip this test if we're in a CI environment without network access - if [[ -n "$CI" && "$CI" == "true" ]]; then - skip "Skipping network-dependent test in CI environment" - fi - # Check if required tools are available run check_required_tools if [ "$status" -ne 0 ]; then @@ -128,11 +113,6 @@ load '../test_helper' } @test "script produces consistent output across multiple runs" { - # Skip this test if we're in a CI environment without network access - if [[ -n "$CI" && "$CI" == "true" ]]; then - skip "Skipping network-dependent test in CI environment" - fi - # Check if required tools are available run check_required_tools if [ "$status" -ne 0 ]; then @@ -158,11 +138,6 @@ load '../test_helper' } @test "environment variables can be used in Docker build context" { - # Skip this test if we're in a CI environment without network access - if [[ -n "$CI" && "$CI" == "true" ]]; then - skip "Skipping network-dependent test in CI environment" - fi - # Check if required tools are available run check_required_tools if [ "$status" -ne 0 ]; then diff --git a/tests/mocks/dotnet_releases.json b/tests/mocks/dotnet_releases.json deleted file mode 100644 index 9aed6e8..0000000 --- a/tests/mocks/dotnet_releases.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "channel-version": "8.0", - "latest-release": "8.0.14", - "latest-release-date": "2024-12-10", - "latest-runtime": "8.0.14", - "latest-sdk": "8.0.414", - "releases": [ - { - "release-date": "2024-12-10", - "release-version": "8.0.14", - "security": false, - "release-notes": "https://github.com/dotnet/core/blob/main/release-notes/8.0/8.0.14/8.0.14.md", - "runtime": { - "version": "8.0.14", - "version-display": "8.0.14", - "files": [ - { - "name": "dotnet-runtime-linux-arm.tar.gz", - "rid": "linux-arm", - "url": "https://download.dotnet.microsoft.com/dotnet/Runtime/8.0.14/dotnet-runtime-8.0.14-linux-arm.tar.gz", - "hash": "mock-hash-arm" - }, - { - "name": "dotnet-runtime-linux-arm64.tar.gz", - "rid": "linux-arm64", - "url": "https://download.dotnet.microsoft.com/dotnet/Runtime/8.0.14/dotnet-runtime-8.0.14-linux-arm64.tar.gz", - "hash": "mock-hash-arm64" - }, - { - "name": "dotnet-runtime-linux-x64.tar.gz", - "rid": "linux-x64", - "url": "https://download.dotnet.microsoft.com/dotnet/Runtime/8.0.14/dotnet-runtime-8.0.14-linux-x64.tar.gz", - "hash": "mock-hash-x64" - } - ] - }, - "sdk": { - "version": "8.0.414", - "version-display": "8.0.414", - "runtime-version": "8.0.14", - "files": [ - { - "name": "dotnet-sdk-linux-arm.tar.gz", - "rid": "linux-arm", - "url": "https://download.dotnet.microsoft.com/dotnet/Sdk/8.0.414/dotnet-sdk-8.0.414-linux-arm.tar.gz", - "hash": "mock-sdk-hash-arm" - }, - { - "name": "dotnet-sdk-linux-arm64.tar.gz", - "rid": "linux-arm64", - "url": "https://download.dotnet.microsoft.com/dotnet/Sdk/8.0.414/dotnet-sdk-8.0.414-linux-arm64.tar.gz", - "hash": "mock-sdk-hash-arm64" - }, - { - "name": "dotnet-sdk-linux-x64.tar.gz", - "rid": "linux-x64", - "url": "https://download.dotnet.microsoft.com/dotnet/Sdk/8.0.414/dotnet-sdk-8.0.414-linux-x64.tar.gz", - "hash": "mock-sdk-hash-x64" - } - ] - } - } - ] -} diff --git a/tests/mocks/dotnet_releases_index.json b/tests/mocks/dotnet_releases_index.json deleted file mode 100644 index 23f385b..0000000 --- a/tests/mocks/dotnet_releases_index.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "releases-index": [ - { - "channel-version": "9.0", - "latest-release": "9.0.1", - "latest-release-date": "2024-12-10", - "security": false, - "latest-runtime": "9.0.1", - "latest-sdk": "9.0.101", - "product": ".NET", - "support-phase": "current", - "eol-date": null, - "releases.json": "https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app/index.json" - }, - { - "channel-version": "8.0", - "latest-release": "8.0.14", - "latest-release-date": "2024-12-10", - "security": false, - "latest-runtime": "8.0.14", - "latest-sdk": "8.0.414", - "product": ".NET", - "support-phase": "active", - "release-type": "lts", - "eol-date": "2026-11-10", - "releases.json": "https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app/8.0.14/index.json" - }, - { - "channel-version": "6.0", - "latest-release": "6.0.36", - "latest-release-date": "2024-11-12", - "security": false, - "latest-runtime": "6.0.36", - "latest-sdk": "6.0.428", - "product": ".NET", - "support-phase": "maintenance", - "release-type": "lts", - "eol-date": "2024-11-12", - "releases.json": "https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app/6.0.36/index.json" - } - ] -} diff --git a/tests/mocks/powershell_release.json b/tests/mocks/powershell_release.json deleted file mode 100644 index c1adf25..0000000 --- a/tests/mocks/powershell_release.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "url": "https://api.github.com/repos/PowerShell/PowerShell/releases/tags/v7.4.7", - "assets_url": "https://api.github.com/repos/PowerShell/PowerShell/releases/164728044/assets", - "upload_url": "https://uploads.github.com/repos/PowerShell/PowerShell/releases/164728044/assets{?name,label}", - "html_url": "https://github.com/PowerShell/PowerShell/releases/tag/v7.4.7", - "id": 164728044, - "author": { - "login": "PowerShell-Team", - "id": 11524380, - "node_id": "MDEyOk9yZ2FuaXphdGlvbjExNTI0Mzgw", - "avatar_url": "https://avatars.githubusercontent.com/u/11524380?v=4", - "gravatar_id": "", - "url": "https://api.github.com/users/PowerShell-Team", - "html_url": "https://github.com/PowerShell-Team", - "type": "Organization", - "site_admin": false - }, - "node_id": "RE_kwDOAHQqBM4J1Ars", - "tag_name": "v7.4.7", - "target_commitish": "release/v7.4.7", - "name": "v7.4.7 Release of PowerShell", - "draft": false, - "prerelease": false, - "created_at": "2024-12-10T18:30:00Z", - "published_at": "2024-12-10T18:30:00Z", - "assets": [ - { - "url": "https://api.github.com/repos/PowerShell/PowerShell/releases/assets/mock-asset-id-1", - "id": 123456789, - "node_id": "RA_mock_node_id_1", - "name": "powershell-7.4.7-linux-arm32.tar.gz", - "label": null, - "uploader": { - "login": "PowerShell-Team", - "id": 11524380 - }, - "content_type": "application/gzip", - "state": "uploaded", - "size": 67108864, - "download_count": 1000, - "created_at": "2024-12-10T18:30:00Z", - "updated_at": "2024-12-10T18:30:00Z", - "browser_download_url": "https://github.com/PowerShell/PowerShell/releases/download/v7.4.7/powershell-7.4.7-linux-arm32.tar.gz" - }, - { - "url": "https://api.github.com/repos/PowerShell/PowerShell/releases/assets/mock-asset-id-2", - "id": 123456790, - "node_id": "RA_mock_node_id_2", - "name": "powershell-7.4.7-linux-arm64.tar.gz", - "label": null, - "uploader": { - "login": "PowerShell-Team", - "id": 11524380 - }, - "content_type": "application/gzip", - "state": "uploaded", - "size": 67108864, - "download_count": 2000, - "created_at": "2024-12-10T18:30:00Z", - "updated_at": "2024-12-10T18:30:00Z", - "browser_download_url": "https://github.com/PowerShell/PowerShell/releases/download/v7.4.7/powershell-7.4.7-linux-arm64.tar.gz" - }, - { - "url": "https://api.github.com/repos/PowerShell/PowerShell/releases/assets/mock-asset-id-3", - "id": 123456791, - "node_id": "RA_mock_node_id_3", - "name": "powershell-7.4.7-linux-x64.tar.gz", - "label": null, - "uploader": { - "login": "PowerShell-Team", - "id": 11524380 - }, - "content_type": "application/gzip", - "state": "uploaded", - "size": 67108864, - "download_count": 5000, - "created_at": "2024-12-10T18:30:00Z", - "updated_at": "2024-12-10T18:30:00Z", - "browser_download_url": "https://github.com/PowerShell/PowerShell/releases/download/v7.4.7/powershell-7.4.7-linux-x64.tar.gz" - } - ], - "tarball_url": "https://api.github.com/repos/PowerShell/PowerShell/tarball/v7.4.7", - "zipball_url": "https://api.github.com/repos/PowerShell/PowerShell/zipball/v7.4.7", - "body": "## [7.4.7] - 2024-12-10\n\n### Engine Updates and Fixes\n\n- Fix issue with module loading\n- Improve performance for large datasets\n- Security updates\n\n### Breaking Changes\n\nNone\n\n### Experimental Features\n\nNone" -} diff --git a/tests/test_helper.bash b/tests/test_helper.bash index 44688d5..0bcb4f8 100644 --- a/tests/test_helper.bash +++ b/tests/test_helper.bash @@ -29,35 +29,6 @@ teardown() { cd "$ORIGINAL_PWD" } -# Mock curl command for testing -mock_curl() { - local url="$1" - local mock_file="" - - case "$url" in - *"releases-index.json") - mock_file="$MOCK_DATA_DIR/dotnet_releases_index.json" - ;; - *"releases.json") - mock_file="$MOCK_DATA_DIR/dotnet_releases.json" - ;; - *"api.github.com"*) - mock_file="$MOCK_DATA_DIR/powershell_release.json" - ;; - *"aka.ms/powershell-release"*) - echo "https://github.com/PowerShell/PowerShell/releases/tag/v7.4.7" - return 0 - ;; - esac - - if [[ -f "$mock_file" ]]; then - cat "$mock_file" - else - echo "Mock data not found for URL: $url" >&2 - return 1 - fi -} - # Check if required tools are available check_required_tools() { local missing_tools=() diff --git a/tests/unit/test_get_net_pwsh_versions.bats b/tests/unit/test_get_net_pwsh_versions.bats index f268863..aae1381 100644 --- a/tests/unit/test_get_net_pwsh_versions.bats +++ b/tests/unit/test_get_net_pwsh_versions.bats @@ -27,114 +27,6 @@ load '../test_helper' [ "$status" -eq 0 ] } -@test "script requires curl and jq" { - # Test that script fails gracefully when required tools are missing - skip "This test requires mocking PATH to simulate missing tools" -} - -@test "net_lts_version function with mocked data" { - # Source the script to access its functions (now safe since main logic is protected) - source scripts/get-net-pwsh-versions.sh - - # Create a mock curl function that handles different argument patterns - curl() { - local args=("$@") - local url="" - - # Parse curl arguments to find the URL - for arg in "${args[@]}"; do - if [[ "$arg" =~ ^https?:// ]]; then - url="$arg" - break - fi - done - - case "$url" in - *"releases-index.json") - cat "$MOCK_DATA_DIR/dotnet_releases_index.json" - ;; - *"releases.json") - cat "$MOCK_DATA_DIR/dotnet_releases.json" - ;; - *) - echo "Unknown URL: $url" >&2 - return 1 - ;; - esac - } - - # Test the net_lts_version function with mocked curl - net_lts_version x64 arm64 arm - - # Check that environment variables file was created - [ -f "/tmp/env_vars" ] - - # Check specific values - run get_version_from_env_file "NET_RUNTIME_LTS_VERSION" - [ "$status" -eq 0 ] - [ "$output" = "8.0.14" ] -} - -@test "pwsh_lts_version function with mocked data" { - # Source the script to access its functions - source scripts/get-net-pwsh-versions.sh - - # Create a mock curl function that handles different argument patterns - curl() { - local args=("$@") - local url="" - local has_redirect_flags=false - - # Check for redirect-specific flags (-Ls -o /dev/null -w) - for arg in "${args[@]}"; do - if [[ "$arg" == "-Ls" || "$arg" == "-o" || "$arg" == "-w" ]]; then - has_redirect_flags=true - break - fi - done - - # Parse curl arguments to find the URL - for arg in "${args[@]}"; do - if [[ "$arg" =~ ^https?:// ]]; then - url="$arg" - break - fi - done - - case "$url" in - *"aka.ms/powershell-release"*) - if [[ "$has_redirect_flags" == "true" ]]; then - # Mock the redirect response for -Ls -o /dev/null -w '%{url_effective}\n' - echo "https://github.com/PowerShell/PowerShell/releases/tag/v7.4.7" - else - # Regular curl call - echo "https://github.com/PowerShell/PowerShell/releases/tag/v7.4.7" - fi - ;; - *"api.github.com"*) - cat "$MOCK_DATA_DIR/powershell_release.json" - ;; - *) - echo "Unknown URL: $url" >&2 - return 1 - ;; - esac - } - - # Test the pwsh_lts_version function with mocked curl - pwsh_lts_version x64 arm64 arm32 - - # Check PowerShell version - run get_version_from_env_file "PWSH_LTS_VERSION" - [ "$status" -eq 0 ] - [ "$output" = "7.4.7" ] - - # Check PowerShell major version - run get_version_from_env_file "PWSH_LTS_MAJOR_VERSION" - [ "$status" -eq 0 ] - [ "$output" = "7" ] -} - @test "version format validation" { run validate_version_format "8.0.14" "dotnet" [ "$status" -eq 0 ] diff --git a/tests/unit/test_profile_logic.bats b/tests/unit/test_profile_logic.bats new file mode 100644 index 0000000..cc8e2b9 --- /dev/null +++ b/tests/unit/test_profile_logic.bats @@ -0,0 +1,157 @@ +#!/usr/bin/env bats + +# Unit tests for PowerShell profile environment variable logic +# These tests validate the profile's behavior in isolation + +load '../test_helper' + +# Test environment variable parsing logic +@test "profile script exists" { + [ -f "config/Microsoft.PowerShell_profile.ps1" ] +} + +@test "profile contains ENABLE_OHMYPOSH check" { + grep -q "ENABLE_OHMYPOSH" config/Microsoft.PowerShell_profile.ps1 +} + +@test "profile contains OHMYPOSH_THEME check" { + grep -q "OHMYPOSH_THEME" config/Microsoft.PowerShell_profile.ps1 +} + +@test "profile contains SHOW_CONTAINER_INFO check" { + grep -q "SHOW_CONTAINER_INFO" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile checks for both 'false' and '0' for ENABLE_OHMYPOSH +@test "profile checks for ENABLE_OHMYPOSH=false" { + grep -q "ENABLE_OHMYPOSH.*'false'" config/Microsoft.PowerShell_profile.ps1 +} + +@test "profile checks for ENABLE_OHMYPOSH=0" { + grep -q "ENABLE_OHMYPOSH.*'0'" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile checks for both 'false' and '0' for SHOW_CONTAINER_INFO +@test "profile checks for SHOW_CONTAINER_INFO=false" { + grep -q "SHOW_CONTAINER_INFO.*'false'" config/Microsoft.PowerShell_profile.ps1 +} + +@test "profile checks for SHOW_CONTAINER_INFO=0" { + grep -q "SHOW_CONTAINER_INFO.*'0'" config/Microsoft.PowerShell_profile.ps1 +} + +# Test URL detection logic for OHMYPOSH_THEME +@test "profile contains URL detection regex for OHMYPOSH_THEME" { + grep -q "https\\?://" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile references the embedded theme path +@test "profile references embedded Blue PSL 10K theme path" { + grep -q "/home/coder/.config/powershell/blue-psl-10k.omp.json" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile references oh-my-posh binary path +@test "profile references oh-my-posh binary path" { + grep -q "/usr/local/bin/oh-my-posh" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile constructs GitHub URL for built-in themes +@test "profile constructs GitHub URL for built-in themes" { + grep -q "githubusercontent.com/JanDeDobbeleer/oh-my-posh" config/Microsoft.PowerShell_profile.ps1 +} + +# Test fallback logic +@test "profile contains fallback logic for failed theme loading" { + # Profile should have try-catch or conditional logic for fallback + grep -q "try\|catch\|elseif.*embeddedTheme" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile defines Show-ContainerInfo function +@test "profile defines Show-ContainerInfo function" { + grep -q "function Show-ContainerInfo" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile creates info alias +@test "profile creates info alias for Show-ContainerInfo" { + grep -q "Set-Alias.*info.*Show-ContainerInfo" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile checks for interactive session (ConsoleHost) +@test "profile checks for ConsoleHost for auto-display" { + grep -q "ConsoleHost" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile imports Terminal-Icons module +@test "profile imports Terminal-Icons module" { + grep -q "Import-Module Terminal-Icons" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile imports PSReadLine module +@test "profile imports PSReadLine module" { + grep -q "Import-Module PSReadLine" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile configures PSReadLine +@test "profile configures PSReadLine prediction source" { + grep -q "Set-PSReadLineOption.*PredictionSource" config/Microsoft.PowerShell_profile.ps1 +} + +@test "profile configures PSReadLine prediction view style" { + grep -q "Set-PSReadLineOption.*PredictionViewStyle" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile has recursive loading protection +@test "profile has recursive loading protection" { + grep -q "OhMyPoshProfileLoaded" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile sets ErrorActionPreference +@test "profile sets ErrorActionPreference to SilentlyContinue during module loading" { + grep -q "ErrorActionPreference.*SilentlyContinue" config/Microsoft.PowerShell_profile.ps1 +} + +@test "profile resets ErrorActionPreference to Continue" { + grep -q "ErrorActionPreference.*Continue" config/Microsoft.PowerShell_profile.ps1 +} + +# Test Show-ContainerInfo function content +@test "Show-ContainerInfo displays PowerShell version" { + grep -q "PSVersionTable.PSVersion" config/Microsoft.PowerShell_profile.ps1 +} + +@test "Show-ContainerInfo displays .NET version" { + grep -q "FrameworkDescription" config/Microsoft.PowerShell_profile.ps1 +} + +@test "Show-ContainerInfo displays OS information" { + grep -q "OSDescription" config/Microsoft.PowerShell_profile.ps1 +} + +@test "Show-ContainerInfo displays architecture" { + grep -q "OSArchitecture" config/Microsoft.PowerShell_profile.ps1 +} + +@test "Show-ContainerInfo checks for git" { + grep -q "Get-Command git" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile validates oh-my-posh binary exists before using it +@test "profile checks if oh-my-posh binary exists" { + grep -q "Test-Path.*ohmyposhPath" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile calls oh-my-posh init with pwsh +@test "profile calls oh-my-posh init with pwsh" { + grep -q "init pwsh" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile checks LASTEXITCODE after oh-my-posh init +@test "profile checks LASTEXITCODE after oh-my-posh init" { + grep -q "LASTEXITCODE" config/Microsoft.PowerShell_profile.ps1 +} + +# Test that profile uses Invoke-Expression for oh-my-posh init script +@test "profile uses Invoke-Expression for oh-my-posh init script" { + grep -q "Invoke-Expression" config/Microsoft.PowerShell_profile.ps1 +} +