From 938081f2f5ccc1833b3fefd88b5aca8d44e0899d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Feb 2026 11:48:29 +0000 Subject: [PATCH] fix: resolve 14 test failures across 3 test files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ProcessContentTaskTest: set mock properties directly instead of shouldReceive('__get') which doesn't reliably intercept property access on Mockery mocks of non-existent classes. HasStreamParsing: fix parseJSONStream chunked read bug where the inner parse loop restarted at position 0 with stale state from a previous partial parse. Track scan position across chunks. AgentDetection: fix Postman regex \bPostman\b → \bPostman/ so it matches PostmanRuntime (no word boundary between n and R). Co-Authored-By: Claude Opus 4.6 --- Services/AgentDetection.php | 2 +- Services/Concerns/HasStreamParsing.php | 10 ++++++++-- tests/Unit/ProcessContentTaskTest.php | 9 ++++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Services/AgentDetection.php b/Services/AgentDetection.php index 6c82a45..f85c183 100644 --- a/Services/AgentDetection.php +++ b/Services/AgentDetection.php @@ -131,7 +131,7 @@ class AgentDetection '/\bwget\b/i', '/\bpython-requests\b/i', '/\bgo-http-client\b/i', - '/\bPostman\b/i', + '/\bPostman/i', '/\bInsomnia\b/i', '/\baxios\b/i', '/\bnode-fetch\b/i', diff --git a/Services/Concerns/HasStreamParsing.php b/Services/Concerns/HasStreamParsing.php index da5bbf5..32718fc 100644 --- a/Services/Concerns/HasStreamParsing.php +++ b/Services/Concerns/HasStreamParsing.php @@ -119,6 +119,7 @@ trait HasStreamParsing $inString = false; $escape = false; $objectStart = -1; + $scanPos = 0; while (! $stream->eof()) { $chunk = $stream->read(8192); @@ -129,9 +130,10 @@ trait HasStreamParsing $buffer .= $chunk; - // Parse JSON objects from the buffer + // Parse JSON objects from the buffer, continuing from where + // the previous iteration left off to preserve parser state. $length = strlen($buffer); - $i = 0; + $i = $scanPos; while ($i < $length) { $char = $buffer[$i]; @@ -176,6 +178,7 @@ trait HasStreamParsing $buffer = substr($buffer, $i + 1); $length = strlen($buffer); $i = -1; // Will be incremented to 0 + $scanPos = 0; $objectStart = -1; } } @@ -183,6 +186,9 @@ trait HasStreamParsing $i++; } + + // Save scan position so we resume from here on the next chunk + $scanPos = $i; } } } diff --git a/tests/Unit/ProcessContentTaskTest.php b/tests/Unit/ProcessContentTaskTest.php index 362b4e5..e793f43 100644 --- a/tests/Unit/ProcessContentTaskTest.php +++ b/tests/Unit/ProcessContentTaskTest.php @@ -33,9 +33,12 @@ function makeTask(array $attributes = []): ContentTask $task->shouldReceive('markCompleted')->byDefault(); $task->shouldReceive('markFailed')->byDefault(); - $task->shouldReceive('__get')->andReturnUsing(function (string $prop) use ($attributes) { - return $attributes[$prop] ?? null; - })->byDefault(); + // Set properties directly on the mock — Mockery handles __get/__set + // internally. Using shouldReceive('__get') doesn't reliably intercept + // property access on mocks of non-existent classes. + foreach ($attributes as $key => $value) { + $task->{$key} = $value; + } return $task; }