scripts: check tools-only plugins, skip pages and routings, run strategies.json
check.mjs now checks a plugin whose only hook is `tool`: each tool's name is one an MCP client takes, and it has a description, args and execute. It skips packages with magpie.gateway (routing strategies) and page-only packages (magpie.page with no main), whose own tests check them. middleware.mjs gains order() and checkStrategies(): a gateway plugin's strategy is asked for an order the way magpie's gateway asks it (internal/routes.Apply), falling back to the listed order on a throw or an answer that isn't a permutation, and strategies.json cases are run against it. Run: HOME=$(mktemp -d) bun test (1554 pass, 0 fail) and bun scripts/check.mjs (every package ok) at this tree with the three packages that follow.
This commit is contained in:
@@ -65,3 +65,43 @@ export function check(dir, mod) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// order asks a module's strategy for the order of seats, as the gateway
|
||||
// does: strategies[name] or strategies[name].order, given the pool's name,
|
||||
// the seats (with every field a seat has) and the plugin's options. An
|
||||
// answer that isn't an order of the seats is the listed order, as the
|
||||
// gateway falls back to; failed says so.
|
||||
export function order(mod, name, pool, seats, options = {}) {
|
||||
const m = mod.default ?? mod
|
||||
const s = m.strategies?.[name]
|
||||
const fn = typeof s === "function" ? s : s?.order
|
||||
if (typeof fn !== "function") throw new Error(`no strategy ${name}`)
|
||||
const full = seats.map((x, i) => ({
|
||||
key: `seat-${i}`, account: false, known: false, learns: false, used: 0,
|
||||
soon: [], pace: 0, weight: 1, resting: false, tokens: 0, ...x,
|
||||
}))
|
||||
const listed = full.map((_, i) => i)
|
||||
let got
|
||||
try {
|
||||
got = fn(pool, JSON.parse(JSON.stringify(full)), options)
|
||||
} catch {
|
||||
return { order: listed, failed: true }
|
||||
}
|
||||
const ok = Array.isArray(got) && got.length === full.length &&
|
||||
got.every((i) => Number.isInteger(i) && i >= 0 && i < full.length) && new Set(got).size === full.length
|
||||
return ok ? { order: got } : { order: listed, failed: true }
|
||||
}
|
||||
|
||||
// checkStrategies runs strategies.json: each case names a strategy, the
|
||||
// seats (only the fields that matter; the rest are filled in), options,
|
||||
// a pool, and the order it expects, by the seats' keys when they have one.
|
||||
export function checkStrategies(dir, mod) {
|
||||
const list = JSON.parse(readFileSync(join(dir, "strategies.json"), "utf8"))
|
||||
for (const c of list) {
|
||||
test(c.name, () => {
|
||||
const got = order(mod, c.strategy, c.pool ?? "test-pool", c.seats, c.options ?? {})
|
||||
expect(got.failed).toBeUndefined()
|
||||
expect(got.order.map((i) => c.seats[i].key ?? i)).toEqual(c.expect)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user