1 Commits

Author SHA1 Message Date
xarmian 1e3991c865 feat(schema): publish cmdhelp.schema.json v0.1 (TASK-932) (#325)
* feat(schema): publish cmdhelp.schema.json v0.1 (TASK-932)

Adds the formal JSON Schema (draft 2020-12) describing cmdhelp v0.1's
`--format json` wire format, plus a schema/README.md documenting intended
use for CLI authors and consumer wrappers.

Per IDEA-927 the schema enforces the v0.1 contracts:
- Required top-level: cmdhelp_version, binary, commands.
- cmdhelp_version pattern is MAJOR.MINOR (no PATCH); '0.1.0' invalid.
- Argument types: closed set {string,int,float,bool,enum,path,url,
  duration,date,datetime,json,ref} plus x-* extension namespace.
- Boolean flag arity (§5.3): negate_flag only valid when type=bool.
- exit_codes union (§5.2): each entry is string OR object{when,recovery,
  message_template}; object form requires `when`. Codes must be numeric.
- Dynamic enums (§7): enum_source pattern is `^dynamic:.+$`.
- additionalProperties: true at extension points for forward-compat (§9).

Validated locally with python jsonschema: 8 tests (1 valid sample,
5 negative cases, 2 x-*/dynamic positive cases) all pass.

Unblocks TASK-934 (JSON emitter), TASK-938 (test suite validates against
this schema), and TASK-940 (publish on getpad.dev).

Parent: PLAN-930.

* fix(schema): enforce flag-name pattern + clarify test-suite wording per Codex review (round 1)

Two findings from Codex round 1 on PR #325:

1. flagMap accepted invalid keys ('--verbose', empty string, digit-leading)
   despite README documenting "without leading --". Added propertyNames
   pattern `^[a-zA-Z][a-zA-Z0-9_-]*$` so producers can't ship malformed
   flag names that consumers would parse incorrectly.

2. schema/README.md described `internal/cmdhelp/` as if it existed and
   already validated in `go test ./...`. The package ships in TASK-934
   (and the validation test in TASK-938). Reworded as future/planned.

Verification:
- Schema syntax: still valid Draft 2020-12.
- Original 8 tests still pass.
- 3 new negative tests for the propertyNames pattern: '--verbose',
  empty string, and digit-leading keys all correctly rejected.
- Single-letter short-flag keys like `h` still accepted.
- `make check` clean.

Note for next review round: Codex's first run reported a `httptest`
panic in `cmd/pad` tests; that's a sandbox networking constraint
(read-only mode can't bind sockets), not a regression — verified
locally with `go test ./cmd/pad/ -run TestEnsureWorkspaceSlugAttachExisting -count=1` (passes).
2026-05-01 00:30:53 -04:00