// A CALL MADE AS THE EDITOR'S JOB, for tests of code that runs only inside // one: an X posts fetch (controller/fetchPosts.ts X_ONLY_AS_A_JOB) asks // `currentJobContext()` and refuses a caller that is no job. The real funnel // (jobs/streamCommand.ts runManagedFunction) gives every job this context; a // test that calls the controller directly, to look at what it does with a // fake gallery-dl, has to say it stands where a job does. // // X's queue by default (`platform:twitter`). Nothing of the funnel's guards // runs here: no queue, no gap, no jar rule — a test of THOSE goes through // runManagedFunction (jobs/pacingGuard.test.ts). import { runInJobContext, type JobContext } from "../../lib/jobContext"; export const X_QUEUE_KEY = "platform:twitter"; export function editorJobContext(over: Partial = {}): JobContext { return { jobId: "test-job", kind: "fetch-posts", queueKey: X_QUEUE_KEY, onLog: () => {}, staleServices: new Set(), ...over }; } // Run `fn` as a job's body. export function asEditorJob(fn: () => T, over: Partial = {}): T { return runInJobContext(editorJobContext(over), fn); } // The same function, every call of it made as a job's body. export function insideEditorJob(fn: (...args: A) => R, over: Partial = {}): (...args: A) => R { return (...args: A) => asEditorJob(() => fn(...args), over); }