gruh i hate fun!!

This commit is contained in:
legop3
2026-08-07 15:54:28 -04:00
parent a55257dd51
commit 9702cf0f82
27 changed files with 67 additions and 2628 deletions
@@ -1,5 +1,5 @@
// Operator Command Dispatcher Tests
// Purpose: Pins the permission, mode, and prefix policy that the registry-driven gate replaced a hardcoded action list with.
// Purpose: Pins shared command permissions, access modes, and prefix parsing.
// Scope: Exercises the router with doubles; individual command behavior is covered by each command's own tests.
const test = require('node:test');
const assert = require('node:assert/strict');
@@ -10,8 +10,6 @@ const ADMIN_DENIAL = /Only admins can run that command/;
const LOCKDOWN_DENIAL = /Lockdown mode: only lockdown admins/;
const FEATURE_DENIAL = /Admin mode: only admins can run feature commands/;
const ALICE = { id: 's1', data: { userId: 'u-alice', nickname: 'alice' } };
function createRouter({ mode = MODES.OPEN, featureEnabled = true } = {}) {
const rovers = new Map([['rover-1', {
id: 'rover-1',
@@ -22,28 +20,15 @@ function createRouter({ mode = MODES.OPEN, featureEnabled = true } = {}) {
const { handleCommand } = createCommandHandlers({
logger: { warn: () => {}, info: () => {} },
io: { sockets: { sockets: new Map([[ALICE.id, ALICE]]) } },
io: { sockets: { sockets: new Map() } },
rovers,
roverManager: {
canDrive: () => true,
getPrimaryRoverForSocket: () => 'rover-1',
applyPrivateDriveSafety: () => null,
},
roverManager: {},
getMode: () => mode,
MODES,
getNickname: (entry) => entry?.data?.nickname || '',
getActiveDrivers: () => ({}),
getActorSocket: () => ALICE,
issueCommand: () => 'cmd-1',
isFeatureEnabled: () => featureEnabled,
sanitizeMentions: (text) => String(text || ''),
funStatsService: {
bumpActorStats: () => ({}),
getActorStats: () => ({}),
listActorStats: () => [],
bumpRoverPets: () => 1,
getRoverPets: () => 0,
},
homeAssistantService: { getLightPolicyState: () => ({}), setAllControllableEntitiesState: () => Promise.resolve() },
liftService: null,
neatoService: null,
@@ -75,16 +60,6 @@ function createRouter({ mode = MODES.OPEN, featureEnabled = true } = {}) {
const nonAdmin = { id: 's1', userId: 'u-alice', label: 'alice', isAdmin: false, isLockdownAdmin: false };
const admin = { id: 's1', userId: 'u-alice', label: 'alice', isAdmin: true, isLockdownAdmin: false };
const lockdownAdmin = { id: 's1', userId: 'u-alice', label: 'alice', isAdmin: true, isLockdownAdmin: true };
test('a non-admin can run fun commands', async () => {
const run = createRouter();
for (const command of ['rs coin', 'rs rate carpet', 'rs uwu hi', 'rs bonkboard', 'rs vibecheck', 'rs snitch']) {
const reply = await run(command, nonAdmin);
assert.doesNotMatch(reply, ADMIN_DENIAL, `${command} should be public`);
assert.ok(reply.length > 0, `${command} should reply`);
}
});
test('admin-only commands stay admin-only for a non-admin', async () => {
const run = createRouter();
@@ -109,30 +84,9 @@ test('system commands remain reachable by anyone', async () => {
assert.match(await run('rs help', nonAdmin), /Rover Bot Commands/);
});
test('the fun category appears in help', async () => {
const run = createRouter();
const help = await run('rs help fun', nonAdmin);
assert.match(help, /\*\*Fun\*\*/);
for (const command of ['bonk', 'honk', 'disco', 'vibecheck', 'bonkboard']) {
assert.match(help, new RegExp(`rs ${command}`), `help should list ${command}`);
}
});
test('admin mode restricts access-mode feature commands but not the public fun ones', async () => {
test('admin mode restricts access-mode feature commands', async () => {
const run = createRouter({ mode: MODES.ADMIN });
assert.match(await run('rs lights on', nonAdmin), FEATURE_DENIAL);
assert.match(await run('rs disco', nonAdmin), FEATURE_DENIAL);
assert.doesNotMatch(await run('rs coin', nonAdmin), FEATURE_DENIAL);
});
test('lockdown suspends the whole fun category for anyone but a lockdown admin', async () => {
const run = createRouter({ mode: MODES.LOCKDOWN });
for (const command of ['rs coin', 'rs bonk bob', 'rs honk', 'rs disco', 'rs vibecheck']) {
assert.match(await run(command, nonAdmin), LOCKDOWN_DENIAL, `${command} should be suspended in lockdown`);
}
// A plain admin is not enough during lockdown.
assert.match(await run('rs coin', admin), LOCKDOWN_DENIAL);
assert.doesNotMatch(await run('rs coin', lockdownAdmin), LOCKDOWN_DENIAL);
});
test('lockdown still suspends the pre-existing moderation-sensitive commands', async () => {
@@ -150,7 +104,6 @@ test('status and help survive lockdown', async () => {
test('a disabled required feature is reported before any permission check', async () => {
const run = createRouter({ featureEnabled: false });
assert.match(await run('rs disco', nonAdmin), /Home Assistant feature is not configured/);
assert.match(await run('rs lights on', nonAdmin), /Home Assistant feature is not configured/);
});
@@ -171,11 +124,10 @@ test('an unknown command is not treated as public', async () => {
test('bot actors are ignored entirely', async () => {
const run = createRouter();
assert.equal(await run('rs coin', { ...nonAdmin, bot: true }), '');
assert.equal(await run('rs status', { ...nonAdmin, bot: true }), '');
});
test('command matching is case insensitive', async () => {
const run = createRouter();
assert.doesNotMatch(await run('RS COIN', nonAdmin), ADMIN_DENIAL);
assert.match(await run('Rs Status', nonAdmin), /\[status handler\]/);
});