Skip to content

UN-2190 [MISC] Auto-capture execution ID in the API deployment Postman collection - #2031

Merged
athul-rs merged 4 commits into
mainfrom
UN-2190-postman-collection-scripts
Jul 14, 2026
Merged

UN-2190 [MISC] Auto-capture execution ID in the API deployment Postman collection#2031
athul-rs merged 4 commits into
mainfrom
UN-2190-postman-collection-scripts

Conversation

@athul-rs

@athul-rs athul-rs commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What

  • The downloaded Postman collection for API deployments now wires the two requests together: the Process document request stores execution_id from its response into a collection variable via a post-response script, and the Execution status request reads {{execution_id}} from that variable. No more manual copy-pasting of execution IDs.

Why

UN-2190 — minor UX gap: after executing a document asynchronously, users had to copy the execution ID from the response and paste it into the status request's REPLACE_WITH_EXECUTION_ID placeholder. The LLMWhisperer Postman collection already does this with whisper_hash; this applies the same pattern.

How

  • postman_collection/dto.py: new ScriptItem/EventItem/VariableItem dataclasses; PostmanItem gets an optional event; the execute request carries a post-response script (pm.collectionVariables.set("execution_id", ...), guarded so non-JSON/error responses are ignored); the status URL uses {{execution_id}} (urlencode with safe="{}" so Postman's braces survive); collection-level variable block added with a REPLACE_WITH_EXECUTION_ID default so manual use still works.
  • to_dict() strips event: null from items that have no scripts.
  • Pipeline collections (single request, no status call) are unchanged.

Can this PR break any existing features. If yes, please list possible items. If no, please explain why. (PS: Admins do not merge the PR without this section filled)

  • No. This only changes the generated Postman collection JSON (a download artifact), not any API behavior. The status request still works manually: if the script never ran, the variable resolves to the REPLACE_WITH_EXECUTION_ID default — identical to today's placeholder. The script is defensive (checks response.message.execution_id exists before setting).

Database Migrations

  • None

Env Config

  • None

Relevant Docs

  • N/A

Related Issues or PRs

  • Jira: UN-2190

Notes on Testing

  • ruff check + format clean.
  • Verified generated JSON structure with a stubbed-Django harness: execute item carries the event block, status item has none, status URL contains execution_id={{execution_id}} unescaped, and the collection-level variable is present.
  • Manual: download a collection from an API deployment, import into Postman, run Process document then Execution status — the second request uses the captured ID.

Screenshots

N/A

Checklist

I have read and understood the Contribution Guidelines.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0937802c-5f36-4a6e-926f-490210e3683a

📥 Commits

Reviewing files that changed from the base of the PR and between 4bafbf7 and f6d7d16.

📒 Files selected for processing (5)
  • backend/api_v2/postman_collection/constants.py
  • backend/api_v2/postman_collection/dto.py
  • backend/api_v2/postman_collection/tests/__init__.py
  • backend/api_v2/postman_collection/tests/test_dto.py
  • backend/api_v2/serializers.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/api_v2/postman_collection/constants.py

Summary by CodeRabbit

  • New Features
    • Postman collections for API deployments now automatically capture execution IDs from deployment responses.
    • Status requests use the captured execution ID to track deployment progress.
    • Collection-level variables are included in generated Postman collections.
    • API execution responses now include an execution_id field.
  • Bug Fixes
    • Preserved Postman variable placeholders in status request URLs so they resolve correctly during collection runs.

Walkthrough

Adds Postman event and collection-variable DTOs, exposes execution_id in API responses, and wires generated deployment collections to capture execution IDs for subsequent status requests.

Changes

Postman execution ID flow

Layer / File(s) Summary
Collection contracts and serialization
backend/api_v2/postman_collection/constants.py, backend/api_v2/postman_collection/dto.py, backend/api_v2/serializers.py
Adds Postman script, event, and variable DTOs; execution ID constants; collection-level variables; and the serialized execution_id response field.
Execution ID capture and status wiring
backend/api_v2/postman_collection/dto.py
Seeds deployment variables, captures execution IDs in execute test scripts, resets missing IDs to a sentinel, preserves {{execution_id}} in status URLs, and omits empty events from serialized items.
Regression coverage
backend/api_v2/postman_collection/tests/test_dto.py
Verifies deployment and pipeline collection shapes, event scripts, collection variables, unencoded interpolation, and constant coupling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Postman
  participant ExecuteAPI
  participant CollectionVariable
  participant StatusAPI
  Postman->>ExecuteAPI: Send execute request
  ExecuteAPI-->>Postman: Return execution_id
  Postman->>CollectionVariable: Store execution_id
  Postman->>StatusAPI: Request status with {{execution_id}}
Loading

Suggested reviewers: hari-kuriakose

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: auto-capturing execution ID in the API deployment Postman collection.
Description check ✅ Passed The description covers the required sections and main details; only the dependencies versions section is missing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch UN-2190-postman-collection-scripts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR auto-wires the two Postman collection requests for API deployments: the Process document request gains a try/catch-guarded post-response script that captures execution_id from the response into a collection variable, and the Execution status request reads {{execution_id}} from that variable instead of a static placeholder. APIExecutionResponseSerializer gains a first-class execution_id field to make the capture possible.

  • ScriptItem, EventItem, and VariableItem dataclasses are added to dto.py; to_dict() strips empty event blocks so pipeline items stay clean, and APIDeploymentDto.get_collection_variables() scopes the variable to API deployments only.
  • urlencode(..., safe="{}") keeps Postman's {{...}} braces unescaped in the status URL, and both the script and the URL reference the same CollectionKey.EXEC_ID_VARIABLE_NAME constant to prevent drift.
  • A regression test suite is added covering event retention, URL encoding, variable presence, script content, and pipeline/deployment shape invariants.

Confidence Score: 5/5

Safe to merge — changes are isolated to the Postman collection download artifact and an additive serializer field; no API behavior is altered.

All three issues flagged in the previous review pass are resolved: the capture script is now wrapped in try/catch, collection variables are scoped to API deployments only (pipelines return an empty list), and execution_id is surfaced as a first-class field in APIExecutionResponseSerializer so the JS guard can actually fire. The view confirms the response shape is {"message": {"execution_id": ...}}, matching what the script reads. A regression test suite pins the contract. No database, config, or runtime API changes are involved.

No files require special attention.

Important Files Changed

Filename Overview
backend/api_v2/postman_collection/dto.py Adds ScriptItem/EventItem/VariableItem dataclasses, wires a try/catch-guarded post-response script onto the execute item, switches status URL to use {{execution_id}} variable (safe-encoded braces), and exposes a collection-level variable block. Pipeline collections inherit the base no-op, keeping their payload functionally unchanged.
backend/api_v2/serializers.py Adds execution_id = CharField() to APIExecutionResponseSerializer; ExecutionResponse always populates this field (required str, no default), so no null-handling concern.
backend/api_v2/postman_collection/constants.py Adds EXEC_ID_VARIABLE_NAME and STATUS_EXEC_ID_VARIABLE constants; the latter is derived from the former to prevent drift.
backend/api_v2/postman_collection/tests/test_dto.py New regression test suite covering event retention/stripping, URL encoding, variable presence, script content, constant coupling, and pipeline vs. deployment shape invariants.
backend/api_v2/postman_collection/tests/init.py Empty init file to make the tests directory a Python package.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant U as User (Postman)
    participant E as Execute endpoint
    participant S as Status endpoint

    U->>E: "POST /api/{org}/{api}/ (Process document)"
    E-->>U: "{"message": {"execution_id": "uuid", "execution_status": "PENDING", "status_api": "..."}}"
    Note over U: Post-response script (test hook):<br/>pm.collectionVariables.set("execution_id", response.message.execution_id)

    U->>S: "GET /api/{org}/{api}/?execution_id={{execution_id}}&..."
    Note over U: {{execution_id}} resolved from collection variable
    S-->>U: "{"status": "COMPLETED", "message": []}"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant U as User (Postman)
    participant E as Execute endpoint
    participant S as Status endpoint

    U->>E: "POST /api/{org}/{api}/ (Process document)"
    E-->>U: "{"message": {"execution_id": "uuid", "execution_status": "PENDING", "status_api": "..."}}"
    Note over U: Post-response script (test hook):<br/>pm.collectionVariables.set("execution_id", response.message.execution_id)

    U->>S: "GET /api/{org}/{api}/?execution_id={{execution_id}}&..."
    Note over U: {{execution_id}} resolved from collection variable
    S-->>U: "{"status": "COMPLETED", "message": []}"
Loading

Reviews (4): Last reviewed commit: "Address review comments on Postman colle..." | Re-trigger Greptile

Comment thread backend/api_v2/postman_collection/dto.py
Comment thread backend/api_v2/postman_collection/dto.py Outdated
Comment thread backend/api_v2/postman_collection/dto.py
@sonarqubecloud

Copy link
Copy Markdown

@jaseemjaskp jaseemjaskp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated PR review (PR Review Toolkit: code-reviewer, silent-failure-hunter, type-design-analyzer, pr-test-analyzer, comment-analyzer, code-simplifier).

The change is correct and well-scoped — the capture script's response.message.execution_id path is validated by the new serializer field and the {"message": ...} response envelope, and urlencode(safe="{}") correctly preserves {{execution_id}}. The already-fixed items (serializer dropping execution_id, pipeline collection variables, non-JSON try/catch) are not re-raised.

The findings below are all new. The only substantive one is the stale-variable risk (P1); the rest are P2/P3 hardening, type-design, comment, and test-coverage suggestions.

Comment thread backend/api_v2/postman_collection/dto.py
Comment thread backend/api_v2/postman_collection/dto.py Outdated
Comment thread backend/api_v2/postman_collection/dto.py Outdated
Comment thread backend/api_v2/postman_collection/dto.py
Comment thread backend/api_v2/postman_collection/dto.py Outdated
Comment thread backend/api_v2/postman_collection/constants.py
Comment thread backend/api_v2/postman_collection/dto.py Outdated
@athul-rs athul-rs changed the title UN-2190 [FEAT] Auto-capture execution ID in the API deployment Postman collection UN-2190 [MISC] Auto-capture execution ID in the API deployment Postman collection Jul 14, 2026
athul-rs and others added 4 commits July 14, 2026 08:17
Add a post-response script to the 'Process document' request that
stores message.execution_id into a collection variable, and point the
'Execution status' request's execution_id query param at that variable.
Users no longer copy-paste execution IDs between requests (mirrors the
LLMWhisperer collection's whisper_hash pattern).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…PI deployments

- Wrap pm.response.json() in try/catch so error pages (non-JSON) don't
  surface a Postman test error
- Move collection variables behind APIBase.get_collection_variables()
  so Pipeline collections (no status request) stay variable-free

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The ExecutionResponse DTO carries execution_id but
APIExecutionResponseSerializer dropped it, so the Postman capture
script (and any API consumer) had to parse it out of status_api.
Add it as a first-class response field; the collection script's
message.execution_id lookup now matches the real payload.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Capture script: add else branch that resets execution_id to the
  default sentinel and warns, so a stale id from a previous run is
  never silently reused when the execute response lacks the field.
- PostmanItem.event: use field(default_factory=list) instead of the
  None/[] tri-state; to_dict() now strips empty (falsy) event blocks,
  preserving existing external behavior (pipeline items omit "event").
- Constrain closed enums: EventItem.listen -> Literal["prerequest",
  "test"], ScriptItem.type -> Literal["text/javascript"].
- Document the capture script's response-shape coupling and that it is
  Postman's "test" hook.
- Drop unnecessary string forward-reference on get_collection_variables.
- constants: derive STATUS_EXEC_ID_VARIABLE from EXEC_ID_VARIABLE_NAME
  so the two can't drift.
- Add tests for the postman_collection package covering event
  strip/keep, pipeline vs api-deployment shape, shared-constant coupling
  across variable/URL/JS, and the unencoded {{execution_id}} status URL.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@athul-rs
athul-rs force-pushed the UN-2190-postman-collection-scripts branch from 4bafbf7 to f6d7d16 Compare July 14, 2026 02:47
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Unstract test results

Per-group results

Status Group Tier Passed Failed Errors Skipped Duration (s)
e2e-login e2e 2 0 0 0 1.3
e2e-smoke e2e 2 0 0 0 0.8
integration-backend integration 56 0 0 27 36.5
integration-connectors integration 1 0 0 7 7.3
unit-backend unit 126 0 0 0 21.7
unit-connectors unit 63 0 0 0 9.9
unit-core unit 27 0 0 0 1.3
unit-platform-service unit 15 0 0 0 2.6
unit-rig unit 69 0 0 0 3.6
unit-sdk1 unit 435 0 0 0 20.7
unit-workers unit 0 0 0 0 19.6
TOTAL 796 0 0 34 125.2

Critical paths

⚠️ Critical paths not yet covered

  • workflow-create-execute — Create a workflow, configure source+destination, execute, poll, fetch result. (entry: POST /api/v1/workflow/{id}/execute/; declared coverage: e2e-workflow)
  • api-deployment-run — Deploy a workflow as an API, POST a document, receive structured JSON. (entry: POST /deployment/api/{org}/{name}/; declared coverage: e2e-api-deployment)
  • prompt-studio-fetch-response — Prompt Studio: create project, add prompt, run single-pass, get response. (entry: POST /api/v1/prompt-studio/prompt-studio-tool/{id}/fetch_response/; declared coverage: e2e-prompt-studio)
  • pipeline-etl-execute — Run an ETL pipeline from source connector to destination. (entry: POST /api/v1/pipeline/{id}/execute/; declared coverage: no groups declared)
  • usage-token-tracking — Per-execution token usage is recorded and retrievable. (entry: GET /api/v1/usage/get_token_usage/; declared coverage: no groups declared)
  • workflow-execution-fan-out — Multi-file workflow execution fans out to file-processing workers and rejoins. (entry: internal: backend → rabbitmq → workers/file_processing; declared coverage: no groups declared)
  • callback-result-delivery — Async results are posted back via the callback worker. (entry: internal: workers/callback → backend /internal endpoints; declared coverage: no groups declared)
✅ Covered critical paths
  • auth-login — covered by e2e-login
  • adapter-register-llm — covered by integration-backend

@athul-rs
athul-rs requested a review from jaseemjaskp July 14, 2026 04:21
@athul-rs
athul-rs merged commit 8218164 into main Jul 14, 2026
11 checks passed
@athul-rs
athul-rs deleted the UN-2190-postman-collection-scripts branch July 14, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants