diff --git a/backend/src/db/migrations/0045_prescreen_reasons.sql b/backend/src/db/migrations/0045_prescreen_reasons.sql new file mode 100644 index 000000000..3190bf8dd --- /dev/null +++ b/backend/src/db/migrations/0045_prescreen_reasons.sql @@ -0,0 +1,14 @@ +-- Migration 0045: prescreen_reasons for the advisory pre-screen (#756, +-- epic #749 Phase 7). +-- +-- The publication pre-screen (#666) used to flip the request to +-- status='blocked' + block_reason='prescreen_failed' and open a "Block:" issue +-- on the dataset repo -- a hard block admins overrode anyway, which masked REAL +-- blockers (bids_validation_failed also uses status='blocked'). Phase 7 makes it +-- a non-blocking advisory: the result is recorded as prescreen_status='concern' +-- with the reasons here, surfaced in the publish-status views, and the request +-- stays in the normal admin-review queue. Reasons are persisted inline (a JSON +-- array) so the status views don't need the GitHub issue that #756 removes. +-- +-- Additive nullable column; publication_requests is not FTS-backed. +ALTER TABLE publication_requests ADD COLUMN prescreen_reasons TEXT; diff --git a/backend/src/routes/admin.ts b/backend/src/routes/admin.ts index 05824aeab..9b9e223db 100644 --- a/backend/src/routes/admin.ts +++ b/backend/src/routes/admin.ts @@ -3404,6 +3404,9 @@ adminRoutes.get("/publish/requests", async (c) => { steps_completed: string; current_step: string | null; last_error: string | null; + prescreen_status: string | null; + prescreen_reasons: string | null; + prescreen_issue_url: string | null; }>(); return c.json({ diff --git a/backend/src/routes/datasets.ts b/backend/src/routes/datasets.ts index cf4c451a2..3d63b1ea0 100644 --- a/backend/src/routes/datasets.ts +++ b/backend/src/routes/datasets.ts @@ -212,8 +212,11 @@ const BLOCK_MESSAGES: Record = { "BIDS validation has not run yet. Please wait for CI to complete, then re-request publication.", bids_validation_in_progress: "BIDS validation is currently running. Please wait for it to complete, then re-request publication.", + // Legacy only: the pre-screen no longer blocks (#756), so new rows never get + // this block_reason. Kept (without the now-removed repo-issue reference) so a + // pre-deploy 'blocked' row still renders a sensible message until re-request. prescreen_failed: - "The automated pre-screen found missing publication essentials (data, README, or dataset_description). See the issue opened on your dataset repository, address the gaps, then re-request publication.", + "The automated pre-screen flagged missing publication essentials (data, README, or dataset_description). Address the gaps and re-request publication; the pre-screen now runs as a non-blocking advisory.", }; /** @@ -2351,7 +2354,7 @@ datasetRoutes.post("/:id/publish/request", authMiddleware, async (c) => { // re-request doesn't leave a stale 'failed'/nonce on a 'requested' row). await db .prepare( - "UPDATE publication_requests SET status = 'requested', block_reason = NULL, prescreen_status = NULL, prescreen_nonce = NULL, prescreen_issue_url = NULL, updated_at = datetime('now') WHERE id = ?", + "UPDATE publication_requests SET status = 'requested', block_reason = NULL, prescreen_status = NULL, prescreen_nonce = NULL, prescreen_issue_url = NULL, prescreen_reasons = NULL, updated_at = datetime('now') WHERE id = ?", ) .bind(requestId) .run(); @@ -2404,7 +2407,7 @@ datasetRoutes.post("/:id/publish/request", authMiddleware, async (c) => { ); await db .prepare( - "UPDATE publication_requests SET prescreen_status = 'pending', prescreen_nonce = ?, prescreen_issue_url = NULL, prescreen_at = NULL, updated_at = datetime('now') WHERE id = ?", + "UPDATE publication_requests SET prescreen_status = 'pending', prescreen_nonce = ?, prescreen_issue_url = NULL, prescreen_reasons = NULL, prescreen_at = NULL, updated_at = datetime('now') WHERE id = ?", ) .bind(nonce, prId) .run(); @@ -2425,7 +2428,7 @@ datasetRoutes.post("/:id/publish/request", authMiddleware, async (c) => { try { await db .prepare( - "UPDATE publication_requests SET prescreen_status = NULL, prescreen_nonce = NULL WHERE id = ?", + "UPDATE publication_requests SET prescreen_status = NULL, prescreen_nonce = NULL, prescreen_reasons = NULL WHERE id = ?", ) .bind(prId) .run(); @@ -2503,6 +2506,8 @@ datasetRoutes.get("/:id/publish/status", authMiddleware, async (c) => { denied_at: string | null; denied_reason: string | null; block_reason: string | null; + prescreen_status: string | null; + prescreen_reasons: string | null; prescreen_issue_url: string | null; steps_completed: string; current_step: string | null; @@ -2521,6 +2526,26 @@ datasetRoutes.get("/:id/publish/status", authMiddleware, async (c) => { const repoName = request.github_repo?.split("/")[1]; + // Pre-screen is advisory (#756): when it flagged a concern, surface it as a + // non-blocking advisory (the request is NOT blocked by it). Real blockers keep + // status='blocked' with a BLOCK_MESSAGE below. + let prescreenAdvisory: { source: "prescreen"; reasons: string[]; issue_url?: string } | undefined; + if (request.prescreen_status === "concern") { + let reasons: string[] = []; + try { + const parsed = JSON.parse(request.prescreen_reasons || "[]"); + if (Array.isArray(parsed)) reasons = parsed.filter((r) => typeof r === "string"); + } catch (err) { + // malformed reasons JSON -> empty list (the advisory flag still shows) + console.error(`[publish-status] malformed prescreen_reasons for ${datasetId}:`, err); + } + prescreenAdvisory = { + source: "prescreen", + reasons, + ...(request.prescreen_issue_url ? { issue_url: request.prescreen_issue_url } : {}), + }; + } + return c.json({ dataset_id: datasetId, status: request.status, @@ -2536,11 +2561,7 @@ datasetRoutes.get("/:id/publish/status", authMiddleware, async (c) => { ci_url: `https://github.com/nemarDatasets/${repoName}/actions`, } : {}), - // Surface the pre-screen issue so `nemar dataset publish status` shows the - // fix list even if the block email was missed. - ...(request.block_reason === "prescreen_failed" && request.prescreen_issue_url - ? { prescreen_issue_url: request.prescreen_issue_url } - : {}), + ...(prescreenAdvisory ? { advisory: prescreenAdvisory } : {}), steps_completed: JSON.parse(request.steps_completed || "[]"), current_step: request.current_step, last_error: request.last_error, diff --git a/backend/src/routes/webhooks.ts b/backend/src/routes/webhooks.ts index aa2dc8f18..37fc597ec 100644 --- a/backend/src/routes/webhooks.ts +++ b/backend/src/routes/webhooks.ts @@ -13,7 +13,6 @@ import { purgeCacheUrls, zarrPurgeTargets } from "../services/cloudflare.js"; import { runDatasetSync } from "../services/dataset-reindex.js"; import { isValidDatasetId } from "../services/datasetId.js"; import { createEzidVersionDoi, parseDoiProvider } from "../services/doi.js"; -import { resolveEmailConfig, sendPublicationBlockedEmail } from "../services/email.js"; import { enrichDataset } from "../services/enrich-dataset.js"; import { TEST_SHOULDER } from "../services/ezid.js"; import { getDatasetsToken } from "../services/github-auth.js"; @@ -1843,13 +1842,21 @@ export function isDataShortageReason(reason: string): boolean { ); } +/** + * Decide whether the pre-screen result should be surfaced as an advisory + * concern. `flagged` only FLAGS (the screen found a gap) -- it never blocks + * publication (#756); the handler records it as prescreen_status='concern'. The + * S3-authority logic is unchanged: storage with real blobs refutes a + * data-shortage reason (and can clear an all-data-shortage flag), an empty + * prefix adds one. + */ export function decidePrescreenOutcome( verdict: "pass" | "block", reasons: string[], s3: PrescreenS3Presence | null, -): { blocked: boolean; reasons: string[] } { +): { flagged: boolean; reasons: string[] } { let out = [...reasons]; - let blocked = verdict === "block"; + let flagged = verdict === "block"; const s3Missing = !!s3 && s3.totalSize === 0 && s3.objectCount === 0; // objectCount === undefined => first-page cap hit => many objects => present. @@ -1857,20 +1864,20 @@ export function decidePrescreenOutcome( if (s3Present) { // Storage confirms real blobs: any data-shortage reason is a false - // negative. Drop those; keep README/metadata reasons. Downgrade to pass - // only when the block carried data-shortage reason(s) that ALL got - // stripped -- never silently clear a reasonless or non-data block. + // negative. Drop those; keep README/metadata reasons. Clear the flag only + // when it carried data-shortage reason(s) that ALL got stripped -- never + // silently clear a reasonless or non-data flag. const kept = out.filter((r) => !isDataShortageReason(r)); - if (blocked && kept.length === 0 && out.length > 0) blocked = false; + if (flagged && kept.length === 0 && out.length > 0) flagged = false; out = kept; } else if (s3Missing) { - blocked = true; + flagged = true; if (!out.some((r) => /no data|\bs3\b|storage/i.test(r))) { out.push("No data files were found in storage for this dataset."); } } - return { blocked, reasons: out }; + return { flagged, reasons: out }; } /** @@ -1984,58 +1991,37 @@ webhooks.post("/prescreen-result", async (c) => { console.error(`[prescreen-result] S3 stats failed for ${body.dataset_id} (non-fatal):`, err); } - const { blocked, reasons } = decidePrescreenOutcome(body.verdict, body.reasons ?? [], s3); + const { flagged, reasons } = decidePrescreenOutcome(body.verdict, body.reasons ?? [], s3); // Audit the S3 override: if the authoritative S3 check changed the workflow's - // verdict (e.g. cleared an annex-blind false block, #753), record what was - // dropped so a downgrade-to-pass is never silent or untraceable. - const finalVerdict = blocked ? "block" : "pass"; - if (body.verdict !== finalVerdict) { + // raw verdict (e.g. cleared an annex-blind false flag, #753), record what was + // dropped so the change is never silent. + const effectiveVerdict = flagged ? "block" : "pass"; + if (body.verdict !== effectiveVerdict) { const stripped = (body.reasons ?? []).filter((r) => !reasons.includes(r)); console.log( - `[prescreen-result] S3 override for ${body.dataset_id}: ${body.verdict} -> ${finalVerdict}; stripped=${JSON.stringify(stripped)} s3_size=${s3?.totalSize ?? "unknown"}`, + `[prescreen-result] S3 override for ${body.dataset_id}: ${body.verdict} -> ${effectiveVerdict}; stripped=${JSON.stringify(stripped)} s3_size=${s3?.totalSize ?? "unknown"}`, ); } - const issueUrl = body.issue_url ?? null; - - if (blocked) { - const res = await c.env.DB.prepare( + // `|| null` (not `?? null`): the advisory workflow sends issue_url="" now, and + // we want NULL in the column, not an empty string. + const issueUrl = body.issue_url || null; + + let res: D1Result; + if (flagged) { + // Advisory (#756): record the concern but DO NOT block. The request stays in + // the normal admin-review queue; the concern + reasons are surfaced in the + // publish-status views. No status flip, no block email, no repo issue (the + // workflow no longer opens one). Real blockers (BIDS) keep status='blocked'. + res = await c.env.DB.prepare( `UPDATE publication_requests - SET status = 'blocked', block_reason = 'prescreen_failed', - prescreen_status = 'failed', prescreen_issue_url = ?, + SET prescreen_status = 'concern', prescreen_reasons = ?, prescreen_issue_url = ?, prescreen_at = datetime('now'), updated_at = datetime('now') WHERE id = ? AND prescreen_status = 'pending'`, ) - .bind(issueUrl, request.id) + .bind(JSON.stringify(reasons), issueUrl, request.id) .run(); - - // Only email if THIS call did the transition. Guards against a duplicate - // email if two callbacks race past the 'pending' read (the second sees - // changes=0 because the first already flipped the row). - if (res.meta.changes > 0) { - const { fromEmail, replyTo, isDev } = resolveEmailConfig(c.env); - c.executionCtx.waitUntil( - sendPublicationBlockedEmail( - request.requested_by_email, - request.requested_by_username, - body.dataset_id, - reasons, - issueUrl, - c.env.RESEND_API_KEY, - fromEmail, - replyTo, - isDev, - ).catch((emailErr) => { - // waitUntil swallows rejections to the runtime log; catch here so the - // failure is attributable and the dataset id is in the message. - console.error( - `[prescreen-result] block email send failed for ${body.dataset_id}:`, - emailErr, - ); - }), - ); - } } else { - await c.env.DB.prepare( + res = await c.env.DB.prepare( `UPDATE publication_requests SET prescreen_status = 'passed', prescreen_at = datetime('now'), updated_at = datetime('now') @@ -2044,12 +2030,23 @@ webhooks.post("/prescreen-result", async (c) => { .bind(request.id) .run(); } + if (res.meta.changes === 0) { + // One-shot guard: the screen was no longer 'pending' (a duplicate/late + // callback). Harmless, but log so a double-dispatch is explicable. + console.warn( + `[prescreen-result] no-op for ${body.dataset_id} request_id=${request.id}: prescreen_status was not 'pending' (duplicate callback?)`, + ); + } console.log( - `[prescreen-result] dataset=${body.dataset_id} request_id=${request.id} verdict=${body.verdict} blocked=${blocked} s3_objects=${s3 ? (s3.objectCount ?? "capped") : "unknown"}`, + `[prescreen-result] dataset=${body.dataset_id} request_id=${request.id} verdict=${body.verdict} prescreen_status=${flagged ? "concern" : "passed"} s3_objects=${s3 ? (s3.objectCount ?? "capped") : "unknown"}`, ); - return c.json({ ok: true, dataset_id: body.dataset_id, blocked }); + return c.json({ + ok: true, + dataset_id: body.dataset_id, + prescreen_status: flagged ? "concern" : "passed", + }); }); /** diff --git a/backend/test/prescreen-advisory-migration.test.ts b/backend/test/prescreen-advisory-migration.test.ts new file mode 100644 index 000000000..7d5df7ee8 --- /dev/null +++ b/backend/test/prescreen-advisory-migration.test.ts @@ -0,0 +1,152 @@ +/** + * Tests for migration 0045_prescreen_reasons.sql and the exact SQL the + * advisory pre-screen runs (epic #749, Phase 7 / #756): + * - /webhooks/prescreen-result `flagged` branch -> prescreen_status='concern' + * + prescreen_reasons, and crucially status is LEFT UNTOUCHED (no block). + * - the `passed` branch. + * - the re-request reset that clears prescreen_reasons. + * + * Real in-memory SQLite via bun:sqlite (no mocks); applies every migration. + * SQL strings mirror webhooks.ts / datasets.ts. + */ + +import { Database } from "bun:sqlite"; +import { beforeEach, describe, expect, test } from "bun:test"; +import { readFileSync, readdirSync } from "node:fs"; +import { join } from "node:path"; + +const MIGRATIONS_DIR = join(import.meta.dir, "../src/db/migrations"); + +function freshDb(): Database { + const db = new Database(":memory:"); + for (const file of readdirSync(MIGRATIONS_DIR) + .filter((f) => f.endsWith(".sql")) + .sort()) { + db.exec(readFileSync(join(MIGRATIONS_DIR, file), "utf-8")); + } + db.prepare( + `INSERT INTO users (id, username, email, github_username, status) + VALUES (1, 'alice', 'alice@nemar.org', 'alice', 'approved')`, + ).run(); + return db; +} + +// A publication request awaiting its pre-screen callback. +function insertPendingRequest(db: Database, datasetId: string): number { + const r = db + .prepare( + `INSERT INTO publication_requests (dataset_id, status, requested_by, prescreen_status) + VALUES (?, 'requested', 1, 'pending') RETURNING id`, + ) + .get(datasetId) as { id: number }; + return r.id; +} + +// Mirrors the `flagged` branch UPDATE in webhooks.ts /webhooks/prescreen-result. +const ADVISORY_SQL = `UPDATE publication_requests + SET prescreen_status = 'concern', prescreen_reasons = ?, prescreen_issue_url = ?, + prescreen_at = datetime('now'), updated_at = datetime('now') + WHERE id = ? AND prescreen_status = 'pending'`; + +function read(db: Database, id: number) { + return db.prepare("SELECT * FROM publication_requests WHERE id = ?").get(id) as { + status: string; + block_reason: string | null; + prescreen_status: string | null; + prescreen_reasons: string | null; + }; +} + +describe("migration 0045 + advisory pre-screen SQL", () => { + let db: Database; + beforeEach(() => { + db = freshDb(); + }); + + test("prescreen_reasons column present, NULL by default", () => { + const id = insertPendingRequest(db, "nm000001"); + expect(read(db, id).prescreen_reasons).toBeNull(); + }); + + test("advisory `concern` records reasons and LEAVES status='requested' (no block)", () => { + const id = insertPendingRequest(db, "nm000001"); + const reasons = JSON.stringify(["README is thin", "no data paper"]); + const r = db.prepare(ADVISORY_SQL).run(reasons, "https://github.com/x/issues/1", id); + expect(r.changes).toBe(1); + const row = read(db, id); + expect(row.prescreen_status).toBe("concern"); + expect(row.prescreen_reasons).toBe(reasons); + // The whole point of #756: the request is NOT blocked. + expect(row.status).toBe("requested"); + expect(row.block_reason).toBeNull(); + }); + + test("advisory UPDATE only fires on a 'pending' screen (one-shot)", () => { + const id = insertPendingRequest(db, "nm000001"); + db.prepare(ADVISORY_SQL).run("[]", null, id); // first callback -> concern + const r2 = db.prepare(ADVISORY_SQL).run('["late"]', null, id); // replay + expect(r2.changes).toBe(0); // prescreen_status is no longer 'pending' + expect(read(db, id).prescreen_status).toBe("concern"); + }); + + test("re-request reset clears prescreen_reasons", () => { + const id = insertPendingRequest(db, "nm000001"); + db.prepare(ADVISORY_SQL).run('["x"]', null, id); + db.prepare( + "UPDATE publication_requests SET status = 'requested', block_reason = NULL, prescreen_status = NULL, prescreen_nonce = NULL, prescreen_issue_url = NULL, prescreen_reasons = NULL, updated_at = datetime('now') WHERE id = ?", + ).run(id); + const row = read(db, id); + expect(row.prescreen_status).toBeNull(); + expect(row.prescreen_reasons).toBeNull(); + }); + + // The `passed` branch (mirrors webhooks.ts) must also never touch status. + const PASSED_SQL = `UPDATE publication_requests + SET prescreen_status = 'passed', prescreen_at = datetime('now'), updated_at = datetime('now') + WHERE id = ? AND prescreen_status = 'pending'`; + + test("passed branch -> prescreen_status='passed' but status stays 'requested'", () => { + const id = insertPendingRequest(db, "nm000001"); + const r = db.prepare(PASSED_SQL).run(id); + expect(r.changes).toBe(1); + const row = read(db, id); + expect(row.prescreen_status).toBe("passed"); + expect(row.status).toBe("requested"); + expect(row.block_reason).toBeNull(); + }); + + test("passed branch is one-shot too (replay -> changes=0)", () => { + const id = insertPendingRequest(db, "nm000001"); + db.prepare(PASSED_SQL).run(id); + expect(db.prepare(PASSED_SQL).run(id).changes).toBe(0); + }); +}); + +// Mirrors the prescreen_reasons parse in datasets.ts / the CLIs: malformed or +// non-array JSON degrades to [] (the advisory flag still shows), never throws. +function parseReasons(raw: string | null): string[] { + let reasons: string[] = []; + try { + const parsed = JSON.parse(raw || "[]"); + if (Array.isArray(parsed)) reasons = parsed.filter((r) => typeof r === "string"); + } catch { + // degrade to [] + } + return reasons; +} + +describe("prescreen_reasons parse (advisory surfacing)", () => { + test("valid JSON string array round-trips", () => { + expect(parseReasons(JSON.stringify(["a", "b"]))).toEqual(["a", "b"]); + }); + test("non-string array members are filtered", () => { + expect(parseReasons('["a", 7, null, "b"]')).toEqual(["a", "b"]); + }); + test("malformed JSON -> [] (no throw)", () => { + expect(parseReasons("not json")).toEqual([]); + }); + test("null / non-array -> []", () => { + expect(parseReasons(null)).toEqual([]); + expect(parseReasons('{"x":1}')).toEqual([]); + }); +}); diff --git a/backend/test/prescreen-decision.test.ts b/backend/test/prescreen-decision.test.ts index 1d823ff4f..f7da41893 100644 --- a/backend/test/prescreen-decision.test.ts +++ b/backend/test/prescreen-decision.test.ts @@ -2,21 +2,23 @@ * Tests for the pure pre-screen decision function (epic #749, Phase 4 / #753): * - decidePrescreenOutcome: combine the `claude -p` verdict with the Worker's * authoritative S3 presence check, symmetric in BOTH directions. - * - isDataShortageReason: which block reasons the S3 check can refute. + * - isDataShortageReason: which reasons the S3 check can refute. * * The git-annex blind spot (#753): for symlink-stored annex content the * workflow's git-tree heuristic reports "0 annexed files / no binary data" and - * blocks a dataset whose blobs ARE in S3. The Worker, holding the AWS creds, - * must overturn that false data-shortage block. + * flags a dataset whose blobs ARE in S3. The Worker, holding the AWS creds, + * must overturn that false data-shortage flag. * - * Pure functions, no I/O, no mocks. + * Phase 7 (#756): the returned field is `flagged` (the screen found a concern), + * NOT `blocked` -- the result is surfaced as a non-blocking advisory by the + * handler; the S3-authority logic here is unchanged. Pure, no I/O, no mocks. */ import { describe, expect, test } from "bun:test"; import { + type PrescreenS3Presence, decidePrescreenOutcome, isDataShortageReason, - type PrescreenS3Presence, } from "../src/routes/webhooks"; const present: PrescreenS3Presence = { totalSize: 478_659_462_060, objectCount: 642 }; @@ -53,13 +55,13 @@ describe("isDataShortageReason", () => { describe("decidePrescreenOutcome", () => { test("pass + no S3 read -> not blocked, reasons unchanged", () => { const r = decidePrescreenOutcome("pass", [], null); - expect(r.blocked).toBe(false); + expect(r.flagged).toBe(false); expect(r.reasons).toEqual([]); }); test("block + S3 read failed (null) -> trust the workflow, stays blocked", () => { const r = decidePrescreenOutcome("block", ["README.md is missing"], null); - expect(r.blocked).toBe(true); + expect(r.flagged).toBe(true); expect(r.reasons).toEqual(["README.md is missing"]); }); @@ -70,13 +72,13 @@ describe("decidePrescreenOutcome", () => { ["The dataset declares 0.0 MB across 0 annexed files", "Binary data files not found"], present, ); - expect(r.blocked).toBe(false); + expect(r.flagged).toBe(false); expect(r.reasons).toEqual([]); }); test("block for data-shortage + S3 present via page-cap (objectCount undefined) -> pass", () => { const r = decidePrescreenOutcome("block", ["No real data found"], capped); - expect(r.blocked).toBe(false); + expect(r.flagged).toBe(false); expect(r.reasons).toEqual([]); }); @@ -86,19 +88,19 @@ describe("decidePrescreenOutcome", () => { ["0.0 MB across 0 annexed files", "dataset_description.json is missing Authors"], present, ); - expect(r.blocked).toBe(true); + expect(r.flagged).toBe(true); expect(r.reasons).toEqual(["dataset_description.json is missing Authors"]); }); test("block for non-data reason + S3 present -> still blocked, reasons unchanged", () => { const r = decidePrescreenOutcome("block", ["README is empty boilerplate"], present); - expect(r.blocked).toBe(true); + expect(r.flagged).toBe(true); expect(r.reasons).toEqual(["README is empty boilerplate"]); }); test("block with NO reasons + S3 present -> stays blocked (never silently unblock a reasonless block)", () => { const r = decidePrescreenOutcome("block", [], present); - expect(r.blocked).toBe(true); + expect(r.flagged).toBe(true); expect(r.reasons).toEqual([]); }); @@ -108,19 +110,19 @@ describe("decidePrescreenOutcome", () => { ["README documents only the storage layout and download steps"], present, ); - expect(r.blocked).toBe(true); + expect(r.flagged).toBe(true); expect(r.reasons).toEqual(["README documents only the storage layout and download steps"]); }); test("pass + S3 empty -> blocked with a synthetic storage reason (workflow passed, blobs missing)", () => { const r = decidePrescreenOutcome("pass", [], empty); - expect(r.blocked).toBe(true); + expect(r.flagged).toBe(true); expect(r.reasons.some((x) => /storage/i.test(x))).toBe(true); }); test("block + S3 empty -> stays blocked; does not duplicate an existing data reason", () => { const r = decidePrescreenOutcome("block", ["No real data in storage"], empty); - expect(r.blocked).toBe(true); + expect(r.flagged).toBe(true); expect(r.reasons).toEqual(["No real data in storage"]); }); diff --git a/src/commands/admin.ts b/src/commands/admin.ts index 6794130fa..b74dd9ef3 100644 --- a/src/commands/admin.ts +++ b/src/commands/admin.ts @@ -1861,6 +1861,19 @@ Examples: ` ${chalk.yellow(">")} ${req.current_step.replace(/_/g, " ")}${req.last_error ? chalk.red(` (${req.last_error})`) : ""}`, ); } + // Non-blocking pre-screen advisory (#756): a concern for the admin to + // weigh before approving, NOT a block. + if (req.prescreen_status === "concern") { + let reasons: string[] = []; + try { + const parsed = JSON.parse(req.prescreen_reasons || "[]"); + if (Array.isArray(parsed)) reasons = parsed.filter((x) => typeof x === "string"); + } catch { + // malformed -> show the flag without inline reasons + } + const summary = reasons.length ? reasons.join("; ") : "see pre-screen"; + console.log(` ${chalk.yellow("! pre-screen advisory:")} ${chalk.dim(summary)}`); + } } console.log(); } catch (error) { diff --git a/src/commands/dataset.ts b/src/commands/dataset.ts index d3691dd0f..694681686 100644 --- a/src/commands/dataset.ts +++ b/src/commands/dataset.ts @@ -4000,6 +4000,18 @@ Examples: console.log(`\n ${chalk.red("Reason:")} ${result.denied_reason}`); } + // Non-blocking pre-screen advisory (#756): a concern to address, but it + // does NOT block the request (yellow, not red). + if (result.advisory?.source === "prescreen") { + console.log(`\n ${chalk.yellow("Pre-screen advisory")} ${chalk.dim("(non-blocking):")}`); + for (const reason of result.advisory.reasons) { + console.log(` ${chalk.yellow("-")} ${reason}`); + } + if (result.advisory.issue_url) { + console.log(chalk.dim(` ${result.advisory.issue_url}`)); + } + } + if (result.status === "approving") { // Source of truth is `PUBLICATION_STEPS` in src/lib/api.ts, which // mirrors the backend orchestrator. Showing fewer steps here than diff --git a/src/lib/api.ts b/src/lib/api.ts index a4d577276..9460ad719 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1319,6 +1319,10 @@ export interface PublishStatusResponse { last_error?: string | null; updated_at?: string; message?: string; + block_reason?: string | null; + // Non-blocking pre-screen advisory (#756): present when the screen flagged a + // concern. The request is NOT blocked by this. + advisory?: { source: "prescreen"; reasons: string[]; issue_url?: string }; } export interface PublishRequestsResponse { @@ -1332,6 +1336,9 @@ export interface PublishRequestsResponse { steps_completed: string[]; current_step: string | null; last_error: string | null; + prescreen_status?: string | null; + prescreen_reasons?: string | null; + prescreen_issue_url?: string | null; }>; count: number; }