fix(swarm): normalize health check test commands - #5205
Open
bestmaa wants to merge 4 commits into
Open
Conversation
| return ["NONE"]; | ||
| } | ||
|
|
||
| if (/^\[\s*(?:"|\])/.test(value)) { |
Contributor
There was a problem hiding this comment.
When a user pastes a JSON array beginning with a non-string value such as [1], this predicate skips JSON parsing and converts the input to CMD-SHELL, causing Docker to execute the JSON text as a shell health check instead of returning the intended validation error.
Suggested change
| if (/^\[\s*(?:"|\])/.test(value)) { | |
| if (value.startsWith("[")) { |
Contributor
Author
There was a problem hiding this comment.
Fixed in 1727c27. The normalizer now parses every value beginning with an opening bracket before validating the array entries, while still preserving valid POSIX test expressions such as [ -f /tmp/ready ] as shell commands. I also added regression coverage for [1]; the focused suite now passes all 20 tests. Thanks for catching this.
Contributor
Author
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.
What is this PR about?
This fixes Swarm health checks getting stuck in
Startingwhen the UI stores the entireTestJSON array as one string. Health-check commands are now normalized both when the form is saved and again when the Docker service spec is generated, so previously stored malformed values are covered too.CMD-SHELLform.NONEinstead of[""].Testing
pnpm --filter=dokploy exec vitest --config __test__/vitest.config.ts __test__/server/swarm-health-check.test.ts __test__/server/mechanizeDockerContainer.test.ts --run: 20 tests passed on Node 24.4.0.pnpm --filter=@dokploy/server run typecheck: passed.pnpm build: passed on Node 24.4.0.Test: [""]stayed at0/1and Docker logged an unknown healthcheck type warning.1/1 Running, with no new invalid-healthcheck warning.Checklist
canarybranch.Issues related
Closes #5171
Screenshots
Not applicable; this change is covered by before/after Docker service state and regression tests.
Greptile Summary
This PR adds shared normalization for Swarm health-check commands at both form-save and Docker service-generation boundaries.
Confidence Score: 4/5
The PR should not merge until pasted JSON arrays beginning with non-string values are rejected instead of being persisted as shell health checks.
The new JSON detection only validates a subset of array-shaped inputs, allowing inputs such as
[1]to bypass the advertised array-of-strings validation and reach Docker as an unintended shell command.Files Needing Attention: packages/server/src/utils/docker/health-check.ts
Reviews (1): Last reviewed commit: "fix(swarm): normalize health check test ..." | Re-trigger Greptile