test(mode): pin the mode-both composition — one visibility rule, both surfaces

A review finding claimed plan mode under the registry's 'both'
presentation leaves non-allowlisted native schemas on the wire. The
claim misreads the filter predicate — 'keep visible plus run_code' IS
'drop everything else' — and the SDK re-render shares the same visible()
predicate, which is precisely the remedy the finding requests. This
test refutes it empirically on unchanged code (first run green) and
stays as the regression pin: plan + both = [exit_plan_mode, read,
run_code] on the wire, read documented and write absent in the SDK.
This commit is contained in:
kingwl
2026-07-10 21:24:07 +08:00
parent e2628442fa
commit bedd908331

View File

@@ -379,6 +379,29 @@ describe('the soft layer', () => {
expect(sdk).not.toContain('write(args:')
})
it('filters native wire schemas by the allowlist under mode both, alongside the pruned SDK', async () => {
class FakeRuntime extends CodeRuntime {
readonly language = 'typescript'
readonly isolation = 'fake'
run(_request: CodeRunRequest): Promise<CodeRunResult> { return Promise.resolve({ logs: [] }) }
}
const ctx = new Context()
await ctx.plugin(SystemPrompt)
await ctx.plugin(ToolRegistry, { mode: 'both' })
await ctx.plugin(FakeRuntime)
await ctx.plugin(ModesService)
registerNamedTools(ctx, ['read', 'write'])
const agent = agentWithSession()
agent.session.append('mode/set', { mode: PLAN_MODE })
const assembly = await ctx.systemPrompt.assemble({ agent })
// ONE visibility rule covers both surfaces: the denied write is absent
// from the native wire schemas AND from the SDK declaration.
expect(assembly.tools.map(tool => tool.name).sort()).toEqual(['exit_plan_mode', 'read', 'run_code'])
const sdk = assembly.sections.find(section => section.name === 'tools:sdk')?.text ?? ''
expect(sdk).toContain('read(args:')
expect(sdk).not.toContain('write(args:')
})
it('leaves the Code Mode SDK section untouched in the default mode', async () => {
class FakeRuntime extends CodeRuntime {
readonly language = 'typescript'