Skip to content
This repository was archived by the owner on Nov 30, 2026. It is now read-only.
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
12 changes: 12 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<!--
The CLI picks interactive or headless behaviour from the environment (TTY, CI and
agent env vars). The suite expects headless, which CI and agents provide but a
developer's own terminal doesn't, so pin it to match CI.

NO_COLOR matters because decorated (TTY) output makes Laravel Prompts' spinner fork
a child process, which can outlive the test and signal the test runner.
-->
<env name="CI" value="true" force="true"/>
<env name="NO_COLOR" value="1" force="true"/>
</php>
<source>
<include>
<directory>./app</directory>
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/OffersSkillsInstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ function partialMiddleware(array $overrides = []): OffersSkillsInstall
});

it('skips when the session is non-interactive', function () {
// Under phpunit, STDIN is not a TTY so isInteractiveSession() returns false.
$this->mockConfig->shouldNotReceive('get');

expect(runMiddleware(new OffersSkillsInstall))->toBeTrue();
$middleware = partialMiddleware(['isInteractiveSession' => false]);

expect(runMiddleware($middleware))->toBeTrue();
});

it('skips when the CLI is a project dependency', function () {
Expand Down
32 changes: 24 additions & 8 deletions tests/Unit/ContextDetectorTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
<?php

use App\Support\ContextDetector;
use Laravel\AgentDetector\AgentDetector;

// Running the suite from inside an agent (Claude Code, Cursor, etc.) or a terminal
// leaks these into the process, so clear them up front and restore them afterwards.
function contextDetectorEnvVars(): array
{
return [
'AI_AGENT',
'CLAUDE_CODE_IS_COWORK',
'TERM_PROGRAM',
...array_keys(AgentDetector::AGENT_ENV_VARS),
];
}

beforeEach(function () {
$this->originalEnv = [];

foreach (contextDetectorEnvVars() as $var) {
$this->originalEnv[$var] = getenv($var);
putenv($var);
}

ContextDetector::flush();
});

afterEach(function () {
putenv('CLAUDECODE');
putenv('CLAUDE_CODE');
putenv('CODEX_SANDBOX');
putenv('CURSOR_AGENT');
putenv('CURSOR_TRACE_ID');
putenv('OPENCODE');
putenv('OPENCODE_CLIENT');
putenv('TERM_PROGRAM');
foreach ($this->originalEnv as $var => $value) {
putenv($value === false ? $var : "{$var}={$value}");
}

ContextDetector::flush();
});

Expand Down