fix(stacks): pass environment id when loading saved compose for env validation#1168
Open
chris-ruecker wants to merge 1 commit into
Open
fix(stacks): pass environment id when loading saved compose for env validation#1168chris-ruecker wants to merge 1 commit into
chris-ruecker wants to merge 1 commit into
Conversation
…alidation The env validate endpoint parses the env id from the query string and uses it for permission checks and the env var lookup, but omitted it when loading the stack's saved compose file. getStackSource then filters on a NULL environmentId, so the lookup fails for every environment-scoped stack and the endpoint returns 400 even though the compose file exists. The dockhand UI always sends the compose content in the request body, so it never hits this path; any API client relying on the documented saved-file mode (empty body) does. The sibling compose endpoint already passes the env id; this aligns the validate handler with it.
chris-ruecker
force-pushed
the
fix/env-validate-saved-compose-env-id
branch
from
June 17, 2026 18:10
f66e3c0 to
b9fc6f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
POST /api/stacks/[name]/env/validate?env=<id>returns400 {"error":"No compose content provided and no saved compose file found"}for every environment-scoped stack when the request body contains no compose content — even though the stack has a saved compose file and the endpoint documents this mode ("Can use saved compose file or accept compose content in body").Root cause
The handler parses the environment id from the query string and uses it for the permission checks and the env var lookup, but drops it when loading the saved compose file:
getStackComposeFile(stackName, envId?)resolves the stack viagetStackSource(stackName, envId), andgetStackSourcetreats a missing env id asisNull(stackSources.environmentId)— so for a stack with a non-nullenvironmentIdthe lookup finds no row,getStackComposeFilereturnsneedsFileLocation: true, and the handler responds 400.Fix
Pass the already-parsed
envIdNumthrough, matching what the sibling compose endpoint (src/routes/api/stacks/[name]/compose/+server.ts) already does:For non-env (legacy) stacks
envIdNumisnull, which preserves the currentisNull(environmentId)lookup — their behaviour is unchanged.Why this went unnoticed
The Dockhand UI (
StackModal.svelte) always sends{ compose, variables }in the request body, which bypasses the saved-file path entirely. Only API clients using the empty-body mode hit the bug. Discovered while writing end-to-end tests for a CLI client that calls this endpoint.How to reproduce / test
Against any stack created in a non-default environment (replace
<id>with the environment id):Before:
400 {"error":"No compose content provided and no saved compose file found"}After:
200with the expected{valid, required, optional, defined, missing, unused}validation result.Stacks without an environment scope and UI-driven validation (compose in body) behave exactly as before.
Type of change