Integration Studio — operator runbook
Contract-test-driven onboarding for SmartLink integrations. Instead of ad-hoc back-and-forth with a counterpart API provider, you declare an integration, bind it to a sandbox + live connector, author positive and negative test cases, run the suite against the sandbox, and promote once it is green. The testsuite is the executable, shareable contract with the counterpart.
- Admin-only. Every route is gated by
require_role("admin"). - UI:
smartlink-admin→ Integration Studio (/studio). - Code:
src/opengov/smartlink/studio/· API base:/api/v1/smartlink. - Net-new tooling (traceability claim 8.26); design spec
docs/specs/2026-06-14-integration-studio-backend-design.md.
Lifecycle
draft ──(green sandbox run)──▶ sandbox_passing ──(promote)──▶ promoted
- draft — created; may be unbound / unproven.
- sandbox_passing (“checks passing”) — a run finished fully green
(
total > 0andfailed == 0) against either system. Written by the run engine, never by hand, and it never downgrades. A live-only imported proposal has no practice copy, so its (typed-value-confirmed) green live run counts. - promoted (“live”) — going live is a real switch-on, not a label: it activates the live connector and exactly the rehearsed actions (those with a passed positive check in the latest green run; the rest stay off and are named in the response), writes the answered “sent twice?” posture onto the event bindings targeting them, and releases their held sends. Refused in plain words until: a live connector is bound, the checks are green, every rehearsed action exists on the live system, the live system answers, and the checklist rows are answered (sign-in or “needs none”, “sent twice?”, plain-HTTP confirmation where it applies). Going live never switches anything off; re-promotion is additive and idempotent.
Prerequisites
An integration binds existing SmartLink connectors — one for sandbox, one for
live — each exposing the operations the test cases exercise. Create those
first (UI: Connectors; or the smartlink-integrate skill / connector +
operation CRUD). The two connectors should expose the same operation codes so
a single testsuite runs against either environment. OPENGOV_ENCRYPTION_KEY must
be set (as for all of SmartLink).
Operate via the UI (/studio)
- Create — + New integration:
code(slug),name,counterpart,description. - Bind environments — choose the sandbox + live connectors. The suite runs
against the sandbox (where
send/write ops are safe to exercise). Live is bound only so you can promote. - Author the contract — per operation, add positive cases (valid input → expected success) and negative cases (invalid input → expected graceful failure). Each case = a request payload + path params + JSONata assertions; negative cases also declare an expected failure category.
- Run & iterate — Run against sandbox. The board shows pass/fail per case; click a failure to see the failure stage + category and an expected-vs-actual diff. Fix the transform / case / connector and re-run.
- Prove & promote — once green, the conformance report is the shareable evidence; Promote to live unlocks (needs live bound + sandbox green).
Operate via the API (curl)
All routes are under /api/v1/smartlink and need an admin token
(-H "Authorization: Bearer $TOKEN"), or run the backend with ./dev.sh --no-auth.
| Action | Method + path |
|---|---|
| List integrations | GET /integrations |
| Create integration | POST /integrations |
| Get integration | GET /integrations/{id} |
| Bind environment | PUT /integrations/{id}/environments/{sandbox|live} |
| Promote | POST /integrations/{id}/promote |
| List test cases | GET /integrations/{id}/test-cases |
| Create test case | POST /integrations/{id}/test-cases |
| Get / update / delete test case | GET|PUT|DELETE /integrations/{id}/test-cases/{case_id} |
| Run the suite | POST /integrations/{id}/testsuite/run |
| Latest run | GET /integrations/{id}/latest-run |
| Conformance report | GET /integrations/{id}/conformance |
Worked example — verify a GitHub username (reproducible end-to-end)
This is the exact flow used to validate the feature against a live counterpart
(GitHub’s public /users/{username}). B=http://localhost:8000/api/v1/smartlink.
# 1. A connector for the counterpart (public, no auth)
CONN=$(curl -s -X POST "$B/connectors" -H 'Content-Type: application/json' -d \
'{"code":"github_api","name":"GitHub API · Sandbox","host":"api.github.com","use_ssl":true,"auth_type":"none"}' \
| python3 -c "import sys,json;print(json.load(sys.stdin)['id'])")
# 2. An operation on that connector
curl -s -X POST "$B/connectors/$CONN/operations" -H 'Content-Type: application/json' -d \
'{"code":"get_user","name":"Get user","http_method":"GET","path_template":"/users/{username}","operation_type":"lookup"}' >/dev/null
# 3. The integration
INT=$(curl -s -X POST "$B/integrations" -H 'Content-Type: application/json' -d \
'{"code":"gh_user","name":"GitHub User Verification","counterpart":"GitHub","description":"Verify a GitHub username resolves to an account."}' \
| python3 -c "import sys,json;print(json.load(sys.stdin)['id'])")
# 4. Bind the sandbox environment (server re-derives code/name/host from the connector)
curl -s -X PUT "$B/integrations/$INT/environments/sandbox" -H 'Content-Type: application/json' \
-d "{\"connector_id\":\"$CONN\"}" >/dev/null
# 5a. A POSITIVE case — a known user resolves
curl -s -X POST "$B/integrations/$INT/test-cases" -H 'Content-Type: application/json' -d '{
"operation_code":"get_user","operation_name":"Get user","http_method":"GET",
"name":"Known user resolves","kind":"positive","path_params":{"username":"octocat"},
"assertions":[{"id":"a1","expression":"status_code = 200"},
{"id":"a2","expression":"data.login = '"'"'octocat'"'"'"}]}' >/dev/null
# 5b. A NEGATIVE case — an unknown user is a clean 404 (counterpart_4xx)
curl -s -X POST "$B/integrations/$INT/test-cases" -H 'Content-Type: application/json' -d '{
"operation_code":"get_user","operation_name":"Get user","http_method":"GET",
"name":"Unknown user returns 404","kind":"negative","path_params":{"username":"zzz-no-such-acct-9991"},
"expected_failure_category":"counterpart_4xx",
"assertions":[{"id":"b1","expression":"status_code = 404"}]}' >/dev/null
# 6. Run the suite against the sandbox -> {passed, failed, total, results[...]}
curl -s -X POST "$B/integrations/$INT/testsuite/run" -H 'Content-Type: application/json' \
-d '{"environment":"sandbox"}'
A fully-green sandbox run (failed == 0) advances the integration to
sandbox_passing; GET /integrations/$INT/conformance then returns the report.
Assertion JSON shape: each assertion is
{"id": "...", "expression": "<jsonata>", "description"?: "..."}—idis required.kindispositive|negative.expected_failure_category(negative cases) must be one of the categories below.
Authoring assertions (JSONata)
Each assertion is a JSONata boolean evaluated over a flat context with four names bound from the executor’s outputs:
| Name | Meaning |
|---|---|
status_code | HTTP status the counterpart returned |
data | response after the operation’s response_transform |
raw_data | the counterpart’s raw JSON body (pre-transform) |
error | error string, or null |
Examples: status_code = 200 · data.status = 'active' ·
$exists(data.legal_name) · data.vat_registered = true · status_code = 404.
- A positive case passes when the execution succeeded AND all assertions pass.
- A negative case passes when all assertions pass AND (if set) the actual
failure category equals the case’s
expected_failure_category— i.e. the counterpart rejected the bad input the way you agreed it should.
Diagnosing failures — the taxonomy
A failed result carries a failure_stage (where in the executor pipeline it
broke) and a failure_category (why).
Stages: request_build → auth → transport → counterpart_http → response_parse → response_transform → success_condition → assertion.
failure_category | What it means → what to check |
|---|---|
network_unreachable | DNS/connect failed → host, SSRF rules, connectivity |
timeout | counterpart too slow → timeout_ms on the connector |
auth_rejected | 401/403 → connector auth_config / credentials |
counterpart_4xx | counterpart rejected the request (often expected for a negative case) |
counterpart_5xx | counterpart server error → retry / counterpart-side issue |
malformed_response | non-JSON or oversized body → counterpart contract |
success_condition_false | 2xx but the operation’s success_condition is false |
assertion_failed | response came back fine but an assertion didn’t match (see the diff) |
outcome_unknown | the request may have run at the counterpart, but its answer is lost (a mesh answer_lost, or a status the platform does not know) → check with the counterpart before sending again; never retried automatically |
transform_error, schema_mismatch | defined but not yet emitted (reserved) |
Behaviour & guarantees
- Runs hit the bound sandbox connector, fresh every run — the run engine
calls
executor.execute_operationdirectly (not the gateway), so per-casepath_paramsare honoured and there is no idempotency-dedup or response cache. - A failing negative test does not trip the connector’s circuit breaker — deliberately-bad inputs never degrade the live connector’s health.
- Evidence is persisted to
smartlink_test_case_results(not the applicantQueryLog). The SSRF guard, per-connector token bucket, and TLS trust store still apply.
Gotchas & limits
- Admin-only (router-wide
require_role("admin")). - No delete-integration route this pass — remove an integration row at the DB if needed (test cases can be deleted via the API).
- Sandbox-first. Only run against the sandbox for
send/write operations; running against live would perform real writes at the counterpart. GET /integrations/{id}/conformanceexists, but the UI currently composes the report client-side from the cases + the latest run.IntegrationTestCaseis parallel to the oldOperationFixture(a saved Playground payload) — different concepts, intentionally not merged.
See also
- Design spec —
docs/specs/2026-06-14-integration-studio-backend-design.md - Implementation plan —
docs/plans/2026-06-14-integration-studio-backend.md - Module notes —
src/opengov/smartlink/CLAUDE.md - Connector + operation authoring — the
smartlink-integrateskill
Imported proposals (from a service import)
A service import (python -m sandbox.importer.run --map <file> [--bots <file>])
proposes one integration per outside system: the connector and its actions
arrive switched off, bound as the integration’s live system (the
capture is the incumbent’s real configuration), with one seeded check per
action whose payload keys are the captured parameters, and one event binding
per automated step (“when this step passes, send these answers to that
system”). Credentials are never imported. To take one live:
- Check the address on the connection page — the captured host (e.g.
gdb:8080) is the old stack’s internal name and may not be reachable here. - Add sign-in details (or confirm the system needs none at go-live).
- Rehearse — add a practice copy of the system, or rehearse against the
real one: a run that includes a
sendaction asks you to type the test value you will use, so you can find and delete the real records it creates. - Go live — answer the checklist; only the rehearsed actions switch on, and the held sends go out.
Held vs paused vs failed — reading the events queue
| You see | It means | What to do |
|---|---|---|
state held | The step passed but the connection has not gone live — the send is kept, not lost. | Nothing; go-live releases it. |
failed_terminal after go-live | The send really failed (and, under a “creates two records” posture, is never retried automatically). The officer sees it on the application. | Fix the cause, then re-trigger (replay_as_queued re-sends the stored payload byte-for-byte; re_render re-renders the template first). |
Connection paused (is_active off) | An administrator paused it: applicant traffic stops; in-flight sends fail and wait for a person. | Resume on the connection page, then replay the failures. |
Pausing a connection does not park its sends — a send already on its way fails terminal and must be replayed after resuming. Delete the live-rehearsal records (the typed test values) from the outside system once you are live.