Skip to content

feat: add complypack validate command - #216

Open
hbraswelrh wants to merge 5 commits into
complytime:mainfrom
hbraswelrh:opsx/validate-command
Open

feat: add complypack validate command#216
hbraswelrh wants to merge 5 commits into
complytime:mainfrom
hbraswelrh:opsx/validate-command

Conversation

@hbraswelrh

Copy link
Copy Markdown
Member

Summary

Add a standalone complypack validate command that validates complypack.yaml configuration files against the JSON Schema and structural rules (closes #143).

Changes

  • CLI: complypack validate [path] [--strict] — validates config, defaults to complypack.yaml in current directory. Unknown fields warn by default, error with --strict.
  • MCP: validate_config tool with path (required) and strict (optional) parameters. Returns isError: true on validation failure.
  • Tests: 12 new test cases across CLI (validate_test.go) and MCP (tools_test.go).

Design

Both layers are thin transport wiring over config.LoadConfig(path, strict, writer) — no new domain logic. Follows the project's architecture pattern of keeping business logic in domain packages.

Files Changed

File Action
cmd/complypack/cli/validate.go New — CLI command
cmd/complypack/cli/validate_test.go New — 6 CLI test scenarios
cmd/complypack/cli/root.go Modified — register validateCmd
internal/mcp/tools.go Modified — validate_config tool + handler
internal/mcp/tools_test.go Modified — 4 MCP test cases
internal/mcp/server.go Modified — register tool

@hbraswelrh
hbraswelrh requested a review from a team as a code owner July 30, 2026 14:22
@hbraswelrh
hbraswelrh marked this pull request as draft July 30, 2026 14:22
@hbraswelrh
hbraswelrh marked this pull request as ready for review July 30, 2026 16:26

@trevor-vaughan trevor-vaughan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion(blocking)
We need a README.md update for the new capabilities.

Sorry about the slightly rambling comments, I ended up having to do more dumpster diving than I expected to make sure I was understanding things properly.

Comment thread internal/mcp/tools.go Outdated
Comment thread cmd/complypack/cli/validate.go
Comment thread cmd/complypack/cli/validate.go Outdated
Comment thread cmd/complypack/cli/validate_test.go Outdated
orig, err := os.Getwd()
require.NoError(t, err)
require.NoError(t, os.Chdir(dir))
t.Cleanup(func() { _ = os.Chdir(orig) })

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(non-blocking)
Should we capture the restore error here just in case there's an issue? Or perhaps use a single t.Chdir(dir) call for automatic cleanup?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in db8261d: Replaced manual os.Chdir/t.Cleanup with t.Chdir(dir).

Comment thread cmd/complypack/cli/validate.go Outdated

@yvonnedevlinrh yvonnedevlinrh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with all of @trevor-vaughan's findings:

  1. Command naming (blocking): The bare validate name is reserved by ADR 019 for the validate_policy CLI equivalent. This needs namespacing (e.g., config validate or validate-config) to avoid a breaking rename later.
  2. Validation depth (blocking): LoadConfig only runs basic checks (version presence, format patterns, platform non-empty). It doesn't call ValidateForPack, ValidateForMCP, or ValidateForInit, so a passing result doesn't mean the config is actually ready for any operation.
  3. Path sanitization (blocking): The MCP handler passes the user-supplied path directly to os.ReadFile with no sanitization, unlike other tools that go through the ResourceStore.
  4. t.Chdir (non-blocking): Agree - t.Chdir(dir) is safer and available on Go 1.24+.
  5. --strict naming (non-blocking): Either approach works; no strong preference from me.

I also left two inline comments on additional issues I found in the MCP handler code.

Comment thread internal/mcp/tools.go Outdated
Text: fmt.Sprintf("validation failed: %v", err),
},
},
IsError: true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM
IsError: true deviates from MCP handler convention — every other handler returns structured JSON with "valid": false; this one uses MCP-level error signaling

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 02414ea: Handler now returns structured JSON with valid, errors, warnings, and scopes fields — matching the validate_policy handler convention. IsError is no longer used for validation failures.

Comment thread internal/mcp/tools.go Outdated
}

// GetValidateConfigHandler exposes handler for testing.
func GetValidateConfigHandler() mcp.ToolHandler {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEDIUM
GetValidateConfigHandler() is dead code — exported "for testing" but zero callers, including tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 02414ea: Removed GetValidateConfigHandler().

hbraswelrh added a commit to hbraswelrh/complypack that referenced this pull request Jul 31, 2026
Addresses PR complytime#216 review feedback from @trevor-vaughan.

- Rename bare `validate` to `config validate` subcommand to avoid
  collision with ADR 019 reserved `validate` for validate_policy parity
- Replace --strict flag with --unknown-fields=warn|error for clarity
- Add --scope flag (pack/serve/init/all) for scope-specific validation
  using new ValidateScoped domain function
- Replace manual os.Chdir with t.Chdir in tests (Go 1.24+)

Signed-off-by: Hannah Braswell <hbraswelrh@users.noreply.github.com>
Assisted-by: claude-opus-4-6
hbraswelrh added a commit to hbraswelrh/complypack that referenced this pull request Jul 31, 2026
Addresses PR complytime#216 review feedback from @yvonnedevlinrh and
@trevor-vaughan.

- Return structured JSON with valid/errors/warnings/scopes fields
  instead of using IsError for validation failures (matches
  validate_policy handler convention)
- Add scope parameter to validate_config tool schema
- Rename strict to unknownFields in tool schema for consistency
  with CLI --unknown-fields flag
- Add stdio transport security comment documenting path safety
  assumption
- Remove dead GetValidateConfigHandler() export (zero callers)

Signed-off-by: Hannah Braswell <hbraswelrh@users.noreply.github.com>
Assisted-by: claude-opus-4-6
hbraswelrh added a commit to hbraswelrh/complypack that referenced this pull request Jul 31, 2026
Addresses PR complytime#216 review feedback from @trevor-vaughan.

- Document complypack config validate with flags and examples
- Add validate_config to MCP tools table
- Add .uf/feedback/ to .gitignore

Signed-off-by: Hannah Braswell <hbraswelrh@users.noreply.github.com>
Assisted-by: claude-opus-4-6
@hbraswelrh

Copy link
Copy Markdown
Member Author

README update addressed in 03475e1: Added config validate documentation with flags, examples, and validate_config MCP tools table entry.

Add standalone config validation via CLI and MCP:

- CLI: complypack validate [path] [--strict]
  Validates complypack.yaml against JSON Schema and structural
  rules. Defaults to complypack.yaml in current directory.
  Unknown fields warn by default, error with --strict.

- MCP: validate_config tool with path and strict parameters.
  Returns isError:true on validation failure.

Both layers are thin wiring over config.LoadConfig — no new
domain logic added.

Closes: complytime#143

Signed-off-by: Hannah Braswell <hbraswel@redhat.com>
Addresses PR complytime#216 review feedback from @trevor-vaughan.

- Rename bare `validate` to `config validate` subcommand to avoid
  collision with ADR 019 reserved `validate` for validate_policy parity
- Replace --strict flag with --unknown-fields=warn|error for clarity
- Add --scope flag (pack/serve/init/all) for scope-specific validation
  using new ValidateScoped domain function
- Replace manual os.Chdir with t.Chdir in tests (Go 1.24+)

Signed-off-by: Hannah Braswell <hbraswel@redhat.com>
Assisted-by: claude-opus-4-6
Addresses PR complytime#216 review feedback from @yvonnedevlinrh and
@trevor-vaughan.

- Return structured JSON with valid/errors/warnings/scopes fields
  instead of using IsError for validation failures (matches
  validate_policy handler convention)
- Add scope parameter to validate_config tool schema
- Rename strict to unknownFields in tool schema for consistency
  with CLI --unknown-fields flag
- Add stdio transport security comment documenting path safety
  assumption
- Remove dead GetValidateConfigHandler() export (zero callers)

Signed-off-by: Hannah Braswell <hbraswel@redhat.com>
Assisted-by: claude-opus-4-6
Addresses PR complytime#216 review feedback from @trevor-vaughan.

- Document complypack config validate with flags and examples
- Add validate_config to MCP tools table
- Add .uf/feedback/ to .gitignore

Signed-off-by: Hannah Braswell <hbraswel@redhat.com>
Assisted-by: claude-opus-4-6
Address divisor-testing REQUEST CHANGES findings:

- Add Valid/Error field assertions to ValidateScoped AllScopes and
  EmptyScopes tests (was only checking structure, not correctness)
- Strengthen MCP handler test assertions: verify response["valid"],
  response["errors"] content, and scope result validity
- Add tests for invalid --scope and --unknown-fields flag values
- Replace string concatenation with filepath.Join in MCP tests (SC-003)
- Add GoDoc comments on configCmd and configValidateCmd (CS-004)

Signed-off-by: Hannah Braswell <hbraswel@redhat.com>
Assisted-by: claude-opus-4-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Add a complypack validate command

3 participants