Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/database/src/Console/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public function handle(): int
}

try {
(new Process(
array_merge([$configuration->command], $configuration->arguments),
null,
$configuration->environment
))->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) {
// Container resolution lets tests replace the process without class overloading.
$this->hypervel->make(Process::class, [
'command' => array_merge([$configuration->command], $configuration->arguments),
'env' => $configuration->environment,
])->setTimeout(null)->setTty(true)->mustRun(function ($type, $buffer) {
$this->output->write($buffer);
});
} catch (ProcessFailedException $e) {
Expand Down
2 changes: 2 additions & 0 deletions src/docs/porting-from-laravel.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ Some packages also define package-local contracts, such as `Hypervel\Permission\

Custom `Hypervel\Contracts\View\View` implementations must provide `gatherData(): array`, returning the data used to render the view, including any shared values. Extending `Hypervel\View\View` supplies it.

Custom `Hypervel\View\ViewFinderInterface` implementations must provide `prependLocation()`, `getPaths()` and `getHints()`; extending `Hypervel\View\FileViewFinder` supplies them.

<a name="missing-equivalents"></a>
### Missing Equivalents

Expand Down
2 changes: 0 additions & 2 deletions src/foundation/src/Console/ViewCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Hypervel\Console\Command;
use Hypervel\Support\Collection;
use Hypervel\View\Engines\CompilerEngine;
use Hypervel\View\FileViewFinder;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;
Expand Down Expand Up @@ -86,7 +85,6 @@ protected function bladeFilesIn(array $paths): Collection
*/
protected function paths(): Collection
{
/** @var FileViewFinder $finder */
$finder = $this->hypervel->make('view')->getFinder();

$paths = (new Collection($finder->getPaths()))->merge(
Expand Down
7 changes: 2 additions & 5 deletions src/phpstan/src/Support/RuntimeInputs.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Hypervel\Testbench\Bootstrap\LoadConfiguration as TestbenchLoadConfiguration;
use Hypervel\Testbench\Bootstrapper;
use Hypervel\Testbench\Foundation\Config as TestbenchConfig;
use Hypervel\View\FileViewFinder;
use LogicException;
use PHPStan\Analyser\DeclarationDependencyTracker;
use PHPStan\Analyser\DependencyTracker;
Expand Down Expand Up @@ -322,10 +321,8 @@ private function createViewsKey(): string
$finder = $this->application()->make('view')->getFinder();
$directories = $finder->getPaths();

if ($finder instanceof FileViewFinder) {
foreach ($finder->getHints() as $paths) {
$directories = [...$directories, ...$paths];
}
foreach ($finder->getHints() as $paths) {
$directories = [...$directories, ...$paths];
}

$listings = [];
Expand Down
6 changes: 1 addition & 5 deletions src/phpstan/src/Support/ViewFileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Generator;
use Hypervel\PHPStan\Concerns\HasContainer;
use Hypervel\View\Factory as ViewFactory;
use Hypervel\View\FileViewFinder;
use Hypervel\View\ViewFinderInterface;
use PHPStan\Analyser\DependencyTracker;
use PHPStan\Analyser\Scope;
Expand Down Expand Up @@ -74,10 +73,7 @@ public function __construct(
$finder = $this->finder();
$viewDirectories = $finder->getPaths();

// Hypervel's finder contract has no namespace hints; the standard finder does.
if ($finder instanceof FileViewFinder) {
$hintDirectories = array_merge(...array_values($finder->getHints()));
}
$hintDirectories = array_merge(...array_values($finder->getHints()));
}

// View names are derived from these directories, so a relative directory is
Expand Down
1 change: 1 addition & 0 deletions src/view/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Documentation: https://hypervel.org/docs/views

## Differences From Laravel

- `ViewFinderInterface` includes `prependLocation()`, `getPaths()` and `getHints()` so callers can prepend locations and read the registered paths and namespace hints. Extending `FileViewFinder` supplies these methods.
- `Blade::component()` accepts the component alias before the class name: `Blade::component('package-alert', Alert::class)`.
- A `View` passed as section content is rendered before the content is stored, so later changes to that `View` instance do not affect the section.

Expand Down
7 changes: 7 additions & 0 deletions src/view/src/ViewFinderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ public function prependLocation(string $location): void;
* Get the active view paths.
*/
public function getPaths(): array;

/**
* Get the namespace to file path hints.
*
* Hypervel pairs namespace registration with discovery on the contract.
*/
public function getHints(): array;
}
9 changes: 6 additions & 3 deletions tests/Ai/BroadcastBatchingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
use Hypervel\Support\Facades\Context;
use Hypervel\Support\Facades\Event;
use Hypervel\Support\Facades\Exceptions;
use Mockery as m;
use JMac\Testing\Double;
use JMac\Testing\Integrations\PHPUnit\VerifiesDoubles;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestWith;
use RuntimeException;
Expand All @@ -31,6 +32,8 @@

class BroadcastBatchingTest extends TestCase
{
use VerifiesDoubles;

public function testBatchesPreserveContentBoundariesAndOriginalReplay(): void
{
config(['ai.broadcasting.batching.milliseconds' => 60000]);
Expand Down Expand Up @@ -238,8 +241,8 @@ public function testCancellationWhileFinishingBroadcastsCancelsTheSender(bool $c
{
config(['broadcasting.default' => 'null', 'ai.broadcasting.batching.max_bytes' => 1]);
$failure = $cleanupThrows ? new RuntimeException('Release cleanup failed.', previous: new CanceledException) : new CanceledException;
$lease = m::mock(ConnectionLease::class);
$lease->shouldReceive('releaseIfIdle')->once()->andThrow($failure);
$lease = Double::for(ConnectionLease::class);
$lease->expects('releaseIfIdle')->throws($failure);
$waiting = new Channel(1);
$senderCanceled = false;
$senderId = null;
Expand Down
65 changes: 34 additions & 31 deletions tests/Ai/ConcurrentToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Hypervel\Ai\Contracts\Gateway\Gateway;
use Hypervel\Ai\Contracts\Gateway\StepTextGateway;
use Hypervel\Ai\Contracts\Providers\TextProvider;
use Hypervel\Ai\Contracts\Tool;
use Hypervel\Ai\Events\ToolFailed;
use Hypervel\Ai\Gateway\RunContext;
use Hypervel\Ai\Gateway\StepResponse;
Expand All @@ -39,8 +38,10 @@
use Hypervel\Engine\Coroutine as EngineCoroutine;
use Hypervel\Support\Facades\Context;
use Hypervel\Support\Facades\DB;
use Hypervel\Tests\Ai\Fixtures\Tools\NamedTool;
use InvalidArgumentException;
use Mockery as m;
use JMac\Testing\Double;
use JMac\Testing\Integrations\PHPUnit\VerifiesDoubles;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestWith;
use RuntimeException;
Expand All @@ -49,6 +50,8 @@

class ConcurrentToolsTest extends TestCase
{
use VerifiesDoubles;

#[DataProvider('deliveryModes')]
public function testOptedInToolsAreBoundedOrderedAndUseTheCapturedContext(bool $streaming): void
{
Expand All @@ -71,17 +74,17 @@ public function testOptedInToolsAreBoundedOrderedAndUseTheCapturedContext(bool $
Coroutine::afterCreated(static function (): void {
CoroutineContext::set('tool-test.account', 'startup');
});
$providerGateway = m::mock(Gateway::class);
$providerGateway = Double::for(Gateway::class);
Ai::extend('tool-test', static fn (Application $app, array $config): Provider => new class($providerGateway, $config, $app->make(Dispatcher::class)) extends Provider {});
$accountProvider = Ai::build(['name' => 'tool-account', 'driver' => 'tool-test', 'key' => 'account-key']);
$active = 0;
$maximum = 0;
$accounts = [];
$requestIds = [];
$resolvedProviders = [];
$tool = m::mock(Tool::class);
$tool->shouldReceive('name')->andReturn('tool');
$tool->shouldReceive('handle')->times(3)->andReturnUsing(function (Request $request) use (&$active, &$maximum, &$accounts, &$requestIds, &$resolvedProviders): string {
$tool = Double::for(NamedTool::class);
$tool->allows('name')->returns('tool');
$tool->expects('handle')->times(3)->resolves(function (Request $request) use (&$active, &$maximum, &$accounts, &$requestIds, &$resolvedProviders): string {
$this->assertSame('tool-connection', DB::getDefaultConnection());
$maximum = max($maximum, ++$active);
$accounts[] = CoroutineContext::get('tool-test.account');
Expand All @@ -97,8 +100,8 @@ public function testOptedInToolsAreBoundedOrderedAndUseTheCapturedContext(bool $
}
});
$calls = [new ToolCall('first', 'tool', []), new ToolCall('second', 'tool', []), new ToolCall('third', 'tool', [])];
$provider = m::mock(TextProvider::class);
$provider->shouldReceive('name')->andReturn('provider');
$provider = Double::for(TextProvider::class);
$provider->allows('name')->returns('provider');
$results = [];
$gateway = $this->gateway($streaming, $calls, $results);
$loop = new TextGenerationLoop($gateway);
Expand Down Expand Up @@ -131,10 +134,10 @@ public static function deliveryModes(): array

public function testInvalidConcurrencyFailsClearlyThroughTheLoop(): void
{
$provider = m::mock(TextProvider::class);
$provider->shouldReceive('name')->andReturn('provider');
$gateway = m::mock(StepTextGateway::class);
$gateway->shouldReceive('generateTextStep')->once()->andReturn(new StepResponse('Finished', [], FinishReason::Stop, new TextUsage, new Meta));
$provider = Double::for(TextProvider::class);
$provider->allows('name')->returns('provider');
$gateway = Double::for(StepTextGateway::class);
$gateway->expects('generateTextStep')->returns(new StepResponse('Finished', [], FinishReason::Stop, new TextUsage, new Meta));

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Tool concurrency must be at least one.');
Expand All @@ -161,9 +164,9 @@ public function testToolFailureCancelsAndJoinsTheOtherTools(bool $canceled, bool

$active = 0;
$resumed = false;
$tool = m::mock(Tool::class);
$tool->shouldReceive('name')->andReturn('tool');
$tool->shouldReceive('handle')->twice()->andReturnUsing(function (Request $request) use ($failure, &$active, &$resumed): string {
$tool = Double::for(NamedTool::class);
$tool->allows('name')->returns('tool');
$tool->expects('handle')->times(2)->resolves(function (Request $request) use ($failure, &$active, &$resumed): string {
++$active;

try {
Expand All @@ -181,14 +184,14 @@ public function testToolFailureCancelsAndJoinsTheOtherTools(bool $canceled, bool
--$active;
}
});
$provider = m::mock(TextProvider::class);
$provider->shouldReceive('name')->andReturn('provider');
$provider = Double::for(TextProvider::class);
$provider->allows('name')->returns('provider');
$results = [];
$gateway = $this->gateway(false, [new ToolCall('first', 'tool', []), new ToolCall('second', 'tool', [])], $results, completes: false);
$caught = null;

try {
(new TextGenerationLoop($gateway))->generate($provider, 'model', '', tools: [$tool], options: new TextGenerationOptions(agent: new ConcurrentToolsTestAgent('', [], [])), context: new RunContext('invocation', m::mock(Agent::class), $provider, 'model', $events));
(new TextGenerationLoop($gateway))->generate($provider, 'model', '', tools: [$tool], options: new TextGenerationOptions(agent: new ConcurrentToolsTestAgent('', [], [])), context: new RunContext('invocation', Double::for(Agent::class), $provider, 'model', $events));
} catch (Throwable $exception) {
$caught = $exception;
}
Expand All @@ -210,9 +213,9 @@ public function testAbandoningLiveSubAgentOutputCancelsAndJoinsItsProducers(): v
$active = 0;
$resumed = false;
$waiting = new Channel(1);
$agent = m::mock(Agent::class, CanActAsTool::class);
$agent->shouldReceive('name')->andReturn('child');
$agent->shouldReceive('stream')->twice()->andReturnUsing(function (string $task) use (&$active, &$resumed, $waiting): StreamableAgentResponse {
$agent = Double::for(Agent::class, CanActAsTool::class);
$agent->allows('name')->returns('child');
$agent->expects('stream')->times(2)->resolves(function (string $task) use (&$active, &$resumed, $waiting): StreamableAgentResponse {
return new StreamableAgentResponse($task, function () use ($task, &$active, &$resumed, $waiting): Generator {
++$active;

Expand All @@ -225,8 +228,8 @@ public function testAbandoningLiveSubAgentOutputCancelsAndJoinsItsProducers(): v
}
});
});
$provider = m::mock(TextProvider::class);
$provider->shouldReceive('name')->andReturn('provider');
$provider = Double::for(TextProvider::class);
$provider->allows('name')->returns('provider');
$results = [];
$gateway = $this->gateway(true, [
new ToolCall('first', 'child', ['task' => 'first']),
Expand Down Expand Up @@ -267,9 +270,9 @@ public function testCancelingTheConsumerCancelsAndJoinsTheTools(bool $throwExcep
$resumed = false;
$caught = null;
$waiting = new Channel(1);
$tool = m::mock(Tool::class);
$tool->shouldReceive('name')->andReturn('tool');
$tool->shouldReceive('handle')->twice()->andReturnUsing(function () use ($waiting, &$active, &$resumed): string {
$tool = Double::for(NamedTool::class);
$tool->allows('name')->returns('tool');
$tool->expects('handle')->times(2)->resolves(function () use ($waiting, &$active, &$resumed): string {
++$active;

try {
Expand All @@ -281,8 +284,8 @@ public function testCancelingTheConsumerCancelsAndJoinsTheTools(bool $throwExcep
--$active;
}
});
$provider = m::mock(TextProvider::class);
$provider->shouldReceive('name')->andReturn('provider');
$provider = Double::for(TextProvider::class);
$provider->allows('name')->returns('provider');
$results = [];
$gateway = $this->gateway(true, [new ToolCall('first', 'tool', []), new ToolCall('second', 'tool', [])], $results, completes: false);
$loop = new TextGenerationLoop($gateway);
Expand Down Expand Up @@ -332,16 +335,16 @@ private function gateway(bool $streaming, array $calls, array &$results, bool $c

return new StepResponse('Finished', [], FinishReason::Stop, new TextUsage, new Meta);
};
$gateway = m::mock(StepTextGateway::class);
$gateway = Double::for(StepTextGateway::class);

if ($streaming) {
$gateway->shouldReceive('generateStreamStep')->times($completes ? 2 : 1)->andReturnUsing(static function (...$arguments) use ($response): Generator {
$gateway->expects('generateStreamStep')->times($completes ? 2 : 1)->resolves(static function (...$arguments) use ($response): Generator {
yield from [];

return $response($arguments[4]);
});
} else {
$gateway->shouldReceive('generateTextStep')->times($completes ? 2 : 1)->andReturnUsing(static fn (...$arguments): StepResponse => $response($arguments[3]));
$gateway->expects('generateTextStep')->times($completes ? 2 : 1)->resolves(static fn (...$arguments): StepResponse => $response($arguments[3]));
}

return $gateway;
Expand Down
Loading
Loading