Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/void/src/cli/cli-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function runSubcommandGroup<T>(
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 {
Expand All @@ -110,6 +110,17 @@ async function runSubcommandGroup<T>(
}
}

// 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);
Expand Down
17 changes: 17 additions & 0 deletions packages/void/src/cli/operator-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,24 @@ const LABEL_WORDS: Record<string, string> = {
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_-]+/)
Expand Down
37 changes: 37 additions & 0 deletions packages/void/test/integration/operator-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
21 changes: 20 additions & 1 deletion packages/void/test/unit/operator-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<string, unknown>, flags: Array<string> = []) {
connect('https://one.example');
Expand Down