Show the bound script source alongside order results

This commit is contained in:
2026-11-17 23:21:30 +01:00
parent 10f18dee76
commit ff25c38251
5 changed files with 118 additions and 28 deletions
+40 -2
View File
@@ -1,6 +1,7 @@
import { test, expect } from '../../web/node_modules/@playwright/test/index.js';
import { createServer, type ViteDevServer } from '../../web/node_modules/vite/dist/node/index.js';
import { createHash, randomUUID } from 'node:crypto';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
let server: ViteDevServer;
@@ -62,7 +63,7 @@ test.afterAll(async () => {
await server?.close();
});
test('opens a single result automatically and shows each result at its own device row', async ({ page }) => {
test('shows the bound script text alongside single and per-device results', async ({ page }) => {
const operationId = randomUUID();
const multiOperationId = randomUUID();
const jobs = [linux, windows].map((device, index) => ({
@@ -71,8 +72,31 @@ test('opens a single result automatically and shows each result at its own devic
attempt_id: randomUUID(),
state: index === 0 ? 'succeeded' : 'failed'
}));
const golden = JSON.parse(readFileSync(resolve(__dirname, '../script_console/codec-golden.json'), 'utf8')) as
{ name: string; plan_payload_bytes: number[] }[];
const [linuxPlan, windowsPlan] = ['legacy_linux_agent', 'windows_system_full'].map(name => {
const fixture = golden.find(row => row.name === name);
if (!fixture) throw new Error('Missing script fixture: ' + name);
return JSON.parse(Buffer.from(fixture.plan_payload_bytes).toString('utf8'));
});
const boundJobs = [linuxPlan, windowsPlan].map(({ jobs: [job] }, index) => {
const { asset_id, agent_id, job_id, attempt_id } = jobs[index]!;
const payload = { ...job.payload, tenant_id: tenantId, asset_id, agent_id, job_id, attempt_id };
return { ...job, payload, job_payload_hash: hash(JSON.stringify(payload)) };
});
const views = [operationId, multiOperationId].map((id, index) => {
const planJobs = index === 0 ? boundJobs.slice(0, 1) : boundJobs;
const plan = { ...linuxPlan, plan_id: randomUUID(), tenant_id: tenantId, jobs: planJobs };
if (!index) plan.script_revision = {
revision_id: randomUUID(), name: script.name, version: 2, script_sha256: planJobs[0]!.script_sha256
};
const raw = JSON.stringify(plan);
return { operation_id: id, plan_id: plan.plan_id, plan_hash: hash(raw),
plan_payload: plan, plan_payload_bytes: [...Buffer.from(raw)] };
});
const api = '/api/v1/tenants/' + tenantId;
const resultReads = new Set<string>();
let mismatchedPlan = false;
await page.route(origin + '/auth/config', r => r.fulfill({ json: {
dev_login_enabled: true, oidc_configured: false, oidc_login_url: null
} }));
@@ -85,13 +109,17 @@ test('opens a single result automatically and shows each result at its own devic
if (pathname === '/api/v1/approvals') return r.fulfill({ json: { ...listing([]), pending_count: 0 } });
if (pathname.startsWith(api + '/operations/')) {
const id = pathname.slice((api + '/operations/').length);
const view = views.find(item => item.operation_id === id);
if (id === operationId || id === multiOperationId) return r.fulfill({ json: {
operation_id: id, customer_name: 'Nord', title: script.name, approval_state: 'approved',
operation_id: id, customer_name: 'Nord', title: script.name, action: 'run_script', approval_state: 'approved',
plan_id: view?.plan_id, plan_hash: view?.plan_hash,
execution_state: id === operationId ? 'succeeded' : 'partially_succeeded',
targets: id === operationId ? [linux] : [linux, windows],
jobs: id === operationId ? jobs.slice(0, 1) : jobs
} });
}
const plan = views.find(view => pathname === api + '/operation-plans/' + view.plan_id);
if (plan) return r.fulfill({ json: mismatchedPlan ? { ...plan, operation_id: randomUUID() } : plan });
const job = jobs.find(item => pathname === api + '/jobs/' + item.job_id);
if (job) {
const success = job.state === 'succeeded';
@@ -110,6 +138,9 @@ test('opens a single result automatically and shows each result at its own devic
await expect(page.getByRole('heading', { name: 'Ergebnis für test-linux' })).toBeVisible();
await expect(page.getByLabel('stdout Textansicht')).toHaveText('Linux');
await expect(page.getByText('Exitcode 0', { exact: true })).toBeVisible();
const source = page.getByRole('article', { name: 'Skriptinhalt' });
await expect(source.getByLabel('Gespeicherter Skripttext')).toHaveText(boundJobs[0]!.payload.action.script_utf8.trim());
await expect(source.getByText('Version 2 · posix_sh')).toBeVisible();
expect([...resultReads]).toEqual(jobs.slice(0, 1).map(job => job.job_id));
await page.setViewportSize({ width: 390, height: 844 });
@@ -119,6 +150,9 @@ test('opens a single result automatically and shows each result at its own devic
const windowsButton = page.getByRole('button', { name: 'Ergebnis anzeigen für test-windows' });
await expect(linuxButton).toBeVisible();
await expect(windowsButton).toBeVisible();
await expect(source.getByRole('heading', { name: 'test-linux' })).toBeVisible();
await expect(source.getByRole('heading', { name: 'test-windows' })).toBeVisible();
await expect(source.getByLabel('Gespeicherter Skripttext')).toHaveText(boundJobs.map(job => job.payload.action.script_utf8.trim()));
expect(resultReads.size).toBe(0);
await linuxButton.click();
const linuxRow = page.getByRole('listitem').filter({ has: page.getByRole('button', { name: 'Ergebnis schließen für test-linux' }) });
@@ -129,6 +163,10 @@ test('opens a single result automatically and shows each result at its own devic
await page.getByRole('button', { name: 'Ergebnis schließen für test-windows' }).click();
await expect(page.getByRole('region', { name: 'Gespeichertes Konsolenergebnis' })).toHaveCount(0);
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(390);
mismatchedPlan = true;
await page.reload();
await expect(source.getByRole('alert')).toContainText('konnte diesem Auftrag nicht zugeordnet werden');
await expect(source.getByLabel('Gespeicherter Skripttext')).toHaveCount(0);
});
for (const library of [true, false]) {