Files
plugins/packages/layerfs/no-magpie.test.mjs
T
yetone 79e383c404 layerfs 0.7.2: tool descriptions and errors say "the app" and "the host", not magpie (#358)
Tool descriptions, and the errors a call answers, are part of the prompt
the agent sends its vendor. provision said "magpie's config directory",
exec "magpie serves these tools…", "MAGPIE_LAYERFS_EXEC=1" and "in
magpie's plugin options". They now say "the app's config directory",
"the host serves these tools…", "the exec switch in the host's
environment (see the package's README)" and "the host's plugin options".
The siblings that reach the model too are reworded the same way: the
source refusal ("the app's config directory"), the sim-only error (no
package or repo name, no variable names) and the bad-backend error.
Every environment variable is still read as before.

Not changed, filed as plugins#360: the workspace path provision answers
is under ~/.magpie-layerfs by default; moving it needs a plan for
existing workspaces.

Run:
- bun test (packages/layerfs): 50 pass, 0 fail
- bun scripts/check.mjs: ok
- no-magpie.test.mjs against HEAD's index.mjs and layerfs.mjs: 2 of 2 red
2026-10-24 17:43:23 +08:00

50 lines
2.1 KiB
JavaScript

// What these tools put in front of the model goes on to whatever vendor
// the agent uses (#358): the tool list (descriptions and argument schemas)
// and the errors a call answers name neither magpie nor its settings.
import { afterAll, expect, test } from "bun:test"
import { mkdtempSync, rmSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { LayerfsTools } from "./index.mjs"
import { createBackend } from "./layerfs.mjs"
const envSnapshot = { ...process.env }
const dirs = []
const mk = (p) => { const d = mkdtempSync(join(tmpdir(), p)); dirs.push(d); return d }
afterAll(() => {
for (const d of dirs) rmSync(d, { recursive: true, force: true })
for (const k of Object.keys(process.env)) if (!(k in envSnapshot)) delete process.env[k]
Object.assign(process.env, envSnapshot)
})
const named = (s) => /magpie/i.test(String(s))
const message = async (p) => { try { await p; return "" } catch (e) { return String(e?.message ?? e) } }
test("no tool description or argument names magpie", async () => {
const { tool } = await LayerfsTools({})
const sent = Object.entries(tool).map(([name, t]) => ({ name, description: t.description, args: t.args }))
expect(sent.length).toBe(8)
expect(named(JSON.stringify(sent))).toBe(false)
})
test("the errors a call answers name neither magpie nor its settings", async () => {
process.env.MAGPIE_LAYERFS_HOME = mk("lfs-home-")
process.env.MAGPIE_LAYERFS_BACKEND = "sim"
delete process.env.MAGPIE_LAYERFS_EXEC
delete process.env.MAGPIE_LAYERFS_NATIVE
const cfg = mk("app-config-")
const { tool } = await LayerfsTools({ directory: cfg }, { exec: false })
const call = (name, args) => tool[name].execute(args, { agent: "test", abort: AbortSignal.timeout(5000) })
const errors = [
await message(call("exec", { project: "website", command: "true" })),
await message(call("provision", { project: "website", source: cfg })),
await message(createBackend({ MAGPIE_LAYERFS_BACKEND: "native" })),
await message(createBackend({ MAGPIE_LAYERFS_BACKEND: "other" })),
]
for (const e of errors) {
expect(e).not.toBe("")
expect(named(e)).toBe(false)
}
})