From c0988b773a1ca58b99bfc9b51f67d52fdb198bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= <16311043+immakermatty@users.noreply.github.com> Date: Wed, 18 Nov 2026 03:36:10 +0000 Subject: [PATCH] module-kit 0.4.1: a runtime stating production never writes without LAZURIO_RUNTIME_DATA_WRITER=true MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dataWriter returned true for a local or Environment entry whenever the writer variable was missing, also in a runtime that states LAZURIO_RUNTIME_DEPLOYMENT=production, against the Module Standard's writer rule (#9). It now refuses there; the writer variable still decides where it is set, and a development version keeps its local and Environment writes. Tests for every entry and for a registry's list. No deployed Application is affected (checked in #9). Agent: environment a480495c-25e0-4e51-828b-1dbf1b77d62f ยท T3 thread mcp:3e1c89fb-5ac2-43b2-9ec4-23f4a2e51382 Co-Authored-By: Claude Opus 5.5 --- README.md | 3 ++- package.json | 2 +- src/tools.ts | 6 +++-- test/tools.test.ts | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f59dd82..11a3258 100644 --- a/README.md +++ b/README.md @@ -219,7 +219,8 @@ changes no shared data and prepares a step a person completes in the interface (an approval, a signature, a sending). `write` changes data and says with `publishesData` whether the change is a publication of data (a commit and push in repository-db, `DOLT_COMMIT` in a database) or a draft. A write is offered -only while `dataWriter` allows it (`LAZURIO_RUNTIME_DATA_WRITER=true`; unset +only while `dataWriter` allows it (`LAZURIO_RUNTIME_DATA_WRITER=true`; unset, +never in a runtime that states `LAZURIO_RUNTIME_DEPLOYMENT=production`, else only to a local or Environment entry), and a write that publishes data is not offered in a production application: there a person publishes in the interface. The one exception is a kind of record for which the Owner allowed diff --git a/package.json b/package.json index f28b0d2..2a23460 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lazurio/module-kit", - "version": "0.4.0", + "version": "0.4.1", "description": "Lazurio Module Standard runtime helpers: listener, health, shutdown, app access, tools for agents", "license": "MIT", "type": "module", diff --git a/src/tools.ts b/src/tools.ts index 2c0339e..66ed1d1 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -264,8 +264,9 @@ export interface ToolRegistry { const TOOL_NAME = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/; /** Whether this App may change data now. `LAZURIO_RUNTIME_DATA_WRITER=true` - * writes and any other value does not; on an Application host the variable is - * always set. Without it (a Module version in an Environment) only a local or + * writes and any other value does not. Without it, a runtime that states + * `LAZURIO_RUNTIME_DEPLOYMENT=production` never writes (Lazurio/module-kit#9); + * otherwise (a development version in an Environment) only a local or * Environment entry writes, to the Environment's own data. */ export function dataWriter( access: AppAccess, @@ -273,6 +274,7 @@ export function dataWriter( ): boolean { const value = env.LAZURIO_RUNTIME_DATA_WRITER; if (value !== undefined) return value === "true"; + if (env.LAZURIO_RUNTIME_DEPLOYMENT === "production") return false; return access.entry === "local" || access.entry === "environment"; } diff --git a/test/tools.test.ts b/test/tools.test.ts index a282657..0db21e9 100644 --- a/test/tools.test.ts +++ b/test/tools.test.ts @@ -895,3 +895,66 @@ describe("review of #6 round 3: effectOf only for tool requests", () => { expect(await custom.effectOf(post("/mcp", call))).toBeNull(); }); }); + +describe("dataWriter in a runtime that states production (#9)", () => { + const entries = [ + { entry: "local", appRole: "admin" }, + { entry: "environment", appRole: "admin" }, + { entry: "app", appRole: "admin" }, + { entry: "app", appRole: "user" }, + { entry: "unknown", appRole: null }, + ] as const; + test("without the writer variable no entry writes", () => { + for (const access of entries) + expect([ + access.entry, + dataWriter(access as never, { + LAZURIO_RUNTIME_DEPLOYMENT: "production", + }), + ]).toEqual([access.entry, false]); + }); + test("the writer variable still decides where it is set", () => { + for (const access of entries) { + expect( + dataWriter(access as never, { + LAZURIO_RUNTIME_DEPLOYMENT: "production", + LAZURIO_RUNTIME_DATA_WRITER: "true", + }), + ).toBe(true); + expect( + dataWriter(access as never, { + LAZURIO_RUNTIME_DEPLOYMENT: "production", + LAZURIO_RUNTIME_DATA_WRITER: "false", + }), + ).toBe(false); + } + }); + test("a development version still lets a local or Environment entry write", () => { + for (const env of [{}, { LAZURIO_RUNTIME_DEPLOYMENT: "environment" }]) + expect(entries.map((access) => dataWriter(access as never, env))).toEqual( + [true, true, false, false, false], + ); + }); + test("a registry in such a runtime offers no write tool to a local entry", async () => { + const env = { + ...localEnvironment(), + LAZURIO_RUNTIME_DEPLOYMENT: "production", + }; + const local = registry(env); + const response = await local.handleMcp( + new Request("http://127.0.0.1:43100/mcp", { + method: "POST", + headers: { + host: "127.0.0.1:43100", + "content-type": "application/json", + }, + body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" }), + }), + ); + const names = ( + (await response.json()) as { result: { tools: Array<{ name: string }> } } + ).result.tools.map((tool) => tool.name); + expect(names).not.toContain("save_record_draft"); + expect(names).toContain("find_records"); + }); +});