diff --git a/changelog.d/803-discovery-promotion.added.md b/changelog.d/803-discovery-promotion.added.md new file mode 100644 index 00000000..eedb54a5 --- /dev/null +++ b/changelog.d/803-discovery-promotion.added.md @@ -0,0 +1 @@ +Discovery can now promote a successful discovered issue into one proposed work item when AUTO_PROMOTE_DISCOVERY is enabled; a failed run or a backlog-report result is never promoted, promotions are deduplicated by issue URL, capped per repository per UTC day and never create a branch or pull request. The default remains off. diff --git a/docs/architecture.md b/docs/architecture.md index ad24b6a7..03a9ba06 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -1316,7 +1316,15 @@ open work it returns `none` with reason `idle`: the scheduler writes discovery interval is due, it may instead run one `discover` job; that job may create at most one concrete issue (never a PR/branch), and if it finds nothing concrete it creates nothing. The callback refuses a discovery result that carries -a branch or pull request (`DISCOVERY_PR_FORBIDDEN`). The job goal gets a bounded +a branch or pull request (`DISCOVERY_PR_FORBIDDEN`). A discovered issue does not +create a work item by default; with `AUTO_PROMOTE_DISCOVERY` enabled, a +`succeeded` discovery whose result is a concrete issue creates one `proposed` +work item through `promoteDiscoveredIssue`, deduped by issue URL and capped per +repository per UTC day: the counter is keyed `discover-promote::`, +while the cap's value comes from the deployment-wide +`AUTO_PROMOTE_DISCOVERY_DAILY_CAP`. A result the run digest classifies as a backlog report +is not promoted, and a failed run never promotes. It never creates a branch or a +pull request. The job goal gets a bounded `Carry-over` block with the last three run digests and up to four open items; the block is data, not an instruction, and is capped well below the 4000-character goal limit. Every line that names an issue or a pull request is checked once diff --git a/src/config.ts b/src/config.ts index 41210c5c..12200ce2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -34,6 +34,10 @@ export interface Config { // erased. The sweep's purge phase reads this; 72 hours is the host-side cron it // replaces. trialPurgeGraceHours: number + /** #803: promote a discovered issue into one proposed work item. Off by default. */ + autoPromoteDiscovery: boolean + /** #803: maximum automatic discovery promotions per UTC day; 0 disables them. */ + autoPromoteDiscoveryDailyCap: number // #708: the per-class windows mutating routes take. A route names its class; // the numbers live here so a deployment tightens a limit without a rebuild. rateLimit: RateLimitBudgets @@ -298,6 +302,8 @@ export function loadConfig(overrides: Partial = {}): Config { }, recentAuthMinutes: Math.max(1, number('RECENT_AUTH_MINUTES', 15)), trialPurgeGraceHours: Math.max(1, number('TRIAL_PURGE_GRACE_HOURS', 72)), + autoPromoteDiscovery: bool('AUTO_PROMOTE_DISCOVERY', false), + autoPromoteDiscoveryDailyCap: Math.max(0, number('AUTO_PROMOTE_DISCOVERY_DAILY_CAP', 3)), rateLimit: { login: { max: Math.max(1, number('RATE_LIMIT_LOGIN_MAX', DEFAULT_RATE_LIMIT_BUDGETS.login.max)), diff --git a/src/jobs/discoveryPromotion.ts b/src/jobs/discoveryPromotion.ts new file mode 100644 index 00000000..9243e222 --- /dev/null +++ b/src/jobs/discoveryPromotion.ts @@ -0,0 +1,41 @@ +import type { Config } from '../config.js' +import type { Store } from '../db.js' +import { randomId } from '../lib/secrets.js' + +// #803: discovery stays issue-only. This is the explicit, opt-in bridge from a +// discovered issue to the normal work-item queue. It never creates a branch or +// a pull request and it never changes the issue itself. +export type DiscoveryPromotionStatus = 'promoted' | 'disabled' | 'duplicate' | 'cap' | 'no-issue' + +export interface DiscoveryPromotionResult { + status: DiscoveryPromotionStatus + workItemId?: string +} + +export function promoteDiscoveredIssue( + store: Store, + config: Config, + input: { repoId: string; userId: string; issueUrl: string | null; title?: string; priority?: number; now?: Date }, +): DiscoveryPromotionResult { + const issueUrl = input.issueUrl ?? '' + if (issueUrl === '') return { status: 'no-issue' } + if (!config.autoPromoteDiscovery || config.autoPromoteDiscoveryDailyCap <= 0) return { status: 'disabled' } + + const existing = store.findWorkItemByIssueUrl(input.repoId, issueUrl) + if (existing !== undefined) return { status: 'duplicate', workItemId: existing.id } + + // The cap is per repository: a deployment-wide counter let one busy + // repository spend every other repository's day. A corrupt value counts as + // zero — `NaN >= cap` is false forever, which would switch the cap off. + const day = (input.now ?? new Date()).toISOString().slice(0, 10) + const key = `discover-promote:${input.repoId}:${day}` + const stored = Number(store.getSetting(key) ?? 0) + const used = Number.isFinite(stored) ? stored : 0 + if (used >= config.autoPromoteDiscoveryDailyCap) return { status: 'cap' } + + const id = randomId('work') + const title = (input.title ?? '').trim().slice(0, 160) || issueUrl + store.createWorkItem({ id, repoId: input.repoId, userId: input.userId, title, issueUrl, state: 'proposed', priority: input.priority }) + store.setSetting(key, String(used + 1)) + return { status: 'promoted', workItemId: id } +} diff --git a/src/jobs/service.ts b/src/jobs/service.ts index 8a7eaebe..09aa20e8 100644 --- a/src/jobs/service.ts +++ b/src/jobs/service.ts @@ -49,7 +49,8 @@ import { addMinutes, nowIso } from '../lib/time.js' import { GithubClient, GithubError, prepareRepo, prepareRepoWithInstallation, repoPermissionWithToken } from '../repos/github.js' import { GithubApp } from '../repos/app.js' import { parseIssueUrl, parsePrUrl } from './prUrl.js' -import { buildCarryOver, buildRunDigest, decideNextJob, failureStreak, lastDurationMs, MIN_DISCOVERY_INTERVAL_MINUTES, parseCarryOverLink, type CarryOverReader } from './continuity.js' +import { promoteDiscoveredIssue } from './discoveryPromotion.js' +import { buildCarryOver, buildRunDigest, decideNextJob, failureStreak, lastDurationMs, MIN_DISCOVERY_INTERVAL_MINUTES, parseCarryOverLink, type CarryOverReader, type OutputKind } from './continuity.js' import { planTick, scheduleFromRow, type TickPlan } from '../schedules/tick.js' import { utcDayEnd, utcDayStart } from '../schedules/budget.js' import type { ScheduleRow } from '../db.js' @@ -1348,6 +1349,7 @@ export class Jobs { }) return } + if (job.kind === 'discover') return if (result.status !== 'succeeded' || (result.prUrl === null && result.issueUrl === null)) return const title = (result.prUrl ?? result.issueUrl ?? job.goal).slice(0, 160) this.store.createWorkItem({ @@ -1365,6 +1367,32 @@ export class Jobs { }) } + // #803: one work item for a successful discovery whose result is a concrete + // issue. `DISCOVERY_PR_FORBIDDEN` finishes the run `failed`, so the status + // guard also covers the run that broke discovery's issue-only contract. + private settleDiscoveryPromotion(job: JobRow, result: { status: 'succeeded' | 'failed' | 'quota_exhausted'; issueUrl: string | null; summary: string }, outputKind: OutputKind): void { + if (result.status !== 'succeeded') { + this.store.audit(job.user_id, 'job.discovery_promotion_skipped', `${job.id}: not-succeeded:${result.status}`) + return + } + if (outputKind === 'meta') { + this.store.audit(job.user_id, 'job.discovery_promotion_skipped', `${job.id}: meta-issue`) + return + } + const promotion = promoteDiscoveredIssue(this.store, this.config, { + repoId: job.repo_id, + userId: job.user_id, + issueUrl: result.issueUrl, + title: result.summary, + priority: job.priority, + }) + this.store.audit( + job.user_id, + promotion.status === 'promoted' ? 'job.discovery_promoted' : 'job.discovery_promotion_skipped', + `${job.id}: ${promotion.status}${promotion.workItemId === undefined ? '' : ` ${promotion.workItemId}`}`, + ) + } + // Returns whether this call moved the row to a terminal state. Callers that // perform side effects must only do so when it returns true. private finish(jobId: string, result: { status: 'succeeded' | 'failed' | 'quota_exhausted'; branch?: string; prUrl?: string | null; issueUrl?: string | null; reviewScore?: number; summary?: string; error?: string; errorCode?: FailureCode }, revoke: () => void, attribution: Attribution | null = null, evidence: Evidence | null = null, fingerprint: string | null = null): boolean { @@ -1427,6 +1455,10 @@ export class Jobs { const digest = buildRunDigest(finalJob, { status: result.status, summary, issueUrl, prUrl }) this.store.updateJob(jobId, { continuity_json: JSON.stringify(digest), output_kind: digest.output_kind }) incCounter('fledge_job_output_total', { kind: job.kind, output: digest.output_kind }, 1, 'Scheduled output classification') + // #803: promotion runs on the classification, not before it. A result the + // digest calls a backlog report must not spend a cap slot or audit a + // promotion, and a run that did not succeed must not promote at all. + if (job.kind === 'discover') this.settleDiscoveryPromotion(finalJob, { status: result.status, issueUrl, summary }, digest.output_kind) if (digest.output_kind === 'meta') { incCounter('fledge_meta_issue_total', { kind: job.kind }, 1, 'Inventory/meta issues rejected by classification') // Close the tracking row so the next scheduled run does not follow up a diff --git a/test/discoveryPromotion.test.ts b/test/discoveryPromotion.test.ts new file mode 100644 index 00000000..c624e8c4 --- /dev/null +++ b/test/discoveryPromotion.test.ts @@ -0,0 +1,110 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import { Store } from '../src/db.js' +import { promoteDiscoveredIssue } from '../src/jobs/discoveryPromotion.js' +import { makeUser, testConfig } from './helpers.js' + +function fixture() { + const store = new Store(':memory:') + const user = makeUser(store, { login: 'discovery-promote', status: 'approved' }) + const repo = store.createRepo({ id: 'repo_discovery_promote', userId: user.id, owner: 'o', name: 'r', defaultBranch: 'main', tokenEnc: 'x', permission: 'admin', repoRole: 'maintainer', goal: '', autoIterate: false, intervalMinutes: 1440 }) + return { store, user, repo } +} + +const now = new Date('2026-11-15T00:00:00.000Z') +const issue = (n: number) => `https://github.com/o/r/issues/${String(n)}` + +test('discovery promotion is off by default and never creates a work item', () => { + const { store, user, repo } = fixture() + try { + const result = promoteDiscoveredIssue(store, testConfig(), { repoId: repo.id, userId: user.id, issueUrl: issue(1), now }) + assert.equal(result.status, 'disabled') + assert.equal(store.findWorkItemByIssueUrl(repo.id, issue(1)), undefined) + } finally { + store.close() + } +}) + +test('an enabled promotion creates one proposed work item, dedupes the issue and caps the day', () => { + const { store, user, repo } = fixture() + try { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 2 }) + const first = promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(1), title: 'First discovered issue', now }) + assert.equal(first.status, 'promoted') + const item = store.getWorkItem(first.workItemId ?? '') + assert.ok(item !== undefined) + assert.equal(item.state, 'proposed') + assert.equal(item.issue_url, issue(1)) + assert.equal(item.pr_url, null) + + const duplicate = promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(1), now }) + assert.equal(duplicate.status, 'duplicate') + assert.equal(duplicate.workItemId, first.workItemId) + + const second = promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(2), now }) + assert.equal(second.status, 'promoted') + + const capped = promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(3), now }) + assert.equal(capped.status, 'cap') + assert.equal(store.findWorkItemByIssueUrl(repo.id, issue(3)), undefined) + assert.equal(store.getSetting(`discover-promote:${repo.id}:2026-11-15`), '2') + } finally { + store.close() + } +}) + +// #803 says only "The setting has a daily cap". A deployment-wide counter let +// one repository spend every other repository's day, so the cap is per +// repository: a busy repository cannot starve a quiet one. +test('the daily cap is per repository', () => { + const { store, user, repo } = fixture() + const other = store.createRepo({ id: 'repo_discovery_promote_b', userId: user.id, owner: 'o', name: 'r2', defaultBranch: 'main', tokenEnc: 'x', permission: 'admin', repoRole: 'maintainer', goal: '', autoIterate: false, intervalMinutes: 1440 }) + try { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 1 }) + assert.equal(promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(1), now }).status, 'promoted') + assert.equal(promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(2), now }).status, 'cap') + assert.equal(promoteDiscoveredIssue(store, config, { repoId: other.id, userId: user.id, issueUrl: issue(3), now }).status, 'promoted') + } finally { + store.close() + } +}) + +// A non-numeric setting reads as NaN, and `NaN >= cap` is false forever, so one +// bad write used to switch the cap off for good. A corrupt value counts as 0 and +// the next promotion rewrites a finite number. +test('a corrupt counter value cannot switch the cap off', () => { + const { store, user, repo } = fixture() + try { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 1 }) + assert.equal(promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(1), now }).status, 'promoted') + const counter = store.listSettings('discover-promote')[0] + assert.ok(counter !== undefined) + store.setSetting(counter.key, 'not-a-number') + assert.equal(promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(2), now }).status, 'promoted') + assert.equal(promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(3), now }).status, 'cap') + } finally { + store.close() + } +}) + +test('a promoted work item keeps the priority it was given', () => { + const { store, user, repo } = fixture() + try { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 3 }) + const result = promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: issue(1), priority: 2, now }) + assert.equal(result.status, 'promoted') + assert.equal(store.getWorkItem(result.workItemId ?? '')?.priority, 2) + } finally { + store.close() + } +}) + +test('a discovery result without an issue URL is not promoted', () => { + const { store, user, repo } = fixture() + try { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 3 }) + assert.equal(promoteDiscoveredIssue(store, config, { repoId: repo.id, userId: user.id, issueUrl: null, now }).status, 'no-issue') + } finally { + store.close() + } +}) diff --git a/test/jobs.test.ts b/test/jobs.test.ts index af334b7a..0f30f4f7 100644 --- a/test/jobs.test.ts +++ b/test/jobs.test.ts @@ -2503,8 +2503,11 @@ test('a discover callback cannot open a branch or pull request', async () => { } }) -test('a discover callback with an issue creates exactly one work item', async () => { - const config = testConfig() +// #803: discover no longer promotes unconditionally. With the switch off the +// callback leaves the backlog alone; with it on, exactly one `proposed` item is +// the bridge into the normal work-item queue (never a branch or PR). +test('a discover callback with an issue creates exactly one proposed work item when promotion is on', async () => { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 3 }) const store = new Store(':memory:') const jobs = new Jobs(store, config, { name: 'noop', async run() { return { status: 'running' } } }, new MemoryMailer()) try { @@ -2517,12 +2520,15 @@ test('a discover callback with an issue creates exactly one work item', async () const result = await jobs.handleCallback('job_discover_issue', secret, { status: 'succeeded', issueUrl, summary: 'found a concrete bug' }) assert.equal(result.ok, true) const item = store.findWorkItemByIssueUrl(repo.id, issueUrl) - assert.equal(item?.state, 'in_progress') + assert.equal(item?.state, 'proposed') + assert.equal(item?.pr_url, null) + assert.equal(store.listWorkItems(repo.id).length, 1) assert.equal(store.getJob('job_discover_issue')?.output_kind, 'issue') + assert.ok(store.listAudit().some((entry) => entry.action === 'job.discovery_promoted')) await jobs.tick() const after = store.listJobsForRepo(repo.id) - assert.equal(after.length, 2, 'the discovered issue feeds the next work session') + assert.equal(after.length, 2, 'the proposed issue feeds the next work session') assert.equal(after[0]?.kind, 'iterate') assert.equal(after[0]?.work_item_id, item?.id) } finally { @@ -2530,6 +2536,111 @@ test('a discover callback with an issue creates exactly one work item', async () } }) +test('a discover callback leaves the backlog unchanged when promotion is off', async () => { + const config = testConfig() + const store = new Store(':memory:') + const jobs = new Jobs(store, config, { name: 'noop', async run() { return { status: 'running' } } }, new MemoryMailer()) + try { + const user = makeUser(store, { login: 'discover-no-promote-user', status: 'approved' }) + const repo = store.createRepo({ id: 'repo_discover_no_promote', userId: user.id, owner: 'o', name: 'r', defaultBranch: 'main', tokenEnc: 'x', permission: 'admin', repoRole: 'developer', upstreamHtmlUrl: 'https://github.com/o/r', goal: '', autoIterate: true, intervalMinutes: 60 }) + const secret = 'discover-no-promote-secret' + store.createJob({ id: 'job_discover_no_promote', repoId: repo.id, userId: user.id, trigger: 'schedule', goal: 'discover', callbackHash: sha256Hex(secret), platformTokenHash: '', kind: 'discover' }) + store.updateJob('job_discover_no_promote', { status: 'running', started_at: new Date().toISOString() }) + const issueUrl = 'https://github.com/o/r/issues/8' + const result = await jobs.handleCallback('job_discover_no_promote', secret, { status: 'succeeded', issueUrl, summary: 'found a concrete bug' }) + assert.equal(result.ok, true) + assert.equal(store.findWorkItemByIssueUrl(repo.id, issueUrl), undefined) + assert.equal(store.listWorkItems(repo.id).length, 0) + assert.equal(store.getJob('job_discover_no_promote')?.output_kind, 'issue') + const skipped = store.listAudit().find((entry) => entry.action === 'job.discovery_promotion_skipped') + assert.ok(skipped !== undefined) + assert.ok(String(skipped.detail).includes('disabled')) + + await jobs.tick() + assert.equal(store.listWorkItems(repo.id).length, 0) + assert.equal(store.listJobsForRepo(repo.id).filter((job) => job.kind === 'iterate').length, 0) + } finally { + store.close() + } +}) + +// #803 asks for a work item only after a *successful* discovery, and #513 makes +// a branch or pull request a failure of discovery's issue-only contract. So a +// failed run must not promote its issue, whatever issue URL it carries. +test('a failed discover callback carrying an issue URL creates no work item', async () => { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 3 }) + const store = new Store(':memory:') + const jobs = new Jobs(store, config, { name: 'noop', async run() { return { status: 'running' } } }, new MemoryMailer()) + try { + const user = makeUser(store, { login: 'discover-failed-user', status: 'approved' }) + const repo = store.createRepo({ id: 'repo_discover_failed', userId: user.id, owner: 'o', name: 'failed', defaultBranch: 'main', tokenEnc: 'x', permission: 'admin', repoRole: 'developer', upstreamHtmlUrl: 'https://github.com/o/failed', goal: '', autoIterate: true, intervalMinutes: 60 }) + const secret = 'discover-failed-secret' + store.createJob({ id: 'job_discover_failed', repoId: repo.id, userId: user.id, trigger: 'schedule', goal: 'discover', callbackHash: sha256Hex(secret), platformTokenHash: '', kind: 'discover' }) + store.updateJob('job_discover_failed', { status: 'running', started_at: new Date().toISOString() }) + const issueUrl = 'https://github.com/o/failed/issues/11' + const result = await jobs.handleCallback('job_discover_failed', secret, { status: 'failed', issueUrl, summary: 'gave up without a concrete issue' }) + assert.equal(result.ok, true) + assert.equal(store.getJob('job_discover_failed')?.status, 'failed') + assert.equal(store.findWorkItemByIssueUrl(repo.id, issueUrl), undefined) + assert.equal(store.listWorkItems(repo.id).length, 0) + assert.ok(!store.listAudit().some((entry) => entry.action === 'job.discovery_promoted')) + const skipped = store.listAudit().find((entry) => entry.action === 'job.discovery_promotion_skipped') + assert.ok(skipped !== undefined) + assert.ok(String(skipped.detail).includes('not-succeeded')) + } finally { + store.close() + } +}) + +test('the forbidden-PR discovery failure does not promote its issue', async () => { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 3 }) + const store = new Store(':memory:') + const jobs = new Jobs(store, config, { name: 'noop', async run() { return { status: 'running' } } }, new MemoryMailer()) + try { + const user = makeUser(store, { login: 'discover-forbidden-user', status: 'approved' }) + const repo = store.createRepo({ id: 'repo_discover_forbidden', userId: user.id, owner: 'o', name: 'forbidden', defaultBranch: 'main', tokenEnc: 'x', permission: 'admin', repoRole: 'developer', upstreamHtmlUrl: 'https://github.com/o/forbidden', goal: '', autoIterate: true, intervalMinutes: 60 }) + const secret = 'discover-forbidden-secret' + store.createJob({ id: 'job_discover_forbidden', repoId: repo.id, userId: user.id, trigger: 'schedule', goal: 'discover', callbackHash: sha256Hex(secret), platformTokenHash: '', kind: 'discover' }) + store.updateJob('job_discover_forbidden', { status: 'running', started_at: new Date().toISOString() }) + const issueUrl = 'https://github.com/o/forbidden/issues/12' + const result = await jobs.handleCallback('job_discover_forbidden', secret, { status: 'succeeded', branch: 'flybot/x', prUrl: 'https://github.com/o/forbidden/pull/1', issueUrl, summary: 'opened a PR by mistake' }) + assert.equal(result.status, 422) + assert.equal(store.getJob('job_discover_forbidden')?.status, 'failed') + assert.equal(store.findWorkItemByIssueUrl(repo.id, issueUrl), undefined) + assert.equal(store.listWorkItems(repo.id).length, 0) + assert.ok(!store.listAudit().some((entry) => entry.action === 'job.discovery_promoted')) + } finally { + store.close() + } +}) + +// The digest classification closes a backlog-report result one block later, so +// promoting it first spent a cap slot and audited a promotion that was undone. +test('a discovery result classified as a backlog report does not promote', async () => { + const config = testConfig({ autoPromoteDiscovery: true, autoPromoteDiscoveryDailyCap: 3 }) + const store = new Store(':memory:') + const jobs = new Jobs(store, config, { name: 'noop', async run() { return { status: 'running' } } }, new MemoryMailer()) + try { + const user = makeUser(store, { login: 'discover-meta-user', status: 'approved' }) + const repo = store.createRepo({ id: 'repo_discover_meta', userId: user.id, owner: 'o', name: 'meta', defaultBranch: 'main', tokenEnc: 'x', permission: 'admin', repoRole: 'developer', upstreamHtmlUrl: 'https://github.com/o/meta', goal: '', autoIterate: true, intervalMinutes: 60 }) + const secret = 'discover-meta-secret' + store.createJob({ id: 'job_discover_meta', repoId: repo.id, userId: user.id, trigger: 'schedule', goal: 'discover', callbackHash: sha256Hex(secret), platformTokenHash: '', kind: 'discover' }) + store.updateJob('job_discover_meta', { status: 'running', started_at: new Date().toISOString() }) + const issueUrl = 'https://github.com/o/meta/issues/13' + const result = await jobs.handleCallback('job_discover_meta', secret, { status: 'succeeded', issueUrl, summary: 'inventory of the backlog' }) + assert.equal(result.ok, true) + assert.equal(store.getJob('job_discover_meta')?.output_kind, 'meta') + assert.equal(store.findWorkItemByIssueUrl(repo.id, issueUrl), undefined) + assert.equal(store.listWorkItems(repo.id).length, 0) + assert.ok(!store.listAudit().some((entry) => entry.action === 'job.discovery_promoted')) + const skipped = store.listAudit().find((entry) => entry.action === 'job.discovery_promotion_skipped') + assert.ok(skipped !== undefined) + assert.ok(String(skipped.detail).includes('meta-issue')) + } finally { + store.close() + } +}) + test('the scheduler idles with no work and starts once a work item appears', async () => { const config = testConfig() const store = new Store(':memory:')