Files
pikasTech-unidesk/scripts/src/hwlab-node-web-sentinel-cicd-shared.test.ts
T

40 lines
1.5 KiB
TypeScript

import { mkdirSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { describe, expect, test } from "bun:test";
import { resolveSentinelChildJson } from "./hwlab-node-web-sentinel-cicd-shared";
describe("sentinel CI/CD child JSON recovery", () => {
test("recovers remote probe JSON from trans truncation dump", () => {
const dir = join(tmpdir(), `unidesk-sentinel-cicd-${Date.now()}-${process.pid}`);
mkdirSync(dir, { recursive: true });
const dumpPath = join(dir, "stdout.json");
writeFileSync(dumpPath, JSON.stringify({
ok: true,
present: true,
digest: "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
valuesRedacted: true,
}));
const summary = {
stdout: {
stream: "stdout",
truncated: true,
dumpPath,
valuesRedacted: true,
},
valuesRedacted: true,
};
const resolved = resolveSentinelChildJson({
stdout: "tail fragment that is not json",
stderr: `UNIDESK_SSH_TRUNCATION_SUMMARY ${JSON.stringify(summary)}\n`,
exitCode: 0,
timedOut: false,
}, "web-probe-sentinel-test-probe");
expect(resolved.parsed?.ok).toBe(true);
expect(resolved.parsed?.present).toBe(true);
expect(resolved.diagnostics.stdoutKind).toBe("ssh-truncation-summary");
expect(resolved.diagnostics.dumpPath).toBe(dumpPath);
expect(resolved.diagnostics.source).toBe("dump");
});
});