Add enhanced admin access checks and error handling for draft transaction customers and self-serve processes. Extend edge gateway diagnostics, refine terminal readiness detection, and improve live session test coverage.

This commit is contained in:
Jeppe Bundgaard
2026-04-28 09:01:52 +02:00
parent d411da2a12
commit e26e37d9d7
19 changed files with 701 additions and 81 deletions
+58 -8
View File
@@ -465,16 +465,16 @@ function paginateRows(rows, page = 1, limit = 10) {
function createSelfServeFixture(overrides = {}) {
const departments = [
{
id: 1,
name: "Copenhagen",
address: "Alpha 1",
latitude: 55.6761,
longitude: 12.5683,
id: 6,
name: "Roskilde",
address: "Industrivej 45, 4000 Roskilde",
latitude: 55.6415,
longitude: 12.0803,
self_serve_enabled: true,
lanes: [
{
id: 7,
department: 1,
department: 6,
name: "7",
status: "AVAILABLE",
machine_available: true,
@@ -489,7 +489,7 @@ function createSelfServeFixture(overrides = {}) {
},
{
id: 8,
department: 1,
department: 6,
name: "8",
status: "FAULT",
machine_available: false,
@@ -725,6 +725,7 @@ function createSelfServeFixture(overrides = {}) {
},
laneAllowedServices: ["MACHINE"],
commandResponse: { success: true },
commandResponses: null,
relayResponse: { success: true },
dynamicImage: TINY_PNG,
};
@@ -1830,6 +1831,14 @@ function createHttpEdgeGatewayFixture(options = {}) {
nextOperationEventId: 19901,
claimPollsRemaining: Number(options.claimPollsRemaining || 2),
reuseClaimGatewayId: Number(options.reuseClaimGatewayId || 0),
shellSessionFailure:
options.shellSessionFailure && typeof options.shellSessionFailure === "object"
? cloneJson(options.shellSessionFailure)
: null,
shellSessionMockClose:
options.shellSessionMockClose && typeof options.shellSessionMockClose === "object"
? cloneJson(options.shellSessionMockClose)
: null,
installSessionFailure:
options.installSessionFailure && typeof options.installSessionFailure === "object"
? cloneJson(options.installSessionFailure)
@@ -4942,6 +4951,26 @@ async function handleEdgeGatewayRoute({ route, request, parsedUrl, pathname, met
return true;
}
if (edgeGatewayFixture.shellSessionFailure) {
const failure = edgeGatewayFixture.shellSessionFailure;
await route.fulfill(
json(
{
success: false,
data: {
message:
failure.message ||
"Gateway agent is not connected to the broker. Restart the edge agent or check the broker URL.",
error_code: failure.error_code || "BROKER_DISCONNECTED",
diagnostics: cloneJson(failure.diagnostics || {}),
},
},
Number(failure.status || 409)
)
);
return true;
}
const sessionId = edgeGatewayFixture.nextShellSessionId++;
const body = request.postDataJSON?.() || {};
const session = {
@@ -4986,6 +5015,23 @@ async function handleEdgeGatewayRoute({ route, request, parsedUrl, pathname, met
expires_at: "2026-04-09 10:15:00",
broker_url: "https://broker.example.test",
ws_url: "mock-ws://edge-broker/browser-shell",
diagnostics: {
ready: true,
reason_code: "READY",
message: "Gateway shell broker path is ready.",
gateway_id: gatewayId,
broker_url: "https://broker.example.test",
ws_url: "mock-ws://edge-broker/browser-shell",
broker_presence: {
connected: true,
connection_id: "mock-broker-1",
last_seen_at: "2026-04-09 09:14:59",
age_seconds: 2,
last_error: null,
disconnect_reason: null,
},
},
mock_close_before_open: edgeGatewayFixture.shellSessionMockClose,
mock_banner: `Connected to ${gateway.label || gateway.hostname}.\n`,
mock_prompt: "edge@truckwash:/opt/truckwash-edge-agent$ ",
},
@@ -5566,7 +5612,11 @@ export async function mockApi(page, options = {}) {
}
if (pathname.endsWith("/modules/self-serve/lane/command") && method === "POST") {
await route.fulfill(json(selfServe.commandResponse));
const commandResponse =
Array.isArray(selfServe.commandResponses) && selfServe.commandResponses.length > 0
? selfServe.commandResponses.shift()
: selfServe.commandResponse;
await route.fulfill(json(commandResponse));
return;
}