From dbab526d0da05e37a96b22f0a8a126d20bbf117c Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Fri, 30 Oct 2026 04:56:29 -0500 Subject: [PATCH] feat(pm-dispatch): cross-repo grants, issue_number attach, reusable Actions Part of #2672 --- .github/actions/pm-dispatch-queue/action.yml | 116 ++++++++++++++++++ .github/actions/pm-dispatch-start/action.yml | 112 +++++++++++++++++ pm-stack/dispatch/README.md | 65 +++++++++- .../dispatch/examples/dispatch-workflow.yml | 90 ++++++++------ pm-stack/dispatch/src/auth.ts | 22 ++-- pm-stack/dispatch/src/server.ts | 47 +++++-- pm-stack/dispatch/src/validate.ts | 13 ++ pm-stack/dispatch/test/auth.test.ts | 41 +++++-- pm-stack/dispatch/test/validate.test.ts | 22 ++++ 9 files changed, 458 insertions(+), 70 deletions(-) create mode 100644 .github/actions/pm-dispatch-queue/action.yml create mode 100644 .github/actions/pm-dispatch-start/action.yml diff --git a/.github/actions/pm-dispatch-queue/action.yml b/.github/actions/pm-dispatch-queue/action.yml new file mode 100644 index 0000000000..bdff4e66b6 --- /dev/null +++ b/.github/actions/pm-dispatch-queue/action.yml @@ -0,0 +1,116 @@ +name: pm-dispatch-queue +description: >- + Enqueue work via pm-dispatch (POST /v1/tasks), optionally tracked by a + GitHub issue. The calling job MUST grant `permissions: id-token: write` — + this action mints a GitHub Actions OIDC token (audience pm-dispatch) to + authenticate. +inputs: + repo: + description: "Target repo (owner/name). Any allowlisted repo may target any allowlisted repo." + required: false + default: ${{ github.repository }} + title: + description: "Queue task title." + required: true + prompt: + description: "The work text (sent as the task prompt/body)." + required: true + model: + description: 'Optional model hint, "provider/model" (stored as the payload model hint only).' + required: false + default: "" + priority: + description: "Optional priority: 10-90 or critical|high|normal|low." + required: false + default: "" + kind: + description: "Optional task kind: triage|small_fix|pr_shepherd|ci_investigation." + required: false + default: "" + issue: + description: '"true" to create a tracking issue in the target repo (ignored when issue_number is set).' + required: false + default: "true" + issue_number: + description: "Optional existing issue number in the target repo to attach to instead of creating an issue. Takes precedence over issue." + required: false + default: "" +outputs: + task_id: + description: "pm-dispatch queue task id." + value: ${{ steps.dispatch.outputs.task_id }} + issue_number: + description: "Tracking/attached issue number (empty when no issue is involved)." + value: ${{ steps.dispatch.outputs.issue_number }} + issue_url: + description: "Issue URL (empty when no issue is involved)." + value: ${{ steps.dispatch.outputs.issue_url }} +runs: + using: composite + steps: + - name: Enqueue work via pm-dispatch + id: dispatch + shell: bash + env: + INPUT_REPO: ${{ inputs.repo }} + INPUT_TITLE: ${{ inputs.title }} + INPUT_PROMPT: ${{ inputs.prompt }} + INPUT_MODEL: ${{ inputs.model }} + INPUT_PRIORITY: ${{ inputs.priority }} + INPUT_KIND: ${{ inputs.kind }} + INPUT_ISSUE: ${{ inputs.issue }} + INPUT_ISSUE_NUMBER: ${{ inputs.issue_number }} + run: | + set -euo pipefail + if [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] || [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]; then + echo "::error::pm-dispatch-queue: ACTIONS_ID_TOKEN_REQUEST_URL / ACTIONS_ID_TOKEN_REQUEST_TOKEN are not set. The calling job must grant 'permissions: id-token: write' so this action can mint an OIDC token." >&2 + exit 1 + fi + case "$INPUT_ISSUE" in + true|false) ;; + *) echo "::error::pm-dispatch-queue: issue must be \"true\" or \"false\", got: $INPUT_ISSUE" >&2; exit 1 ;; + esac + oidc_token="$(curl -sS -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ + "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=pm-dispatch" | jq -r '.value // empty')" + if [ -z "$oidc_token" ]; then + echo "::error::pm-dispatch-queue: failed to mint a GitHub Actions OIDC token (audience pm-dispatch)." >&2 + exit 1 + fi + payload="$(jq -n \ + --arg repo "$INPUT_REPO" \ + --arg title "$INPUT_TITLE" \ + --arg prompt "$INPUT_PROMPT" \ + --arg model "$INPUT_MODEL" \ + --arg priority "$INPUT_PRIORITY" \ + --arg kind "$INPUT_KIND" \ + --argjson issue "$INPUT_ISSUE" \ + '{repo: $repo, title: $title, prompt: $prompt, issue: $issue} + + (if $model != "" then {model: $model} else {} end) + + (if $priority != "" then {priority: $priority} else {} end) + + (if $kind != "" then {kind: $kind} else {} end)')" + if [ -n "$INPUT_ISSUE_NUMBER" ]; then + payload="$(printf '%s' "$payload" | jq --argjson issue_number "$INPUT_ISSUE_NUMBER" '. + {issue_number: $issue_number}')" + fi + response="$(curl -sS -w $'\n%{http_code}' -X POST "https://dispatch.security.cab/v1/tasks" \ + -H "Authorization: Bearer $oidc_token" \ + -H "Content-Type: application/json" \ + -d "$payload")" + http_code="${response##*$'\n'}" + body="${response%$'\n'*}" + if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then + echo "::error::pm-dispatch-queue: pm-dispatch POST /v1/tasks failed (HTTP $http_code):" >&2 + echo "$body" >&2 + exit 1 + fi + echo "$body" + task_id="$(printf '%s' "$body" | jq -r '.task_id // empty')" + issue_number="$(printf '%s' "$body" | jq -r '.issue_number // empty')" + issue_url="$(printf '%s' "$body" | jq -r '.issue_url // empty')" + if [ -z "$issue_url" ] && [ -n "$issue_number" ]; then + issue_url="https://github.com/${INPUT_REPO}/issues/${issue_number}" + fi + { + echo "task_id=$task_id" + echo "issue_number=$issue_number" + echo "issue_url=$issue_url" + } >> "$GITHUB_OUTPUT" diff --git a/.github/actions/pm-dispatch-start/action.yml b/.github/actions/pm-dispatch-start/action.yml new file mode 100644 index 0000000000..ca21894098 --- /dev/null +++ b/.github/actions/pm-dispatch-start/action.yml @@ -0,0 +1,112 @@ +name: pm-dispatch-start +description: >- + Launch a tracked OpenCode session via pm-dispatch (POST /v1/sessions). + The calling job MUST grant `permissions: id-token: write` — this action + mints a GitHub Actions OIDC token (audience pm-dispatch) to authenticate. +inputs: + repo: + description: "Target repo (owner/name). Any allowlisted repo may target any allowlisted repo." + required: false + default: ${{ github.repository }} + title: + description: "Session / tracking-issue title." + required: true + prompt: + description: "Work for the OpenCode session." + required: true + model: + description: 'Optional model hint, "provider/model".' + required: false + default: "" + priority: + description: "Optional priority: 10-90 or critical|high|normal|low." + required: false + default: "" + kind: + description: "Optional task kind hint (passed through to pm-dispatch)." + required: false + default: "" + wait: + description: '"true" to wait for the launch, "false" to return after the enqueue.' + required: false + default: "true" +outputs: + task_id: + description: "pm-dispatch queue task id." + value: ${{ steps.dispatch.outputs.task_id }} + session_id: + description: "OpenCode session id (empty when wait is false)." + value: ${{ steps.dispatch.outputs.session_id }} + issue_number: + description: "Tracking issue number (empty when no issue was created)." + value: ${{ steps.dispatch.outputs.issue_number }} + issue_url: + description: "Tracking issue URL (empty when no issue was created)." + value: ${{ steps.dispatch.outputs.issue_url }} +runs: + using: composite + steps: + - name: Launch a tracked OpenCode session via pm-dispatch + id: dispatch + shell: bash + env: + INPUT_REPO: ${{ inputs.repo }} + INPUT_TITLE: ${{ inputs.title }} + INPUT_PROMPT: ${{ inputs.prompt }} + INPUT_MODEL: ${{ inputs.model }} + INPUT_PRIORITY: ${{ inputs.priority }} + INPUT_KIND: ${{ inputs.kind }} + INPUT_WAIT: ${{ inputs.wait }} + run: | + set -euo pipefail + if [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] || [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]; then + echo "::error::pm-dispatch-start: ACTIONS_ID_TOKEN_REQUEST_URL / ACTIONS_ID_TOKEN_REQUEST_TOKEN are not set. The calling job must grant 'permissions: id-token: write' so this action can mint an OIDC token." >&2 + exit 1 + fi + case "$INPUT_WAIT" in + true|false) ;; + *) echo "::error::pm-dispatch-start: wait must be \"true\" or \"false\", got: $INPUT_WAIT" >&2; exit 1 ;; + esac + oidc_token="$(curl -sS -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ + "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=pm-dispatch" | jq -r '.value // empty')" + if [ -z "$oidc_token" ]; then + echo "::error::pm-dispatch-start: failed to mint a GitHub Actions OIDC token (audience pm-dispatch)." >&2 + exit 1 + fi + payload="$(jq -n \ + --arg repo "$INPUT_REPO" \ + --arg title "$INPUT_TITLE" \ + --arg prompt "$INPUT_PROMPT" \ + --arg model "$INPUT_MODEL" \ + --arg priority "$INPUT_PRIORITY" \ + --arg kind "$INPUT_KIND" \ + --argjson wait "$INPUT_WAIT" \ + '{repo: $repo, title: $title, prompt: $prompt, wait: $wait} + + (if $model != "" then {model: $model} else {} end) + + (if $priority != "" then {priority: $priority} else {} end) + + (if $kind != "" then {kind: $kind} else {} end)')" + response="$(curl -sS -w $'\n%{http_code}' -X POST "https://dispatch.security.cab/v1/sessions" \ + -H "Authorization: Bearer $oidc_token" \ + -H "Content-Type: application/json" \ + -d "$payload")" + http_code="${response##*$'\n'}" + body="${response%$'\n'*}" + if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then + echo "::error::pm-dispatch-start: pm-dispatch POST /v1/sessions failed (HTTP $http_code):" >&2 + echo "$body" >&2 + exit 1 + fi + echo "$body" + task_id="$(printf '%s' "$body" | jq -r '.task_id // empty')" + session_id="$(printf '%s' "$body" | jq -r '.session_id // empty')" + issue_number="$(printf '%s' "$body" | jq -r '.issue_number // empty')" + issue_url="" + if [ -n "$issue_number" ]; then + issue_url="https://github.com/${INPUT_REPO}/issues/${issue_number}" + fi + { + echo "task_id=$task_id" + echo "session_id=$session_id" + echo "issue_number=$issue_number" + echo "issue_url=$issue_url" + } >> "$GITHUB_OUTPUT" diff --git a/pm-stack/dispatch/README.md b/pm-stack/dispatch/README.md index 368d5adcb9..ab6e86bae2 100644 --- a/pm-stack/dispatch/README.md +++ b/pm-stack/dispatch/README.md @@ -72,14 +72,28 @@ for a session that launched, nor `claimed` without a session id. "priority": 40, // optional, same mapping as above "model": "deepseek/deepseek-chat", // optional; stored as payload.model_hint only "issue": false, // optional; default false - "dedupe_key": "…" // optional; default: canonical key from the + "dedupe_key": "…", // optional; default: canonical key from the // created issue, else a unique dispatch key + "issue_number": 123 // optional; attach to this existing issue + // in repo instead of creating one (see below) } ``` Returns `201 {task_id, issue_number|null, queue}`. With `issue: true` the issue is created first (labels `queue/queued` + `source/dispatch`) and gets an agent-note comment naming the task id. +With `issue_number` set, no issue is created: the task attaches to +that existing issue in `repo` — the canonical dedupe key is derived +from it, and after the enqueue the issue gets the same agent-note +comment naming the task id plus the `queue/queued` and +`source/dispatch` labels. The response is `201 {task_id, +issue_number, issue_url, queue}`, where `issue_url` is +`https://github.com//issues/`. `issue_number` +takes precedence over `issue` when both are sent. For dezren39/nix, +where the GitHub App is not installed, the attach is skipped with a +`warnings` entry; the task is still enqueued and `issue_number` is +still returned. + ### Why assignment is a direct PATCH The queue's `claim_repo_task` RPC claims the *next* task in a queue — it cannot claim a specific row. A dispatch launch knows exactly which @@ -101,9 +115,12 @@ Every endpoint except `GET /health` requires `Authorization: Bearer …`: - **GitHub Actions OIDC** (preferred): a JWT from `token.actions.githubusercontent.com`, RS256-verified against GitHub's JWKS (cached), `aud` = `pm-dispatch` (env `DISPATCH_OIDC_AUDIENCE`). - The token's `repository` claim must be in the allowlist **and equal - the request body's `repo`** — a workflow can only dispatch for its own - repo. See `examples/dispatch-workflow.yml`. + The token's `repository` claim must be in the allowlist. **Grants + mesh:** every allowlisted repo may target every allowlisted repo — + the claim need not equal the request body's `repo`. Repos outside + the allowlist can neither call nor be targeted. Bearer callers are + bound only by the allowlist on the target. + See `examples/dispatch-workflow.yml`. - **Static bearer secret**: `DISPATCH_API_TOKEN` (in the laptop's `~/secrets/dispatch.env`), compared in constant time — the shape a repo stores as a GitHub Actions secret. @@ -111,6 +128,46 @@ Every endpoint except `GET /health` requires `Authorization: Bearer …`: The caller identity (`{type:"bearer"}` or `{type:"oidc", repository, actor, workflow_ref}`) is recorded in the task payload. +## GitHub Actions (reusable) + +Two composite actions in this repo wrap the dispatch endpoints so +call sites do not hand-roll the OIDC + curl plumbing: + +- `.github/actions/pm-dispatch-start` ("the starter") — POSTs to + `/v1/sessions`; outputs `task_id`, `session_id`, `issue_number` + and `issue_url`. +- `.github/actions/pm-dispatch-queue` ("the queuer") — POSTs to + `/v1/tasks`, including the `issue` / `issue_number` inputs; + outputs `task_id`, `issue_number` and `issue_url`. + +Usage, pinned to `@main` so fleet call sites pick up central updates: + +```yaml +jobs: + dispatch: + runs-on: ubuntu-latest + permissions: + id-token: write # required — the actions mint an OIDC token (aud pm-dispatch) + contents: read + steps: + - uses: developing-today/code/.github/actions/pm-dispatch-start@main + with: + title: "fix(widget): flaky test" + prompt: "Fix the flaky widget test" + - uses: developing-today/code/.github/actions/pm-dispatch-queue@main + with: + title: "investigate the red build" + prompt: "…" + issue_number: "123" # optional: attach instead of creating +``` + +The calling job MUST grant `permissions: id-token: write`; without +it the OIDC token-request environment is absent and the actions fail +with a clear error. `repo` defaults to the caller's repository, and +under the grants mesh any allowlisted repo may target any +allowlisted repo. See `examples/dispatch-workflow.yml` for a +complete workflow. + ## Configuration (env) | Name | Default | Notes | | --- | --- | --- | diff --git a/pm-stack/dispatch/examples/dispatch-workflow.yml b/pm-stack/dispatch/examples/dispatch-workflow.yml index 04d4c5feeb..22e377c5fd 100644 --- a/pm-stack/dispatch/examples/dispatch-workflow.yml +++ b/pm-stack/dispatch/examples/dispatch-workflow.yml @@ -1,16 +1,25 @@ # EXAMPLE — not installed in any live repo. Copy into a fleet repo's -# .github/workflows/ and adjust the dispatch URL to the laptop's tailnet -# address (or the dispatch.security.cab hostname once the pm-stack -# Cloudflare tunnel carries it). +# .github/workflows/ and adjust as needed. # -# Two auth styles are shown: -# A) GitHub Actions OIDC (preferred): the workflow mints a short-lived -# token with audience "pm-dispatch"; pm-dispatch verifies it against -# GitHub's JWKS and requires the token's repository claim to equal -# the repo in the request body — a workflow can only dispatch for -# its own repo. -# B) Static bearer secret: the DISPATCH_TOKEN repo secret holds the -# DISPATCH_API_TOKEN from the laptop's ~/secrets/dispatch.env. +# Canonical form: the reusable composite actions in developing-today/code +# wrap the pm-dispatch plumbing (OIDC fetch with audience "pm-dispatch", +# POST, outputs). Pin them @main so call sites pick up central updates: +# +# - pm-dispatch-start ("the starter"): POST /v1/sessions — launch a +# tracked OpenCode session now. +# - pm-dispatch-queue ("the queuer"): POST /v1/tasks — enqueue only, +# optionally creating a tracking issue or attaching to an existing +# one via issue_number. +# +# OIDC requires the calling job to grant `permissions: id-token: write`. +# Under the grants mesh, any allowlisted repo may target any allowlisted +# repo (the actions' `repo` input defaults to the caller's repo). +# +# Note: the raw-curl form still works — mint a token from +# $ACTIONS_ID_TOKEN_REQUEST_URL with `&audience=pm-dispatch` and POST to +# https://dispatch.security.cab/v1/sessions or /v1/tasks with it as the +# bearer token; a static DISPATCH_TOKEN secret also still works for the +# raw form. name: dispatch-example @@ -18,43 +27,48 @@ on: workflow_dispatch: inputs: prompt: - description: "Work for the OpenCode session" + description: "Work for the dispatch" required: true type: string jobs: - dispatch-oidc: + dispatch-session: runs-on: ubuntu-latest permissions: - id-token: write # required to mint the OIDC token + id-token: write contents: read steps: - - name: Launch a tracked OpenCode session (OIDC) - env: - DISPATCH_URL: http://100.99.113.103:4879 - PROMPT: ${{ inputs.prompt }} + - name: Launch a tracked OpenCode session + id: start + uses: developing-today/code/.github/actions/pm-dispatch-start@main + with: + title: "dispatch example session" + prompt: ${{ inputs.prompt }} + priority: "high" + wait: "true" + - name: Show the dispatch result run: | - set -euo pipefail - TOKEN=$(curl -s -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ - "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pm-dispatch" | jq -r .value) - curl -s -X POST "$DISPATCH_URL/v1/sessions" \ - -H "Authorization: Bearer $TOKEN" \ - -H "Content-Type: application/json" \ - -d "$(jq -n --arg repo "$GITHUB_REPOSITORY" --arg prompt "$PROMPT" \ - '{repo: $repo, prompt: $prompt, priority: "high"}')" + echo "task: ${{ steps.start.outputs.task_id }}" + echo "session: ${{ steps.start.outputs.session_id }}" + echo "issue: ${{ steps.start.outputs.issue_url }}" - dispatch-secret: + dispatch-queue: runs-on: ubuntu-latest + permissions: + id-token: write + contents: read steps: - - name: Enqueue work only (bearer secret) - env: - DISPATCH_URL: http://100.99.113.103:4879 - DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }} - PROMPT: ${{ inputs.prompt }} + - name: Enqueue work only + id: queue + uses: developing-today/code/.github/actions/pm-dispatch-queue@main + with: + title: "queued from Actions" + prompt: ${{ inputs.prompt }} + kind: "triage" + issue: "true" + # issue_number: "123" # optional: attach to this existing issue + # instead of creating one (takes precedence over issue) + - name: Show the dispatch result run: | - set -euo pipefail - curl -s -X POST "$DISPATCH_URL/v1/tasks" \ - -H "Authorization: Bearer $DISPATCH_TOKEN" \ - -H "Content-Type: application/json" \ - -d "$(jq -n --arg repo "$GITHUB_REPOSITORY" --arg prompt "$PROMPT" \ - '{repo: $repo, title: "queued from Actions", prompt: $prompt, kind: "triage", issue: true}')" + echo "task: ${{ steps.queue.outputs.task_id }}" + echo "issue: ${{ steps.queue.outputs.issue_url }}" diff --git a/pm-stack/dispatch/src/auth.ts b/pm-stack/dispatch/src/auth.ts index c0cb4d1a70..5cb32cd491 100644 --- a/pm-stack/dispatch/src/auth.ts +++ b/pm-stack/dispatch/src/auth.ts @@ -4,8 +4,8 @@ // 1. GitHub Actions OIDC — a JWT issued by // https://token.actions.githubusercontent.com (RS256, verified against // its JWKS), audience = cfg.oidcAudience. The token's `repository` -// claim must be in the allowlist AND equal the request body's repo: -// a workflow can only dispatch for its own repo. +// claim must be in the allowlist. Grants mesh: any allowlisted +// repo may dispatch for any allowlisted repo (see assertCallerRepo). // 2. A static bearer secret (DISPATCH_API_TOKEN), compared in constant // time — the shape a repo stores as a GitHub Actions secret. // @@ -186,17 +186,25 @@ export async function authenticate(req: Request, deps: AuthDeps): Promise; @@ -163,6 +175,7 @@ export function parseTaskRequest(body: unknown): TaskRequest { priority: resolvePriority(b.priority), model: parseModel(b.model), issue: optBool(b, "issue", false), + issueNumber: parseIssueNumber(b.issue_number), dedupeKey: optString(b, "dedupe_key"), }; } diff --git a/pm-stack/dispatch/test/auth.test.ts b/pm-stack/dispatch/test/auth.test.ts index fbfd42d7d7..3a786845e2 100644 --- a/pm-stack/dispatch/test/auth.test.ts +++ b/pm-stack/dispatch/test/auth.test.ts @@ -109,25 +109,42 @@ describe("OIDC verification", () => { }); }); -describe("OIDC repo binding", () => { - const oidcCaller = { +describe("cross-repo grants (assertCallerRepo)", () => { + const allowlist = [ + "developing-today/code", + "developing-today/opencode", + "developing-today/openchamber", + "dezren39/nix", + ]; + const openchamberCaller = { type: "oidc" as const, - repository: "developing-today/code", + repository: "developing-today/openchamber", actor: "dezren39", }; - test("claim equal to the request repo passes", () => { - expect(() => assertCallerRepo(oidcCaller, "developing-today/code", ["developing-today/code"])).not.toThrow(); + test("cross-repo allowed: an openchamber token may target opencode", () => { + expect(() => assertCallerRepo(openchamberCaller, "developing-today/opencode", allowlist)).not.toThrow(); }); - test("claim different from the request repo is rejected — a workflow only dispatches for its own repo", () => { - expect(() => - assertCallerRepo(oidcCaller, "developing-today/opencode", ["developing-today/code", "developing-today/opencode"]), - ).toThrow(/does not match/); + test("same-repo still allowed", () => { + expect(() => assertCallerRepo(openchamberCaller, "developing-today/openchamber", allowlist)).not.toThrow(); }); - test("bearer callers are bound only by the allowlist", () => { - expect(() => assertCallerRepo({ type: "bearer" }, "developing-today/opencode", ["developing-today/opencode"])).not.toThrow(); - expect(() => assertCallerRepo({ type: "bearer" }, "dezren39/nix", ["developing-today/code"])).toThrow(/allowlist/); + test("an OIDC caller outside the allowlist is rejected", () => { + const outsider = { type: "oidc" as const, repository: "someone/else", actor: "mallory" }; + expect(() => assertCallerRepo(outsider, "developing-today/opencode", allowlist)).toThrow(/allowlist/); + }); + + test("a target outside the allowlist is rejected for OIDC callers", () => { + expect(() => assertCallerRepo(openchamberCaller, "someone/else", allowlist)).toThrow(/allowlist/); + }); + + test("bearer callers are unaffected by caller/target repo pairing: an allowlisted target passes", () => { + expect(() => assertCallerRepo({ type: "bearer" }, "developing-today/opencode", allowlist)).not.toThrow(); + expect(() => assertCallerRepo({ type: "bearer" }, "dezren39/nix", allowlist)).not.toThrow(); + }); + + test("bearer callers are rejected for a non-allowlisted target", () => { + expect(() => assertCallerRepo({ type: "bearer" }, "someone/else", allowlist)).toThrow(/allowlist/); }); }); diff --git a/pm-stack/dispatch/test/validate.test.ts b/pm-stack/dispatch/test/validate.test.ts index 1be81fb89c..cd2bcf7e78 100644 --- a/pm-stack/dispatch/test/validate.test.ts +++ b/pm-stack/dispatch/test/validate.test.ts @@ -102,3 +102,25 @@ describe("request validation", () => { expect(titleFromPrompt("x".repeat(200)).length).toBe(120); }); }); + +describe("task issue_number parsing", () => { + const base = { repo: "developing-today/code", title: "t", prompt: "p" }; + + test("accepts a positive integer and exposes it as issueNumber", () => { + expect(parseTaskRequest({ ...base, issue_number: 2672 }).issueNumber).toBe(2672); + expect(parseTaskRequest({ ...base, issue_number: 1 }).issueNumber).toBe(1); + }); + + test("absent issue_number is undefined", () => { + expect(parseTaskRequest(base).issueNumber).toBeUndefined(); + expect(parseTaskRequest({ ...base, issue_number: null }).issueNumber).toBeUndefined(); + }); + + test("rejects zero, negatives, floats and strings", () => { + expect(() => parseTaskRequest({ ...base, issue_number: 0 })).toThrow(/issue_number/); + expect(() => parseTaskRequest({ ...base, issue_number: -3 })).toThrow(ValidationError); + expect(() => parseTaskRequest({ ...base, issue_number: 1.5 })).toThrow(ValidationError); + expect(() => parseTaskRequest({ ...base, issue_number: "42" })).toThrow(ValidationError); + expect(() => parseTaskRequest({ ...base, issue_number: true })).toThrow(ValidationError); + }); +});