controller: group services into Core vs Optional & Maintenance

The Controller listed every wrolpi-* service in one flat table, which was
confusing for new users who couldn't tell always-on infrastructure from
one-off/dev/maintenance units.

Services are now split into two groups computed once in the backend and
exposed as `service.group`:

* Core Services      - persistent services enabled at boot (api, app, caddy,
                       kiwix, ...), the normal running system.
* Optional & Maintenance - one-off/dev/maintenance tasks (bootstrap, repair,
                       upgrade, *-dev, discovered wrolpi-*), plus persistent
                       services the user has disabled at boot (e.g. Samba with
                       no shares configured).

Rule: core iff kind == "persistent" and enabled; otherwise optional. Group
membership only changes when the user toggles Boot, never on start/stop or
polling, so rows stay put. Within each group, failed/stopped services sort
first so problems stay visible.

Feature parity across all three render paths: the React ControllerPage, the
server-side Jinja template, and the client-side poll refresh. Docker
containers have no group field and fall back to a single ungrouped list.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roland 2026-07-22 19:41:17 -06:00 • committed by lrnselfreliance
parent 331e1eceda
commit e51e5fb2fb
7 changed files with 353 additions and 73 deletions

View file

@ -14,6 +14,8 @@ jest.mock('../../api/controller', () => ({
viewable: true,
view_path: '/docs',
enabled: true,
kind: 'persistent',
group: 'core',
},
{
name: 'wrolpi-app',
@ -22,6 +24,28 @@ jest.mock('../../api/controller', () => ({
viewable: true,
view_path: '',
enabled: true,
kind: 'persistent',
group: 'core',
},
{
name: 'smbd',
port: 445,
status: 'stopped',
viewable: false,
view_path: '',
enabled: false,
kind: 'persistent',
group: 'optional',
},
{
name: 'wrolpi-repair',
port: null,
status: 'stopped',
viewable: false,
view_path: '',
enabled: false,
kind: 'task',
group: 'optional',
},
]),
startService: jest.fn().mockResolvedValue({success: true}),
@ -150,6 +174,39 @@ describe('ControllerPage', () => {
expect(screen.getByTestId('shutdown-button')).toBeInTheDocument();
});
});
});
describe('groupServices', () => {
const {groupServices} = require('./ControllerPage');
test('splits core from optional by group field', () => {
const {core, optional} = groupServices([
{name: 'wrolpi-api', status: 'running', group: 'core'},
{name: 'smbd', status: 'stopped', group: 'optional'},
{name: 'wrolpi-repair', status: 'stopped', group: 'optional'},
]);
expect(core.map(s => s.name)).toEqual(['wrolpi-api']);
expect(optional.map(s => s.name)).toEqual(['smbd', 'wrolpi-repair']);
});
test('treats a missing group (Docker containers) as core', () => {
const {core, optional} = groupServices([
{name: 'api', status: 'running'},
{name: 'db', status: 'running'},
]);
expect(core).toHaveLength(2);
expect(optional).toHaveLength(0);
});
test('sorts problems first, then alphabetically, within a group', () => {
const {core} = groupServices([
{name: 'caddy', status: 'running', group: 'core'},
{name: 'wrolpi-api', status: 'failed', group: 'core'},
{name: 'wrolpi-app', status: 'running', group: 'core'},
]);
expect(core.map(s => s.name)).toEqual(['wrolpi-api', 'caddy', 'wrolpi-app']);
});
});
describe('ControllerPage in Docker mode', () => {