Public: anyone can read this; the crew can change it.
When the included credit runs out mid-change, the app page and the pull say so and offer a way on #13806
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13797-when-the-included-credit-runs-out-mid-ch → main 9 commits fork 3 threads · 3 unresolved
10 files
changed +189
−27
docs/features/land-as-is.md +15 −7
| @@ -1,10 +1,18 @@ | ||
| 1 | # Land it as it is | |
| 1 | # Ship it as it is | |
| 2 | 2 | |
| 3 | When the crew cannot go on (its included credit is spent, or it has no model key) a green pull still goes live. | |
| 3 | When the crew cannot go on, a green pull still goes live. | |
| 4 | 4 | |
| 5 | - The pull page and the app's page each say so in one sentence, and offer **Land it as it is** with the preview link beside it, and **Add a key**. | |
| 6 | - The button is the pull's own ship action (`POST /:owner/:name/pulls/:n/ship`, same-origin checked, `mergePull` behind it). It is offered only for a pull whose check is green and whose verdict is "Ready to land"; a red pull never shows it. | |
| 7 | - MCP: the existing `merge` tool takes `action: "land"` (squash, only while the check is green); its plan carries `crew` with the same sentence. | |
| 5 | The crew cannot go on when its included credit is spent or it has no model key. | |
| 6 | ||
| 7 | - The pull page and the app's page say why, in one sentence. | |
| 8 | - Beside it: **Ship it as it is**, the preview link and **Add your key**. | |
| 9 | - Only an admin sees **Add your key**. Anyone else is told only an admin can add one. | |
| 10 | - The button is the pull's own ship action: `POST /:owner/:name/pulls/:n/ship`, same-origin checked, `mergePull` behind it. | |
| 11 | - It shows only for a pull whose check is green. A red pull never shows it. | |
| 12 | - It shows on a pull a reviewer asked changes of, for an admin only: nobody can answer the changes without credit. | |
| 13 | - A repository that requires review keeps its rule, so there it does not show. | |
| 14 | - A conflict, a mirror or a review still waited for never shows it. | |
| 15 | - Before the credit runs out, the app page says "About one more change left". | |
| 16 | - MCP: the `merge` tool takes `action: "land"` (squash, only while the check is green). Its plan carries `crew`, the same sentence. | |
| 17 | - Terminal: the palette's "<owner>/<name> — Ship it as it is" (`src/tui/screens/landasis.ts`) while a pull waits. Enter ships the pull under the cursor, squashed. `landable` gives page, terminal and MCP the same rows. | |
| 8 | 18 | - Code: `src/web/studio/land_as_is.ts`. Test: `test/land-as-is.test.ts`. |
| 9 | - Terminal: the palette's "<owner>/<name> — Land it as it is" (`src/tui/screens/landasis.ts`) while an open app has a pull to land; Enter lands the pull under the cursor, squashed, as the page's button does. `landable` gives the page, the terminal and MCP the same rows (a writer's, the crew stopped, the check green). | |
| 10 | - Only an admin is shown **Add a key**; anyone else is told only the admin can. |
src/http/mcp/tools/merge.ts +4 −3
| @@ -5,7 +5,7 @@ import { checkSummary } from "../../../core/runs.ts"; | ||
| 5 | 5 | import { canVerdict } from "../../../core/verdict.ts"; |
| 6 | 6 | import { reviewWords } from "../../../actions/review_words.ts"; |
| 7 | 7 | import { mergeFailure } from "../../../web/pages/pull.ts"; |
| 8 | import { LAND_AS_IS, stalledWords } from "../../../web/studio/land_as_is.ts"; | |
| 8 | import { LAND_AS_IS, shipsPastReviews, stalledWords } from "../../../web/studio/land_as_is.ts"; | |
| 9 | 9 | import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| 10 | 10 | |
| 11 | 11 | /** |
| @@ -16,7 +16,7 @@ import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts" | ||
| 16 | 16 | */ |
| 17 | 17 | export const tool: Tool = { |
| 18 | 18 | name: "merge", |
| 19 | doc: "`{ repo, number, strategy?, action?, dryRun? }` (a person, never an agent: a person merges): land a pull as its page's Merge button does, `merge` (default) or `squash`; `action: \"land\"` is the page's Land it as it is (squash, and only while the check is green); plans carry `crew` when the crew cannot go on; planned unless `dryRun` is false: the plan is the pull's `head`, `base`, `mergeable`, `conflicts` and `check` as `pull` reads them; landing is `mergePull`'s, with its refusals (conflict, review or check required, not a writer) in the page's words, and takes an rw token", | |
| 19 | doc: "`{ repo, number, strategy?, action?, dryRun? }` (a person, never an agent: a person merges): land a pull as its page's Merge button does, `merge` (default) or `squash`; `action: \"land\"` is the page's Ship it as it is (squash, and only while the check is green); plans carry `crew` when the crew cannot go on; planned unless `dryRun` is false: the plan is the pull's `head`, `base`, `mergeable`, `conflicts` and `check` as `pull` reads them; landing is `mergePull`'s, with its refusals (conflict, review or check required, not a writer) in the page's words, and takes an rw token", | |
| 20 | 20 | description: "Land a pull, as its page's Merge button does; a person's only.", |
| 21 | 21 | inputSchema: { |
| 22 | 22 | type: "object", |
| @@ -73,7 +73,8 @@ export const tool: Tool = { | ||
| 73 | 73 | } |
| 74 | 74 | if (act === "land" && checkSummary(ctx.app.db, pull.id, pull.headOid).state !== "ok") |
| 75 | 75 | return bad("check_required", `${LAND_AS_IS} waits for a green check`); |
| 76 | const merged = await mergePull(ctx.app, user, repo, pull, strategy); | |
| 76 | const merged = await mergePull(ctx.app, user, repo, pull, strategy, undefined, | |
| 77 | act === "land" && shipsPastReviews(ctx.app, repo, pull, user) ? { pastReviews: true } : {}); | |
| 77 | 78 | if (!merged.ok) { |
| 78 | 79 | const error = merged.error; |
| 79 | 80 | const code = |
src/tui/screens/landasis.ts +2 −2
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | import { mergePull } from "../../actions/pulls.ts"; |
| 10 | 10 | import type { Repo } from "../../core/repos.ts"; |
| 11 | 11 | import { mergeFailure } from "../../web/pages/pull.ts"; |
| 12 | import { LAND_AS_IS, landable, stalledWords } from "../../web/studio/land_as_is.ts"; | |
| 12 | import { LAND_AS_IS, landable, shipsPastReviews, stalledWords } from "../../web/studio/land_as_is.ts"; | |
| 13 | 13 | import type { Ctx, Screen } from "../app/app.ts"; |
| 14 | 14 | import { binding } from "../app/keys.ts"; |
| 15 | 15 | import type { Command } from "../app/palette.ts"; |
| @@ -40,7 +40,7 @@ export function landScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 40 | 40 | const at = all[state.index]; |
| 41 | 41 | if (at === undefined || busy) return true; |
| 42 | 42 | busy = true; |
| 43 | void mergePull(f.app, f.user, repo, at, "squash") | |
| 43 | void mergePull(f.app, f.user, repo, at, "squash", undefined, shipsPastReviews(f.app, repo, at, f.user) ? { pastReviews: true } : {}) | |
| 44 | 44 | .then((done) => ctx.toast(done.ok ? `Landed #${at.number} as it is.` : mergeFailure(done.error), done.ok ? undefined : "danger")) |
| 45 | 45 | .finally(() => { |
| 46 | 46 | busy = false; |
src/web/pages/pull-verdict.ts +3
| @@ -37,6 +37,8 @@ export interface Verdict { | ||
| 37 | 37 | readonly tone: Tone | undefined; |
| 38 | 38 | /** A fixed phrase of ours, never a person's text. */ |
| 39 | 39 | readonly words: string; |
| 40 | /** Set when a reviewer's asked-for changes hold the pull: callers read this, never the words. */ | |
| 41 | readonly kind?: "changes_requested"; | |
| 40 | 42 | readonly action: { readonly label: string; readonly href: string } | null; |
| 41 | 43 | } |
| 42 | 44 | |
| @@ -63,6 +65,7 @@ export function verdictOf(v: VerdictInput, thread: string, page = ""): Verdict { | ||
| 63 | 65 | return { |
| 64 | 66 | tone: "attn", |
| 65 | 67 | words: v.changesRequested ? "A reviewer asked for changes" : "Waiting for a review", |
| 68 | ...(v.changesRequested ? { kind: "changes_requested" as const } : {}), | |
| 66 | 69 | action: { label: "Review", href: `${page}#review-body` }, |
| 67 | 70 | }; |
| 68 | 71 | if (v.teamsHolding > 0) |
src/web/pages/pull.ts +2 −2
| @@ -36,7 +36,7 @@ import { tierLine, type TierState } from "../../checks/tiers.ts"; | ||
| 36 | 36 | import { fromKeptFork } from "../../core/landing_kind.ts"; |
| 37 | 37 | import { combinedCard } from "./pull-combined.ts"; |
| 38 | 38 | import { verdictLine, verdictOf, type VerdictInput } from "./pull-verdict.ts"; |
| 39 | import { landAsIs } from "../studio/land_as_is.ts"; | |
| 39 | import { landAsIs, shipsOn } from "../studio/land_as_is.ts"; | |
| 40 | 40 | import { getAppByRepo } from "../../core/apps.ts"; |
| 41 | 41 | import { labelsFor, listLabels } from "../../core/issues.ts"; |
| 42 | 42 | import { marksByName } from "../../core/marks.ts"; |
| @@ -1146,7 +1146,7 @@ export async function pullFilesPage(ctx: Ctx): Promise<Response> { | ||
| 1146 | 1146 | ${changeHead(ctx, repo, pull, { headOid: status.headOid, conflicts: status.conflicts.length })} |
| 1147 | 1147 | ${changeTabs(repo, pull, "files")} |
| 1148 | 1148 | ${verdictLine(verdict)} |
| 1149 | ${verdict.tone === "success" && mayMerge && check.state === "ok" && !stale | |
| 1149 | ${shipsOn(verdict, ctx.app, repo, pull, ctx.auth.user) && mayMerge && check.state === "ok" && !stale | |
| 1150 | 1150 | ? landAsIs(ctx, repo, pull) |
| 1151 | 1151 | : null} |
| 1152 | 1152 | <p class="files-where muted small" id="files"> |
src/web/studio/actions.ts +7 −1
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | import type { Routed } from "../../crew/route.ts"; |
| 12 | 12 | import { COMPOSER_FIELDS, claimShare, refuseTell, releaseShare } from "../share_target.ts"; |
| 13 | 13 | import { mayView } from "../../core/sealed.ts"; |
| 14 | import { shipsPastReviews } from "./land_as_is.ts"; | |
| 14 | 15 | import { holdPull, releasePull } from "../../actions/holds.ts"; |
| 15 | 16 | import { addComment } from "../../actions/issues.ts"; |
| 16 | 17 | import { parseFrom } from "../../actions/tell_from.ts"; |
| @@ -308,7 +309,12 @@ export async function shipSubmit(ctx: Ctx): Promise<Response> { | ||
| 308 | 309 | return notFoundPage(ctx); |
| 309 | 310 | // The inbox and the feed say where they were; the pull page does not. |
| 310 | 311 | const back = backTo(form, changeHref(base, pull.number)); |
| 311 | const merged = await mergePull(ctx.app, ctx.auth.user, repo, pull, "squash"); | |
| 312 | const merged = await mergePull( | |
| 313 | ctx.app, ctx.auth.user, repo, pull, "squash", undefined, | |
| 314 | // The crew cannot answer a reviewer's changes without credit: an admin's press lands the | |
| 315 | // green change (#13797). | |
| 316 | shipsPastReviews(ctx.app, repo, pull, ctx.auth.user) ? { pastReviews: true } : {}, | |
| 317 | ); | |
| 312 | 318 | // A conflict is never the person's to fix: the pull's agent brings the |
| 313 | 319 | // branch up to date, and the pull comes back green, or lands on its own. |
| 314 | 320 | if ( |
src/web/studio/change.ts +2 −2
| @@ -68,7 +68,7 @@ import { previewBlock } from "../pages/apps.ts"; | ||
| 68 | 68 | import { filmstrip, filmstripJs } from "../pages/filmstrip.ts"; |
| 69 | 69 | import { lookCard } from "../pages/looks.ts"; |
| 70 | 70 | import { approveHereCard, keptChange, pullChecksLineFor, reachLine, teamsCard, verdictFacts } from "../pages/pull.ts"; |
| 71 | import { landAsIs } from "./land_as_is.ts"; | |
| 71 | import { landAsIs, shipsOn } from "./land_as_is.ts"; | |
| 72 | 72 | import { changeSummary, verdictLine, verdictOf } from "../pages/pull-verdict.ts"; |
| 73 | 73 | import { guestWalls, strangerCard } from "../pages/pull-guest.ts"; |
| 74 | 74 | import { combinedCard } from "../pages/pull-combined.ts"; |
| @@ -807,7 +807,7 @@ async function changeConversation( | ||
| 807 | 807 | )} |
| 808 | 808 | <div id="pull-check">${checkLine}</div> |
| 809 | 809 | ${when(runLine, (l) => l)} ${gate} ${decisionSection} |
| 810 | ${verdict.tone === "success" && writer && word === "look" | |
| 810 | ${shipsOn(verdict, ctx.app, repo, pull, ctx.auth.user) && writer && word === "look" | |
| 811 | 811 | ? landAsIs(ctx, repo, pull) |
| 812 | 812 | : null} |
| 813 | 813 | ${when(visionPreview, (v) => visionPreviewCard(v))} |
src/web/studio/crew_key.ts +11 −1
| @@ -92,6 +92,16 @@ function payingCard(app: App, compact: boolean): Html | null { | ||
| 92 | 92 | return html`<p class="small muted" id="crew-key-note" role="status">${icon("key")} ${OWN_KEY_NOTE}</p>`; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | /** What one change costs at most, from what the host's credit paid for (#13797: $0.33 to $0.80). */ | |
| 96 | const CHANGE_USD = 0.8; | |
| 97 | ||
| 98 | /** Said on the app page before the credit runs out: when about one more change is left. */ | |
| 99 | function runningLow(app: App): Html | null { | |
| 100 | const credit = crewHasCredential(app.db) ? undefined : includedCredit(app); | |
| 101 | if (credit === undefined || credit.leftUsd <= 0 || credit.leftUsd > CHANGE_USD) return null; | |
| 102 | return html`<p class="small muted" id="crew-key-note" role="status">${icon("alert")} About one more change left on the included credit (${usdWords(credit.leftUsd)}). A key of your own keeps it building.</p>`; | |
| 103 | } | |
| 104 | ||
| 95 | 105 | /** What the crew runs on, said once, with the field when a key would change anything (`compact`: a line and a link, no field). */ |
| 96 | 106 | export function crewKeyCard(ctx: Ctx, compact = false): Html | null { |
| 97 | 107 | // Credit left is something to run on: the card never asks for a key then, in any form (#11508). |
| @@ -99,7 +109,7 @@ export function crewKeyCard(ctx: Ctx, compact = false): Html | null { | ||
| 99 | 109 | const admin = ctx.auth.user?.isAdmin === true; |
| 100 | 110 | // On a repository page: one line and a link, the field lives on the feed page. |
| 101 | 111 | if (compact) { |
| 102 | if (crewCanRun(ctx.app)) return null; | |
| 112 | if (crewCanRun(ctx.app)) return runningLow(ctx.app); | |
| 103 | 113 | return html`<p class="small muted" id="crew-key-note" role="status">${icon("alert")} The crew needs a model key to start. |
| 104 | 114 | ${blockedWay(noKeyBlocked(ctx.app, ctx.auth.user))}</p>`; |
| 105 | 115 | } |
src/web/studio/land_as_is.ts +34 −4
| @@ -15,7 +15,7 @@ import type { App } from "../../app.ts"; | ||
| 15 | 15 | import { requireWriter } from "../../actions/access.ts"; |
| 16 | 16 | import { getAppByRepo } from "../../core/apps.ts"; |
| 17 | 17 | import { listOpenPulls, type Pull } from "../../core/pulls.ts"; |
| 18 | import type { Repo } from "../../core/repos.ts"; | |
| 18 | import { canAdmin, type Repo } from "../../core/repos.ts"; | |
| 19 | 19 | import { checkSummary } from "../../core/runs.ts"; |
| 20 | 20 | import type { User } from "../../core/users.ts"; |
| 21 | 21 | import type { Ctx } from "../../http/context.ts"; |
| @@ -26,7 +26,7 @@ import { crewCanRun, hasCrew, includedCredit } from "./crew_key.ts"; | ||
| 26 | 26 | import { changeHref } from "./nouns.ts"; |
| 27 | 27 | |
| 28 | 28 | /** The one label, on the page, in the terminal and in the MCP tool's `action`. */ |
| 29 | export const LAND_AS_IS = "Land it as it is"; | |
| 29 | export const LAND_AS_IS = "Ship it as it is"; | |
| 30 | 30 | export const ADD_KEY_HREF = "/settings/subscriptions"; |
| 31 | 31 | |
| 32 | 32 | /** |
| @@ -36,10 +36,40 @@ export const ADD_KEY_HREF = "/settings/subscriptions"; | ||
| 36 | 36 | export function stalledWords(app: App): string | null { |
| 37 | 37 | if (!hasCrew(app) || crewCanRun(app)) return null; |
| 38 | 38 | return includedCredit(app) !== undefined |
| 39 | ? "The crew cannot go on: the included credit is spent." | |
| 39 | ? "The included credit is spent; this change is waiting." | |
| 40 | 40 | : "The crew cannot go on: it has no model key."; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | /** | |
| 44 | * Whether this person's press lands past a reviewer's verdict: they administer the repository, | |
| 45 | * the crew is stopped so nobody can answer the changes asked (#13797), and the check is green. | |
| 46 | * A repository that requires review keeps it. | |
| 47 | */ | |
| 48 | export function shipsPastReviews(app: App, repo: Repo, pull: Pull, user: User | undefined): boolean { | |
| 49 | return ( | |
| 50 | user !== undefined && | |
| 51 | canAdmin(app.db, repo, user) && | |
outdated
Bypass applies to any writer; no owner check (finding 1). Also the requireReview rule is untested. |
||
| 52 | stalledWords(app) !== null && | |
| 53 | !pull.mergedAt && | |
| 54 | !repo.requireReview && | |
| 55 | checkSummary(app.db, pull.id, pull.headOid).state === "ok" | |
| 56 | ); | |
| 57 | } | |
| 58 | ||
| 59 | /** | |
Matches on display text; use the verdict's state, not its words (finding 2). Should also agree with shipsPastReviews (finding 3). |
||
| 60 | * Whether the verdict leaves the button on offer: ready to land, or held only by a reviewer's ask | |
| 61 | * this person may land past. A conflict, a mirror or a review still waited for offers none. | |
| 62 | */ | |
| 63 | export function shipsOn( | |
| 64 | v: { readonly tone: string | undefined; readonly kind?: string }, | |
| 65 | app: App, | |
| 66 | repo: Repo, | |
| 67 | pull: Pull, | |
| 68 | user: User | undefined, | |
| 69 | ): boolean { | |
| 70 | return v.tone === "success" || (v.kind === "changes_requested" && shipsPastReviews(app, repo, pull, user)); | |
| 71 | } | |
| 72 | ||
| 43 | 73 | /** |
| 44 | 74 | * The open pulls of this repository the viewer may land as they are: a writer's, the crew |
| 45 | 75 | * stopped, the check green. |
| @@ -59,7 +89,7 @@ const landForm = (repo: Repo, pull: Pull): Html => | ||
| 59 | 89 | /** Who may add a key gets the link; anyone else is told why there is none. */ |
| 60 | 90 | const keyOffer = (ctx: Ctx): Html => |
| 61 | 91 | ctx.auth.user?.isAdmin === true |
| 62 | ? btn("Add a key", { href: ADD_KEY_HREF, size: "sm" }) | |
| 92 | ? btn("Add your key", { href: ADD_KEY_HREF, size: "sm" }) | |
| 63 | 93 | : html`<span class="muted small">${blockedWay(noKeyBlocked(ctx.app, ctx.auth.user))}</span>`; |
| 64 | 94 | |
| 65 | 95 | /** The pull's own page: the sentence, the button, the preview beside it, the key. */ |
test/land-as-is.test.ts +109 −5
| @@ -15,12 +15,14 @@ import { openPull } from "../src/actions/pulls.ts"; | ||
| 15 | 15 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 16 | 16 | import { getPull, type Pull } from "../src/core/pulls.ts"; |
| 17 | 17 | import type { Repo } from "../src/core/repos.ts"; |
| 18 | import { submitReview } from "../src/core/reviews.ts"; | |
| 18 | 19 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; |
| 19 | 20 | import { createUser, type User } from "../src/core/users.ts"; |
| 20 | 21 | import { createToken } from "../src/core/tokens.ts"; |
| 21 | 22 | import { promote } from "./helpers/members.ts"; |
| 22 | import { landable } from "../src/web/studio/land_as_is.ts"; | |
| 23 | import { landCommands } from "../src/tui/screens/landasis.ts"; | |
| 23 | import { landable, shipsPastReviews } from "../src/web/studio/land_as_is.ts"; | |
| 24 | import { landCommands, landScreen } from "../src/tui/screens/landasis.ts"; | |
| 25 | import { updateRepoSettings } from "../src/core/repos.ts"; | |
| 24 | 26 | import { serve, type Servers } from "../src/http/server.ts"; |
| 25 | 27 | import { STRANGER_NEVER_SEES } from "../src/design/first_five_minutes.ts"; |
| 26 | 28 | import { LAND_AS_IS } from "../src/web/studio/land_as_is.ts"; |
| @@ -142,7 +144,7 @@ describe("land it as it is", () => { | ||
| 142 | 144 | test("credit runs out after a green pull: the sentence, the button, the preview and the key on both pages; pressing it lands", async () => { |
| 143 | 145 | const pull = await pullWith("ok"); |
| 144 | 146 | spendCredit(); |
| 145 | const sentence = "The crew cannot go on: the included credit is spent."; | |
| 147 | const sentence = "The included credit is spent; this change is waiting."; | |
| 146 | 148 | for (const path of [`/alice/garden/pulls/${pull.number}`, `/alice/garden/pulls/${pull.number}/files`, "/alice/garden"]) { |
| 147 | 149 | const page = await get(path); |
| 148 | 150 | expect(page).toContain(sentence); |
| @@ -183,7 +185,7 @@ describe("land it as it is", () => { | ||
| 183 | 185 | const rw = createToken(app.db, alice.id, "rw", "rw").token; |
| 184 | 186 | const green = await pullWith("ok"); |
| 185 | 187 | const plan = await mcp(rw, { repo: "alice/garden", number: green.number, action: "land" }); |
| 186 | expect(plan.value.crew).toBe("The crew cannot go on: the included credit is spent."); | |
| 188 | expect(plan.value.crew).toBe("The included credit is spent; this change is waiting."); | |
| 187 | 189 | expect(getPull(app.db, repo.id, green.number)?.mergedAt).toBeNull(); |
| 188 | 190 | const landed = await mcp(rw, { repo: "alice/garden", number: green.number, action: "land", dryRun: false }); |
| 189 | 191 | expect(landed.value.strategy).toBe("squash"); |
| @@ -200,7 +202,7 @@ describe("land it as it is", () => { | ||
| 200 | 202 | const a = await pullWith("ok"); |
| 201 | 203 | const b = await pullWith("ok"); |
| 202 | 204 | const page = await get("/alice/garden"); |
| 203 | expect(page.split("The crew cannot go on").length - 1).toBe(1); | |
| 205 | expect(page.split("this change is waiting").length - 1).toBe(1); | |
| 204 | 206 | expect(page).toContain(`action="/alice/garden/pulls/${a.number}/ship"`); |
| 205 | 207 | expect(page).toContain(`action="/alice/garden/pulls/${b.number}/ship"`); |
| 206 | 208 | const rows = landable(app, alice, repo).map((p) => p.number); |
| @@ -235,4 +237,106 @@ describe("land it as it is", () => { | ||
| 235 | 237 | // Signed out, nothing is offered. |
| 236 | 238 | expect(landable(app, undefined, made.value)).toEqual([]); |
| 237 | 239 | }); |
| 240 | ||
| 241 | test("a reviewer asked for changes and the credit is spent: the page names the credit and both ways, and shipping lands it", async () => { | |
| 242 | spendCredit(); | |
| 243 | const rev = await createUser(app.db, { origin: "seed", trusted: true, username: "rev", email: "[email protected]", password: "a-good-passphrase" }); | |
| 244 | if (!rev.ok) throw new Error(rev.error); | |
| 245 | const pull = await pullWith("ok"); | |
| 246 | const asked = submitReview(app.db, { issueId: pull.id, authorId: rev.value.id, state: "changes_requested", commitOid: pull.headOid }); | |
| 247 | if (!asked.ok) throw new Error(asked.error); | |
| 248 | for (const path of [`/alice/garden/pulls/${pull.number}`, `/alice/garden/pulls/${pull.number}/files`, "/alice/garden"]) { | |
| 249 | const page = await get(path); | |
| 250 | expect(page).toContain("The included credit is spent; this change is waiting."); | |
| 251 | expect(page).toContain("Ship it as it is"); | |
| 252 | expect(page).toContain("Add your key"); | |
| 253 | } | |
| 254 | const landed = await fetch(`${base}/alice/garden/pulls/${pull.number}/ship`, { method: "POST", headers: { cookie, origin: base }, redirect: "manual" }); | |
| 255 | expect(landed.status).toBe(303); | |
| 256 | expect(getPull(app.db, repo.id, pull.number)?.mergedAt).not.toBeNull(); | |
| 257 | }); | |
| 258 | ||
| 259 | const askedChanges = async (): Promise<Pull> => { | |
| 260 | let rev = getUserByName("rev"); | |
| 261 | const pull = await pullWith("ok"); | |
| 262 | const asked = submitReview(app.db, { issueId: pull.id, authorId: rev.id, state: "changes_requested", commitOid: pull.headOid }); | |
| 263 | if (!asked.ok) throw new Error(asked.error); | |
| 264 | return pull; | |
| 265 | }; | |
| 266 | const getUserByName = (name: string): User => app.db.query<any, [string]>("SELECT * FROM user WHERE username = ?1").get(name) as User; | |
| 267 | const ship = (pull: Pull) => | |
| 268 | fetch(`${base}/alice/garden/pulls/${pull.number}/ship`, { method: "POST", headers: { cookie, origin: base }, redirect: "manual" }); | |
| 269 | const mergedAt = (pull: Pull) => getPull(app.db, repo.id, pull.number)?.mergedAt; | |
| 270 | ||
| 271 | test("a repository that requires review keeps its rule: no card, and shipping does not land", async () => { | |
| 272 | spendCredit(); | |
| 273 | const pull = await askedChanges(); | |
| 274 | updateRepoSettings(app.db, repo, { ...repo, requireReview: true }); | |
| 275 | try { | |
| 276 | const live = { ...repo, requireReview: true }; | |
| 277 | expect(shipsPastReviews(app, live, pull, alice)).toBe(false); | |
| 278 | expect(await get(`/alice/garden/pulls/${pull.number}`)).not.toContain("data-land-as-is"); | |
| 279 | await ship(pull); | |
| 280 | expect(mergedAt(pull)).toBeNull(); | |
| 281 | } finally { | |
| 282 | updateRepoSettings(app.db, repo, { ...repo, requireReview: false }); | |
| 283 | } | |
| 284 | }); | |
| 285 | ||
| 286 | test("only an admin lands past a reviewer: a person who does not administer the repository is not let", async () => { | |
| 287 | spendCredit(); | |
| 288 | const pull = await askedChanges(); | |
| 289 | expect(shipsPastReviews(app, repo, pull, alice)).toBe(true); | |
| 290 | const bob = getUserByName("bob"); | |
| 291 | expect(shipsPastReviews(app, repo, pull, bob)).toBe(false); | |
| 292 | expect(shipsPastReviews(app, repo, pull, undefined)).toBe(false); | |
| 293 | const rw = createToken(app.db, bob.id, "bobrw", "rw").token; | |
| 294 | const refused = await mcp(rw, { repo: "alice/garden", number: pull.number, action: "land", dryRun: false }); | |
| 295 | expect(refused.error).toBeDefined(); | |
| 296 | expect(mergedAt(pull)).toBeNull(); | |
| 297 | }); | |
| 298 | ||
| 299 | test("MCP land goes past a reviewer's ask for the admin", async () => { | |
| 300 | spendCredit(); | |
| 301 | const pull = await askedChanges(); | |
| 302 | const rw = createToken(app.db, alice.id, "rw2", "rw").token; | |
| 303 | const landed = await mcp(rw, { repo: "alice/garden", number: pull.number, action: "land", dryRun: false }); | |
| 304 | expect(landed.value?.strategy).toBe("squash"); | |
| 305 | expect(mergedAt(pull)).not.toBeNull(); | |
| 306 | }); | |
| 307 | ||
| 308 | test("a pull that conflicts is not offered the card", async () => { | |
| 309 | spendCredit(); | |
| 310 | const pull = await pullWith("ok"); | |
| 311 | const moved = await commitToBranch(app, alice, repo, { branch: "main", message: "Clash", files: [{ path: `F${n}.md`, content: "other\n" }] }); | |
| 312 | if (!moved.ok) throw new Error(JSON.stringify(moved.error)); | |
| 313 | const page = await get(`/alice/garden/pulls/${pull.number}`); | |
| 314 | expect(page).toContain("Conflicts with main"); | |
| 315 | expect(page).not.toContain("data-land-as-is"); | |
| 316 | }); | |
| 317 | ||
| 318 | test("the terminal lands a reviewer-held pull for the admin, under the same label", async () => { | |
| 319 | spendCredit(); | |
| 320 | const pull = await askedChanges(); | |
| 321 | // The land runs detached and ends in a toast: wait on that, not on a timer. | |
| 322 | let toasted!: () => void; | |
| 323 | const landed = new Promise<void>((r) => (toasted = r)); | |
| 324 | const ctx = { push() {}, toast: () => toasted(), invalidate() {}, theme: {} } as any; | |
| 325 | const screen = landScreen({ app, user: alice } as any, ctx, repo); | |
| 326 | expect(screen.title).toContain(LAND_AS_IS); | |
| 327 | expect(landable(app, alice, repo).map((p) => p.number)).toContain(pull.number); | |
| 328 | // Rows are in listing order: move to the pull, then Enter. | |
| 329 | const rows = landable(app, alice, repo); | |
| 330 | for (let i = 0; i < rows.findIndex((p) => p.id === pull.id); i++) screen.key({ key: "j", ctrl: false, alt: false } as any); | |
| 331 | screen.key({ key: "enter", ctrl: false, alt: false } as any); | |
| 332 | await landed; | |
| 333 | expect(mergedAt(pull)).not.toBeNull(); | |
| 334 | }); | |
| 335 | ||
| 336 | test("before the credit runs out the app page says about one more change is left", async () => { | |
| 337 | writeFileSync(join(dataDir, "parent.json"), JSON.stringify({ credit: { token: "bearer-token-123", capUsd: 2, spentUsd: 1.5 } })); | |
| 338 | expect(await get("/alice/garden")).toContain("About one more change left"); | |
| 339 | writeFileSync(join(dataDir, "parent.json"), JSON.stringify({ credit: { token: "bearer-token-123", capUsd: 2, spentUsd: 0.2 } })); | |
| 340 | expect(await get("/alice/garden")).not.toContain("About one more change left"); | |
| 341 | }); | |
| 238 | 342 | }); |
new above
offline
Overrides a reviewer for any writer; restrict to the owner as the comment claims, and test it.