Files
plugins/packages/minimax/compact-tools.test.mjs
T
KlarkxyandKlarkxy 2b87fad98d minimax 0.2.7: opt-in compactTools lists only the four dispatcher tools (#1014)
Adds the plugin option `compactTools` (default false, declared in
package.json `magpie.options`). Only an explicit `true` leaves the sixteen
named Matrix tools out of the tools plugin's advertised list; `list_tools`,
`tool_schema`, `call_tool` and `web_search` stay, built by the same code,
with descriptions and schemas unchanged. `call_tool` still checks arguments
against the live catalog. This is option A as decided on #1005; option B
(rewritten descriptions) is not in it.

Run at the reviewed head a2d18183, on mote with a temp HOME:
- bun test packages/minimax: 165 pass, 0 fail
- bun scripts/check.mjs: exit 0
- Advertised list (name, description, args) hashed with
  MiniMaxCodeToolsPlugin at origin/main dba24067 and at the head: for no
  options, {}, and {compactTools:false} both give sha256 3cacc575d5abf786…
  (32300 chars), so off is byte-identical to main; {compactTools:true}
  gives 3890 chars at the head.
- git merge-tree with origin/main dba24067: clean.

Broken by hand, each red then restored:
- off path builds the Matrix tools after the dispatchers (order change):
  "compactTools off leaves the advertised tool list byte-for-byte" and
  "discovery stays scoped to Matrix" go red.
- on path appends text to list_tools' description: both "on ... unchanged"
  tests (connector-tools and the tools plugin) go red.
- compactToolsOn(options) as Boolean(options?.compactTools): "only true for
  an explicit true" and the off byte-for-byte test go red.

Not tried: a real MiniMax account or a live agy catalog; fake fetch only.

Co-authored-by: Klarkxy <6316992+klarkxy@users.noreply.github.com>
2026-11-11 23:44:15 +08:00

44 lines
2.3 KiB
JavaScript

// The tools plugin's advertised list with compactTools on and off:
// default stays today's twenty tools; on keeps only the four dispatchers,
// with their descriptions and schemas unchanged.
import "./nonet.mjs"
import { expect, test } from "bun:test"
import { compactToolsOn } from "./connector-tools.mjs"
import { MiniMaxCodeToolsPlugin } from "./magpie.mjs"
import { createWebTools } from "./web-tools.mjs"
const advertised = (tool) => JSON.stringify(Object.fromEntries(
Object.entries(tool).map(([name, t]) => [name, { description: t.description, args: t.args }]),
))
test("compactToolsOn is only true for an explicit true", () => {
expect(compactToolsOn()).toBe(false)
expect(compactToolsOn({})).toBe(false)
expect(compactToolsOn({ compactTools: false })).toBe(false)
expect(compactToolsOn({ compactTools: "true" })).toBe(false)
expect(compactToolsOn({ compactTools: 1 })).toBe(false)
expect(compactToolsOn({ compactTools: true })).toBe(true)
})
test("the tools plugin with compactTools off matches today's advertised list", async () => {
const today = advertised((await MiniMaxCodeToolsPlugin({ directory: "/tmp" })).tool)
expect(advertised((await MiniMaxCodeToolsPlugin({ directory: "/tmp" }, {})).tool)).toBe(today)
expect(advertised((await MiniMaxCodeToolsPlugin({ directory: "/tmp" }, { compactTools: false })).tool)).toBe(today)
const names = Object.keys((await MiniMaxCodeToolsPlugin({ directory: "/tmp" })).tool)
expect(names.at(-1)).toBe("web_search")
expect(names).toHaveLength(20)
})
test("the tools plugin with compactTools on lists only the four dispatchers, unchanged", async () => {
const full = (await MiniMaxCodeToolsPlugin({ directory: "/tmp" })).tool
const compact = (await MiniMaxCodeToolsPlugin({ directory: "/tmp" }, { compactTools: true })).tool
expect(Object.keys(compact)).toEqual(["list_tools", "tool_schema", "call_tool", "web_search"])
for (const name of Object.keys(compact)) {
expect(compact[name].description).toBe(full[name].description)
expect(JSON.stringify(compact[name].args)).toBe(JSON.stringify(full[name].args))
}
const web = createWebTools(async () => ({})).web_search
expect(compact.web_search.description).toBe(web.description)
expect(JSON.stringify(compact.web_search.args)).toBe(JSON.stringify(web.args))
})