mirror of
https://github.com/stablyai/orca.git
synced 2026-10-06 16:02:25 +00:00
fix(cli): preserve primitive success results in JSON output
Check for an object before inspecting screenshot fields so primitive success results remain printable. Related: https://github.com/stablyai/orca/pull/14735 Co-authored-by: Neil <neil@stably.ai> Co-authored-by: VXNCXNX <VXNCXNX@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,57 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { ComputerActionResult } from '../shared/runtime-types'
|
||||
import { formatComputerAction } from './computer-format'
|
||||
import { formatComputerAction, prepareComputerCliJsonResult } from './computer-format'
|
||||
import { printResult } from './format'
|
||||
|
||||
describe('prepareComputerCliJsonResult', () => {
|
||||
it.each([
|
||||
'Physical size: 1440x3200\n',
|
||||
'33',
|
||||
'screenshotStatus',
|
||||
'',
|
||||
42,
|
||||
-1,
|
||||
0,
|
||||
true,
|
||||
false,
|
||||
null
|
||||
])('preserves successful primitive JSON output for %j', (result) => {
|
||||
const response = {
|
||||
id: 'req-primitive',
|
||||
ok: true as const,
|
||||
result,
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
}
|
||||
const formatter = vi.fn(() => 'unused')
|
||||
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => undefined)
|
||||
|
||||
try {
|
||||
expect(prepareComputerCliJsonResult(response)).toBe(response)
|
||||
printResult(response, true, formatter)
|
||||
expect(logSpy).toHaveBeenCalledOnce()
|
||||
expect(logSpy).toHaveBeenCalledWith(JSON.stringify(response, null, 2))
|
||||
expect(formatter).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
logSpy.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ result: {} },
|
||||
{ result: [] },
|
||||
{ result: { screenshotStatus: {} } },
|
||||
{ result: { screenshot: { data: 'cG5n', format: 'png' } } }
|
||||
])('preserves object results without a computer screenshot: %j', ({ result }) => {
|
||||
const response = {
|
||||
id: 'req-object',
|
||||
ok: true as const,
|
||||
result,
|
||||
_meta: { runtimeId: 'runtime-1' }
|
||||
}
|
||||
|
||||
expect(prepareComputerCliJsonResult(response)).toBe(response)
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatComputerAction', () => {
|
||||
it('does not treat legacy action results without metadata as completed', () => {
|
||||
|
||||
@@ -63,7 +63,11 @@ export function prepareComputerCliJsonResult<TResult>(
|
||||
screenshotStatus?: unknown
|
||||
}
|
||||
}
|
||||
if (!record.result || !('screenshotStatus' in record.result)) {
|
||||
if (
|
||||
!record.result ||
|
||||
typeof record.result !== 'object' ||
|
||||
!('screenshotStatus' in record.result)
|
||||
) {
|
||||
return response
|
||||
}
|
||||
const screenshot = record.result?.screenshot
|
||||
|
||||
Reference in New Issue
Block a user