[Bug]: [mutate] Windows: the 5 s minimum per-mutant timeout is shorter than a child boot under Xdebug, so untested mutants are scored as killed

オープン
#1,968 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 5 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
php
領域
testing

調査の方向性

Start in MutationTest::calculateTimeout() and MutationTest::start(), where the per-mutant timeout is computed and the child's arguments and XDEBUG_MODE are set, then in hasFinished(), which maps ProcessTimedOutException to Timeout. The mutation code lives in pestphp/pest-plugin-mutate, which the issue says is where to work. Done means a mutant that no test covers is reported as untested rather than killed, with the fix chosen by the maintainers from the options listed.

索引モデルが issue の本文から書いたものです。

説明

bug
What Happened

On Windows, pest --mutate scores some mutants as killed when no test can kill them, because their child process times out before the covering test has even run.

MutationTest::calculateTimeout() gives each mutant run the initial suite duration plus max(5, 20%):

return (int) ($initialTestSuiteDuration + max(5, $initialTestSuiteDuration * 0.2));

When the targeted test set is small (a single test file, as when mutating one class), the initial suite takes ~2 s, so each child gets ~7 s. On Windows, booting a child Pest process (Laravel app) takes 4 to 7 s on its own, partly because children inherit XDEBUG_MODE=coverage and the --coverage-php=... argument (see the TODO: filter arguments to remove unnecessary stuff (Teamcity, Coverage, etc.) in MutationTest::start()). Some legitimate runs exceed the budget, hasFinished() maps the ProcessTimedOutException to Timeout, and the score counts Timeout as killed.

Expected: a mutant that no test kills is reported as untested, regardless of process start-up time.

How to Reproduce
  1. On Windows, with Xdebug, write a test that executes a class but asserts nothing about it:

    it('runs the code without checking anything', function () {
        (new SomeValueObject(120.5, 80.0))->format();
    
        expect(true)->toBeTrue();
    });
    
  2. XDEBUG_MODE=coverage php vendor/bin/pest tests/Unit/SanityTest.php --mutate --class='App\Domain\SomeValueObject' --covered-only --no-cache

Result: Mutations: 15 untested, 6 timeout, 0 tested, score 28.57 %. No test can kill any of these 21 mutants, so the expected score is 0 %.

With the minimum raised from 5 to 30 s on Windows (max(PHP_OS_FAMILY === 'Windows' ? 30 : 5, ...)), the same run reports 21 untested, 0 tested, score 0.00 %.

This was measured with the child-launch fix from #1916 applied (otherwise every mutant is scored as killed and this bug is invisible).

Sample Repository

None (private project). The reproduction above only needs any Laravel app with Pest and one class.

Pest Version

3.8.6 (pestphp/pest-plugin-mutate v3.0.5, symfony/process v7.4.8)

PHP Version

8.4.15 ZTS (x64), Xdebug 3.5.3

Operation System

Windows

Notes

Filed here because issues are disabled on pestphp/pest-plugin-mutate.

Related: #1843 (timed-out mutants scored as killed, different root cause: a deadlock) and #1916 (child process fails to launch on Windows, also scored as killed). pestphp/pest-plugin-mutate#45 would make all three visible instead of silent.

Possible fixes, from least to most invasive:

  • do not pass coverage arguments/env to the per-mutant children (the existing TODO), which removes most of the start-up cost;
  • a higher minimum timeout, or a --mutate-timeout option;
  • report Timeout separately from kills in the score.
主要言語
PHP
スター
11.8k
フォーク
559
平均マージ
5日 23時間
マージ済み PR(30日)
24

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pestphp/pest のほかの issue

pestphp/pest の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。