Skip to content

Conversation

@nxtcoder17
Copy link
Owner

@nxtcoder17 nxtcoder17 commented Jan 17, 2025

fixes major issues with commands executions, and adds tests to support it

Summary by Sourcery

Bug Fixes:

  • Fixed issues related to command execution and added corresponding tests.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 17, 2025

Reviewer's Guide by Sourcery

This pull request refactors the command execution logic to fix major issues and adds tests to support it. The changes include a new way to handle multiple commands, a fix for interactive mode, and a new way to kill processes.

Sequence diagram for the new command execution flow

sequenceDiagram
    participant M as Main
    participant W as Watcher
    participant E as Executor
    participant P as Process

    M->>W: Create Watcher
    M->>E: Create Executor(s)
    M->>W: WatchAndExecute(executors)
    activate W

    loop For each file change event
        W->>W: Check ignore rules
        W->>E: OnWatchEvent
        E->>P: Start new command
        P-->>E: Command completed
        E->>P: Kill process
    end

    Note over W,E: Multiple executors can now run in parallel

    M->>W: Context cancelled
    W->>E: Stop
    E->>P: Kill all processes
    deactivate W
Loading

Class diagram for CmdExecutor refactoring

classDiagram
    class CmdExecutor {
        -logger *slog.Logger
        -parentCtx context.Context
        -commands []func(context.Context) *exec.Cmd
        -interactive bool
        -mu sync.Mutex
        -kill func() error
        +OnWatchEvent(ev Event) error
        +Start() error
        +Stop() error
    }

    class CmdExecutorArgs {
        +Logger *slog.Logger
        +Commands []func(context.Context) *exec.Cmd
        +Interactive bool
    }

    note for CmdExecutor "Refactored to support multiple commands
and improved process management"

    CmdExecutor ..> CmdExecutorArgs : uses
Loading

File-Level Changes

Change Details Files
Refactor command execution to support multiple commands.
  • The Command field in CmdExecutorArgs is renamed to Commands and is now a slice of functions that return *exec.Cmd.
  • The newCmd field in CmdExecutor is replaced with commands, which is a slice of functions that return *exec.Cmd.
  • The Start method now iterates over the commands slice and executes each command in a separate goroutine.
  • The Start method now uses a context to manage the lifecycle of each command.
  • The Start method now uses syscall.Kill to kill the process group of the command.
  • The Stop method now uses a kill function to stop the process group of the command.
pkg/executor/cmd-executor.go
Fix interactive mode.
  • The Start method now sends a SIGTERM signal to the interactive process before killing it.
pkg/executor/cmd-executor.go
Add a new WatchAndExecute method to the watcher.
  • The Watch method is now called by the WatchAndExecute method.
  • The WatchAndExecute method now takes a slice of executor.Executor as an argument.
  • The WatchAndExecute method now starts all executors and then starts the watcher.
  • The WatchAndExecute method now calls OnWatchEvent on all executors when a watch event is received.
pkg/watcher/watcher.go
pkg/watcher/lib.go
Add tests for the executor and watcher packages.
  • Added tests for the CmdExecutor to verify the execution of single and multiple commands.
  • Added tests for the Watcher to verify the execution of single and multiple commands with single and multiple change events.
pkg/executor/cmd-executor_test.go
pkg/watcher/lib_test.go
Update the main command to use the new WatchAndExecute method.
  • The main command now uses the WatchAndExecute method to start the watcher and executors.
  • The main command now supports multiple executors, including the SSE executor.
  • The main command now uses a single context to manage the lifecycle of the watcher and executors.
cmd/main.go
Add a default ignore list to the watcher.
  • The watcher now has a default ignore list for common directories and files.
  • The main command now uses the default ignore list.
cmd/main.go
pkg/watcher/watcher.go
Fix SSE executor to properly close the server.
  • The SSE executor now properly closes the server when the context is cancelled.
pkg/executor/sse-executor.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@nxtcoder17 nxtcoder17 self-assigned this Jan 17, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @nxtcoder17 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please expand the PR description to detail the specific issues that were fixed and the key improvements made in this refactoring
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@nxtcoder17 nxtcoder17 merged commit f4e8bb1 into master Jan 18, 2025
@nxtcoder17 nxtcoder17 deleted the refactor/watch-and-execute branch January 18, 2025 04:16
nxtcoder17 added a commit to nxtcoder17/Runfile that referenced this pull request Jan 18, 2025
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