Skip to content

refactor(deployments): consolidate version reads, status mapping, and v1 auth prologue - #5013

Merged
waleedlatif1 merged 2 commits into
stagingfrom
refactor/deployments-version-list
Jun 13, 2026
Merged

refactor(deployments): consolidate version reads, status mapping, and v1 auth prologue#5013
waleedlatif1 merged 2 commits into
stagingfrom
refactor/deployments-version-list

Conversation

@waleedlatif1

@waleedlatif1waleedlatif1 commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Follow-up to feat(deployments): add v1 deployment endpoints and Deployments block #5009 — removes the remaining duplicate code paths across the deployment surfaces:
  • Version-list reads: UI deployments list route and mothership get_deployment_log now consume the shared listWorkflowVersions helper (same shapes, 'Admin' fallback applied in one place)
  • Single-version fetch: new getWorkflowDeploymentVersion helper backs both the UI version GET and the deployments tool version route
  • Error-status mapping: statusForOrchestrationError replaces the identical validation/not_found/else ternary that was copy-pasted in six routes
  • v1 mutation prologue: resolveV1DeploymentWorkflow extracts the shared active-record load + admin check + 404 masking used by v1 deploy, undeploy, and rollback
  • No behavior change on any surface

Type of Change

  • Refactor

Testing

146 tests across the affected suites pass; typecheck and check:api-validation:strict clean

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…owVersions
The UI deployments list route and the mothership get_deployment_log handler
each had their own inline version query; both now consume the shared
persistence helper, so every deployment surface (UI, v1, admin, tools,
mothership) reads versions through one code path.
@vercel

vercelBot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
docsSkippedSkippedJun 12, 2026 11:56pm

Request Review

@cursor

cursorBot commented Jun 12, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Refactor-only with tests updated; intended behavior parity across deployment surfaces, with no new auth or data-model changes.

Overview
This refactor deduplicates deployment API paths by routing version reads and orchestration error handling through shared helpers, and by extracting the repeated v1 workflow resolution step.

Version reads now go through listWorkflowVersions (UI deployments list, copilot get_deployment_log) and the new getWorkflowDeploymentVersion (UI version GET, deployments tool version route), replacing inline Drizzle queries.

HTTP status mapping for failed deploy/promote/activate flows uses statusForOrchestrationError across UI, v1, and tool routes instead of duplicated ternaries.

v1 deploy, undeploy, and rollback share resolveV1DeploymentWorkflow for active-record load, workspace admin check, and 404 masking on access failures.

Tests were updated to mock the persistence helpers rather than db.select chains.

Reviewed by Cursor Bugbot for commit 2e6570e. Configure here.

@greptile-apps

greptile-appsBot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR completes the deployment-surface refactoring started in #5009 by centralising four previously copy-pasted code patterns into shared helpers.

  • statusForOrchestrationError replaces six identical validation → 400 / not_found → 404 / else → 500 ternaries across UI, v1, and tool routes.
  • getWorkflowDeploymentVersion and listWorkflowVersions (already existing) now back both the UI and tool version endpoints, removing duplicate Drizzle queries.
  • resolveV1DeploymentWorkflow extracts the active-record load + admin check + 404-masking prologue shared by v1 deploy, undeploy, and rollback; tests and types are updated throughout.

Confidence Score: 5/5

Safe to merge — purely extracts duplicate code into shared helpers with no observable behavior change on any route surface.

All six error-status ternaries are replaced by an equivalent function; the new resolveV1DeploymentWorkflow and getWorkflowDeploymentVersion helpers replicate the exact logic that was previously inlined. The Admin fallback in listWorkflowVersions was already correct from #5009. No new logic is introduced.

No files require special attention; the single minor note is in types.ts where the 'conflict' code could map to 409 now that the mapping is centralised.

Important Files Changed

FilenameOverview
apps/sim/lib/workflows/orchestration/types.tsAdds statusForOrchestrationError helper; correctly preserves existing 400/404/500 behavior. 'conflict' maps to 500 (same as old ternaries).
apps/sim/lib/workflows/persistence/utils.tsAdds getWorkflowDeploymentVersion (single-version fetch) alongside the existing listWorkflowVersions; both helpers are straightforward Drizzle selects with correct null handling.
apps/sim/app/api/v1/workflows/utils.tsNew resolveV1DeploymentWorkflow helper cleanly consolidates active-record load + admin check + 404 masking used by three v1 routes.
apps/sim/app/api/v1/workflows/[id]/deploy/route.tsReplaces duplicate prologue and error-status ternaries with helpers; behavior preserved for both POST (deploy) and DELETE (undeploy).
apps/sim/app/api/v1/workflows/[id]/rollback/route.tsSame prologue/error-status refactor as deploy route; no behavioral change.
apps/sim/app/api/workflows/[id]/deployments/route.tsReplaces inline Drizzle query with listWorkflowVersions; Admin fallback now applied inside the helper, behavior identical.
apps/sim/app/api/workflows/[id]/deployments/[version]/route.tsGET now delegates to getWorkflowDeploymentVersion; PATCH uses statusForOrchestrationError. Leftover db/workflowDeploymentVersion imports are still needed by the activation update in PATCH.
apps/sim/lib/copilot/tools/handlers/deployment/manage.tsReplaces inline Drizzle query in executeGetDeploymentLog with listWorkflowVersions; the extra deployedByName field from the helper is correctly discarded in the output map.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph Routes ["Deployment Route Surfaces"]
R1["v1 /deploy POST+DELETE"]
R2["v1 /rollback POST"]
R3["tools /deploy POST"]
R4["tools /promote POST"]
R5["workflows /deploy POST"]
R6["workflows /deployments/version PATCH"]
end
subgraph Helpers ["New Shared Helpers"]
P1["resolveV1DeploymentWorkflow\n(active record + admin check + 404 mask)"]
P2["statusForOrchestrationError\n(validation→400, not_found→404, else→500)"]
P3["getWorkflowDeploymentVersion\n(single version fetch)"]
P4["listWorkflowVersions\n(version list + Admin fallback)"]
end
R1 --> P1
R2 --> P1
R1 --> P2
R2 --> P2
R3 --> P2
R4 --> P2
R5 --> P2
R6 --> P2
subgraph VersionRoutes ["Version Read Surfaces"]
V1["tools /version GET"]
V2["workflows /deployments/:version GET"]
V3["workflows /deployments GET"]
V4["copilot executeGetDeploymentLog"]
end
V1 --> P3
V2 --> P3
V3 --> P4
V4 --> P4
Loading

Reviews (2): Last reviewed commit: "refactor(deployments): shared status map..." | Re-trigger Greptile

…d v1 workflow resolver
- statusForOrchestrationError maps orchestration error codes to HTTP statuses
in one place (was an identical ternary in six routes: UI deploy/activate,
v1 deploy/rollback, tool deploy/promote)
- getWorkflowDeploymentVersion consolidates the single-version fetch used by
the UI version GET and the deployments tool version route
- resolveV1DeploymentWorkflow extracts the v1 mutation prologue (active-record
load, admin permission check, 404 masking) shared by deploy, undeploy, and
rollback
@waleedlatif1waleedlatif1 changed the title refactor(deployments): consolidate version-list reads onto listWorkflowVersionsrefactor(deployments): consolidate version reads, status mapping, and v1 auth prologueJun 12, 2026
@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@waleedlatif1

Copy link
Copy Markdown
CollaboratorAuthor

@cursor review

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2e6570e. Configure here.

@waleedlatif1
waleedlatif1 merged commit cd324d5 into stagingJun 13, 2026
15 checks passed
@waleedlatif1
waleedlatif1 deleted the refactor/deployments-version-list branch June 13, 2026 00:12
Sign up for freeto 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.

1 participant

@waleedlatif1