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

Repository-limit and agent-not-here refusals live in one module, read by migrate, repos, apps and the fleet #5714

Parked opened this
Closed without merging

mason/forge:mason/5655-repository-limit-and-agent-not-here-refu → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
7 files changed +74 −6
src/actions/crew_limit_words.ts added +14
@@ -0,0 +1,14 @@
1 /**
2 * The refusals for a repository limit and for an agent who is not here,
3 * said from one place so the page, the API, MCP and the terminal read the
4 * same. migrate, repos, apps and the fleet import these; none types its own.
5 */
6
7 /** A repository was refused because its owner is at the limit. */
8 export const AT_REPOSITORY_LIMIT = "at the repositories limit";
9
10 /** The agent named does not exist on this forge. */
11 export const AGENT_NOT_ON_FORGE = "That agent is not on this forge.";
12
13 /** The agent named exists, but is not on this repository's crew. */
14 export const AGENT_NOT_ON_CREW = "that agent is not on this repository's crew";
src/actions/migrate.ts +3 −2
@@ -66,6 +66,7 @@ import type { Provider } from "../origins/types.ts";
6666 import { requireUser } from "./access.ts";
6767 import { enableApp } from "./apps.ts";
6868 import { addToCrew } from "./crew.ts";
69 import { AGENT_NOT_ON_FORGE, AT_REPOSITORY_LIMIT } from "./crew_limit_words.ts";
6970 import {
7071 createRepo,
7172 deleteRepo,
@@ -254,7 +255,7 @@ export function migrationJobFor(
254255 }
255256
256257 /** A refusal in words a person can act on. */
257 export function migrateMessage(error: MigrateError, limit = "at the repositories limit"): string {
258 export function migrateMessage(error: MigrateError, limit = AT_REPOSITORY_LIMIT): string {
258259 switch (error) {
259260 case "invalid_url":
260261 return "That is not a URL this forge will clone from. Paste an https:// (or http://) address of a public repository, with no password in it. A git:// address is not supported: use its https:// address.";
@@ -265,7 +266,7 @@ export function migrateMessage(error: MigrateError, limit = "at the repositories
265266 case "unreachable":
266267 return "The origin could not be reached. Try again, or reconnect it under Settings → Origins.";
267268 case "no_such_agent":
268 return "That agent is not on this forge.";
269 return AGENT_NOT_ON_FORGE;
269270 case "invalid_branch":
270271 return "That is not a branch name git would take.";
271272 case "name_taken":
src/actions/repos.ts +2 −1
@@ -13,6 +13,7 @@ import { canSeeSealed } from "../core/sealed.ts";
1313 import { capacityValue } from "../core/capacity.ts";
1414 import { NEW_FOR_MS } from "./accounts.ts";
1515 import { repositoryLimitSentence } from "../settings/quotas.ts";
16 import { AT_REPOSITORY_LIMIT } from "./crew_limit_words.ts";
1617 import { storageChanged, storageRefusal, storageSentence } from "../core/storage.ts";
1718 import {
1819 createLabel as insertLabel,
@@ -104,7 +105,7 @@ export function repositoryLimitMessage(app: App, user: User, ownerId = user.id):
104105 return (
105106 repositoryLimitRefusal(app, user, ownerId) ??
106107 storageSentence(app, ownerId) ??
107 "at the repositories limit"
108 AT_REPOSITORY_LIMIT
108109 );
109110 }
110111
src/fleet/verbs.ts +2 −1
@@ -20,6 +20,7 @@ import {
2020 } from "../actions/issues.ts";
2121 import { linkIssue, unlinkIssue, dependencyWords } from "../actions/dependencies.ts";
2222 import { updateRepoSettings } from "../actions/repos.ts";
23 import { AGENT_NOT_ON_CREW } from "../actions/crew_limit_words.ts";
2324 import { cancelRepoRun, requeueRepoRun } from "../actions/runs.ts";
2425 import { isCrew } from "../core/agents.ts";
2526 import { mergePull } from "../actions/pulls.ts";
@@ -117,7 +118,7 @@ const WORDS: Record<string, string> = {
117118 mirrored: "mirrored: change it at the origin",
118119 unknown_label: "no such label here",
119120 assignee_cannot_read: "the assignee cannot read this repository",
120 agent_not_on_crew: "that agent is not on this repository's crew",
121 agent_not_on_crew: AGENT_NOT_ON_CREW,
121122 already_merged: "a merged pull stays closed",
122123 finished: "already finished",
123124 not_agent: "only an agent run is queued again",
src/tui/screens/common.ts +2 −1
@@ -15,6 +15,7 @@ import { binding, type Binding } from "../app/keys.ts";
1515 import type { KeyEvent } from "../term/input.ts";
1616 import { ARCHIVED_WHY, type RepoCounts } from "../../core/repos.ts";
1717 import { SIGNUP_CLOSED_MESSAGE } from "../../actions/users.ts";
18 import { AGENT_NOT_ON_CREW } from "../../actions/crew_limit_words.ts";
1819 import type { Session } from "../session.ts";
1920 import { G, Screen as Surface, type Rect } from "../term/screen.ts";
2021 import { style } from "../term/style.ts";
@@ -903,7 +904,7 @@ const MESSAGES: Record<string, string> = {
903904 no_such_agent: "no such agent",
904905 scaffold_failed: "the repository was made, but the app could not be started",
905906 assignee_cannot_read: "they cannot see this repository",
906 agent_not_on_crew: "that agent is not on this repository's crew",
907 agent_not_on_crew: AGENT_NOT_ON_CREW,
907908 invalid_model: "that model name is not valid",
908909 brief_too_long: "that brief is too long (4000 characters at most)",
909910 invalid_budget: "the budget must be between 0 and 100 dollars",
src/web/pages/apps.ts +2 −1
@@ -14,6 +14,7 @@
1414
1515 import { storageLimitMessage } from "../../core/storage.ts";
1616 import { repositoryLimitMessage } from "../../actions/repos.ts";
17 import { AGENT_NOT_ON_FORGE } from "../../actions/crew_limit_words.ts";
1718 import { appLimitWords } from "../../actions/app_limit.ts";
1819 import { getUserByName } from "../../core/users.ts";
1920 import {
@@ -441,7 +442,7 @@ const NEW_APP_ERRORS: Record<string, string> = {
441442 "Another app already answers to that hostname. Pick another name.",
442443 already_app: "That repository is already an app.",
443444 scaffold_failed: "The starter app could not be committed.",
444 no_such_agent: "That agent is not on this forge.",
445 no_such_agent: AGENT_NOT_ON_FORGE,
445446 };
446447
447448 // POST /apps/new
test/crew-limit-words.test.ts added +49
@@ -0,0 +1,49 @@
1 /**
2 * The repository-limit and agent-not-here refusals are said from one
3 * module, src/actions/crew_limit_words.ts. Each file that says them imports
4 * them; a copy typed back into any of them fails here.
5 */
6
7 import { describe, expect, test } from "bun:test";
8 import { readFileSync } from "node:fs";
9 import { join } from "node:path";
10 import {
11 AGENT_NOT_ON_CREW,
12 AGENT_NOT_ON_FORGE,
13 AT_REPOSITORY_LIMIT,
14 } from "../src/actions/crew_limit_words.ts";
15
16 const ROOT = join(import.meta.dir, "..");
17 const read = (path: string): string => readFileSync(join(ROOT, path), "utf8");
18
19 const READERS = [
20 "src/actions/migrate.ts",
21 "src/actions/repos.ts",
22 "src/web/pages/apps.ts",
23 "src/fleet/verbs.ts",
24 "src/tui/screens/common.ts",
25 ];
26
27 const SENTENCES = {
28 AT_REPOSITORY_LIMIT: "at the repositories limit",
29 AGENT_NOT_ON_FORGE: "That agent is not on this forge.",
30 AGENT_NOT_ON_CREW: "that agent is not on this repository's crew",
31 };
32
33 describe("crew and limit refusals live in one module", () => {
34 test("the module says each sentence in its exact words", () => {
35 expect(AT_REPOSITORY_LIMIT).toBe(SENTENCES.AT_REPOSITORY_LIMIT);
36 expect(AGENT_NOT_ON_FORGE).toBe(SENTENCES.AGENT_NOT_ON_FORGE);
37 expect(AGENT_NOT_ON_CREW).toBe(SENTENCES.AGENT_NOT_ON_CREW);
38 });
39
40 for (const path of READERS) {
41 test(`${path} imports the words and types none of them`, () => {
42 const text = read(path);
43 expect(text).toContain("crew_limit_words.ts");
44 for (const sentence of Object.values(SENTENCES)) {
45 expect(text).not.toContain(sentence);
46 }
47 });
48 }
49 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs