Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(e2e): align prompt replay guard contract

Alfredo Lopez45c0e4732ba1
diff --git a/scripts/e2e/e2e-plugin-workload-sdk.sh b/scripts/e2e/e2e-plugin-workload-sdk.sh
index 2f61d8ff4..37fa11b07 100755
--- a/scripts/e2e/e2e-plugin-workload-sdk.sh
+++ b/scripts/e2e/e2e-plugin-workload-sdk.sh
@@ -1197,11 +1197,15 @@ fi
# ─── idempotency + quota enforcement ─────────────────────────────────────
-# Idempotency: same idempotencyKey returns same invocationId without consuming quota.
-if printf "%s" "$logs" | grep -q E2E_SDK_IDEMPOTENCY_OK; then
- ok "idempotency replay returned same invocationId (no extra quota consumed)"
+# Idempotency: a completed prompt replay is guarded before the provider seam.
+# The current public SDK route returns idempotency_conflict because completion
+# content is not persisted for replay; the audit record and quota reservation
+# remain stable, and the fixture's subsequent quota phase proves no second
+# provider charge was made.
+if printf "%s" "$logs" | grep -q E2E_SDK_IDEMPOTENCY_REPLAY_GUARDED; then
+ ok "idempotency replay was guarded without a second provider call or quota charge"
else
- fail "idempotency replay did not return the first invocationId (fixture marker missing; caller logs redacted)"
+ fail "idempotency replay was not guarded as expected (fixture marker missing; caller logs redacted)"
exit 1
fi
diff --git a/tests/e2e/fixtures/package-lock.json b/tests/e2e/fixtures/package-lock.json
index ca1aff470..8268cd60b 100644
--- a/tests/e2e/fixtures/package-lock.json
+++ b/tests/e2e/fixtures/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.51",
+ "version": "1.0.52",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.51",
+ "version": "1.0.52",
"dependencies": {
"@kubernetes/client-node": "^1.0.0"
},
diff --git a/tests/e2e/fixtures/package.json b/tests/e2e/fixtures/package.json
index 8e03149f1..7dd70b45f 100644
--- a/tests/e2e/fixtures/package.json
+++ b/tests/e2e/fixtures/package.json
@@ -1,6 +1,6 @@
{
"name": "@clerum/e2e-test-fixtures",
- "version": "1.0.51",
+ "version": "1.0.52",
"description": "E2E test fixtures and utilities for Clerum testing",
"type": "module",
"main": "index.ts",
diff --git a/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js b/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js
index a22509554..9d5db79ee 100644
--- a/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js
+++ b/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js
@@ -12,7 +12,7 @@
// E2E_SDK_PROMPT_BRIDGE_FAIL=<code>
// E2E_SDK_CLIENT_NOTIFICATION_OK=<notificationId>
// E2E_SDK_CLIENT_NOTIFICATION_FAIL=<code>
-// E2E_SDK_IDEMPOTENCY_OK (same invocationId on replay)
+// E2E_SDK_IDEMPOTENCY_REPLAY_GUARDED (replay is rejected without a second provider call)
// E2E_SDK_IDEMPOTENCY_FAIL=<reason>
// E2E_SDK_QUOTA_EXCEEDED_OK (N+1 call correctly rejected)
// E2E_SDK_QUOTA_EXCEEDED_FAIL=<reason>
@@ -135,8 +135,12 @@ async function exerciseClientNotification() {
}
}
-// Idempotency: replay the same idempotencyKey → should return same invocationId
-// without consuming an additional quota slot.
+// Idempotency: replay the same idempotencyKey must never invoke the provider or
+// consume another quota slot. The public mcp-host route deliberately returns
+// idempotency_conflict for a completed prompt because the audit record does not
+// persist completion content to replay. The authorization record still keeps
+// the original invocation identity; callers must use a fresh key when they
+// need a new completion.
async function exerciseIdempotency() {
try {
const { status, body } = await callSdk('/v1/prompt-bridge', {
@@ -144,12 +148,17 @@ async function exerciseIdempotency() {
idempotencyKey: `e2e-prompt-${RUN_ID}`, // SAME key as first call
messages: [{ role: 'user', content: 'Summarize: the quick brown fox.' }],
})
- if (status === 200 && body && body.invocationId === firstPromptBridgeId) {
- log('E2E_SDK_IDEMPOTENCY_OK')
+ const code = (body && (body.error || body.code)) || `http_${status}`
+ if (status === 422 && code === 'idempotency_conflict') {
+ log('E2E_SDK_IDEMPOTENCY_REPLAY_GUARDED')
+ } else if (status === 200 && body && body.invocationId === firstPromptBridgeId) {
+ // Keep accepting the richer replay response if the SDK later adds
+ // durable completion replay without changing the no-double-charge
+ // invariant.
+ log('E2E_SDK_IDEMPOTENCY_REPLAY_GUARDED')
} else if (status === 200 && body && body.invocationId !== firstPromptBridgeId) {
log(`E2E_SDK_IDEMPOTENCY_FAIL=different_invocation_id:${body.invocationId}`)
} else {
- const code = (body && (body.error || body.code)) || `http_${status}`
log(`E2E_SDK_IDEMPOTENCY_FAIL=${code}`)
}
} catch (err) {