Skip to content

feat(doctor): Perl preview section — producer/markers/roots/frameworks/runners/next-cmd (Campaign 31 item 5) - #1457

Merged
EffortlessSteven merged 1 commit into
mainfrom
perl-doctor-upgrade
Jul 2, 2026
Merged

EffortlessSteven merged 1 commit into
mainfrom
perl-doctor-upgrade

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

What

Upgrades ripr doctor to tell a maintainer exactly why Perl analysis is or is not available and how to invoke it. Adds a dedicated "Perl preview:" section (replacing the shallow one-line fold) reporting every check the objective (attachment §7) requires.

Changes (7 files, +397/−18)

cli/commands.rs — new report_perl_preview(root) helper

Line Reports
project: real recursive .pm/.pl/.t counts + CPAN marker detection (Makefile.PL/Build.PL/cpanfile). Fixes count_files which returned only 0/1 via shallow_has_extension.
adapter: cfg!(feature = \"lang-perl\") compiled/NOT compiled
producer: [perl].producer configured name (or "not configured")
perllsp: found at (version ) | NOT found. Probes perllsp + perl-lsp, honors [perl].executable
schema: ripr-perl-facts-v1 expected
test roots: t/ and/or t2/ detected
frameworks: Test2::V1/V0/Suite, Test::More, Test::Exception, Test::Fatal (added V1 + Suite)
runners: prove/yath/carton/dzil (extended from prove-only)
next: exact next command, branches on managed-mode + producer presence

Schema single-sourcing (item 5)

The ripr-perl-facts-v1 const was duplicated as two private declarations (perl/mod.rs + app/check.rs). Moved the canonical declaration to crate::app::PERL_FACT_PACKET_SCHEMA (pub(crate), always-compiled) and updated all references — one source of truth across both feature builds.

Tests (2 new cli_smoke, all green)

doctor_reports_perl_preview_section_when_perl_markers_present — builds a Makefile.PL + lib/.pm + t/.t workspace, asserts the full section renders (project/adapter/producer/perllsp/schema/test roots/frameworks/runners/next + Test::More + t/ detected + real counts).
doctor_omits_perl_preview_when_no_perl_markers — Rust-only workspace must not emit the section.

Gates (all green)

default + lang-perl lib + lang-perl integration; goldens check (zero drift), check-static-language, check-no-panic-family, check-process-policy (commands.rs Command::new allowlist bumped 4→6: producer version probe + which/where path resolution), check-local-context, check-architecture, check-public-api, check-output-contracts, check-fixture-contracts, check-evidence-promotion-honesty, check-spec-format, check-traceability, check-goals, check-doc-index, fmt, clippy.

Scope / non-goals

One semantic slice (doctor Perl preview + schema single-sourcing). No change to perl_preview_card, GapRecord, public projection (item 6), or the producer invocation itself (item 4).

…s/runners/next-cmd (Campaign 31 item 5)

Upgrades `ripr doctor` to tell a maintainer exactly why Perl analysis is or is
not available and how to invoke it. Adds a dedicated "Perl preview:" section
(replacing the shallow one-line fold) that reports every check the objective
(attachment §7) requires:

- project: real recursive .pm/.pl/.t counts + CPAN marker detection
  (Makefile.PL/Build.PL/cpanfile). Fixes count_files, which previously returned
  only 0/1 via shallow_has_extension, not a real count.
- adapter: cfg!(feature = "lang-perl") compiled/NOT compiled.
- producer: [perl].producer configured name (or "not configured").
- perllsp: found at <path> (version <v>) | NOT found on PATH. Probes both
  canonical names (perllsp/perl-lsp), honors [perl].executable.
- schema: ripr-perl-facts-v1 expected (the schema this build consumes).
- test roots: t/ and/or t2/ detected.
- frameworks: Test2::V1/V0/Suite, Test::More, Test::Exception, Test::Fatal
  (extended from the prior V0/More/Exception/Fatal-only set; added V1 + Suite).
- runners: prove/yath/carton/dzil availability (extended from prove-only).
- next: exact next command, branching on managed-mode config + producer presence
  (managed+present -> ripr check --languages perl --base ... --head HEAD;
   managed+absent -> install perllsp; else explicit --perl-facts).

Schema single-sourcing (Campaign 31 item 5): the ripr-perl-facts-v1 const was
duplicated as two private declarations (perl/mod.rs + app/check.rs). Moved the
canonical declaration to crate::app::PERL_FACT_PACKET_SCHEMA (pub(crate),
always-compiled) and updated all references. Now one source of truth across both
feature builds.

Tests: doctor_reports_perl_preview_section_when_perl_markers_present (asserts
the full section renders), doctor_omits_perl_preview_when_no_perl_markers
(Rust-only must not emit the section). Both in cli_smoke.rs.

Gates: default + lang-perl lib + lang-perl integration green; goldens check
(zero drift), check-static-language, check-no-panic-family, check-process-policy
(commands.rs Command::new allowlist bumped 4->6: producer version probe +
which/where path resolution), check-local-context, check-architecture,
check-public-api, check-output-contracts, check-fixture-contracts,
check-evidence-promotion-honesty, check-spec-format, check-traceability,
check-goals, check-doc-index, fmt, clippy all green.

Scope: one semantic slice (doctor Perl preview + schema single-sourcing). No
change to perl_preview_card, GapRecord, public projection (item 6), or the
producer invocation itself (item 4).
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EffortlessSteven, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e784ec51-22ee-4ffb-adcb-5f0facfe786c

📥 Commits

Reviewing files that changed from the base of the PR and between be41e7c and 5493d8f.

📒 Files selected for processing (7)
  • crates/ripr/src/analysis/language/perl/mod.rs
  • crates/ripr/src/analysis/language/perl/tests.rs
  • crates/ripr/src/app.rs
  • crates/ripr/src/app/check.rs
  • crates/ripr/src/cli/commands.rs
  • crates/ripr/tests/cli_smoke.rs
  • policy/process_allowlist.txt
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perl-doctor-upgrade

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes the Perl fact packet schema version in crates/ripr/src/app.rs and introduces a rich Perl preview section to the doctor command, which recursively counts Perl files, detects test frameworks, and checks for local tooling. The review feedback highlights several critical improvement opportunities regarding the new directory traversal logic: using entry.file_type() to avoid expensive stat calls and prevent infinite recursion from circular symlinks, combining multiple file-counting traversals into a single pass to reduce disk I/O, and making the test framework detection recursive and memory-efficient.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +4243 to +4262
fn count_recursive(dir: &Path, ext: &str) -> usize {
let Ok(entries) = std::fs::read_dir(dir) else {
return 0;
};
let mut n = 0;
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
// Skip hidden + build/dependency dirs that inflate counts.
let name = path.file_name().and_then(|s| s.to_str()).unwrap_or("");
if name.starts_with('.') || matches!(name, "target" | "node_modules" | "blib") {
continue;
}
n += count_recursive(&path, ext);
} else if path.extension().and_then(|e| e.to_str()) == Some(ext) {
n += 1;
}
}
n
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using path.is_dir() recursively follows symbolic links. If the workspace contains a circular symlink loop, this will result in infinite recursion and a stack overflow (panic). Additionally, path.is_dir() performs an expensive stat system call for every entry.

Using entry.file_type() is both safer (it does not follow symlinks, preventing infinite recursion) and more efficient (it avoids the redundant stat system call on Unix systems where the file type is already populated by read_dir).

    fn count_recursive(dir: &Path, ext: &str) -> usize {
        let Ok(entries) = std::fs::read_dir(dir) else {
            return 0;
        };
        let mut n = 0;
        for entry in entries.flatten() {
            let Ok(ft) = entry.file_type() else {
                continue;
            };
            if ft.is_dir() {
                let path = entry.path();
                // Skip hidden + build/dependency dirs that inflate counts.
                let name = path.file_name().and_then(|s| s.to_str()).unwrap_or("");
                if name.starts_with('.') || matches!(name, "target" | "node_modules" | "blib") {
                    continue;
                }
                n += count_recursive(&path, ext);
            } else {
                let path = entry.path();
                if path.extension().and_then(|e| e.to_str()) == Some(ext) {
                    n += 1;
                }
            }
        }
        n
    }

Comment on lines +4482 to +4523
fn detect_perl_frameworks(root: &Path) -> String {
let mut found: Vec<&str> = Vec::new();
let mut contents: Vec<String> = Vec::new();
for dir in ["t", "t2"] {
let test_dir = root.join(dir);
let Ok(entries) = std::fs::read_dir(&test_dir) else {
continue;
};
for entry in entries.flatten() {
let path = entry.path();
if path.extension().is_some_and(|e| e == "t")
&& let Ok(content) = std::fs::read_to_string(&path)
{
contents.push(content);
}
}
}
let blob = contents.join("\n");
if blob.contains("use Test2::V1") || blob.contains("use Test2::Bundle::More") {
found.push("Test2::V1");
}
if blob.contains("use Test2::V0") || blob.contains("use Test2::Tools::Basic") {
found.push("Test2::V0");
}
if blob.contains("use Test2::Suite") {
found.push("Test2::Suite");
}
if blob.contains("use Test::More") {
found.push("Test::More");
}
if blob.contains("use Test::Exception") {
found.push("Test::Exception");
}
if blob.contains("use Test::Fatal") {
found.push("Test::Fatal");
}
if found.is_empty() {
"none detected".to_string()
} else {
found.join(", ")
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The current implementation of detect_perl_frameworks has three main issues:

  1. Shallow Scan Limitation: It only reads top-level files in t/ and t2/, completely missing nested .t files (which are extremely common in Perl projects).
  2. Memory/CPU Inefficiency: It reads all .t files entirely into memory at once, joins them into a single giant string, and performs multiple substring searches. This can cause high memory usage and unnecessary CPU overhead.
  3. Symlink Safety: It should use entry.file_type() to avoid symlink loops during recursive traversal.

We can resolve all three issues by implementing a recursive, memory-efficient, and symlink-safe scanner that short-circuits once all frameworks are found.

fn detect_perl_frameworks(root: &Path) -> String {
    let mut has_v1 = false;
    let mut has_v0 = false;
    let mut has_suite = false;
    let mut has_more = false;
    let mut has_exception = false;
    let mut has_fatal = false;

    fn scan_dir(
        dir: &Path,
        has_v1: &mut bool,
        has_v0: &mut bool,
        has_suite: &mut bool,
        has_more: &mut bool,
        has_exception: &mut bool,
        has_fatal: &mut bool,
    ) {
        let Ok(entries) = std::fs::read_dir(dir) else {
            return;
        };
        for entry in entries.flatten() {
            if *has_v1 && *has_v0 && *has_suite && *has_more && *has_exception && *has_fatal {
                return;
            }
            let Ok(ft) = entry.file_type() else {
                continue;
            };
            let path = entry.path();
            if ft.is_dir() {
                let name = path.file_name().and_then(|s| s.to_str()).unwrap_or("");
                if !name.starts_with('.') {
                    scan_dir(&path, has_v1, has_v0, has_suite, has_more, has_exception, has_fatal);
                }
            } else if path.extension().is_some_and(|e| e == "t") {
                if let Ok(content) = std::fs::read_to_string(&path) {
                    if !*has_v1 && (content.contains("use Test2::V1") || content.contains("use Test2::Bundle::More")) {
                        *has_v1 = true;
                    }
                    if !*has_v0 && (content.contains("use Test2::V0") || content.contains("use Test2::Tools::Basic")) {
                        *has_v0 = true;
                    }
                    if !*has_suite && content.contains("use Test2::Suite") {
                        *has_suite = true;
                    }
                    if !*has_more && content.contains("use Test::More") {
                        *has_more = true;
                    }
                    if !*has_exception && content.contains("use Test::Exception") {
                        *has_exception = true;
                    }
                    if !*has_fatal && content.contains("use Test::Fatal") {
                        *has_fatal = true;
                    }
                }
            }
        }
    }

    for dir in ["t", "t2"] {
        scan_dir(
            &root.join(dir),
            &mut has_v1,
            &mut has_v0,
            &mut has_suite,
            &mut has_more,
            &mut has_exception,
            &mut has_fatal,
        );
    }

    let mut found = Vec::new();
    if has_v1 { found.push("Test2::V1"); }
    if has_v0 { found.push("Test2::V0"); }
    if has_suite { found.push("Test2::Suite"); }
    if has_more { found.push("Test::More"); }
    if has_exception { found.push("Test::Exception"); }
    if has_fatal { found.push("Test::Fatal"); }

    if found.is_empty() {
        "none detected".to_string()
    } else {
        found.join(", ")
    }
}

Comment on lines +4326 to +4328
let pm_count = count_files(root, "pm");
let pl_count = count_files(root, "pl");
let t_count = count_files(root, "t");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Calling count_files three times results in three separate, full recursive traversals of the workspace directory tree. For large workspaces, this introduces significant disk I/O and CPU overhead.

We can optimize this by performing a single recursive traversal that counts .pm, .pl, and .t files simultaneously.

    let (pm_count, pl_count, t_count) = {
        fn count_recursive(dir: &Path, pm: &mut usize, pl: &mut usize, t: &mut usize) {
            let Ok(entries) = std::fs::read_dir(dir) else {
                return;
            };
            for entry in entries.flatten() {
                let Ok(ft) = entry.file_type() else {
                    continue;
                };
                if ft.is_dir() {
                    let path = entry.path();
                    let name = path.file_name().and_then(|s| s.to_str()).unwrap_or("");
                    if name.starts_with('.') || matches!(name, "target" | "node_modules" | "blib") {
                        continue;
                    }
                    count_recursive(&path, pm, pl, t);
                } else {
                    let path = entry.path();
                    if let Some(ext) = path.extension().and_then(|e| e.to_str()) {
                        match ext {
                            "pm" => *pm += 1,
                            "pl" => *pl += 1,
                            "t" => *t += 1,
                            _ => {}
                        }
                    }
                }
            }
        }
        let mut pm = 0;
        let mut pl = 0;
        let mut t = 0;
        count_recursive(root, &mut pm, &mut pl, &mut t);
        (pm, pl, t)
    };

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5493d8f5e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +4530 to +4533
"ripr check --languages perl --base origin/main --head HEAD".to_string()
} else if managed {
// Managed mode configured but producer missing.
"install perllsp on PATH (or set [perl].executable), then: ripr check --languages perl"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Emit only runnable check commands

When [perl].producer = "perllsp" is configured, these next: branches print ripr check invocations with --languages (and the found-producer branch also --head), but the check parser/help in this file only accepts --root, --base, --diff, --worktree, --mode, format/gap/perl-facts flags before returning unknown check argument. A maintainer following the advertised exact command therefore fails before exercising the Perl producer; emit a supported config-driven command or add and test the advertised flags.

Useful? React with 👍 / 👎.

.and_then(|c| c.perl().executable().map(|p| p.display().to_string()));
let candidates: Vec<String> = match explicit {
Some(path) => vec![path],
None => vec!["perllsp".to_string(), "perl-lsp".to_string()],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Align producer detection with the managed spawn path

When no [perl].executable override is configured and only perl-lsp is on PATH, this fallback reports a producer as found, so the managed-mode next: command is presented as ready. The actual managed invocation in app/check.rs defaults to spawning perllsp, not this fallback name, so the recommended path still fails unless the executable override is set or the app layer also supports the fallback; keep doctor detection aligned with the binary ripr check will spawn, or tell users to configure [perl].executable.

Useful? React with 👍 / 👎.

Comment on lines +4528 to +4530
if managed && found_bin.is_some() {
// Managed mode + producer present: ripr invokes perllsp itself.
"ripr check --languages perl --base origin/main --head HEAD".to_string()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Gate managed next command on the compiled adapter

In a default build without the lang-perl feature, a repo with [perl].producer = "perllsp" and a producer binary on PATH still reaches this branch and prints a Perl ripr check next command even though the preceding adapter line says the adapter is not compiled. That command can run the producer but the pipeline will report Perl unavailable, so the doctor section does not fail closed on the real next step; include adapter availability in this branch and recommend rebuilding with --features lang-perl before managed analysis.

Useful? React with 👍 / 👎.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.92818% with 49 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ripr/src/cli/commands.rs 71.67% 49 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

1 participant