Skip to content

Commit fd89156

Browse files
committed
test(scripts): challenge suite fixes from running validation
- 03: assert tags via `.tags` (the retrieve API field) not `.runTags`. - 04, 13: pre-warm the gate so the same-key burst all reaches the buffer. Without the pre-warm, the first 1-2 same-key triggers land in PG during gate-transition and create a second race-winner (separate concern from B6's buffer-side dedup, surfaced for follow-up).
1 parent 4e7d5d8 commit fd89156

3 files changed

Lines changed: 42 additions & 7 deletions

File tree

scripts/mollifier-challenge/03-mutations-on-buffered.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ else
2323
fail "POST /tags status=$(cat "$WORK/last.status")"
2424
fi
2525
api GET "/api/v3/runs/$BUFFERED_ID"
26-
if body_matches '.runTags // [] | (any(. == "challenge-tag-a") and any(. == "challenge-tag-b"))'; then
26+
if body_matches '.tags // [] | (any(. == "challenge-tag-a") and any(. == "challenge-tag-b"))'; then
2727
pass "retrieve shows both new tags on the snapshot"
2828
else
29-
fail "retrieve runTags=$(last_body | jq -c '.runTags // []')"
29+
fail "retrieve tags=$(last_body | jq -c '.tags // []')"
3030
fi
3131

3232
# Idempotent dedup
3333
api POST "/api/v1/runs/$BUFFERED_ID/tags" '{"tags":["challenge-tag-a"]}'
3434
api GET "/api/v3/runs/$BUFFERED_ID"
35-
tag_count=$(last_body | jq '.runTags // [] | map(select(. == "challenge-tag-a")) | length')
35+
tag_count=$(last_body | jq '.tags // [] | map(select(. == "challenge-tag-a")) | length')
3636
if [[ "$tag_count" == "1" ]]; then
3737
pass "duplicate tag deduplicated by mutateSnapshot Lua"
3838
else

scripts/mollifier-challenge/04-idempotency-collision.sh

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,28 @@ header "Idempotency collision in burst"
1111
KEY="challenge-idem-$(date +%s)-$RANDOM"
1212
info "idempotencyKey=$KEY"
1313

14-
# Fire BURST_SIZE triggers simultaneously, all using the same key. With
15-
# the gate tripped, some will mollify and SETNX the lookup. Subsequent
16-
# triggers with the same key should return the SETNX winner's runId
14+
# Pre-warm the gate FIRST. The Q5 design assumes the same-key burst all
15+
# reaches the buffer — that's where SETNX is the race-winner. If the
16+
# gate is still cold, the first 1-2 triggers go to PG and the buffer
17+
# SETNX never sees them, producing two distinct race-winners (one PG,
18+
# one buffer). That PG+buffer race exists architecturally but it's a
19+
# separate concern from B6's buffer-side dedup, which is what this
20+
# script exercises.
21+
info "pre-warming the gate with $((BURST_SIZE / 2)) no-key triggers"
22+
warm_dir=$WORK/warm
23+
mkdir -p "$warm_dir"
24+
for i in $(seq 1 $((BURST_SIZE / 2))); do
25+
curl -s -o "$warm_dir/$i.json" -X POST \
26+
-H "Authorization: Bearer $API_KEY" \
27+
-H "Content-Type: application/json" \
28+
-d "{\"payload\":{\"warm\":$i}}" \
29+
"$API_BASE/api/v1/tasks/$TASK_ID/trigger" &
30+
done
31+
wait
32+
33+
# Fire BURST_SIZE same-key triggers simultaneously. The gate is now
34+
# tripped, so all should mollify. SETNX serialises them — one wins, the
35+
# rest receive duplicate_idempotency with the winner's runId
1736
# (kind: duplicate_idempotency → isCached:true).
1837
burst_dir=$WORK/burst
1938
mkdir -p "$burst_dir"

scripts/mollifier-challenge/13-resume-parent-guard.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,23 @@ fi
2121
PARENT_ID=$(last_body | jq -r '.id')
2222
info "PG parent runId=$PARENT_ID"
2323

24-
# Step 2: burst children with a shared idempotency key → some mollified.
24+
# Pre-warm the gate. If the gate is cold, the first same-key triggers
25+
# would pass through to PG and the IdempotencyKeyConcern's PG-first
26+
# check would find a PG-cached row on the triggerAndWait — defeating
27+
# the test of the resumeParentOnCompletion guard. Pre-warming ensures
28+
# the same-key burst all reaches the buffer.
29+
warm_dir=$WORK/warm
30+
mkdir -p "$warm_dir"
31+
for i in $(seq 1 $((BURST_SIZE / 2))); do
32+
curl -s -o "$warm_dir/$i.json" -X POST \
33+
-H "Authorization: Bearer $API_KEY" \
34+
-H "Content-Type: application/json" \
35+
-d "{\"payload\":{\"warm\":$i}}" \
36+
"$API_BASE/api/v1/tasks/$TASK_ID/trigger" &
37+
done
38+
wait
39+
40+
# Step 2: burst children with a shared idempotency key → all mollified.
2541
KEY="challenge-andwait-$(date +%s)-$RANDOM"
2642
BURST_DIR=$WORK/burst
2743
mkdir -p "$BURST_DIR"

0 commit comments

Comments
 (0)