Skip to content

Comments

Refactor random directory generation with optional cleanup#112

Merged
ryan-gang merged 5 commits intomainfrom
dir-cleanup-panic
Mar 26, 2025
Merged

Refactor random directory generation with optional cleanup#112
ryan-gang merged 5 commits intomainfrom
dir-cleanup-panic

Conversation

@ryan-gang
Copy link
Contributor

@ryan-gang ryan-gang commented Mar 11, 2025

Improvements to random directory generation now allow for optional cleanup. This enhances flexibility in test setups by enabling or disabling cleanup as needed.

Summary by CodeRabbit

  • New Features

    • Introduced flexible temporary directory management with optional cleanup, allowing for cleaner resource handling during testing.
  • Refactor

    • Enhanced the generation of unique temporary directories and streamlined the iteration process to improve consistency and reliability in test workflows.
    • Updated function names to follow a consistent naming convention, improving clarity and accessibility.

@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2025

Walkthrough

The changes enhance the directory creation functions by introducing a performCleanup parameter to getRandomDirectory, allowing for conditional cleanup of created directories. New functions, such as GetRandomDirectory, have been added, and existing functions have been renamed to follow a consistent naming convention. The modifications also include updates to various stage files to reflect these changes, ensuring that the new directory creation logic is uniformly applied across different test cases.

Changes

File(s) Change Summary
internal/utils_fs.go Modified getRandomDirectory to accept a performCleanup parameter, introduced GetRandomDirectory, and renamed getShortRandomDirectory and getShortRandomDirectories to GetShortRandomDirectory and GetShortRandomDirectories, respectively.
internal/stage1.go Updated call to getRandomDirectory to GetRandomDirectory.
internal/stage10.go, internal/stage11.go, internal/stage12.go Changed calls from getRandomDirectory to GetRandomDirectory.
internal/stage_q1.go to internal/stage_q5.go Replaced calls to getShortRandomDirectory with GetShortRandomDirectory.
internal/stage_r1.go to internal/stage_r4.go Updated calls from getShortRandomDirectories to GetShortRandomDirectories.
internal/utils_build.go Renamed directory creation calls to GetRandomDirectory and GetShortRandomDirectory based on the useShorterDirectory flag.

Possibly related PRs

Suggested reviewers

  • rohitpaulk

Poem

I hopped through lines of code with glee,
Where cleanup rules now set us free.
Directories unique, tidy, and bright,
With new functions, everything feels right.
A rabbit’s cheer echoes in every byte,
Hopping on patches deep into the night!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 5b28906 and d07fe67.

📒 Files selected for processing (1)
  • internal/stage1.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/stage1.go

🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 plan to trigger planning for file edits and PR creation.
  • @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.

@ryan-gang ryan-gang self-assigned this Mar 11, 2025
@ryan-gang
Copy link
Contributor Author

Ref:
image

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac5bbc and 4b6c58e.

📒 Files selected for processing (15)
  • internal/utils_fs.go (2 hunks)
  • internal/stage1.go (1 hunks)
  • internal/stage10.go (1 hunks)
  • internal/stage11.go (1 hunks)
  • internal/stage12.go (2 hunks)
  • internal/stage_q1.go (1 hunks)
  • internal/stage_q2.go (1 hunks)
  • internal/stage_q3.go (1 hunks)
  • internal/stage_q4.go (1 hunks)
  • internal/stage_q5.go (1 hunks)
  • internal/stage_r1.go (1 hunks)
  • internal/stage_r2.go (1 hunks)
  • internal/stage_r3.go (1 hunks)
  • internal/stage_r4.go (1 hunks)
  • internal/utils_build.go (1 hunks)
🔇 Additional comments (19)
internal/stage12.go (2)

15-15: Function call updated with cleanup functionality.

The change from getRandomDirectory to getRandomDirectoryWithCleanup aligns with the PR objective to include optional cleanup functionality. This ensures that temporary directories created during tests are properly cleaned up.


25-25: Consistent use of cleanup functionality.

Good use of the new function with cleanup capabilities for the second directory creation as well, maintaining consistency throughout the test implementation.

internal/stage_r4.go (1)

32-32: Updated to use directory generation with cleanup.

The function call has been appropriately updated to use getShortRandomDirectoriesWithCleanup, aligning with the PR objective to introduce optional cleanup for randomly generated directories. The error handling remains unchanged and follows the same pattern as the original code.

internal/stage_r3.go (1)

32-32: Consistent implementation of cleanup functionality.

The change to getShortRandomDirectoriesWithCleanup here follows the same pattern as in other files, providing a consistent approach to directory management across test cases. This modification ensures that test directories are cleaned up after use.

internal/stage_r1.go (1)

32-32: Directory creation updated with cleanup capability.

The function call has been properly updated to use getShortRandomDirectoriesWithCleanup. This is part of a consistent pattern across the codebase to introduce optional cleanup for test directories, improving resource management in tests.

internal/stage_r2.go (1)

32-32: Function name updated to reflect cleanup behavior.

The function call has been updated from getShortRandomDirectories to getShortRandomDirectoriesWithCleanup, which better reflects that this function now includes automatic cleanup functionality. This change is consistent with the refactoring approach across the codebase.

internal/stage1.go (1)

14-15: Good explanation for disabling cleanup.

The comment clearly explains why cleanup is disabled for this specific case (we don't want to clean up the HOME directory). The explicit false parameter makes the intention clear in the code.

internal/utils_build.go (1)

30-33: Function names updated to reflect cleanup behavior.

The function variables have been properly renamed to use the new functions with explicit cleanup behavior. This change is consistent with the refactoring approach in the rest of the codebase.

internal/utils_fs.go (4)

16-19: Good documentation for modified function.

The updated documentation clearly explains the purpose of the new performCleanup parameter and provides useful context about when to use cleanup.


21-29: Improved directory creation logic.

The updated logic now properly checks if a directory already exists and retries with a new random path if needed. This prevents potential issues if a directory with the same random name already exists.


31-37: Well-implemented conditional cleanup.

The conditional cleanup logic is cleanly implemented, using the performCleanup parameter to decide whether to register a teardown function.


42-44: Good wrapper function implementation.

This wrapper function provides a clean API for the common case where cleanup is desired, without requiring callers to specify the boolean parameter.

internal/stage_q1.go (1)

26-26: Consistent function update for directory cleanup

The function call has been updated to use getShortRandomDirectoryWithCleanup instead of getShortRandomDirectory, implementing the new cleanup functionality. This change maintains the same function signature and error handling pattern.

internal/stage_q3.go (1)

26-26: Consistent function update for directory cleanup

The function call has been updated to use getShortRandomDirectoryWithCleanup instead of getShortRandomDirectory, consistent with the changes in other files. This ensures temporary directories created during tests are properly cleaned up.

internal/stage11.go (1)

23-23: Consistent adoption of cleanup functionality

The function call has been updated to use getRandomDirectoryWithCleanup instead of getRandomDirectory. This change is consistent with the refactoring approach across the codebase to add automatic cleanup for test directories.

internal/stage10.go (1)

22-22: Consistent function update for directory cleanup

The function call has been updated to use getRandomDirectoryWithCleanup instead of getRandomDirectory, maintaining consistency with similar changes across the codebase. This ensures test directories are properly cleaned up after tests complete.

internal/stage_q5.go (1)

26-26: Good update to use the improved directory function with cleanup

The change from getShortRandomDirectory to getShortRandomDirectoryWithCleanup aligns with the PR objective of refactoring random directory generation to include cleanup functionality. This helps prevent test artifacts from remaining in the filesystem after tests complete.

internal/stage_q2.go (1)

28-28: Consistent implementation of directory cleanup functionality

The function update to getShortRandomDirectoryWithCleanup maintains consistency with the changes across other files and implements the cleanup feature as intended in the PR objectives.

internal/stage_q4.go (1)

31-31: Appropriate adoption of cleanup-enabled directory function

This change correctly implements the new directory function with cleanup capabilities, which will help maintain a cleaner test environment by removing temporary directories when they're no longer needed.

@ryan-gang ryan-gang requested a review from rohitpaulk March 11, 2025 06:45

randomDir, err := getRandomDirectory(stageHarness)
// We don't want to cleanup the HOME directory here
randomDir, err := getRandomDirectory(stageHarness, false)
Copy link
Member

Choose a reason for hiding this comment

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

@ryan-gang why can't this be destroyed after the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a case, where I found a gocache in the $HOME directory, which was in use when we tried to force cleanup, that led to a panic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like we purged the logs for the panic.
I am reverting this change for now, will keep my eyes peeled for anything similar.

Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

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

Notes added

@ryan-gang
Copy link
Contributor Author

Functionally not much changed here, our interfaces are still the same, fixtures also didn't change. Still cleanup is present for all stages.
Merging this in.

@ryan-gang ryan-gang merged commit 4bce235 into main Mar 26, 2025
6 checks passed
@ryan-gang ryan-gang deleted the dir-cleanup-panic branch March 26, 2025 06:56
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