Skip to content

BCH-1148: Populate step_count in workflow definition list response#398

Merged
saltpy-cs merged 4 commits into
mainfrom
fix/BCH-1148
May 22, 2026
Merged

BCH-1148: Populate step_count in workflow definition list response#398
saltpy-cs merged 4 commits into
mainfrom
fix/BCH-1148

Conversation

@saltpy-cs
Copy link
Copy Markdown
Contributor

@saltpy-cs saltpy-cs commented May 20, 2026

The API preloaded Steps but never exposed a step count field, causing the UI to always display 0 steps for workflow definitions.

Summary by CodeRabbit

  • New Features

    • Workflow definitions now expose a computed, non-persisted step_count (integer, minimum 0), populated consistently across read operations.
  • Documentation

    • API documentation updated to include the new step_count property in workflow definition schemas.
  • Tests

    • Added unit test coverage verifying step_count population.

Review Change Stack

@saltpy-cs saltpy-cs requested a review from gusfcarvalho May 20, 2026 16:00
@saltpy-cs saltpy-cs self-assigned this May 20, 2026
@saltpy-cs
Copy link
Copy Markdown
Contributor Author

Screenshot 2026-05-20 at 16 54 33

The API preloaded Steps but never exposed a step count field, causing
the UI to always display 0 steps for workflow definitions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9cd7618b-a5a6-4c7e-b29d-f62409ebe644

📥 Commits

Reviewing files that changed from the base of the PR and between 0ebc84a and 7706008.

📒 Files selected for processing (3)
  • docs/docs.go
  • docs/swagger.json
  • docs/swagger.yaml

📝 Walkthrough

Walkthrough

Adds a non-persisted integer StepCount to WorkflowDefinition, exposes it in Go and Swagger schemas, populates it from preloaded Steps in service read methods, and adds a GetAll unit test asserting expected counts.

Changes

Workflow Step Count Field

Layer / File(s) Summary
Struct contract and API schema
internal/service/relational/workflows/workflow_definition.go, docs/docs.go, docs/swagger.json, docs/swagger.yaml
WorkflowDefinition gains a computed, non-persisted StepCount int (json:"step_count", gorm:"-", validate:"min=0"). API docs and Swagger JSON/YAML schemas are updated to include step_count as an integer with minimum: 0 and described as computed (not persisted).
Service population and test
internal/service/relational/workflows/workflow_definition_service.go, internal/service/relational/workflows/workflow_definition_service_test.go
Service read paths that preload Steps (GetByID, GetAll, FindByName, GetWithInstances) assign StepCount = len(Steps) for returned definitions. A new unit test seeds two workflows (one with 2 steps, one with 0) and verifies GetAll returns correct StepCount values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I count the hops in every flow,
Not stored in soil where data grow,
Computed quick from steps I see,
A gentle tally—one, two, three.
Docs sing the number; tests agree.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: adding and populating the step_count field in workflow definition list responses.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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 `@docs/docs.go`:
- Around line 40169-40172: Update the Go struct comment for the StepCount field
so the generated Swagger description is singular: change the comment on
StepCount in workflow_definition.go from "Computed fields (not persisted)" to
"Computed field (not persisted)". Regenerate the docs with swag so docs/docs.go
reflects the corrected "step_count" description.

In `@docs/swagger.json`:
- Around line 40163-40166: The step_count property in the OpenAPI schema
currently lacks a minimum constraint; update the "step_count" schema (type:
integer) to include "minimum": 0 so negative values are disallowed and the API
contract documents that counts cannot be negative.

In `@internal/service/relational/workflows/workflow_definition_service_test.go`:
- Around line 101-118: Add an assertion that workflow definitions with no
associated steps report StepCount == 0: after calling
NewWorkflowDefinitionService(db) and creating a definition without steps (as
done in TestWorkflowDefinitionService_GetAll or the existing setup in
TestWorkflowDefinitionService_GetAll_StepCount), call service.GetAll(...) and
assert that the returned retrieved[n].StepCount equals 0 for that definition;
reference the GetAll method and the retrieved slice to locate where to add the
assertion.

In `@internal/service/relational/workflows/workflow_definition_service.go`:
- Around line 66-68: FindByName, GetByID, and GetWithInstances preload Steps but
never set the computed StepCount field, causing inconsistent API responses;
after each place you load a WorkflowDefinition (e.g., the returned variable
named definitions or def), set def.StepCount = len(def.Steps) (or for slices
loop and set definitions[i].StepCount = len(definitions[i].Steps)) before
returning so StepCount is populated consistently across those methods (update in
FindByName, GetByID, and GetWithInstances).
🪄 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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: da734735-8214-40ba-b366-b310db37941b

📥 Commits

Reviewing files that changed from the base of the PR and between 36e309e and bb56929.

📒 Files selected for processing (6)
  • docs/docs.go
  • docs/swagger.json
  • docs/swagger.yaml
  • internal/service/relational/workflows/workflow_definition.go
  • internal/service/relational/workflows/workflow_definition_service.go
  • internal/service/relational/workflows/workflow_definition_service_test.go

Comment thread docs/docs.go
Comment thread docs/swagger.json
saltpy-cs and others added 2 commits May 21, 2026 14:55
- Fix grammar: singular "Computed field" in StepCount doc comment
- Add validate:"min=0" tag so swagger emits minimum:0 constraint
- Populate StepCount in GetByID, FindByName, and GetWithInstances for consistent API responses
- Add zero-step assertion to TestWorkflowDefinitionService_GetAll_StepCount

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@saltpy-cs saltpy-cs merged commit c83f5be into main May 22, 2026
5 checks passed
@saltpy-cs saltpy-cs deleted the fix/BCH-1148 branch May 22, 2026 08:22
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.

1 participant