diff --git a/pm-stack/dispatch/src/validate.ts b/pm-stack/dispatch/src/validate.ts index 9167caa1d..289bd4a89 100644 --- a/pm-stack/dispatch/src/validate.ts +++ b/pm-stack/dispatch/src/validate.ts @@ -144,10 +144,17 @@ export interface SessionRequest { wait: boolean; } +/** Minimum spec floor for a session prompt with no explicit title (#4925): + * a prompt shorter than this cannot name any work, so accepting it would mint + * a spec-less repo issue that costs a triage lane. 40 chars is the value the + * stalled #4948 carried; an explicit title exempts the request (the caller + * named the work). */ +export const MIN_PROMPT_SPEC_CHARS = 40; + export function parseSessionRequest(body: unknown): SessionRequest { if (typeof body !== "object" || body === null) throw new ValidationError("body: must be a JSON object"); const b = body as Record; - return { + const req: SessionRequest = { repo: reqString(b, "repo"), prompt: reqString(b, "prompt"), title: optNonBlankString(b, "title"), @@ -157,6 +164,15 @@ export function parseSessionRequest(body: unknown): SessionRequest { issue: optBool(b, "issue", true), wait: optBool(b, "wait", true), }; + // Minimum-spec gate (#4925). It runs after every field validation above so + // existing per-field errors keep precedence; an explicit title is the + // caller naming the work, so it exempts the request. + if (req.title === undefined && req.prompt.length < MIN_PROMPT_SPEC_CHARS) { + throw new ValidationError( + `prompt: too short to name any work (${req.prompt.length} < ${MIN_PROMPT_SPEC_CHARS} chars) and no title given — describe the work in the prompt or pass an explicit title`, + ); + } + return req; } /** Session-directory scoping for POST /v1/sessions (issues #2903, #2664). diff --git a/pm-stack/dispatch/test/server.test.ts b/pm-stack/dispatch/test/server.test.ts index 74ff3971b..748810707 100644 --- a/pm-stack/dispatch/test/server.test.ts +++ b/pm-stack/dispatch/test/server.test.ts @@ -69,7 +69,7 @@ function sessionsRequest(token: string, body: Record): Request // (the exact orphan class #4917 tracks; baseline runs of this file // filed #4937/#4938). Issue-creation and failure-compensation behaviour // is covered hermetically by launch_failure.test.ts stubs. -const base = { repo: "developing-today/code", prompt: "do the thing", issue: false }; +const base = { repo: "developing-today/code", prompt: "fix the pm-dispatch session request minimum spec gate", issue: false }; describe("POST /v1/sessions directory scoping (issue #2903)", () => { test("OIDC + foreign directory is rejected with 400 before any side effect", async () => { diff --git a/pm-stack/dispatch/test/validate.test.ts b/pm-stack/dispatch/test/validate.test.ts index 40625cff0..c0bef1575 100644 --- a/pm-stack/dispatch/test/validate.test.ts +++ b/pm-stack/dispatch/test/validate.test.ts @@ -3,6 +3,7 @@ import { mkdtempSync, mkdirSync, realpathSync, rmSync, symlinkSync } from "node: import { tmpdir } from "node:os"; import { join } from "node:path"; import { + MIN_PROMPT_SPEC_CHARS, ValidationError, parseModel, parseSessionRequest, @@ -149,7 +150,10 @@ describe("request validation", () => { } }); test("sessions require repo and prompt; defaults issue+wait on", () => { - const r = parseSessionRequest({ repo: "developing-today/code", prompt: "do the thing" }); + const r = parseSessionRequest({ + repo: "developing-today/code", + prompt: "Fix the parser so trailing whitespace in a mark is rejected", + }); expect(r.issue).toBe(true); expect(r.wait).toBe(true); expect(r.priority).toBe(40); @@ -158,6 +162,21 @@ describe("request validation", () => { expect(() => parseSessionRequest("nope")).toThrow(ValidationError); }); + test("minimum spec gate rejects a titleless prompt that names no work (#4925)", () => { + const repo = "developing-today/code"; + // Too short and no title: refused, and the error names the missing spec. + expect(() => parseSessionRequest({ repo, prompt: "do the thing" })).toThrow(/too short to name any work/); + expect(() => parseSessionRequest({ repo, prompt: "x".repeat(MIN_PROMPT_SPEC_CHARS - 1) })).toThrow(ValidationError); + // An explicit title exempts the request (the caller named the work). + const titled = parseSessionRequest({ repo, prompt: "do the thing", title: "Fix pm-dispatch spec gate" }); + expect(titled.title).toBe("Fix pm-dispatch spec gate"); + // A prompt at the floor with no title passes. + const compliant = parseSessionRequest({ repo, prompt: "x".repeat(MIN_PROMPT_SPEC_CHARS) }); + expect(compliant.title).toBeUndefined(); + // The gate runs after field validation: an invalid priority still errors as priority. + expect(() => parseSessionRequest({ repo, prompt: "x", priority: "constructor" })).toThrow(/priority/); + }); + test("a prototype-spelling priority 400s at parse time, so no non-number reaches the packet (#2757)", () => { expect(() => parseSessionRequest({ repo: "developing-today/code", prompt: "x", priority: "constructor" })).toThrow( ValidationError, @@ -172,7 +191,9 @@ describe("request validation", () => { parseTaskRequest({ repo: "developing-today/code", title: "t", prompt: "p", priority: "__proto__" }), ).toThrow(ValidationError); // A valid named priority still parses to a number. - expect(parseSessionRequest({ repo: "developing-today/code", prompt: "x", priority: "high" }).priority).toBe(20); + expect( + parseSessionRequest({ repo: "developing-today/code", prompt: "x", title: "t", priority: "high" }).priority, + ).toBe(20); }); test("tasks accept prompt or body, default kind triage and issue off", () => { @@ -301,7 +322,7 @@ describe("session blank title/directory parsing (issue #2664)", () => { test("empty and whitespace-only title/directory parse as omitted", () => { const r = parseSessionRequest({ repo: "developing-today/code", - prompt: "do the thing", + prompt: "make the mark parser reject trailing whitespace", title: " ", directory: "", }); @@ -309,7 +330,7 @@ describe("session blank title/directory parsing (issue #2664)", () => { expect(r.directory).toBeUndefined(); const r2 = parseSessionRequest({ repo: "developing-today/code", - prompt: "do the thing", + prompt: "make the mark parser reject trailing whitespace", title: "", directory: " \t ", });