Files
cleveragents-core/features/cli_json_envelope.feature
T
freemo a0df5a4cd0
CI / lint (pull_request) Successful in 27s
CI / typecheck (pull_request) Successful in 57s
CI / security (pull_request) Successful in 1m2s
CI / quality (pull_request) Successful in 34s
CI / build (pull_request) Successful in 23s
CI / helm (pull_request) Successful in 26s
CI / unit_tests (pull_request) Failing after 7m7s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Failing after 11m8s
CI / integration_tests (pull_request) Failing after 22m44s
CI / coverage (pull_request) Successful in 10m50s
CI / status-check (pull_request) Failing after 2s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 57m6s
fix(cli): wrap format_output() in spec-required JSON/YAML envelope across all CLI commands
Implements the spec-required JSON/YAML output envelope for all CLI commands
that use format_output(). The envelope structure is:

  {
    "command": "<command that was run>",
    "status": "ok" | "warn" | "error",
    "exit_code": 0,
    "data": { ... command-specific payload ... },
    "timing": { "duration_ms": 123 },
    "messages": [{ "level": "ok", "text": "..." }]
  }

Changes:
- Add _build_envelope() helper to construct the spec-required envelope
- Add optional command, status, exit_code, messages parameters to format_output()
- Wrap json/yaml output in the envelope; plain/table/rich/color unchanged
- Add timing measurement (duration_ms) to all json/yaml outputs
- Add new BDD feature file (cli_json_envelope.feature) with 14 scenarios
  testing envelope field presence, values, and data payload
- Update 14 existing step files to unwrap the envelope when checking
  specific data keys (backward-compatible via _unwrap_envelope() helper)

Closes #3431
2026-04-05 19:48:40 +00:00

86 lines
4.2 KiB
Gherkin

Feature: CLI JSON/YAML output envelope structure
As a programmatic consumer of the CleverAgents CLI
I want all --format json and --format yaml outputs to include the spec-required envelope
So that I can reliably parse command, status, exit_code, data, timing, and messages fields
Background:
Given a CLI output format test runner
And a mocked lifecycle service for format tests
# ── Envelope field presence ──────────────────────────────────────────────
Scenario: JSON output includes all required envelope fields
Given there are actions for format testing
When I run action list with --format json
Then the JSON envelope should contain field "command"
And the JSON envelope should contain field "status"
And the JSON envelope should contain field "exit_code"
And the JSON envelope should contain field "data"
And the JSON envelope should contain field "timing"
And the JSON envelope should contain field "messages"
Scenario: YAML output includes all required envelope fields
Given there are actions for format testing
When I run action list with --format yaml
Then the YAML envelope should contain field "command"
And the YAML envelope should contain field "status"
And the YAML envelope should contain field "exit_code"
And the YAML envelope should contain field "data"
And the YAML envelope should contain field "timing"
And the YAML envelope should contain field "messages"
# ── Envelope field values ────────────────────────────────────────────────
Scenario: JSON envelope status is "ok" for successful commands
Given there are actions for format testing
When I run action list with --format json
Then the JSON envelope status should be "ok"
Scenario: JSON envelope exit_code is 0 for successful commands
Given there are actions for format testing
When I run action list with --format json
Then the JSON envelope exit_code should be 0
Scenario: JSON envelope timing contains duration_ms
Given there are actions for format testing
When I run action list with --format json
Then the JSON envelope timing should contain "duration_ms"
Scenario: JSON envelope messages is a non-empty list
Given there are actions for format testing
When I run action list with --format json
Then the JSON envelope messages should be a non-empty list
# ── Data field contains actual payload ──────────────────────────────────
Scenario: JSON envelope data field contains actor list payload
Given there are actions for format testing
When I run action list with --format json
Then the JSON envelope data should contain actor records
Scenario: YAML envelope data field contains actor list payload
Given there are actions for format testing
When I run action list with --format yaml
Then the YAML envelope data should contain actor records
# ── format_output() direct call envelope ────────────────────────────────
Scenario: Direct format_output call with json wraps data in envelope
When I call format_output with a dict and format json
Then the format result should be valid JSON dict
And the JSON result data field should contain original keys
Scenario: Direct format_output call with yaml wraps data in envelope
When I call format_output with a dict and format yaml
Then the format result should be valid YAML dict
And the YAML result data field should contain original keys
Scenario: Direct format_output call with command name sets envelope command
When I call format_output with command name "agents actor list" and format json
Then the JSON envelope command should be "agents actor list"
Scenario: Plain format does not wrap in envelope
When I call format_output with a dict and format plain
Then the format result should contain plain key-value pairs
And the plain result should not contain envelope keys