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

+57 -7
View File
@@ -9,6 +9,8 @@ import type { RedditPost } from '../src/reddit/api.js';
const ACCOUNT = '@t2_grower:reddit.com';
const OTHER_ACCOUNT = '@t2_other:reddit.com';
/** Migrations that make up account growth, replayed together in the upgrade test. */
const GROWTH_MIGRATION_COUNT = 2;
function thread(id: string, overrides: Partial<RedditPost> = {}): RedditPost {
return {
@@ -76,6 +78,26 @@ describe('AccountGrowthRepository', () => {
expect(saved.trustLevel).toBe(3);
});
it('leaves the daily limit automatic until an operator sets one', () => {
expect(repo.getSettings(ACCOUNT).dailyLimit).toBeNull();
expect(repo.saveSettings(ACCOUNT, { dailyLimit: 6 }).dailyLimit).toBe(6);
// Null is meaningful: it hands the allowance back to the adaptive ladder.
expect(repo.saveSettings(ACCOUNT, { dailyLimit: null }).dailyLimit).toBeNull();
});
it('keeps a stored daily limit when an unrelated setting is saved', () => {
repo.saveSettings(ACCOUNT, { dailyLimit: 8 });
expect(repo.saveSettings(ACCOUNT, { enabled: true }).dailyLimit).toBe(8);
});
it('rejects a daily limit outside the allowed range', () => {
for (const dailyLimit of [0, -1, 51, 2.5]) {
expect(() => repo.saveSettings(ACCOUNT, { dailyLimit })).toThrow(/between 1 and 50/);
}
});
it('rejects invalid quiet hours and negative pacing', () => {
expect(() => repo.saveSettings(ACCOUNT, {
quietHours: { enabled: true, startHour: 25, endHour: 3 },
@@ -456,26 +478,54 @@ describe('AccountGrowthRepository', () => {
});
describe('growth migration', () => {
it('upgrades a database created before growth existed', () => {
const db = new Database(':memory:');
db.pragma('foreign_keys = ON');
// Simulate the pre-growth schema by running migrations, then rewinding the
// version so the growth migration is applied on its own.
runMigrations(db);
/** Rewinds past every growth migration so they replay from a pre-growth state. */
function rewindPastGrowth(db: Database.Database): void {
const version = db.pragma('user_version', { simple: true }) as number;
db.exec('DROP TABLE account_growth_comments');
db.exec('DROP TABLE account_growth_subreddits');
db.exec('DROP TABLE account_growth_settings');
db.pragma(`user_version = ${version - 1}`);
db.pragma(`user_version = ${version - GROWTH_MIGRATION_COUNT}`);
}
it('upgrades a database created before growth existed', () => {
const db = new Database(':memory:');
db.pragma('foreign_keys = ON');
runMigrations(db);
rewindPastGrowth(db);
runMigrations(db);
insertAccount(db, ACCOUNT);
const repo = new AccountGrowthRepository(db);
expect(repo.getSettings(ACCOUNT).enabled).toBe(false);
expect(repo.getSettings(ACCOUNT).dailyLimit).toBeNull();
expect(repo.enqueueDiscovered(ACCOUNT, [thread('a')], 1_000).discovered).toBe(1);
});
it('adds the daily limit to a database that already had the growth tables', () => {
// The real upgrade path for an instance already running account growth.
const db = new Database(':memory:');
db.pragma('foreign_keys = ON');
runMigrations(db);
const version = db.pragma('user_version', { simple: true }) as number;
db.exec('ALTER TABLE account_growth_settings DROP COLUMN daily_limit');
db.pragma(`user_version = ${version - 1}`);
insertAccount(db, ACCOUNT);
// Seed a row with the old shape so the upgrade runs against real data.
db.prepare(`
INSERT INTO account_growth_settings (account_id, enabled, trust_level, updated_at)
VALUES (?, 1, 3, 100)
`).run(ACCOUNT);
runMigrations(db);
const settings = new AccountGrowthRepository(db).getSettings(ACCOUNT);
expect(settings.dailyLimit).toBeNull();
// The upgrade must not disturb what the account already earned.
expect(settings.trustLevel).toBe(3);
expect(settings.enabled).toBe(true);
});
it('is idempotent when run twice', () => {
const db = new Database(':memory:');
runMigrations(db);