Skip to content

lisa/feat/workflow-seed-cmd#410

Merged
gusfcarvalho merged 7 commits into
mainfrom
lisa/feat/workflow-seed-cmd
Jun 1, 2026
Merged

lisa/feat/workflow-seed-cmd#410
gusfcarvalho merged 7 commits into
mainfrom
lisa/feat/workflow-seed-cmd

Conversation

@ccf-lisa
Copy link
Copy Markdown
Contributor

@ccf-lisa ccf-lisa Bot commented Jun 1, 2026

automated implementation by lisa.

Summary by CodeRabbit

  • New Features

    • Added a CLI seed command to import workflows, steps, dependencies, control relationships, instances, and role assignments from JSON
    • Included SOC 2 sample workflow templates for immediate use
  • Bug Fixes / Validation

    • Import rejects duplicate step names, trims keys before ID generation, and validates cadence, dependencies, and required fields
  • Tests

    • Added tests for idempotent imports, dependency wiring, relationships, cadence persistence, and audit/soft-delete preservation

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a CLI workflows seed importer that reads JSON workflow definitions, deterministically IDs and validates definitions, steps, dependencies, control relationships, instances, and role assignments, and upserts them into the DB with per-definition transactions; includes tests and a sample JSON seed.

Changes

Workflow Seed Import

Layer / File(s) Summary
Command registration and orchestration
cmd/seed/seed.go, cmd/seed/workflows.go
Registers workflows subcommand and implements top-level orchestration: logging, DB connection, decode, import loop, summary logging, and fatal exit on failures.
Seed data structures and types
cmd/seed/workflows.go
Defines JSON seed types for workflow definitions, steps, control relationships, instances, role assignments, and a summary accumulator for created/updated/skipped/failed counts.
File I/O and JSON decoding
cmd/seed/workflows.go
Opens and decodes the provided JSON file into typed seed structures with unknown-field rejection and error wrapping.
Per-definition import loop
cmd/seed/workflows.go
Iterates seed definitions with empty/duplicate-key checks, runs each definition import inside a DB transaction, and aggregates per-definition summaries into a global result.
Single workflow definition import
cmd/seed/workflows.go
Validates suggested cadence, constructs a WorkflowDefinition with deterministic UUID, validates via services, upserts it, and orchestrates importing steps, control relationships, and instances while aggregating counters.
Workflow steps and dependencies
cmd/seed/workflows.go
Two-pass steps import: upsert step definitions and build name→UUID map, then resolve depends-on names and create step dependencies idempotently.
Control relationship import
cmd/seed/workflows.go
Import control relationships with defaulted fields, deterministic UUIDs, optional is-active, validation, and upsert counting.
Workflow instances, scheduling, and role assignments
cmd/seed/workflows.go
Validate instance cadence/system ID, preserve or compute scheduling fields, upsert instances, then validate/generate deterministic IDs for role assignments and upsert them with activation handling.
Persistence helpers and deterministic IDs
cmd/seed/workflows.go
Generic upsert helper using GORM OnConflict UpdateAll, model-type ID extraction, deterministic UUID generation (SHA-256), and summary aggregation.
Summary aggregation
cmd/seed/workflows.go
Merge per-definition import counters into a global summary by summing created/updated/skipped/failed fields.
Test DB setup and tests
cmd/seed/workflows_test.go, cmd/seed/testdata/soc2_workflows.sample.json
In-memory SQLite test DB setup, end-to-end test that imports the sample JSON twice and asserts created/updated/failed counts, duplicate-step validation test, trimming/key-determinism test, audit/soft-delete preservation tests, assertion helpers, and the sample JSON fixture.
Validation and assertion helpers
cmd/seed/workflows_test.go
Helpers to assert persisted row counts, step dependency resolution, control relationship field passthrough, and cron cadence persistence; unit tests for duplicate step names and trimming of keys for deterministic IDs.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as workflows CLI
  participant Importer as importWorkflowsFromFile
  participant Service as workflow service layer
  participant DB as Database
  CLI->>Importer: provide --file path, invoke command
  Importer->>Importer: decode JSON, iterate definitions
  Importer->>Service: validate & upsert WorkflowDefinition
  Importer->>Service: upsert Steps, Dependencies, ControlRelationships, Instances
  Service->>DB: create/update rows (upsert)
  DB-->>Service: persisted results
  Service-->>Importer: operation counts / errors
  Importer-->>CLI: aggregated summary (created/updated/failed)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 In a burrow of code I quietly sow,
Two workflows planted where demo systems grow,
Hashes spin UUIDs, steps linked in a line,
Instances schedule, role bindings align,
Seeder hops home content — imports done on time.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Title check ❓ Inconclusive The title is a branch name reference that lacks descriptive detail about the actual changes. While it indicates a workflow seed command feature, it does not clearly summarize the main change or its scope for someone scanning PR history. Rename the title to something more descriptive like 'Add workflow seed command to populate workflow definitions and instances' to clearly communicate the primary change.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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: 5

🤖 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 `@cmd/seed/workflows_test.go`:
- Around line 112-125: The negative assertion in
assertWorkflowSeedControlRelationships is too weak: replace the current
conditional that checks relationship.ControlSource == "Technology control scope
is defined" with a strict expectation (e.g., assert that
relationship.ControlSource == "" or the exact expected stripped value). Update
the test in assertWorkflowSeedControlRelationships to fail unless
relationship.ControlSource equals the expected empty/stripped value, referencing
the workflows.ControlRelationship struct and its ControlSource field to locate
the check.
- Around line 17-19: The in-memory SQLite DB is volatile across pooled
connections; after opening with gorm.Open (sqlite.Open(":memory:")) get the
underlying sql.DB via db.DB() and constrain the pool to one connection (call
sqlDB.SetMaxOpenConns(1) and sqlDB.SetMaxIdleConns(1), and optionally
sqlDB.SetConnMaxLifetime(0)) so GORM uses a single persistent connection for the
in-memory database; update the code around the gorm.Open call and the local db
variable to retrieve and configure sqlDB accordingly.

In `@cmd/seed/workflows.go`:
- Around line 167-190: Before calling importWorkflowSeedDefinition, detect
duplicate seedDef.Key values in the incoming definitions slice and reject
duplicates instead of letting later upserts silently override earlier imports:
add a local seen map[string]struct{} (or bool) at the start of the function and,
inside the for _, definitions loop (before processing/trim check or immediately
after validating non-empty key), check if seedDef.Key is already in seen; if it
is, increment summary.Failed, log an error (include "key" seedDef.Key and "name"
seedDef.Name) and continue without calling importWorkflowSeedDefinition or
mergeWorkflowSeedSummary; otherwise add the key to seen and proceed as before.
- Around line 156-159: In importWorkflowsFromFile when decoding into
[]workflowSeedDefinition, enable strict JSON decoding by creating a
json.Decoder, calling decoder.DisallowUnknownFields() before
decoder.Decode(&definitions) to cause unknown/misspelled fields to error, and
propagate that error (including the original error) so importWorkflowSeeds fails
fast on unexpected attributes; locate the json.NewDecoder(f).Decode call and
replace it with the decoder + DisallowUnknownFields flow.
- Around line 394-397: preserveWorkflowInstanceSchedule currently treats any
non-nil DB error like gorm.ErrRecordNotFound and lets execution continue,
risking zeroing schedule fields during the upsert; change
preserveWorkflowInstanceSchedule(tx, instanceSvc, instance) to return an error,
and inside it inspect the error from the First(...) call: if err ==
gorm.ErrRecordNotFound then proceed without modifying LastExecutedAt, but for
any other err return that error immediately; then update the caller to check the
returned error (e.g., if err := preserveWorkflowInstanceSchedule(...); err !=
nil { return summary, fmt.Errorf("preserve workflow schedule: %w", err) })
before calling instanceSvc.ValidateInstance to ensure DB failures are bubbled
up.
🪄 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: 6428dc9e-604c-4fae-95a0-993bb13a8e22

📥 Commits

Reviewing files that changed from the base of the PR and between b771d5e and 21977e7.

📒 Files selected for processing (4)
  • cmd/seed/seed.go
  • cmd/seed/testdata/soc2_workflows.sample.json
  • cmd/seed/workflows.go
  • cmd/seed/workflows_test.go

Comment thread cmd/seed/workflows_test.go
Comment thread cmd/seed/workflows_test.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new seed workflows command to import workflow definitions (including steps, dependencies, control relationships, instances, and role assignments) from a JSON file, along with sample SOC 2 workflow templates and an end-to-end test validating idempotent imports.

Changes:

  • Introduces seed workflows Cobra command that reads JSON, validates entities, and upserts workflow-related records transactionally.
  • Adds sample SOC 2 workflow seed JSON for immediate import/use.
  • Adds SQLite-based end-to-end test verifying counts, dependency wiring, relationship persistence, cron cadence persistence, and idempotent re-import behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
cmd/seed/workflows.go Implements JSON import + validation + deterministic IDs + upsert logic for workflow seed data.
cmd/seed/workflows_test.go Adds end-to-end test coverage for import correctness and idempotency.
cmd/seed/testdata/soc2_workflows.sample.json Provides sample SOC 2 workflow templates used by tests and for seeding.
cmd/seed/seed.go Registers the new workflows seed subcommand.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows_test.go
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: 1

🤖 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 `@cmd/seed/workflows_test.go`:
- Around line 73-100: The review comment about adding a context parameter is
incorrect—leave the test call to importWorkflowSeedDefinition(tx *gorm.DB,
seedDef workflowSeedDefinition) as-is because importWorkflowSeedDefinition is
defined without a context parameter (see importWorkflowSeedDefinition signature
in workflows.go); optionally tighten the two strings.Contains assertions into a
single targeted check (or replace with a typed error match) that ensures the
returned error contains both "duplicate step name" and the offending step name
"Collect evidence".
🪄 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: d6963da0-7914-44a3-9f61-5467d9c12cd5

📥 Commits

Reviewing files that changed from the base of the PR and between a4ba58e and 58390d7.

📒 Files selected for processing (2)
  • cmd/seed/workflows.go
  • cmd/seed/workflows_test.go

Comment thread cmd/seed/workflows_test.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread cmd/seed/workflows.go
@ccf-lisa
Copy link
Copy Markdown
Contributor Author

ccf-lisa Bot commented Jun 1, 2026

No new automated feedback in the past 64 minutes. Waiting for a human review before continuing.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread cmd/seed/workflows.go
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: 1

🤖 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 `@cmd/seed/workflows_test.go`:
- Around line 147-213: The test must assert the upsert return value for the
soft-deleted path (or add a complementary non-soft-deleted case) because
upsertWorkflowSeed currently computes the "created" flag via
tx.Model(value).Where("id = ?", id).Count(&count) which ignores rows with
DeletedAt.Valid = true; update
TestUpsertWorkflowSeedPreservesWorkflowDefinitionAuditAndSoftDeleteFields to
capture the (bool, error) returned from upsertWorkflowSeed and assert it is
false (or add a separate seed case where DeletedAt is nil and assert true) so
the test validates the created/updated flag behavior for upsertWorkflowSeed and
its OnConflict update path.
🪄 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: dc738fd2-9535-43d3-8630-12fbea10d10e

📥 Commits

Reviewing files that changed from the base of the PR and between aa6e75d and 2005afa.

📒 Files selected for processing (2)
  • cmd/seed/workflows.go
  • cmd/seed/workflows_test.go

Comment thread cmd/seed/workflows_test.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows.go
Comment thread cmd/seed/workflows_test.go
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread cmd/seed/workflows.go
@ccf-lisa
Copy link
Copy Markdown
Contributor Author

ccf-lisa Bot commented Jun 1, 2026

PR approved. Marking as ready for e2e.

@gusfcarvalho gusfcarvalho merged commit 3f2d541 into main Jun 1, 2026
6 checks passed
@gusfcarvalho gusfcarvalho deleted the lisa/feat/workflow-seed-cmd branch June 1, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants