fix(webui): Stop in the agent drawer: an archived or unavailable organization says so in Restart's plain line ending Nothing changed, not Outcome unknown, with one test each; each Stop keeps its own state per agent, as each restart does, so a second Stop or question in another drawer no longer drops a running Stop's line or its running state, with a two-drawer test (#1873, lane sp20-drawer-stop)
This commit is contained in:
1 parent
57af33630d
commit
b23ccdfc12
2 files changed
+95
-17
No files matched your search
@@ -910,3 +910,73 @@ for (const [label, answers, line] of [
|
||||
assert.equal(posts.filter(p => p.url.endsWith('/agent/launch')).length, launched ? 1 : 0);
|
||||
assert.equal(await b.evaluate('window.__answers.length'), 0, 'every queued answer was asked for');
|
||||
});
|
||||
|
||||
// SP20 (#1873): an organization refusal of Stop says so in one plain line, the line Restart gives.
|
||||
for (const [label, answer, line] of [
|
||||
['the organization is archived', { status: 409, body: { error: 'org-archived', message: 'organization is archived' } },
|
||||
/^Not stopped: Acme Studio is archived, so its agents are not changed\. Nothing changed\.$/],
|
||||
['the organization is not available', { status: 404, body: { error: 'org-unavailable' } },
|
||||
/^Not stopped: Acme Studio is not available to this Console\. Nothing changed\.$/],
|
||||
]) test(`SP20: a Stop refusal says so in the drawer: ${label}`, async t => {
|
||||
const { b, wait } = await setup(t, { hash: '#/agents?agent=acme%3Acoder' });
|
||||
const d = '[data-ws-drawer="acme:coder"]';
|
||||
await wait(`${open('acme:coder')} && document.querySelector('${d} [data-drawer-stop]')`);
|
||||
await b.evaluate(`window.__answers.push(${JSON.stringify(answer)})`);
|
||||
await b.evaluate(`document.querySelector('${d} [data-drawer-stop]').click()`);
|
||||
await wait(`document.querySelector('${d} [data-drawer-stop-yes]')`);
|
||||
await b.evaluate(`document.querySelector('${d} [data-drawer-stop-yes]').click()`);
|
||||
await wait(`/^Not stopped: /.test(${status(d)}) && ${usable(d)}`);
|
||||
assert.match(await b.evaluate(status(d)), line);
|
||||
assert.equal(await b.evaluate(`document.activeElement === document.querySelector('${d} [data-drawer-stop]')`), true, 'focus is back on Stop');
|
||||
assert.deepEqual((await b.evaluate('window.__posts')).map(p => [p.url, p.method]), [['/api/orgs/acme/agent/terminate', 'POST']]);
|
||||
});
|
||||
|
||||
// SP20: each Stop keeps its own state, as each restart does. Another drawer's question or Stop does not
|
||||
// lose a running Stop's line or its running state, and a Stop that ends does not drop another drawer's question.
|
||||
test('SP20: two Stops in two drawers each keep their own line and running state', async t => {
|
||||
const data = D => { D.acme.instances.ideas = { definition: 'ideas', running: ['run-4'] }; };
|
||||
const { b, wait } = await setup(t, { hash: '#/agents?agent=acme%3Acoder', data });
|
||||
const d = '[data-ws-drawer="acme:coder"]', i = '[data-ws-drawer="acme:ideas"]';
|
||||
const refused = who => ({ status: 409, body: { error: 'instance-protected', message: `instance-protected: ${who} is protected from ending. Nothing changed.`, sent: false } });
|
||||
const state = x => `[${status(x)}, document.querySelector('${x} [data-drawer-stop]')?.firstChild.textContent, document.querySelector('${x} [data-drawer-stop]')?.disabled, document.querySelector('${x} [data-drawer-restart]')?.disabled]`;
|
||||
await wait(`${open('acme:coder')} && document.querySelector('${d} [data-drawer-stop]')`);
|
||||
// Coder's Stop runs: its terminate is held.
|
||||
await b.evaluate(`window.__answers.push({ hold: new Promise(r => { window.__release = r; }), ...${JSON.stringify(refused('coder'))} })`);
|
||||
await b.evaluate(`document.querySelector('${d} [data-drawer-stop]').click()`);
|
||||
await wait(`document.querySelector('${d} [data-drawer-stop-yes]')`);
|
||||
await b.evaluate(`document.querySelector('${d} [data-drawer-stop-yes]').click()`);
|
||||
await wait(`window.__posts.length === 1`);
|
||||
// Ideas asks to stop and is cancelled; back on coder, its Stop still shows as running.
|
||||
await b.evaluate('location.hash = "#/agents?agent=acme%3Aideas"');
|
||||
await wait(`${open('acme:ideas')} && document.querySelector('${i} [data-drawer-stop]')`);
|
||||
await b.evaluate(`document.querySelector('${i} [data-drawer-stop]').click()`);
|
||||
await wait(`document.querySelector('${i} [data-drawer-stop-no]')`);
|
||||
await b.evaluate(`document.querySelector('${i} [data-drawer-stop-no]').click()`);
|
||||
await b.evaluate('location.hash = "#/agents?agent=acme%3Acoder"');
|
||||
await wait(`${open('acme:coder')} && document.querySelector('${d} [data-drawer-stop]')`);
|
||||
assert.deepEqual(await b.evaluate(state(d)), ['Stopping coder…', 'Stopping…', true, true]);
|
||||
// Ideas' Stop question is open when coder's Stop is refused; each drawer keeps its own.
|
||||
await b.evaluate('location.hash = "#/agents?agent=acme%3Aideas"');
|
||||
await wait(`${open('acme:ideas')} && document.querySelector('${i} [data-drawer-stop]')`);
|
||||
await b.evaluate(`document.querySelector('${i} [data-drawer-stop]').click()`);
|
||||
await wait(`document.querySelector('${i} [data-drawer-stop-no]')`);
|
||||
await b.evaluate('window.__release()');
|
||||
await b.evaluate('new Promise(r => setTimeout(r, 300))');
|
||||
await b.evaluate('location.hash = "#/agents?agent=acme%3Acoder"');
|
||||
await wait(`${open('acme:coder')} && /^Not stopped: /.test(${status(d)}) && ${usable(d)}`);
|
||||
assert.equal(await b.evaluate(status(d)), 'Not stopped: instance-protected: coder is protected from ending. Nothing changed.');
|
||||
await b.evaluate('location.hash = "#/agents?agent=acme%3Aideas"');
|
||||
await wait(`${open('acme:ideas')} && document.querySelector('${i} [data-drawer-stop]')`);
|
||||
assert.equal(await b.evaluate(`!!document.querySelector('${i} [data-drawer-stop-yes]')`), true, 'ideas keeps its question');
|
||||
// Ideas' Stop runs and is refused; coder's line is still there after, and ideas' is too.
|
||||
await b.evaluate(`window.__answers.push(${JSON.stringify(refused('ideas'))})`);
|
||||
await b.evaluate(`document.querySelector('${i} [data-drawer-stop-yes]').click()`);
|
||||
await wait(`/^Not stopped: /.test(${status(i)}) && ${usable(i)}`);
|
||||
await b.evaluate('location.hash = "#/agents?agent=acme%3Acoder"');
|
||||
await wait(`${open('acme:coder')} && document.querySelector('${d} [data-drawer-stop]')`);
|
||||
assert.deepEqual(await b.evaluate(state(d)), ['Not stopped: instance-protected: coder is protected from ending. Nothing changed.', 'Stop', false, false]);
|
||||
await b.evaluate('location.hash = "#/agents?agent=acme%3Aideas"');
|
||||
await wait(`${open('acme:ideas')} && document.querySelector('${i} [data-drawer-stop]')`);
|
||||
assert.deepEqual(await b.evaluate(state(i)), ['Not stopped: instance-protected: ideas is protected from ending. Nothing changed.', 'Stop', false, false]);
|
||||
assert.deepEqual((await b.evaluate('window.__posts')).map(p => JSON.parse(p.body).instance), ['coder', 'ideas']);
|
||||
});
|
||||
Reference in new issue
Block a user