Skip to content

Commit 58687f1

Browse files
committed
fix: prevent waitForKey from blocking in non-interactive mode
Add non-interactive mode check to waitForKey() method to prevent infinite loops when readKey() returns null in test/CI environments. This fixes timeouts and blocking input issues that were occurring in tests. Note: PHPUnit version temporarily downgraded to 11.5.
1 parent a3708e7 commit 58687f1

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"ext-pdo": "*",
128128
"psr/log": "^3.0",
129129
"psr/simple-cache": "^3.0",
130+
130131
"psr/event-dispatcher": "^1.0"
131132
},
132133
"suggest": {
@@ -145,7 +146,7 @@
145146
"ext-pdo_oci": "Required for Oracle database support"
146147
},
147148
"require-dev": {
148-
"phpunit/phpunit": "^12.0",
149+
"phpunit/phpunit": "^11.5.0",
149150
"monolog/monolog": "^3.9",
150151
"symfony/cache": "^7.3",
151152
"phpstan/phpstan": "^2.0",

src/ai/mcp/tools/AnalyzeQueryTool.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function execute(array $arguments): string|array
6565
try {
6666
// Get EXPLAIN plan for better AI analysis
6767
$explainAnalysis = null;
68+
6869
try {
6970
$connection = $this->db->connection;
7071
$dialect = $connection->getDialect();

src/cli/commands/AiCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ protected function analyze(): int
7070
$pdo = $connection->getPdo();
7171

7272
$explainAnalysis = null;
73+
7374
try {
7475
$explainResults = $dialect->executeExplain($pdo, $sql, []);
7576
$queryBuilder = $db->find();

src/cli/ui/InputHandler.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,23 @@ protected static function parseEscapeSequence(string $seq): string
245245
*/
246246
public static function waitForKey(array $allowedKeys = []): string
247247
{
248+
// Check for non-interactive mode first (fastest check)
249+
$nonInteractive = getenv('PDODB_NON_INTERACTIVE') !== false
250+
|| getenv('PHPUNIT') !== false;
251+
252+
// Only check stream_isatty if not already in non-interactive mode (expensive check)
253+
if (!$nonInteractive) {
254+
$nonInteractive = !stream_isatty(STDIN);
255+
}
256+
257+
if ($nonInteractive) {
258+
// In non-interactive mode, return empty string or first allowed key
259+
if (!empty($allowedKeys)) {
260+
return $allowedKeys[0];
261+
}
262+
return '';
263+
}
264+
248265
while (true) {
249266
$key = self::readKey(1000000); // 1 second timeout, but will loop
250267

0 commit comments

Comments
 (0)