Skip to content

Add wolverine-diagnostics codegen-preview CLI command#2486

Merged
jeremydmiller merged 2 commits into
mainfrom
feature/2467-wolverine-diagnostics-codegen-preview
Apr 9, 2026
Merged

Add wolverine-diagnostics codegen-preview CLI command#2486
jeremydmiller merged 2 commits into
mainfrom
feature/2467-wolverine-diagnostics-codegen-preview

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Summary

Closes #2467.

  • Adds WolverineDiagnosticsCommand (wolverine-diagnostics) to src/Wolverine/Diagnostics/ as an extensible parent command using a string-typed sub-command action (JasperFx/Oakton's idiomatic pattern — no true sub-command mechanism exists; enum-style dispatch used via string switch).
  • First sub-command is codegen-preview with --handler and --route flags.
  • Command lives in core Wolverine package; HTTP route support avoids a direct compile-time dependency on Wolverine.Http by matching against ICodeFile.FileName (mirrors HttpChain.determineFileName() logic).

Usage:
```bash

By fully-qualified message type

dotnet run -- wolverine-diagnostics codegen-preview --handler MyApp.Orders.CreateOrder

By short class name or handler class name (fuzzy match)

dotnet run -- wolverine-diagnostics codegen-preview --handler CreateOrderHandler

HTTP endpoint

dotnet run -- wolverine-diagnostics codegen-preview --route "POST /api/orders"
dotnet run -- wolverine-diagnostics codegen-preview --route "GET /api/orders/{id}"
```

Note on sub-command naming: JasperFx's `Enum.Parse`-based argument conversion does not support hyphens in enum value names. Using a `string` action property allows `codegen-preview` (with hyphen) to work exactly as described in the issue. Future sub-commands (`describe-routing`, `describe-resiliency`) follow the same pattern.

Test plan

  • 13 unit/smoke tests in `CoreTests.Diagnostics.WolverineDiagnosticsCommandTests`
    • `RouteInputToFileName` theory covering 8 route patterns including hyphens, route params, no-method prefix
    • `FindHandlerChain` — exact full name, short name, handler class name, fuzzy contains, no-match
    • End-to-end `codegen_preview_generates_code_for_handler` verifying generated C# contains handler name
  • Run `dotnet test --filter CoreTests.Diagnostics` — all pass
  • Build `Wolverine.csproj` — succeeds with no new errors

🤖 Generated with Claude Code

jeremydmiller and others added 2 commits April 9, 2026 16:45
- Wolverine now detects codegen commands (via DynamicCodeBuilder.WithinCodegenCommand)
  and OpenAPI generation tools (via ASPNETCORE_HOSTINGSTARTUPASSEMBLIES containing
  "GetDocument") and automatically applies lightweight startup mode, suppressing
  persistence and transport initialization.
- Replaced the Environment.CommandLine.Contains("codegen") code smell in
  WolverineHttpEndpointRouteBuilderExtensions with DynamicCodeBuilder.WithinCodegenCommand.
- Added smoke tests verifying codegen preview and host startup work without DB.
- Added documentation in command-line.md explaining that CLI commands do not
  require external connectivity.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a new `wolverine-diagnostics` Oakton command with an extensible
sub-command dispatch pattern (string action argument). The first
sub-command is `codegen-preview`:

  dotnet run -- wolverine-diagnostics codegen-preview --handler MyApp.Orders.CreateOrder
  dotnet run -- wolverine-diagnostics codegen-preview --route "POST /api/orders"

- --handler: accepts fully-qualified message type, short class name, or
  handler class name with fuzzy contains fallback; prints the single
  generated MessageHandler adapter class with full middleware chain.
- --route: converts "METHOD /path" to an expected HttpChain FileName and
  searches all ICodeFileCollection instances, so HTTP endpoints work
  without a direct Wolverine.Http compile-time dependency from core.
- Starts the host in codegen lightweight mode so no DB/transport
  connectivity is required (same behaviour as `codegen preview --start`).
- 13 passing unit/smoke tests covering route-name conversion, handler
  chain matching strategies, and end-to-end code generation.
- Docs added to docs/guide/command-line.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit fd53c28 into main Apr 9, 2026
16 of 19 checks passed
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.

Add CLI command to preview generated code for a specific handler or HTTP endpoint

1 participant