fix: resolve 14 test failures across 3 test files
Some checks failed
CI / PHP 8.4 (push) Failing after 1m33s
CI / PHP 8.3 (push) Failing after 1m35s

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 <noreply@anthropic.com>
This commit is contained in:
Claude 2026-02-23 11:48:29 +00:00
parent 5fa46104f4
commit 938081f2f5
No known key found for this signature in database
GPG key ID: AF404715446AEB41
3 changed files with 15 additions and 6 deletions

View file

@ -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',

View file

@ -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;
}
}
}

View file

@ -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;
}