Public: anyone can read this; the crew can change it.
A test file that sets the pinned `net` gives it back, and pinned-ceiling starts clean (#302) #17776
Merged 15h 20m ago, live in production
cf/pinned-net → main 0 commits
6 files
changed +69
−0
test/helpers/own-net.ts added +27
| @@ -0,0 +1,27 @@ | ||
| 1 | /** | |
| 2 | * The pinned actions' `net` and the cloud accounts' `net` for one test file, and given back. Each | |
| 3 | * is one object for the process, and the suite runs many files in one: `order-cloud` and | |
| 4 | * `new-forge-clouds` left a `resolve` that reads their own database, closed by then. Beside | |
| 5 | * `globals.ts`, not in it: many tests import that one and need none of the pinned actions. | |
| 6 | * | |
| 7 | * Called at a file's top level, it holds for that file: no name resolves, every probe is answered | |
| 8 | * 200 and there is no boot limit, until the file sets its own. | |
| 9 | */ | |
| 10 | ||
| 11 | import { afterAll, beforeAll } from "bun:test"; | |
| 12 | import { net as cloudNet } from "../../src/actions/cloud.ts"; | |
| 13 | import { net } from "../../src/actions/pinned.ts"; | |
| 14 | ||
| 15 | export function ownNet(): void { | |
| 16 | let found: { pinned: typeof net; cloud: typeof cloudNet }; | |
| 17 | beforeAll(() => { | |
| 18 | found = { pinned: { ...net }, cloud: { ...cloudNet } }; | |
| 19 | net.resolve = async () => []; | |
| 20 | net.probe = async () => new Response("ok", { status: 200 }); | |
| 21 | net.bootLimit = undefined; | |
| 22 | }); | |
| 23 | afterAll(() => { | |
| 24 | Object.assign(net, { bootLimit: undefined }, found.pinned); | |
| 25 | Object.assign(cloudNet, found.cloud); | |
| 26 | }); | |
| 27 | } |
test/new-forge-clouds.test.ts +2
| @@ -32,9 +32,11 @@ import { cloudsOffered, NO_CHARGE, parseWhere, whereChoices, whereFields, whereH | ||
| 32 | 32 | import { newForgePage, newForgeSubmit } from "../src/web/pages/new-forge.ts"; |
| 33 | 33 | import { pricingDone } from "../src/web/pages/pricing.ts"; |
| 34 | 34 | import { quietLogs } from "./helpers/globals.ts"; |
| 35 | import { ownNet } from "./helpers/own-net.ts"; | |
| 35 | 36 | import { seedPlaces } from "./helpers/places-fixture.ts"; |
| 36 | 37 | |
| 37 | 38 | quietLogs(); |
| 39 | ownNet(); | |
| 38 | 40 | makingWatch.tries = 0; |
| 39 | 41 | |
| 40 | 42 | const COMMIT = "d".repeat(40); |
test/order-cloud.test.ts +2
| @@ -52,9 +52,11 @@ import { usePlacement } from "../src/spawn/door.ts"; | ||
| 52 | 52 | import { bootHostedChild, closeHostedChildren } from "../src/spawn/host.ts"; |
| 53 | 53 | import { getPaidPlacement } from "../src/settings/paid_placement.ts"; |
| 54 | 54 | import { quietLogs } from "./helpers/globals.ts"; |
| 55 | import { ownNet } from "./helpers/own-net.ts"; | |
| 55 | 56 | import { ocean, seedPlaces } from "./helpers/places-fixture.ts"; |
| 56 | 57 | |
| 57 | 58 | quietLogs(); |
| 59 | ownNet(); | |
| 58 | 60 | |
| 59 | 61 | const COMMIT = "c".repeat(40); |
| 60 | 62 | // No page and no test waits on the in-process watch: each asks the order itself. |
test/own-net.test.ts added +34
| @@ -0,0 +1,34 @@ | ||
| 1 | /** | |
| 2 | * `ownNet` (`helpers/own-net.ts`): what a file sets on the shared `net` objects ends with it, and | |
| 3 | * what the last file left is not its own. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { net as cloudNet } from "../src/actions/cloud.ts"; | |
| 7 | import { net } from "../src/actions/pinned.ts"; | |
| 8 | import { ownNet } from "./helpers/own-net.ts"; | |
| 9 | ||
| 10 | const before = { pinned: { ...net }, cloud: { ...cloudNet } }; | |
| 11 | /** What a file that gave nothing back leaves: a resolve over a closed database, and a limit. */ | |
| 12 | const left = { resolve: () => Promise.reject(new Error("Cannot use a closed database")), bootLimit: 10 }; | |
| 13 | beforeAll(() => void Object.assign(net, left)); | |
| 14 | afterAll(() => { | |
| 15 | Object.assign(net, { bootLimit: undefined }, before.pinned); | |
| 16 | Object.assign(cloudNet, before.cloud); | |
| 17 | }); | |
| 18 | ||
| 19 | describe("a file that asks for its own", () => { | |
| 20 | ownNet(); | |
| 21 | ||
| 22 | test("starts on answers of its own, not on what the last file left", async () => { | |
| 23 | expect(await net.resolve("acme.forge.test")).toEqual([]); | |
| 24 | expect((await net.probe("https://acme.forge.test/")).status).toBe(200); | |
| 25 | expect(net.bootLimit).toBeUndefined(); | |
| 26 | net.resolve = async () => ["203.0.113.7"]; | |
| 27 | net.fetch = cloudNet.fetch = async () => new Response("its own"); | |
| 28 | }); | |
| 29 | }); | |
| 30 | ||
| 31 | test("and once it ends, everything it set is as it found it", () => { | |
| 32 | expect(net).toMatchObject({ ...left, fetch: before.pinned.fetch, probe: before.pinned.probe }); | |
| 33 | expect(cloudNet.fetch).toBe(before.cloud.fetch); | |
| 34 | }); |
test/pinned-ceiling.test.ts +2
| @@ -19,10 +19,12 @@ import { getCloudAccount } from "../src/core/cloud_account.ts"; | ||
| 19 | 19 | import { getPinned } from "../src/core/pinned.ts"; |
| 20 | 20 | import { createUser, getUserByName } from "../src/core/users.ts"; |
| 21 | 21 | import { quietLogs } from "./helpers/globals.ts"; |
| 22 | import { ownNet } from "./helpers/own-net.ts"; | |
| 22 | 23 | import { recordCloud } from "./helpers/recorded-cloud.ts"; |
| 23 | 24 | import { seedPlaces } from "./helpers/places-fixture.ts"; |
| 24 | 25 | |
| 25 | 26 | quietLogs(); |
| 27 | ownNet(); | |
| 26 | 28 | |
| 27 | 29 | const V1 = "a".repeat(40); |
| 28 | 30 | const V2 = "b".repeat(40); |
test/pinned-forge.test.ts +2
| @@ -18,10 +18,12 @@ import { createToken } from "../src/core/tokens.ts"; | ||
| 18 | 18 | import { createUser, getUserByName } from "../src/core/users.ts"; |
| 19 | 19 | import { serve, type Servers } from "../src/http/server.ts"; |
| 20 | 20 | import { quietLogs } from "./helpers/globals.ts"; |
| 21 | import { ownNet } from "./helpers/own-net.ts"; | |
| 21 | 22 | import { recordCloud, sequence } from "./helpers/recorded-cloud.ts"; |
| 22 | 23 | import { seedPlaces } from "./helpers/places-fixture.ts"; |
| 23 | 24 | |
| 24 | 25 | quietLogs(); |
| 26 | ownNet(); | |
| 25 | 27 | |
| 26 | 28 | const TOKEN = "dop_v1_9Zq4TxLm7Kp2Vb8nWcR5"; |
| 27 | 29 | const V1 = "a".repeat(40); |
new above
offline