Files
HealthLog/eslint-plugins/healthlog/__tests__/job-handler-outcome.test.mjs
T
Marc-André Bombeck f0a804a812 test(jobs): pin the outcome spine and the binding rule
runJob's claim is behavioural, not typed: an ok:false outcome has to
reach pg-boss as a failed job, reported once, with the handler's own
facts and the thrown error's stack rather than runJob's frame. That is
what the retention cleanups now rely on, so it is pinned.

The rule's tests carry its blind spots in the valid list, where a reader
will trip over them: an aliased receiver is not detected, and neither is
a handler that returns ok:true after swallowing.
2026-07-27 23:11:38 +02:00

68 lines
2.4 KiB
JavaScript

/**
* Unit tests for the `healthlog/job-handler-outcome` rule — the bare
* `boss.work(` ban, the one exempt module that owns `createAndWork`, the
* test-file exemption, and the scope limit to `src/lib/jobs/`.
*
* The `invalid` cases below also stand as the rule's own documented blind
* spots: an aliased or renamed receiver is not detected, and neither is a
* handler that returns `{ ok: true }` after swallowing. Those sit in `valid`
* on purpose, so a future reader can see what this rule does not claim.
*/
import { describe, it } from "vitest";
import { RuleTester } from "eslint";
import rule from "../job-handler-outcome.js";
RuleTester.describe = describe;
RuleTester.it = it;
RuleTester.itOnly = it.only;
const ruleTester = new RuleTester({
languageOptions: { ecmaVersion: 2023, sourceType: "module" },
});
ruleTester.run("job-handler-outcome", rule, {
valid: [
{
code: "await createAndWork(boss, QUEUE, { localConcurrency: 1 }, handleX);",
filename: "/repo/src/lib/jobs/reminder/register-status.ts",
},
{
// The wrapper's own call — this module is the one legal caller.
code: "await boss.work(queue, options, runJob(queue, handler));",
filename: "/repo/src/lib/jobs/reminder/registrar-shared.ts",
},
{
// Tests mock `boss.work` and assert against it directly.
code: 'boss.work("q", {}, async () => {});',
filename: "/repo/src/lib/jobs/__tests__/whoop-queues.test.ts",
},
{
// Out of scope: not the worker tree.
code: 'boss.work("q", {}, async () => {});',
filename: "/repo/src/lib/integrations/status.ts",
},
{
// Documented blind spot: an aliased receiver is not detected.
code: 'const b = boss; b.work("q", {}, async () => {});',
filename: "/repo/src/lib/jobs/reminder/register-rollup.ts",
},
{
// Documented blind spot: this rule cannot see a swallowed failure.
code: "await createAndWork(boss, QUEUE, {}, async () => ({ ok: true, did: {} }));",
filename: "/repo/src/lib/jobs/reminder/register-rollup.ts",
},
],
invalid: [
{
code: 'await boss.work("scratch", async () => {});',
filename: "/repo/src/lib/jobs/reminder/register-maintenance.ts",
errors: [{ messageId: "bareBossWork" }],
},
{
code: "await boss.work(QUEUE, { localConcurrency: 1 }, handleX);",
filename: "/repo/src/lib/jobs/worker-status.ts",
errors: [{ messageId: "bareBossWork" }],
},
],
});