#!/usr/bin/env bash set -euo pipefail if [[ $# -ne 1 ]]; then printf 'Usage: %s \n' "${0##*/}" >&2 exit 2 fi change=$1 if [[ ! "$change" =~ ^[a-z0-9]+(-[a-z0-9]+)*$ ]]; then printf 'Invalid OpenSpec change name: %s\n' "$change" >&2 exit 2 fi script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) workspace=$(cd "$script_dir/../.." && pwd -P) change_dir="$workspace/specs/openspec/changes/$change" metadata_file="$change_dir/.openspec.yaml" design_file="$change_dir/design.md" for required_file in "$metadata_file" "$design_file"; do if [[ ! -f "$required_file" ]]; then printf 'Missing canonical change input: %s\n' "${required_file#$workspace/}" >&2 exit 1 fi done # shellcheck source=lib/delivery-map.sh source "$script_dir/lib/delivery-map.sh" wl_parse_delivery_map "$metadata_file" "$design_file" areas=("${wl_areas[@]}") affected_flags=("${wl_affected_flags[@]}") map_statuses=("${wl_map_statuses[@]}") contract_status=$wl_contract_status printf 'Delivery Map verified:' for index in 0 1 2 3; do printf ' %s=%s' "${areas[$index]}" "${map_statuses[$index]}" done printf '\n' printf 'Contract Gate Decision verified: runtime-openapi=%s\n' "$contract_status" run_gate() { local label=$1 shift printf '\n==> %s\n' "$label" "$@" } run_gate 'OpenSpec CLI contract' bash "$workspace/specs/scripts/verify-openspec-version.sh" run_gate 'OpenSpec planning structure' bash "$workspace/specs/scripts/verify-openspec-planning.sh" "$change" run_gate 'OpenSpec project schema' bash -c 'cd "$1" && openspec schema validate wealth-ledger-sdd' _ "$workspace/specs" run_gate 'OpenSpec change validation' bash -c 'cd "$1" && openspec validate "$2" --type change --strict --store wealth-ledger-specs' _ "$workspace/specs" "$change" run_gate 'OpenSpec main specs' bash -c 'cd "$1" && openspec validate --specs --strict --store wealth-ledger-specs' _ "$workspace/specs" run_gate 'OpenSpec authority' bash "$workspace/specs/scripts/verify-openspec-authority.sh" if [[ "${affected_flags[0]}" -eq 1 ]]; then run_gate 'Frontend canonical verification' npm --prefix "$workspace/frontend" run verify fi if [[ "${affected_flags[1]}" -eq 1 ]]; then run_gate 'Backend canonical verification' npm --prefix "$workspace/backend" run verify fi if [[ "${affected_flags[3]}" -eq 1 ]]; then run_gate 'Docs canonical verification' npm --prefix "$workspace/docs" run verify fi if [[ "$contract_status" == "required" ]]; then run_gate 'Runtime OpenAPI contract' bash "$workspace/specs/scripts/verify-runtime-openapi.sh" fi printf '\nWorkspace verification passed for %s.\n' "$change"