From c5a231f13dd9d71f37582465defa605b53a9efb3 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 24 Nov 2026 06:51:58 +0800 Subject: [PATCH] fix(cli): print data keys as they are and label refusal details as details Operator text output turned every object key into a label, so data keys such as worker names ("email-gateway") and model IDs ("@cf/zai-org/glm-5.3") had their hyphens replaced with spaces. Keys that are not camelCase or snake_case field names now print unchanged. A failed platform request with details always printed "Partial result:", even for a plain refusal such as the self-hosted capability error. The CLI now prints "Partial result:" only for partial failures and "Details:" for everything else. Co-Authored-By: Claude Opus 5.5 --- packages/void/src/cli/cli-main.ts | 13 ++++++- packages/void/src/cli/operator-cmd.ts | 17 +++++++++ .../test/integration/operator-cli.test.ts | 37 +++++++++++++++++++ packages/void/test/unit/operator-cli.test.ts | 21 ++++++++++- 4 files changed, 86 insertions(+), 2 deletions(-) diff --git a/packages/void/src/cli/cli-main.ts b/packages/void/src/cli/cli-main.ts index df41fe534..39bb35b1f 100644 --- a/packages/void/src/cli/cli-main.ts +++ b/packages/void/src/cli/cli-main.ts @@ -100,7 +100,7 @@ async function runSubcommandGroup( const platformMessage = message.replace(/^platform:/, pc.bold(pc.red('platform:'))); console.error( err instanceof OperatorClientError && err.details !== undefined - ? `${platformMessage}\nPartial result:\n${JSON.stringify(err.details, null, 2)}` + ? `${platformMessage}\n${isPartialResult(err) ? 'Partial result' : 'Details'}:\n${JSON.stringify(err.details, null, 2)}` : platformMessage, ); } else { @@ -110,6 +110,17 @@ async function runSubcommandGroup( } } +// A refusal can carry details (blockers, a revision, a capability). Only a +// request that did part of its work returns a partial result. +function isPartialResult(err: OperatorClientError): boolean { + return ( + err.code === 'partial_failure' || + (typeof err.details === 'object' && + err.details !== null && + (err.details as { partial?: unknown }).partial === true) + ); +} + const args = process.argv.slice(2); const command = args[0]; const helpPath = getHelpPath(args); diff --git a/packages/void/src/cli/operator-cmd.ts b/packages/void/src/cli/operator-cmd.ts index 9876af11a..3e17e84a1 100644 --- a/packages/void/src/cli/operator-cmd.ts +++ b/packages/void/src/cli/operator-cmd.ts @@ -110,7 +110,24 @@ const LABEL_WORDS: Record = { urls: 'URLs', }; +// API field names are camelCase or snake_case. Any other key is data, such as +// a worker name ('email-gateway') or a model ID ('@cf/zai-org/glm-5.3'), and +// prints as it is. +function isFieldName(key: string): boolean { + for (const char of key) { + const letterOrDigit = + (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9'); + if (!letterOrDigit && char !== '_') { + return false; + } + } + return true; +} + function fieldLabel(key: string): string { + if (!isFieldName(key)) { + return key; + } const words = key .replace(/([a-z0-9])([A-Z])/g, '$1 $2') .split(/[\s_-]+/) diff --git a/packages/void/test/integration/operator-cli.test.ts b/packages/void/test/integration/operator-cli.test.ts index 778b01aa8..ca710a083 100644 --- a/packages/void/test/integration/operator-cli.test.ts +++ b/packages/void/test/integration/operator-cli.test.ts @@ -329,6 +329,43 @@ describe('operator CLI (real subprocess and HTTP)', () => { expect(result.stderr).toContain('"status": "skipped"'); expect(requests).toHaveLength(2); }); + it('prints data keys such as worker names as they are', async () => { + reply = () => ({ + body: { + dryRun: true, + action: 'worker.rollback-all', + target: 'production', + versions: { 'email-gateway': 'version-gateway', 'void-api-staging': 'version-api' }, + createdAt: '2026-01-01T00:00:00Z', + }, + }); + + const result = await run(['worker', 'rollback-all', '--plan']); + + expect(result.code).toBe(0); + expect(result.stdout).toContain('email-gateway: version-gateway'); + expect(result.stdout).toContain('void-api-staging: version-api'); + expect(result.stdout).not.toContain('Email gateway'); + expect(result.stdout).toContain('Created at: 2026-01-01T00:00:00Z'); + }); + it('labels refusal details as details, not as a partial result', async () => { + reply = () => ({ + status: 501, + body: { + error: 'capability_unavailable', + message: 'Manage this self-hosted Void platform with `void platform upgrade`.', + details: { capability: 'hosted-platform-operations' }, + }, + }); + + const result = await run(['worker', 'list']); + + expect(result.code).toBe(1); + expect(result.stderr).toContain('Manage this self-hosted Void platform'); + expect(result.stderr).toContain('Details:'); + expect(result.stderr).toContain('"capability": "hosted-platform-operations"'); + expect(result.stderr).not.toContain('Partial result'); + }); it('exchanges piped API sessions only on explicit auth token invocation', async () => { reply = () => ({ body: { diff --git a/packages/void/test/unit/operator-cli.test.ts b/packages/void/test/unit/operator-cli.test.ts index 534fe905a..a8ba9b7d2 100644 --- a/packages/void/test/unit/operator-cli.test.ts +++ b/packages/void/test/unit/operator-cli.test.ts @@ -16,7 +16,7 @@ import { saveOperatorToken, } from '../../src/cli/operator-auth.ts'; import { OperatorClient } from '../../src/cli/operator-client.ts'; -import { followOperatorLogs, runOperatorCommand } from '../../src/cli/operator-cmd.ts'; +import { followOperatorLogs, humanLines, runOperatorCommand } from '../../src/cli/operator-cmd.ts'; import { parsePlatformArgs } from '../../src/cli/platform-args.ts'; import { getActivePlatformConnection, @@ -65,6 +65,25 @@ function connect(apiUrl: string) { }); } +describe('operator text output labels', () => { + it('humanizes field names but prints data keys as they are', () => { + expect( + humanLines({ + createdAt: 'now', + project_id: 'proj_1', + picked: { '@cf/zai-org/glm-5.3': 1, 'email-gateway': 2, 'api.example.com': 3 }, + }), + ).toEqual([ + 'Created at: now', + 'Project ID: proj_1', + 'Picked:', + ' @cf/zai-org/glm-5.3: 1', + ' email-gateway: 2', + ' api.example.com: 3', + ]); + }); +}); + describe('operator mutation completion output', () => { async function runMutation(result: Record, flags: Array = []) { connect('https://one.example');