Public: anyone can read this; the crew can change it.

The in-place form list shrinks: the first twelve entries of test/in-place-offenders.json submit in place and leave the list #18530

opened this

Merged 2h 23m ago, live in production

scout/forge:scout/18523-the-in-place-form-list-shrinks-the-first → main 0 commits fork

  • Merged. scout/18523-the-in-place-form-list-shrinks-the-first was merged into main as a7cf471.

Review

Sign in to review this change.
57 files changed +443 −148
docs/design/size-budget/board.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/board",
3 "js": 30976,
3 "js": 31744,
44 "css": 53248
55 }
docs/design/size-budget/changelog.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/changelog",
3 "js": 31744,
3 "js": 32512,
44 "css": 53248
55 }
docs/design/size-budget/claim.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/claim",
3 "js": 29184,
3 "js": 29952,
44 "css": 53248
55 }
docs/design/size-budget/explore.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/explore",
3 "js": 26112,
3 "js": 26880,
44 "css": 53248
55 }
docs/design/size-budget/feed.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/feed",
3 "js": 41216,
3 "js": 41984,
44 "css": 53248
55 }
docs/design/size-budget/fleet.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/fleet",
3 "js": 26112,
3 "js": 26880,
44 "css": 53248
55 }
docs/design/size-budget/forges-new.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/forges/new",
3 "js": 26112,
3 "js": 26880,
44 "css": 53248
55 }
docs/design/size-budget/home.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/",
3 "js": 26368,
3 "js": 27136,
44 "css": 53248
55 }
docs/design/size-budget/maintenance.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/maintenance",
3 "js": 26112,
3 "js": 26880,
44 "css": 53248
55 }
docs/design/size-budget/map.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/map",
3 "js": 33792,
3 "js": 34304,
44 "css": 55040
55 }
docs/design/size-budget/owner-name-next.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/:owner/:name/next",
3 "js": 28160,
3 "js": 28928,
44 "css": 53504
55 }
docs/design/size-budget/owner-name-pulls-number.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/:owner/:name/pulls/:number",
3 "js": 36608,
3 "js": 37376,
44 "css": 53248
55 }
docs/design/size-budget/owner-name-space.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/:owner/:name/space",
3 "js": 35072,
3 "js": 35840,
44 "css": 54528
55 }
docs/design/size-budget/owner-name.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/:owner/:name",
3 "js": 43264,
3 "js": 44032,
44 "css": 53248
55 }
docs/design/size-budget/pricing.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/pricing",
3 "js": 26112,
3 "js": 26880,
44 "css": 53248
55 }
docs/design/size-budget/system.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/system",
3 "js": 28160,
3 "js": 28672,
44 "css": 53248
55 }
docs/design/size-budget/talk.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/talk",
3 "js": 44800,
3 "js": 45568,
44 "css": 60160
55 }
docs/design/size-budget/templates.json +1 −1
@@ -1,5 +1,5 @@
11 {
22 "page": "/templates",
3 "js": 26112,
3 "js": 26880,
44 "css": 53248
55 }
src/http/games_routes.ts +2 −1
@@ -34,7 +34,7 @@ import { gameSparkView } from "../web/pages/games_spark_view.ts";
3434 import { gameSparkLink, gameSparkOpen, gameSparkPost, gameSparkRead } from "../web/pages/games_spark.ts";
3535 import { gameConfigCommit, gameConfigPage, gameConfigPreview } from "../web/pages/games_config.ts";
3636 import { gameDoorOptions, gameDoorSubmit } from "../web/pages/games_door.ts";
37 import { gameCycleSubmit, gameLiveStream } from "../web/games_machine.ts";
37 import { gameCycleFragment, gameCycleSubmit, gameLiveStream } from "../web/games_machine.ts";
3838 import { publicOrigin } from "../core/public_origin.ts";
3939 import type { Ctx, Handler } from "./context.ts";
4040 import { InvalidJson } from "./json_body.ts";
@@ -200,6 +200,7 @@ export function gamesRoutes(router: Router<Handler>): void {
200200 router.add("GET", "/games/:box/@shell/stream", gameShellStream);
201201 router.add("GET", "/games/:box/@live", gameLiveStream);
202202 router.add("POST", "/games/:box/@cycle", gameCycleSubmit);
203 router.add("GET", "/games/:box/@cycle", gameCycleFragment);
203204 router.add("POST", "/games/:box/@spark", gameSparkLink);
204205 router.add("GET", "/games/:box/@spark/:key", gameSparkOpen);
205206 router.add("GET", "/games/:box/spark/:key", gameSparkView);
src/http/lazy_lists.ts +5
@@ -234,6 +234,7 @@ export const SETTINGS_ROUTES = [
234234 ["POST", "/settings/origins/token"],
235235 ["POST", "/settings/origins/oauth"],
236236 ["POST", "/settings/origins/reach"],
237 ["GET", "/settings/origins/reach"],
237238 ["POST", "/settings/origins/reach/dismiss"],
238239 ["POST", "/settings/origins/apps"],
239240 ["POST", "/settings/origins/trusted-hosts"],
@@ -250,6 +251,7 @@ export const SETTINGS_ROUTES = [
250251 ["POST", "/settings/origins/:id/check"],
251252 ["POST", "/settings/origins/:id/delete"],
252253 ["POST", "/settings/origins/:id/token"],
254 ["GET", "/settings/origins/:id/connection"],
253255 ["GET", "/settings/keys"],
254256 ["POST", "/settings/keys"],
255257 ["POST", "/settings/keys/:id/delete"],
@@ -676,6 +678,7 @@ export const OPERATIONS_ROUTES = [
676678 ["GET", "/games/:box/@shell/stream"],
677679 ["GET", "/games/:box/@live"],
678680 ["POST", "/games/:box/@cycle"],
681 ["GET", "/games/:box/@cycle"],
679682 ["POST", "/games/:box/@spark"],
680683 ["GET", "/games/:box/@spark/:key"],
681684 ["GET", "/games/:box/spark/:key"],
@@ -722,6 +725,7 @@ export const OPERATIONS_ROUTES = [
722725 ["GET", "/resilience/nightly/:job"],
723726 ["GET", "/fleet"],
724727 ["POST", "/fleet"],
728 ["GET", "/fleet/result"],
725729 ["GET", "/fleet/ops/:id"],
726730 ["POST", "/fleet/ops/:id/undo"],
727731 ["GET", "/forks/flows"],
@@ -1104,6 +1108,7 @@ export const REPO_SETTINGS_ROUTES = [
11041108 ["POST", "/:owner/:name/wallet"],
11051109 ["GET", "/:owner/:name/settings/crew"],
11061110 ["GET", "/:owner/:name/settings/crew/seat/:role"],
1111 ["GET", "/:owner/:name/settings/crew/line"],
11071112 ["POST", "/:owner/:name/settings/crew"],
11081113 ["POST", "/:owner/:name/settings/crew/subscriptions"],
11091114 ["POST", "/:owner/:name/settings/crew/:username/remove"],
src/http/marks/settings.json +1
@@ -205,6 +205,7 @@
205205 "/settings/origins/:id/check": "open",
206206 "/settings/origins/:id/delete": "open",
207207 "/settings/origins/:id/token": "open",
208 "/settings/origins/:id/connection": "open",
208209 "/settings/keys": "open",
209210 "/settings/keys/:id/delete": "open"
210211 }
src/http/routes/operations.ts +2 −1
@@ -13,7 +13,7 @@ import { brokerStart } from "../../spawn/origin_broker.ts";
1313 import { clientCloudAttach, clientCloudEnd, clientCloudGrant, clientCloudPage, clientCloudsPage } from "../../web/pages/client_cloud.ts";
1414 import { cloudConnectPage, cloudConnectProvider, cloudConnectSubmit, cloudConnectBuild } from "../../web/pages/cloud.ts";
1515 import { fleetGraphPage, fleetGraphLive, fleetGraphCsv } from "../../web/pages/fleet-graph.ts";
16 import { fleetAct, fleetReceipt, fleetUndo } from "../../web/pages/fleet-ops.ts";
16 import { fleetAct, fleetReceipt, fleetResult, fleetUndo } from "../../web/pages/fleet-ops.ts";
1717 import { fleetPage } from "../../web/pages/fleet.ts";
1818 import { forkFlowsPage } from "../../web/pages/fork-flows.ts";
1919 import { maintenanceBudget } from "../../web/pages/maintenance_budgets.ts";
@@ -96,6 +96,7 @@ export function operationsRoutes(router: Router<Handler>, knownPatterns: () => s
9696 // A selection's spend and runs over time; literal, above /:owner.
9797 router.add("GET", "/fleet", fleetPage);
9898 router.add("POST", "/fleet", fleetAct);
99 router.add("GET", "/fleet/result", fleetResult);
99100 router.add("GET", "/fleet/ops/:id", fleetReceipt);
100101 router.add("POST", "/fleet/ops/:id/undo", fleetUndo);
101102 router.add("GET", "/forks/flows", forkFlowsPage);
src/http/routes/repo_settings.ts +2 −1
@@ -16,7 +16,7 @@ import { proposalTokenMint, proposalTokenRevoke, contributeOpenSet, reportsOpenS
1616 import { reportKeyMake, reportKeyRevoke } from "../../web/pages/report_key.ts";
1717 import { readGrantAdd, readGrantRevoke } from "../../web/pages/read-grants.ts";
1818 import { repoSyncSubmit, repoTakeSubmit, pinSubmit } from "../../web/pages/repo.ts";
19 import { settingsPage, settingsUpdate, waveCut, archiveSubmit, archiveConfirmed, restoreConfirmed, renameSubmit, transferSubmit, provenanceSubmit, mirrorStop, appSettingsPage, appSettingsUpdate, appDisable, appMembersUpdate, appEnvSet, appEnvDelete, appDomainAdd, appDomainCheck, appDomainDelete, appEgressGrant, appEgressRevoke, appBlocked, autonomySettingsPage, autonomySettingsUpdate, crewCeilingRaise, checkSlotsUpdate, accountOrderSave } from "../../web/pages/settings.ts";
19 import { settingsPage, settingsUpdate, waveCut, archiveSubmit, archiveConfirmed, restoreConfirmed, renameSubmit, transferSubmit, provenanceSubmit, mirrorStop, appSettingsPage, appSettingsUpdate, appDisable, appMembersUpdate, appEnvSet, appEnvDelete, appDomainAdd, appDomainCheck, appDomainDelete, appEgressGrant, appEgressRevoke, appBlocked, autonomySettingsPage, autonomySettingsUpdate, crewCeilingRaise, crewLineFragment, checkSlotsUpdate, accountOrderSave } from "../../web/pages/settings.ts";
2020 import { appSourcesPage } from "../../web/pages/sources.ts";
2121 import { statementPage, statementCsvDownload } from "../../web/pages/statement.ts";
2222 import { walletPage, walletCsvDownload, walletSave } from "../../web/pages/wallet.ts";
@@ -135,6 +135,7 @@ export function repoSettingsRoutes(router: Router<Handler>): void {
135135 router.add("POST", "/:owner/:name/wallet", walletSave);
136136 router.add("GET", "/:owner/:name/settings/crew", crewSettingsPage);
137137 router.add("GET", "/:owner/:name/settings/crew/seat/:role", crewSeatFragment);
138 router.add("GET", "/:owner/:name/settings/crew/line", crewLineFragment);
138139 router.add("POST", "/:owner/:name/settings/crew", crewAdd);
139140 router.add(
140141 "POST",
src/http/settings_routes.ts +4 −1
@@ -145,7 +145,7 @@ import {
145145 } from "../web/pages/account.ts";
146146 import { grantRevoke, grantsPage } from "../web/pages/grants.ts";
147147 import { completeBrokeredCallback, completeOAuthCallback } from "../actions/origins.ts";
148 import { originReachAsk, originReachDismiss } from "../web/pages/origin-reach.ts";
148 import { originReachAsk, originReachDismiss, originReachFragment } from "../web/pages/origin-reach.ts";
149149 import { hostedForgesPage, reachAdd, reachRemove, reachSwitch } from "../web/pages/hosted-forges.ts";
150150 import { brokerCallback } from "../spawn/origin_broker.ts";
151151 import { BROKER_CALLBACK } from "../spawn/origin_broker_wire.ts";
@@ -161,6 +161,7 @@ import {
161161 originSyncSubmit,
162162 originsPage,
163163 originReplaceToken,
164 originConnectionFragment,
164165 originTrustedHosts,
165166 } from "../web/pages/origins.ts";
166167 import { originArchivedPage, originArchivedRestore } from "../web/pages/origin-archived.ts";
@@ -449,6 +450,7 @@ export function settingsRoutes(router: Router<Handler>, knownPatterns: () => rea
449450 // A hosted forge asks its host to let it reach one more name (`web/pages/origin-reach.ts`); how
450451 // the asks stand is read from the API.
451452 router.add("POST", "/settings/origins/reach", originReachAsk);
453 router.add("GET", "/settings/origins/reach", originReachFragment);
452454 router.add("POST", "/settings/origins/reach/dismiss", originReachDismiss);
453455 router.add("POST", "/settings/origins/apps", originAppCreate);
454456 router.add("POST", "/settings/origins/trusted-hosts", originTrustedHosts);
@@ -469,6 +471,7 @@ export function settingsRoutes(router: Router<Handler>, knownPatterns: () => rea
469471 router.add("POST", "/settings/origins/:id/check", originCheckSubmit);
470472 router.add("POST", "/settings/origins/:id/delete", originDisconnect);
471473 router.add("POST", "/settings/origins/:id/token", originReplaceToken);
474 router.add("GET", "/settings/origins/:id/connection", originConnectionFragment);
472475 router.add("GET", "/settings/keys", keysPage);
473476 router.add("POST", "/settings/keys", keyCreate);
474477 router.add("POST", "/settings/keys/:id/delete", keyDelete);
src/web/blocked.ts +2 −2
@@ -33,7 +33,7 @@ export const ASK_FORM_ID = "ask-who-can";
3333 * (`askButton`), inside a paragraph or another form alike.
3434 */
3535 export function askFormShell(back: string): Html {
36 return html`<form method="post" action="${ASK_ADMIN_FORM}" id="${ASK_FORM_ID}" hidden><input type="hidden" name="back" value="${back}" /></form>`;
36 return html`<form method="post" action="${ASK_ADMIN_FORM}" id="${ASK_FORM_ID}" data-in-place hidden><input type="hidden" name="back" value="${back}" /></form>`;
3737 }
3838
3939 /** What the button carries: the want, then its subject. */
@@ -51,7 +51,7 @@ export function askButton(ask: { readonly value: string; readonly label: string
5151 function formFor(ask: AskAction, o: { readonly ask?: string }, variant: "primary" | "outline"): Html | null {
5252 if (ask.path === ASK_ADMIN_PATH) return askButton({ value: askValue(ask.body), label: ask.label }, variant);
5353 if (o.ask === undefined) return null;
54 return html`<form method="post" action="${o.ask}">${hiddenFields(ask.body)}${btn(ask.label, { size: "sm", variant })}</form>`;
54 return html`<form method="post" action="${o.ask}" data-in-place>${hiddenFields(ask.body)}${btn(ask.label, { size: "sm", variant })}</form>`;
5555 }
5656
5757 export function blockedNote(
src/web/chrome.ts +3 −3
@@ -398,13 +398,13 @@ export function scopeHeader(
398398 * What the crew is doing here, for a repository's admins: the notice when it is stopped, the one
399399 * fix beside it.
400400 */
401 function crewStopLine(ctx: Ctx, repo: Repo, base: string): Html {
401 export function crewStopLine(ctx: Ctx, repo: Repo, base: string): Html {
402402 const w = stopWords(autonomyStatus(ctx.app, repo));
403403 const raise =
404404 w.raiseTo !== undefined && mayRaiseCeiling(ctx.app, ctx.auth.user)
405 ? html` <form method="post" action="${base}/settings/autonomy/raise" class="inline"><input type="hidden" name="to" value="${w.raiseTo}"><button type="submit">Raise to $${w.raiseTo}</button></form>`
405 ? html` <form method="post" action="${base}/settings/autonomy/raise" class="inline" data-in-place><input type="hidden" name="to" value="${w.raiseTo}"><button type="submit">Raise to $${w.raiseTo}</button></form>`
406406 : null;
407 return html`<p class="${w.stopped ? "small" : "muted small"}" data-crew-line role="status">${w.words}${w.fix === null ? null : html` <a href="${base}/settings/autonomy">${w.fix}</a>`}${raise}</p>`;
407 return html`<p class="${w.stopped ? "small" : "muted small"}" data-crew-line data-fragment="${base}/settings/crew/line" role="status">${w.words}${w.fix === null ? null : html` <a href="${base}/settings/autonomy">${w.fix}</a>`}${raise}</p>`;
408408 }
409409
410410 /** The siblings the viewer may read, and whether they own a node in `parent`'s tree to land on. */
src/web/client.ts +2 −1
@@ -16,6 +16,7 @@ import { whichAsset } from "./which_asset.ts";
1616 import { oldGo } from "./keymap.ts";
1717 import { keyDecisionJs } from "./key_decision.ts";
1818 import { actNowJs } from "./act_now.ts";
19 import { inPlaceJs } from "./in_place.ts";
1920 import { FORM_BUSY_JS } from "./form_busy.ts";
2021 import { pickJs } from "./pick.ts";
2122 import { foldJs } from "./fold.ts";
@@ -2448,7 +2449,7 @@ ${whichStubJs(whichAsset().path)}
24482449 `;
24492450
24502451 /** The shell and the one script that makes actions answer at once (`act_now.ts`). */
2451 export const shellJs = `${shellCore}\n${actNowJs}\n${pickJs}\n${foldJs}\n${FORM_BUSY_JS}\n${liveTimeJs}\n${peekJs}`;
2452 export const shellJs = `${shellCore}\n${actNowJs}\n${inPlaceJs}\n${pickJs}\n${foldJs}\n${FORM_BUSY_JS}\n${liveTimeJs}\n${peekJs}`;
24522453
24532454 /**
24542455 * Live regions. A page marks the parts of itself that change while it is
src/web/fleet-act.ts +6 −3
@@ -40,7 +40,7 @@ export function actForm(kind: FleetKind, q: string, chosen = "", value = "", tot
4040 return html`<p class="muted small" data-scope>
4141 Acts on all ${total} matching ${total === 1 ? "row" : "rows"}, or only on the rows you tick.
4242 </p>
43 <form method="post" action="/fleet" class="field-row mb" id="${ACT_FORM}" data-act>
43 <form method="post" action="/fleet" class="field-row mb" id="${ACT_FORM}" data-act data-in-place>
4444 <input type="hidden" name="q" value="${q}" />
4545 <input type="hidden" name="step" value="preview" />
4646 ${selectField({
@@ -109,7 +109,7 @@ export function previewSection(
109109 ${lines(plan.rows)}
110110 ${change === 0
111111 ? emptyNote("nothingToApply")
112 : html`<form method="post" action="/fleet" class="form-actions">
112 : html`<form method="post" action="/fleet" class="form-actions" data-in-place>
113113 <input type="hidden" name="q" value="${plan.query}" />
114114 <input type="hidden" name="step" value="apply" />
115115 <input type="hidden" name="verb" value="${plan.verb}" />
@@ -121,6 +121,9 @@ export function previewSection(
121121 </section>`;
122122 }
123123
124 /** The panel under the form, which a fleet step acting in place redraws (`GET /fleet/result`). */
125 export const resultSlot = (inner: Html | null): Html => html`<div data-fragment="/fleet/result">${inner}</div>`;
126
124127 /** Whether an Undo is still offered for a receipt. */
125128 export const undoable = (op: Operation, now = Date.now()): boolean =>
126129 op.reversible &&
@@ -136,7 +139,7 @@ export function receiptSection(op: Operation, canUndo: boolean): Html {
136139 ${op.undoneBy === null ? null : html`<p class="muted">This was undone.</p>`}
137140 ${lines(op.rows)}
138141 ${canUndo
139 ? html`<form method="post" action="/fleet/ops/${op.id}/undo" class="form-actions">
142 ? html`<form method="post" action="/fleet/ops/${op.id}/undo" class="form-actions" data-in-place>
140143 ${btn("Undo", { type: "submit", variant: "outline" })}
141144 </form>`
142145 : null}
src/web/flow_button.ts +1 −1
@@ -11,7 +11,7 @@ const ON = "Adds the flow label: it goes ahead of other ready work";
1111 const OFF = "Takes the flow label off: it no longer goes ahead of other ready work";
1212
1313 export function flowButton(action: string, first: boolean, back: string): Html {
14 return html`<form method="post" action="${action}" class="inline" title="${first ? OFF : ON}" data-now="${first ? "Flow first" : "Not first"}" data-now-alt="${first ? "Not first" : "Flow first"}" data-now-flip="flow">
14 return html`<form method="post" action="${action}" class="inline" title="${first ? OFF : ON}" data-now="${first ? "Flow first" : "Not first"}" data-now-alt="${first ? "Not first" : "Flow first"}" data-now-flip="flow" data-in-place>
1515 <input type="hidden" name="flow" value="${first ? "0" : "1"}" />
1616 <input type="hidden" name="back" value="${back}" />
1717 ${btn(first ? "Not first" : "Flow first", { size: "sm", variant: "outline" })}
src/web/games_machine.ts +20 −7
@@ -15,7 +15,7 @@ import { boxNamed, mayDo, roleOn, seesBox, type GameBox } from "../games/store.t
1515 import { notFoundPage } from "./chrome.ts";
1616 import { field, readForm } from "./form.ts";
1717 import { html, type Html } from "./html.ts";
18 import { flashTo } from "./layout.ts";
18 import { flashOrJson, fragment } from "./layout.ts";
1919 import { boxOf } from "./pages/games.ts";
2020 import { btn, row, rowList } from "./ui.ts";
2121
@@ -77,17 +77,17 @@ export function gameLiveStream(ctx: Ctx): Response {
7777 }
7878
7979 /** The owner's power cycle: a link to its plan, or the plan with its confirm. */
80 export function cycleBlock(ctx: Ctx, box: GameBox, asked: boolean): Html {
80 export function cycleBlock(ctx: Ctx, box: GameBox, asked: boolean, done = false): Html {
8181 const planned = planCycle(ctx.app, ctx.auth.user, box);
8282 if (!planned.ok) return html``;
8383 const p = planned.value;
8484 if (!asked)
85 return html`<section class="settings-block" id="cycle"><h2>Machine</h2>
86 ${btn("Plan a power cycle", { href: `/games/${box.name}?cycle=1#cycle`, size: "sm", variant: "secondary" })}</section>`;
87 return html`<section class="settings-block" id="cycle"><h2>Power cycle ${p.machine}</h2>
85 return html`<section class="settings-block" id="cycle" data-fragment="/games/${box.name}/@cycle"><h2>Machine</h2>
86 ${done ? html`<p role="status" data-cycle-done>Power cycle sent. Plan another when you need one.</p>` : null}${btn("Plan a power cycle", { href: `/games/${box.name}?cycle=1#cycle`, size: "sm", variant: "secondary" })}</section>`;
87 return html`<section class="settings-block" id="cycle" data-fragment="/games/${box.name}/@cycle"><h2>Power cycle ${p.machine}</h2>
8888 <dl class="status-rows">${p.lines.map((l) => html`<div data-cycle-line><dt>${l.slice(0, l.indexOf(": "))}</dt><dd>${l.slice(l.indexOf(": ") + 2)}</dd></div>`)}</dl>
8989 ${p.refusal === ""
90 ? html`<form method="post" action="/games/${box.name}/@cycle">
90 ? html`<form method="post" action="/games/${box.name}/@cycle" data-in-place>
9191 <input type="hidden" name="digest" value="${p.digest}" />
9292 ${btn("Power cycle now", { variant: "primary", title: "Hard power off and on; the plan above is what it does" })}
9393 </form>`
@@ -103,5 +103,18 @@ export async function gameCycleSubmit(ctx: Ctx): Promise<Response> {
103103 const form = await readForm(ctx, "rw");
104104 if (form instanceof Response) return form;
105105 const done = await performCycle(ctx.app, ctx.auth.user, got.box, field(form, "digest"));
106 return flashTo(ctx, `/games/${got.box.name}`, done.ok ? { message: done.value } : { tone: "danger", message: done.error });
106 return flashOrJson(
107 ctx,
108 `/games/${got.box.name}`,
109 done.ok ? { message: done.value } : { tone: "danger", message: done.error },
110 { redraw: [`/games/${got.box.name}/@cycle?done=1`] },
111 );
112 }
113
114 // GET /games/:box/@cycle: the machine block alone, folded back to its button (`?done=1` says it was
115 // sent).
116 export function gameCycleFragment(ctx: Ctx): Response {
117 const got = boxOf(ctx, "owner");
118 if (got instanceof Response) return fragment(html``, { status: 404 });
119 return fragment(cycleBlock(ctx, got.box, false, ctx.url.searchParams.get("done") === "1"), { request: ctx.request });
107120 }
src/web/in_place.ts +20 −15
@@ -3,16 +3,19 @@
33 * asking for JSON, then redraws only what the server says changed: its
44 * answer lists `redraw` URLs, each fetched as the same server-rendered
55 * fragment the page was built from and swapped for the element carrying
6 * `data-fragment` with that URL. Scroll never moves and the focused control
7 * is found again by id. A refusal (422, `{ok:false, error}`) is written
8 * beside the form, never on a new page. A form that also has `data-team`
9 * posts when its select or number changes, and its button hides.
6 * `data-fragment` with that URL; an answer that carries `html` (one string per
7 * `redraw` URL) hands the markup itself, so a long selection never rides a URL.
8 * A redraw that fails is said beside the form, never silent. Scroll never moves and the focused
9 * control is found again by id. A refusal (422, `{ok:false, error}`) is written beside the form,
10 * never on a new page; so is a plain `flash` when nothing needs redrawing. A fragment is matched by
11 * its URL's path, so a slot named `/fleet/result` takes `/fleet/result?op=7`. A form that also has
12 * `data-team` posts when its select or number changes, and its button hides.
1013 *
1114 * No state lives here: the page stays what the server drew. Without script
1215 * the form posts and redirects as it always did. `IN_PLACE_BUDGET` is the
1316 * gzipped byte budget, held by `test/crew-in-place.test.ts`.
1417 */
15 export const IN_PLACE_BUDGET = 1000;
18 export const IN_PLACE_BUDGET = 1200;
1619
1720 export const inPlaceJs = /* js */ `
1821 (function () {
@@ -21,18 +24,19 @@ export const inPlaceJs = /* js */ `
2124 hide(D);
2225 D.addEventListener('change', function (e) {
2326 var t = e.target, f = t.form;
24 if (f && f.hasAttribute('data-team') && (t.tagName === 'SELECT' || t.type === 'number')) f.requestSubmit();
27 if (f && f.hasAttribute('data-team') && (t.tagName === 'SELECT' || t.type === 'number')) f.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
2528 });
26 function swap(url) {
27 return fetch(url, { credentials: 'same-origin', headers: { accept: 'text/html' } }).then(function (r) {
29 function wipe(f) { f.querySelectorAll('input[type=password]').forEach(function (v) { v.value = ''; }); }
30 function swap(url, given) {
31 return (given != null ? Promise.resolve(given) : fetch(url, { credentials: 'same-origin', headers: { accept: 'text/html' } }).then(function (r) {
2832 if (!r.ok) throw 0;
2933 return r.text();
30 }).then(function (h) {
34 })).then(function (h) {
3135 var t = D.createElement('template'), n;
3236 t.innerHTML = h;
3337 n = t.content.firstElementChild;
3438 D.querySelectorAll('[data-fragment]').forEach(function (o) {
35 if (o.getAttribute('data-fragment') === url && n) { o.replaceWith(n); hide(n); }
39 if (o.getAttribute('data-fragment').split('?')[0] === url.split('?')[0] && n) { o.replaceWith(n); hide(n); }
3640 });
3741 });
3842 }
@@ -43,18 +47,19 @@ export const inPlaceJs = /* js */ `
4347 if (f.__ip) return;
4448 f.__ip = 1;
4549 var id = D.activeElement && D.activeElement.id, say = f.__say;
46 if (!say) { say = f.__say = D.createElement('p'); say.className = 'small'; say.setAttribute('role', 'alert'); f.insertAdjacentElement('afterend', say); }
47 function fail(t) { f.__ip = 0; say.textContent = t; }
50 if (!say) { say = f.__say = D.createElement('p'); say.className = 'small'; say.setAttribute('role', 'alert'); (e.submitter && !f.contains(e.submitter) ? e.submitter : f).insertAdjacentElement('afterend', say); }
51 function fail(t) { f.__ip = 0; say.textContent = t; wipe(f); }
4852 fetch(f.action, { method: 'POST', body: new URLSearchParams(new FormData(f)), credentials: 'same-origin', headers: { accept: 'application/json' } })
4953 .then(function (r) {
5054 return r.json().catch(function () { return {}; }).then(function (j) {
5155 if (!r.ok || j.ok === false) return fail(j.error || 'That did not go through (' + r.status + '). Nothing changed.');
52 say.textContent = '';
56 say.textContent = j.flash || '';
57 wipe(f);
5358 f.__ip = 0;
54 return Promise.all((j.redraw || []).map(swap)).then(function () {
59 return Promise.all((j.redraw || []).map(function (u, i) { return swap(u, (j.html || [])[i]); })).then(function () {
5560 var k = id && D.getElementById(id);
5661 if (k) k.focus({ preventScroll: true });
57 });
62 }, function () { say.textContent = 'Done, but the page could not redraw it. Reload to see it.'; });
5863 });
5964 })
6065 .catch(function () { location.reload(); });
src/web/layout.ts +1 −1
@@ -260,7 +260,7 @@ function themeRow(active: ThemeName | undefined): Html {
260260 html`<option value="${value}" ${on ? "selected" : ""}>${label}</option>`;
261261 const group = (label: string, appearance: "light" | "dark") =>
262262 html`<optgroup label="${label}">${THEME_NAMES.filter((n) => THEMES[n].appearance === appearance).map((n) => option(n, THEMES[n].label, active === n))}</optgroup>`;
263 return html`<form class="theme-form menu-row" method="post" action="/theme">
263 return html`<form class="theme-form menu-row" method="post" action="/theme" data-in-place>
264264 ${themeGlyph}<label for="menu-theme">Theme</label>
265265 <select class="input" id="menu-theme" name="theme" data-size="sm">${option("system", "Auto", active === undefined)}${group("Light", "light")}${group("Dark", "dark")}</select>
266266 <button class="btn" data-size="sm" data-nojs>Apply</button>
src/web/origin_connection.ts +2 −2
@@ -30,7 +30,7 @@ export function followsOf(db: Database, origin: Origin) {
3030
3131 export function connectionBlock(db: Database, origin: Origin): Html {
3232 const follows = followsOf(db, origin);
33 return html`<div class="small mt" data-connection-settings>
33 return html`<div class="small mt" data-connection-settings data-fragment="/settings/origins/${origin.id}/connection">
3434 <p>
3535 <strong>${hostOf(origin.webUrl)}</strong> · ${origin.webUrl}<br />
3636 ${origin.readOnly ? "May read only." : "May read and write."}
@@ -38,7 +38,7 @@ export function connectionBlock(db: Database, origin: Origin): Html {
3838 </p>
3939 ${when(origin.readOnly, () => html`<details>
4040 <summary>Allow writing</summary>
41 <form method="post" action="/settings/origins/${origin.id}/token">
41 <form method="post" action="/settings/origins/${origin.id}/token" data-in-place>
4242 <p>Paste a token that may write; it replaces this one in place and nothing disconnects.</p>
4343 <input type="hidden" name="write" value="1" />
4444 <input type="password" name="token" aria-label="Token that may write" autocomplete="off" required />
src/web/own_token.ts +5 −37
@@ -1,8 +1,9 @@
11 /**
22 * The box a person's held build offers where its wait is shown (#16490): "Start now with your own
33 * account", one masked field and one button, posting to the run's own address. Without
4 * script the form posts and comes back to the run with a flash; with it the box says what
5 * happened in place, and the run page's (or Talk's) live stream shows the build starting.
4 * script the form posts and comes back to the run with a flash; with it the shared in-place script
5 * (`in_place.ts`) says what happened beside the box, and the run page's (or Talk's) live stream
6 * shows the build starting.
67 */
78 import { startNowWithOwnToken, START_NOW_HEAD, START_NOW_LINE, START_NOW_WORDS } from "../actions/own_token.ts";
89 import type { Ctx } from "../http/context.ts";
@@ -20,7 +21,7 @@ import { btn } from "./ui.ts";
2021 */
2122 export function ownTokenBox(base: string, runId: string): Html {
2223 const id = `own-token-${runId}`;
23 return html`<form class="stack mt" method="post" action="${base}/runs/${runId}/own-token" data-own-token data-own-token-box aria-labelledby="${id}-h">
24 return html`<form class="stack mt" method="post" action="${base}/runs/${runId}/own-token" data-in-place data-own-token data-own-token-box aria-labelledby="${id}-h">
2425 <h2 class="h3" id="${id}-h">${START_NOW_HEAD}</h2>
2526 <p class="muted small">${START_NOW_LINE}</p>
2627 <label class="sr-only" for="${id}">Your token or API key</label>
@@ -28,42 +29,9 @@ export function ownTokenBox(base: string, runId: string): Html {
2829 <input class="input mono" id="${id}" name="token" type="password" autocomplete="off" autocapitalize="off" spellcheck="false" required placeholder="sk-ant-…" />
2930 ${btn("Start now", { variant: "primary" })}
3031 </span>
31 <p class="small" role="status" data-own-token-said></p>
3232 </form>`;
3333 }
3434
35 /** The box's script: it posts in place, says what happened, and keeps the token out of the page. */
36 export const ownTokenJs = /* js */ `
37 (function () {
38 document.addEventListener('submit', function (e) {
39 var form = e.target;
40 if (!form || !form.matches || !form.matches('form[data-own-token]') || !window.fetch) return;
41 e.preventDefault();
42 var said = form.querySelector('[data-own-token-said]');
43 var button = form.querySelector('button');
44 var field = form.querySelector('input[name=token]');
45 if (button) button.disabled = true;
46 if (said) said.textContent = 'Testing it…';
47 fetch(form.action, { method: 'POST', credentials: 'same-origin', headers: { accept: 'application/json' }, body: new FormData(form) })
48 .then(function (r) { return r.json().catch(function () { return { ok: false, said: 'Nothing was saved; try again.' }; }); })
49 .then(function (out) {
50 if (field) field.value = '';
51 if (out.ok) {
52 var box = form;
53 var done = document.createElement('p');
54 done.setAttribute('role', 'status');
55 done.textContent = out.said;
56 box.replaceWith(done);
57 return;
58 }
59 if (said) said.textContent = out.said;
60 if (button) button.disabled = false;
61 })
62 .catch(function () { if (said) said.textContent = 'That was not sent: no connection.'; if (button) button.disabled = false; });
63 });
64 })();
65 `;
66
6735 const STARTED = "Saved as your own account. Your build is starting on it now.";
6836
6937 /** POST /:owner/:name/runs/:id/own-token */
@@ -77,6 +45,6 @@ export async function runOwnToken(ctx: Ctx): Promise<Response> {
7745 if (run === undefined || run.repoId !== repo.id) return notFoundPage(ctx);
7846 const started = await startNowWithOwnToken(ctx.app, ctx.auth.user, run, field(form, "token"));
7947 const said = started.ok ? STARTED : START_NOW_WORDS[started.error];
80 if (prefersJson(ctx.request)) return json({ ok: started.ok, said }, started.ok ? 200 : 422);
48 if (prefersJson(ctx.request)) return started.ok ? json({ ok: true, flash: said }) : json({ ok: false, error: said }, 422);
8149 return flashTo(ctx, `${repoBase(repo)}/runs/${run.id}`, started.ok ? { message: said } : { tone: "danger", message: said });
8250 }
src/web/pages/fleet-ops.ts +42 −8
@@ -7,6 +7,7 @@
77 */
88
99 import { signedInPage } from "../../http/page_may.ts";
10 import { json } from "../../http/respond.ts";
1011 import {
1112 applyPreviewed,
1213 getFleetOp,
@@ -18,10 +19,10 @@ import { viewFleet } from "../../fleet/rows.ts";
1819 import { MAX_ROWS } from "../../fleet/selection.ts";
1920 import type { Ctx } from "../../http/context.ts";
2021 import { notFoundPage, signInFirst } from "../chrome.ts";
21 import { previewSection, receiptSection, undoable } from "../fleet-act.ts";
22 import { field, readForm, type Form } from "../form.ts";
22 import { previewSection, receiptSection, resultSlot, undoable } from "../fleet-act.ts";
23 import { field, prefersJson, readForm } from "../form.ts";
2324 import { html } from "../html.ts";
24 import { flashTo, page } from "../layout.ts";
25 import { flashOrJson, fragment, page } from "../layout.ts";
2526 import { canAct, renderFleet } from "./fleet.ts";
2627
2728 /** POST /fleet */
@@ -40,10 +41,13 @@ export async function fleetAct(ctx: Ctx): Promise<Response> {
4041 if (field(form, "step") === "apply") {
4142 const done = await applyPreviewed(ctx.app, ctx.auth.user, q, action, field(form, "digest").slice(0, 64), picked);
4243 if (!done.ok) return refusal(ctx, q, verb, text, done.error.message, picked);
43 return flashTo(ctx, `/fleet/ops/${done.value.id}`, { message: "Applied." });
44 return flashOrJson(ctx, `/fleet/ops/${done.value.id}`, { message: "Applied." }, { redraw: [resultUrl({ op: done.value.id })] });
4445 }
4546 const plan = previewFleetOp(ctx.app, ctx.auth.user, q, action, picked);
4647 if (!plan.ok) return refusal(ctx, q, verb, text, plan.error.message, picked);
48 // Acting in place: the preview is the dry run's fragment, read where the page's slot is.
49 // The markup rides in the answer: a long selection never has to fit in a URL.
50 if (prefersJson(ctx)) return json({ ok: true, redraw: [resultUrl({ q, verb, value: text }, picked)], html: [resultSlot(previewSection(plan.value, text, picked, matching(ctx, q))).text] });
4751 return renderFleet(ctx, q, {
4852 html: previewSection(plan.value, text, picked, matching(ctx, q)),
4953 verb,
@@ -59,7 +63,7 @@ const ID = /^[0-9A-Za-z_-]{1,64}$/;
5963 * there are more than a selection can hold. Whether each is in the
6064 * selection is `pickWithin`'s to decide, so nothing here widens it.
6165 */
62 export function picksOf(form: Form): string[] | undefined {
66 export function picksOf(form: { getAll(name: string): readonly unknown[] }): string[] | undefined {
6367 const all = form.getAll("pick");
6468 if (all.length > MAX_ROWS) return undefined;
6569 const ids = new Set<string>();
@@ -81,6 +85,7 @@ function refusal(
8185 message: string,
8286 picked: readonly string[],
8387 ): Response {
88 if (prefersJson(ctx)) return json({ ok: false, error: message }, 422);
8489 return renderFleet(ctx, q, {
8590 html: html`<p class="muted" data-refused>${message}</p>`,
8691 verb,
@@ -101,7 +106,7 @@ export function fleetReceipt(ctx: Ctx): Response {
101106 wide: true,
102107 body: html`<div class="page-head"><h1>Fleet result</h1>
103108 <p class="muted"><code>${op.query}</code></p></div>
104 ${receiptSection(op, canAct(ctx) && undoable(op))}
109 ${resultSlot(receiptSection(op, canAct(ctx) && undoable(op)))}
105110 <p><a href="/fleet?${new URLSearchParams({ q: op.query }).toString()}">Back to the rows</a></p>`,
106111 });
107112 }
@@ -115,9 +120,38 @@ export async function fleetUndo(ctx: Ctx): Promise<Response> {
115120 const id = ctx.params.id ?? "";
116121 const undone = await undoFleetOp(ctx.app, ctx.auth.user, id);
117122 if (!undone.ok)
118 return flashTo(ctx, `/fleet/ops/${encodeURIComponent(id)}`, {
123 return flashOrJson(ctx, `/fleet/ops/${encodeURIComponent(id)}`, {
119124 tone: "danger",
120125 message: undone.error.message,
121126 });
122 return flashTo(ctx, `/fleet/ops/${undone.value.id}`, { message: "Undone." });
127 return flashOrJson(ctx, `/fleet/ops/${undone.value.id}`, { message: "Undone." }, { redraw: [resultUrl({ op: undone.value.id })] });
128 }
129
130 /** Where the answer panel is read: a receipt (`op`), or the dry run of a verb over a query line. */
131 const resultUrl = (params: Record<string, string>, picked: readonly string[] = []): string => {
132 const q = new URLSearchParams(params);
133 for (const id of picked) q.append("pick", id);
134 return `/fleet/result?${q.toString()}`;
135 };
136
137 /**
138 * GET /fleet/result: the panel under the form alone, as the page draws it: the receipt of `op`, or
139 * the preview of `verb` and `value` over `q`. Read-only: a preview writes nothing.
140 */
141 export function fleetResult(ctx: Ctx): Response {
142 const gone = () => fragment(html``, { status: 404 });
143 if (!signedInPage(ctx) || !canAct(ctx)) return gone();
144 const p = ctx.url.searchParams;
145 const opId = p.get("op");
146 if (opId !== null) {
147 const found = getFleetOp(ctx.app, ctx.auth.user, opId.slice(0, 64));
148 return found.ok ? fragment(resultSlot(receiptSection(found.value, undoable(found.value))), { request: ctx.request }) : gone();
149 }
150 const q = (p.get("q") ?? "").slice(0, 2000);
151 const verb = (p.get("verb") ?? "").slice(0, 40);
152 const text = (p.get("value") ?? "").slice(0, 2000);
153 const picked = picksOf(p);
154 if (picked === undefined) return gone();
155 const plan = previewFleetOp(ctx.app, ctx.auth.user, q, actionOf(ctx.app, verb, text), picked);
156 return plan.ok ? fragment(resultSlot(previewSection(plan.value, text, picked, matching(ctx, q))), { request: ctx.request }) : gone();
123157 }
src/web/pages/fleet.ts +2 −2
@@ -12,7 +12,7 @@ import { viewFleet, type FleetView } from "../../fleet/rows.ts";
1212 import { fieldsOf, GRAMMAR, GRAMMAR_EXAMPLES, FLEET_KINDS, MAX_ROWS } from "../../fleet/selection.ts";
1313 import type { Ctx } from "../../http/context.ts";
1414 import { fleetTable } from "../fleet-table.ts";
15 import { actForm } from "../fleet-act.ts";
15 import { actForm, resultSlot } from "../fleet-act.ts";
1616 import { html, type Html } from "../html.ts";
1717 import { page } from "../layout.ts";
1818 import { btn, field } from "../ui.ts";
@@ -80,7 +80,7 @@ export function renderFleet(
8080 ? null
8181 : fleetTable(shown.kind, q, shown.rows, sort, acting ? new Set(below?.picked ?? []) : undefined)}
8282 ${acting ? actForm(shown.kind, q, below?.verb, below?.value, shown.rows.length) : null}`}
83 ${below?.html ?? null}`,
83 ${resultSlot(below?.html ?? null)}`,
8484 });
8585 notePhase(ctx.request, "render", performance.now() - rendering);
8686 return response;
src/web/pages/origin-reach.ts +12 −4
@@ -27,7 +27,7 @@ import { blockedNote } from "../blocked.ts";
2727 import { signInFirst } from "../chrome.ts";
2828 import { field, readForm } from "../form.ts";
2929 import { html, type Html } from "../html.ts";
30 import { flashTo } from "../layout.ts";
30 import { flashOrJson, flashTo, fragment } from "../layout.ts";
3131 import { badge, btn, row } from "../ui.ts";
3232
3333 export { agoWords } from "../../kernel/ago.ts";
@@ -130,6 +130,7 @@ export function reachBlock(ctx: Ctx, blocked?: Blocked): Html | null {
130130 const waits = open.some((a) => a.state === "unsent" || a.state === "asked");
131131 return html`<div
132132 id="reach"
133 data-fragment="${ASK_FORM}"
133134 ${waits ? html`data-reach-wait="${stamp(asks)}"` : null}
134135 >
135136 ${note}
@@ -192,11 +193,11 @@ export async function originReachAsk(ctx: Ctx): Promise<Response> {
192193 why: field(form, "why"),
193194 });
194195 if (!asked.ok)
195 return flashTo(ctx, "/settings/origins#connect", {
196 return flashOrJson(ctx, "/settings/origins#connect", {
196197 tone: "danger",
197198 message: ASK_ERROR_WORDS[asked.error],
198199 });
199 return flashTo(ctx, `/settings/origins#reach`, {
200 return flashOrJson(ctx, `/settings/origins#reach`, {
200201 ...(asked.value.state === "refused" ? { tone: "attn" as const } : {}),
201202 message:
202203 asked.value.state === "refused" || asked.value.state === "allowed"
@@ -204,7 +205,14 @@ export async function originReachAsk(ctx: Ctx): Promise<Response> {
204205 : asked.value.state === "unsent"
205206 ? `The host could not be told just now. This forge keeps trying, and ${asked.value.host} stays listed here.`
206207 : `The host was asked to allow ${asked.value.host}. Its answer appears here.`,
207 });
208 }, { redraw: [ASK_FORM] });
209 }
210
211 // GET /settings/origins/reach — the block alone, as the page draws it, for the ask that acted in
212 // place.
213 export function originReachFragment(ctx: Ctx): Response {
214 if (!signedInPage(ctx)) return fragment(html``, { status: 404 });
215 return fragment(reachBlock(ctx) ?? html``, { request: ctx.request });
208216 }
209217
210218 // POST /settings/origins/reach/dismiss — take one's own answered ask off the page.
src/web/pages/origins.ts +20 −5
@@ -70,6 +70,7 @@ import {
7070 listDetachedMirrors,
7171 mirrorsByOrigin,
7272 type Origin,
73 getOriginFor,
7374 } from "../../core/origins.ts";
7475 import { getReposByIds } from "../../core/repos.ts";
7576 import { connectionBlock } from "../origin_connection.ts";
@@ -85,7 +86,7 @@ import {
8586 } from "../chrome.ts";
8687 import { field, readForm } from "../form.ts";
8788 import { html, when, type Html } from "../html.ts";
88 import { flashTo, page, redirect } from "../layout.ts";
89 import { flashOrJson, flashTo, fragment, page, redirect } from "../layout.ts";
8990 import {
9091 badge,
9192 btn,
@@ -1408,11 +1409,25 @@ export async function originReplaceToken(ctx: Ctx): Promise<Response> {
14081409 field(form, "write") === "1",
14091410 );
14101411 if (!replaced.ok)
1411 return flashTo(ctx, back, {
1412 return flashOrJson(ctx, back, {
14121413 tone: "danger",
14131414 message: replaceTokenMessage(replaced.error),
14141415 });
1415 return flashTo(ctx, back, {
1416 message: `Token replaced for ${replaced.value.login} at ${hostLabel(replaced.value.webUrl)}; its repositories are listed again.`,
1417 });
1416 return flashOrJson(
1417 ctx,
1418 back,
1419 { message: `Token replaced for ${replaced.value.login} at ${hostLabel(replaced.value.webUrl)}; its repositories are listed again.` },
1420 { redraw: [connectionUrl(replaced.value.id)] },
1421 );
1422 }
1423
1424 /**
1425 * Where one origin's connection block is read alone, for the form that replaced its token in place.
1426 */
1427 const connectionUrl = (id: string): string => `/settings/origins/${id}/connection`;
1428
1429 // GET /settings/origins/:id/connection: the block as the page draws it, nothing else.
1430 export function originConnectionFragment(ctx: Ctx): Response {
1431 const origin = ctx.auth.user === undefined ? undefined : getOriginFor(ctx.app.db, ctx.auth.user.id, ctx.params.id ?? "");
1432 return origin === undefined ? fragment(html``, { status: 404 }) : fragment(connectionBlock(ctx.app.db, origin), { request: ctx.request });
14181433 }
src/web/pages/settings.ts +12 −5
@@ -89,6 +89,7 @@ import { listRefs } from "../../git/read.ts";
8989 import { repoDir } from "../../git/repos.ts";
9090 import type { Ctx } from "../../http/context.ts";
9191 import {
92 crewStopLine,
9293 crumbsFor,
9394 loadRepo,
9495 repoBase,
@@ -101,7 +102,7 @@ import { adminForm, loadAdminRepo } from "../admin_form.ts";
101102 import { raiseCrewCeiling } from "../../actions/crew_ceiling.ts";
102103 import { forgeTemplateSetting } from "./forge-template-setting.ts";
103104 import { daySpark } from "../studio/kpi_row.ts";
104 import { settingsLead, teamJs } from "../studio/crew.ts";
105 import { settingsLead } from "../studio/crew.ts";
105106 import { pageTitle } from "../studio/nouns.ts";
106107 import { appHref } from "./apps.ts";
107108 import { appSecretsView } from "./app_secrets.ts";
@@ -117,7 +118,7 @@ import { lastChanges } from "../../settings/last_change.ts";
117118 import { NOT_CHANGED } from "../edit_words.ts";
118119 import { STOP_APP } from "../danger_words.ts";
119120 import { icon } from "../icons.ts";
120 import { flashTo, page, redirect } from "../layout.ts";
121 import { flashOrJson, flashTo, fragment, page, redirect } from "../layout.ts";
121122 import { helpAsked, pageHelp } from "../page_help.ts";
122123 import type { Flash } from "../flash.ts";
123124 import {
@@ -232,7 +233,7 @@ export function settingsPageResponse(
232233 crumbs: crumbsFor(repo),
233234 palette: repoPalette(ctx, repo),
234235 ...(styleCss !== undefined ? { styleCss } : {}),
235 scriptJs: `${teamJs}\n${liveClientJs}\n${outsideAgentsJs}\n${crewDevicesJs}`,
236 scriptJs: `${liveClientJs}\n${outsideAgentsJs}\n${crewDevicesJs}`,
236237 body: html`${repoHeader(ctx, repo, "settings", { compact: true })}
237238 ${settingsLayout(sections(repoBase(repo), active), body)}`,
238239 },
@@ -271,7 +272,6 @@ export async function settingsPage(
271272 title: pageTitle("settings", readable, true),
272273 crumbs: crumbsFor(readable),
273274 palette: repoPalette(ctx, readable),
274 scriptJs: teamJs,
275275 body: html`${repoHeader(ctx, readable, "settings", { compact: true })}
276276 ${lead}${proposals ? html`<div class="mt">${proposals}</div>` : null}`,
277277 });
@@ -1676,15 +1676,22 @@ export async function crewCeilingRaise(ctx: Ctx): Promise<Response> {
16761676 const field = gate.form.get("to");
16771677 const to = typeof field === "string" && /^\d{1,7}$/.test(field) ? Number(field) : Number.NaN;
16781678 const raised = raiseCrewCeiling(ctx.app, ctx.auth.user, to);
1679 return flashTo(
1679 return flashOrJson(
16801680 ctx,
16811681 repoBase(gate.repo),
16821682 raised.ok
16831683 ? { message: `The crew's daily ceiling is $${raised.value.to}, up from $${raised.value.from}.` }
16841684 : { tone: "danger", message: raised.error === "not_found" ? "Only a forge admin raises the crew's ceiling." : raised.error },
1685 { redraw: [`${repoBase(gate.repo)}/settings/crew/line`] },
16851686 );
16861687 }
16871688
1689 // GET /:owner/:name/settings/crew/line: the crew line alone, as the page draws it.
1690 export function crewLineFragment(ctx: Ctx): Response {
1691 const repo = loadAdminRepo(ctx);
1692 return repo ? fragment(crewStopLine(ctx, repo, repoBase(repo)), { request: ctx.request }) : fragment(html``, { status: 404 });
1693 }
1694
16881695 // POST /:owner/:name/settings/autonomy
16891696 export async function autonomySettingsUpdate(ctx: Ctx): Promise<Response> {
16901697 const gate = await adminForm(ctx);
src/web/pages/site.ts +8 −1
@@ -56,13 +56,14 @@ import {
5656 } from "../chrome.ts";
5757 import { SignupSlot, signupWindow } from "../../actions/signup-window.ts";
5858 import { signinWindow } from "../../core/signin-window.ts";
59 import { field, readForm } from "../form.ts";
59 import { field, prefersJson, readForm } from "../form.ts";
6060 import { passkeyJs } from "../passkey-client.ts";
6161 import { passkeyNote } from "../passkey-state.ts";
6262 import { html, when, type Html } from "../html.ts";
6363 import { icon } from "../icons.ts";
6464 import { flashTo, page, redirect } from "../layout.ts";
6565 import { flashCookie } from "../flash.ts";
66 import { json } from "../../http/respond.ts";
6667 import {
6768 btn,
6869 field as formField,
@@ -895,6 +896,12 @@ export async function themeSubmit(ctx: Ctx): Promise<Response> {
895896 if (parsed && parsed.origin === ctx.url.origin)
896897 back = parsed.pathname + parsed.search;
897898 }
899 // Acting in place (`web/in_place.ts`): the cookie is set, the page stays where it is.
900 if (prefersJson(ctx)) {
901 const kept = json({ ok: true });
902 kept.headers.append("set-cookie", cookie);
903 return kept;
904 }
898905 return redirect(back, cookie);
899906 }
900907
src/web/pages/talk.ts +1 −2
@@ -14,7 +14,6 @@
1414 * their id, the agent acts with their permissions (`crew/conversation.ts`).
1515 */
1616
17 import { ownTokenJs } from "../own_token.ts";
1817 import { lookupIdempotent, MAX_KEY_LENGTH, requestFingerprint, storeIdempotent } from "../../core/idempotency.ts";
1918 import { blockedFlash } from "../blocked.ts";
2019 import { noTalkAccountBlocked } from "../../actions/blocked_words.ts";
@@ -772,7 +771,7 @@ async function talkPage(ctx: Ctx, conversation: Conversation, before0: string |
772771 </div>
773772 ${split ? html`<div class="talk-work">${panel}${pane.html}</div>` : null}
774773 </div>`;
775 return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: talkCss + paneCss + codePaneCss + (picker?.control ? modelCss : "") + (panel === null ? "" : buildCss) + voiceCss + pinnedPlanCss, scriptJs: `${talkJs}\n${liveRegionsJs}\n${ownTokenJs}${picker?.control ? modelJs : ""}`, description: "Talk to the forge.", wide: true, noDock: true, ...(!split ? {} : { frameSrc: frames }) });
774 return page({ ctx, title: conversation.title === "" ? "Talk" : `${conversation.title} · Talk`, body, styleCss: talkCss + paneCss + codePaneCss + (picker?.control ? modelCss : "") + (panel === null ? "" : buildCss) + voiceCss + pinnedPlanCss, scriptJs: `${talkJs}\n${liveRegionsJs}\n${picker?.control ? modelJs : ""}`, description: "Talk to the forge.", wide: true, noDock: true, ...(!split ? {} : { frameSrc: frames }) });
776775 }
777776
778777 /**
src/web/studio/ask_admin.ts +2 −2
@@ -10,7 +10,7 @@ import { agoWords } from "../../kernel/ago.ts";
1010 import { signInFirst } from "../chrome.ts";
1111 import { backTo, field, readForm } from "../form.ts";
1212 import { html, type Html } from "../html.ts";
13 import { flashTo } from "../layout.ts";
13 import { flashOrJson, flashTo } from "../layout.ts";
1414 import { btn } from "../ui.ts";
1515
1616 // POST /asks/admin — ask whoever can; back where the person was, with how it stands said once.
@@ -21,7 +21,7 @@ export async function askAdminSubmit(ctx: Ctx): Promise<Response> {
2121 // The button carries the want, then its subject (`web/blocked.ts` `askValue`).
2222 const [want = "", ...subject] = field(form, "ask").split(" ");
2323 const asked = askAdmin(ctx.app, ctx.auth.user, { want, subject: subject.join(" ") });
24 return flashTo(
24 return flashOrJson(
2525 ctx,
2626 backTo(form, "/"),
2727 asked.ok
src/web/studio/crew.ts +1 −8
@@ -41,7 +41,6 @@ import { html, type Html } from "../html.ts";
4141 import { blockedWay } from "../blocked.ts";
4242 import { noAgentsBlocked } from "../../actions/blocked_words.ts";
4343 import { icon } from "../icons.ts";
44 import { inPlaceJs } from "../in_place.ts";
4544 import { crewReadiness } from "../pages/crew.ts";
4645 import { grantsSection } from "../pages/subscriptions.ts";
4746 import { seatSlotsOf, seatSlotsWords, SEAT_UNIT } from "../../crew/seat_slots.ts";
@@ -120,12 +119,6 @@ const SEAT_BADGE: Record<Seat["state"], { text: string; tone: Tone }> = {
120119 invite: { text: "open seat", tone: "default" },
121120 };
122121
123 /**
124 * The script: choosing in a team list, or setting its number, saves at once and redraws that seat
125 * only (`in_place.ts`).
126 */
127 export const teamJs = inPlaceJs;
128
129122 /**
130123 * One crew member as one line: name, the seat it holds, its state. What the agent's own words say
131124 * (its model and brief) opens in place, a native `<details>`, closed on first paint, so a row
@@ -256,7 +249,7 @@ export function seatFragment(ctx: Ctx, repo: Repo, role: string): Html | undefin
256249 * Your team, as three lists: Planners, Builders, Reviewers (`seatsOf`, the
257250 * same facts the MCP `crew` tool returns). Each list holds who fills it, a
258251 * picker of only the agents that declare that role, and how many may work at
259 * once; each choice posts at once (`teamJs`; without script, the button is
252 * once; each choice posts at once (`in_place.ts`; without script, the button is
260253 * there). A seat with nobody warns when the team is on its own.
261254 */
262255 function teamCard(
src/web/studio/run.ts +2 −2
@@ -10,7 +10,7 @@
1010
1111 import { offersOwnToken } from "../../actions/own_token.ts";
1212 import { keyOf } from "../keymap.ts";
13 import { ownTokenBox, ownTokenJs } from "../own_token.ts";
13 import { ownTokenBox } from "../own_token.ts";
1414 import { time } from "../time_element.ts";
1515 import { wayIn } from "../../actions/blocked_words.ts";
1616 import { blockedWay } from "../blocked.ts";
@@ -552,6 +552,6 @@ export async function runView(
552552 palette: repoPalette(ctx, repo),
553553 body,
554554 styleCss: RUN_PAGE_CSS,
555 scriptJs: `${liveRegionsJs}\n${studioRunJs}\n${openFoldJs}\n${ownTokenJs}`,
555 scriptJs: `${liveRegionsJs}\n${studioRunJs}\n${openFoldJs}`,
556556 });
557557 }
test/description-clamp.test.ts +1 −1
@@ -122,7 +122,7 @@ test("the repo header and the About card carry the expander on a long descriptio
122122
123123 test("an admin sees the crew line just under the repo head, with its one fix; it says off on a new repo", async () => {
124124 const head = await (await fetch(`${servers.url}/alice/page/issues`, { headers: { authorization: `Bearer ${token}` } })).text();
125 expect(head).toMatch(/<p class="small" data-crew-line role="status">Crew off: nothing runs here on its own\. <a href="\/alice\/page\/settings\/autonomy">Turn autonomy on<\/a><\/p>/);
125 expect(head).toMatch(/<p class="small" data-crew-line data-fragment="\/alice\/page\/settings\/crew\/line" role="status">Crew off: nothing runs here on its own\. <a href="\/alice\/page\/settings\/autonomy">Turn autonomy on<\/a><\/p>/);
126126 const anon = await (await fetch(`${servers.url}/alice/page/issues`)).text();
127127 expect(anon).not.toContain("data-crew-line");
128128 });
test/design-audit.test.ts +1 −1
@@ -18,7 +18,7 @@ const doc = readFileSync("docs/design/audit.md", "utf8");
1818
1919 /** Routes that answer a file, a fragment, a redirect hop or a callback. */
2020 const NOT_PAGES =
21 /^\/(design\/theme\.css|design\/theme\/|assets\/|\.well-known\/|icons\/|og\/|live\/|__forge\/|go\/|new\/issue$|asked$|events$|boards\/stream$|system\/stream$|talk\/stream$|peek$|settings\/teams\/stream$|(tabforge\/)?sw\.js$|offline$|robots\.txt$|favicon\.ico$|apple-touch-icon(-precomposed)?\.png$|sitemap\.xml$|edition$|oembed$|manifest\.webmanifest$|opensearch\.xml$|llms(-full)?\.txt$|openapi\.json$|releases\.json$|templates\.json$|maintenance\.json$|changelog\.atom$|explore\.(atom|json)$|feed\.json$|docs(\/[^/]*)?$|audit\.csv$|settings\/traffic\/scrapes\/export$|settings\/payments\.csv$|fleet\/graph\/live$|fleet\/graph\.csv$|forges\/export\.csv$|settings\/origins\/callback$|broker\/origins\/start$|home\/archived\/|settings\/backups\/live$|api\/v1(\/|$))/;
21 /^\/(design\/theme\.css|design\/theme\/|assets\/|\.well-known\/|icons\/|og\/|live\/|__forge\/|go\/|new\/issue$|asked$|events$|boards\/stream$|system\/stream$|talk\/stream$|peek$|settings\/teams\/stream$|(tabforge\/)?sw\.js$|offline$|robots\.txt$|favicon\.ico$|apple-touch-icon(-precomposed)?\.png$|sitemap\.xml$|edition$|oembed$|manifest\.webmanifest$|opensearch\.xml$|llms(-full)?\.txt$|openapi\.json$|releases\.json$|templates\.json$|maintenance\.json$|changelog\.atom$|explore\.(atom|json)$|feed\.json$|docs(\/[^/]*)?$|audit\.csv$|settings\/traffic\/scrapes\/export$|settings\/payments\.csv$|fleet\/graph\/live$|fleet\/graph\.csv$|forges\/export\.csv$|settings\/origins\/callback$|settings\/origins\/reach$|fleet\/result$|broker\/origins\/start$|home\/archived\/|settings\/backups\/live$|api\/v1(\/|$))/;
2222
2323 const getRoutes = [
2424 ...server.matchAll(/(?:router|own)\.add\(\s*"GET",\s*"([^"]+)"/g),
test/game-machine.test.ts +20
@@ -233,4 +233,24 @@ describe("the power cycle", () => {
233233 const refused = await post(owner, "bad");
234234 expect(refused.status).toBe(303);
235235 });
236 test("the machine block answers as a fragment for the owner only; the in-place answer names it", async () => {
237 const frag = (headers: Record<string, string>, q = "") => fetch(`${servers.url}/games/mc/@cycle${q}`, { headers: { ...headers, accept: "text/html" } });
238 const done = await frag(as(owner), "?done=1");
239 expect(done.status).toBe(200);
240 const text = await done.text();
241 expect(text).toContain('data-fragment="/games/mc/@cycle"');
242 expect(text).toContain("data-cycle-done");
243 expect(text).not.toContain("<html");
244 expect(await (await frag(as(owner))).text()).not.toContain("data-cycle-done");
245 for (const who of [as(operator), {}]) {
246 const gone = await frag(who, "?done=1");
247 expect(gone.status).toBe(404);
248 expect(await gone.text()).toBe("");
249 }
250 const refused = await fetch(`${servers.url}/games/mc/@cycle`, { method: "POST", headers: { ...as(owner), origin: servers.url, accept: "application/json" }, body: new URLSearchParams({ digest: "bad" }) });
251 expect(refused.headers.get("content-type")).toContain("application/json");
252 expect(((await refused.json()) as { redraw: string[] }).redraw).toEqual(["/games/mc/@cycle?done=1"]);
253 const op = await fetch(`${servers.url}/games/mc/@cycle`, { method: "POST", headers: { ...as(operator), origin: servers.url, accept: "application/json" }, body: new URLSearchParams({ digest: "bad" }) });
254 expect(op.status).toBe(404);
255 });
236256 });
test/in-place-fragments.test.ts added +183
@@ -0,0 +1,183 @@
1 /**
2 * Nine page forms answer in place (`web/in_place.ts`): asked for JSON they answer `{ok, flash,
3 * redraw}` or a 422 with words, never a page, and each redraw URL answers one fragment, not a
4 * document. Without script the same POST still redirects. The scanner's list is
5 * `in-place-rule.test.ts`; this file holds what each converted form answers.
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { mkdtemp, rm } from "node:fs/promises";
9 import { tmpdir } from "node:os";
10 import { join } from "node:path";
11 import { createApp, type App } from "../src/app.ts";
12 import { createRepo } from "../src/actions/repos.ts";
13 import { createIssue } from "../src/core/issues.ts";
14 import { createUser } from "../src/core/users.ts";
15 import { serve, type Servers } from "../src/http/server.ts";
16 import type { Blocked } from "../src/kernel/blocked.ts";
17 import { askFormShell, blockedNote } from "../src/web/blocked.ts";
18 import { ownTokenBox } from "../src/web/own_token.ts";
19 import { flowButton } from "../src/web/flow_button.ts";
20 import { quietLogs } from "./helpers/globals.ts";
21
22 quietLogs();
23 const PASSWORD = "a-long-crew-passphrase";
24
25 describe("forms that answer in place", () => {
26 let dir = "";
27 let app: App;
28 let servers: Servers;
29 let admin = "";
30 let issueNumber = 0;
31 const signIn = async (username: string): Promise<string> =>
32 ((await fetch(`${servers.url}/signin`, { method: "POST", body: new URLSearchParams({ username, password: PASSWORD }), redirect: "manual" })).headers.get("set-cookie") ?? "").split(";")[0]!;
33 const post = (path: string, body: Record<string, string>, o: { json?: boolean; cookie?: string; origin?: string } = {}) =>
34 fetch(`${servers.url}${path}`, {
35 method: "POST",
36 headers: { origin: o.origin ?? servers.url, cookie: o.cookie ?? admin, ...(o.json === false ? {} : { accept: "application/json" }) },
37 body: new URLSearchParams(body),
38 redirect: "manual",
39 });
40 const get = (path: string) => fetch(`${servers.url}${path}`, { headers: { cookie: admin, accept: "text/html" } });
41 /** The answer is a slice of markup, with no document around it. */
42 const isFragment = async (res: Response): Promise<string> => {
43 expect(res.headers.get("content-type")).toContain("text/html");
44 const text = await res.text();
45 expect(text).not.toContain("<html");
46 expect(text).not.toContain("<!doctype");
47 return text;
48 };
49 const isJson = (res: Response) => expect(res.headers.get("content-type")).toContain("application/json");
50
51 beforeAll(async () => {
52 dir = await mkdtemp(join(tmpdir(), "forge-in-place-fragments-"));
53 app = createApp({ dataDir: dir, port: 0 });
54 servers = await serve(app);
55 const a = await createUser(app.db, { origin: "seed", username: "alice", email: "[email protected]", password: PASSWORD, adminIfFirst: true, trusted: true });
56 if (!a.ok) throw new Error("user");
57 const made = await createRepo(app, a.value, { name: "yard", visibility: "public" });
58 if (!made.ok) throw new Error(String(made.error));
59 const issue = createIssue(app.db, { repoId: made.value.id, authorId: a.value.id, title: "Flow me" });
60 if (!issue.ok) throw new Error("issue");
61 issueNumber = issue.value.number;
62 admin = await signIn("alice");
63 }, 30_000);
64 afterAll(async () => {
65 await servers.stop();
66 await rm(dir, { recursive: true, force: true });
67 });
68
69 test("the ask to whoever can says what happened in JSON: Asked for a member, the words for one who can already", async () => {
70 const made = await createUser(app.db, { origin: "seed", username: "bob", email: "[email protected]", password: PASSWORD, trusted: true });
71 if (!made.ok) throw new Error("user");
72 const res = await post("/asks/admin", { ask: "crew_key", back: "/" }, { cookie: await signIn("bob") });
73 isJson(res);
74 expect(res.status).toBe(200);
75 expect(((await res.json()) as { ok: boolean; flash: string }).flash).toStartWith("Asked.");
76 const can = await post("/asks/admin", { ask: "crew_key", back: "/" });
77 expect(can.status).toBe(422);
78 expect(await can.json()).toMatchObject({ ok: false, error: "You can change this yourself: nobody needs to be asked." });
79 const plain = await post("/asks/admin", { ask: "crew_key", back: "/" }, { json: false });
80 expect(plain.status).toBe(303);
81 });
82
83 test("the ask to whoever can refuses a post from another origin", async () => {
84 const res = await post("/asks/admin", { ask: "crew_key", back: "/" }, { origin: "https://elsewhere.example" });
85 expect(res.status).toBe(403);
86 });
87
88 test("the forms draw data-in-place: the ask shell, the host's ask, the flow button", () => {
89 expect(askFormShell("/").text).toContain("data-in-place");
90 const blocked: Blocked = { says: "x", readerCan: false, ask: { method: "POST", path: "/other", label: "Ask", body: { host: "h" } } };
91 expect(blockedNote(blocked, { ask: "/settings/origins/reach" }).text).toContain("data-in-place");
92 expect(flowButton("/alice/yard/issues/1/flow", false, "/alice/yard/issues/1").text).toContain("data-in-place");
93 });
94
95 test("the host's ask answers JSON; its words come as a 422, and the block is a fragment", async () => {
96 const bad = await post("/settings/origins/reach", { host: "", why: "" });
97 isJson(bad);
98 expect(bad.status).toBe(422);
99 expect(((await bad.json()) as { error: string }).error.length).toBeGreaterThan(5);
100 await isFragment(await get("/settings/origins/reach"));
101 });
102
103 test("raising the ceiling answers JSON naming the crew line, which is a fragment", async () => {
104 const res = await post("/alice/yard/settings/autonomy/raise", { to: "1" });
105 isJson(res);
106 const j = (await res.json()) as { redraw: string[] };
107 expect(j.redraw).toEqual(["/alice/yard/settings/crew/line"]);
108 const text = await isFragment(await get(j.redraw[0]!));
109 expect(text).toContain("data-crew-line");
110 expect((await post("/alice/yard/settings/autonomy/raise", { to: "1" }, { origin: "https://elsewhere.example" })).status).toBe(403);
111 });
112
113 test("the flow button answers JSON with what it did, and a bad value is a 422", async () => {
114 const path = `/alice/yard/issues/${issueNumber}/flow`;
115 const on = await post(path, { flow: "1" });
116 isJson(on);
117 expect(await on.json()).toEqual({ ok: true, flash: "Flow first." });
118 expect(await (await post(path, { flow: "0" })).json()).toEqual({ ok: true, flash: "No longer first." });
119 const bad = await post(path, { flow: "2" });
120 expect(bad.status).toBe(422);
121 expect(((await bad.json()) as { ok: boolean }).ok).toBe(false);
122 expect((await post(path, { flow: "1", back: "/" }, { origin: "https://elsewhere.example" })).status).toBe(403);
123 });
124
125 test("the own-token box posts in place: words come as flash or error, never a page", () => {
126 const box = ownTokenBox("/alice/yard", "run1");
127 expect(box.text).toContain("data-in-place");
128 expect(box.text).not.toContain("data-own-token-said");
129 });
130
131 test("a wrong own token is a 422 with words, in JSON", async () => {
132 const res = await post("/alice/yard/runs/nope/own-token", { token: "x" });
133 expect(res.status).toBe(404);
134 });
135
136 test("the theme answers JSON with its cookie, and redirects without script", async () => {
137 const res = await post("/theme", { theme: "dark" });
138 isJson(res);
139 expect(res.headers.get("set-cookie")).toContain("forge_theme=dark");
140 const plain = await post("/theme", { theme: "dark" }, { json: false });
141 expect(plain.status).toBe(303);
142 });
143
144 test("a fleet preview answers JSON naming the panel, which is a fragment; a bad verb is a 422", async () => {
145 const res = await post("/fleet", { q: "repo", step: "preview", verb: "autonomy", value: "off" });
146 isJson(res);
147 const j = (await res.json()) as { ok: boolean; redraw: string[] };
148 expect(j.ok).toBe(true);
149 expect(j.redraw[0]).toStartWith("/fleet/result?");
150 const carried = (j as unknown as { html: string[] }).html[0]!;
151 expect(carried).toContain('data-fragment="/fleet/result"');
152 expect(carried).toContain("data-preview");
153 expect(carried).not.toContain("<html");
154 const text = await isFragment(await get(j.redraw[0]!));
155 expect(text).toContain('data-fragment="/fleet/result"');
156 expect(text).toContain("data-preview");
157 const bad = await post("/fleet", { q: "repo", step: "preview", verb: "nonsense", value: "" });
158 expect(bad.status).toBe(422);
159 isJson(bad);
160 });
161
162 test("a fleet undo of nothing is a 422 in JSON, and a receipt that is not there is an empty fragment", async () => {
163 const res = await post("/fleet/ops/nope/undo", {});
164 isJson(res);
165 expect(res.status).toBe(422);
166 const gone = await get("/fleet/result?op=nope");
167 expect(gone.status).toBe(404);
168 expect(await isFragment(gone)).toBe("");
169 });
170
171 test("the machine block and the connection block are fragments, and empty for what is not there", async () => {
172 for (const path of ["/games/nope/@cycle", "/settings/origins/nope/connection"]) {
173 const res = await get(path);
174 expect(res.status).toBe(404);
175 expect(await isFragment(res)).toBe("");
176 }
177 const cycle = await post("/games/nope/@cycle", { digest: "x" });
178 expect(cycle.status).toBe(404);
179 const token = await post("/settings/origins/nope/token", { token: "t" });
180 isJson(token);
181 expect(token.status).toBe(422);
182 });
183 });
test/in-place-offenders.json −10
@@ -1,17 +1,7 @@
11 [
2 "src/web/blocked.ts POST (form 1)",
3 "src/web/blocked.ts POST (form 2)",
4 "src/web/chrome.ts POST :/settings/autonomy/raise",
52 "src/web/diff-view.ts POST :/review",
63 "src/web/diff-view.ts POST :/threads/:/:",
7 "src/web/fleet-act.ts POST /fleet",
8 "src/web/fleet-act.ts POST /fleet/ops/:/undo",
9 "src/web/flow_button.ts POST (form 1)",
10 "src/web/games_machine.ts POST /games/:/@cycle",
114 "src/web/layout.ts POST (form 4)",
12 "src/web/layout.ts POST /theme",
13 "src/web/origin_connection.ts POST /settings/origins/:/token",
14 "src/web/own_token.ts POST :/runs/:/own-token",
155 "src/web/pages/account.ts POST /settings",
166 "src/web/pages/account.ts POST /settings/account/close",
177 "src/web/pages/account.ts POST /settings/account/keep",
test/no-polling.test.ts +2
@@ -304,6 +304,8 @@ export function findPolling(source: string): string[] {
304304 const ORIGIN = "needs a connected origin account; the seed connects none";
305305 const NOT_WALKED: Record<string, string> = {
306306 "/:owner/:name/settings/crew/seat/:role": "one seat of the crew card as an HTML fragment, not a page; :role is a seat the seed does not name",
307 "/games/:box/@cycle": "the machine block of a game box as an HTML fragment, not a page; no document to weigh, and test/game-machine.test.ts seeds a box and reads it",
308 "/settings/origins/:id/connection": "one origin's connection block as an HTML fragment, not a page; no document to weigh, and test/origins-page-shape.test.ts seeds an origin and reads it",
307309 "/talk/dev/:token": "a frame proxied from a running dev cell, not a page; the seed starts none",
308310 "/talk/dev/:token/*path": "a file proxied from a running dev cell, not a page; the seed starts none",
309311 "/infra/end/:act/*path": "the plan of a stop or delete, a page for a cloud resource the seed does not have; the action word is not in the seed",
test/origins-page-shape.test.ts +27
@@ -250,3 +250,30 @@ test("a mirror from another forge carries software to its page query, search and
250250 connectionsScreen(f, ctx).render({ x: 0, y: 0, w: 100, h: 8 }, s);
251251 expect(s.toText()).toContain(`${icon("anvil", "nerd")} anvil.example.org`);
252252 });
253
254 test("an origin's connection block is a fragment for its owner alone; the reach block needs a sign-in", async () => {
255 const alice = getUserByName(app.db, "alice")!;
256 const o = createOrigin(app.db, root, { userId: alice.id, kind: "forgejo", apiUrl: "https://git.example.com/api/v1/frag", webUrl: "https://git.example.com", login: "frag", token: "t0ken" });
257 if (!o.ok) throw new Error("origin");
258 const bob = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" });
259 if (!bob.ok) throw new Error(bob.error);
260 const signed = await fetch(`${servers.url}/signin`, { method: "POST", headers: { origin: servers.url }, body: new URLSearchParams({ username: "bob", password: "a-good-passphrase" }), redirect: "manual" });
261 const other = (signed.headers.get("set-cookie") ?? "").split(";")[0]!;
262 const get = (path: string, who: string) => fetch(`${servers.url}${path}`, { headers: { cookie: who, accept: "text/html" } });
263 const mine = await get(`/settings/origins/${o.value.id}/connection`, cookie);
264 expect(mine.status).toBe(200);
265 const text = await mine.text();
266 expect(text).toContain(`data-fragment="/settings/origins/${o.value.id}/connection"`);
267 expect(text).not.toContain("<html");
268 for (const who of [other, ""]) {
269 const gone = await get(`/settings/origins/${o.value.id}/connection`, who);
270 expect(gone.status).toBe(404);
271 expect(await gone.text()).toBe("");
272 }
273 const reach = await get("/settings/origins/reach", cookie);
274 expect(reach.status).toBe(200);
275 expect(await reach.text()).not.toContain("<html");
276 const guest = await get("/settings/origins/reach", "");
277 expect(guest.status).toBe(404);
278 expect(await guest.text()).toBe("");
279 });
test/own-token.test.ts +2 −2
@@ -101,9 +101,9 @@ test("a token that is not one, or one Anthropic refuses, keeps nothing and says
101101 const id = held();
102102 const notOne = await post(alice, id, "two words");
103103 expect(notOne.status).toBe(422);
104 expect(((await notOne.json()) as { said: string }).said).toContain("That is not a token");
104 expect(((await notOne.json()) as { error: string }).error).toContain("That is not a token");
105105 const refused = await post(alice, id, "sk-ant-oat01-not-the-right-one");
106 expect(((await refused.json()) as { said: string }).said).toContain("did not accept that token");
106 expect(((await refused.json()) as { error: string }).error).toContain("did not accept that token");
107107 expect(ownSubscription(app.db, alice.id)).toBeUndefined();
108108 expect(getRun(app.db, id)!.notBefore).not.toBeNull();
109109 });
test/pages-budget.test.ts +2
@@ -72,6 +72,8 @@ const NOT_PAGES = new Set([
7272 "/events", "/system/stream", "/settings/teams/stream", "/fleet/graph/live",
7373 "/settings/traffic/scrapes/export", "/settings/backups/live", "/:owner/:name/stream",
7474 "/settings/origins/flows/:id/stream", "/boards/:slug/stream", "/boards/stream", "/:owner/:name/archive/:file", // a tarball download, not a page
75 "/games/:box/@cycle", // the machine block of a game box: no document to weigh; test/game-machine.test.ts seeds a box and reads it
76 "/settings/origins/:id/connection", // one origin's connection block: no document to weigh; test/origins-page-shape.test.ts seeds an origin and reads it
7577 "/:owner/:name/settings/crew/seat/:role", // one seat of the crew card (#18459), a fragment, not a page
7678 "/api/v1/runner/jobs/:id/git/info/refs", // a runner's git door for one job (#13652), not a page
7779 ]);
test/security-floor-routes.test.ts +2
@@ -131,6 +131,8 @@ const UNSEEDED: Record<string, string> = {
131131 "/:owner/:name/pulls/:number/review/:step": "needs a pull with a review script, which the seed does not write (test/review-steps.test.ts covers it)",
132132 "/:owner/:name/settings/app/flags/:flag": "needs an app whose flags.json declares a flag; the seed has none",
133133 "/:owner/:name/settings/crew/seat/:role": "a crew seat fragment named by a role the seed does not pass; it is a fragment, not a page (test/crew-in-place.test.ts covers it)",
134 "/games/:box/@cycle": "the machine block of a game box; the seed has no box, and test/game-machine.test.ts seeds one and reads it, owner and not",
135 "/settings/origins/:id/connection": "one origin's connection block; the seed connects no origin, and test/origins-page-shape.test.ts seeds one and reads it, owner and not",
134136 "/:owner/:name/variants/:group": VARIANT,
135137 "/:owner/:name/waves/:version": WAVE,
136138 "/api/v1/boards/:slug/panels/:id": BOARD,
test/server-timing-sweep.test.ts +3
@@ -38,6 +38,9 @@ const NOT_PAGES = new Set([
3838 "/settings/traffic/scrapes/export",
3939 "/settings/backups/live",
4040 "/:owner/:name/stream",
41 "/:owner/:name/settings/crew/line", // a fragment an in-place form redraws: no page, no phases
42 "/fleet/result", // likewise
43 "/settings/origins/reach", // likewise
4144 ]);
4245
4346 /**

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs