Skip to content

feat: parser integration, CI modernization with mise, and Dev Container support#26

Merged
unclesp1d3r merged 28 commits into
mainfrom
17-parser-integration-magic-file-loading-directory-support
Jan 24, 2026
Merged

feat: parser integration, CI modernization with mise, and Dev Container support#26
unclesp1d3r merged 28 commits into
mainfrom
17-parser-integration-magic-file-loading-directory-support

Conversation

@unclesp1d3r
Copy link
Copy Markdown
Member

This pull request introduces several improvements to the development workflow, focusing on modernizing CI/CD pipelines, enhancing developer experience with Dev Containers, and refining documentation and configuration. The most significant changes are the migration to the mise tool for environment setup in CI, the addition of a comprehensive Dev Container configuration for Rust development, and updates to documentation and configuration files for clarity and maintainability.

CI/CD Modernization:

  • Replaced the use of dtolnay/rust-toolchain and various tool-specific setup steps in all GitHub Actions workflows with the unified jdx/mise-action@v3 for environment setup and caching, simplifying and standardizing the CI pipeline. Also updated actions/checkout to v6 in all workflows. [1]], [2]], [3]], [4]], [5]], [6]], [7]], [8]], [9]], [10]])

  • Updated job dependencies in .github/workflows/ci.yml to ensure quality and test jobs run in the correct order, improving workflow reliability. [1]], [2]])

Dev Container Support:

  • Added .devcontainer/devcontainer.json to provide a feature-rich Rust development environment with pre-installed tools, VS Code extensions, and performance optimizations (e.g., cargo cache volume), streamlining onboarding and local development. ([.devcontainer/devcontainer.jsonR1-R97])

  • Added support for Dependabot updates for Dev Containers in .github/dependabot.yml, ensuring container features stay up-to-date. ([.github/dependabot.ymlL1-R11])

Documentation and Configuration Updates:

  • Improved the commit message guidelines in .github/commit-instructions.md for clarity and brevity, with clearer examples and scope/type explanations. ([.github/commit-instructions.mdL3-L34])

  • Cleaned up .pre-commit-config.yaml by removing the local cargo-audit hook (now handled in CI) and correcting plugin names. [1]], [2]])

  • Minor configuration tweaks, such as enabling collapsed walkthroughs in .coderabbitai.yaml and adding /cache to .serena/.gitignore. [1]], [2]])

unclesp1d3r and others added 10 commits January 22, 2026 20:55
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
* feat(docs): add contribution guidelines and update architecture diagrams

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* style(toml): format spacing and alignment in dist-workspace.toml

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* chore(vscode): update ruff configuration paths in settings

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* feat(parser): implement libmagic strength calculation and parsing

- Add apprentice_magic_strength algorithm port from libmagic
- Implement strength modifier parsing with !:strength syntax
- Calculate default strength based on rule specificity
- Store strength in MagicRule structure for evaluation
- Update rule sorting by strength during evaluation
- Add unit tests for strength parsing and calculation
- Integrate strength into confidence scoring and rule ordering

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* feat(docs): update documentation for phase 1 MVP enhancements

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* style(docs): format spacing and alignment in book.toml

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* feat(tools): add tools configuration for project dependencies

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* ci: upgrade checkout action to v6 and add mise-action

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* chore(ci): replace rustfmt action with just fmt-check command

chore(mise): update Rust and add new tools for formatting and auditing

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* refactor(justfile): streamline cross-platform helper commands

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* chore: simplify justfile and mise.toml tooling

- Move Rust components (llvm-tools-preview) to mise.toml
- Add mdformat with plugins via mise pipx backend
- DRY up GoReleaser and coverage recipes with private helpers
- Remove unused recipes (cd-root, help, test-justfile, test-fs)
- Simplify format-docs using mdformat's built-in --exclude
- Update dependencies

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* ci: update job dependencies for test and coverage workflows

- Ensure 'quality' job is a dependency for 'test'
- Ensure 'test' job is a dependency for 'test-cross-platform'

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* chore(deps): update Rust version to 1.91.0 in configuration

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* fix: remove unused mdbook-yml-header preprocessor

No docs use YAML front matter, so this preprocessor is unnecessary
and was causing CI issues.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* chore: add .gitignore and project.yml for configuration

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

* chore(docs): update repository URL in documentation files

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>

---------

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
@unclesp1d3r unclesp1d3r self-assigned this Jan 23, 2026
@unclesp1d3r unclesp1d3r linked an issue Jan 23, 2026 that may be closed by this pull request
12 tasks
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 23, 2026

Caution

Review failed

The pull request is closed.

Summary by CodeRabbit

  • New Features

    • Format-aware magic loading: text, directory, and binary detection; directory loading preserves alphabetical order
    • Magic source tracking preserved with loaded metadata
    • Configurable evaluator limits with timeout and improved error diagnostics
  • Documentation

    • Major docs and getting-started updates reflecting Phase 1 MVP, examples, and API usage
  • Chores

    • Devcontainer added for standardized dev env
    • Homebrew publish workflow and distribution metadata added
  • Tests

    • Extensive integration and directory-loading test coverage added

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Adds format detection and unified magic-file loading (Text/Directory/Binary) with alphabetical directory merging and non-fatal per-file parse errors; MagicDatabase records source_path; evaluator recursion underflow now returns propagated errors; CLI discovery/fallbacks, docs, tests, devcontainer, and CI/release tooling updated.

Changes

Cohort / File(s) Summary
Configuration & Devcontainer
\.coderabbitai.yaml, .devcontainer/devcontainer.json, .github/dependabot.yml, mise.toml, dist-workspace.toml, .github/workflows/ci.yml, justfile
Add Rust devcontainer; update Dependabot and tooling entries; add new tools and rust components; change distribution/publish fields (homebrew tap); gate CI quality on rust changes; route commands via mise exec.
Docs & Guides
.github/commit-instructions.md, AGENTS.md, README.md, docs/src/...
Rework commit guidance; add emoji guidance; expand README and docs for Phase 1, parser/evaluator APIs, error modeling, examples, and getting-started content.
Parser & Format Detection
Parser core: src/parser/mod.rs, src/parser/..., docs/src/parser.md, tests/parser_integration_tests.rs
Add MagicFileFormat enum and detect_format(path); add load_magic_file() dispatcher and load_magic_directory() that merges files alphabetically and treats per-file parse errors as non-fatal; add tests and docs.
Library & CLI
src/lib.rs, src/main.rs, tests/cli_integration_tests.rs, tests/compatibility_tests.rs
MagicDatabase gains source_path: Option<PathBuf> and accessor; load_from_file now uses parser loaders and sets source_path; CLI discovery uses detect_format() and accepts directories; fallback order adjusted; CLI tests updated to accept --magic-file.
Evaluator & Safety
src/evaluator/mod.rs, docs/src/evaluator.md, docs/src/introduction.md
decrement_recursion_depth now returns Result<(), LibmagicError> and callers propagate failures; evaluator docs expanded (EvaluationConfig, offset semantics, errors).
Error Surface
src/error.rs, docs/src/architecture.md
ParseError adds UnsupportedFormat { ... } and IoError(#[from]); EvaluationError adds InternalError { ... }; LibmagicError updated to wrap parse/evaluation errors and include Timeout variant.
Tests & Snapshots
tests/..., tests/snapshots/..., tests/directory_loading_tests.rs, tests/json_integration_test.rs
Add comprehensive directory-loading and parser integration tests; update CLI integration tests to resolve magic files; add compatibility guards for binary formats; update JSON tests; add new CLI failure snapshot.
Workflows / Release
.github/workflows/release.yml, .github/workflows/compatibility.yml
Add publish-homebrew-formula release job and gate announce on its result; disable compatibility-tests (if: false); bump action versions and adjust CI orchestration.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant CLI as CLI
    participant Main as Main
    participant Parser as Parser
    participant DB as MagicDatabase
    participant Eval as Evaluator

    User->>CLI: invoke rmagic [--magic-file /path]
    CLI->>Main: main(args)
    Main->>Parser: detect_format(path)
    Parser-->>Main: MagicFileFormat (Text/Directory/Binary)

    alt Text
        Main->>Parser: load_magic_file(path)
        Parser->>Parser: parse_text_magic_file()
        Parser-->>Main: Vec\<MagicRule\>
    else Directory
        Main->>Parser: load_magic_directory(path)
        Parser->>Parser: iterate files (alphabetical), parse each (skip non-fatal parse errors)
        Parser-->>Main: Vec\<MagicRule\>
    else Binary
        Main-->>User: Error (UnsupportedFormat, suggest --use-builtin)
    end

    Main->>DB: MagicDatabase::load_from_file(path)
    DB->>DB: store rules and source_path (Option\<PathBuf\>)
    Main->>Eval: evaluate(file, DB.rules)
    Eval-->>Main: Match results or LibmagicError
    Main-->>User: output results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐇 I hopped through files both text and bin,
I sniffed formats, kept my rules tucked in.
I left a trail — a source_path to find,
Alphabetized, skipped faults gentle-kind.
Hooray — the rabbit logged the magic, heartened and keen.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main changes: parser integration, CI modernization with mise, and Dev Container support. It accurately reflects the primary objectives and is specific enough to convey the changeset's scope.
Description check ✅ Passed The description comprehensively covers the changeset, detailing CI/CD modernization, Dev Container support, and documentation updates. It is well-organized and directly related to the actual changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 17-parser-integration-magic-file-loading-directory-support

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

…ectory-support

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
@unclesp1d3r unclesp1d3r added this to the Phase 1 MVP milestone Jan 23, 2026
@coderabbitai coderabbitai Bot added enhancement New feature or request evaluator Rule evaluation engine and logic testing Test infrastructure and coverage labels Jan 23, 2026
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
@unclesp1d3r unclesp1d3r changed the title feat: parser integration magic file loading directory support feat: parser integration, CI modernization with mise, and Dev Container support Jan 23, 2026
unclesp1d3r and others added 10 commits January 22, 2026 23:56
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Convert `decrement_recursion_depth()` from a panicking function to one
that returns `Result<(), LibmagicError>`. This addresses the critical
issue where a programming error in recursion tracking would crash the
entire application instead of returning a recoverable error.

Changes:
- Add `InternalError` variant to `EvaluationError` for internal logic errors
- Add `internal_error()` constructor method
- Update `decrement_recursion_depth()` to return `Result`
- Update all call sites to use `?` operator or `.unwrap()` in tests
- Convert `#[should_panic]` test to check for error result instead

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Address high-priority issues from PR review:

Documentation fixes:
- Remove non-existent `start_time` field from EvaluationContext docs
- Fix MatchResult value type: `Value` not `Vec<u8>`
- Update security claims in load_magic_file() to be accurate
- Remove outdated "placeholder" warnings from getting-started.md
- Fix test count claims: 650+ tests (was inconsistent 745+/200+)

Error handling improvements:
- Return error when ALL files in directory fail to parse
- Track parse failures and provide detailed error messages
- Add tests for all-files-fail and partial-failure scenarios

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The actions-rust-lang/rustfmt@v1 action uses its own rustfmt binary
which doesn't properly respect the mise-installed toolchain or the
project's rustfmt.toml configuration (edition = "2024").

Replace with a direct `cargo fmt --check` command which uses the
mise-installed rust toolchain consistently.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 24, 2026

Codecov Report

❌ Patch coverage is 92.64706% with 30 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/parser/mod.rs 93.14% 22 Missing ⚠️
src/main.rs 73.33% 4 Missing ⚠️
src/evaluator/mod.rs 91.30% 2 Missing ⚠️
src/error.rs 97.43% 1 Missing ⚠️
src/lib.rs 90.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
Signed-off-by: UncleSp1d3r <unclesp1d3r@evilbitlabs.io>
@unclesp1d3r unclesp1d3r requested a review from Copilot January 24, 2026 05:21
@unclesp1d3r unclesp1d3r merged commit 7cca539 into main Jan 24, 2026
23 checks passed
@unclesp1d3r unclesp1d3r deleted the 17-parser-integration-magic-file-loading-directory-support branch January 24, 2026 05:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the project’s developer/CI workflow (mise + Dev Container), and integrates the parser into the library/CLI so MagicDatabase::load_from_file now loads real rules (with format detection + directory support), alongside updated docs and expanded integration testing.

Changes:

  • Add unified magic file loading (text vs directory vs binary detection) and wire it into MagicDatabase + CLI.
  • Modernize tooling and CI around mise, plus add a Rust Dev Container configuration.
  • Update/expand integration tests, snapshots, and documentation to reflect the new end-to-end flow.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tests/snapshots/cli_integration_tests__canonical_cli_test_failures.snap.new New insta snapshot artifact capturing canonical CLI failures (currently appears to be a .snap.new).
tests/parser_integration_tests.rs New end-to-end integration tests for parser loading + MagicDatabase integration.
tests/json_integration_test.rs Update JSON CLI tests to use byte-based rules that the parser supports.
tests/directory_loading_tests.rs New integration tests for directory (Magdir-style) loading behavior.
tests/compatibility_tests.rs Skip DB loading test when magic DB is binary-only via detect_format.
tests/cli_integration_tests.rs Canonical CLI tests now pass an explicit magic file and attempt to resolve a parseable text magic file.
src/parser/mod.rs Add format detection, directory loader, and unified load_magic_file() API.
src/main.rs Update magic file discovery logic to use detect_format; allow directories in validation.
src/lib.rs Implement MagicDatabase::load_from_file using the parser; add source_path() metadata.
src/evaluator/mod.rs Make recursion-depth underflow an error (not a panic) and update call sites/tests accordingly.
src/error.rs Add ParseError::UnsupportedFormat, ParseError::IoError, and EvaluationError::InternalError.
mise.toml Expand mise-managed toolchain/tool list (Rust components + actionlint/lychee/markdownlint-cli2).
justfile Route dev commands through mise exec and update lint/docs tooling commands.
docs/src/parser.md Update parser docs to reflect complete parsing + format detection.
docs/src/introduction.md Update “project status” section to reflect completed components.
docs/src/getting-started.md Remove “placeholder” notes and align examples with real behavior.
docs/src/evaluator.md Update evaluator documentation to reflect implemented engine + APIs.
docs/src/architecture.md Update architecture docs to reflect completed parser/evaluator components.
dist-workspace.toml Enable shell + Homebrew installers and bump GitHub Actions versions for cargo-dist workflows.
README.md Refresh project status/feature list and usage examples.
AGENTS.md Add explicit guidance to avoid emojis/non-ASCII in docs/code.
.github/workflows/release.yml Bump Actions versions and add Homebrew formula publish job.
.github/workflows/compatibility.yml Disable compatibility job via if: false.
.github/workflows/ci.yml Migrate more steps to mise; update job dependencies and gating.
.github/dependabot.yml Add Dependabot support for Dev Container updates.
.github/commit-instructions.md Simplify/clarify Conventional Commit guidance.
.devcontainer/devcontainer.json Add Dev Container setup for Rust + tooling + VS Code extensions.
.coderabbitai.yaml Toggle walkthrough collapse behavior.

Comment thread src/parser/mod.rs
Comment on lines +781 to +783
"Binary compiled magic files (.mgc) are not supported for parsing.\n\
Use the --use-builtin option to use the built-in magic rules instead,\n\
or provide a text-based magic file or directory.",
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

This error message tells users to use --use-builtin, but the CLI args currently don’t include that flag. Either implement --use-builtin in src/main.rs or adjust the guidance here (and related docs/tests) to avoid pointing to a non-existent option.

Suggested change
"Binary compiled magic files (.mgc) are not supported for parsing.\n\
Use the --use-builtin option to use the built-in magic rules instead,\n\
or provide a text-based magic file or directory.",
"Binary compiled magic files (.mgc) are not supported for parsing. \
Provide a text-based magic file or directory instead.",

Copilot uses AI. Check for mistakes.
Comment thread src/main.rs
Comment on lines +87 to +88
MagicFileFormat::Binary | MagicFileFormat::Directory => continue,
MagicFileFormat::Text => return path,
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

default_magic_file_path() currently skips MagicFileFormat::Directory, but directories are now supported (and validate_magic_file explicitly allows them). Allowing Directory here would make the CLI work on systems that ship a Magdir directory rather than a single text file.

Suggested change
MagicFileFormat::Binary | MagicFileFormat::Directory => continue,
MagicFileFormat::Text => return path,
MagicFileFormat::Binary => continue,
MagicFileFormat::Text | MagicFileFormat::Directory => return path,

Copilot uses AI. Check for mistakes.
Comment thread src/parser/mod.rs
Comment on lines +145 to +149
use std::io::Read;
use std::path::{Path, PathBuf};

/// Represents the format of a magic file or directory
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

src/parser/mod.rs is already very large, and this PR adds substantial new functionality here (format detection + directory loading). Given the project’s documented file-size guideline (AGENTS.md:84-88), consider extracting this into dedicated modules/files to keep mod.rs focused on orchestration.

Copilot generated this review using guidance from repository custom instructions.
Comment thread src/parser/mod.rs
Comment on lines +569 to +596
let entries = fs::read_dir(dir_path).map_err(|e| {
ParseError::invalid_syntax(
0,
format!("Failed to read directory '{}': {}", dir_path.display(), e),
)
})?;

// Collect and sort entries by filename for deterministic ordering
let mut file_paths: Vec<std::path::PathBuf> = Vec::new();
for entry in entries {
let entry = entry.map_err(|e| {
ParseError::invalid_syntax(
0,
format!(
"Failed to read directory entry in '{}': {}",
dir_path.display(),
e
),
)
})?;

let path = entry.path();
let file_type = entry.file_type().map_err(|e| {
ParseError::invalid_syntax(
0,
format!("Failed to read file type for '{}': {}", path.display(), e),
)
})?;
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

load_magic_directory() converts directory access failures into InvalidSyntax (line=0). With the new ParseError::IoError variant and CLI exit-code handling, these should surface as I/O errors (preserving ErrorKind) so they map to LibmagicError::IoError rather than a “magic syntax” error.

Suggested change
let entries = fs::read_dir(dir_path).map_err(|e| {
ParseError::invalid_syntax(
0,
format!("Failed to read directory '{}': {}", dir_path.display(), e),
)
})?;
// Collect and sort entries by filename for deterministic ordering
let mut file_paths: Vec<std::path::PathBuf> = Vec::new();
for entry in entries {
let entry = entry.map_err(|e| {
ParseError::invalid_syntax(
0,
format!(
"Failed to read directory entry in '{}': {}",
dir_path.display(),
e
),
)
})?;
let path = entry.path();
let file_type = entry.file_type().map_err(|e| {
ParseError::invalid_syntax(
0,
format!("Failed to read file type for '{}': {}", path.display(), e),
)
})?;
let entries = fs::read_dir(dir_path).map_err(ParseError::IoError)?;
// Collect and sort entries by filename for deterministic ordering
let mut file_paths: Vec<std::path::PathBuf> = Vec::new();
for entry in entries {
let entry = entry.map_err(ParseError::IoError)?;
let path = entry.path();
let file_type = entry.file_type().map_err(ParseError::IoError)?;

Copilot uses AI. Check for mistakes.
Comment on lines 13 to 16
compatibility-tests:
name: Compatibility Tests
if: false
runs-on: ${{ matrix.os }}
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

Setting if: false disables the entire compatibility job (including on the scheduled run). If this is meant to be temporarily paused, consider removing the schedule trigger or gating behind an input/label so it can still be run when needed.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +44
---
source: tests/cli_integration_tests.rs
assertion_line: 149
expression: normalized_summary
---
Found 81 test failures out of 81 canonical tests:

CVE-2014-1943.testfile
CLI error: CLI failed: Compiling libmagic-rs v0.1.0 (/Volumes/Projects/Projects/libmagic-rs)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.38s
Running `target/debug/rmagic CVE-2014-1943.testfile`
Error: Magic file parse error
Invalid syntax at line 12: Failed to parse rule: Parsing Error: Error { input: "MZ\tMS-DOS executable", code: Digit }
The magic file contains invalid syntax or formatting.
Please check the magic file format or try a different magic file.


HWP2016.hwp.testfile
CLI error: CLI failed: Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/rmagic HWP2016.hwp.testfile`
Error: Magic file parse error
Invalid syntax at line 12: Failed to parse rule: Parsing Error: Error { input: "MZ\tMS-DOS executable", code: Digit }
The magic file contains invalid syntax or formatting.
Please check the magic file format or try a different magic file.


HWP2016.hwpx.zip.testfile
CLI error: CLI failed: Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
Running `target/debug/rmagic HWP2016.hwpx.zip.testfile`
Error: Magic file parse error
Invalid syntax at line 12: Failed to parse rule: Parsing Error: Error { input: "MZ\tMS-DOS executable", code: Digit }
The magic file contains invalid syntax or formatting.
Please check the magic file format or try a different magic file.


HWP97.hwp.testfile
CLI error: CLI failed: Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/rmagic HWP97.hwp.testfile`
Error: Magic file parse error
Invalid syntax at line 12: Failed to parse rule: Parsing Error: Error { input: "MZ\tMS-DOS executable", code: Digit }
The magic file contains invalid syntax or formatting.
Please check the magic file format or try a different magic file.


Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

This file looks like an insta generated “new snapshot” artifact (*.snap.new). These are created when snapshot assertions fail and typically shouldn’t be committed; either delete it or accept the snapshot update so only the canonical *.snap is tracked (e.g., via cargo insta accept).

Suggested change
---
source: tests/cli_integration_tests.rs
assertion_line: 149
expression: normalized_summary
---
Found 81 test failures out of 81 canonical tests:
CVE-2014-1943.testfile
CLI error: CLI failed: Compiling libmagic-rs v0.1.0 (/Volumes/Projects/Projects/libmagic-rs)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.38s
Running `target/debug/rmagic CVE-2014-1943.testfile`
Error: Magic file parse error
Invalid syntax at line 12: Failed to parse rule: Parsing Error: Error { input: "MZ\tMS-DOS executable", code: Digit }
The magic file contains invalid syntax or formatting.
Please check the magic file format or try a different magic file.
HWP2016.hwp.testfile
CLI error: CLI failed: Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/rmagic HWP2016.hwp.testfile`
Error: Magic file parse error
Invalid syntax at line 12: Failed to parse rule: Parsing Error: Error { input: "MZ\tMS-DOS executable", code: Digit }
The magic file contains invalid syntax or formatting.
Please check the magic file format or try a different magic file.
HWP2016.hwpx.zip.testfile
CLI error: CLI failed: Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.07s
Running `target/debug/rmagic HWP2016.hwpx.zip.testfile`
Error: Magic file parse error
Invalid syntax at line 12: Failed to parse rule: Parsing Error: Error { input: "MZ\tMS-DOS executable", code: Digit }
The magic file contains invalid syntax or formatting.
Please check the magic file format or try a different magic file.
HWP97.hwp.testfile
CLI error: CLI failed: Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
Running `target/debug/rmagic HWP97.hwp.testfile`
Error: Magic file parse error
Invalid syntax at line 12: Failed to parse rule: Parsing Error: Error { input: "MZ\tMS-DOS executable", code: Digit }
The magic file contains invalid syntax or formatting.
Please check the magic file format or try a different magic file.
Please check the magic file format or try a different magic file.

Copilot uses AI. Check for mistakes.
Comment thread src/parser/mod.rs
Comment on lines +1536 to +1540
fn test_detect_format_text_file() {
let temp_dir = std::env::temp_dir();
let text_file = temp_dir.join("test_text_magic.txt");
fs::write(&text_file, "# Magic file\n0 string test Test").unwrap();

Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

These tests write to fixed filenames under std::env::temp_dir(). Since Rust tests run in parallel by default, this can cause flaky failures due to cross-test collisions. Prefer tempfile::TempDir / NamedTempFile (unique per test) instead of hard-coded paths.

Copilot uses AI. Check for mistakes.
Comment thread src/parser/mod.rs
Comment on lines +221 to +224
Err(e) => Err(ParseError::invalid_syntax(
0,
format!("Failed to read magic file: {e}"),
)),
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

detect_format() docs say it returns ParseError::IoError when the path can’t be read, but this branch converts non-EOF read failures into InvalidSyntax. Returning an I/O-flavored error (preserving ErrorKind) is important so callers/CLI can distinguish parse errors from file access errors.

Suggested change
Err(e) => Err(ParseError::invalid_syntax(
0,
format!("Failed to read magic file: {e}"),
)),
Err(e) => Err(e.into()),

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/ci.yml
Comment on lines +58 to 62
- uses: dtolnay/rust-toolchain@1.91.0
with:
components: llvm-tools, cargo, rustfmt, clippy
- uses: jdx/mise-action@v3
with:
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

The PR description says workflows were migrated off dtolnay/rust-toolchain in favor of mise, but this workflow still uses dtolnay/rust-toolchain and then runs mise-action as well. Consider using a single toolchain setup path (preferably mise) to avoid drift and redundant installs.

Copilot uses AI. Check for mistakes.
Comment thread src/parser/mod.rs
Comment on lines +617 to +621
// I/O errors are critical
return Err(ParseError::invalid_syntax(
0,
format!("Failed to read file '{}': {}", path.display(), e),
));
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

read_to_string failures are treated as InvalidSyntax, which will make the CLI report this as a magic syntax issue (exit code 4) instead of a file access issue (exit code 3). Consider returning ParseError::IoError (or wrapping an io::Error with path context while preserving its kind).

Suggested change
// I/O errors are critical
return Err(ParseError::invalid_syntax(
0,
format!("Failed to read file '{}': {}", path.display(), e),
));
// I/O errors are critical: preserve the original error kind so the
// CLI can distinguish file access issues from syntax issues.
let io_error = std::io::Error::new(
e.kind(),
format!("Failed to read file '{}': {}", path.display(), e),
);
return Err(ParseError::IoError(io_error));

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request evaluator Rule evaluation engine and logic testing Test infrastructure and coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser Integration: Magic File Loading & Directory Support

2 participants