From cdac6e844cdebef8b207d9e96b867b494800140b Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 30 Sep 2026 16:36:20 +0000 Subject: [PATCH] fix(dev): filter component:breaking-changes output to only breaking change errors --- .../ComponentBreakingChangesCommand.php | 7 ++++- .../ComponentBreakingChangesCommandTest.php | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/dev/src/Command/ComponentBreakingChangesCommand.php b/dev/src/Command/ComponentBreakingChangesCommand.php index ede839fe4ac..a99421c7a28 100644 --- a/dev/src/Command/ComponentBreakingChangesCommand.php +++ b/dev/src/Command/ComponentBreakingChangesCommand.php @@ -274,7 +274,12 @@ private function runRoave(string $workTree): array $proc->setTimeout(600); $proc->run(); - return [0 !== $proc->getExitCode(), $proc->getOutput() . $proc->getErrorOutput()]; + $lines = array_filter( + explode("\n", $proc->getOutput()), + fn(string $line) => str_starts_with($line, '::error') + ); + + return [0 !== $proc->getExitCode(), implode("\n", $lines) ?: trim($proc->getErrorOutput())]; } private function commit(string $cwd, string $msg): void diff --git a/dev/tests/Unit/Command/ComponentBreakingChangesCommandTest.php b/dev/tests/Unit/Command/ComponentBreakingChangesCommandTest.php index 215c3d77dc5..8e7077a9ca8 100644 --- a/dev/tests/Unit/Command/ComponentBreakingChangesCommandTest.php +++ b/dev/tests/Unit/Command/ComponentBreakingChangesCommandTest.php @@ -185,6 +185,37 @@ public function testGaOnlyOptionFiltersOutPre10ComponentsWhenEnabled(): void $this->assertSame(['google/beta'], $checked); } + public function testFiltersRoaveOutputToOnlyBreakingChangeErrors(): void + { + $this->fs->dumpFile($this->rootDir . '/Alpha/src/Foo.php', 'commitAll('break Alpha'); + + $binDir = $this->rootDir . '/bin'; + $this->fs->mkdir($binDir); + $fakeRoave = $binDir . '/roave-backward-compatibility-check'; + $this->fs->dumpFile($fakeRoave, <<<'SH' +#!/usr/bin/env bash +echo "No security vulnerability advisories found." +echo "::error file=/src/Foo.php,line=1,col=1::Method Foo#x() changed" +echo "#StandWithUkraine" >&2 +echo "Installing dependencies from lock file" >&2 +exit 3 +SH); + $this->fs->chmod($fakeRoave, 0755); + + $origPath = getenv('PATH'); + putenv('PATH=' . $binDir . PATH_SEPARATOR . $origPath); + try { + $tester = new CommandTester(new ComponentBreakingChangesCommand($this->rootDir)); + $code = $tester->execute(['--base-ref' => 'baseline'], ['capture_stderr_separately' => true]); + } finally { + putenv('PATH=' . $origPath); + } + + $this->assertSame(Command::FAILURE, $code); + $this->assertSame("::error file=/src/Foo.php,line=1,col=1::Method Foo#x() changed\n", $tester->getDisplay()); + } + public function testRejectsLowercaseComponentName(): void { $cmd = new ComponentBreakingChangesCommand($this->rootDir);