factory 0.1.51: dsh's web_search goes out as WebSearch, and a tool set refused for a name not listed yet goes once more renamed in full
@a1pha1nthefog on X (2026-11-19): dsh (DeepSeek Harness) on Factory's
claude-opus-5-5 is still refused (content_policy_rejected) on magpie
v0.1.4532, whose Factory mover installs 0.1.50. 0.1.50 renamed the six dsh
tools on our list, but dsh also declares web_search, and two real accounts
saw Factory refuse web_search, read_file and execute_command the same day,
and every listed name behind leading underscores (_read, _web_search), while
omp_read and WebSearch pass (can1357/oh-my-pi#19553, single-tool probes with
a passing system block). 0.1.50's dsh test passed because its fake Factory
refused only the names the plugin itself listed.
- tool-names.mjs lists web_search, read_file and execute_command (as
WebSearch, Read and Execute, droid's own names) and refuses a listed
name behind leading underscores (refusedName).
- Factory adds names without notice, so one more missing name would refuse
every request again. A 403 content_policy_rejected for a request that
declares tools now goes once more with every tool renamed (droid's
names and mcp__ tools kept): if Factory takes it, that tool set goes
renamed in full for the rest of the process (at most 256 sets kept); if
it refuses again, the refusal is about the content and is the answer, as
before. A request with no tools is never sent twice.
- The tests' fake Factory now refuses what real accounts were seen
refusing (SEEN_REFUSED), apart from the plugin's own list, and dsh's
first request must be taken on the first try.
Only name fields change, as in 0.1.50: descriptions, schemas, arguments and
dsh's prompt go as written, and replies carry the caller's names back.
Run (mote, at origin/main 5f320200 plus this change): HOME=$(mktemp -d)
bun test is 9139 tests, 0 fail; bun test packages/factory is 220 pass, 0 fail;
bun scripts/check.mjs factory passes. Real dsh 0.2.1-rc.2 headless in a
sandbox HOME against the plugin's fetch, with a fake Factory refusing the
seen names plus web_fetch (standing in for a name Factory adds next): the
first try declared Execute, Edit, Glob, Grep, Read, WebSearch and Create and
was refused for web_fetch; the second went with every tool renamed and was
taken; dsh ran "echo dsh-ran-$((6*7))" through bash and its next turn went
renamed in full at once.
Broken by hand: without web_search, read_file and execute_command in the
list, 5 of tool-names.test.mjs's 18 tests fail, both dsh ones among them;
with the second try taken out, both second-try tests fail.
Not tried: a real Factory account. None is here, so Factory's own answer to
the renamed dsh request is not seen; the refused names come from two real
accounts' probes on 2026-11-19, not ours. Whether Factory reads an
Anthropic server tool's name (web_search_20250305) was not probed; those
keep Anthropic's name.
This commit is contained in:
@@ -176,16 +176,24 @@ Since 2026-11-17 Factory refuses (403 `content_policy_rejected`) any request
|
||||
that declares a tool under certain exact names, on every route, and the list
|
||||
moves. As of 2026-11-18 it holds Claude Code's `Bash`, `Write`, `Agent` and
|
||||
`TaskCreate`/`TaskGet`/`TaskList`/`TaskUpdate`, OpenCode's and pi's `bash`,
|
||||
`read`, `edit`, `write`, `glob`, `grep` and `task` (dsh declares six of
|
||||
these), `run_shell`, `Shell`, `StrReplace`, and the names first used in their
|
||||
place (`BashTool`, `bash_tool`, ...). The plugin declares such a tool under
|
||||
droid's own name for the job (`Execute` for `Bash`, `Create` for `Write`,
|
||||
`read`, `edit`, `write`, `glob`, `grep` and `task`, `run_shell`, `Shell`,
|
||||
`StrReplace`, and the names first used in their place (`BashTool`,
|
||||
`bash_tool`, ...). On 2026-11-19 two accounts also saw `web_search`,
|
||||
`read_file` and `execute_command` refused, and each of these names behind
|
||||
leading underscores (`_read`); dsh declares seven of them. The plugin
|
||||
declares such a tool under droid's own name for the job (`Execute` for `Bash`, `Create` for `Write`,
|
||||
`Task` for `Agent`, `Read` for `read`, ...), or, when droid has none or the
|
||||
request already declares it, under its own name with a suffix drawn from the
|
||||
process (`TaskCreate_3f9a`). It renames the tool's earlier calls and
|
||||
`tool_choice` to match and gives the caller its own name back in every reply,
|
||||
streamed or not. The lists are in `tool-names.mjs`.
|
||||
|
||||
Factory adds names without notice. A request refused while it declares tools
|
||||
goes once more with every tool renamed the same way (droid's own names and
|
||||
`mcp__` tools kept). If that is taken, the same tool set goes renamed in full
|
||||
for the rest of the process; if it is refused again, the refusal is about
|
||||
what the request says, and that is the answer.
|
||||
|
||||
## Claude Code through magpie
|
||||
|
||||
Factory's Anthropic route requires Droid's fixed client preamble and
|
||||
|
||||
@@ -7,7 +7,7 @@ import { STATUS_CODES } from "node:http"
|
||||
import { createHash } from "node:crypto"
|
||||
import { readFileSync } from "node:fs"
|
||||
import { parseToolJSON, wrapAnthropicTools, unwrapAnthropicTools } from "./anthropic-tools.mjs"
|
||||
import { aliasToolNames, restoreToolNames } from "./tool-names.mjs"
|
||||
import { aliasToolNames, restoreToolNames, toolSet } from "./tool-names.mjs"
|
||||
|
||||
const PROVIDER = "factory"
|
||||
|
||||
@@ -455,6 +455,15 @@ async function reconcile(c) {
|
||||
// "Requested active organization is not accessible by this user".
|
||||
const orgRefused = (status, text) => status === 403 && text.toLowerCase().includes("active organization is not accessible")
|
||||
|
||||
// renamedInFull holds the tool sets (toolSet) Factory refused until every
|
||||
// tool was renamed, in this process; the oldest goes past 256.
|
||||
const renamedInFull = new Set()
|
||||
function remember(set, key) {
|
||||
set.delete(key)
|
||||
set.add(key)
|
||||
if (set.size > 256) set.delete(set.values().next().value)
|
||||
}
|
||||
|
||||
// contentRefused is Factory's usage policy check refusing what the request
|
||||
// says, not who sent it: a 403 with code "content_policy_rejected" (droid
|
||||
// 0.245.0 tells it apart the same way, and only when Factory sent no
|
||||
@@ -2168,7 +2177,7 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
||||
|
||||
const { fresh, mendOrg } = account(getAuth)
|
||||
|
||||
const send = async (input, init, body, renewed) => {
|
||||
const send = async (input, init, body, renewed, every = false) => {
|
||||
const c = await fresh(renewed)
|
||||
let url = input instanceof Request ? input.url : String(input)
|
||||
// Gemini's: Factory's generate route, the model in the body
|
||||
@@ -2213,8 +2222,9 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
||||
// another agent's request opens as droid's does (droidBody)
|
||||
const anthropic = path.includes("/llm/a/") && (path.endsWith("/messages") || path.endsWith("/messages/count_tokens"))
|
||||
// Factory refuses some tool names outright (tool-names.mjs): those
|
||||
// go out under another name and come back as the caller's
|
||||
const named = aliasToolNames(anthropic ? anthropicBody(body) : droidBody(path, body))
|
||||
// go out under another name and come back as the caller's; with
|
||||
// every, all of its tools do (renamedInFull)
|
||||
const named = aliasToolNames(anthropic ? anthropicBody(body) : droidBody(path, body), every)
|
||||
const adapted = anthropic ? wrapAnthropicTools(named.body) : { body: named.body, names: new Set() }
|
||||
const out = sanitizeBody(adapted.body)
|
||||
// the caller's length is of the body it sent, not of this one
|
||||
@@ -2244,23 +2254,41 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
||||
const less = leaveOutAttachments(path, body)
|
||||
if (less) {
|
||||
await res.body?.cancel()
|
||||
res = await send(input, init, less.body, onRenew)
|
||||
res = await send(input, init, less.body, onRenew, every)
|
||||
if (res.status !== 413) return res
|
||||
}
|
||||
const anthropic = path.includes("/llm/a/")
|
||||
return errorReply(url, 413, anthropic ? "request_too_large" : "invalid_request_error", tooLarge(await res.text(), less?.left ?? 0), new Headers(res.headers))
|
||||
}
|
||||
// a tool set Factory refused by a name tool-names.mjs doesn't
|
||||
// list yet, and took with every tool renamed, goes renamed in
|
||||
// full from then on
|
||||
const tools = toolSet(body)
|
||||
let every = renamedInFull.has(tools)
|
||||
let res
|
||||
try {
|
||||
res = await send(input, init, body, onRenew)
|
||||
res = await send(input, init, body, onRenew, every)
|
||||
if (res.status === 413) return answer(await smaller(res))
|
||||
if (res.status !== 403) return answer(res)
|
||||
let text = await res.text()
|
||||
if (!contentRefused(res.status, text, res.headers) && (await mendOrg(res.status, text, onRenew).catch(() => false))) {
|
||||
res = await send(input, init, body, onRenew)
|
||||
res = await send(input, init, body, onRenew, every)
|
||||
if (res.status !== 403) return answer(res)
|
||||
text = await res.text()
|
||||
}
|
||||
// Factory's list of tool names it refuses grows without notice
|
||||
// (tool-names.mjs): refused with tools declared, the request
|
||||
// goes once more with each tool renamed. Refused again, it is
|
||||
// what the request says, and that refusal is the answer.
|
||||
if (contentRefused(res.status, text, res.headers) && tools && !every) {
|
||||
every = true
|
||||
res = await send(input, init, body, onRenew, true)
|
||||
if (res.status !== 403) {
|
||||
if (res.ok) remember(renamedInFull, tools)
|
||||
return answer(res)
|
||||
}
|
||||
text = await res.text()
|
||||
}
|
||||
const why = explain(res.status, text, res.headers)
|
||||
// the refusal, then what to do about it, as provider.Explain joins them
|
||||
const ids = upstreamIds(text, res.headers)
|
||||
@@ -2289,4 +2317,4 @@ export const FactoryAuthPlugin = async ({ client, magpie }) => {
|
||||
}
|
||||
|
||||
// for tests
|
||||
export const _internal = { CONVERSATION, sessionId, STANDARD_ONLY, contentRefused, explain, fastBody, FAST_BETA, limitWindows, windowEnd, dollars, vendorError, CORE, droidBody, DROID_LINE, geminiBody, GEMINI_ORDER, leaveOutAttachments, LEFT_OUT, TOO_LARGE_HINT, MODELS, PROMOTIONS, rateOf, configModels, providerModel, providerModels }
|
||||
export const _internal = { renamedInFull, CONVERSATION, sessionId, STANDARD_ONLY, contentRefused, explain, fastBody, FAST_BETA, limitWindows, windowEnd, dollars, vendorError, CORE, droidBody, DROID_LINE, geminiBody, GEMINI_ORDER, leaveOutAttachments, LEFT_OUT, TOO_LARGE_HINT, MODELS, PROMOTIONS, rateOf, configModels, providerModel, providerModels }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-factory-auth",
|
||||
"version": "0.1.50",
|
||||
"version": "0.1.51",
|
||||
"description": "Sign in to a Factory (Droid) subscription from OpenCode or magpie",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
@@ -19,8 +19,24 @@ export const REFUSED_TOOL_NAMES = new Set([
|
||||
"Shell", "StrReplace",
|
||||
"agent", "bash", "edit", "glob", "grep", "read", "run_shell", "task", "write",
|
||||
"AgentTool", "BashTool", "WriteTool", "bash_tool", "edit_tool", "read_tool", "write_tool",
|
||||
// measured on two real accounts on 2026-11-19 (can1357/oh-my-pi#19553):
|
||||
// web_search, read_file and execute_command too, and every name above
|
||||
// with leading underscores (_read, _web_search), while omp_read passes
|
||||
"web_search", "read_file", "execute_command",
|
||||
])
|
||||
|
||||
// refusedName says whether Factory refuses a tool declared as name: one of
|
||||
// the names above, or one of them behind leading underscores.
|
||||
export function refusedName(name) {
|
||||
if (typeof name !== "string") return false
|
||||
return REFUSED_TOOL_NAMES.has(name) || REFUSED_TOOL_NAMES.has(name.replace(/^_+/, ""))
|
||||
}
|
||||
|
||||
// TAKEN_NAMES are names Factory took as declared in the same probes (droid's
|
||||
// own among them). A request renamed in full (aliasToolNames' every) keeps
|
||||
// these, and mcp__ tools, as they are.
|
||||
export const TAKEN_NAMES = new Set(["Read", "Edit", "Glob", "Grep", "Task", "WebSearch", "TodoWrite", "Execute", "Create"])
|
||||
|
||||
// DROID_NAMES is the tool of Factory's own client, droid, that does the
|
||||
// same job, which Factory takes as declared: a refused tool goes out under
|
||||
// it, unless the request already declares that name or another refused
|
||||
@@ -33,6 +49,7 @@ export const DROID_NAMES = new Map([
|
||||
["read", "Read"], ["read_tool", "Read"],
|
||||
["edit", "Edit"], ["edit_tool", "Edit"],
|
||||
["glob", "Glob"], ["grep", "Grep"],
|
||||
["web_search", "WebSearch"], ["read_file", "Read"], ["execute_command", "Execute"],
|
||||
])
|
||||
|
||||
// A refused tool droid has no name for (Claude Code's TaskCreate, ...), or
|
||||
@@ -109,10 +126,12 @@ function uses(request) {
|
||||
// aliasToolNames renames each declared tool Factory refuses, and every
|
||||
// later mention of it in the request, to a name it takes: droid's own for
|
||||
// the job (Execute for Bash, Create for Write, ...), else a suffixed one,
|
||||
// never one the request already declares. It returns the body and the names
|
||||
// to restore in the reply (alias → original). A body with nothing to rename
|
||||
// goes on byte for byte.
|
||||
export function aliasToolNames(body) {
|
||||
// never one the request already declares. With every, it renames each
|
||||
// declared tool but TAKEN_NAMES and mcp__ ones the same way: Factory's list
|
||||
// keeps growing, and a request refused for a name not on ours yet goes once
|
||||
// more so. It returns the body and the names to restore in the reply
|
||||
// (alias → original). A body with nothing to rename goes on byte for byte.
|
||||
export function aliasToolNames(body, every = false) {
|
||||
const aliases = new Map()
|
||||
const raw = text(body)
|
||||
if (raw == null) return { body, aliases }
|
||||
@@ -120,16 +139,17 @@ export function aliasToolNames(body) {
|
||||
try { request = parseToolJSON(raw) } catch { return { body, aliases } }
|
||||
if (!isObject(request)) return { body, aliases }
|
||||
const decl = declared(request)
|
||||
if (!decl.some(([h, k]) => REFUSED_TOOL_NAMES.has(h[k]))) return { body, aliases }
|
||||
const renames = (name) => refusedName(name) || (every && typeof name === "string" && !TAKEN_NAMES.has(name) && !name.startsWith("mcp__"))
|
||||
if (!decl.some(([h, k]) => renames(h[k]))) return { body, aliases }
|
||||
const taken = new Set(decl.map(([h, k]) => h[k]))
|
||||
const renamed = new Map()
|
||||
for (const [holder, key] of decl) {
|
||||
const name = holder[key]
|
||||
if (!REFUSED_TOOL_NAMES.has(name)) continue
|
||||
if (!renames(name)) continue
|
||||
if (!renamed.has(name)) {
|
||||
let alias = DROID_NAMES.get(name)
|
||||
let alias = DROID_NAMES.get(name) ?? DROID_NAMES.get(name.replace(/^_+/, ""))
|
||||
if (alias == null || taken.has(alias)) alias = suffixed(name)
|
||||
while (taken.has(alias) || REFUSED_TOOL_NAMES.has(alias)) alias += "_"
|
||||
while (taken.has(alias) || refusedName(alias)) alias += "_"
|
||||
taken.add(alias)
|
||||
renamed.set(name, alias)
|
||||
aliases.set(alias, name)
|
||||
@@ -140,6 +160,18 @@ export function aliasToolNames(body) {
|
||||
return { body: JSON.stringify(request), aliases }
|
||||
}
|
||||
|
||||
// toolSet names the tools a request declares, in order, or "" when it
|
||||
// declares none: a set refused until renamed in full is renamed in full
|
||||
// from then on.
|
||||
export function toolSet(body) {
|
||||
const raw = text(body)
|
||||
if (raw == null) return ""
|
||||
let request
|
||||
try { request = parseToolJSON(raw) } catch { return "" }
|
||||
if (!isObject(request)) return ""
|
||||
return declared(request).map(([h, k]) => String(h[k])).join("\n")
|
||||
}
|
||||
|
||||
// restore puts the original names back wherever a reply names a tool: a
|
||||
// "name" field holding an alias (Anthropic's tool_use, OpenAI's function
|
||||
// calls in Responses and chat completions, Gemini's functionCall). A call's
|
||||
|
||||
@@ -1,18 +1,29 @@
|
||||
import { afterEach, expect, test } from "bun:test"
|
||||
import { FactoryAuthPlugin, _internal } from "./index.mjs"
|
||||
import { REFUSED_TOOL_NAMES, suffixed } from "./tool-names.mjs"
|
||||
import { refusedName, suffixed } from "./tool-names.mjs"
|
||||
|
||||
const real = globalThis.fetch
|
||||
afterEach(() => (globalThis.fetch = real))
|
||||
afterEach(() => { globalThis.fetch = real; _internal.renamedInFull.clear() })
|
||||
const A = "https://api.factory.ai/api/llm/a/v1/messages"
|
||||
const R = "https://api.factory.ai/api/llm/o/v1/responses"
|
||||
const C = "https://api.factory.ai/api/llm/o/v1/chat/completions"
|
||||
const schema = { type: "object", properties: { command: { type: "string" } }, required: ["command"] }
|
||||
const sse = (events) => new Response(events.map((e) => `event: ${e.type}\ndata: ${JSON.stringify(e)}\n\n`).join(""), { headers: { "content-type": "text/event-stream" } })
|
||||
|
||||
// SEEN_REFUSED is what real accounts saw Factory refuse as a declared tool
|
||||
// name (plugins#1291, #1306, can1357/oh-my-pi#19553), kept apart from the
|
||||
// plugin's own list so a name it misses shows here.
|
||||
const SEEN_REFUSED = new Set([
|
||||
"Agent", "Bash", "TaskCreate", "TaskGet", "TaskList", "TaskUpdate", "Write", "Shell", "StrReplace",
|
||||
"agent", "bash", "edit", "glob", "grep", "read", "run_shell", "task", "write",
|
||||
"AgentTool", "BashTool", "WriteTool", "bash_tool", "edit_tool", "read_tool", "write_tool",
|
||||
"web_search", "read_file", "execute_command",
|
||||
])
|
||||
const seenRefused = (n) => typeof n === "string" && (SEEN_REFUSED.has(n) || SEEN_REFUSED.has(n.replace(/^_+/, "")))
|
||||
|
||||
// refusing stands in for Factory: a declared refused name is a 403.
|
||||
function refusing(names) {
|
||||
return names.some((n) => REFUSED_TOOL_NAMES.has(n))
|
||||
return names.some((n) => seenRefused(n))
|
||||
? Response.json({ code: "content_policy_rejected", detail: "This request was blocked by Factory's usage policy check." }, { status: 403 })
|
||||
: null
|
||||
}
|
||||
@@ -39,7 +50,9 @@ test("Claude Code's Bash goes out as droid's Execute everywhere and its call com
|
||||
{ role: "user", content: [{ type: "tool_result", tool_use_id: "t1", content: "a.txt" }, { type: "text", text: "Use the Bash tool again." }] },
|
||||
],
|
||||
}
|
||||
const { l, seen } = await loaded((sent) => refusing(sent.tools.map((t) => t.name)) ?? Response.json({
|
||||
// Anthropic's server tool keeps the name Anthropic gives it; whether
|
||||
// Factory's check reads a server tool's name was not probed
|
||||
const { l, seen } = await loaded((sent) => refusing(sent.tools.filter((t) => !t.type).map((t) => t.name)) ?? Response.json({
|
||||
id: "m1", type: "message", role: "assistant", stop_reason: "tool_use",
|
||||
content: [{ type: "text", text: "Running Execute" }, { type: "tool_use", id: "t2", name: "Execute", input: { command: "pwd" } }],
|
||||
}))
|
||||
@@ -152,7 +165,7 @@ test("a refused tool droid has no name for goes out suffixed, the same in every
|
||||
// two refused tools with one droid name: the first takes it
|
||||
expect(names[0]).toEqual([suffixed("TaskCreate"), "Execute", suffixed("run_shell")])
|
||||
expect(names[1]).toEqual(names[0])
|
||||
expect(names[0].some((n) => REFUSED_TOOL_NAMES.has(n))).toBe(false)
|
||||
expect(names[0].some((n) => seenRefused(n))).toBe(false)
|
||||
})
|
||||
|
||||
test("a request without a refused name, and a refused reply, go on as they are", async () => {
|
||||
@@ -200,7 +213,9 @@ test("a stream event whose JSON spans several data lines is restored, CRLF kept"
|
||||
})
|
||||
|
||||
// @a1pha1nthefog (X, 2026-11-19): dsh (DeepSeek Harness) on Factory's Opus
|
||||
// 5.5 got content_policy_rejected on its first turn, the user message "1".
|
||||
// 5.5 got content_policy_rejected on its first turn, the user message "1",
|
||||
// and again on 0.1.50: dsh declares web_search too, which two real accounts
|
||||
// saw refused the same day (can1357/oh-my-pi#19553).
|
||||
// The fixture is dsh 0.2.1-rc.2's own request (dsh headless, captured as it
|
||||
// left dsh): its prompt is 2.5 KB, and it declares bash, edit, glob, grep,
|
||||
// read and write, names Factory refuses. Through magpie it reaches Factory as
|
||||
@@ -209,7 +224,9 @@ const dsh = JSON.parse(await Bun.file(new URL("./testdata/dsh-0.2.1-chat.json",
|
||||
const dshNames = dsh.tools.map((t) => t.function.name)
|
||||
|
||||
test("dsh's own first request declares names Factory refuses", () => {
|
||||
expect(dshNames.filter((n) => REFUSED_TOOL_NAMES.has(n)).sort()).toEqual(["bash", "edit", "glob", "grep", "read", "write"])
|
||||
expect(dshNames.filter((n) => seenRefused(n)).sort()).toEqual(["bash", "edit", "glob", "grep", "read", "web_search", "write"])
|
||||
// and the plugin's list holds every one of them
|
||||
expect(dshNames.filter((n) => seenRefused(n)).every(refusedName)).toBe(true)
|
||||
})
|
||||
|
||||
test("dsh's request on chat completions goes out with no refused name, its prompt as dsh wrote it, and a streamed call comes back as bash", async () => {
|
||||
@@ -221,10 +238,12 @@ test("dsh's request on chat completions goes out with no refused name, its promp
|
||||
{ headers: { "content-type": "text/event-stream" } }))
|
||||
const res = await l.fetch(C, { method: "POST", body: JSON.stringify({ ...dsh, model: "glm-5.3" }) })
|
||||
expect(res.status).toBe(200)
|
||||
// taken on the first try, not after a refusal
|
||||
expect(seen.length).toBe(1)
|
||||
const sent = JSON.parse(seen[0].body)
|
||||
const names = sent.tools.map((t) => t.function.name)
|
||||
expect(names.some((n) => REFUSED_TOOL_NAMES.has(n))).toBe(false)
|
||||
expect(names.filter((n, i) => n !== dshNames[i])).toEqual(["Execute", "Edit", "Glob", "Grep", "Read", "Create"])
|
||||
expect(names.some((n) => seenRefused(n))).toBe(false)
|
||||
expect(names.filter((n, i) => n !== dshNames[i])).toEqual(["Execute", "Edit", "Glob", "Grep", "Read", "WebSearch", "Create"])
|
||||
// only the names change: descriptions, schemas and dsh's own text stay
|
||||
expect(sent.tools.map((t) => t.function.parameters)).toEqual(dsh.tools.map((t) => t.function.parameters))
|
||||
expect(sent.tools.map((t) => t.function.description)).toEqual(dsh.tools.map((t) => t.function.description))
|
||||
@@ -248,6 +267,71 @@ test("dsh's request translated to Messages for a Claude model goes out with no r
|
||||
}
|
||||
const res = await l.fetch(A, { method: "POST", body: JSON.stringify(body) })
|
||||
expect(res.status).toBe(200)
|
||||
expect(JSON.parse(seen[0].body).tools.map((t) => t.name).some((n) => REFUSED_TOOL_NAMES.has(n))).toBe(false)
|
||||
expect(JSON.parse(seen[0].body).tools.map((t) => t.name).some((n) => seenRefused(n))).toBe(false)
|
||||
expect((await res.json()).content[0].name).toBe("write")
|
||||
})
|
||||
|
||||
test("the names two real accounts saw refused on 11-19 go out as droid's, and any of them behind leading underscores is refused too", async () => {
|
||||
expect(["web_search", "read_file", "execute_command", "_read", "__bash", "_web_search"].every(refusedName)).toBe(true)
|
||||
expect(["omp_read", "readfile", "run_bash", "shell_command", "Read", "WebSearch", "web_fetch"].some(refusedName)).toBe(false)
|
||||
const { l, seen } = await loaded((sent) => refusing(sent.tools.map((t) => t.function.name)) ?? Response.json({
|
||||
id: "c1", object: "chat.completion", choices: [{ index: 0, finish_reason: "tool_calls", message: { role: "assistant", content: null,
|
||||
tool_calls: [{ id: "x", type: "function", function: { name: "WebSearch", arguments: "{}" } }] } }],
|
||||
}))
|
||||
const tools = ["web_search", "read_file", "execute_command", "_grep"].map((name) => ({ type: "function", function: { name, parameters: schema } }))
|
||||
const res = await l.fetch(C, { method: "POST", body: JSON.stringify({ model: "glm-5.3", tools, messages: [{ role: "user", content: "hi" }] }) })
|
||||
expect(res.status).toBe(200)
|
||||
expect(seen.length).toBe(1)
|
||||
expect(JSON.parse(seen[0].body).tools.map((t) => t.function.name)).toEqual(["WebSearch", "Read", "Execute", "Grep"])
|
||||
expect((await res.json()).choices[0].message.tool_calls[0].function.name).toBe("web_search")
|
||||
})
|
||||
|
||||
// Factory's list grows without notice: a fake that refuses a name the
|
||||
// plugin doesn't list stands in for the next one it adds.
|
||||
const refusingAlso = (extra) => (names) => names.some((n) => seenRefused(n) || extra.includes(n))
|
||||
? Response.json({ code: "content_policy_rejected", detail: "This request was blocked by Factory's usage policy check." }, { status: 403 })
|
||||
: null
|
||||
|
||||
test("a request refused for a name not listed yet goes once more with every tool renamed, and that tool set goes renamed from then on", async () => {
|
||||
const refuse = refusingAlso(["web_fetch"])
|
||||
const { l, seen } = await loaded((sent) => refuse(sent.tools.map((t) => t.function.name)) ?? Response.json({
|
||||
id: "c1", object: "chat.completion", choices: [{ index: 0, finish_reason: "tool_calls", message: { role: "assistant", content: null,
|
||||
tool_calls: [{ id: "x", type: "function", function: { name: JSON.parse(seen.at(-1).body).tools[1].function.name, arguments: "{}" } }] } }],
|
||||
}))
|
||||
const body = JSON.stringify({ ...dsh, model: "glm-5.3", stream: false })
|
||||
const res = await l.fetch(C, { method: "POST", body })
|
||||
expect(res.status).toBe(200)
|
||||
expect(seen.length).toBe(2)
|
||||
const first = JSON.parse(seen[0].body).tools.map((t) => t.function.name)
|
||||
const second = JSON.parse(seen[1].body).tools.map((t) => t.function.name)
|
||||
expect(first).toContain("web_fetch")
|
||||
expect(second).not.toContain("web_fetch")
|
||||
expect(second).toContain(suffixed("web_fetch"))
|
||||
// droid's names stay as they are; dsh's others are renamed too
|
||||
expect(second).toContain("Execute")
|
||||
expect(second.filter((n) => dshNames.includes(n))).toEqual([])
|
||||
// only names change
|
||||
expect(JSON.parse(seen[1].body).tools.map((t) => t.function.description)).toEqual(dsh.tools.map((t) => t.function.description))
|
||||
expect((await res.json()).choices[0].message.tool_calls[0].function.name).toBe("create_goal")
|
||||
// the next turn of the same tool set is renamed in full at once
|
||||
const again = await l.fetch(C, { method: "POST", body })
|
||||
expect(again.status).toBe(200)
|
||||
expect(seen.length).toBe(3)
|
||||
expect(JSON.parse(seen[2].body).tools.map((t) => t.function.name)).toEqual(second)
|
||||
})
|
||||
|
||||
test("refused again with every tool renamed, it is the request's content, and that refusal is the answer after two tries", async () => {
|
||||
const { l, seen } = await loaded(() => Response.json({ code: "content_policy_rejected", detail: "This request was blocked by Factory's usage policy check." }, { status: 403 }))
|
||||
const res = await l.fetch(C, { method: "POST", body: JSON.stringify({ ...dsh, model: "glm-5.3", stream: false }) })
|
||||
expect(res.status).toBe(400)
|
||||
expect((await res.json()).error.code).toBe("content_policy_rejected")
|
||||
expect(seen.length).toBe(2)
|
||||
expect(_internal.renamedInFull.size).toBe(0)
|
||||
})
|
||||
|
||||
test("a refused request that declares no tools is not sent again", async () => {
|
||||
const { l, seen } = await loaded(() => Response.json({ code: "content_policy_rejected", detail: "blocked" }, { status: 403 }))
|
||||
const res = await l.fetch(C, { method: "POST", body: JSON.stringify({ model: "glm-5.3", messages: [{ role: "user", content: "hi" }] }) })
|
||||
expect(res.status).toBe(400)
|
||||
expect(seen.length).toBe(1)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user