fix: reconcile physique targeting for queued posts

This commit is contained in:
jjbrunton committed 2026-08-10 18:23:23 +01:00
1 parent d0a8bd0e2f
commit d8d635e1ee
10 files changed
+250 -12

No files matched your search

+11 -3
View File
@@ -25,10 +25,11 @@ function harness() {
// harnesses would otherwise share the same `conversations` instance.
const config = structuredClone(ConfigSchema.parse(getTestConfig())) as Config;
const saved: Config[] = [];
const candidateQueue = { reconcilePhysiqueTargeting: vi.fn(() => ({ retained: 2, rejected: 1 })) };
const ctx = {
config,
runtimeConfig: config,
services: { configStore: { save: (next: Config) => saved.push(next) } },
services: { configStore: { save: (next: Config) => saved.push(next) }, candidateQueue },
getOnConfigChange: () => undefined,
activity: { push: vi.fn() },
broadcaster: { push: vi.fn() },
@@ -37,7 +38,7 @@ function harness() {
const app = express();
app.use(express.json());
app.use('/api', createConfigRouter(ctx));
return { app, config, saved };
return { app, config, saved, candidateQueue, ctx };
}
describe('config route conversation kill controls', () => {
@@ -112,7 +113,7 @@ describe('config route conversation kill controls', () => {
describe('config route physique targeting', () => {
it('hot-updates and persists the image-candidate score range', async () => {
const { app, config, saved } = harness();
const { app, config, saved, candidateQueue, ctx } = harness();
const targetingRef = config.reddit.physiqueTargeting;
const response = await request(app, '/api/config', {
@@ -129,6 +130,13 @@ describe('config route physique targeting', () => {
expect(config.reddit.physiqueTargeting).toBe(targetingRef);
expect(config.reddit.physiqueTargeting).toEqual({ enabled: true, minScore: 3, maxScore: 7 });
expect(saved.at(-1)?.reddit.physiqueTargeting).toEqual({ enabled: true, minScore: 3, maxScore: 7 });
expect(candidateQueue.reconcilePhysiqueTargeting).toHaveBeenCalledWith({
enabled: true, minScore: 3, maxScore: 7,
});
expect(ctx.activity.push).toHaveBeenCalledWith(
'info',
'Physique targeting reconciled 2 prepared image candidate(s) and rejected 1',
);
});
it('rejects an inverted physique range without mutating configuration', async () => {