test(ptc): migrate remaining inspection consumers

This commit is contained in:
_Kerman committed 2026-11-09 12:48:09 +08:00
1 parent 0e12a87b02
commit 71b5e93457
12 files changed
+23 -22

No files matched your search

@@ -46,7 +46,7 @@ it.for(['standard', 'ptc'] as const)('keeps %s plugin changes pending until the
} catch (error) { fixtureError = error }
const call = mode === 'ptc'
? { type: 'tool_use', id: `manage-${requests.length}`, name: 'run_code', input: {
code: `return await tools.plugin_manager(${JSON.stringify(args)});`, description: 'Disable web tools after restart',
code: `Harness.inspect(await tools.plugin_manager(${JSON.stringify(args)}));`, description: 'Disable web tools after restart',
} }
: { type: 'tool_use', id: `manage-${requests.length}`, name: 'plugin_manager', input: args }
response.writeHead(200, { 'content-type': 'text/event-stream' })
+1 -1
View File
@@ -796,7 +796,7 @@ describe('web e2e: navigation & panes over a rich seeded session', () => {
const callId = ToolCallId('long-ptc-result')
const call = agent.session.append('tool/call', {
turn: 3, step: 1, callId, name: 'run_code',
arguments: JSON.stringify({ code: 'console.log("PTC output")', description: 'Long program output' }),
arguments: JSON.stringify({ code: 'Harness.inspect("PTC output")', description: 'Long program output' }),
})
await page.getByRole('tab', { name: 'Trajectory' }).click()
await page.locator('tr[data-kind="tool"]').filter({ hasText: 'Long program output' }).click()
@@ -62,7 +62,7 @@ async function executeShell(text: string, nested: boolean, name = 'bash', maxInl
if (tool === undefined) throw new Error('missing fixture binding')
const blocks = await tool(shellArgs)
expect(blocks).toEqual([{ type: 'text', text }])
return { logs: [], value: true }
return { logs: ['true'] }
}
}
await ctx.plugin(BindingRuntime)
@@ -86,7 +86,7 @@ async function executeShell(text: string, nested: boolean, name = 'bash', maxInl
signal: new AbortController().signal,
name: nested ? 'run_code' : name,
arguments: nested ? {
code: `const blocks = await tools.${name}(${JSON.stringify(shellArgs)}); return blocks[0].text === ${JSON.stringify(text)};`,
code: `const blocks = await tools.${name}(${JSON.stringify(shellArgs)}); Harness.inspect(blocks[0].text === ${JSON.stringify(text)});`,
description: 'Dispatch shell fixture through the tool pipeline',
} : shellArgs,
})
@@ -95,7 +95,7 @@ async function executeShell(text: string, nested: boolean, name = 'bash', maxInl
let block: ToolResultNode
if (nested) {
expect(result.value).toMatchObject({ result: true })
expect(result.value).toMatchObject({ logs: ['true'] })
const dispatches = session.snapshotEvents().filter(event => event.type === 'tool/ptc-dispatch')
expect(dispatches).toHaveLength(1)
const event = dispatches[0]!
@@ -135,7 +135,7 @@ it('separates facade options from raw RPC parameters', () => {
it('documents facade initialization, emitted observations, and separate key arguments', () => {
expect(COMMON_GUIDANCE).toContain('host-provided bridge initialization once')
expect(COMMON_GUIDANCE).toContain('not a preinstalled global')
expect(COMMON_GUIDANCE).toContain('void await')
expect(COMMON_GUIDANCE).toContain('Observations emit through Harness.inspect')
expect(COMMON_GUIDANCE).toContain('do not pack them into a chord string')
expect(COMMON_GUIDANCE).toContain('perform a left-button double-click')
})
@@ -109,7 +109,7 @@ it.skipIf(process.platform === 'win32')('delivers a valid PNG larger than 4 MiB
if (this.requests.length === 1) {
const code = 'const app = await tools.cua({ method: "getApp", params: { selector: "9" } }); '
+ 'const result = await tools.cua({ method: "screenshot", params: { appHandle: app.appHandle, windowId: 7 } }); '
+ 'return { mimeType: result.mimeType, encodedLength: result.data.length };'
+ 'Harness.inspect({ mimeType: result.mimeType, encodedLength: result.data.length });'
const call = { type: 'tool-call' as const, id: ToolCallId('large-image-ptc'), name: 'run_code',
arguments: JSON.stringify({ code, description: 'Inspect the generated large screenshot' }),
}
@@ -163,7 +163,7 @@ class PatchPtcRuntime extends PtcRuntime {
return { ...request, cwd: request.cwd ?? process.cwd(), timeoutMs: request.timeoutMs ?? 120_000 }
}
async run(request: PtcRunSpec) {
return { logs: [], value: await request.bindings[0]!.functions.apply_patch!({ input: this.patch }) }
return { logs: [JSON.stringify(await request.bindings[0]!.functions.apply_patch!({ input: this.patch }))] }
}
}
@@ -179,10 +179,10 @@ it('dispatches native and PTC patch calls with identical values', async () => {
await t.file('a', 'old\n')
const ptc = await executeModelToolFixture(p.ctx, {
signal: p.exec.signal, callId: p.exec.callId, agent: { ctx: p.ctx, session: { header: { cwd: t.workspace }, append() {} } } as never,
name: 'run_code', arguments: { code: 'return await tools.apply_patch({patch})', description: 'Apply the fixture patch' },
name: 'run_code', arguments: { code: 'Harness.inspect(JSON.stringify(await tools.apply_patch({patch})))', description: 'Apply the fixture patch' },
})
if (ptc.isError) throw new Error(JSON.stringify(ptc))
expect(ptc.value).toEqual({ logs: [], result: native.value })
expect(ptc.value).toEqual({ logs: [JSON.stringify(native.value)] })
expect(await t.bytes('a')).toBe('new\n')
})
@@ -18,7 +18,7 @@ class BindingProbe extends PtcRuntime {
readonly language = 'typescript'
readonly isolation = 'in-process-test'
behavior: (spec: PtcRunSpec) => Promise<PtcRunResult> = async spec => ({
logs: [], value: Object.keys(spec.bindings[0]!.functions).sort(),
logs: [JSON.stringify(Object.keys(spec.bindings[0]!.functions).sort())],
})
resolve(request: PtcRunRequest): PtcRunSpec {
@@ -81,7 +81,7 @@ describe('MCP resource tools', () => {
}
if (mode !== 'native') {
expect(await call(ctx, 'run_code', { code: 'inspect bindings', description: 'Inspect bindings' }))
.toMatchObject({ isError: false, value: { result: [] } })
.toMatchObject({ isError: false, value: { logs: ['[]'] } })
}
})
@@ -219,9 +219,9 @@ describe('MCP resource tools', () => {
expect(result.isError).toBe(false)
expect(request).toHaveBeenCalledOnce()
expect(renderPrompt(await ctx.systemPrompt.assemble())).not.toContain('mcp')
runtime.behavior = async spec => ({ logs: [], value: Object.keys(spec.bindings[0]!.functions) })
runtime.behavior = async spec => ({ logs: [JSON.stringify(Object.keys(spec.bindings[0]!.functions))] })
expect(await call(ctx, 'run_code', { code: 'inspect bindings', description: 'Inspect bindings' }))
.toMatchObject({ isError: false, value: { result: [] } })
.toMatchObject({ isError: false, value: { logs: ['[]'] } })
})
it('retains tools for a configured provider while its requests fail', async () => {
@@ -85,9 +85,10 @@ class ProgramFixture extends PtcRuntime {
}
async run(request: PtcRunRequest): Promise<PtcRunResult> {
expect(request.program).toBe('return await tools.echo({ value: "ptc" })')
expect(request.program).toBe('Harness.inspect(await tools.echo({ value: "ptc" }))')
const value = await request.bindings[0]!.functions.echo!({ value: 'ptc' })
return { logs: [], value }
if (typeof value !== 'string') throw new Error('expected a string echo result')
return { logs: [value] }
}
}
@@ -140,7 +141,7 @@ it.each([true, false])('loads cordis.yml executor presets with runtime availabil
})).toMatchObject({ isError: false, value: 'echo:native' })
expect(await executeModelToolFixture(ctx, {
agent: ptc, name: 'run_code', callId: ToolCallId('program'), signal,
arguments: { code: 'return await tools.echo({ value: "ptc" })', description: 'Echo through the program' },
arguments: { code: 'Harness.inspect(await tools.echo({ value: "ptc" }))', description: 'Echo through the program' },
})).toMatchObject({ isError: false, content: [{ type: 'text', text: 'echo:ptc' }] })
expect(ptc.session.snapshotEvents().find(event => event.type === 'tool/ptc-dispatch')).toMatchObject({
data: { name: 'echo', isError: false, content: [{ type: 'text', text: 'echo:ptc' }] },
@@ -26,7 +26,7 @@ class SkillProgram extends PtcRuntime {
readonly isolation = 'fixture'
resolve(request: PtcRunRequest): PtcRunSpec { return { ...request, cwd: process.cwd(), timeoutMs: 120_000 } }
async run(request: PtcRunSpec) {
return { logs: [], value: await request.bindings[0]!.functions.skill!({ name: request.program }) }
return { logs: [JSON.stringify(await request.bindings[0]!.functions.skill!({ name: request.program }))] }
}
}
@@ -198,11 +198,11 @@ describe('multimodal recovery through real providers', () => {
? 'await Promise.all([tools.ends({}), tools.middle({}), tools.small({})])'
: '[await tools.ends({}), await tools.middle({}), await tools.small({})]'
const result = await execute('run_code', {
code: `const [ends, middle, small] = ${calls}; return { ends: ends.content[2].text.length, middle: middle.content[0].text.length, small: small.content[0].text.length };`,
code: `const [ends, middle, small] = ${calls}; Harness.inspect(JSON.stringify({ ends: ends.content[2].text.length, middle: middle.content[0].text.length, small: small.content[0].text.length }));`,
description: 'Inspect independent image result budgets',
})
expect(result.isError).toBe(false)
expect(result.value).toMatchObject({ result: { ends: LONG.length, middle: LONG.length, small: SMALL.length } })
expect(result.value).toMatchObject({ logs: [JSON.stringify({ ends: LONG.length, middle: LONG.length, small: SMALL.length })] })
const dispatches = session.snapshotEvents().filter(event => event.type === 'tool/ptc-dispatch').map(event => event.data)
expect(dispatches).toHaveLength(3)
for (const dispatch of dispatches) expect(cost(dispatch.content)).toBeLessThanOrEqual(CAP)
+1 -1
View File
@@ -94,7 +94,7 @@ try {
const bindings = [{ global: 'tools', functions: { echo: async (input: unknown) => String(input) } }]
const policy = { mode: 'danger-full-access', workspaceRoot: root } as const
const result = await runtime.run(runtime.resolve({
program: 'const fs=await import("node:fs/promises"); await fs.writeFile("ptc.txt","embedded"); console.log("worker-output"); return {value:await tools.echo("bridge"),env:Object.keys(process.env),executable:process.execPath,cwd:process.cwd()};',
program: 'const fs=await import("node:fs/promises"); await fs.writeFile("ptc.txt","embedded"); Harness.inspect("worker-output"); return {value:await tools.echo("bridge"),env:Object.keys(process.env),executable:process.execPath,cwd:process.cwd()};',
bindings, cwd: root, sandboxPolicy: policy,
}))
assert.equal(result.error, undefined, JSON.stringify(result))
+1 -1
View File
@@ -536,7 +536,7 @@ def completion_chunks(body: dict[str, object]) -> list[dict[str, object]]:
return tool_call_chunks(
"call-code-worker",
"run_code",
{"code": "return 6 * 7", "description": "Compute the smoke value"},
{"code": "Harness.inspect(6 * 7)", "description": "Compute the smoke value"},
)
if prompt == WORKFLOW_PROMPT:
assert_advertised_tool(body, "workflow")