OpenWriterControle/scripts/validation/validate-test-suites.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

251 lines
7.9 KiB
Bash
Executable file

#!/bin/bash
# validate-test-suites.sh
# Validates all test suite JSON files against schema and checks paths exist
#
# Usage:
# ./scripts/validation/validate-test-suites.sh [agent]
# ./scripts/validation/validate-test-suites.sh openagent
# ./scripts/validation/validate-test-suites.sh --all
#
# Exit codes:
# 0 - All suites valid
# 1 - Validation errors found
# 2 - Missing dependencies
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Check for ajv-cli (JSON schema validator)
# Use npx to run from local node_modules
if ! command -v npx &> /dev/null; then
echo -e "${RED}❌ Error: npx not found (Node.js required)${NC}"
exit 2
fi
# Check if ajv-cli is installed
if ! (cd "$PROJECT_ROOT/evals/framework" && npx ajv validate -s /dev/null -d /dev/null 2>&1 | grep -q "valid"); then
echo -e "${RED}❌ Error: ajv-cli not found${NC}"
echo ""
echo "Install with: cd evals/framework && npm install"
echo "Or globally: npm install -g ajv-cli"
exit 2
fi
AJV_CMD="cd $PROJECT_ROOT/evals/framework && npx ajv"
# Parse arguments
AGENT="${1:-openagent}"
VALIDATE_ALL=false
if [[ "$1" == "--all" ]]; then
VALIDATE_ALL=true
fi
# Counters
TOTAL_SUITES=0
VALID_SUITES=0
INVALID_SUITES=0
TOTAL_ERRORS=0
TOTAL_WARNINGS=0
echo -e "${BLUE}🔍 Validating Test Suites${NC}"
echo ""
# Function to validate a single suite
validate_suite() {
local agent=$1
local suite_file=$2
local suite_name
suite_name=$(basename "$suite_file" .json)
TOTAL_SUITES=$((TOTAL_SUITES + 1))
echo -e "${BLUE}Validating:${NC} $agent/$suite_name"
local schema_file="$PROJECT_ROOT/evals/agents/$agent/config/suite-schema.json"
local tests_dir="$PROJECT_ROOT/evals/agents/$agent/tests"
local suite_valid=true
local suite_errors=0
local suite_warnings=0
# 1. Validate JSON syntax
if ! jq empty "$suite_file" 2>/dev/null; then
echo -e " ${RED}❌ Invalid JSON syntax${NC}"
suite_valid=false
suite_errors=$((suite_errors + 1))
INVALID_SUITES=$((INVALID_SUITES + 1))
TOTAL_ERRORS=$((TOTAL_ERRORS + 1))
return
fi
# 2. Validate against schema
if [[ -f "$schema_file" ]]; then
# shellcheck disable=SC2294
validation_output=$(eval "$AJV_CMD validate -s \"$schema_file\" -d \"$suite_file\" --strict=false 2>&1")
if ! echo "$validation_output" | grep -q "valid"; then
echo -e " ${RED}❌ Schema validation failed${NC}"
echo "$validation_output" | grep -v "valid" | sed 's/^/ /'
suite_valid=false
suite_errors=$((suite_errors + 1))
fi
else
echo -e " ${YELLOW}⚠️ Schema not found: $schema_file${NC}"
suite_warnings=$((suite_warnings + 1))
fi
# 3. Validate test paths exist
local missing_tests=()
local test_count=0
while IFS= read -r test_path; do
test_count=$((test_count + 1))
local full_path="$tests_dir/$test_path"
if [[ ! -f "$full_path" ]]; then
missing_tests+=("$test_path")
fi
done < <(jq -r '.tests[].path' "$suite_file")
# 4. Check test count matches
local declared_count
declared_count=$(jq -r '.totalTests' "$suite_file")
if [[ "$test_count" -ne "$declared_count" ]]; then
echo -e " ${YELLOW}⚠️ Test count mismatch: found $test_count, declared $declared_count${NC}"
suite_warnings=$((suite_warnings + 1))
fi
# 5. Report missing tests
if [[ ${#missing_tests[@]} -gt 0 ]]; then
echo -e " ${RED}❌ Missing test files (${#missing_tests[@]}):${NC}"
for missing in "${missing_tests[@]}"; do
echo -e " - $missing"
# Suggest similar files
local dir
dir=$(dirname "$missing")
local filename
filename=$(basename "$missing")
if [[ -d "$tests_dir/$dir" ]]; then
local similar
# shellcheck disable=SC2001
similar=$(find "$tests_dir/$dir" -name "*.yaml" -type f -exec basename {} \; | grep -i "$(echo "$filename" | cut -d'-' -f1)" | head -3)
if [[ -n "$similar" ]]; then
echo -e " ${YELLOW}Did you mean?${NC}"
echo "$similar" | sed 's/^/ - /'
fi
fi
done
suite_valid=false
suite_errors=$((suite_errors + ${#missing_tests[@]}))
fi
# 6. Summary for this suite
if [[ "$suite_valid" == true ]]; then
echo -e " ${GREEN}✅ Valid${NC} ($test_count tests)"
VALID_SUITES=$((VALID_SUITES + 1))
else
echo -e " ${RED}❌ Invalid${NC} ($suite_errors errors, $suite_warnings warnings)"
INVALID_SUITES=$((INVALID_SUITES + 1))
fi
TOTAL_ERRORS=$((TOTAL_ERRORS + suite_errors))
TOTAL_WARNINGS=$((TOTAL_WARNINGS + suite_warnings))
echo ""
}
# Validate suites
if [[ "$VALIDATE_ALL" == true ]]; then
# Validate all agents
for agent_dir in "$PROJECT_ROOT/evals/agents"/*; do
if [[ -d "$agent_dir" ]]; then
agent=$(basename "$agent_dir")
# Check for suites directory
suites_dir="$agent_dir/config/suites"
if [[ -d "$suites_dir" ]]; then
for suite_file in "$suites_dir"/*.json; do
if [[ -f "$suite_file" ]]; then
validate_suite "$agent" "$suite_file"
fi
done
fi
# Check for legacy core-tests.json
legacy_file="$agent_dir/config/core-tests.json"
if [[ -f "$legacy_file" ]]; then
validate_suite "$agent" "$legacy_file"
fi
fi
done
else
# Validate specific agent
agent_dir="$PROJECT_ROOT/evals/agents/$AGENT"
if [[ ! -d "$agent_dir" ]]; then
echo -e "${RED}❌ Agent not found: $AGENT${NC}"
exit 1
fi
# Check for suites directory
suites_dir="$agent_dir/config/suites"
if [[ -d "$suites_dir" ]]; then
for suite_file in "$suites_dir"/*.json; do
if [[ -f "$suite_file" ]]; then
validate_suite "$AGENT" "$suite_file"
fi
done
fi
# Check for legacy core-tests.json
legacy_file="$agent_dir/config/core-tests.json"
if [[ -f "$legacy_file" ]]; then
validate_suite "$AGENT" "$legacy_file"
fi
if [[ $TOTAL_SUITES -eq 0 ]]; then
echo -e "${YELLOW}⚠️ No test suites found for agent: $AGENT${NC}"
echo ""
echo "Expected locations:"
echo " - $suites_dir/*.json"
echo " - $legacy_file"
exit 1
fi
fi
# Final summary
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo -e "${BLUE}Summary${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════${NC}"
echo -e "Total suites: $TOTAL_SUITES"
echo -e "${GREEN}Valid suites: $VALID_SUITES${NC}"
if [[ $INVALID_SUITES -gt 0 ]]; then
echo -e "${RED}Invalid suites: $INVALID_SUITES${NC}"
fi
if [[ $TOTAL_ERRORS -gt 0 ]]; then
echo -e "${RED}Total errors: $TOTAL_ERRORS${NC}"
fi
if [[ $TOTAL_WARNINGS -gt 0 ]]; then
echo -e "${YELLOW}Total warnings: $TOTAL_WARNINGS${NC}"
fi
echo ""
# Exit with appropriate code
if [[ $INVALID_SUITES -gt 0 ]] || [[ $TOTAL_ERRORS -gt 0 ]]; then
echo -e "${RED}❌ Validation failed${NC}"
exit 1
else
echo -e "${GREEN}✅ All suites valid${NC}"
exit 0
fi