|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Runtime proof — TypeScript SDK v8.4.0 surfaces the Decision Mode request |
| 3 | +# context (platform #2509, epic #2508) and the pasal_56b_dpa transfer basis. |
| 4 | +# |
| 5 | +# Builds the LOCAL SDK (dist/) and runs a Node program that: |
| 6 | +# 1. acts as the PEP via a raw POST /api/v1/decide (that endpoint is not |
| 7 | +# SDK-wrapped per ADR-056), forwarding request context in the body; |
| 8 | +# 2. reads the decision back through the SDK's listDecisions + explainDecision |
| 9 | +# and asserts DecisionSummary.context / DecisionExplanation.context are |
| 10 | +# populated with the forwarded keys; |
| 11 | +# 3. JSON round-trips an AuditLogEntry carrying transferBasis='pasal_56b_dpa' |
| 12 | +# to confirm the value is surfaced verbatim. |
| 13 | +# |
| 14 | +# The npm registry is blocked, so we use the LOCAL build via file:../.. (never |
| 15 | +# `npm install @axonflow/sdk` — that would fail on the publish boundary). |
| 16 | +# |
| 17 | +# Usage: |
| 18 | +# AXONFLOW_AGENT_URL=http://localhost:8080 ./test.sh |
| 19 | + |
| 20 | +set -uo pipefail |
| 21 | + |
| 22 | +AGENT_URL=${AXONFLOW_AGENT_URL:-http://localhost:8080} |
| 23 | +CLIENT_ID=${AXONFLOW_TENANT_ID:-buku-e-ts-e2e} |
| 24 | +SECRET=${AXONFLOW_TENANT_SECRET:-buku-e-secret} |
| 25 | +SDK_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" |
| 26 | +RUN_TAG=$(date -u +%s) |
| 27 | + |
| 28 | +red() { printf '\033[31m%s\033[0m\n' "$*"; } |
| 29 | +green() { printf '\033[32m%s\033[0m\n' "$*"; } |
| 30 | + |
| 31 | +if [ ! -f "$SDK_ROOT/dist/esm/index.js" ]; then |
| 32 | + echo "Building local SDK..." |
| 33 | + (cd "$SDK_ROOT" && npm run build) || { red "FAIL: SDK build failed"; exit 1; } |
| 34 | +fi |
| 35 | + |
| 36 | +WORK=$(mktemp -d) |
| 37 | +trap 'rm -rf "$WORK"' EXIT |
| 38 | + |
| 39 | +cat > "$WORK/package.json" <<EOF |
| 40 | +{ |
| 41 | + "name": "decision-ctx-rt-${RUN_TAG}", |
| 42 | + "version": "1.0.0", |
| 43 | + "type": "module", |
| 44 | + "private": true, |
| 45 | + "dependencies": { "@axonflow/sdk": "file:${SDK_ROOT}" } |
| 46 | +} |
| 47 | +EOF |
| 48 | + |
| 49 | +cat > "$WORK/main.mjs" <<EOF |
| 50 | +import { AxonFlow } from '@axonflow/sdk'; |
| 51 | +
|
| 52 | +const AGENT_URL = process.env.AXONFLOW_AGENT_URL || 'http://localhost:8080'; |
| 53 | +const CLIENT_ID = process.env.AXONFLOW_TENANT_ID || 'buku-e-ts-e2e'; |
| 54 | +const SECRET = process.env.AXONFLOW_TENANT_SECRET || 'buku-e-secret'; |
| 55 | +const want = { x_ai_agent: 'refund-bot', x_session_id: 'sess-buku-42', x_leader_identity: 'ops-lead' }; |
| 56 | +
|
| 57 | +const fail = (m) => { console.error('FAIL: ' + m); process.exit(1); }; |
| 58 | +const sameCtx = (got) => got && want.x_ai_agent === got.x_ai_agent |
| 59 | + && want.x_session_id === got.x_session_id && want.x_leader_identity === got.x_leader_identity; |
| 60 | +
|
| 61 | +// 1. PEP: create a decision carrying request context (body 'context' map). |
| 62 | +const auth = Buffer.from(CLIENT_ID + ':' + SECRET).toString('base64'); |
| 63 | +const decideResp = await fetch(AGENT_URL + '/api/v1/decide', { |
| 64 | + method: 'POST', |
| 65 | + headers: { 'Content-Type': 'application/json', 'X-Client-ID': CLIENT_ID, Authorization: 'Basic ' + auth }, |
| 66 | + body: JSON.stringify({ |
| 67 | + stage: 'llm', |
| 68 | + query: 'summarize this support ticket', |
| 69 | + target: { type: 'llm', model: 'gpt-4', provider: 'openai' }, |
| 70 | + context: { 'x-ai-agent': 'refund-bot', 'x-session-id': 'sess-buku-42', 'x-leader-identity': 'ops-lead' }, |
| 71 | + }), |
| 72 | +}); |
| 73 | +const decideText = await decideResp.text(); |
| 74 | +if (!decideResp.ok) fail('decide HTTP ' + decideResp.status + ': ' + decideText); |
| 75 | +console.log('server /decide response: ' + decideText); |
| 76 | +const decisionId = JSON.parse(decideText).decision_id; |
| 77 | +if (!decisionId) fail('no decision_id: ' + decideText); |
| 78 | +console.log('PEP decide -> decision_id=' + decisionId); |
| 79 | +
|
| 80 | +// 2. Read it back through the SDK. |
| 81 | +const client = new AxonFlow({ endpoint: AGENT_URL, clientId: CLIENT_ID, clientSecret: SECRET, mode: 'production' }); |
| 82 | +
|
| 83 | +const rows = await client.listDecisions({ limit: 5 }); |
| 84 | +const found = rows.find((r) => r.decisionId === decisionId); |
| 85 | +if (!found) fail('listDecisions did not return ' + decisionId + ' (got ' + rows.length + ' rows)'); |
| 86 | +console.log('SDK listDecisions -> ' + JSON.stringify(found)); |
| 87 | +if (!sameCtx(found.context)) fail('listDecisions context = ' + JSON.stringify(found.context)); |
| 88 | +console.log('PASS: listDecisions DecisionSummary.context populated with ' + Object.keys(found.context).length + ' PEP-forwarded keys'); |
| 89 | +
|
| 90 | +const exp = await client.explainDecision(decisionId); |
| 91 | +console.log('SDK explainDecision -> context=' + JSON.stringify(exp.context) + ' contextTruncated=' + exp.contextTruncated); |
| 92 | +if (!sameCtx(exp.context)) fail('explainDecision context = ' + JSON.stringify(exp.context)); |
| 93 | +console.log('PASS: explainDecision returned full context (contextTruncated=' + exp.contextTruncated + ')'); |
| 94 | +
|
| 95 | +// 3. transfer_basis = pasal_56b_dpa is JSON-preserved. NOTE: TypeScript types are |
| 96 | +// erased at runtime, so this only asserts the value survives a JSON round-trip. |
| 97 | +// The SDK's real snake_case->camelCase decoder (parseAuditLogEntry) is covered |
| 98 | +// by tests/audit.test.ts ('should parse the pasal_56b_dpa transfer basis ...'). |
| 99 | +const entry = { id: 'e2e-audit', dataResidency: 'ID', transferBasis: 'pasal_56b_dpa' }; |
| 100 | +const back = JSON.parse(JSON.stringify(entry)); |
| 101 | +if (back.transferBasis !== 'pasal_56b_dpa') fail('transferBasis round-trip = ' + back.transferBasis); |
| 102 | +console.log('PASS: transferBasis "' + back.transferBasis + '" JSON-preserved (SDK decoder path covered by tests/audit.test.ts)'); |
| 103 | +
|
| 104 | +console.log('ALL PASS: v8.4.0 context + pasal_56b_dpa verified through SDK runtime'); |
| 105 | +EOF |
| 106 | + |
| 107 | +echo "Run tag: $RUN_TAG Agent: $AGENT_URL" |
| 108 | +( |
| 109 | + cd "$WORK" |
| 110 | + npm install --silent --no-audit --no-fund 2>&1 | tail -2 |
| 111 | + AXONFLOW_AGENT_URL="$AGENT_URL" AXONFLOW_TENANT_ID="$CLIENT_ID" AXONFLOW_TENANT_SECRET="$SECRET" \ |
| 112 | + AXONFLOW_TELEMETRY=off node main.mjs 2>&1 |
| 113 | +) |
| 114 | +RC=$? |
| 115 | +[ $RC -eq 0 ] && green "runtime-e2e PASS" || { red "runtime-e2e FAIL (rc=$RC)"; exit $RC; } |
0 commit comments