From c39f5f25fcc9b2a25fa6e189eee19e93cf98fde2 Mon Sep 17 00:00:00 2001 From: Neil <4138956+nwparker@users.noreply.github.com> Date: Sat, 3 Oct 2026 00:50:46 -0700 Subject: [PATCH] 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 Co-authored-by: VXNCXNX --- src/cli/computer-format.test.ts | 55 +++++++++++++++++++++++++++++++-- src/cli/computer-format.ts | 6 +++- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/cli/computer-format.test.ts b/src/cli/computer-format.test.ts index d5385c0dec7..2945ba53729 100644 --- a/src/cli/computer-format.test.ts +++ b/src/cli/computer-format.test.ts @@ -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', () => { diff --git a/src/cli/computer-format.ts b/src/cli/computer-format.ts index 75833f69783..3ec34c9cfbc 100644 --- a/src/cli/computer-format.ts +++ b/src/cli/computer-format.ts @@ -63,7 +63,11 @@ export function prepareComputerCliJsonResult( 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