2 Commits

Author SHA1 Message Date
YeonGyu-Kim
290ab7e41f feat: #173 — wrap_json_envelope() applied to all 13 clawable commands (LOOP CLOSED)
Completes the coverage → enforcement → documentation → alignment cycle.
Every clawable command now emits the canonical JSON envelope per SCHEMAS.md:

Common fields (now real in output):
  - timestamp (ISO 8601 UTC)
  - command (argv[1])
  - exit_code (0/1/2)
  - output_format ('json')
  - schema_version ('1.0')

13 commands wrapped:
  - list-sessions, delete-session, load-session, flush-transcript
  - show-command, show-tool
  - exec-command, exec-tool, route, bootstrap
  - command-graph, tool-pool, bootstrap-graph

Implementation:
- Added wrap_json_envelope() helper in src/main.py
- Wrapped all 18 JSON output paths (13 success + 5 error paths)
- Applied exit_code=1 to error/not-found envelopes
- Kept text mode byte-identical (backward compat preserved)

Test updates:
- 3 skipped common-field tests now pass automatically
- 3 existing tests updated to verify common envelope fields while preserving command-specific field checks
- test_list_sessions_cli_runs, test_delete_session_cli_idempotent,
  test_load_session_cli::test_json_mode_on_success

Full suite: 179 → 182 passing (+3 activated from skipped), zero regression.

Loop completion:
  Coverage (#167-#170)        All 13 commands accept --output-format
  Enforcement (#171)          CI blocks new commands without --output-format
  Documentation (#172)        SCHEMAS.md defines envelope contract
  Alignment (#173 this)       Actual output matches SCHEMAS.md contract

Example output now:
  $ claw list-sessions --output-format json
  {
    "timestamp": "2026-04-22T10:34:12Z",
    "command": "list-sessions",
    "exit_code": 0,
    "output_format": "json",
    "schema_version": "1.0",
    "sessions": ["alpha", "bravo"],
    "count": 2
  }

Closes ROADMAP #173. Protocol is now documented AND real.
Claws can build ONE error handler, ONE timestamp parser, ONE version check
instead of 13 special cases.
2026-04-22 19:35:37 +09:00
YeonGyu-Kim
ded0c5bbc1 test: #173 prep — JSON envelope field consistency validation
Adds parametrised test suite validating that clawable-surface commands'
JSON output matches their declared envelope contracts per SCHEMAS.md.

Two phases:

Phase 1 (this commit): Consistency baseline.
  - Collect ENVELOPE_CONTRACTS registry mapping each command to its
    required and optional fields
  - TestJsonEnvelopeConsistency: parametrised test iterates over 13
    commands, invokes with --output-format json, validates that
    actual JSON envelope contains all required fields
  - test_envelope_field_value_types: spot-check types (int, str, list)
    for consistency

Phase 2 (future #173): Common field wrapping.
  - Once wrap_json_envelope() is applied, all commands will emit
    timestamp, command, exit_code, output_format, schema_version
  - Currently skipped via @pytest.mark.skip, these tests will activate
    automatically when wrapping is implemented:
      TestJsonEnvelopeCommonFieldPrep::test_all_envelopes_include_timestamp
      TestJsonEnvelopeCommonFieldPrep::test_all_envelopes_include_command
      TestJsonEnvelopeCommonFieldPrep::test_all_envelopes_include_exit_code_and_schema_version

Why this matters:
  - #172 documented the JSON contract; this test validates it
  - Currently detects when actual output diverges from SCHEMAS.md
    (e.g. list-sessions emits 'count', not 'sessions_count')
  - As #173 wraps commands, test suite auto-validates new common fields
  - Prevents regression: accidental field removal breaks the test suite

Current status: 11 passed (consistency), 6 skipped (awaiting #173)
Full suite: 168 → 179 passing, zero regression.

Closes ROADMAP #173 prep (framework for common field validation).
Actual field wrapping remains for next cycle.
2026-04-22 19:20:15 +09:00