fix(deploy): normalize Docker access errors and harden SSE parsing
- handle malformed plain-text SSE payloads safely - normalize Docker socket permission errors - verify authoritative deployment job status - preserve deployment logs on failure
This commit is contained in:
1 parent
323596c586
commit
73b4b6255d
8 files changed
+182
-31
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { formatDeploymentErrorMessage } from "../../src/server/services/ssh-services/docker-containers.ts";
|
||||
import {
|
||||
DOCKER_ACCESS_DENIED_MESSAGE,
|
||||
parseDockerJson,
|
||||
} from "../../src/server/services/ssh-services/internal/docker.ts";
|
||||
|
||||
test("Docker socket permission failures have an actionable deployment error", () => {
|
||||
const message = formatDeploymentErrorMessage(
|
||||
new Error(
|
||||
"permission denied while trying to connect to the docker API at unix:///var/run/docker.sock",
|
||||
),
|
||||
);
|
||||
|
||||
assert.match(message, /Docker access was denied/i);
|
||||
assert.match(message, /docker group/i);
|
||||
assert.doesNotMatch(message, /Unexpected token|not valid JSON/i);
|
||||
});
|
||||
|
||||
test("Docker JSON parsing reports socket permission failures before JSON errors", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
parseDockerJson(
|
||||
"permission denied while trying to connect to the docker API at unix:///var/run/docker.sock",
|
||||
"Docker image inspection",
|
||||
),
|
||||
{ message: DOCKER_ACCESS_DENIED_MESSAGE },
|
||||
);
|
||||
});
|
||||
|
||||
test("Docker JSON parsing hides malformed raw output", () => {
|
||||
assert.throws(
|
||||
() => parseDockerJson("not-json", "Docker image inspection"),
|
||||
{ message: "Docker image inspection returned an invalid response from Docker" },
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { parseServerSentEventBlock } from "../src/lib/server-sent-events.ts";
|
||||
|
||||
test("SSE parser reads JSON events with CRLF delimiters", () => {
|
||||
assert.deepEqual(
|
||||
parseServerSentEventBlock(
|
||||
'event: log\r\ndata: {"id":1,"message":"building"}',
|
||||
),
|
||||
{ event: "log", data: { id: 1, message: "building" } },
|
||||
);
|
||||
});
|
||||
|
||||
test("SSE parser preserves malformed plain-text data instead of throwing", () => {
|
||||
assert.deepEqual(
|
||||
parseServerSentEventBlock(
|
||||
"event: error\ndata: permission denied while trying to connect to /var/run/docker.sock",
|
||||
),
|
||||
{
|
||||
event: "error",
|
||||
data: "permission denied while trying to connect to /var/run/docker.sock",
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user