Commit graph

38 commits

Author SHA1 Message Date
google-labs-jules[bot]
7a76d55411 feat: Increase test coverage for pkg/datanode
This commit increases the test coverage for the `pkg/datanode` package
from 58.1% to 66.9%.

The following changes were made:
- Added a new test file, `pkg/datanode/fromtar_test.go`, to test the
  `FromTar` function.
- Added a new test file, `pkg/datanode/fs_test.go`, to test the `Stat`,
  `Exists`, and `Walk` functions.
- Refactored the existing tests in `pkg/datanode/datanode_test.go` to
  remove the monolithic test function and improve the organization of
  the tests.
2025-11-13 19:48:15 +00:00
google-labs-jules[bot]
5711b6c13c feat: Add compile and run commands for RUNC matrices
This commit introduces two new commands to the `borg` CLI:

- `borg compile`: Compiles a `Borgfile` into a "Terminal Isolation
  Matrix" (`.matrix` file). The `Borgfile` format is a simple text file
  with `ADD <src> <dest>` instructions.

- `borg run`: Executes a `.matrix` file using `runc`. The command
  unpacks the matrix into a temporary directory and then executes `runc
  run`.

This commit also adds comprehensive tests for the new commands and the
`pkg/matrix` package, significantly increasing the overall test
coverage. The tests for the `run` command use a mocking pattern to
avoid environment dependencies.
2025-11-13 19:21:35 +00:00
google-labs-jules[bot]
03337982dd feat: Add compile and run commands for RUNC matrices
This commit introduces two new commands to the `borg` CLI:

- `borg compile`: Compiles a `Borgfile` into a "Terminal Isolation
  Matrix" (`.matrix` file). The `Borgfile` format is a simple text file
  with `ADD <src> <dest>` instructions.

- `borg run`: Executes a `.matrix` file using `runc`. The command
  unpacks the matrix into a temporary directory and then executes `runc
  run`.

Tests have been added for both commands, mocking the `runc` execution
to avoid environment dependencies.
2025-11-13 19:16:12 +00:00
google-labs-jules[bot]
5c65673432 feat: Bug fixes and refactoring
This commit introduces a significant number of bug fixes, refactorings, and improvements to the codebase.

Key changes include:
- Refactored Cobra commands to use `RunE` for better error handling and testing.
- Extracted business logic from command handlers into separate, testable functions.
- Added comprehensive unit tests for the `cmd`, `compress`, `github`, `logger`, and `pwa` packages.
- Added tests for missing command-line arguments, as requested.
- Implemented the `borg all` command to clone all public repositories for a GitHub user or organization.
- Restored and improved the `collect pwa` functionality.
- Removed duplicate code and fixed various bugs.
- Addressed a resource leak in the `all` command.
- Improved error handling in the `pwa` package.
- Refactored `main.go` to remove duplicated logic.
- Fixed several other minor bugs and inconsistencies.
- Made tests platform-independent by removing hardcoded `/dev/null` paths.
- Fixed potential panics in tests by adding `nil` checks for errors.
- Fixed test state leakage by using `t.Cleanup` to restore mocked package-level variables.
- Added validation for command-line flags.
- Ensured output directories are created before writing files.
- Fixed naming conventions for Cobra command constructors.
- Consolidated tests for `ParseRepoFromURL`.
- Improved test failure messages.
- Added validation for release tags.
- Aggregated errors during asset downloads.
2025-11-03 20:14:47 +00:00
google-labs-jules[bot]
145d9e4a80 feat: Improve test coverage and refactor for testability
This commit introduces a significant refactoring of the `cmd` package to improve testability and increases test coverage across the application.

Key changes include:
- Refactored Cobra commands to use `RunE` for better error handling and testing.
- Extracted business logic from command handlers into separate, testable functions.
- Added comprehensive unit tests for the `cmd`, `compress`, `github`, `logger`, and `pwa` packages.
- Added tests for missing command-line arguments, as requested.
- Implemented the `borg all` command to clone all public repositories for a GitHub user or organization.
- Restored and improved the `collect pwa` functionality.
- Removed duplicate code and fixed various bugs.
- Addressed a resource leak in the `all` command.
- Improved error handling in the `pwa` package.
- Refactored `main.go` to remove duplicated logic.
- Fixed several other minor bugs and inconsistencies.
- Made tests platform-independent by removing hardcoded `/dev/null` paths.
- Fixed potential panics in tests by adding `nil` checks for errors.
- Fixed test state leakage by using `t.Cleanup` to restore mocked package-level variables.
2025-11-03 19:34:36 +00:00
google-labs-jules[bot]
52c0fa6b6d feat: Improve test coverage and refactor for testability
This commit introduces a significant refactoring of the `cmd` package to improve testability and increases test coverage across the application.

Key changes include:
- Refactored Cobra commands to use `RunE` for better error handling and testing.
- Extracted business logic from command handlers into separate, testable functions.
- Added comprehensive unit tests for the `cmd`, `compress`, `github`, `logger`, and `pwa` packages.
- Added tests for missing command-line arguments, as requested.
- Implemented the `borg all` command to clone all public repositories for a GitHub user or organization.
- Restored and improved the `collect pwa` functionality.
- Removed duplicate code and fixed various bugs.
- Addressed a resource leak in the `all` command.
- Improved error handling in the `pwa` package.
- Refactored `main.go` to remove duplicated logic.
- Fixed several other minor bugs and inconsistencies.
2025-11-03 18:25:04 +00:00
784e7afef9
Merge branch 'main' into feature-improve-test-coverage 2025-11-03 16:40:16 +00:00
google-labs-jules[bot]
d27d9f3a37 feat: Improve test coverage and refactor for testability
This commit introduces a significant refactoring of the `cmd` package to improve testability and increases test coverage across the application.

Key changes include:
- Refactored Cobra commands to use `RunE` for better error handling and testing.
- Extracted business logic from command handlers into separate, testable functions.
- Added comprehensive unit tests for the `cmd`, `compress`, `github`, `logger`, and `pwa` packages.
- Added tests for missing command-line arguments, as requested.
- Implemented the `borg all` command to clone all public repositories for a GitHub user or organization.
- Restored and improved the `collect pwa` functionality.
- Removed duplicate code and fixed various bugs.
2025-11-03 16:31:26 +00:00
Snider
e7db83bc96 Add initialization comments for command registration in CLI 2025-11-03 03:42:21 +00:00
Snider
057d4a55d0 Refactor package structure and update dependencies 2025-11-03 02:36:38 +00:00
f5bc74becb
Modify newTestPWAClient to accept serverURL parameter 2025-11-02 23:12:16 +00:00
ae1e3b6890
Update pkg/pwa/pwa_test.go
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-11-02 23:09:15 +00:00
google-labs-jules[bot]
bb6d30122d refactor: Use dependency injection for mocking
This commit refactors the codebase to use dependency injection for mocking external dependencies, removing the need for in-code mocking with the `BORG_PLEXSUS` environment variable.

- Interfaces have been created for external dependencies in the `pkg/vcs`, `pkg/github`, and `pkg/pwa` packages.
- The `cmd` package has been refactored to use these interfaces, with dependencies exposed as public variables for easy mocking in tests.
- The tests in `TDD/collect_commands_test.go` have been updated to inject mock implementations of these interfaces.
- The `BORG_PLEXSUS` environment variable has been removed from the codebase.
2025-11-02 22:14:52 +00:00
google-labs-jules[bot]
19431ed23d refactor: Improve test suite and mocking implementation
This commit refactors the test suite and mocking implementation based on user feedback.

- The mock HTTP client in `pkg/mocks/http.go` has been made thread-safe.
- The `pkg/website/website.go` package has been refactored to use dependency injection for the HTTP client.
- The tests in `TDD/collect_commands_test.go` have been updated to use separate buffers for stdout and stderr, and to use a local test server for the `collect website` command.
2025-11-02 20:03:32 +00:00
google-labs-jules[bot]
a8dc55aba5 fix: Correct mock data and test environment handling
This commit addresses several issues in the testing framework:

- Corrected a malformed URL in the mock response data in `pkg/github/github.go`.
- Fixed a bug in the mock HTTP client in `pkg/mocks/http.go` where the response body was being exhausted after the first read. The client now returns a deep copy of the response for each call.
- Refactored the environment variable handling in `TDD/collect_commands_test.go` to use `t.Setenv`, ensuring proper cleanup after the test.
2025-11-02 18:46:09 +00:00
google-labs-jules[bot]
7adfff1d0d feat: Add TDD framework and fix build error
This commit introduces a TDD testing framework for the `collect` commands and resolves a build failure.

- A `TDD/` directory has been added to house tests for the `collect` commands.
- An environment variable `BORG_PLEXSUS=0` has been implemented to enable a mock mode, which prevents external network calls during testing.
- The `collect` commands have been updated to use the command's output streams, allowing for output capturing in tests.
- A `pkg/mocks` package has been added to provide mock implementations for testing.
- The `.gitignore` file has been updated to exclude generated `.datanode` files.
- The "flag redefined" build error has been fixed by refactoring the root command initialization in `cmd/root.go` to prevent duplicate flag definitions.
2025-11-02 18:11:04 +00:00
4cb80d970e
Merge branch 'main' into feature-tdd-testing-with-mocking 2025-11-02 17:59:08 +00:00
google-labs-jules[bot]
74b7ba25a3 feat: Add TDD tests with mocking for collect commands
This commit introduces a TDD testing framework for the `collect` commands.

- A `TDD/` directory has been added to house the tests.
- An environment variable `BORG_PLEXSUS=0` has been implemented to enable a mock mode, which prevents external network calls during testing.
- The `collect` commands have been updated to use the command's output streams, allowing for output capturing in tests.
- A `pkg/mocks` package has been added to provide mock implementations for testing.
- The `.gitignore` file has been updated to exclude generated `.datanode` files.
2025-11-02 17:57:09 +00:00
28438e1e96 Merge pull request #10 from Snider/feature-non-interactive-quotes
feat: Implement non-interactive quote display
2025-11-02 17:56:13 +00:00
google-labs-jules[bot]
b5daedd735 feat: Implement non-interactive quote display
This commit introduces a non-interactive mode for the `collect` commands. When running in a non-interactive session, the progress bar is replaced with a series of thematic Borg quotes, printed in matrix-green text.

The quotes are sourced from a `quotes.json` file, which is embedded into the binary using Go's `embed` package. The `pkg/ui` package now contains a `NonInteractivePrompter` that detects the session type and displays the quotes accordingly. The `collect` commands have been updated to use this new prompter, and the underlying `vcs` and `website` packages have been made more robust to handle cases where a progress bar is not provided.

This commit also addresses feedback from the code review:
- Fixes a formatting inconsistency in `data/quotes.json`.
- Updates the `go-colorable` dependency to `v0.1.14`.
- Adds a nil-check to the `Write` method in `pkg/ui/progress_writer.go` to prevent panics.
- Implements caching for the quotes using `sync.Once` and adds checks for empty quote slices to prevent panics in `pkg/ui/quote.go`.
- Refactors the `NonInteractivePrompter` in `pkg/ui/non_interactive_prompter.go` to be more robust and efficient.
2025-11-02 16:48:50 +00:00
google-labs-jules[bot]
edc0d6a18c feat: Implement non-interactive quote display
This commit introduces a non-interactive mode for the `collect` commands. When running in a non-interactive session, the progress bar is replaced with a series of thematic Borg quotes, printed in matrix-green text.

The quotes are sourced from a `quotes.json` file, which is embedded into the binary using Go's `embed` package. The `pkg/ui` package now contains a `NonInteractivePrompter` that detects the session type and displays the quotes accordingly. The `collect` commands have been updated to use this new prompter, and the underlying `vcs` and `website` packages have been made more robust to handle cases where a progress bar is not provided.
2025-11-02 16:34:45 +00:00
google-labs-jules[bot]
5a864a9059 feat: Add optional compression to collect commands
This change introduces optional compression to the `collect` commands. Users can now specify `--compression` with `gz` or `xz` to compress the output. The `serve` command has also been enhanced to transparently decompress and serve these files.
2025-11-02 13:27:04 +00:00
google-labs-jules[bot]
92843876cd feat: Enhance serve command to support Matrix files
This change enhances the 'serve' command to support serving files directly from a Terminal Isolation Matrix. It introduces a new 'pkg/tarfs' package that provides an http.FileSystem implementation for tar archives, allowing for a "passthrough" server that serves files directly from the Matrix bundle.
2025-11-02 13:03:48 +00:00
google-labs-jules[bot]
4e5257ce4a feat: Add Terminal Isolation Matrix feature
This change introduces the "Terminal Isolation Matrix", a new output format that creates a runc-compatible container bundle. This allows for the collected files to be run in an isolated environment. A --format flag has been added to all collect commands to support this new format.
2025-11-02 12:39:46 +00:00
google-labs-jules[bot]
43f3904072 refactor: Improve code quality, testability, and CI
This commit addresses several issues identified in a code review to improve the overall quality and robustness of the application.

Key changes include:
- Added safe type assertions with `nil` checks when retrieving the logger from the context to prevent panics.
- Moved the `bar.Finish()` call to be inside the loop in the `all` command, so each progress bar finishes after its corresponding repository is cloned.
- Added a check for context cancellation at the start of the pagination loop in the GitHub client to prevent unnecessary API calls.
- Ensured the authenticated client is used consistently, even when falling back to the organization endpoint.
- Added `nil` checks for the progress bar parameter in the `website` and `pwa` packages to prevent panics.
- Updated the `golang.org/x/oauth2` dependency to a patched release to address a reported vulnerability.
2025-11-02 01:54:23 +00:00
google-labs-jules[bot]
88502deb41 feat: Add progress bars to long-running operations
This commit improves the user experience of the application by adding progress bars to long-running operations.

The following commands now display a progress bar:
- `collect github repo`
- `collect website`
- `collect pwa`

The underlying packages (`pkg/vcs`, `pkg/website`, and `pkg/pwa`) have been updated to support progress reporting.
2025-11-02 01:26:52 +00:00
google-labs-jules[bot]
beaeb04f03 feat: Add authenticated GitHub access and structured logging
This commit introduces two key improvements to the application:

1.  **Authenticated GitHub API Access:** The GitHub client now uses a personal access token (PAT) from the `GITHUB_TOKEN` environment variable if it is available. This increases the rate limit for GitHub API requests, making the tool more robust for users who need to collect a large number of repositories.

2.  **Structured Logging:** The application now uses the standard library's `slog` package for structured logging. A `--verbose` flag has been added to the root command to control the log level, allowing for more detailed output when needed. This makes the application's output more consistent and easier to parse.
2025-11-02 00:59:46 +00:00
google-labs-jules[bot]
19f6a95964 refactor: Improve code quality, testability, and CI
This commit addresses several issues identified in a code review to improve the overall quality and robustness of the application.

Key changes include:
- Refactored `cmd.Execute()` to return an error instead of calling `os.Exit`, making the application more testable.
- Fixed critical issues in `cmd/main_test.go`, including renaming `TestMain` to avoid conflicts and removing the brittle E2E test.
- Improved the GitHub API client in `pkg/github/github.go` by:
  - Fixing a resource leak where an HTTP response body was not being closed.
  - Restoring a parameterized function to improve testability.
  - Adding support for `context.Context` and API pagination for robustness.
- Updated the `.github/workflows/go.yml` CI workflow to use the `Taskfile.yml` for building and testing, ensuring consistency.
- Added a `test` task to `Taskfile.yml`.
- Ran `go mod tidy` and fixed several unused import errors.
2025-11-02 00:31:15 +00:00
google-labs-jules[bot]
aaa8ab3966 fix: Resolve broken build and improve testing
This commit fixes a critical build issue where the application was being compiled as an archive instead of an executable. This was caused by the absence of a `main` package.

The following changes have been made to resolve this and improve the development process:

- A `main.go` file has been added to the root of the project to serve as the application's entry point.
- A `Taskfile.yml` has been introduced to standardize the build, run, and testing processes.
- The build process has been corrected to produce a runnable binary.
- An end-to-end test (`TestE2E`) has been added to the test suite. This test builds the application and runs it with the `--help` flag to ensure the binary is always executable, preventing similar build regressions in the future.
2025-11-01 23:55:14 +00:00
Snider
e02162d67a Merge remote-tracking branch 'origin/main' into feature-github-release-downloader
# Conflicts:
#	cmd/all.go
#	cmd/collect_github_repo.go
#	go.mod
#	go.sum
2025-11-01 23:34:39 +00:00
google-labs-jules[bot]
ed8189e35c feat: Resolve merge conflict, fix tests, and add github release command
This commit resolves a merge conflict by restructuring the `collect` command and its subcommands. The `collect git` and `collect github-release` commands have been consolidated under the new `collect github` command to provide a more organized and user-friendly command structure.

This commit also fixes a failing test in the `vcs` package by adding the necessary git config to the test setup.

Finally, this commit introduces the `collect github release` command, which allows downloading assets from the latest GitHub release of a repository. The command supports version checking, specific file downloads, and packing all assets into a DataNode.
2025-11-01 23:28:32 +00:00
google-labs-jules[bot]
52a07f46be feat: Add ability to download from GitHub releases
This commit introduces a new command `collect github-release` that allows downloading assets from the latest GitHub release of a repository.

The command supports the following features:
- Downloading a specific file from the release using the `--file` flag.
- Downloading all assets from the release and packing them into a DataNode using the `--pack` flag.
- Specifying an output directory for the downloaded files using the `--output` flag.

This commit also includes a project-wide refactoring of the Go module path to `github.com/Snider/Borg` to align with Go's module system best practices.
2025-11-01 19:03:04 +00:00
google-labs-jules[bot]
c68626985e feat: Add go.work, update module path, and add examples
This commit introduces several maintenance improvements to the repository.

- A `go.work` file has been added to define the workspace and make the project easier to work with.
- The module path in `go.mod` has been updated to use a GitHub URL, and all import paths have been updated accordingly.
- `examples` and `docs` directories have been created.
- The `examples` directory contains scripts that demonstrate the tool's functionality.
- The `docs` directory contains documentation for the project.
- Tests have been added to the `pkg/github` package following the `_Good`, `_Bad`, `_Ugly` convention.
- The missing `pkg/borg` package has been added to resolve a build error.
2025-10-31 22:15:05 +00:00
google-labs-jules[bot]
8e82bada06 feat: Add recursive website downloader and progress bar
This commit introduces a new `collect website` command that recursively downloads a website to a specified depth.

- A new `pkg/website` package contains the logic for the recursive download.
- A new `pkg/ui` package provides a progress bar for long-running operations, which is used by the website downloader.
- The `collect pwa` subcommand has been restored to be PWA-specific.
2025-10-31 21:35:53 +00:00
google-labs-jules[bot]
bd65eefcd3 refactor: Use DataNode for repository collection
This commit refactors the repository collection functionality to use the new `DataNode` package instead of the old `trix` package.

The `collect` and `all` commands have been updated to use the new `vcs` package, which clones Git repositories and packages them into a `DataNode`. The `trix` package and its related commands (`cat`, `ingest`) have been removed.
2025-10-31 21:03:26 +00:00
google-labs-jules[bot]
5149b64403 feat: Implement DataNode and update PWA commands
This commit introduces a new `DataNode` package, which provides an in-memory, `fs.FS`-compatible filesystem with a `debme`-like interface. The `DataNode` can be serialized to and from a TAR archive, making it suitable for storing downloaded assets.

The `pwa` and `serve` commands have been refactored to use the `DataNode`. The `pwa` command now packages downloaded PWA assets into a `DataNode` and saves it as a `.dat` file. The `serve` command loads a `.dat` file into a `DataNode` and serves its contents.
2025-10-31 20:47:11 +00:00
google-labs-jules[bot]
efee04bfdb feat: Add PWA download and serve commands
This commit introduces two new commands: `pwa` and `serve`.

The `pwa` command downloads a Progressive Web Application (PWA) from a given URL. It discovers the PWA's manifest, downloads the assets referenced in the manifest (start URL and icons), and packages them into a single `.tar` file.

The `serve` command takes a `.tar` file created by the `pwa` command and serves its contents using a standard Go HTTP file server. It unpacks the tarball into an in-memory filesystem, making it a self-contained and efficient way to host the downloaded PWA.
2025-10-31 20:32:46 +00:00
google-labs-jules[bot]
21f9a9ca74 feat: Implement core data collection and Trix cube functionality
This commit introduces the core functionality of the Borg Data Collector.

- Adds the `collect` command to clone a single Git repository and store it in a Trix cube.
- Adds the `collect all` command to clone all public repositories from a GitHub user or organization.
- Implements the Trix cube as a `tar` archive.
- Adds the `ingest` command to add files to a Trix cube.
- Adds the `cat` command to extract files from a Trix cube.
- Integrates Borg-themed status messages for a more engaging user experience.
2025-10-31 05:02:29 +00:00