Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat([issue-13198]): approve or reject a waiting GitHub deployment from the inbox

Adam Eivy6fc5746a1d34
diff --git a/client/src/components/github/GitHubDeploymentReview.jsx b/client/src/components/github/GitHubDeploymentReview.jsx
new file mode 100644
index 0000000000..743f6ee1a5
--- /dev/null
+++ b/client/src/components/github/GitHubDeploymentReview.jsx
@@ -0,0 +1,107 @@
+import { useEffect, useId, useState } from 'react';
+import { getGitHubDeploymentReview, reviewGitHubDeployment } from '../../services/api';
+
+// Approve or reject the environments a waiting workflow run is blocked on.
+// Operator only: the server re-checks every id against the run's pending list.
+export default function GitHubDeploymentReview({ notification, onReviewed, onCancel }) {
+ const formId = useId();
+ const [environments, setEnvironments] = useState(null);
+ const [loadFailed, setLoadFailed] = useState(false);
+ const [selected, setSelected] = useState(() => new Set());
+ const [comment, setComment] = useState('');
+ const [submitting, setSubmitting] = useState(null);
+
+ useEffect(() => {
+ let live = true;
+ getGitHubDeploymentReview(notification.accountId, notification.threadId)
+ .then((review) => {
+ if (!live) return;
+ setEnvironments(review.environments);
+ setSelected(new Set(review.environments.filter((entry) => entry.canApprove).map((entry) => entry.environmentId)));
+ })
+ .catch(() => live && setLoadFailed(true));
+ return () => { live = false; };
+ }, [notification.accountId, notification.threadId]);
+
+ const toggle = (id) => setSelected((prev) => {
+ const next = new Set(prev);
+ if (next.has(id)) next.delete(id);
+ else next.add(id);
+ return next;
+ });
+
+ const submit = async (state) => {
+ setSubmitting(state);
+ const updated = await reviewGitHubDeployment(notification.accountId, notification.threadId, {
+ state, environmentIds: [...selected], ...(comment.trim() ? { comment: comment.trim() } : {}),
+ }).catch(() => null);
+ setSubmitting(null);
+ if (updated) onReviewed(updated);
+ };
+
+ const panel = 'mt-2 space-y-2 rounded-lg border border-port-border bg-port-bg p-3 text-xs';
+ if (loadFailed) return <p role="alert" className={`${panel} text-port-error`}>Could not read the deployment from GitHub.</p>;
+ if (!environments) return <p className={`${panel} text-gray-400`}>Loading the deployment…</p>;
+ if (!environments.length) {
+ return <p className={`${panel} text-gray-400`}>Nothing is waiting on this run any more. It was approved, rejected or expired; the next check marks it finished.</p>;
+ }
+ const busy = submitting !== null;
+ return (
+ <form className={panel} aria-label="Review deployment" onSubmit={(event) => event.preventDefault()}>
+ <fieldset className="space-y-1.5">
+ <legend className="mb-1 text-gray-400">Environments waiting on you</legend>
+ {environments.map((entry) => {
+ const id = `${formId}-env-${entry.environmentId}`;
+ return (
+ <div key={entry.environmentId} className="flex min-w-0 items-start gap-2">
+ <input
+ id={id}
+ type="checkbox"
+ checked={selected.has(entry.environmentId)}
+ disabled={!entry.canApprove || busy}
+ onChange={() => toggle(entry.environmentId)}
+ className="mt-0.5"
+ />
+ <label htmlFor={id} className="min-w-0 break-words text-gray-200">
+ <span className="font-mono text-white">{entry.name}</span>
+ {!entry.canApprove && <span className="text-gray-500"> · only {entry.reviewers.join(', ') || 'its reviewers'} can approve</span>}
+ </label>
+ </div>
+ );
+ })}
+ </fieldset>
+ <label htmlFor={`${formId}-comment`} className="block space-y-1 text-gray-400">
+ <span className="block">Comment (optional)</span>
+ <textarea
+ id={`${formId}-comment`}
+ value={comment}
+ maxLength={1000}
+ rows={2}
+ onChange={(event) => setComment(event.target.value)}
+ className="w-full rounded border border-port-border bg-port-card px-2 py-1.5 text-sm text-white"
+ />
+ </label>
+ <div className="flex flex-wrap gap-2">
+ <button
+ type="button"
+ onClick={() => submit('approved')}
+ disabled={busy || selected.size === 0}
+ className="min-h-[36px] rounded-lg bg-port-success px-3 py-1.5 text-xs font-medium text-white disabled:opacity-50"
+ >
+ {submitting === 'approved' ? 'Approving…' : 'Approve and deploy'}
+ </button>
+ <button
+ type="button"
+ onClick={() => submit('rejected')}
+ disabled={busy || selected.size === 0}
+ className="min-h-[36px] rounded-lg border border-port-error/60 px-3 py-1.5 text-xs text-port-error disabled:opacity-50"
+ >
+ {submitting === 'rejected' ? 'Rejecting…' : 'Reject'}
+ </button>
+ <button type="button" onClick={onCancel} disabled={busy} className="min-h-[36px] rounded-lg px-3 py-1.5 text-xs text-gray-400 disabled:opacity-50">
+ Cancel
+ </button>
+ </div>
+ </form>
+ );
+}
diff --git a/client/src/components/github/GitHubInboxTab.jsx b/client/src/components/github/GitHubInboxTab.jsx
index 8ea88d4115..58ca3da98c 100644
--- a/client/src/components/github/GitHubInboxTab.jsx
+++ b/client/src/components/github/GitHubInboxTab.jsx
@@ -7,6 +7,7 @@ import {
import Pill from '../ui/Pill';
import OverflowMenu from '../ui/OverflowMenu';
import GitHubThreadDrawer from './GitHubThreadDrawer';
+import GitHubDeploymentReview from './GitHubDeploymentReview';
import { AGENT_REFUSED_LABELS, DECISION_VIEW, TRUST_VIEW } from './githubTriageLabels';
import socket from '../../services/socket';
import LoadFailedState from '../ui/LoadFailedState';
@@ -148,7 +149,8 @@ function RepoFilter({ repos, repo, onSelect, total }) {
);
}
-function NotificationRow({ notification, accountLabel, busy, onAction }) {
+function NotificationRow({ notification, accountLabel, busy, onAction, onUpdated }) {
+ const [reviewing, setReviewing] = useState(false);
const handled = notification.state !== 'open';
const trust = TRUST_VIEW[notification.trust];
const decision = DECISION_VIEW[notification.decision];
@@ -192,11 +194,28 @@ function NotificationRow({ notification, accountLabel, busy, onAction }) {
{notification.readOnGithub && <Pill tone="muted">Read on GitHub</Pill>}
{handled && <Pill tone="muted">{STATE_LABELS[notification.state] || notification.state}</Pill>}
</div>
+ {reviewing && (
+ <GitHubDeploymentReview
+ notification={notification}
+ onCancel={() => setReviewing(false)}
+ onReviewed={(updated) => { setReviewing(false); onUpdated(notification, updated); }}
+ />
+ )}
{!handled && notification.agent?.refused && (
<p className="mt-1 text-xs text-gray-500">{AGENT_REFUSED_LABELS[notification.agent.refused] || notification.agent.refused}</p>
)}
</div>
<div className="flex shrink-0 flex-wrap items-center gap-1.5">
+ {!handled && notification.deployment && !reviewing && (
+ <button
+ type="button"
+ disabled={busy}
+ onClick={() => setReviewing(true)}
+ className="inline-flex min-h-[36px] items-center gap-1 rounded-lg bg-port-accent px-3 py-1.5 text-xs font-medium text-white disabled:opacity-50"
+ >
+ <Rocket size={13} aria-hidden="true" /> Review deployment
+ </button>
+ )}
{canResolve && (
<button
type="button"
@@ -301,7 +320,11 @@ export default function GitHubInboxTab() {
? resolveGitHubNotificationWithAgent(row.accountId, row.threadId)
: applyGitHubNotificationAction(row.accountId, row.threadId, action)).catch(() => null);
setBusyKey(null);
- if (!updated) return;
+ if (updated) applyUpdate(row, updated);
+ };
+
+ const applyUpdate = (row, updated) => {
+ const key = keyOf(row);
if (belongsInView(updated, view)) {
setData((prev) => ({ ...prev, notifications: prev.notifications.map((entry) => (keyOf(entry) === key ? updated : entry)) }));
} else {
@@ -438,6 +461,7 @@ export default function GitHubInboxTab() {
accountLabel={labelFor(notification.accountId)}
busy={busyKey === key || removing.has(key)}
onAction={handleAction}
+ onUpdated={applyUpdate}
/>
</CollapsibleListItem>
);
diff --git a/client/src/pages/GitHub.test.jsx b/client/src/pages/GitHub.test.jsx
index 80ecdb266a..fc4c5dc533 100644
--- a/client/src/pages/GitHub.test.jsx
+++ b/client/src/pages/GitHub.test.jsx
@@ -22,6 +22,8 @@ const mock = vi.hoisted(() => ({
applyGitHubNotificationAction: vi.fn(),
resolveGitHubNotificationWithAgent: vi.fn(),
clearFinishedGitHubNotifications: vi.fn(),
+ getGitHubDeploymentReview: vi.fn(),
+ reviewGitHubDeployment: vi.fn(),
getGitHubNotification: vi.fn(),
getGitHubAutomations: vi.fn(),
setGitHubNotificationCadence: vi.fn(),
@@ -421,6 +423,30 @@ describe('GitHub inbox tab', () => {
expect(screen.getByRole('link', { name: 'Open' }).getAttribute('href')).toBe(runUrl);
});
+ it('approves a waiting deployment from its row, only for environments you can approve', async () => {
+ const deployment = { runId: 4242, name: 'Deploy (prod)', headBranch: 'main', displayTitle: 'Example change', htmlUrl: 'https://github.com/octocat/hello/actions/runs/4242' };
+ mock.getGitHubNotifications.mockResolvedValue({
+ notifications: [{ ...NOTIFICATION, reason: 'approval_requested', subjectType: 'WorkflowRun', decision: 'surface-high', htmlUrl: deployment.htmlUrl, deployment }],
+ sync: {},
+ });
+ mock.getGitHubDeploymentReview.mockResolvedValue({
+ runId: 4242,
+ environments: [
+ { environmentId: 11, name: 'prod', canApprove: true, waitTimer: 0, reviewers: ['octocat'] },
+ { environmentId: 12, name: 'prod-eu', canApprove: false, waitTimer: 0, reviewers: ['release-team'] },
+ ],
+ });
+ mock.reviewGitHubDeployment.mockResolvedValue({ ...NOTIFICATION, state: 'done' });
+ renderTab('inbox');
+ fireEvent.click(await screen.findByRole('button', { name: 'Review deployment' }));
+ expect((await screen.findByLabelText(/^prod$/)).checked).toBe(true);
+ expect(screen.getByLabelText(/prod-eu/).disabled).toBe(true);
+ expect(screen.getByText(/only release-team can approve/)).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: 'Approve and deploy' }));
+ await waitFor(() => expect(mock.reviewGitHubDeployment).toHaveBeenCalledWith('github-com', '101', { state: 'approved', environmentIds: [11] }));
+ expect(await screen.findByText('Your inbox is clear.')).toBeTruthy();
+ });
+
it('marks a thread done and takes it out of the inbox', async () => {
mock.applyGitHubNotificationAction.mockResolvedValue({ ...NOTIFICATION, state: 'done', unread: false });
renderTab('inbox');
diff --git a/client/src/services/apiGithub.js b/client/src/services/apiGithub.js
index fdb93f4dc9..ccbc414408 100644
--- a/client/src/services/apiGithub.js
+++ b/client/src/services/apiGithub.js
@@ -47,6 +47,12 @@ export const applyGitHubNotificationAction = (accountId, threadId, action, optio
});
export const resolveGitHubNotificationWithAgent = (accountId, threadId, options = {}) =>
request(`/github/notifications/${encodeURIComponent(accountId)}/${encodeURIComponent(threadId)}/agent`, { method: 'POST', ...options });
+export const getGitHubDeploymentReview = (accountId, threadId, options = {}) =>
+ request(`/github/notifications/${encodeURIComponent(accountId)}/${encodeURIComponent(threadId)}/deployment`, options);
+export const reviewGitHubDeployment = (accountId, threadId, review, options = {}) =>
+ request(`/github/notifications/${encodeURIComponent(accountId)}/${encodeURIComponent(threadId)}/deployment`, {
+ method: 'POST', body: JSON.stringify(review), ...options,
+ });
export const getGitHubNotification = (accountId, threadId, options = {}) =>
request(`/github/notifications/${encodeURIComponent(accountId)}/${encodeURIComponent(threadId)}`, options);
diff --git a/server/lib/hostControlRoutes.js b/server/lib/hostControlRoutes.js
index 2d295f89f3..2bd779ad23 100644
--- a/server/lib/hostControlRoutes.js
+++ b/server/lib/hostControlRoutes.js
@@ -1095,6 +1095,8 @@ export const HOST_CONTROL_ROUTES = Object.freeze([
// create/edit pick the `gh` identity, mode, trust and allowed providers.
'POST /api/github/notifications/:accountId/:threadId',
'POST /api/github/notifications/clear-finished',
+ // Approving a deployment can ship to production (#13198).
+ 'POST /api/github/notifications/:accountId/:threadId/deployment',
'POST /api/github/audit/:accountId/apply',
'POST /api/github/audit-changes/:id/undo',
'POST /api/github/automations/activity/:id/undo',
diff --git a/server/lib/validation.js b/server/lib/validation.js
index 09157eb898..aae5d82109 100644
--- a/server/lib/validation.js
+++ b/server/lib/validation.js
@@ -1011,6 +1011,13 @@ export const githubNotificationsClearSchema = z.object({
accountId: z.string().trim().min(1).max(100).optional(),
}).strict();
+// Deployment approval from the inbox (#13198): operator only.
+export const githubDeploymentReviewSchema = z.object({
+ state: z.enum(['approved', 'rejected']),
+ environmentIds: z.array(z.number().int().positive()).min(1).max(20),
+ comment: z.string().trim().max(1000).optional(),
+}).strict();
+
export const githubNotificationActionSchema = z.object({
action: z.enum(['read', 'done', 'reopen', 'mute', 'unsubscribe', 'resubscribe']),
}).strict();
diff --git a/server/routes/github.js b/server/routes/github.js
index b6405c80f1..2466a1a60c 100644
--- a/server/routes/github.js
+++ b/server/routes/github.js
@@ -1,12 +1,13 @@
import express from 'express';
import { asyncHandler, ServerError } from '../lib/errorHandler.js';
import { validateRequest, githubRepoUpdateSchema, githubSecretSchema, githubAccountCreateSchema, githubAccountUpdateSchema,
- githubNotificationsQuerySchema, githubNotificationsSyncSchema, githubNotificationsClearSchema, githubNotificationActionSchema, GITHUB_NOTIFICATION_THREAD_ID_RE,
+ githubNotificationsQuerySchema, githubNotificationsSyncSchema, githubNotificationsClearSchema, githubNotificationActionSchema, githubDeploymentReviewSchema, GITHUB_NOTIFICATION_THREAD_ID_RE,
githubNotificationCadenceSchema, githubAuditApplySchema } from '../lib/validation.js';
import * as githubService from '../services/github.js';
import * as githubAccounts from '../services/githubAccounts.js';
import * as githubNotifications from '../services/githubNotifications.js';
import * as githubAudit from '../services/githubNotificationAudit.js';
+import * as githubDeployment from '../services/githubNotificationDeployment.js';
import { requestHasHostControl } from '../services/authGate.js';
const router = express.Router();
@@ -189,6 +190,21 @@ router.post('/notifications/:accountId/:threadId/agent', asyncHandler(async (req
res.json(await githubNotifications.resolveWithAgent(req.params.accountId, threadIdParam(req)));
}));
+/**
+ * GET /api/github/notifications/:accountId/:threadId/deployment — the environments a waiting run needs you to approve
+ */
+router.get('/notifications/:accountId/:threadId/deployment', asyncHandler(async (req, res) => {
+ res.json(await githubDeployment.getDeploymentReview(req.params.accountId, threadIdParam(req)));
+}));
+
+/**
+ * POST /api/github/notifications/:accountId/:threadId/deployment — approve or reject those environments
+ */
+router.post('/notifications/:accountId/:threadId/deployment', asyncHandler(async (req, res) => {
+ const body = validateRequest(githubDeploymentReviewSchema, req.body ?? {});
+ res.json(await githubDeployment.reviewDeployment(req.params.accountId, threadIdParam(req), body));
+}));
+
/**
* GET /api/github/automations — the notification check's cadence and each account's last run
*/
diff --git a/server/services/githubNotificationDeployment.js b/server/services/githubNotificationDeployment.js
new file mode 100644
index 0000000000..f0140651a2
--- /dev/null
+++ b/server/services/githubNotificationDeployment.js
@@ -0,0 +1,84 @@
+/**
+ * Deployment approvals from the GitHub notifications inbox (#13198): read the
+ * environments a waiting workflow run is blocked on, and approve or reject
+ * them as the operator.
+ *
+ * Operator only. Approving can ship to production, so nothing in Assist,
+ * Autopilot, an agent rule or an agent lane calls this module; the route is
+ * host-control gated. The run comes from triage's forge read
+ * (`evidence.workflowRun`), never from a title, and the environments sent are
+ * re-checked against the run's pending list at the moment of the tap.
+ */
+import { query } from '../lib/db.js';
+import { ServerError } from '../lib/errorHandler.js';
+import { safeJSONParse } from '../lib/fileUtils.js';
+import { toPgJson } from '../lib/pgJson.js';
+import { execGh } from './github.js';
+import { getAccount } from './githubAccounts.js';
+import { applyNotificationAction, getNotification, requireAccountEnv } from './githubNotifications.js';
+
+const GH_TIMEOUT_MS = 30_000;
+const REPO_RE = /^[A-Za-z0-9_.-]{1,100}\/[A-Za-z0-9_.-]{1,100}$/;
+const PENDING_JQ = '[.[] | {environmentId: .environment.id, name: .environment.name, canApprove: (.current_user_can_approve == true), waitTimer: (.wait_timer // 0), reviewers: [.reviewers[]? | (.reviewer.login // .reviewer.slug // .reviewer.name // empty)]}]';
+
+async function loadRun(accountId, threadId) {
+ const account = await getAccount(accountId);
+ const row = (await query('SELECT * FROM github_notifications WHERE account_id = $1 AND thread_id = $2', [account.id, threadId])).rows[0];
+ if (!row) throw new ServerError('Notification not found', { status: 404, code: 'GITHUB_NOTIFICATION_NOT_FOUND' });
+ const runId = row.evidence?.workflowRun?.id;
+ if (row.reason !== 'approval_requested' || !Number.isInteger(runId) || runId <= 0 || !REPO_RE.test(row.repo_full_name)) {
+ throw new ServerError('This notification is not a deployment waiting for approval', { status: 409, code: 'GITHUB_NOTIFICATION_NOT_DEPLOYMENT' });
+ }
+ return { account, row, runId, path: `repos/${row.repo_full_name}/actions/runs/${runId}/pending_deployments` };
+}
+
+async function readPending(account, env, path) {
+ const out = await execGh(['api', '--hostname', account.host, '--method', 'GET', path, '--jq', PENDING_JQ], GH_TIMEOUT_MS, { env });
+ const environments = safeJSONParse(out, null, { logError: false });
+ if (!Array.isArray(environments)) {
+ throw new ServerError('GitHub returned an unreadable list of pending deployments', { status: 502, code: 'GITHUB_DEPLOYMENTS_UNPARSEABLE' });
+ }
+ return environments.filter((entry) => Number.isInteger(entry?.environmentId) && entry.environmentId > 0).map((entry) => ({
+ environmentId: entry.environmentId,
+ name: String(entry.name || '').slice(0, 255),
+ canApprove: entry.canApprove === true,
+ waitTimer: Number.isInteger(entry.waitTimer) ? entry.waitTimer : 0,
+ reviewers: Array.isArray(entry.reviewers) ? entry.reviewers.filter((name) => typeof name === 'string').slice(0, 20) : [],
+ }));
+}
+
+/** The run and the environments it waits on; empty once nothing is waiting. */
+export async function getDeploymentReview(accountId, threadId) {
+ const { account, path, runId } = await loadRun(accountId, threadId);
+ const env = await requireAccountEnv(account);
+ return { runId, environments: await readPending(account, env, path) };
+}
+
+/**
+ * Approve or reject the chosen environments, then mark the thread done
+ * without teaching a learned rule. Every id must still be pending and one
+ * the operator can approve; otherwise nothing is sent.
+ */
+export async function reviewDeployment(accountId, threadId, { state, environmentIds, comment = '' }) {
+ const { account, row, path, runId } = await loadRun(accountId, threadId);
+ const env = await requireAccountEnv(account);
+ const pending = new Map((await readPending(account, env, path)).map((entry) => [entry.environmentId, entry]));
+ const ids = [...new Set(environmentIds)];
+ const refused = ids.filter((id) => !pending.get(id)?.canApprove);
+ if (refused.length) {
+ throw new ServerError('Those environments are no longer waiting on you; reload the deployment', { status: 409, code: 'GITHUB_DEPLOYMENT_NOT_PENDING' });
+ }
+ await execGh([
+ 'api', '--hostname', account.host, '--method', 'POST', path,
+ ...ids.flatMap((id) => ['-F', `environment_ids[]=${id}`]),
+ '-f', `state=${state}`, '-f', `comment=${comment}`,
+ ], GH_TIMEOUT_MS, { env });
+ const environments = ids.map((id) => pending.get(id).name);
+ await query(
+ 'INSERT INTO github_notification_events (account_id, thread_id, actor, kind, detail) VALUES ($1, $2, \'operator\', $3, $4::jsonb)',
+ [account.id, row.thread_id, state === 'approved' ? 'deployment-approved' : 'deployment-rejected', toPgJson({ runId, environments })],
+ );
+ console.log(`🚦 ${state === 'approved' ? 'Approved' : 'Rejected'} deployment of run ${runId} to ${environments.join(', ')} in ${row.repo_full_name}`);
+ await applyNotificationAction(account.id, row.thread_id, 'done', { learn: false, detail: { deployment: state, runId } });
+ return getNotification(account.id, row.thread_id);
+}
diff --git a/server/services/githubNotifications.db.test.js b/server/services/githubNotifications.db.test.js
index c0616723bd..329ff23484 100644
--- a/server/services/githubNotifications.db.test.js
+++ b/server/services/githubNotifications.db.test.js
@@ -48,6 +48,7 @@ const {
syncAccountNotifications, syncAllNotifications, listNotifications, applyNotificationAction, clearFinishedNotifications, getNotification, runScheduledNotificationCheck, describeScheduledCheck,
listAutomationActivity, undoAutomationAction, listLearnedRules, resolveWithAgent, getAutomationsOverview, setNotificationCadence,
} = await import('./githubNotifications.js');
+const { getDeploymentReview, reviewDeployment } = await import('./githubNotificationDeployment.js');
const { runAccountAudit, applyAuditSuggestion, listAuditChanges, undoAuditChange, sendDueAuditReports } = await import('./githubNotificationAudit.js');
let dbReady = false;
@@ -407,6 +408,40 @@ describe.skipIf(!runDb)('GitHub notifications inbox against Postgres', () => {
await updateAccount(account.id, { mode: 'observe' });
});
+ it('approves only environments still waiting on you, then marks the deployment done', async () => {
+ const login = account.login;
+ const requestedAt = '2026-10-01T10:00:00Z';
+ const pendingPath = `repos/${login}/hello/actions/runs/4242/pending_deployments`;
+ const forge = {
+ [`repos/${login}/hello/actions/runs?status=waiting&per_page=50`]: [{ id: 4242, name: 'Deploy (prod)', headBranch: 'main', actor: login, createdAt: '2026-10-01T09:00:00Z', updatedAt: requestedAt }],
+ [pendingPath]: [
+ { environmentId: 11, name: 'prod', canApprove: true, waitTimer: 0, reviewers: [login] },
+ { environmentId: 12, name: 'prod-eu', canApprove: false, waitTimer: 0, reviewers: ['release-team'] },
+ ],
+ };
+ const actions = mockGh(() => listing([
+ thread('2201', { owner: login, reason: 'approval_requested', type: 'WorkflowRun', url: null, updatedAt: requestedAt }),
+ ]), forge);
+ await syncAccountNotifications(account.id);
+
+ expect((await getDeploymentReview(account.id, '2201')).environments.map((entry) => [entry.environmentId, entry.canApprove])).toEqual([[11, true], [12, false]]);
+ // An environment someone else must approve is refused before anything is sent.
+ await expect(reviewDeployment(account.id, '2201', { state: 'approved', environmentIds: [11, 12] })).rejects.toMatchObject({ code: 'GITHUB_DEPLOYMENT_NOT_PENDING' });
+ expect(actions).toEqual([]);
+
+ const reviewed = await reviewDeployment(account.id, '2201', { state: 'approved', environmentIds: [11], comment: 'Ship it' });
+ const post = vi.mocked(execGh).mock.calls.map(([args]) => args).find((args) => args.includes('POST'));
+ expect(post).toEqual(expect.arrayContaining([pendingPath, 'environment_ids[]=11', 'state=approved', 'comment=Ship it']));
+ expect(post).not.toContain('environment_ids[]=12');
+ expect(actions).toEqual([['POST', pendingPath], ['DELETE', 'notifications/threads/2201']]);
+ expect(reviewed).toMatchObject({ state: 'done' });
+ expect(reviewed.events.map((event) => event.kind)).toEqual(expect.arrayContaining(['deployment-approved', 'done']));
+ // A thread that is not a waiting deployment has nothing to approve.
+ await expect(getDeploymentReview(account.id, '2201')).resolves.toMatchObject({ runId: 4242 });
+ await query(`UPDATE github_notifications SET evidence = evidence - 'workflowRun' WHERE account_id = $1 AND thread_id = '2201'`, [account.id]);
+ await expect(reviewDeployment(account.id, '2201', { state: 'rejected', environmentIds: [11] })).rejects.toMatchObject({ code: 'GITHUB_NOTIFICATION_NOT_DEPLOYMENT' });
+ });
+
it('sorts undecided threads only in Assist, acts only on trusted ones, and undoes into a learned rule', async () => {
const login = account.login;
const pr = (author, state = 'open', merged = false) => ({ author, association: 'NONE', state, merged });
diff --git a/server/services/githubNotifications.js b/server/services/githubNotifications.js
index 72c5c47ce4..c708db4b89 100644
--- a/server/services/githubNotifications.js
+++ b/server/services/githubNotifications.js
@@ -70,7 +70,7 @@ const listingCursor = (stored) => (typeof stored === 'string' && stored.startsWi
const isNotModified = (error) => /\bHTTP 304\b/.test(String(error?.ghStderr || error?.message || ''));
-async function requireAccountEnv(account) {
+export async function requireAccountEnv(account) {
if (!account.enabled) {
throw new ServerError(`${account.label} is turned off`, { status: 409, code: 'GITHUB_ACCOUNT_DISABLED' });
}