Skip to content

test: fix flaky CommandsTest override-discovery tests under random order#10141

Merged
paulbalandan merged 1 commit intocodeigniter4:4.8from
paulbalandan:fix-syscall-issue-commands-test
Apr 26, 2026
Merged

test: fix flaky CommandsTest override-discovery tests under random order#10141
paulbalandan merged 1 commit intocodeigniter4:4.8from
paulbalandan:fix-syscall-issue-commands-test

Conversation

@paulbalandan
Copy link
Copy Markdown
Member

Description

CommandsTest::testDiscoveredLegacyCommandsCanBeOverridden (and its modern counterpart) fail intermittently under --order-by=random on GHA. Reproducer: vendor/bin/phpunit tests/system/CLI --order-by=random --random-order-seed=1777101167, which produces:

1) CodeIgniter\CLI\CommandsTest::testDiscoveredLegacyCommandsCanBeOverridden
Failed asserting that '
CodeIgniter Version: 4.8.0-dev
' [ASCII](length: 32) contains "This is App\Commands\AppInfo" [ASCII](length: 28).

/home/runner/work/CodeIgniter4/CodeIgniter4/tests/system/CLI/CommandsTest.php:451

The override tests copy a fixture into app/Commands/ and expect discovery to pick it up. app/Commands/ is not tracked in git, so on a fresh checkout it does not exist until the test creates it.

PHP keys its stat cache by exact path string and only invalidates the exact path argument passed to mkdir/copy/unlink. The test's copyCommand calls mkdir(APPPATH . 'Commands') (no trailing slash), but FileLocator::listFiles() later checks is_dir(APPPATH . 'Commands/') (with trailing slash). When an earlier CLI test in the random order primes the cache with the trailing-slash form while the directory does not yet exist, the stat-cache entry survives the mkdir. Discovery then skips the App namespace and the original fixture command wins the app:info slot, so the override assertion fails.

Calling clearstatcache(true) after the filesystem mutations clears both the stat cache and the realpath cache, so subsequent discovery sees the fresh state. Scoped to the test fixture; production behavior matches PHP's documented cache rules and is not changed here.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@github-actions github-actions Bot added testing Pull requests that changes tests only 4.8 PRs that target the `4.8` branch. labels Apr 25, 2026
Copy link
Copy Markdown
Contributor

@patel-vansh patel-vansh left a comment

Choose a reason for hiding this comment

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

LGTM

@paulbalandan paulbalandan merged commit eec6f58 into codeigniter4:4.8 Apr 26, 2026
58 of 62 checks passed
@paulbalandan paulbalandan deleted the fix-syscall-issue-commands-test branch April 26, 2026 04:56
@paulbalandan
Copy link
Copy Markdown
Member Author

Adding this test fix in addition to #10142 for defense in depth.

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

Labels

4.8 PRs that target the `4.8` branch. testing Pull requests that changes tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants