Skip to content

Add comprehensive test suite for file persistence and change tracking #65

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

grouville
Copy link
Member

@grouville grouville commented Jun 13, 2025

Summary

Comprehensive test suite to ensure reliable file persistence, change tracking, and environment isolation in container-use.

Key Improvements

Core Functionality Tests

  • Work Persistence: Files and changes persist across container restarts
  • Change Tracking: Automatic capture and auditing of all modifications
  • File Handling: Graceful handling of Python caches, binaries, and large files
  • Environment Isolation: Safe parallel operations with proper isolation
  • Configuration: Reliable persistence of base images and setup commands

Test Coverage

  • Git operations (error handling, worktrees, empty directories)
  • Selective staging for Python cache and binary files
  • Configuration persistence and isolation verification
  • Behavior-driven tests focused on user experience
  • Test helpers for isolated environment setup

Implementation Notes

  • Modified git.go to support test isolation via CONTAINER_USE_CONFIG_DIR
  • Documented known limitations with skipped tests
  • Added to GitHub workflows for CI/CD

Status

Ready for review


Note: Some edge cases (Python cache, binary directories, environment variables) are documented as skipped tests for future resolution.

@grouville grouville marked this pull request as ready for review June 13, 2025 00:44
@@ -0,0 +1,210 @@
package environment
Copy link
Collaborator

Choose a reason for hiding this comment

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

the unit tests will conflict with #59, but not in a way that's hard to fix i don't think, just gotta move some shit around

@grouville grouville force-pushed the test-suite branch 2 times, most recently from dd281c8 to 88bc059 Compare June 13, 2025 22:35
Copy link
Member

@aluzzardi aluzzardi left a comment

Choose a reason for hiding this comment

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

Thank you @grouville, much appreciated! Some minor comments

@@ -0,0 +1,729 @@
package environment
Copy link
Member

Choose a reason for hiding this comment

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

nit: MAYBE we should move these into their own package, e.g. environment/integration or something, keep the unit tests top-level. MAYBE. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

imo for small projects the thing he's doing with -short is quite nice and provides a similar test grouping UX. i'd like to try it out and see if there are other drawbacks that aren't yet obvious to me... the one i can see from here is it might be too easy to share helpers that turn unit tests into int tests.

Copy link
Member Author

@grouville grouville Jun 16, 2025

Choose a reason for hiding this comment

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

nit: MAYBE we should move these into their own package, e.g. environment/integration or something, keep the unit tests top-level. MAYBE. Thoughts?

Regarding the integration tests: I’ve kept them in the environment package because they need access to the private functions to thoroughly verify the implementation. Moving them to a separate package (like environment_test or environment/integration) would limit testing to the public API only, reducing coverage (or requiring to turn more of those functions public. What would be your recommended approach (I don't mind) ?

@grouville grouville force-pushed the test-suite branch 2 times, most recently from 0a223b7 to 67a1630 Compare June 16, 2025 00:34
@grouville grouville requested review from aluzzardi and cwlbraa June 16, 2025 18:05
@grouville grouville force-pushed the test-suite branch 2 times, most recently from 4038593 to 6f4ec13 Compare June 16, 2025 18:33
@grouville grouville requested a review from cwlbraa June 17, 2025 08:16
@grouville grouville changed the title test: Ensure reliable preservation of user work and robust handling of edge cases Add comprehensive test suite for file persistence and change tracking Jun 17, 2025
Copy link
Collaborator

@cwlbraa cwlbraa left a comment

Choose a reason for hiding this comment

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

lgtm, just need to decide whether this or #62 goes in first... conventional wisdom says tests go in first, but idk cc @aluzzardi

…al behaviors users rely on:

* Persistence of work across sessions (files and changes remain intact through restarts).
* Automatic change tracking and audit trails for effective debugging.
* Graceful handling of problematic files, including Python cache, binary files, and large files.
* Isolation of multiple environments to support safe parallel operations.
* Reliable persistence of environment configuration (base images, setup commands).

Detailed testing includes:

* Git operations, specifically handling command errors, worktree paths, and empty directories.
* Selective file staging to manage Python cache and binary files appropriately.
* Verification of configuration persistence and environment isolation.

Adopted a behavior-driven testing approach focusing on user-experienced behaviors rather than internal implementation details.

Modified git.go to support test isolation via the `CONTAINER_USE_CONFIG_DIR` environment variable. Introduced test helpers to streamline the creation of isolated test environments.

Documented known limitations clearly with skipped tests for currently unresolved issues related to Python cache, binary directories, and environment variables.

Signed-off-by: Guillaume de Rouville <[email protected]>
make it work

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Guillaume de Rouville <[email protected]>
Updated the test to use commands that developers actually run:
- Creating build directories (common in CI/CD)
- Writing to build output logs (typical build process)
- Creating coverage directories (test runners like pytest)

These are more representative of real-world scenarios where commands
produce no git-trackable changes but should still be audited.

Related to issue dagger#82
The test now:
- Simulates Python cache directories without needing Python installed
- Verifies that development continues normally with __pycache__ present
- Serves as a regression test for Python workflows
- Renamed from PythonCache to PythonDevelopmentWorkflow for clarity

The original bug appears to have been fixed - __pycache__ directories
are properly ignored by git and don't interfere with operations.
Concurrency was properly implemented -- added a test showing that in a sequencial environment, every git operation is sequential and working
Removed the impossible concurrency test

Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Guillaume de Rouville <[email protected]>
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.

3 participants