PSA/ee/appliance/operator/tests/workloads.test.mjs
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

105 lines
2.9 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { listAppliancePods, readPodLogsSince, readPodLogsTail } from '../lib/workloads.mjs';
class FakeRunner {
constructor(handlers = []) {
this.handlers = handlers;
this.calls = [];
}
async runCapture(command, args) {
this.calls.push([command, ...args]);
const handler = this.handlers.shift();
if (!handler) {
return { ok: false, code: 1, output: 'unexpected command' };
}
return handler(command, args);
}
}
function makeEnv() {
return {
runtime: { assetRoot: '/tmp' },
paths: { kubeconfig: '/tmp/kubeconfig' },
};
}
test('listAppliancePods returns appliance namespace pods with status columns', async () => {
const runner = new FakeRunner([
async () => ({
ok: true,
code: 0,
output: JSON.stringify({
items: [
{
metadata: {
namespace: 'msp',
name: 'alga-core-0',
creationTimestamp: '2026-03-25T11:59:00Z',
},
spec: {
containers: [{ name: 'app' }, { name: 'sidecar' }],
},
status: {
phase: 'Running',
startTime: '2026-03-25T12:00:00Z',
containerStatuses: [
{ ready: true, restartCount: 1, state: { running: {} } },
{ ready: false, restartCount: 2, state: { waiting: { reason: 'CrashLoopBackOff' } } },
],
},
},
],
}),
}),
]);
const result = await listAppliancePods(makeEnv(), {
runner,
nowMs: Date.parse('2026-03-25T13:00:00Z'),
});
assert.deepEqual(result.namespaces, ['msp']);
assert.equal(result.pods.length, 1);
assert.equal(result.pods[0].key, 'msp/alga-core-0');
assert.equal(result.pods[0].ready, '1/2');
assert.equal(result.pods[0].restarts, 3);
assert.equal(result.pods[0].status, 'CrashLoopBackOff');
assert.equal(result.pods[0].age, '1h');
assert.deepEqual(result.errors, []);
});
test('readPodLogsTail and readPodLogsSince parse timestamped lines', async () => {
const runner = new FakeRunner([
async () => ({
ok: true,
code: 0,
output: [
'2026-03-25T12:00:00Z ready',
'2026-03-25T12:00:01Z reconciling',
].join('\n'),
}),
async () => ({
ok: true,
code: 0,
output: '2026-03-25T12:00:02Z done\n',
}),
]);
const pod = { namespace: 'msp', name: 'alga-core-0' };
const tail = await readPodLogsTail(makeEnv(), pod, { runner, tailLines: 50 });
assert.equal(tail.ok, true);
assert.equal(tail.lines.length, 2);
assert.equal(tail.lines[0].timestamp, '2026-03-25T12:00:00Z');
assert.equal(tail.lines[0].message, 'ready');
const since = await readPodLogsSince(makeEnv(), pod, {
runner,
sinceTime: '2026-03-25T12:00:01Z',
});
assert.equal(since.ok, true);
assert.equal(since.lines.length, 1);
assert.equal(since.lines[0].message, 'done');
});