Skip to content

Feat/test agent#3

Merged
Evan-Paillard merged 5 commits intomainfrom
feat/test-agent
Feb 26, 2026
Merged

Feat/test agent#3
Evan-Paillard merged 5 commits intomainfrom
feat/test-agent

Conversation

@Evan-Paillard
Copy link
Copy Markdown
Collaborator

@Evan-Paillard Evan-Paillard commented Feb 2, 2026

Add integration tests for agent injection

Description

Added a proper integration test suite to verify the builder actually generates bootable archives.

Key changes:

  • tests/integration_test.rs: Downloads a kernel, builds an initramfs with a custom agent, and boots it in QEMU.
  • tests/agent/: A dummy agent to verify reliable communication from inside the VM.

This proves that injected binaries run correctly on boot.

How Has This Been Tested?

Ran cargo test --test integration_test locally.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Tests
    • Added comprehensive integration test suite for InitramfsBuilder, covering compression modes, file and init script injection, metadata validation, exclude patterns, and reproducibility verification.

.gitignore Outdated
**/.DS_Store

# Test artifacts
tests/fixtures/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you are not generating any fixture with the tests, tell me if i am wrong but if not you should leave the gitignore untouched

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

A new integration test suite is added for InitramfsBuilder with helper utilities and seven tokio-based async tests. Tests validate CPIO archive generation, metadata accuracy, init script injection, file injection, compression modes, exclude patterns, and reproducibility. Includes CPIO newc parser and gzip decompression utilities.

Changes

Cohort / File(s) Summary
Integration Test Suite
tests/integration_test.rs
Seven async integration tests for InitramfsBuilder covering archive generation, metadata validation, init/file injection, compression modes, exclude patterns, and reproducibility. Includes helper functions for test file creation, CPIO entry parsing, and gzip decompression.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A suite of tests, bundled with care,
CPIO archives parsed everywhere!
Gzip streams flow, injections take hold,
Reproducibility—the story retold.
Compression modes tested, no bugs left behind! 🎉

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.64% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feat/test agent' is vague and does not clearly describe the main change. It uses non-descriptive terminology that doesn't convey meaningful information about adding an integration test suite. Consider renaming to something like 'Add integration tests for initramfs builder validation' to clearly convey the main purpose of the changeset.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description includes most required sections from the template and provides clear context about the changes, testing performed, and checklist status, though one checklist item remains unchecked.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/test-agent

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

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

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be228b2 and 1e891cb.

📒 Files selected for processing (1)
  • tests/integration_test.rs
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/integration_test.rs`:
- Around line 250-252: The strict ordering assertion between none_size and
gzip_size is flaky; change the check on the sizes (the variables none_size and
gzip_size derived from sizes.iter()) to a tolerant assertion or weaker check:
either assert both sizes are non-zero (e.g., assert!(none_size > 0 && gzip_size
> 0)) or use a ratio/tolerance comparison (e.g., treat none_size >= gzip_size *
0.95) so gzip can be slightly larger without failing; update the assertion
accordingly to match the earlier metadata ratio style if you keep a ratio-based
check.
- Around line 91-94: The test currently hardcodes the floating image string
"debian:stable-slim" in the InitramfsBuilder chain
(InitramfsBuilder::new().image(...).build(&output)); add a helper function like
test_image() that reads INITRAMFS_TEST_IMAGE from the environment with a
fallback to "debian:stable-slim", then replace the literal in the image(...)
call with test_image(); this centralizes the image, allows CI to pin or override
the image, and improves reproducibility while keeping existing assertions
intact.

Comment on lines +91 to +94
let result = InitramfsBuilder::new()
.image("debian:stable-slim")
.compression(Compression::Gzip)
.build(&output)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, find the integration test file
find . -name "integration_test.rs" -type f

Repository: DO-2K24-27/rusty-initramfs-builder

Length of output: 105


🏁 Script executed:

# Read the integration test file to see the context around lines 91-94
wc -l ./tests/integration_test.rs

Repository: DO-2K24-27/rusty-initramfs-builder

Length of output: 109


🏁 Script executed:

# Read the area around lines 91-94
sed -n '85,100p' ./tests/integration_test.rs

Repository: DO-2K24-27/rusty-initramfs-builder

Length of output: 557


🏁 Script executed:

# Check the entire test file to see all test functions and image usage patterns
grep -n "\.image(" ./tests/integration_test.rs

Repository: DO-2K24-27/rusty-initramfs-builder

Length of output: 449


🏁 Script executed:

# Check for existing env var patterns in the test file
grep -n "env::" ./tests/integration_test.rs

Repository: DO-2K24-27/rusty-initramfs-builder

Length of output: 60


🏁 Script executed:

# Read the full test file to understand what assertions are being made
cat -n ./tests/integration_test.rs

Repository: DO-2K24-27/rusty-initramfs-builder

Length of output: 12226


Consider parameterizing the base image via environment variable for better test reproducibility and CI efficiency.

debian:stable-slim is a floating tag and will pull different builds over time. While current assertions are robust (checking for basic directory structures that exist in all stable Debian releases), pinning or centralizing the image string with env overrides improves build reproducibility and avoids unnecessary re-pulls across CI runs.

🔧 Suggested change (within this call site)
-        .image("debian:stable-slim")
+        .image(&test_image())

Add a helper near the top of the file:

fn test_image() -> String {
    std::env::var("INITRAMFS_TEST_IMAGE")
        .unwrap_or_else(|_| "debian:stable-slim".to_string())
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration_test.rs` around lines 91 - 94, The test currently hardcodes
the floating image string "debian:stable-slim" in the InitramfsBuilder chain
(InitramfsBuilder::new().image(...).build(&output)); add a helper function like
test_image() that reads INITRAMFS_TEST_IMAGE from the environment with a
fallback to "debian:stable-slim", then replace the literal in the image(...)
call with test_image(); this centralizes the image, allows CI to pin or override
the image, and improves reproducibility while keeping existing assertions
intact.

Comment on lines +250 to +252
let none_size = sizes.iter().find(|(l, _)| l == "none").unwrap().1;
let gzip_size = sizes.iter().find(|(l, _)| l == "gzip").unwrap().1;
assert!(none_size > gzip_size);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Compression size ordering isn’t guaranteed.

Gzip can be slightly larger for certain inputs, which can make this flaky. Consider adding a tolerance or only asserting non‑zero sizes. If you keep a ratio check, align the earlier metadata test for consistency.

🔧 Example tolerance-based assertion
-    assert!(none_size > gzip_size);
+    assert!(
+        gzip_size <= none_size + 4096,
+        "gzip output larger than uncompressed by >4KiB"
+    );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration_test.rs` around lines 250 - 252, The strict ordering
assertion between none_size and gzip_size is flaky; change the check on the
sizes (the variables none_size and gzip_size derived from sizes.iter()) to a
tolerant assertion or weaker check: either assert both sizes are non-zero (e.g.,
assert!(none_size > 0 && gzip_size > 0)) or use a ratio/tolerance comparison
(e.g., treat none_size >= gzip_size * 0.95) so gzip can be slightly larger
without failing; update the assertion accordingly to match the earlier metadata
ratio style if you keep a ratio-based check.

@Evan-Paillard Evan-Paillard merged commit 02cf29d into main Feb 26, 2026
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 12, 2026
8 tasks
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