diff --git a/docs/scripts.md b/docs/scripts.md index 0f16aaa..fb7130f 100644 --- a/docs/scripts.md +++ b/docs/scripts.md @@ -15,7 +15,7 @@ Run scripts from the repository root. PowerShell and Bash commands have equivale | Script | Purpose | | --- | --- | -| `commands/build.ps1`, `commands/build.sh` | Generate four client packages in `generated/` from the shared skill catalog. | +| `commands/build.ps1`, `commands/build.sh` | Generate four client packages in `generated/` from the shared skill catalog. `-SkipCodexSchema` / `--skip-codex-schema` skips the Codex schema check; Claude-only installs and updates pass it. | | `commands/check-capabilities.ps1`, `commands/check-capabilities.sh` | Check required tools and versions. | | `commands/install.ps1`, `commands/install.sh` | Install a selected client configuration. | | `commands/update.ps1`, `commands/update.sh` | Update an existing installation; Quick reuses saved choices. | diff --git a/scripts/commands/build.ps1 b/scripts/commands/build.ps1 index 3496a1c..a062ac9 100644 --- a/scripts/commands/build.ps1 +++ b/scripts/commands/build.ps1 @@ -1,5 +1,5 @@ [CmdletBinding()] -param([switch]$Summary) +param([switch]$Summary, [switch]$SkipCodexSchema) $ErrorActionPreference = 'Stop' $root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent . (Join-Path $root 'shared/hooks/scripts/Resolve-Python.ps1') @@ -217,7 +217,8 @@ foreach ($shell in @('powershell','bash')) { $settingsPath = Join-Path $output "claude-$shell/settings.json" Invoke-Python (Join-Path $root 'scripts/checks/validate-config.py') $tomlPath $settingsPath if ($LASTEXITCODE -ne 0) { throw "Generated configuration validation failed for $shell." } - Test-CodexSchema $tomlPath + # Claude-only installs and updates never use the Codex packages, so their schema check is skipped. + if (-not $SkipCodexSchema) { Test-CodexSchema $tomlPath } } $leftoverPlaceholders = @(Get-ChildItem $output -File -Recurse | ForEach-Object { diff --git a/scripts/commands/build.sh b/scripts/commands/build.sh index b717a71..98fb9ab 100644 --- a/scripts/commands/build.sh +++ b/scripts/commands/build.sh @@ -1,9 +1,11 @@ #!/usr/bin/env bash set -euo pipefail summary=false +skip_codex_schema=false while [ $# -gt 0 ]; do case "$1" in --summary) summary=true; shift ;; + --skip-codex-schema) skip_codex_schema=true; shift ;; *) printf 'Unknown argument: %s\n' "$1" >&2; exit 1 ;; esac done @@ -216,7 +218,10 @@ done toml_path="$output/codex-$shell/config.toml" settings_path="$output/claude-$shell/settings.json" run_python "$root/scripts/checks/validate-config.py" "$toml_path" "$settings_path" -if command -v codex >/dev/null; then +# Claude-only installs and updates never use the Codex packages, so their schema check is skipped. +if [ "$skip_codex_schema" = true ]; then + : +elif command -v codex >/dev/null; then schema_home=$(mktemp -d) cp "$toml_path" "$schema_home/config.toml" CODEX_HOME="$schema_home" codex --strict-config --help >/dev/null diff --git a/scripts/commands/install.ps1 b/scripts/commands/install.ps1 index aa117af..1c3acc0 100644 --- a/scripts/commands/install.ps1 +++ b/scripts/commands/install.ps1 @@ -26,7 +26,7 @@ if (-not $DryRun -and (Test-AnyManifestPresent (Get-InstallDestinations -HomePat $options = Read-InstallOptions -HomePath $homePath -RepositoryRoot $root -Client $Client -DryRun:$DryRun $buildScript = Join-Path $root 'scripts/commands/build.ps1' -& $buildScript -Summary:$Summary +& $buildScript -Summary:$Summary -SkipCodexSchema:($Client -eq 'Claude') if (-not $?) { throw 'Build failed. Installation was not started.' } $generated = Join-Path $root 'generated' if (-not (Test-Path $generated)) { throw 'Generated output is missing after a successful build.' } diff --git a/scripts/commands/install.sh b/scripts/commands/install.sh index b59b370..d539aa4 100644 --- a/scripts/commands/install.sh +++ b/scripts/commands/install.sh @@ -39,6 +39,7 @@ read_install_options build_args=() [ "$summary" = false ] || build_args+=(--summary) +[ "$client" != claude ] || build_args+=(--skip-codex-schema) bash "$root/scripts/commands/build.sh" "${build_args[@]}" generated="$root/generated" [ -d "$generated" ] || { printf 'Generated output is missing after a successful build.\n' >&2; exit 1; } diff --git a/scripts/commands/update.ps1 b/scripts/commands/update.ps1 index fb6c30f..e609e36 100644 --- a/scripts/commands/update.ps1 +++ b/scripts/commands/update.ps1 @@ -33,7 +33,7 @@ if (-not $DryRun -and -not (Test-AllManifestsPresent (Get-InstallDestinations -H $options = if ($Quick) { $saved } else { Read-InstallOptions -HomePath $homePath -RepositoryRoot $root -Client $Client -DryRun:$DryRun } $buildScript = Join-Path $root 'scripts/commands/build.ps1' -& $buildScript -Summary:$Summary +& $buildScript -Summary:$Summary -SkipCodexSchema:($Client -eq 'Claude') if (-not $?) { throw 'Build failed. Update was not started.' } $generated = Join-Path $root 'generated' if (-not (Test-Path $generated)) { throw 'Generated output is missing after a successful build.' } diff --git a/scripts/commands/update.sh b/scripts/commands/update.sh index a0ed139..dfb40e7 100644 --- a/scripts/commands/update.sh +++ b/scripts/commands/update.sh @@ -45,6 +45,7 @@ if [ "$quick" = false ]; then read_install_options; fi build_args=() [ "$summary" = false ] || build_args+=(--summary) +[ "$client" != claude ] || build_args+=(--skip-codex-schema) bash "$root/scripts/commands/build.sh" "${build_args[@]}" generated="$root/generated" [ -d "$generated" ] || { printf 'Generated output is missing after a successful build.\n' >&2; exit 1; } diff --git a/scripts/tests/test-build-validation.ps1 b/scripts/tests/test-build-validation.ps1 index 9572062..46bd694 100644 --- a/scripts/tests/test-build-validation.ps1 +++ b/scripts/tests/test-build-validation.ps1 @@ -43,6 +43,15 @@ $actualFiles = @(Get-ChildItem $baselineGenerated -File -Recurse | ForEach-Objec if (Compare-Object $expectedFiles $actualFiles) { throw 'generated/ is incomplete after two parallel builds.' } if (@(Get-ChildItem $baseline -Force | Where-Object Name -like 'generated.*').Count) { throw 'Parallel builds left a build directory, retired tree, or lock behind.' } +# A Codex CLI that rejects every config proves the schema check runs by default and is skipped on request. +function codex { $global:LASTEXITCODE = 1; 'unsupported setting' } +try { + & (Join-Path $baseline 'scripts/commands/build.ps1') -Summary -SkipCodexSchema 3>&1 | Out-Null + $schemaChecked = $false + try { & (Join-Path $baseline 'scripts/commands/build.ps1') -Summary 2>&1 | Out-Null } catch { $schemaChecked = $_.Exception.Message -match 'Codex schema validation failed' } + if (-not $schemaChecked) { throw 'The build must run the Codex schema check unless it is skipped.' } +} finally { Remove-Item function:codex -ErrorAction SilentlyContinue } + Test-BuildFails 'invalid Claude settings.json' { param($copy) Add-Content (Join-Path $copy 'adapters/claude/config/settings.json') '} this is not json {' diff --git a/scripts/tests/test-build-validation.sh b/scripts/tests/test-build-validation.sh index b2ebe26..f9b8132 100644 --- a/scripts/tests/test-build-validation.sh +++ b/scripts/tests/test-build-validation.sh @@ -45,6 +45,17 @@ wait "$second_build" || { printf 'Parallel build 2 failed:\n%s\n' "$(cat "$work/ [ "$(cd "$baseline/generated" && find . -type f | sort)" = "$expected_files" ] || { printf 'generated/ is incomplete after two parallel builds.\n' >&2; exit 1; } [ -z "$(find "$baseline" -maxdepth 1 -name 'generated.*' -print -quit)" ] || { printf 'Parallel builds left a build directory, retired tree, or lock behind.\n' >&2; exit 1; } +# A Codex CLI that rejects every config proves the schema check runs by default and is skipped on request. +mkdir -p "$work/fake-codex" +printf '#!/usr/bin/env bash\nexit 1\n' > "$work/fake-codex/codex" +chmod +x "$work/fake-codex/codex" +PATH="$work/fake-codex:$PATH" bash "$baseline/scripts/commands/build.sh" --summary --skip-codex-schema >/dev/null 2>&1 \ + || { printf 'The build must skip the Codex schema check on request.\n' >&2; exit 1; } +if PATH="$work/fake-codex:$PATH" bash "$baseline/scripts/commands/build.sh" --summary >/dev/null 2>&1; then + printf 'The build must run the Codex schema check unless it is skipped.\n' >&2 + exit 1 +fi + mutate_invalid_json() { printf '} this is not json {' >> "$1/adapters/claude/config/settings.json" }