From 90d1607846e4a9bc5dc946d3476348b1c8917ebd Mon Sep 17 00:00:00 2001 From: Roman Pavlovskyi <634881+rpavlovs@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:16:54 +0100 Subject: [PATCH] A test's server no longer inherits the local key bloks-server sets for its agents --- test/helpers/server.ts | 4 ++++ test/local-key.test.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/test/helpers/server.ts b/test/helpers/server.ts index bdb327a0..589c3998 100755 --- a/test/helpers/server.ts +++ b/test/helpers/server.ts @@ -174,6 +174,10 @@ export async function startHarness(extraEnv: Record = {}): Promi // bin/bloks-server.mjs sets this, so a test run from inside a Bloks // agent would inherit it and find pairing forced on BLOKS_LOOPBACK_ONLY: "", + // and this, which makes any request without that start's key a + // stranger's (server/local-key.ts), the readiness check below + // included; a test of the key turns it on in extraEnv + BLOKS_LOCAL_KEY: "", // and these, which would make a test's server think it was // started by bloks-server and may update itself; a test that // wants releases serves its own (server/server-update.ts) diff --git a/test/local-key.test.ts b/test/local-key.test.ts index c75cf8a4..57998e01 100644 --- a/test/local-key.test.ts +++ b/test/local-key.test.ts @@ -54,6 +54,22 @@ test("the app's own server needs no key: its window is its own page", async (t) assert.equal((await fetch(`${h.url}/api/config`)).status, 200); }); +test("tests run inside bloks-server still get a server without the key", async (t) => { + // bin/bloks-server.mjs sets the flag for everything it starts, an agent + // running these tests included; a harness that kept it would never pass + // its own readiness check, which carries no key + const before = process.env.BLOKS_LOCAL_KEY; + process.env.BLOKS_LOCAL_KEY = "1"; + t.after(() => { + if (before === undefined) delete process.env.BLOKS_LOCAL_KEY; + else process.env.BLOKS_LOCAL_KEY = before; + }); + const h = await startHarness(); + t.after(() => h.stop()); + assert.equal((await fetch(`${h.url}/api/config`)).status, 200); + assert.equal(existsSync(join(h.home, ".bloks", LOCAL_KEY_FILE)), false, "the server made a key"); +}); + test("an agent's own turn credential works on a server started with the key, and nothing wider does", async (t) => { // #480: the agent block let the credential through, then the remote // surface took the request for a stranger's and sent it to pair