Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): cover approved prompt target selection
Alfredo Lopezf74ab807b069
diff --git a/scripts/e2e/e2e-plugin-workload-sdk.sh b/scripts/e2e/e2e-plugin-workload-sdk.shindex 37fa11b07..2f23487cc 100755--- a/scripts/e2e/e2e-plugin-workload-sdk.sh+++ b/scripts/e2e/e2e-plugin-workload-sdk.sh@@ -671,7 +671,7 @@ prompt_grant_payload() {--arg fallbackTargetRef "$E2E_PROMPT_FALLBACK_TARGET_REF" \--arg fallbackCredentialSlot "$E2E_PROMPT_FALLBACK_CREDENTIAL_SLOT" \--arg caller "$caller" \- '{recipeNamespace:$namespace,recipeName:$recipe,capabilityFamily:"promptBridge",provider:$provider,allowedModels:[$model,$fallbackModel],promptTargets:[{targetRef:$targetRef,provider:$provider,model:$model,credentialSlot:$credentialSlot},{targetRef:$fallbackTargetRef,provider:$fallbackProvider,model:$fallbackModel,credentialSlot:$fallbackCredentialSlot}],defaultTargetRef:$targetRef,allowedCallers:[$caller],quotaLimits:{maxRequestsPerRun:3}}'+ '{recipeNamespace:$namespace,recipeName:$recipe,capabilityFamily:"promptBridge",provider:$provider,allowedModels:[$model,$fallbackModel],promptTargets:[{targetRef:$targetRef,provider:$provider,model:$model,credentialSlot:$credentialSlot},{targetRef:$fallbackTargetRef,provider:$fallbackProvider,model:$fallbackModel,credentialSlot:$fallbackCredentialSlot}],defaultTargetRef:$targetRef,allowedCallers:[$caller],quotaLimits:{maxRequestsPerRun:4}}'}# ─── prerequisites ───────────────────────────────────────────────────────@@ -712,6 +712,7 @@ ok "SDK clientNotifications userRef targets desktop user ${USER_REF}"sed -e "s/PLACEHOLDER_PROVIDER/${E2E_WORKFLOW_MODEL_PROVIDER}/" \-e "s/PLACEHOLDER_MODEL/${E2E_WORKFLOW_MODEL_NAME}/" \+ -e "s/PLACEHOLDER_FALLBACK_TARGET_REF/${E2E_PROMPT_FALLBACK_TARGET_REF}/" \-e "s/PLACEHOLDER_RECIPE_NAME/${RECIPE_NAME}/" \-e "s/PLACEHOLDER_USER_REF/${USER_REF}/" \"$FIXTURE" | kctl apply -f -@@ -1076,6 +1077,13 @@ elseexit 1fi+if printf "%s" "$logs" | grep -q E2E_SDK_EXPLICIT_TARGET_OK; then+ ok "sdk-caller explicit approved targetRef was served and returned non-empty content"+else+ fail "sdk-caller explicit approved targetRef did not return a served target/content marker"+ exit 1+fi+if printf "%s" "$logs" | grep -q E2E_SDK_CLIENT_NOTIFICATION_OK; thenok "sdk-caller clientNotifications call was accepted (notificationId returned)"else@@ -1211,7 +1219,7 @@ fi# Quota enforcement: N+1 call is rejected after quota exhausted.if printf "%s" "$logs" | grep -q E2E_SDK_QUOTA_EXCEEDED_OK; then- ok "quota enforcement correctly rejected call after 3/3 requests consumed"+ ok "quota enforcement correctly rejected call after 4/4 requests consumed"elsefail "quota enforcement did not reject the excess call (fixture marker missing; caller logs redacted)"exit 1diff --git a/tests/e2e/fixtures/package-lock.json b/tests/e2e/fixtures/package-lock.jsonindex 8268cd60b..7205f87da 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.52",+ "version": "1.0.53","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@clerum/e2e-test-fixtures",- "version": "1.0.52",+ "version": "1.0.53","dependencies": {"@kubernetes/client-node": "^1.0.0"},diff --git a/tests/e2e/fixtures/package.json b/tests/e2e/fixtures/package.jsonindex 7dd70b45f..dca048fa7 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.52",+ "version": "1.0.53","description": "E2E test fixtures and utilities for Clerum testing","type": "module","main": "index.ts",diff --git a/tests/e2e/fixtures/plugin-workload-sdk-recipe.yaml b/tests/e2e/fixtures/plugin-workload-sdk-recipe.yamlindex 4b8ce8aa8..851865ea8 100644--- a/tests/e2e/fixtures/plugin-workload-sdk-recipe.yaml+++ b/tests/e2e/fixtures/plugin-workload-sdk-recipe.yaml@@ -35,7 +35,9 @@ spec:- name: E2E_SDK_USER_REFvalue: PLACEHOLDER_USER_REF- name: E2E_SDK_QUOTA_LIMIT- value: '3'+ value: '4'+ - name: E2E_SDK_EXPLICIT_TARGET_REF+ value: PLACEHOLDER_FALLBACK_TARGET_REFpluginWorkloadSdk:promptBridge:allowedModels:diff --git a/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js b/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.jsindex 9d5db79ee..4db5afae3 100644--- a/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js+++ b/tests/e2e/fixtures/workflow-plugin-sdk-e2e/src/index.js@@ -13,6 +13,7 @@// E2E_SDK_CLIENT_NOTIFICATION_OK=<notificationId>// E2E_SDK_CLIENT_NOTIFICATION_FAIL=<code>// E2E_SDK_IDEMPOTENCY_REPLAY_GUARDED (replay is rejected without a second provider call)+// E2E_SDK_EXPLICIT_TARGET_OK=<invocationId> (approved targetRef was served)// E2E_SDK_IDEMPOTENCY_FAIL=<reason>// E2E_SDK_QUOTA_EXCEEDED_OK (N+1 call correctly rejected)// E2E_SDK_QUOTA_EXCEEDED_FAIL=<reason>@@ -24,7 +25,8 @@ const CALLER_REF = process.env.E2E_SDK_CALLER_REF || 'sdk-caller'const EVENT_TYPE = process.env.E2E_SDK_EVENT_TYPE || 'e2e.test.notification'const USER_REF = process.env.E2E_SDK_USER_REF || 'e2e-test-user'const RUN_ID = process.env.E2E_SDK_RUN_ID || String(Date.now())-const QUOTA_LIMIT = parseInt(process.env.E2E_SDK_QUOTA_LIMIT || '3', 10)+const QUOTA_LIMIT = parseInt(process.env.E2E_SDK_QUOTA_LIMIT || '4', 10)+const EXPLICIT_TARGET_REF = process.env.E2E_SDK_EXPLICIT_TARGET_REF || ''/** Tracks the invocationId from the first promptBridge call for idempotency check. */let firstPromptBridgeId = null@@ -135,6 +137,40 @@ async function exerciseClientNotification() {}}+// Explicit selector: the backend can request one target from the operator's+// ordered policy. The targetRef is injected as non-secret recipe configuration;+// the workload never receives a provider key or credential slot value.+async function exerciseExplicitTarget() {+ if (!EXPLICIT_TARGET_REF) {+ log('E2E_SDK_EXPLICIT_TARGET_FAIL=missing_target_ref')+ return+ }+ try {+ const { status, body } = await callSdk('/v1/prompt-bridge', {+ purpose: 'generation',+ targetRef: EXPLICIT_TARGET_REF,+ idempotencyKey: `e2e-explicit-${RUN_ID}`,+ messages: [{ role: 'user', content: 'Reply with the word approved.' }],+ })+ if (+ status === 200 &&+ body &&+ body.invocationId &&+ typeof body.content === 'string' &&+ body.content.trim() &&+ body.servedTarget &&+ body.servedTarget.targetRef === EXPLICIT_TARGET_REF+ ) {+ log(`E2E_SDK_EXPLICIT_TARGET_OK=${body.invocationId}`)+ } else {+ const code = (body && (body.error || body.code)) || `http_${status}`+ log(`E2E_SDK_EXPLICIT_TARGET_FAIL=${code}`)+ }+ } catch (err) {+ log(`E2E_SDK_EXPLICIT_TARGET_FAIL=exception:${err && err.message ? err.message : err}`)+ }+}+// 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@@ -167,11 +203,12 @@ async function exerciseIdempotency() {}// Quota enforcement: fill remaining quota slots then verify N+1 is rejected.-// The first promptBridge call consumed 1 slot; the idempotency replay does NOT-// consume a slot. So we fill (QUOTA_LIMIT - 1) more, then attempt one beyond.+// The default and explicit-target prompt calls consumed 2 slots; the+// idempotency replay does NOT consume a slot. Fill the remaining slots, then+// attempt one beyond.async function exerciseQuotaEnforcement() {try {- const remaining = QUOTA_LIMIT - 1+ const remaining = QUOTA_LIMIT - 2for (let i = 0; i < remaining; i++) {const { status, body } = await callSdk('/v1/prompt-bridge', {purpose: 'classification',@@ -215,6 +252,11 @@ async function main() {await exercisePromptBridge()await exerciseClientNotification()+ // Phase 1b: explicit approved target selection.+ if (firstPromptBridgeId) {+ await exerciseExplicitTarget()+ }+// Phase 2: Idempotency — same key returns same invocationId.if (firstPromptBridgeId) {await exerciseIdempotency()