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

Origin browsing's file-or-directory sentences live in one module, read by every provider #5606

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/5586-origin-browsing-s-file-or-directory-sent → main 1 commit fork

  • Merged. mason/5586-origin-browsing-s-file-or-directory-sent was merged into main as 7420795.

Review

Sign in to review this change.
4 files changed +45 −4
src/origins/providers/forgejo.ts +3 −2
@@ -74,6 +74,7 @@ import {
7474 toCommit,
7575 toTreeEntry,
7676 } from "./http.ts";
77 import { PATH_IS_DIRECTORY, PATH_IS_FILE } from "../words.ts";
7778
7879 /** What we ask for before the instance tells us its own ceiling. */
7980 const DEFAULT_LIMIT = 50;
@@ -250,7 +251,7 @@ export class ForgejoProvider implements Provider {
250251 });
251252 if (!result.ok) return result;
252253 if (!Array.isArray(result.value.data))
253 return fail("not_found", "that path is a file, not a directory");
254 return fail("not_found", PATH_IS_FILE);
254255 return succeed(
255256 sortEntries(result.value.data.map((r) => toTreeEntry(r, path))),
256257 );
@@ -271,7 +272,7 @@ export class ForgejoProvider implements Provider {
271272 });
272273 if (!result.ok) return result;
273274 if (Array.isArray(result.value.data))
274 return fail("not_found", "that path is a directory, not a file");
275 return fail("not_found", PATH_IS_DIRECTORY);
275276 return succeed(toBlob(result.value.data));
276277 }
277278
src/origins/providers/github.ts +3 −2
@@ -62,6 +62,7 @@ import {
6262 toCommit,
6363 toTreeEntry,
6464 } from "./http.ts";
65 import { PATH_IS_DIRECTORY, PATH_IS_FILE } from "../words.ts";
6566
6667 const PER_PAGE = 100;
6768 /** A page walk we drive ourselves (labels, reviews) stops here regardless. */
@@ -194,7 +195,7 @@ export class GitHubProvider implements Provider {
194195 });
195196 if (!result.ok) return result;
196197 if (!Array.isArray(result.value.data))
197 return fail("not_found", "that path is a file, not a directory");
198 return fail("not_found", PATH_IS_FILE);
198199 return succeed(
199200 sortEntries(result.value.data.map((r) => toTreeEntry(r, path))),
200201 );
@@ -215,7 +216,7 @@ export class GitHubProvider implements Provider {
215216 });
216217 if (!result.ok) return result;
217218 if (Array.isArray(result.value.data))
218 return fail("not_found", "that path is a directory, not a file");
219 return fail("not_found", PATH_IS_DIRECTORY);
219220 return succeed(toBlob(result.value.data));
220221 }
221222
src/origins/words.ts added +10
@@ -0,0 +1,10 @@
1 /**
2 * The sentences origin browsing answers with when a path names the wrong
3 * kind of thing, said from one place so every provider reads the same.
4 */
5
6 /** A directory listing was asked of a path that is a file. */
7 export const PATH_IS_FILE = "that path is a file, not a directory";
8
9 /** A file was asked of a path that is a directory. */
10 export const PATH_IS_DIRECTORY = "that path is a directory, not a file";
test/origin-words.test.ts added +29
@@ -0,0 +1,29 @@
1 /**
2 * Origin browsing's file-or-directory sentences are said from one module
3 * (#5586); a copy typed back into a provider fails here.
4 */
5
6 import { expect, test } from "bun:test";
7 import { readFileSync } from "node:fs";
8 import * as words from "../src/origins/words.ts";
9
10 const PROVIDERS = [
11 "src/origins/providers/forgejo.ts",
12 "src/origins/providers/github.ts",
13 ];
14
15 const sentences = Object.entries(words) as [string, string][];
16
17 test("each sentence is non-empty", () => {
18 expect(sentences.length).toBe(2);
19 for (const [, s] of sentences) expect(s.trim().length).toBeGreaterThan(0);
20 });
21
22 test("no provider types a sentence out itself", () => {
23 for (const file of PROVIDERS) {
24 const source = readFileSync(new URL(`../${file}`, import.meta.url), "utf8");
25 for (const [name, s] of sentences) {
26 expect({ file, name, typed: source.includes(s) }).toEqual({ file, name, typed: false });
27 }
28 }
29 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs