Let the owner change regions by place name, without a restart

The p2p node can now add and drop regions while running (SetRegions):
topics, validators, subscriptions and per-region peer discovery start and
stop with them, and a newly followed region catches up by sync.

PUT /api/v1/regions (owner token) applies a change and the node saves it in
regions.json, which wins over --region from then on. The owner's browser
gets a "Regions" page: search a place by name (GeoNames cities, offline,
CC BY 4.0), follow its cell plus any cell within about 40 km.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 10:28:16 +01:00
co-authored by Claude Sonnet 5.5
parent e7bec4fb63
commit fd439710df
24 changed files with 70080 additions and 42 deletions
+54
View File
@@ -41,6 +41,11 @@ function fakeNode() {
s.calls.push({ method: r.method, path: r.path + (r.query.size ? "?" + r.query : ""), body: r.body, auth: r.auth });
if (r.auth !== `Bearer ${s.token}`) return { status: 401, body: { error: "unauthorized" } };
if (r.path === "/api/v1/mine") return { status: 200, body: s.mine };
if (r.path === "/api/v1/regions" && r.method === "PUT") {
const { regions } = JSON.parse(r.body) as { regions: string[] };
if (regions.includes("zzz")) return { status: 400, body: { error: `"zzz" is not a region: use 3 geohash characters` } };
return { status: 200, body: { regions } };
}
if (r.path === "/api/v1/inbox") return { status: 200, body: s.threads.filter((t) => t.listing === r.query.get("listing")) };
const th = /^\/api\/v1\/inbox\/([0-9a-f]{32})\/([0-9a-f]{64})$/.exec(r.path);
if (th) {
@@ -383,3 +388,52 @@ test("signing out forgets the token", async () => {
assert.equal(page!.window.sessionStorage.getItem("allmende.owner.token"), null);
await page!.waitFor(() => q("nav a[href='#/mine']") === null, "the owner link to vanish");
});
test("the owner picks regions by place name and the node follows them at once", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
qa(".pane-listings a").find((a) => a.textContent === "Regions")!.click();
await page!.waitFor(() => q('[name="place"]') !== null, "the regions page");
assert.ok(q(".rp-chips")!.textContent!.includes("u1x"), "what the node follows now");
const search = q<HTMLInputElement>('[name="place"]')!;
await page!.waitFor(() => !search.disabled, "the place list is loaded");
search.value = "köln";
search.dispatchEvent(new page!.window.Event("input", { bubbles: true }));
await page!.waitFor(() => q(".rp-result") !== null, "a result");
q(".rp-result")!.click();
await page!.waitFor(() => /Regions around/.test(text()), "the cells around it");
button("Add")!.click();
assert.ok(qa(".rp-chip").length >= 2, "the new regions are added next to the old one");
submit(q("form")!);
await page!.waitFor(() => /Saved/.test(text()), "saved");
const put = node.s.calls.find((c) => c.method === "PUT" && c.path === "/api/v1/regions")!;
assert.equal(put.auth, `Bearer ${TOKEN}`, "only the owner can change regions");
const sent = (JSON.parse(put.body) as { regions: string[] }).regions;
assert.equal(sent[0], "u1x");
assert.ok(sent.includes("u1j"), `Köln's own cell is followed: ${sent}`);
assert.ok(q("#status")!.textContent!.includes(sent.join(", ")), "the status line shows the new regions");
});
test("a region the node refuses is explained and the page stays usable", async () => {
open(`#/login/${TOKEN}`);
await page!.waitFor(() => qa(".pane-listings .ocard").length === 2, "the listings");
location_(`#/mine/regions`);
await page!.waitFor(() => q('[name="regions"]') !== null, "the regions page");
q<HTMLInputElement>('[name="regions"]')!.value = "zzz";
submit(q("form")!);
await page!.waitFor(() => /not a region/.test(text()), "the node's explanation");
assert.ok(!button("Save")?.disabled, "saving can be tried again");
});
test("without signing in the regions page leads to the sign-in", async () => {
open("#/mine/regions");
await page!.waitFor(() => q('input[name="token"]') !== null, "the sign-in form");
assert.equal(node.s.calls.length, 0);
});
/** Moves the open page to another hash, as a click on a link would. */
function location_(hash: string): void {
page!.window.location.hash = hash;
}