Skip to content

The PHP test filter deletes the -expected side of an assertion diff while keeping the --- Expected header, and npm run-script <s> is rewritten to npm run run-script <s> #3411

Open

Description

@HetCreep

Two independent defects, both reproduced against the shipped binary. The first is the more serious: a failing test's diff is shown with the wrong value attributed to the wrong side.

Provenance: AI-assisted source audit, human-directed, at v0.44.2 (700bdde). Both reproduced by running rtk 0.44.2 with a stand-in on PATH; outputs verbatim.

1. The Expected value is deleted from assertion diffs

What the test tool printed:

  FAILED  Tests\ExampleTest
  Failed asserting that two values are equal.
  --- Expected
  +++ Actual
  @@ @@
  -1.5
  +2.5
Tests:  1 failed

What rtk pest passes to the caller:

  FAILED  Tests\ExampleTest
  Failed asserting that two values are equal.
  --- Expected
  +++ Actual
  @@ @@
  +2.5
Tests:  1 failed

-1.5 is gone. The --- Expected / +++ Actual headers are still there, so the surviving +2.5 reads as though it were the expected value. The reader — usually an AI agent — is not told a line was removed.

Cause: src/cmds/php/test_output.rs:12, is_progress_line, classifies a line as PHPUnit progress output if every character is in . F E S I R W - 0-9 space / % ( ). A numeric diff line like -1.5 is entirely inside that set, so it is discarded as progress noise. + is not in the set, so the +actual line survives — which is why the loss is one-sided and silent rather than symmetric and obvious.

Reached from pest_cmd.rs:28, paratest_cmd.rs:28 and artisan_cmd.rs:26.

Any numeric-only expected value is affected: -1.5, -42, -0, -3.14. Non-numeric expected values (strings, arrays) contain characters outside the set and survive.

2. npm run-script is rewritten to npm run run-script

$ rtk rewrite npm run-script build
rtk npm run-script build

$ rtk -v npm run-script build
Running: npm run run-script build

run-script is npm's own long-form alias for run, but it is absent from the 66-entry NPM_SUBCOMMANDS list (src/cmds/js/npm_cmd.rs:82), so rtk classes it as a script name and prepends run at :90. npm then reports Missing script: "run-script".

Suggested fixes (untested — no programmer has reviewed these)

  1. Diff lines: require a progress line to be only the status characters (.FESIRW) plus whitespace and the trailing N / N (NN%) counter, rather than accepting -, /, (, ) and digits in any combination. Anchoring on the counter format would be tighter still. Alternatively, stop applying is_progress_line once a --- Expected header has been seen, since everything after it is diff content.
  2. npm alias: add run-script to NPM_SUBCOMMANDS. Worth checking the same list for npm's other aliases (i/install, un/uninstall, ln/link, t/test, rb/rebuild, ls/list) — I only verified run-script.

Note on the first one

The general "a filter deletes output without a marker" class is already tracked in #2317. I am filing this separately because the failure here is not just omission: the retained header makes the surviving line look like the value that was removed, so the reader is actively misled about which side of the comparison failed.

Activity

  1. pszymkowiak commented on Aug 4, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 93%

    Summary

    PHP test filter silently drops numeric '-expected' diff lines (misattributing values) and npm's 'run-script' alias is missing from NPM_SUBCOMMANDS causing a broken rewrite; both are localized, well-reproduced fixes.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/cmds/php/test_output.rs
    • src/cmds/js/npm_cmd.rs
    • src/cmds/php/pest_cmd.rs
    • src/cmds/php/paratest_cmd.rs
    • src/cmds/php/artisan_cmd.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  2. HetCreep commented on Aug 30, 2026

    @HetCreep
    Author

    Correcting my own report. Re-verified at develop @ 0de9610.

    Provenance: AI-assisted source audit, human-directed, at develop @ 0de9610.

    My mechanism description was incomplete

    I described the misattribution as applying to negative and zero values generally, and gave -42 and -0 as examples. That is too broad: the branch also requires a has_dot conjunct, so it fires on dot-bearing values only. The narrower claim is the correct one, and the examples in my report should be read as -42.0 / -0.0 rather than the integer forms.

    To be clear about what did not happen: nothing was fixed. git diff 700bdde HEAD -- src/cmds/php/test_output.rs is empty — that file has not changed since the baseline my report was written against. The error is mine, not a stale description of repaired code.

    Two things that make the report broader than I filed it

    • A fourth reach path: pipe_cmd.rs:32-34 — rtk pipe --filter pest|paratest|php-test reaches the same formatter.
    • rules.rs:90 recommends rewriting npm run-script … to rtk npm run-script …, so rtk's own discover engine steers users into the invocation that npm_cmd.rs then mishandles. rum, urn and x are also missing from NPM_SUBCOMMANDS.

    Happy to split the npm half into its own issue if you would rather track them separately.

  3. KuSh commented on Sep 13, 2026

    @KuSh
    Collaborator

    Defect 2 (npm run-script <s> → npm run run-script <s>) is fixed by #3087, which adds run-script to NPM_SUBCOMMANDS along with 14 other names. Verified against that PR's head (56519c49), npm 12.0.2, LC_ALL=C, in a project declaring a build script:

    $ rtk npm run-script build      # base f9d8c775
    npm error Missing script: "run-script"
    
    $ rtk npm run-script build      # head 56519c49
    > echo BUILD_SCRIPT_RAN
    BUILD_SCRIPT_RAN
    

    The alias sweep you asked for in that same section is not covered by #3087 and is tracked separately in #4011, together with two other directions the list has drifted (bin is allowlisted but was removed from npm in v9; trust and undeprecate are real npm 11/12 commands and are missing).

    Defect 1, the PHPUnit -expected diff line eaten by is_progress_line, is untouched and remains this issue's subject.

  4. HetCreep commented on Sep 16, 2026

    @HetCreep
    Author

    Re-checked this at 5e0f92c, 468 commits past the 0de9610 checkpoint used for the last pass on this issue (range confirmed: git merge-base --is-ancestor 0de9610 5e0f92c succeeds, git rev-list --count 0de9610..5e0f92c = 468). This was verified by reading the code at this commit — I did not build or run the rtk binary, or execute npm, for this pass.

    PHP diff filter — still fully open. git log --oneline 0de9610..5e0f92c -- src/cmds/php/test_output.rs returns zero commits; the file is unchanged. Current is_progress_line (src/cmds/php/test_output.rs:5-21, called at :42-44):

    fn is_progress_line(line: &str) -> bool {
        let trimmed = line.trim();
        if trimmed.is_empty() {
            return false;
        }
        let has_dot = trimmed.contains('.');
        let progress_charset = trimmed.chars().all(|c| {
            matches!(c, '.' | 'F' | 'E' | 'W' | 'R' | 'S' | 'I' | 'D' | 'N' | 'O' | 'K' | '0'..='9' | ' ' | '/' | '%' | '(' | ')' | '-')
        });
        has_dot && progress_charset
    }

    I re-traced the whole repro, not just the disputed pair: -1.5 (dot present, every character in the allow-set) is still dropped; +2.5 survives only because + isn't in the set; --- Expected, +++ Actual, @@ @@, and the FAILED/Tests: summary lines all survive because they contain no . at all; Failed asserting that two values are equal. survives because, although it has a ., it also has lowercase letters outside the allow-set. Reconstructing the block from this logic reproduces the original corrupted output byte-for-byte. All three call sites are still live: pest_cmd.rs:3,28,40, paratest_cmd.rs:3,28,45,63,98, artisan_cmd.rs:3,26 — artisan_cmd.rs's only in-range commit (ad63139) is a rustfmt-only reformat, nothing logical changed. Please don't close this half.

    npm run-script doubling — the cited example is fixed, the underlying gap isn't. 56519c4 ("fix(npm): recognize extended subcommands") is genuinely in-range (git merge-base --is-ancestor 56519c4 0de9610 is false) and adds 15 subcommand strings to NPM_SUBCOMMANDS in one block, "run-script" among them — a generic batch add whose commit message doesn't reference this issue, so it reads as a coincidental sweep rather than a targeted fix. At npm_cmd.rs:86 (array spans :10-90), "run-script" is now recognized; the routing at :96-99 and the inject-or-not branch at :101-108 mean first_arg == "run-script" sets is_npm_subcommand = true and skips the run injection. rtk npm run-script build now forwards as npm run-script build, unchanged — confirmed as the only dispatch path via src/main.rs:2625. That part is genuinely fixed, thank you.

    What isn't fixed: npm itself ships run-script as just one of three built-in aliases for run. Its own cmd-list.js — checked against the locally installed npm 11.17.0, C:\Program Files\nodejs\node_modules\npm\lib\utils\cmd-list.js:113,140,142 — defines 'run-script': 'run', rum: 'run', and urn: 'run' as equivalent. NPM_SUBCOMMANDS only picked up "run-script"; grepping the full 80-entry array for "rum"/"urn" finds neither. Since the is_npm_subcommand check is exact-string with no alias resolution, rtk npm rum build and rtk npm urn build still fall to the else-branch at :104-108, still get run prepended, and still produce npm run rum build / npm run urn build — the identical corruption this issue reported, just via npm's other two spellings of the same command. Would suggest describing this half as "fixed for the run-script spelling, still open for the rum/urn aliases" rather than closed — please leave it open too.

    Both halves are correctness/conformance bugs: no attacker-controlled input on either path, just wrong output handed back to whoever (or whatever automation) invoked the command.

  5. HetCreep commented on Oct 14, 2026

    @HetCreep
    Author

    Re-checked on v1.0.0 (stable, 2026-10-13): the official release binary plus the v1.0.0 source. Provenance: AI-assisted check, human-directed. "ran" = executed against rtk 1.0.0 with a control; "read" = verified from source only.

    Fixed (ran/read): defect 2. run-script is now in NPM_SUBCOMMANDS (src/cmds/js/npm_cmd.rs:90), so rtk npm run-script build reaches npm as run-script build and no longer as run run-script.

    Narrowed, still live (ran, with a pest stand-in and the same lines unfiltered as control): defect 1 now needs a decimal: src/cmds/php/test_output.rs requires has_dot for the progress-line check, so -42 / -0 are kept, but a dotted expected value such as -1.5 under --- Expected is still deleted while +2.5 and the --- Expected header are kept, with no marker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions