Treat successful but empty live projections with existing live input as stale, reject them on the frontend, and keep the previous visible channel state during rebuild failures. Add DOM coverage for the Settings analysis flow and backend serialization coverage for empty projection state. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { isAdmin } = require('../server/authz');
|
|
const { serializeState } = require('../server/routes/live');
|
|
|
|
const routeSource = fs.readFileSync(path.join(__dirname, '..', 'server', 'routes', 'live.js'), 'utf8');
|
|
|
|
test('projection status route requires authentication', () => {
|
|
assert.match(routeSource, /router\.get\('\/projection\/status', requireAuth,/);
|
|
});
|
|
|
|
test('projection rebuild route requires authentication and admin authorization', () => {
|
|
assert.match(routeSource, /router\.post\('\/projection\/rebuild', requireAuth, requireAdmin,/);
|
|
});
|
|
|
|
test('projection authorization distinguishes viewer and admin roles', () => {
|
|
assert.equal(isAdmin({ role: 'viewer' }), false);
|
|
assert.equal(isAdmin({ role: 'admin' }), true);
|
|
assert.equal(isAdmin(null), false);
|
|
});
|
|
|
|
test('projection success with live input but zero projected channels is exposed as stale', () => {
|
|
const state = serializeState({
|
|
status: 'success',
|
|
started_at: 100,
|
|
completed_at: 200,
|
|
input_hash: 'hash',
|
|
projected_count: 0,
|
|
processed_count: 3,
|
|
total_count: 3,
|
|
error: null
|
|
});
|
|
assert.equal(state.stale, true);
|
|
assert.equal(state.projectedCount, 0);
|
|
assert.equal(state.total, 3);
|
|
});
|