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

Full suite red: test/quotas-storage.test.ts #12767

Merged opened this in answer to

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

Merged

scout/forge:scout/12744-full-suite-red-test-quotas-storage-test → main 3 commits fork 2 threads · 2 unresolved

  • Merged. scout/12744-full-suite-red-test-quotas-storage-test was merged into main as ec75c06.

Review

Sign in to review this change.
1 file changed +59 −45
test/quotas-storage.test.ts +59 −45
@@ -41,6 +41,12 @@ describe("storage quota", () => {
4141 let bobToken: string;
4242 let carolId: string;
4343 let carolToken: string;
44 let daveId: string;
45 let daveTok: string;
46 let ginaId: string;
47 let ginaTok: string;
48 let migrated: Awaited<ReturnType<typeof mirrorAndWait>>;
49 let migratedFromEmpty = false;
4450
4551 beforeAll(async () => {
4652 dataDir = await mkdtemp(join(tmpdir(), "forge-quotas-storage-"));
@@ -61,6 +67,47 @@ describe("storage quota", () => {
6167 adaToken = createToken(app.db, adaId, "t", "admin").token;
6268 bobToken = createToken(app.db, bobId, "t", "admin").token;
6369 setQuota(app.db, "storage", 1, adaId); // one megabyte
70 // The accounts the mirror and migrate tests act as: signing up hashes a
71 // password, which is not what they measure.
72 const dave = await signUp(app, { username: "dave", email: "[email protected]", password: "dave-passphrase" }, { slot: fixtureSlot(app) });
73 const gina = await signUp(app, { username: "gina", email: "[email protected]", password: "gina-passphrase" }, { slot: fixtureSlot(app) });
74 if (!dave.ok || !gina.ok) throw new Error("signup");
75 proveAll(app);
76 promote(app.db);
77 daveId = dave.value.id;
78 ginaId = gina.value.id;
79 daveTok = createToken(app.db, daveId, "t", "admin").token;
80 ginaTok = createToken(app.db, ginaId, "t", "admin").token;
81 // The origin the mirror and migrate tests copy: a public repository just over the
82 // 1 MB limit, on this same forge, pushed once here so neither test pays for it.
83 expect((await push("ada", adaToken, "bigorigin", 1_100_000)).code).toBe(0);
84 app.db.query("UPDATE repo SET visibility = 'public' WHERE name = 'bigorigin'").run();
85 // gina imports it by migrate: let in because her account is empty.
86 const state = newFakeState("forgejo", "someone", "tok");
87 state.repos.push({
88 id: 3,
89 fullName: "ada/bigorigin",
90 cloneUrl: `${servers.url}/ada/bigorigin.git`,
91 defaultBranch: "main",
92 });
93 const fake = serveFakeForge(state);
94 try {
95 const post = (path: string, body: unknown) =>
96 fetch(`${servers.url}${path}`, {
97 method: "POST",
98 headers: { authorization: `Bearer ${ginaTok}`, "content-type": "application/json" },
99 body: JSON.stringify(body),
100 });
101 const connected = await post("/api/v1/user/origins", { host: fake.url, token: "tok" });
102 const originId = ((await connected.json()) as { id: string }).id;
103 migratedFromEmpty = (await accountBytes(app, ginaId)) === 0;
104 migrated = await mirrorAndWait(
105 await post("/api/v1/migrate", { source: { originId, fullName: "ada/bigorigin" }, name: "moved" }),
106 );
107 if (!migrated || migrated.stage !== "done") throw new Error(`migrate import did not finish: ${JSON.stringify(migrated)}`);
108 } finally {
109 fake.stop();
110 }
64111 });
65112 afterAll(async () => {
66113 servers.stop();
@@ -239,14 +286,7 @@ describe("storage quota", () => {
239286 });
240287
outdated

Stale: the origin is 1.1 MB now, pushed in beforeAll.

241288 test("a mirror bigger than the limit is allowed in, and the next create is refused as storage_limit", async () => {
outdated

Shim object only to keep the old body compiling. Replace the uses of dave.value.id below with daveId and delete this line and the daveToken alias (use daveTok).

242 // The origin: a public repository of 1.5 MB on this same forge.
243 expect((await push("ada", adaToken, "bigorigin", 1_500_000)).code).toBe(0);
244 app.db.query("UPDATE repo SET visibility = 'public' WHERE name = 'bigorigin'").run();
245 const dave = await signUp(app, { username: "dave", email: "[email protected]", password: "dave-passphrase" }, { slot: fixtureSlot(app) });
246 if (!dave.ok) throw new Error("signup");
247 proveAll(app);
248 promote(app.db);
249 const daveToken = createToken(app.db, dave.value.id, "t", "admin").token;
289 // The origin: a public repository of 1.1 MB on this same forge.
250290 const state = newFakeState("forgejo", "someone", "tok");
251291 state.repos.push({
252292 id: 2,
@@ -259,19 +299,19 @@ describe("storage quota", () => {
259299 const post = (path: string, body: unknown) =>
260300 fetch(`${servers.url}${path}`, {
261301 method: "POST",
262 headers: { authorization: `Bearer ${daveToken}`, "content-type": "application/json" },
302 headers: { authorization: `Bearer ${daveTok}`, "content-type": "application/json" },
263303 body: JSON.stringify(body),
264304 });
265305 const connected = await post("/api/v1/user/origins", { host: fake.url, token: "tok" });
266306 const originId = ((await connected.json()) as { id: string }).id;
267307 // Empty at the start, so the mirror is let in; the figure is read once.
268 expect(await accountBytes(app, dave.value.id)).toBe(0);
308 expect(await accountBytes(app, daveId)).toBe(0);
269309 const job = await mirrorAndWait(
270310 await post(`/api/v1/user/origins/${originId}/mirror`, { fullName: "ada/bigorigin" }),
271311 );
272312 expect(job?.stage).toBe("done");
273313 // The fetch marked the figure stale, so this check walks it and refuses.
274 const made = await createRepo(app, getUserById(app.db, dave.value.id)!, {
314 const made = await createRepo(app, getUserById(app.db, daveId)!, {
275315 name: "more",
276316 visibility: "private",
277317 });
@@ -285,41 +325,15 @@ describe("storage quota", () => {
285325 });
286326
287327 test("a migrate import bigger than the limit is allowed in, and the next create is refused as storage_limit", async () => {
288 const gina = await signUp(app, { username: "gina", email: "[email protected]", password: "gina-passphrase" }, { slot: fixtureSlot(app) });
289 if (!gina.ok) throw new Error("signup");
290 proveAll(app);
291 promote(app.db);
292 const token = createToken(app.db, gina.value.id, "t", "admin").token;
293 const state = newFakeState("forgejo", "someone", "tok");
294 state.repos.push({
295 id: 3,
296 fullName: "ada/bigorigin",
297 cloneUrl: `${servers.url}/ada/bigorigin.git`,
298 defaultBranch: "main",
328 // The import ran in beforeAll, from an empty account, so its clone is
329 // not counted against this test's budget; what it did is asserted here.
330 expect(migratedFromEmpty).toBe(true);
331 expect(migrated!.stage).toBe("done");
332 const made = await createRepo(app, getUserById(app.db, ginaId)!, {
333 name: "more",
334 visibility: "private",
299335 });
300 const fake = serveFakeForge(state);
301 try {
302 const post = (path: string, body: unknown) =>
303 fetch(`${servers.url}${path}`, {
304 method: "POST",
305 headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
306 body: JSON.stringify(body),
307 });
308 const connected = await post("/api/v1/user/origins", { host: fake.url, token: "tok" });
309 const originId = ((await connected.json()) as { id: string }).id;
310 expect(await accountBytes(app, gina.value.id)).toBe(0);
311 const job = await mirrorAndWait(
312 await post("/api/v1/migrate", { source: { originId, fullName: "ada/bigorigin" }, name: "moved" }),
313 );
314 expect(job?.stage).toBe("done");
315 const made = await createRepo(app, getUserById(app.db, gina.value.id)!, {
316 name: "more",
317 visibility: "private",
318 });
319 expect(made).toEqual({ ok: false, error: "storage_limit" });
320 } finally {
321 fake.stop();
322 }
336 expect(made).toEqual({ ok: false, error: "storage_limit" });
323337 });
324338
325339 /** A fresh account holding 1.5 MB, its figure measured, against the 1 MB limit. */

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs