toBe("fatal: not a git repository\nerror: build failed\n"); }); it('keeps the strict checking failure lines after the warning', function () { $stderr = capturedHostKeyChangedWarning() ."Host key for coolify-abc has changed and you have requested strict checking.\r\n" ."Host key verification failed.\r\n"; $stripped = SshMultiplexingHelper::stripHostKeyChangedWarning($stderr); expect($stripped)->toBe("Host key for coolify-abc has changed and you have requested strict checking.\r\nHost key verification failed.\r\n") ->and(SshMultiplexingHelper::isHostKeyMismatch($stderr))->toBeTrue(); }); it('keeps a changed host key warning that a program on the server prints later', function () { $stderr = "Cloning into 'app'...\n".capturedHostKeyChangedWarning(); expect(SshMultiplexingHelper::stripHostKeyChangedWarning($stderr))->toBe($stderr); }); it('removes the warning from stderr that arrives in chunks of any size', function (int $chunkSize) { $stderr = capturedHostKeyChangedWarning()."warning: remote line\n"; $held = ''; $passed = ''; foreach (str_split($stderr, $chunkSize) as $chunk) { $passed .= SshMultiplexingHelper::filterHostKeyChangedWarning($held, $chunk); } $passed .= SshMultiplexingHelper::filterHostKeyChangedWarning($held, '', final: true); expect($passed)->toBe("warning: remote line\n") ->and($held)->toBeNull(); })->with([1, 7, 64, 100000]); it('passes other stderr on at once', function () { $held = ''; expect(SshMultiplexingHelper::filterHostKeyChangedWarning($held, "error: build failed\n"))->toBe("error: build failed\n") ->and(SshMultiplexingHelper::filterHostKeyChangedWarning($held, "@ not a warning\n"))->toBe("@ not a warning\n"); });