Skip to content

Adds create capability step call - #104

Merged
jlpdeveloper merged 23 commits into
mainfrom
capability-steps/create
Jul 13, 2026
Merged

Adds create capability step call#104
jlpdeveloper merged 23 commits into
mainfrom
capability-steps/create

Conversation

@jlpdeveloper

@jlpdeveloper jlpdeveloper commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Code Rabbit Summary

Summary by CodeRabbit

  • New Features

    • Added an API endpoint for creating capability steps with flow step, capability, target, and protocol details.
    • Added validation for required capability-step fields.
    • Added clear responses for successful creation, invalid requests, missing records, and server errors.
    • Added API request documentation and an example request/response.
  • Tests

    • Expanded coverage for capability-step creation, validation, routing, and error handling.

Fixes

Closes #101

- Add queries to create, delete, and retrieve capability steps in `capabilities.sql`.
- Implement corresponding methods in generated database code (`capabilities.sql.gen.go`).
- Extend `Querier` interface and `models.gen.go` for capability steps management.
…rsion methods

- Add `TestCreateCapabilityStepRequest_Validate` to test request validation logic.
- Add `TestCreateCapabilityStepRequest_ToParams` to test parameter conversion logic.
- Implement `ToParams` method in `createCapabilityStepRequest` to map to database parameters.
… clarity and organization in capability service tests
@jlpdeveloper jlpdeveloper added this to the Phase 2: API Endpoints milestone Jul 13, 2026
@jlpdeveloper jlpdeveloper self-assigned this Jul 13, 2026
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jlpdeveloper, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 081419ce-257b-4dc8-ac9a-b30e5acb5322

📥 Commits

Reviewing files that changed from the base of the PR and between a64749c and e2b4710.

📒 Files selected for processing (4)
  • _bruno/Capabilities/Create Capability Step.yml
  • internal/capability/handler.go
  • internal/capability/service_capability_steps.go
  • internal/capability/service_capability_steps_test.go
📝 Walkthrough

Walkthrough

Adds capability-step persistence queries and models, validates and creates capability steps through the service layer, exposes POST /capability-steps, and documents the endpoint with tests and a Bruno request example.

Changes

Capability step creation

Layer / File(s) Summary
Capability-step persistence contracts
internal/capability/capabilities.sql, internal/capability/db/*
Adds capability-step queries, database models, generated query methods, parameters, and querier interface methods.
Request validation and service creation
internal/capability/request.go, internal/capability/service_capability_steps.go, internal/capability/*_test.go
Validates required IDs and text fields, checks the capability and flow step, and creates the capability-step record.
HTTP endpoint and route wiring
internal/capability/handler.go, internal/capability/router.go, internal/capability/*test.go, _bruno/Capabilities/*
Adds the POST /capability-steps handler and route, maps validation and service errors to HTTP responses, and documents the request.
Handler regression coverage
internal/capability/handler_command_capability_test.go, internal/capability/handler_query_capability_test.go, internal/capability/handler_test.go
Adds table-driven coverage for capability command and query handlers and updates shared test mocks.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Handler
  participant postgresService
  participant Queries
  Client->>Handler: POST /capability-steps
  Handler->>postgresService: Validate and create request
  postgresService->>Queries: Check capability and flow step
  postgresService->>Queries: Insert capability step
  Queries-->>postgresService: Created CapabilityStep
  postgresService-->>Handler: Created CapabilityStep
  Handler-->>Client: 201 Created
Loading

Possibly related PRs

Suggested labels: enhancement

Poem

A rabbit taps POST in the night,
With protocol and target just right.
The flow step is found,
A new row comes around,
And 201 makes the moonlight bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and directly describes the primary change: adding a capability-step creation call.
Linked Issues check ✅ Passed The PR adds the requested POST /capability-steps endpoint and supporting validation, service, DB, handler, and tests.
Out of Scope Changes check ✅ Passed The changes stay focused on capability-step creation and its supporting plumbing, with no obvious unrelated additions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch capability-steps/create

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (5)
internal/capability/capabilities.sql (1)

52-53: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Naming implies single-row delete, but this deletes all steps for a capability.

DeleteCapabilityStep (singular) deletes every row matching capability_id, not a single step by its own primary key — unlike DeleteCapability above which deletes by id. If a future caller expects to delete one specific step, this will silently wipe out all steps for that capability. Consider renaming to DeleteCapabilitySteps (plural) to match its actual bulk-delete semantics, or scope by the step's own id if single-row deletion was intended.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/capability/capabilities.sql` around lines 52 - 53, Rename the SQL
query symbol DeleteCapabilityStep to DeleteCapabilitySteps to reflect that it
deletes all capability_steps rows matching capability_id, and update every
generated or handwritten caller referencing the old name. Preserve the existing
bulk-delete behavior.
internal/capability/request_test.go (1)

178-239: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Missing whitespace-only test case for Target/Protocol.

The table covers missing (empty-string) Target/Protocol, but not whitespace-only values (e.g. " "), which is the case that specifically exercises strings.TrimSpace rather than a plain emptiness check.

✅ Suggested additional case
 		{
 			name: "Missing protocol",
 			req: createCapabilityStepRequest{
 				CapabilityId: 1,
 				FlowStepId:   1,
 				Target:       "target",
 			},
 			wantErr: true,
 		},
+		{
+			name: "Whitespace-only target",
+			req: createCapabilityStepRequest{
+				CapabilityId: 1,
+				FlowStepId:   1,
+				Target:       "   ",
+				Protocol:     "protocol",
+			},
+			wantErr: true,
+		},
 	}

As per path instructions, "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/capability/request_test.go` around lines 178 - 239, Extend
TestCreateCapabilityStepRequest_Validate with cases where Target and Protocol
contain only whitespace, such as "   ", and expect validation errors. Keep the
other required fields populated so each case specifically exercises whitespace
handling via strings.TrimSpace.

Source: Path instructions

internal/capability/db/querier.gen.go (1)

13-21: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Drop the redundant n == 0 check in CreateCapabilityStep. GetFlowStep already selects the step id directly, and the missing-row case comes back as an error; the extra integer check only obscures that contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/capability/db/querier.gen.go` around lines 13 - 21, Remove the
redundant n == 0 validation from CreateCapabilityStep and rely on GetFlowStep’s
direct step-ID result and error for missing rows. Preserve the existing error
propagation and creation flow otherwise.
internal/capability/handler_command_cap_step_test.go (1)

23-105: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the response body and invalid-request short-circuiting.

For success, decode and verify the returned capability-step JSON. For malformed and invalid requests, assert the mocked service was not invoked. Status-only assertions can miss response serialization and accidental service execution regressions.

As per path instructions, **/*_test.go: “Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/capability/handler_command_cap_step_test.go` around lines 23 - 105,
The CreateCapabilityStep table tests should validate response content and
prevent service calls for invalid input. Extend mockCapabilityService to track
invocations, assert the success response decodes to the expected
db.CapabilityStep, and verify the service was not called for the “Invalid JSON”
and “Validation Error” cases while preserving the existing status assertions.

Source: Path instructions

internal/capability/service_capability_steps_test.go (1)

41-102: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the flow-step branch and persistence contract.

Add a GetFlowStep not-found/error case, assert lookup errors are propagated correctly, and verify CreateCapabilityStep receives the expected capability ID, flow-step ID, protocol, and target. The current success test only checks one returned field, so mapper or validation regressions can pass unnoticed.

As per path instructions, **/*_test.go: “Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/capability/service_capability_steps_test.go` around lines 41 - 102,
Expand the CreateCapabilityStep tests around
postgresService.CreateCapabilityStep: add a GetFlowStep error/not-found case and
assert the lookup error is propagated. In the success case, capture and validate
CreateCapabilityStep’s arguments for capability ID, flow-step ID, protocol, and
target, while retaining the existing result assertion; keep the existing
persistence-error coverage.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@_bruno/Capabilities/Create` Capability Step.yml:
- Line 74: Update the endpoint description in “Create Capability Step” so it
describes creating a new capability step, not creating a capability for a flow.

In `@internal/capability/service_capability_steps.go`:
- Around line 13-25: Update the validation goroutines around GetCapability and
GetFlowStep so only confirmed missing records are sent to errChan as
"capability" or "flow_step". Preserve and propagate database, connection, and
context deadline errors unchanged so the handler retains 500/timeout semantics,
including adapting the errChan result and caller logic as needed.

---

Nitpick comments:
In `@internal/capability/capabilities.sql`:
- Around line 52-53: Rename the SQL query symbol DeleteCapabilityStep to
DeleteCapabilitySteps to reflect that it deletes all capability_steps rows
matching capability_id, and update every generated or handwritten caller
referencing the old name. Preserve the existing bulk-delete behavior.

In `@internal/capability/db/querier.gen.go`:
- Around line 13-21: Remove the redundant n == 0 validation from
CreateCapabilityStep and rely on GetFlowStep’s direct step-ID result and error
for missing rows. Preserve the existing error propagation and creation flow
otherwise.

In `@internal/capability/handler_command_cap_step_test.go`:
- Around line 23-105: The CreateCapabilityStep table tests should validate
response content and prevent service calls for invalid input. Extend
mockCapabilityService to track invocations, assert the success response decodes
to the expected db.CapabilityStep, and verify the service was not called for the
“Invalid JSON” and “Validation Error” cases while preserving the existing status
assertions.

In `@internal/capability/request_test.go`:
- Around line 178-239: Extend TestCreateCapabilityStepRequest_Validate with
cases where Target and Protocol contain only whitespace, such as "   ", and
expect validation errors. Keep the other required fields populated so each case
specifically exercises whitespace handling via strings.TrimSpace.

In `@internal/capability/service_capability_steps_test.go`:
- Around line 41-102: Expand the CreateCapabilityStep tests around
postgresService.CreateCapabilityStep: add a GetFlowStep error/not-found case and
assert the lookup error is propagated. In the success case, capture and validate
CreateCapabilityStep’s arguments for capability ID, flow-step ID, protocol, and
target, while retaining the existing result assertion; keep the existing
persistence-error coverage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 616af5b8-bc8a-4abf-ba0d-01287effebd1

📥 Commits

Reviewing files that changed from the base of the PR and between 5076867 and a64749c.

📒 Files selected for processing (18)
  • _bruno/Capabilities/Create Capability Step.yml
  • internal/capability/capabilities.sql
  • internal/capability/db/capabilities.sql.gen.go
  • internal/capability/db/models.gen.go
  • internal/capability/db/querier.gen.go
  • internal/capability/handler.go
  • internal/capability/handler_command_cap_step_test.go
  • internal/capability/handler_command_capability_test.go
  • internal/capability/handler_query_capability_test.go
  • internal/capability/handler_test.go
  • internal/capability/request.go
  • internal/capability/request_test.go
  • internal/capability/router.go
  • internal/capability/router_test.go
  • internal/capability/service_capability_steps.go
  • internal/capability/service_capability_steps_test.go
  • internal/capability/service_capability_test.go
  • router/router_test.go

Comment thread _bruno/Capabilities/Create Capability Step.yml Outdated
Comment thread internal/capability/service_capability_steps.go
@jlpdeveloper
jlpdeveloper merged commit e510e4f into main Jul 13, 2026
3 checks passed
@jlpdeveloper
jlpdeveloper deleted the capability-steps/create branch July 13, 2026 01:46
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 Create Capability Step

1 participant