OpenWriterControle/scripts/tests/test-e2e-install.sh
Darren Hinde 013682c499
fix: resolve installer failures and add comprehensive validation (#189)
* fix: ContextScout falls back to global core/ when local core/ missing

Users who install OAC globally have core standards at
~/.config/opencode/context/core/ but no local core/ directory.
ContextScout now does a one-time check on startup: if local
core/navigation.md doesn't exist, it checks the global path
from paths.json. This resolves the ENOENT errors when agents
try to read core/standards/ files that only exist globally.

- paths.json: enabled global path (~/.config/opencode/context)
- contextscout.md: added global_fallback rule with 2-glob cap
- Fallback is ONLY for core/ files, never project-intelligence

* docs: add context resolution explanation to README

Explains how ContextScout resolves context files: local-first,
global fallback only for core/ files, project-intelligence always
local. Includes flow diagram, key rules, and common setup table.

* fix: resolve installer failures and add comprehensive validation

## Summary
Fixes critical installer failures where ContextScout and other components couldn't find their configuration files after installation. Adds comprehensive validation system to prevent future issues.

## Problems Fixed

### 1. Missing Critical Files (13 dead registry references)
Files were referenced in registry but didn't exist on disk:
- workflows-delegation (split into 3 files)
- design-iteration (split into 8 files)
- animation-patterns (split into 6 files)
- adding-agent (split into 2 files)
- adding-skill (split into 3 files)
- navigation-design (split into 2 files)
- external-libraries (split into 3 files)
- claude-code-docs/* (directory removed)

### 2. Missing Infrastructure Files
ContextScout failed after installation because 2 critical files weren't in registry:
- paths.json - Context root configuration
- navigation.md - Root navigation for discovery

### 3. Profile Inconsistencies
Profiles referenced components that don't exist:
- context:adding-skill → context:adding-skill-basics
- context:animation-patterns → animation-basics/components/advanced
- context:design-assets (removed - doesn't exist)
- context:to-be-consumed/* (removed - directory doesn't exist)
- skill:context-manager → subagent:context-manager

## Changes Made

### Registry (registry.json)
- Removed 13 dead references
- Added 27 new split-file entries
- Added 2 critical infrastructure entries
- Fixed all 5 profile configurations
- Updated ContextScout dependencies
- Updated agent-metadata.json dependencies

### New Validation Scripts
- scripts/registry/check-dependencies.ts - Comprehensive dependency checker
- scripts/tests/test-installer-files.sh - Installer simulation test
- scripts/registry/fix-registry.py - Automated registry fixer
- scripts/hooks/pre-commit - Git pre-commit hook

### Documentation
- docs/maintenance/REGISTRY_FIXES_SUMMARY.md
- docs/maintenance/CONTEXTSCOUT_FIX.md
- docs/maintenance/REGISTRY_VALIDATION.md

## Validation Results

Before:
- 13 missing files in registry
- 78 orphaned files on disk
- 3 missing dependencies
- Installer would fail

After:
- 244 total paths, 0 missing
- 262 dependency checks, 0 failures
- 0 orphaned dependencies
- All profiles consistent
- Installer works correctly

## Testing

```bash
# Registry validation
bun run scripts/registry/validate-registry.ts
# ✓ All 244 paths valid

# Dependency checking
bun run scripts/registry/check-dependencies.ts
# ✓ All 262 checks passed

# Installer test
./scripts/tests/test-installer-files.sh --local --profile=essential
# ✓ All files accessible
```

## Usage

### Run validation before commits:
```bash
bun run scripts/registry/check-dependencies.ts
```

### Install pre-commit hook:
```bash
cp scripts/hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
```

### Test installer:
```bash
./scripts/tests/test-installer-files.sh --local --profile=essential
```

## Impact

This fix ensures:
- ✓ Installer downloads all required files
- ✓ ContextScout works immediately after install
- ✓ No broken dependencies
- ✓ No missing profile components
- ✓ Future issues caught by validation

## Breaking Changes

None - all changes are additive or fix broken references.

## Related

- Fixes: ContextScout failing after installation
- Prevents: Missing file errors during install
- Adds: Comprehensive validation system

* fix: resolve shellcheck warnings in test scripts

- Remove unused REPO_URL variable from test-installer-files.sh
- Add shellcheck disable comments for cleanup functions used via trap
- Fixes CI failures in ShellCheck Analysis workflow

* fix: resolve shellcheck errors across all scripts

Fixed arithmetic expansion issues and code quality warnings:
- Changed ((var++)) to POSIX-compliant 1 syntax
- Fixed unquoted variables and grep pipe issues (SC2002, SC2143)
- Added shellcheck disable comments for intentional patterns
- Fixed variable initialization and return statement placement

Scripts fixed:
- scripts/tests/*.sh (5 files)
- scripts/registry/*.sh (4 files)
- scripts/validation/*.sh (2 files)
- scripts/*.sh (2 files)
- evals/framework/scripts/*.sh (2 files)

All scripts now pass shellcheck --severity=warning

* chore: trigger CI shellcheck validation
2026-02-06 17:07:42 +00:00

289 lines
8.2 KiB
Bash
Executable file

#!/usr/bin/env bash
set -e
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
TEST_DIR="/tmp/opencode-e2e-test-$$"
PASSED=0
FAILED=0
pass() {
echo -e "${GREEN}✓${NC} $1"
PASSED=$((PASSED + 1))
}
fail() {
echo -e "${RED}✗${NC} $1"
FAILED=$((FAILED + 1))
}
warn() {
echo -e "${YELLOW}⚠${NC} $1"
}
setup() {
rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR"
}
# shellcheck disable=SC2329
cleanup() {
rm -rf "$TEST_DIR"
}
trap cleanup EXIT
print_header() {
echo -e "${CYAN}${BOLD}"
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ End-to-End Installation Test Suite ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
}
test_essential_profile() {
echo -e "\n${BOLD}Test: Essential Profile Installation${NC}"
local install_dir="$TEST_DIR/essential/.opencode"
bash "$REPO_ROOT/install.sh" essential --install-dir="$install_dir" > "$TEST_DIR/essential.log" 2>&1
local expected_files=(
"agent/core/openagent.md"
"agent/subagents/core/task-manager.md"
"agent/subagents/core/documentation.md"
"command/context.md"
"command/clean.md"
"context/core/essential-patterns.md"
"context/project/project-context.md"
)
local missing=0
for file in "${expected_files[@]}"; do
if [ -f "$install_dir/$file" ]; then
pass "Found: $file"
else
fail "Missing: $file"
missing=$((missing + 1))
fi
done
if [ $missing -eq 0 ]; then
pass "Essential profile: all expected files present"
fi
}
test_developer_profile() {
echo -e "\n${BOLD}Test: Developer Profile Installation${NC}"
local install_dir="$TEST_DIR/developer/.opencode"
bash "$REPO_ROOT/install.sh" developer --install-dir="$install_dir" > "$TEST_DIR/developer.log" 2>&1
local expected_files=(
"agent/core/openagent.md"
"agent/core/opencoder.md"
"agent/subagents/code/tester.md"
"agent/subagents/code/reviewer.md"
"agent/subagents/code/build-agent.md"
"command/commit.md"
"command/test.md"
"context/core/standards/code.md"
)
local found=0
for file in "${expected_files[@]}"; do
if [ -f "$install_dir/$file" ]; then
found=$((found + 1))
fi
done
if [ $found -ge 6 ]; then
pass "Developer profile: $found/${#expected_files[@]} key files present"
else
fail "Developer profile: only $found/${#expected_files[@]} key files found"
fi
}
test_custom_install_dir() {
echo -e "\n${BOLD}Test: Custom Installation Directory${NC}"
local custom_dir="$TEST_DIR/custom-location/my-agents"
bash "$REPO_ROOT/install.sh" essential --install-dir="$custom_dir" > "$TEST_DIR/custom.log" 2>&1
if [ -d "$custom_dir" ]; then
pass "Custom directory created: $custom_dir"
else
fail "Custom directory not created"
fi
if [ -f "$custom_dir/agent/core/openagent.md" ]; then
pass "Files installed to custom location"
else
fail "Files not found in custom location"
fi
}
test_skip_existing_files() {
echo -e "\n${BOLD}Test: Skip Existing Files Strategy${NC}"
local install_dir="$TEST_DIR/skip-test/.opencode"
mkdir -p "$install_dir/agent/core"
echo "CUSTOM CONTENT - DO NOT OVERWRITE" > "$install_dir/agent/core/openagent.md"
bash "$REPO_ROOT/install.sh" essential --install-dir="$install_dir" > "$TEST_DIR/skip.log" 2>&1
local content
content=$(cat "$install_dir/agent/core/openagent.md")
if [[ "$content" == "CUSTOM CONTENT - DO NOT OVERWRITE" ]]; then
pass "Existing file preserved (skip strategy working)"
else
fail "Existing file was overwritten"
fi
}
test_file_content_validity() {
echo -e "\n${BOLD}Test: File Content Validity${NC}"
local install_dir="$TEST_DIR/content-test/.opencode"
bash "$REPO_ROOT/install.sh" essential --install-dir="$install_dir" > "$TEST_DIR/content.log" 2>&1
local agent_file="$install_dir/agent/core/openagent.md"
if [ -f "$agent_file" ]; then
if grep -q "OpenAgent\|openagent" "$agent_file"; then
pass "Agent file contains expected content"
else
fail "Agent file appears empty or corrupted"
fi
local size
size=$(wc -c < "$agent_file")
if [ "$size" -gt 100 ]; then
pass "Agent file has substantial content ($size bytes)"
else
fail "Agent file too small ($size bytes)"
fi
else
fail "Agent file not found"
fi
}
test_directory_structure() {
echo -e "\n${BOLD}Test: Directory Structure${NC}"
local install_dir="$TEST_DIR/structure-test/.opencode"
bash "$REPO_ROOT/install.sh" developer --install-dir="$install_dir" > "$TEST_DIR/structure.log" 2>&1
local expected_dirs=(
"agent"
"agent/core"
"agent/subagents"
"command"
"context"
"context/core"
)
for dir in "${expected_dirs[@]}"; do
if [ -d "$install_dir/$dir" ]; then
pass "Directory exists: $dir"
else
fail "Missing directory: $dir"
fi
done
}
test_registry_consistency() {
echo -e "\n${BOLD}Test: Registry Consistency${NC}"
if [ -f "$REPO_ROOT/registry.json" ]; then
if command -v jq &> /dev/null; then
local agent_count
agent_count=$(jq '.components.agents | length' "$REPO_ROOT/registry.json")
if [ "$agent_count" -gt 0 ]; then
pass "Registry has $agent_count agents defined"
else
fail "Registry has no agents"
fi
local profile_count
profile_count=$(jq '.profiles | keys | length' "$REPO_ROOT/registry.json")
if [ "$profile_count" -ge 4 ]; then
pass "Registry has $profile_count profiles"
else
fail "Registry missing profiles (found $profile_count)"
fi
else
warn "jq not installed, skipping JSON validation"
fi
else
fail "registry.json not found"
fi
}
test_help_and_list() {
echo -e "\n${BOLD}Test: Help and List Commands${NC}"
if bash "$REPO_ROOT/install.sh" --help 2>&1 | grep -q "Usage:"; then
pass "Help command works"
else
fail "Help command failed"
fi
if bash "$REPO_ROOT/install.sh" list 2>&1 | grep "Available Components\|Agents" > /dev/null; then
pass "List command works"
else
fail "List command failed"
fi
}
main() {
print_header
echo "Repository: $REPO_ROOT"
echo "Test directory: $TEST_DIR"
echo ""
setup
test_help_and_list
test_essential_profile
test_developer_profile
test_custom_install_dir
test_skip_existing_files
test_file_content_validity
test_directory_structure
test_registry_consistency
echo ""
echo -e "${BOLD}═══════════════════════════════════════════════════════════════${NC}"
echo -e "${BOLD}E2E Test Summary${NC}"
echo -e " ${GREEN}Passed: $PASSED${NC}"
echo -e " ${RED}Failed: $FAILED${NC}"
echo -e "${BOLD}═══════════════════════════════════════════════════════════════${NC}"
if [ $FAILED -gt 0 ]; then
echo -e "\n${RED}Some tests failed!${NC}"
exit 1
else
echo -e "\n${GREEN}All E2E tests passed!${NC}"
exit 0
fi
}
main "$@"