Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report job status on each prompt #411

Merged
merged 3 commits into from
Aug 31, 2024
Merged

Report job status on each prompt #411

merged 3 commits into from
Aug 31, 2024

Conversation

magicant
Copy link
Owner

@magicant magicant commented Aug 29, 2024

Closes #407

Summary by CodeRabbit

  • New Features

    • Enhanced job reporting in interactive shells, providing status updates before prompts.
    • Introduction of the Reporter decorator for real-time job status feedback in interactive mode.
    • New Accumulator structure for organized job report formatting.
  • Bug Fixes

    • Improved error handling in interactive shells to prevent termination on syntax errors.
  • Tests

    • Added new tests for job control functionalities, ensuring compliance with expected behaviors.
  • Documentation

    • Updated changelogs to reflect new features and enhancements across projects.

@magicant magicant added the enhancement New feature or request label Aug 29, 2024
@magicant magicant added this to the 0.1.0 β3 milestone Aug 29, 2024
@magicant magicant self-assigned this Aug 29, 2024
Copy link

coderabbitai bot commented Aug 29, 2024

Walkthrough

The changes introduce a new Reporter decorator for interactive shells that reports job status before displaying prompts. The Accumulator struct has been removed, simplifying job reporting. The prepare_input function has been modified to apply the Reporter when in interactive mode, enhancing user feedback on job statuses. Additionally, new tests and a job control script have been added to ensure functionality and compliance with expected behaviors.

Changes

Files Change Summary
yash-builtin/src/jobs.rs Removed Accumulator struct and report method; modified main to use accumulator.add.
yash-cli/CHANGELOG-bin.md Updated to clarify interactive shell behavior and error handling.
yash-cli/CHANGELOG-lib.md Documented changes to prepare_input function with new lifetime parameters and updated dependencies.
yash-cli/src/startup/input.rs Modified prepare_input to apply Reporter in interactive mode; added inner function for logic.
yash-cli/tests/scripted_test.rs Added job_control_ex test function for job control functionality.
yash-cli/tests/scripted_test/job-y.sh New script for testing job control features, including job status reporting and POSIX compliance.
yash-env/CHANGELOG.md Added entries for job::fmt::Accumulator and input::Reporter.
yash-env/src/input.rs Introduced new reporter module and made Reporter publicly accessible.
yash-env/src/input/reporter.rs Implemented Reporter struct and functionality for job status reporting in interactive mode.
yash-env/src/job/fmt.rs Added new Accumulator struct with methods for job report formatting.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Shell
    participant Reporter
    participant JobManager

    User->>Shell: Input command
    Shell->>Reporter: Check job status
    Reporter->>JobManager: Get job updates
    JobManager-->>Reporter: Return job status
    Reporter-->>Shell: Display job status
    Shell-->>User: Show prompt
Loading

Assessment against linked issues

Objective Addressed Explanation
Report job status on each prompt (#[407])

🐰 In the meadow, I hop with glee,
Job statuses dance, oh what a spree!
With each little prompt, they come to play,
Reporting their tales in a joyful way.
So thank you, dear coder, for this delight,
The shell now shines, oh what a sight! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@magicant magicant marked this pull request as ready for review August 31, 2024 10:18
Copy link

@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: 3

Outside diff range, codebase verification and nitpick comments (3)
yash-cli/CHANGELOG-lib.md (1)

34-36: Clarify the changelog entry for prepare_input.

The changelog entry for the prepare_input function mentions the addition of the Reporter decorator but does not explicitly state the new behavior in interactive mode. It would be beneficial to clarify that this decorator is specifically applied when the shell is in interactive mode to enhance user feedback on job statuses.

Consider revising the entry to explicitly mention the interactive mode condition:

- The `startup::input::prepare_input` function now applies the `yash_env::input::Reporter` decorator to the returned source input if the shell is interactive, enhancing user feedback on job statuses.
yash-cli/src/startup/input.rs (1)

Line range hint 71-94: Review the implementation of the prepare_input function.

The prepare_input function has been modified to include a conditional check for the interactive mode of the shell. If the shell is interactive, the Reporter decorator is applied. This implementation aligns with the PR objectives to enhance user feedback on job statuses.

However, it's important to ensure that the Reporter decorator does not interfere with other decorators like Echo and Prompter which are applied based on different conditions. The current implementation seems to handle these concerns separately, which is good.

Consider adding a unit test to verify that the Reporter decorator is applied correctly in interactive mode and that it behaves as expected with other decorators.

yash-cli/tests/scripted_test.rs (1)

268-271: Review the implementation of the job_control_ex test function.

The job_control_ex function is designed to test the job-y.sh script using the run_with_pty method. This is consistent with the existing testing structure and is a good practice for ensuring that the new job control functionality is tested in an environment that mimics user interaction.

However, it would be beneficial to include more details in the test function's documentation or comments about what specific aspects of the job-y.sh script are being tested, especially regarding the new job status reporting functionality. This would help maintainers and other developers understand the scope and purpose of the test more clearly.

Consider adding comments or documentation within the test function to clarify the specific behaviors being tested:

/// Tests the new job status reporting functionality in `job-y.sh`.
/// This test ensures that job statuses are correctly reported at each prompt when running the script.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 112163d and 9f34655.

Files selected for processing (10)
  • yash-builtin/src/jobs.rs (3 hunks)
  • yash-cli/CHANGELOG-bin.md (1 hunks)
  • yash-cli/CHANGELOG-lib.md (1 hunks)
  • yash-cli/src/startup/input.rs (4 hunks)
  • yash-cli/tests/scripted_test.rs (1 hunks)
  • yash-cli/tests/scripted_test/job-y.sh (1 hunks)
  • yash-env/CHANGELOG.md (2 hunks)
  • yash-env/src/input.rs (1 hunks)
  • yash-env/src/input/reporter.rs (1 hunks)
  • yash-env/src/job/fmt.rs (3 hunks)
Additional context used
Shellcheck
yash-cli/tests/scripted_test/job-y.sh

[warning] 5-5: Use semicolon or linefeed before 'done' (or quote to make it literal).

(SC1010)


[error] 8-8: You need a space after the [ and before the ].

(SC1035)


[error] 8-8: Couldn't parse this test expression. Fix to allow more checks.

(SC1073)


[error] 8-8: You need a space before the ].

(SC1020)


[error] 8-8: Missing space before ]. Fix any mentioned problems and try again.

(SC1072)

Additional comments not posted (7)
yash-cli/tests/scripted_test/job-y.sh (2)

14-23: Approve job control test setup.

The setup for testing job control with background processes and synchronization via a FIFO is correctly implemented and should effectively test the specified behavior.


8-9: Correct the syntax of the test expression.

The test expression on line 8 has multiple syntax errors related to spacing around brackets. Correcting these will ensure the script functions as intended.

Apply this diff to correct the syntax:

-[1] + Done                 sleep 0
+[1] + Done sleep 0

Likely invalid or redundant comment.

Tools
Shellcheck

[error] 8-8: You need a space after the [ and before the ].

(SC1035)


[error] 8-8: Couldn't parse this test expression. Fix to allow more checks.

(SC1073)


[error] 8-8: You need a space before the ].

(SC1020)


[error] 8-8: Missing space before ]. Fix any mentioned problems and try again.

(SC1072)

yash-env/src/input/reporter.rs (1)

25-47: Well-implemented Reporter struct.

The Reporter struct is well-designed and appropriately uses RefCell for mutable access to the environment. This is crucial for its functionality to report job status changes effectively.

yash-env/CHANGELOG.md (1)

8-16: Clear and informative changelog entries.

The changelog entries for job::fmt::Accumulator and input::Reporter are well-written and provide clear information about the new features added to the project.

yash-env/src/job/fmt.rs (1)

202-302: Well-designed Accumulator struct with effective methods.

The Accumulator struct is effectively designed to collect and format job reports. The methods new and add are well-implemented and documented, providing clear functionality for managing job reports.

yash-builtin/src/jobs.rs (1)

151-151: Review the integration of accumulator.add.

The replacement of accumulator.report with accumulator.add suggests a shift in how job statuses are handled. Ensure that the new method integrates well with the existing job management system and that it correctly updates job statuses as intended.

Run the following script to verify the integration of the accumulator.add method:

Also applies to: 158-158

Verification successful

Integration of accumulator.add is verified.

The accumulator.add method is correctly implemented in yash-env/src/job/fmt.rs and is integrated across multiple files, aligning with the intended functionality of updating job statuses. The method's usage and implementation confirm its role in the job management system. No issues were found with its integration.

  • File: yash-env/src/job/fmt.rs
  • Method Definition: pub fn add<S: System>(&mut self, index: usize, job: &Job, system: &S)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of `accumulator.add` method.

# Test: Search for the method usage. Expect: Only occurrences of the new method.
rg --type rust -A 5 $'accumulator.add'

Length of output: 2060


Script:

#!/bin/bash
# Description: Find the definition of the `accumulator.add` method to verify its implementation.

# Search for the definition of the `add` method in Rust files.
ast-grep --lang rust --pattern 'fn add($_, $_, $_) { $$$ }'

Length of output: 61


Script:

#!/bin/bash
# Description: Search for the `add` method within struct or trait implementations.

# Search for the `add` method in the context of a struct or trait.
rg --type rust -A 10 'fn add'

Length of output: 15469

yash-env/src/input.rs (1)

32-33: Approve the introduction of the reporter module.

The addition of the reporter module and its public exposure via pub use reporter::Reporter; are well-aligned with the PR's objectives to enhance job status reporting in the interactive shell. This change promotes better modularity and maintainability.

Consider verifying the integration of the Reporter module with the rest of the system to ensure there are no conflicts or issues:

Verification successful

Integration of the Reporter module is verified and no issues are found.

The Reporter module is well-integrated into the system, with its usage in yash-cli/src/startup/input.rs and thorough testing in yash-env/src/input/reporter.rs. There are no conflicts or issues detected in the integration.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of the `Reporter` module.

# Test: Search for any potential conflicts or issues related to the `Reporter` module.
rg --type rust -A 5 $'Reporter'

Length of output: 5162

Comment on lines +3 to +5
test_e 'interactive shell reports job status before prompt' -im
echo >&2; sleep 0& while kill -0 $! 2>/dev/null; do :; done
echo done >&2; exit
Copy link

Choose a reason for hiding this comment

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

Fix syntax issue with 'done' placement.

The script contains a syntax warning on line 5. To ensure proper execution and readability, consider adjusting the placement of 'done' or using a semicolon before it as suggested by Shellcheck (SC1010).

Apply this diff to fix the syntax issue:

-echo done >&2; exit
+echo done >&2; exit;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test_e 'interactive shell reports job status before prompt' -im
echo >&2; sleep 0& while kill -0 $! 2>/dev/null; do :; done
echo done >&2; exit
test_e 'interactive shell reports job status before prompt' -im
echo >&2; sleep 0& while kill -0 $! 2>/dev/null; do :; done
echo done >&2; exit;
Tools
Shellcheck

[warning] 5-5: Use semicolon or linefeed before 'done' (or quote to make it literal).

(SC1010)

yash-env/src/input/reporter.rs Show resolved Hide resolved
yash-builtin/src/jobs.rs Show resolved Hide resolved
@magicant magicant merged commit 579d8ee into master Aug 31, 2024
7 checks passed
@magicant magicant deleted the reporter branch August 31, 2024 15:32
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Report job status on each prompt
1 participant