Skip to content

Commit 01d209a

Browse files
test(api): add dry-run coverage to smoke evaluator path (#24)
Adds generic dry-run coverage to the smoke test path, ensuring that the /launch/dry-run endpoint contract and stable response fields are exercised. Includes a new example curl script and Makefile target for local testing.
1 parent ccf248e commit 01d209a

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help build build-agent build-control-plane test test-agent test-control-plane fmt lint doctor dev-preflight dev-up dev-down demo dev-db-reset example-intake example-schedule example-launch-validate example-launch-execute example-readiness example-orphans
1+
.PHONY: help build build-agent build-control-plane test test-agent test-control-plane fmt lint doctor dev-preflight dev-up dev-down demo dev-db-reset example-intake example-schedule example-launch-validate example-launch-dry-run example-launch-execute example-readiness example-orphans
22

33
# Configuration
44
BIN_DIR=bin
@@ -72,6 +72,9 @@ example-schedule: ## Run a workload eligibility evaluation explanation
7272
example-launch-validate: ## Validate a launch without executing it
7373
@bash examples/curls/launch-validate.sh
7474

75+
example-launch-dry-run: ## Dry-run a launch without executing it
76+
@bash examples/curls/launch-dry-run.sh
77+
7578
example-launch-execute: ## Execute a launch on a local runtime
7679
@bash examples/curls/launch-execute.sh
7780

examples/curls/launch-dry-run.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
API_BASE="${API_BASE:-http://127.0.0.1:9090}"
5+
PAYLOAD_FILE="/tmp/payload.json"
6+
SPEC_FILE="examples/launch-specs/cloudhypervisor-validate.json"
7+
8+
if [ ! -f "$PAYLOAD_FILE" ]; then
9+
echo "Error: /tmp/payload.json is missing. Please run 'make example-intake' first to ingest a node."
10+
exit 1
11+
fi
12+
13+
NODE_ID=$(grep -o '"hostname": *"[^"]*"' "$PAYLOAD_FILE" | cut -d'"' -f4 | head -n 1)
14+
if [ -z "$NODE_ID" ]; then
15+
NODE_ID="unknown"
16+
fi
17+
18+
TMP_SPEC=$(mktemp)
19+
trap 'rm -f "$TMP_SPEC"' EXIT
20+
21+
# Safely replace PUT_NODE_ID_HERE with the dynamic NODE_ID and override launch_mode to DryRun
22+
if command -v python3 >/dev/null 2>&1; then
23+
python3 -c "import json, sys; d = json.load(sys.stdin); d['node_id'] = '${NODE_ID}'; d['launch_mode'] = 'DryRun'; json.dump(d, sys.stdout)" < "$SPEC_FILE" > "$TMP_SPEC"
24+
curl -s -X POST -H "Content-Type: application/json" -d @"$TMP_SPEC" "${API_BASE}/api/v1alpha1/launch/dry-run" | python3 -m json.tool || true
25+
else
26+
sed "s/PUT_NODE_ID_HERE/${NODE_ID}/g" "$SPEC_FILE" | sed 's/"launch_mode": "Validate"/"launch_mode": "DryRun"/g' > "$TMP_SPEC"
27+
curl -s -X POST -H "Content-Type: application/json" -d @"$TMP_SPEC" "${API_BASE}/api/v1alpha1/launch/dry-run"
28+
echo ""
29+
fi

scripts/smoke-test.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,40 @@ fi
109109
python3 -m json.tool < "$VALIDATE_RESP" > /dev/null
110110
echo "Launch Validate API success. (is_valid status not asserted for generic CI environments)"
111111

112+
echo "--------------------------------------------"
113+
echo "5. Launch Dry-Run (POST /api/v1alpha1/launch/dry-run)..."
114+
LAUNCH_SPEC_DRYRUN="examples/launch-specs/cloudhypervisor-validate.json"
115+
TMP_SPEC_DRYRUN="$TMP_DIR/launch_spec_dryrun.json"
116+
DRYRUN_RESP="$TMP_DIR/dryrun_resp.json"
117+
118+
# Safely inject node_id and override launch_mode
119+
python3 -c "import json, sys; d = json.load(sys.stdin); d['node_id'] = '${NODE_ID}'; d['launch_mode'] = 'DryRun'; json.dump(d, sys.stdout)" < "$LAUNCH_SPEC_DRYRUN" > "$TMP_SPEC_DRYRUN"
120+
121+
HTTP_CODE=$(curl -s -w "%{http_code}" -X POST -H "Content-Type: application/json" -d @"$TMP_SPEC_DRYRUN" "${API_BASE}/api/v1alpha1/launch/dry-run" -o "$DRYRUN_RESP")
122+
123+
if [ "$HTTP_CODE" -ne 200 ]; then
124+
echo "Error: Launch Dry-Run API failed with HTTP $HTTP_CODE"
125+
cat "$DRYRUN_RESP"
126+
exit 1
127+
fi
128+
python3 -m json.tool < "$DRYRUN_RESP" > /dev/null
129+
130+
# Assert stable fields exist in response regardless of actual is_valid boolean status
131+
python3 -c "import json, sys
132+
try:
133+
d = json.load(open('$DRYRUN_RESP'))
134+
assert 'validation' in d, 'missing validation object'
135+
v = d['validation']
136+
assert 'is_valid' in v, 'missing is_valid'
137+
if not v['is_valid']:
138+
assert 'rejected_backends' in v or 'backend_rejection_evidence' in v, 'missing rejection evidence'
139+
except Exception as e:
140+
print(f'Assertion Error: {e}')
141+
sys.exit(1)
142+
" || { echo "Error: Launch Dry-Run assertions failed"; cat "$DRYRUN_RESP"; exit 1; }
143+
144+
echo "Launch Dry-Run API success. (is_valid status not asserted for generic CI environments)"
145+
112146
echo "--------------------------------------------"
113147
echo "Smoke test completed successfully."
114148
exit 0

0 commit comments

Comments
 (0)