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

An origin's reconnect and storage-limit sentences live in one module, read by credentials, sync, storage and mirror #5640

Parked opened this
Closed without merging

mason/forge:mason/5623-an-origin-s-reconnect-and-storage-limit → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
8 files changed +64 −9
src/actions/migrate.ts +2 −1
@@ -63,6 +63,7 @@ import {
6363 type MirrorJob,
6464 } from "../origins/jobs.ts";
6565 import type { Provider } from "../origins/types.ts";
66 import { AT_STORAGE_LIMIT } from "../origins/words.ts";
6667 import { requireUser } from "./access.ts";
6768 import { enableApp } from "./apps.ts";
6869 import { addToCrew } from "./crew.ts";
@@ -287,7 +288,7 @@ export function migrateMessage(error: MigrateError, limit = "at the repositories
287288 case "repository_limit":
288289 return `Not made: ${limit}.`;
289290 case "storage_limit":
290 return "Not made: this account is at the forge's storage limit. Delete a repository or app data first.";
291 return `Not made: ${AT_STORAGE_LIMIT}. Delete a repository or app data first.`;
291292 }
292293 }
293294
src/core/storage.ts +3 −2
@@ -17,6 +17,7 @@ import { appsRoot } from "../apps/data.ts";
1717 import { dirBytes } from "../apps/bytes.ts";
1818 import { repoDir } from "../git/repos.ts";
1919 import { getQuota } from "../settings/quotas.ts";
20 import { AT_STORAGE_LIMIT } from "../origins/words.ts";
2021 import type { User } from "./users.ts";
2122
2223 /** The limit is set in megabytes (decimal), the unit people say it in. */
@@ -177,8 +178,8 @@ export async function storageRefusal(
177178 export function storageLimitMessage(app: App, ownerId: string): string {
178179 const sentence = storageSentence(app, ownerId);
179180 return sentence === undefined
180 ? "this account is at the forge's storage limit"
181 : `this account is at the forge's storage limit: ${sentence}`;
181 ? AT_STORAGE_LIMIT
182 : `${AT_STORAGE_LIMIT}: ${sentence}`;
182183 }
183184
184185 /** What a refused push says, over HTTP and SSH alike. */
src/origins/credential.ts +3 −2
@@ -29,6 +29,7 @@ import { err, ok, type Result } from "../kernel/result.ts";
2929 import { appFor, refresh, type AppRegistration } from "./oauth.ts";
3030 import { providerFor } from "./providers/index.ts";
3131 import type { Provider, ProviderCredential, ProviderResult } from "./types.ts";
32 import { NEEDS_RECONNECT } from "./words.ts";
3233
3334 const log = createLog("origins");
3435
@@ -88,7 +89,7 @@ async function resolveToken(
8889 const current = getOriginById(app.db, originId);
8990 if (!current) return authFailure("this origin is no longer connected");
9091 if (current.needsReauth)
91 return authFailure("this origin needs to be reconnected");
92 return authFailure(NEEDS_RECONNECT);
9293
9394 if (current.authKind === "oauth" && expiringSoon(current)) {
9495 const pending = refreshing.get(originId);
@@ -96,7 +97,7 @@ async function resolveToken(
9697 else await runRefresh(app, originId);
9798 const after = getOriginById(app.db, originId);
9899 if (!after || after.needsReauth)
99 return authFailure("this origin needs to be reconnected");
100 return authFailure(NEEDS_RECONNECT);
100101 }
101102
102103 const sealed = sealedSecrets(app.db, originId);
src/origins/mirror.ts +2 −1
@@ -32,6 +32,7 @@ import { adoptDefaultBranch, configureMirror } from "./git-mirror.ts";
3232 import { advance, createJob, runningJob, type MirrorJob } from "./jobs.ts";
3333 import { syncOrigin } from "./sync.ts";
3434 import type { RemoteRepo } from "./types.ts";
35 import { AT_STORAGE_LIMIT } from "./words.ts";
3536
3637 export type MirrorError =
3738 | "not_found"
@@ -301,7 +302,7 @@ export function mirrorMessage(error: MirrorError): string {
301302 case "repository_limit":
302303 return "this account is at the forge's repositories limit";
303304 case "storage_limit":
304 return "this account is at the forge's storage limit";
305 return AT_STORAGE_LIMIT;
305306 }
306307 }
307308
src/origins/push-through.ts +3 −2
@@ -40,6 +40,7 @@ import { err, ok, type Result } from "../kernel/result.ts";
4040 import { providerForOrigin } from "./credential.ts";
4141 import { redact, secretsIn } from "./credentials.ts";
4242 import { pushToOrigin, snapshotRefs } from "./git-mirror.ts";
43 import { NEEDS_RECONNECT } from "./words.ts";
4344
4445 /** A push-through must not outlive a pusher's patience. */
4546 const TIMEOUT_MS = 60_000;
@@ -194,13 +195,13 @@ async function wayThrough(
194195 const provider = providerForOrigin(app, link.origin);
195196 if (!provider.ok)
196197 return err({
197 message: `${link.origin.webUrl}: this origin needs to be reconnected`,
198 message: `${link.origin.webUrl}: ${NEEDS_RECONNECT}`,
198199 });
199200
200201 const authEnv = await provider.value.gitAuthEnv(link.cloneUrl);
201202 if (Object.keys(authEnv).length === 0)
202203 return err({
203 message: `${link.origin.webUrl}: this origin needs to be reconnected`,
204 message: `${link.origin.webUrl}: ${NEEDS_RECONNECT}`,
204205 });
205206 return ok({ link, authEnv });
206207 }
src/origins/sync.ts +2 −1
@@ -53,6 +53,7 @@ import {
5353 importReviewStates,
5454 } from "./import.ts";
5555 import type { Provider, ProviderFailure, RemoteIssue } from "./types.ts";
56 import { NEEDS_RECONNECT } from "./words.ts";
5657
5758 const log = createLog("origins");
5859
@@ -153,7 +154,7 @@ async function runOrigin(
153154 };
154155
155156 if (origin.needsReauth) {
156 report.error = "this origin needs to be reconnected";
157 report.error = NEEDS_RECONNECT;
157158 recordSync(app.db, origin.id, { at: startedAt, error: report.error });
158159 schedule(app, origin.id, SYNC_INTERVAL_MS);
159160 return report;
src/origins/words.ts added +10
@@ -0,0 +1,10 @@
1 /**
2 * What an origin's state says, on the web and in the terminal alike: one
3 * place for each sentence, so a refusal reads the same wherever it is said.
4 */
5
6 /** An origin whose credential was revoked or expired past refreshing. */
7 export const NEEDS_RECONNECT = "this origin needs to be reconnected";
8
9 /** An account refused a create, fork or mirror for the bytes it holds. */
10 export const AT_STORAGE_LIMIT = "this account is at the forge's storage limit";
test/origin-state-words.test.ts added +39
@@ -0,0 +1,39 @@
1 /**
2 * An origin that needs reconnecting, or an account at its storage limit,
3 * reads the same wherever it is said, because it is said from one place:
4 * src/origins/words.ts. A copy typed back into a file that says it 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 { AT_STORAGE_LIMIT, NEEDS_RECONNECT } from "../src/origins/words.ts";
11
12 const root = join(import.meta.dir, "..");
13 const read = (file: string): string => readFileSync(join(root, file), "utf8");
14
15 const sayers = [
16 "src/origins/credential.ts",
17 "src/origins/sync.ts",
18 "src/core/storage.ts",
19 "src/origins/mirror.ts",
20 "src/origins/push-through.ts",
21 "src/actions/migrate.ts",
22 ];
23
24 describe("an origin's state words", () => {
25 test("the sentences read as they always have", () => {
26 expect(NEEDS_RECONNECT).toBe("this origin needs to be reconnected");
27 expect(AT_STORAGE_LIMIT).toBe(
28 "this account is at the forge's storage limit",
29 );
30 });
31
32 for (const file of sayers)
33 test(`${file} imports the words and types neither sentence`, () => {
34 const text = read(file);
35 expect(text).toMatch(/from "(\.\/|\.\.\/origins\/)words\.ts"/);
36 expect(text).not.toContain(NEEDS_RECONNECT);
37 expect(text).not.toContain(AT_STORAGE_LIMIT);
38 });
39 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs