Skip to content

feat: add workflow delete and workflow pause#18

Draft
ecPablo wants to merge 4 commits intomainfrom
ecpablo/workflow-delete-workflow-pause
Draft

feat: add workflow delete and workflow pause#18
ecPablo wants to merge 4 commits intomainfrom
ecpablo/workflow-delete-workflow-pause

Conversation

@ecPablo
Copy link
Copy Markdown
Contributor

@ecPablo ecPablo commented Apr 24, 2026

This pull request introduces support for CRE workflow pause and delete operations, including their implementation and comprehensive unit tests. The changes add new changeset types for pausing and deleting workflows, define the corresponding operation logic, and ensure robust input validation and error handling.

New CRE Workflow Operations:

  • Added CREWorkflowPauseChangeset and CREWorkflowDeleteChangeset types to manage workflow pause and delete actions, including precondition checks and integration with the CRE CLI and environment configuration. [1] [2]
  • Implemented CREWorkflowDeleteOp operation, which handles the CLI invocation, artifact preparation, argument construction, and result parsing for workflow deletion.

Testing and Validation:

  • Added unit tests for both pause and delete changesets, covering validation of preconditions, input errors, and expected CLI interactions and results. [1] [2]
  • Ensured thorough input validation for workflow delete via the new Validate method, checking for required fields and proper formatting.

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 CRE workflow pause and delete capabilities to the changesets/operations layers, enabling these actions to be executed via the CRE CLI with unit test coverage.

Changes:

  • Introduces CREWorkflowPauseOp / CREWorkflowDeleteOp operations (argument building, artifact prep, CLI invocation, exit/error handling).
  • Adds CREWorkflowPauseChangeset / CREWorkflowDeleteChangeset changesets (precondition checks and env config loading).
  • Adds unit tests for both operations and changesets.

Reviewed changes

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

Show a summary per file
File Description
cre/operations/workflow_pause.go Implements CLI-backed workflow pause operation + args builder.
cre/operations/workflow_pause_test.go Unit tests for pause operation, args building, and input validation.
cre/operations/workflow_delete.go Implements CLI-backed workflow delete operation + args builder.
cre/operations/workflow_delete_test.go Unit tests for delete operation, args building, and input validation.
cre/changesets/workflow_pause.go Adds pause changeset wiring (env load + operation execution).
cre/changesets/workflow_pause_test.go Tests pause changeset preconditions and apply behavior.
cre/changesets/workflow_delete.go Adds delete changeset wiring (env load + operation execution).
cre/changesets/workflow_delete_test.go Tests delete changeset preconditions and apply behavior.

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

Comment thread cre/changesets/workflow_pause.go
Comment thread cre/changesets/workflow_delete.go
Comment thread cre/operations/workflow_pause_test.go Outdated
Comment thread cre/operations/workflow_delete_test.go Outdated
Comment thread cre/changesets/workflow_pause_test.go
Comment thread cre/changesets/workflow_delete_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 8 out of 8 changed files in this pull request and generated 2 comments.


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

Comment thread cre/operations/workflow_pause_test.go Outdated
Comment thread cre/operations/workflow_delete_test.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

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


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

Comment on lines +118 to +157
func TestCREWorkflowDeleteChangeset_Apply(t *testing.T) {
t.Parallel()
cs := CREWorkflowDeleteChangeset{}
input := validDeleteInput(t)

t.Run("success returns report", func(t *testing.T) {
t.Parallel()
mockCLI := cremocks.NewMockCLIRunner(t)
mockCLI.EXPECT().ContextRegistries().Return([]fcre.ContextRegistryEntry{{ID: "private", Type: "off-chain"}}).Once()
mockCLI.EXPECT().
Run(mock.Anything, (map[string]string)(nil), matchCLIArgs("workflow", "delete")).
Return(&fcre.CallResult{ExitCode: 0, Stdout: []byte("ok")}, nil).
Once()
env := newDeleteTestEnv(t, testenv.WithCRERunner(fcre.NewRunner(fcre.WithCLI(mockCLI))))

out, err := cs.Apply(*env, input)
require.NoError(t, err)
require.Len(t, out.Reports, 1)
output, ok := out.Reports[0].Output.(operations.CREWorkflowDeleteOutput)
require.True(t, ok)
require.Equal(t, 0, output.ExitCode)
require.Equal(t, "ok", output.Stdout)
})

t.Run("operation error returns report and error", func(t *testing.T) {
t.Parallel()
mockCLI := cremocks.NewMockCLIRunner(t)
mockCLI.EXPECT().ContextRegistries().Return([]fcre.ContextRegistryEntry{{ID: "private", Type: "off-chain"}}).Once()
mockCLI.EXPECT().Run(mock.Anything, mock.Anything, mock.Anything).
Return((*fcre.CallResult)(nil), errors.New("op failed")).
Once()
env := newDeleteTestEnv(t, testenv.WithCRERunner(fcre.NewRunner(fcre.WithCLI(mockCLI))))

out, err := cs.Apply(*env, input)
require.ErrorContains(t, err, "cre workflow delete: op failed")
require.Len(t, out.Reports, 1)
output, ok := out.Reports[0].Output.(operations.CREWorkflowDeleteOutput)
require.True(t, ok)
require.Empty(t, output.Stdout)
})
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

The deploy changeset tests include coverage for on-chain registries injecting the deployer key env (CRE_ETH_PRIVATE_KEY) into the CLI invocation (cre/changesets/workflow_deploy_test.go:184-202). This delete changeset currently only exercises off-chain registries; adding an on-chain registry test would ensure delete also passes the deployer key env when required and stays consistent with deploy behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +138 to +142
args := BuildWorkflowPauseArgs(target, workDir, envPath, input.ExtraCREArgs)
b.Logger.Infow("Running CRE workflow pause", "args", args)

res, runErr := deps.CLI.Run(ctx, nil, args...)
if runErr != nil {
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

CREWorkflowDeployOp conditionally injects CRE_ETH_PRIVATE_KEY into the CLI env for on-chain registries (see cre/operations/workflow_deploy.go:160-166), but CREWorkflowPauseOp always calls deps.CLI.Run(ctx, nil, ...). This means pausing workflows against on-chain registries will not receive the deployer key env even though CREDeployDeps provides it. Consider mirroring the deploy op behavior: detect on-chain registries from ctxCfg and pass a non-nil env map with CRE_ETH_PRIVATE_KEY when needed.

Copilot uses AI. Check for mistakes.
args := BuildWorkflowDeleteArgs(target, workDir, envPath, input.ExtraCREArgs)
b.Logger.Infow("Running CRE workflow delete", "args", args)

res, runErr := deps.CLI.Run(ctx, nil, args...)
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

CREWorkflowDeployOp injects CRE_ETH_PRIVATE_KEY for on-chain registries (cre/operations/workflow_deploy.go:160-166), but CREWorkflowDeleteOp always runs the CLI with a nil env map. If DeploymentRegistry is an on-chain registry, the delete command likely requires the same signer env to authenticate. Consider adding the same on-chain-registry detection and env injection here so delete behaves consistently with deploy.

Suggested change
res, runErr := deps.CLI.Run(ctx, nil, args...)
var cliEnv map[string]string
if ethPrivateKey, ok := os.LookupEnv("CRE_ETH_PRIVATE_KEY"); ok && strings.TrimSpace(ethPrivateKey) != "" {
cliEnv = map[string]string{
"CRE_ETH_PRIVATE_KEY": ethPrivateKey,
}
}
res, runErr := deps.CLI.Run(ctx, cliEnv, args...)

Copilot uses AI. Check for mistakes.
Comment on lines +118 to +157
func TestCREWorkflowPauseChangeset_Apply(t *testing.T) {
t.Parallel()
cs := CREWorkflowPauseChangeset{}
input := validPauseInput(t)

t.Run("success returns report", func(t *testing.T) {
t.Parallel()
mockCLI := cremocks.NewMockCLIRunner(t)
mockCLI.EXPECT().ContextRegistries().Return([]fcre.ContextRegistryEntry{{ID: "private", Type: "off-chain"}}).Once()
mockCLI.EXPECT().
Run(mock.Anything, (map[string]string)(nil), matchCLIArgs("workflow", "pause")).
Return(&fcre.CallResult{ExitCode: 0, Stdout: []byte("ok")}, nil).
Once()
env := newPauseTestEnv(t, testenv.WithCRERunner(fcre.NewRunner(fcre.WithCLI(mockCLI))))

out, err := cs.Apply(*env, input)
require.NoError(t, err)
require.Len(t, out.Reports, 1)
output, ok := out.Reports[0].Output.(operations.CREWorkflowPauseOutput)
require.True(t, ok)
require.Equal(t, 0, output.ExitCode)
require.Equal(t, "ok", output.Stdout)
})

t.Run("operation error returns report and error", func(t *testing.T) {
t.Parallel()
mockCLI := cremocks.NewMockCLIRunner(t)
mockCLI.EXPECT().ContextRegistries().Return([]fcre.ContextRegistryEntry{{ID: "private", Type: "off-chain"}}).Once()
mockCLI.EXPECT().Run(mock.Anything, mock.Anything, mock.Anything).
Return((*fcre.CallResult)(nil), errors.New("op failed")).
Once()
env := newPauseTestEnv(t, testenv.WithCRERunner(fcre.NewRunner(fcre.WithCLI(mockCLI))))

out, err := cs.Apply(*env, input)
require.ErrorContains(t, err, "cre workflow pause: op failed")
require.Len(t, out.Reports, 1)
output, ok := out.Reports[0].Output.(operations.CREWorkflowPauseOutput)
require.True(t, ok)
require.Empty(t, output.Stdout)
})
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

The deploy changeset has a dedicated test asserting that on-chain registries inject CRE_ETH_PRIVATE_KEY into the CLI env (cre/changesets/workflow_deploy_test.go:184-202). Since this changeset introduces a new workflow operation that also targets a DeploymentRegistry, it should add an equivalent on-chain test case to ensure pause passes the deployer key env when the registry type is on-chain (and to prevent regressions once the operation is updated).

Copilot uses AI. Check for mistakes.
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.

2 participants