Show provisioning requesters and reserve Maxis for system actions

This commit is contained in:
2026-10-08 16:19:49 -04:00
parent 2b155ded8f
commit d8fb7e1d66
10 changed files with 77 additions and 15 deletions
+16 -3
View File
@@ -9,17 +9,30 @@ afterEach(async () => { await fixture.cleanup(); });
it('persists the manual requester while preserving source filtering and historical records', async () => {
const { withRequestUsername } = await import('../../src/lib/server/auth/request-context.js');
const { beginDeployment, getDeployment, listDeployments } = await import('../../src/lib/server/provisioning/history.js');
const { closeDb } = await import('../../src/lib/server/db/index.js');
const { db, closeDb } = await import('../../src/lib/server/db/index.js');
const legacy = beginDeployment('legacy', 'restart');
const [manual, automatic] = await withRequestUsername('alice', async () => [
beginDeployment('manual', 'restart'), beginDeployment('automatic', 'restart', 'watchdog:incident')
const [manual, automatic, rebalance] = await withRequestUsername('alice', async () => [
beginDeployment('manual', 'restart'), beginDeployment('automatic', 'restart', 'watchdog:incident'),
beginDeployment('rebalance', 'restart', 'rebalance:run')
]);
closeDb();
expect(getDeployment(manual)?.deployment).toMatchObject({ triggered_by: 'ui', requested_by: 'alice' });
expect(getDeployment(automatic)?.deployment).toMatchObject({ triggered_by: 'watchdog:incident', requested_by: null });
expect(getDeployment(rebalance)?.deployment).toMatchObject({ triggered_by: 'rebalance:run', requested_by: 'alice' });
expect(getDeployment(legacy)?.deployment).toMatchObject({ triggered_by: 'ui', requested_by: null });
expect(listDeployments({ source: 'manual' }).map(row => row.id)).toEqual(expect.arrayContaining([manual, legacy]));
expect(listDeployments({ source: 'manual' }).map(row => row.id)).not.toContain(automatic);
const { GET } = await import('../../src/routes/api/provisioning/+server.js');
for (const view of ['active', 'history']) {
if (view === 'history') db().prepare("UPDATE server_deployments SET state='done'").run();
const result = await GET({ url: new URL(`http://localhost/api/provisioning?view=${view}`) }).json();
expect(result.deployments).toEqual(expect.arrayContaining([
expect.objectContaining({ id: manual, requested_by: 'alice' }),
expect.objectContaining({ id: automatic, requested_by: null }),
expect.objectContaining({ id: rebalance, requested_by: 'alice' }),
expect.objectContaining({ id: legacy, requested_by: null })
]));
}
});
it('isolates overlapping users and stops attributing deferred work after the request returns', async () => {