feat: let the operator set the daily comment limit per account

The allowance was derived from the adaptive trust level with no way to
change it, which made the dashboard's "1 / 2 today" unexplainable and
left no way to slow an account down or push one along.

`dailyLimit` is null by default, keeping today's adaptive behaviour. A
whole number between 1 and 50 overrides it and is enforced verbatim in
either direction — it can raise an account above what it has earned or
hold it below. The trust level keeps being tracked underneath and is
reported as `adaptiveAllowance`, so the earned figure stays visible next
to the override, and clearing the field hands pacing back to the ladder.

Raising the limit above the earned allowance does remove the adaptive
backoff after a bad comment, so the dashboard says exactly that where the
limit is set. It does not touch the pause on two consecutive removals, a
comment the public cannot see, or a captcha challenge: those are safety
stops rather than rate controls and no limit setting can disable them.

Also correct two things the page was saying badly. The allowance is now
labelled "used in last 24h" with the trust level shown as what it earns,
because it is a rolling window and not a midnight reset. And a
per-community cap above the account allowance now states how much of it
is actually reachable — "1 of 10 today" beside an account limit of 2 read
as far more headroom than existed, since caps distribute the allowance
rather than adding to it.

Verified against a local instance: override above and below the earned
allowance, unrelated saves preserving it, clearing it through the UI,
rejection of 0/51/2.5/non-numeric, and a limit failing to clear a pause.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jamie BruntonandClaude Opus 5 committed 2026-08-11 21:07:25 +01:00
1 parent f88db1ae7d
commit 5deac87cf1
15 files changed
+351 -26

No files matched your search

+71 -1
View File
@@ -16,6 +16,8 @@ function settings(overrides: Record<string, unknown> = {}) {
enabled: true,
trustLevel: 1,
dailyAllowance: 3,
adaptiveAllowance: 3,
dailyLimit: null,
minDelayMs: 3_600_000,
jitterMs: 900_000,
quietHours: { enabled: true, startHour: 23, endHour: 7 },
@@ -197,7 +199,7 @@ describe('GrowthPage', () => {
expect(await screen.findByText('1 / 3')).toBeVisible();
expect(screen.getByText('Used in last 24h')).toBeVisible();
expect(screen.getByText('1 of 4 → 3/day')).toBeVisible();
expect(screen.getByText('1 of 4 → 3/day earned')).toBeVisible();
// 6 posted less 1 removed.
expect(screen.getByText('5')).toBeVisible();
expect(screen.getByText('4')).toBeVisible();
@@ -213,6 +215,74 @@ describe('GrowthPage', () => {
expect(screen.getByText(/Two removals in a row/i)).toBeVisible();
});
describe('daily limit', () => {
it('shows the allowance as automatic until an operator overrides it', async () => {
renderGrowth();
expect(await screen.findByText('Automatic — 3/day')).toBeVisible();
expect(screen.getByText('1 of 4 → 3/day earned')).toBeVisible();
});
it('sets a limit through the API', async () => {
renderGrowth();
const user = userEvent.setup();
const field = await screen.findByLabelText('Daily limit');
await user.clear(field);
await user.type(field, '9');
await user.click(screen.getByRole('button', { name: 'Save limit' }));
await waitFor(() => expect(requests).toHaveLength(1));
expect(requests[0]).toMatchObject({ method: 'PATCH', body: { dailyLimit: 9 } });
});
it('clearing the field hands the allowance back to the ladder', async () => {
detailPayload = detail({ settings: settings({ dailyLimit: 9, dailyAllowance: 9 }) });
renderGrowth();
const user = userEvent.setup();
await user.clear(await screen.findByLabelText('Daily limit'));
await user.click(screen.getByRole('button', { name: 'Save limit' }));
await waitFor(() => expect(requests).toHaveLength(1));
expect(requests[0]).toMatchObject({ body: { dailyLimit: null } });
});
it('does not submit an out-of-range limit', async () => {
renderGrowth();
const user = userEvent.setup();
const field = await screen.findByLabelText('Daily limit');
await user.clear(field);
await user.type(field, '99');
await user.click(screen.getByRole('button', { name: 'Save limit' }));
expect(requests).toHaveLength(0);
});
it('shows an override and warns when it exceeds what was earned', async () => {
detailPayload = detail({
settings: settings({ trustLevel: 0, dailyLimit: 12, dailyAllowance: 12, adaptiveAllowance: 2 }),
});
renderGrowth();
expect(await screen.findByText('Set to 12/day')).toBeVisible();
expect(screen.getByText(/above the 2\/day this account has earned/i)).toBeVisible();
// The safety stop is not something a limit can switch off.
expect(screen.getByText(/pause on two removals in a row.*still applies/i)).toBeVisible();
});
it('does not warn when the override sits within what was earned', async () => {
detailPayload = detail({
settings: settings({ trustLevel: 4, dailyLimit: 3, dailyAllowance: 3, adaptiveAllowance: 12 }),
});
renderGrowth();
expect(await screen.findByText('Set to 3/day')).toBeVisible();
expect(screen.queryByText(/this account has earned/i)).not.toBeInTheDocument();
});
});
it('warns when a community cap exceeds what the account allowance permits', async () => {
detailPayload = detail({
settings: settings({ trustLevel: 0, dailyAllowance: 2 }),