LayerFS's trajectory page is served by a loopback service the host starts once a store exists (no write into the install), keeps its view in location.hash across its 5 s reload, reports every skipped secret-shaped file in sorted order (#477), and drops the unloaded sample. By @Mola-maker. Run at dfa99f7e merged onto current main: - mote (macOS, Bun 1.4.2, temp HOME): bun test in packages/layerfs, 64 pass 0 fail, 2 of 2; bun scripts/check.mjs layerfs ok; the temp HOME held nothing from layerfs afterwards. - WSL2 Ubuntu 24.04 (temp HOME): 64 pass 0 fail, 2 of 2 (#477's item 3 was red here on f3633eaf8). - Broken by hand: dropping the `location.hash =` assignment in page/app.js turns the hash test red. Earlier rounds' breaks (Origin/Host checks, < escape, start gates, nosniff, sort, restore/settle/round, reload guard) each went red, see the 05:18 and 05:45 reviews. - Earlier round: the page in a magpie-shaped sandboxed frame with pagePolicy CSP, Chromium and WebKit. - PR checks: test and on-npm pass. Not tried: a real magpie window.
56 lines
2.5 KiB
JavaScript
56 lines
2.5 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 }
|
|
// Suite hygiene (0.10.0 review, item 3): no test may touch the real
|
|
// HOME — the first test calls LayerfsTools with no env at all, so the
|
|
// suite pins a scratch home before any test runs.
|
|
process.env.MAGPIE_LAYERFS_HOME = mk("lfs-suite-home-")
|
|
// The cleanup's time grows with the machine's disk load, not with the
|
|
// suite: on a loaded box removing every dir took over bun's default 5s
|
|
// hook bar (#362), so the hook carries its own.
|
|
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)
|
|
}, 120_000)
|
|
|
|
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
|
|
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)
|
|
}
|
|
})
|