Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 4 additions & 2 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,17 @@ 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,
env: Environment = process.env,
): 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";
}

Expand Down
63 changes: 63 additions & 0 deletions test/tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
Loading