Plan device actions exclusively as approved scripts and provide reboot library revisions

This commit is contained in:
2026-11-18 12:04:58 +01:00
parent adc04f0148
commit cd80bfc704
31 changed files with 1014 additions and 779 deletions
+26 -30
View File
@@ -26,7 +26,7 @@ test('simulated human prepares root request through UI only, without approving',
const request = object(expected.request), params = object(request.parameters);
expect(params.execution_identity).toBe('root');
expect(object(request.targets).asset_ids).toEqual([expected.asset_id]);
expect(['run_script', 'query_logs', 'set_service_state', 'apt_native_acceptance', 'ensure_package', 'apply_updates', 'reboot']).toContain(request.action);
if (request.action !== 'run_script') throw new Error('Retired device action. Supply a run_script request for this preparation.');
let authorizationRequests = 0;
page.on('request', r => { if (new URL(r.url()).pathname.endsWith('/authorizations')) authorizationRequests++; });
const sessionResponse = page.waitForResponse(r => new URL(r.url()).pathname === '/auth/session' && r.status() === 200);
@@ -38,39 +38,30 @@ test('simulated human prepares root request through UI only, without approving',
await page.getByRole('checkbox', { name: `Ziel ${text(expected.asset_id)}`, exact: true }).check();
await page.getByRole('link', { name: 'Aufträge', exact: true }).click();
await page.getByRole('link', { name: 'Neuer Auftrag', exact: true }).click();
await page.getByRole('link', { name: 'Verwaltung', exact: true }).click();
await page.getByRole('link', { name: 'Erweitert', exact: true }).click();
await page.getByRole('link', { name: 'Wartungsauftrag planen', exact: true }).click();
await page.getByLabel('Aktion', { exact: true }).selectOption(text(request.action));
if (request.action === 'run_script') {
const variants = params.variants;
if (!Array.isArray(variants) || variants.length !== 1) throw new Error('One exact script variant required');
const variant = object(variants[0]);
await page.getByRole('combobox', { name: 'Interpreter', exact: true }).selectOption(text(variant.interpreter));
await page.getByLabel('Exakte UTF-8 Skriptbytes', { exact: false }).fill(text(variant.script_utf8));
await page.getByLabel('Erwartete stdout-Ausgabe', { exact: false }).fill(text(params.expected_stdout));
} else {
await page.getByLabel('Aktionsparameter', { exact: true }).fill(JSON.stringify(params));
}
await page.getByLabel('Ausführungsidentität', { exact: true }).selectOption('root');
await page.getByLabel('Laufzeitlimit (s)', { exact: true }).fill(String(params.timeout_seconds));
await page.getByLabel('Ausgabelimit (Bytes)', { exact: true }).fill(String(params.max_output_bytes));
// Runner fixes browser/Node TZ to UTC. The actual UI's minute-precision form
// selects an explicit future minute; all resulting exact bytes are reviewed
// again in the separate approval test before any executable job can exist.
await page.getByRole('button', { name: 'Weiter zum Skript', exact: true }).click();
await page.getByRole('radio', { name: 'Einmaliges Skript' }).check();
const variants = params.variants;
if (!Array.isArray(variants) || variants.length !== 1) throw new Error('One exact script variant required');
const variant = object(variants[0]);
await page.getByLabel('Plattform und Interpreter').selectOption(text(variant.interpreter));
await page.getByLabel('Skriptinhalt', { exact: true }).fill(text(variant.script_utf8));
await page.getByLabel('Ausführen als', { exact: true }).selectOption('root');
await page.getByText('Zeitfenster und Ausführungsoptionen', { exact: true }).click();
await page.getByLabel('Erwartete Standardausgabe (optional)').fill(params.expected_stdout == null ? '' : text(params.expected_stdout));
await page.getByLabel('Laufzeit je Gerät in Sekunden').fill(String(params.timeout_seconds));
await page.getByLabel('Ausgabelimit in Byte').fill(String(params.max_output_bytes));
const start = new Date(Math.ceil(Date.now() / 60000) * 60000);
await page.getByLabel('Frühester Start (lokale Zeit)', { exact: true }).fill(start.toISOString().slice(0, 16));
await page.getByLabel('Startfrist / Ablauf (lokale Zeit)', { exact: true }).fill(new Date(start.getTime() + 15 * 60000).toISOString().slice(0, 16));
await page.getByLabel('Maximal parallel', { exact: true }).fill('1');
await page.getByLabel('Frühester Start', { exact: true }).fill(start.toISOString().slice(0, 16));
await page.getByLabel('Startfrist', { exact: true }).fill(new Date(start.getTime() + 15 * 60000).toISOString().slice(0, 16));
await page.getByLabel('Geräte gleichzeitig').fill('1');
await page.getByLabel('Stopp nach Fehlern', { exact: true }).fill('1');
await page.getByLabel('Begründung', { exact: true }).fill(text(request.reason));
await page.getByRole('button', { name: 'Plan erstellen · noch keine Ausführung' }).click();
const detail = page.locator('section[data-plan-id]');
await detail.getByText('Technische Plandaten', { exact: true }).click();
await expect(detail.getByLabel('Technische Plandaten', { exact: true })).toBeVisible();
const plan = object(JSON.parse(await detail.getByLabel('Technische Plandaten', { exact: true }).innerText()));
const prepared = page.waitForResponse(r => r.request().method() === 'POST' && new URL(r.url()).pathname.endsWith('/operation-plans') && r.ok());
await page.getByRole('button', { name: 'Zusammenfassung ansehen' }).click();
await expect(page.getByRole('heading', { name: 'Zusammenfassung' })).toBeVisible();
const plan = object(await (await prepared).json());
expect(createHash('sha256').update(bytes(plan.plan_payload_bytes)).digest('hex')).toBe(plan.plan_hash);
await detail.getByRole('button', { name: 'Zur Genehmigung einreichen' }).click();
await page.getByRole('button', { name: 'Zur Genehmigung einreichen' }).click();
const op = page.locator('section[data-operation-id]');
await op.getByText('Technische Auftragsdaten', { exact: true }).click();
await expect(op.getByLabel('Technische Auftragsdaten', { exact: true })).toContainText('"job_count": 0');
@@ -186,6 +177,11 @@ test('one opted-in immutable dev/test action: inspect all fixed bytes → UI cli
const approve = detail.getByRole('button', { name: 'SIMULIERT: Genehmigen', exact: true });
await expect(approve).toBeDisabled();
await detail.getByRole('checkbox', { name: 'Ich habe die Geräte, den Inhalt und die Ausführungsrechte geprüft.', exact: false }).check();
if (action.action !== 'run_script') {
await expect(approve).toBeDisabled();
await expect(detail.getByRole('alert')).toContainText('frühere Aktionsart');
return;
}
await expect(approve).toBeEnabled();
await approve.click(); // Deliberately no API client, injected fetch, route or direct approval request.
await op.getByText('Technische Auftragsdaten', { exact: true }).click();