Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c818331
feat(cli): Implement robust CLI argument parsing and file type detection
unclesp1d3r Oct 3, 2025
40e6243
feat(tests): Add compatibility testing framework and CI integration
unclesp1d3r Oct 3, 2025
459176a
feat(magic): Add basic magic file for testing and enhance CLI functio…
unclesp1d3r Oct 3, 2025
57895d3
feat(cli): Enhance error handling and validation in CLI
unclesp1d3r Oct 3, 2025
ce82bc2
chore(third_party): Update third-party test files and configurations
unclesp1d3r Oct 3, 2025
c8f6079
feat(third_party): Add magic.mgc file for file type detection testing
unclesp1d3r Oct 3, 2025
a292ebc
chore(tests): Remove submodule for compatibility tests and update ver…
unclesp1d3r Oct 3, 2025
9e66f36
feat(output): Add JSON output support for file type detection
unclesp1d3r Oct 5, 2025
d89a7c4
refactor(validation): Improve configuration validation with modular c…
unclesp1d3r Oct 5, 2025
669c409
refactor(error): Improve error handling and message formatting in CLI…
unclesp1d3r Oct 5, 2025
dfbdcfd
feat(evaluator): Add support for string type evaluation in magic rules
unclesp1d3r Oct 5, 2025
70fb073
feat(magic): Add basic string type support in AST and matching
unclesp1d3r Oct 5, 2025
6e788f9
refactor(validation): Improve error handling and message formatting i…
unclesp1d3r Oct 5, 2025
a901194
refactor(performance): Optimize JSON and parsing operations with iter…
unclesp1d3r Oct 5, 2025
67b22b4
chore(hooks): Simplify CI auto-fix hook configuration
unclesp1d3r Oct 5, 2025
320c355
feat(error): Add comprehensive error handling for libmagic-rs
unclesp1d3r Oct 5, 2025
03cf006
feat(error): Add evaluation error types for runtime detection
unclesp1d3r Oct 6, 2025
0422003
feat(evaluator): Implement graceful error handling in rule evaluation
unclesp1d3r Oct 7, 2025
34b6c1c
chore(ci): Update CI configuration for libmagic-rs
unclesp1d3r Oct 7, 2025
2d13b03
chore(dependencies): Update dependencies and improve test handling
unclesp1d3r Oct 7, 2025
3a939f1
test(cli): normalize rmagic(.exe) via insta filters for cross-platfor…
unclesp1d3r Oct 7, 2025
28cd4ea
build(justfile): improve cross-platform coverage commands
unclesp1d3r Oct 7, 2025
819eb65
refactor(project-structure): Reorganize test files and update documen…
unclesp1d3r Oct 8, 2025
670c37d
feat(tests): normalize file paths in CLI integration test snapshots
unclesp1d3r Oct 8, 2025
fbd4142
chore(tasks): Update implementation progress tracking in project tasks
unclesp1d3r Oct 8, 2025
4304438
chore(tasks): Update implementation progress tracking in project tasks
unclesp1d3r Oct 8, 2025
f8446b7
feat(parser): Enhance magic rule parsing with advanced value and oper…
unclesp1d3r Oct 8, 2025
1ab2604
fix: resolve clippy warning in test_all_offset_spec_variants (#8)
Copilot Nov 9, 2025
8bc47fa
Merge branch 'main' into create_rmagic_cli
unclesp1d3r Dec 14, 2025
b210656
fix(tests): Handle Windows drive letters in CLI output normalization …
Copilot Dec 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coderabbitai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ reviews:
"!*.svg",
"!*.ico",
"!*.wxs",
"!third_party/**",
]
path_instructions:
- path: "src/lib.rs"
Expand Down
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ LICENSE text
*.ico binary
*.svg text

# Test files
**/*.result binary
**/*.testfile binary

# Font files
*.ttf binary
*.eot binary
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:
files: lcov.info
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
slug: EvilBit-Labs/StringyMcStringFace
slug: EvilBit-Labs/libmagic-rs
- uses: qltysh/qlty-action/coverage@v2
with:
token: ${{ secrets.QLTY_COVERAGE_TOKEN }}
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Compatibility Tests

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
# Run daily at 2 AM UTC to catch any regressions
- cron: "0 2 * * *"

jobs:
compatibility-tests:
name: Compatibility Tests
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout code
uses: actions/checkout@v5

- uses: dtolnay/rust-toolchain@1.90

- name: Install just task runner
uses: taiki-e/install-action@v2
with:
tool: just

- name: Verify compatibility test files are available
run: just verify-compatibility-tests

- name: Build rmagic
run: cargo build --release

- name: Run compatibility tests
run: cargo test test_compatibility_with_original_libmagic -- --ignored
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,3 @@ megalinter-reports/
.intentionally-empty-file.o

# Files for validating the tooling
test_files/
Empty file added .gitmodules
Empty file.
9 changes: 2 additions & 7 deletions .kiro/hooks/ci-auto-fix.kiro.hook
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
"when": {
"type": "userTriggered",
"patterns": [
"**/*.rs",
"**/Cargo.toml",
"**/Cargo.lock",
"justfile",
"deny.toml",
"rust-toolchain.toml"
"**/*.rs"
]
},
"then": {
"type": "askAgent",
"prompt": "1. First, run `just ci-check` to identify any failures\n2. Analyze the output to understand what specific checks are failing. If everything passes, you're done.\n3. Make minimal, targeted fixes to address ONLY the failing checks:\n- For formatting issues: run `just format`\n- For linting issues (clippy): fix the specific violations reported (rerun with `just lint-rust` / `just lint-rust-min`)\n- For compilation/type errors: fix the underlying Rust code until `just check` (or `cargo check`) succeeds\n- For test failures: fix the failing tests or underlying code (verify with `just test` or `just test-ci`)\n- For dependency security/advisory issues: run `just audit` (cargo-audit) and/or update `Cargo.toml` then `cargo update`\n- For license/compliance issues: run `just deny` and address cargo-deny findings\n4. After making fixes, run `just ci-check` again to verify all checks pass\n5. If any checks still fail, repeat steps 2-4 until all checks pass\n6. Provide a summary of what was fixed and confirm that `just ci-check` now passes completely\nKeep changes minimal and focused - only fix what's actually causing the CI failures. Do not make unnecessary refactoring or style changes beyond what's required to pass the checks."
}
}
}
455 changes: 113 additions & 342 deletions .kiro/specs/rust-libmagic-implementation/tasks.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .mdformat.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ exclude = [
"**/CHANGELOG.md",
"target/**",
"megalinter-reports/**",
"**/*.result",
"**/*.testfile",
]
validate = true
number = true
Expand Down
38 changes: 19 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ repos:
hooks:
- id: cargo-machete

# Markdown formatting and linting (temporarily disabled in CI due to path issues)
- repo: https://github.com/hukkin/mdformat
rev: 0.7.22
hooks:
- id: mdformat
additional_dependencies:
- mdformat-gfm
- mdformat-admon
- mdformat-config
- mdformat-footnote
- mdformat-frontmatter
- mdformat-simple-breaks
- mdformat-tables
- mdformat-web
- mdformat-wikilink
- mdformat-gfm-alerts
- mdformat-rustfmt
- mdformat-toc
files: \.(md|mdx)$
# Markdown formatting and linting (temporarily disabled due to rust code block formatting issues)
# - repo: https://github.com/hukkin/mdformat
# rev: 0.7.22
# hooks:
# - id: mdformat
# additional_dependencies:
# - mdformat-gfm
# - mdformat-admon
# - mdformat-config
# - mdformat-footnote
# - mdformat-frontmatter
# - mdformat-simple-breaks
# - mdformat-tables
# - mdformat-web
# - mdformat-wikilink
# - mdformat-gfm-alerts
# - mdformat-toc
# files: \.(md|mdx)$
# exclude: ^target/|

# Security audit for Rust dependencies (moved to CI)
- repo: local
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
**/*.md
**/*.yml
**/*.result
**/*.testfile
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ thiserror = "2.0.17"

[dev-dependencies]
criterion = "0.7.0"
insta = { version = "1.39.0", features = ["json"] }
nix = { version = "0.30", features = ["fs"] }
proptest = "1.8.0"
regex = "1.11.0"
temp-env = "0.2.0"
tempfile = "3.8.1"

# The profile that 'dist' will build with
[profile.dist]
Expand Down
13 changes: 13 additions & 0 deletions docs/src/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rmagic [OPTIONS] <FILE>...
- **Description**: Path to the file(s) to analyze
- **Multiple**: Yes, can specify multiple files
- **Examples**:

```bash
rmagic file.bin
rmagic file1.exe file2.pdf file3.zip
Expand All @@ -28,6 +29,7 @@ rmagic [OPTIONS] <FILE>...

- **Description**: Display help information and exit
- **Example**:

```bash
rmagic --help
```
Expand All @@ -36,6 +38,7 @@ rmagic [OPTIONS] <FILE>...

- **Description**: Display version information and exit
- **Example**:

```bash
rmagic --version
```
Expand All @@ -47,10 +50,13 @@ rmagic [OPTIONS] <FILE>...
- **Description**: Output results in JSON format instead of text
- **Default**: Text format
- **Example**:

```bash
rmagic --json file.bin
```

- **Output Example**:

```json
{
"filename": "file.bin",
Expand All @@ -65,6 +71,7 @@ rmagic [OPTIONS] <FILE>...
- **Description**: Output results in text format (default behavior)
- **Default**: Enabled
- **Example**:

```bash
rmagic --text file.bin
# Output: file.bin: ELF 64-bit LSB executable
Expand All @@ -78,6 +85,7 @@ rmagic [OPTIONS] <FILE>...
- **Type**: Path to magic file
- **Default**: Built-in magic database
- **Example**:

```bash
rmagic --magic-file custom.magic file.bin
rmagic --magic-file /usr/share/misc/magic file.bin
Expand All @@ -90,6 +98,7 @@ rmagic [OPTIONS] <FILE>...
- **Description**: Output MIME type instead of description
- **Status**: 📋 Planned
- **Example**:

```bash
rmagic --mime-type file.bin
# Output: application/x-executable
Expand All @@ -100,6 +109,7 @@ rmagic [OPTIONS] <FILE>...
- **Description**: Output MIME encoding
- **Status**: 📋 Planned
- **Example**:

```bash
rmagic --mime-encoding text.txt
# Output: us-ascii
Expand All @@ -110,6 +120,7 @@ rmagic [OPTIONS] <FILE>...
- **Description**: Brief output (no filename prefix)
- **Status**: 📋 Planned
- **Example**:

```bash
rmagic --brief file.bin
# Output: ELF 64-bit LSB executable
Expand Down Expand Up @@ -236,6 +247,7 @@ rmagic --recursive /path/to/directory/
- **Description**: Default magic file path
- **Default**: Built-in magic database
- **Example**:

```bash
export MAGIC=/usr/local/share/magic
rmagic file.bin # Uses /usr/local/share/magic
Expand All @@ -246,6 +258,7 @@ rmagic --recursive /path/to/directory/
- **Description**: Enable debug output
- **Values**: `0` (off), `1` (basic), `2` (verbose)
- **Example**:

```bash
RMAGIC_DEBUG=1 rmagic file.bin
```
Expand Down
6 changes: 4 additions & 2 deletions docs/src/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,10 @@ use libmagic_rs::*;
#[test]
fn test_end_to_end_workflow() {
// Test complete workflows
let db = MagicDatabase::load_from_file("test_files/magic/simple.magic").unwrap();
let result = db.evaluate_file("test_files/samples/elf64").unwrap();
let db = MagicDatabase::load_from_file("third_party/magic.mgc").unwrap();
let result = db
.evaluate_file("third_party/tests/elf64.testfile")
.unwrap();
assert_eq!(result.description, "ELF 64-bit LSB executable");
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ libmagic-rs/
│ └── io/
│ └── mod.rs # I/O utilities (placeholder)
├── tests/ # Integration tests
├── test_files/ # Test magic files and samples
├── third_party/ # Canonical libmagic tests and magic files
└── docs/ # This documentation
```

Expand Down
59 changes: 57 additions & 2 deletions docs/src/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ Validate against GNU `file` command:
```rust
#[test]
fn test_elf_detection_compatibility() {
let gnu_result = run_gnu_file("test_files/elf64_sample");
let our_result = evaluate_file("test_files/elf64_sample");
let gnu_result = run_gnu_file("third_party/tests/elf64.testfile");
let our_result = evaluate_file("third_party/tests/elf64.testfile");

assert_eq!(extract_file_type(&gnu_result), our_result.description);
}
Expand Down Expand Up @@ -452,6 +452,61 @@ cargo flamegraph --bench parser_bench
valgrind --tool=massif target/release/rmagic large_file.bin
```

## CLI Testing and Cross-Platform Snapshots

### CLI Integration Tests

CLI functionality is tested using integration tests with insta snapshots to ensure consistent output across different platforms.

### Cross-Platform Normalization

**Important**: CLI insta snapshots must use the normalization helper to ensure consistent results between Windows and Unix systems:

```rust
mod common;

#[test]
fn test_cli_help_output() {
let result = run_cli(&["--help"]);
let stdout = String::from_utf8(result.stdout).unwrap();

// REQUIRED: Use normalization for CLI snapshots
let normalized_stdout = common::normalize_cli_output(&stdout);
assert_snapshot!("help_output", normalized_stdout);
}
```

### Normalization Features

The `common::normalize_cli_output()` function handles:

- **Executable Names**: Converts `rmagic.exe` → `rmagic` for Windows compatibility
- **Path Prefixes**: Removes Windows `\\?\\` path prefixes
- **Error Messages**: Filters out cargo-specific error output

### Running CLI Tests

```bash
# Run all CLI integration tests
cargo test --test cli_integration_tests

# Run CLI normalization tests
cargo test --test cli_normalization

# Review snapshot changes
cargo insta review

# Accept all snapshot changes (use with caution)
cargo insta accept
```

### Snapshot Best Practices

1. **Always Normalize**: Use `normalize_cli_output()` for CLI snapshots
2. **Review Changes**: Always review snapshot diffs with `cargo insta review`
3. **Test Cross-Platform**: Verify tests pass on both Windows and Unix
4. **Keep Snapshots Small**: Use focused tests for specific CLI features

## Future Testing Plans

### Integration Testing
Expand Down
Loading
Loading