Files
archie/e2e/checks/execution-identities.cjs
T

47 lines
2.3 KiB
JavaScript

// Real local API records; workflow edits stay unsaved and the test agent retires.
const assert = require('node:assert/strict');
module.exports = async ({ page, go, shot }) => {
const base = process.env.ARCHIE_E2E_URL || 'http://localhost:5173';
const headers = { 'X-Archie-CSRF': '1', Origin: base };
let agent;
const command = async (name, display_name = '') => {
const response = await page.request.post(`${base}/api/identities/${agent.id}/${name}`, {
headers, data: { expected_version: agent.version, display_name },
});
assert.equal(response.ok(), true, await response.text());
agent = await response.json();
};
const openSettings = async () => {
await go('/workflows');
await page.getByRole('button', { name: /^implement/ }).click();
await page.locator('.vue-flow__node').filter({ hasText: 'Start' }).first().click();
return page.getByRole('combobox', { name: 'Execution identity', exact: true });
};
try {
const created = await page.request.post(`${base}/api/identities`, {
headers, data: { display_name: `E2E execution agent ${Date.now()}`, kind: 'bot' },
});
assert.equal(created.ok(), true, await created.text());
agent = await created.json();
const select = await openSettings();
await select.locator(`option[value="${agent.id}"]`).waitFor({ state: 'attached' });
assert.equal(await select.locator(`option[value="${agent.id}"]`).textContent(), agent.display_name);
await select.selectOption(agent.id);
assert.equal(await select.inputValue(), agent.id);
await shot('named-execution-identity');
await command('rename', agent.display_name + ' renamed');
await page.reload();
const renamed = await openSettings();
await renamed.locator(`option[value="${agent.id}"]`).waitFor({ state: 'attached' });
assert.equal(await renamed.locator(`option[value="${agent.id}"]`).textContent(), agent.display_name);
await command('suspend');
await page.reload();
const suspended = await openSettings();
await suspended.waitFor();
await page.waitForFunction(() => !document.querySelector('select[aria-label="Execution identity"]')?.disabled);
assert.equal(await suspended.locator(`option[value="${agent.id}"]:not([disabled])`).count(), 0);
} finally {
if (agent && agent.lifecycle !== 'retired') await command('retire');
}
};