Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/mock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ cd "$(dirname "$0")/.."
if [[ -n "$1" && "$1" != '--'* ]]; then
URL="$1"
shift
elif [[ -f .castiron.stats.yml && -f api_reference/openapi.transformed.yml ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Consume the actual sealed local API-reference contract

The producer seals the local reference at .castiron/api-definition.yaml in .castiron/generation-inputs.json with a SHA-256 digest; .castiron.stats.yml contains the nested generation-lineage marker, not openapi_transformed_spec_hash. With the actual artifact set, this condition is false, so scripts/mock and scripts/test select the network-backed .stats.yml URL and fail in a hermetic environment. If api_reference/openapi.transformed.yml also exists, awk finds no expected hash and mock startup fails before invoking Steady. Resolve the API-reference path from the canonical generation-input descriptor, verify its SHA-256 and a repo-local regular file, and use the network fallback only when the descriptor/reference pair is absent.

URL="api_reference/openapi.transformed.yml"
EXPECTED_HASH="$(awk '$1 == "openapi_transformed_spec_hash:" { print $2; exit }' .castiron.stats.yml)"
ACTUAL_HASH="$(node -e 'process.stdout.write(require("node:crypto").createHash("md5").update(require("node:fs").readFileSync(process.argv[1])).digest("hex"))' "$URL")"

if [[ -z "$EXPECTED_HASH" || "$ACTUAL_HASH" != "$EXPECTED_HASH" ]]; then
echo "Error: Local OpenAPI specification does not match generation metadata" >&2
exit 1
fi
else
URL="$(grep 'openapi_spec_url' .stats.yml | cut -d' ' -f2)"
fi
Expand Down
Loading