forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentDetectorTest.php
More file actions
77 lines (64 loc) · 1.44 KB
/
AgentDetectorTest.php
File metadata and controls
77 lines (64 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php declare(strict_types = 1);
namespace PHPStan\Command;
use Override;
use PHPUnit\Framework\TestCase;
use function putenv;
class AgentDetectorTest extends TestCase
{
private const ENV_VARS = [
'AI_AGENT',
'CURSOR_TRACE_ID',
'CURSOR_AGENT',
'GEMINI_CLI',
'CODEX_SANDBOX',
'AUGMENT_AGENT',
'OPENCODE_CLIENT',
'OPENCODE',
'CLAUDECODE',
'CLAUDE_CODE',
'REPLIT_AGENT',
];
#[Override]
protected function setUp(): void
{
foreach (self::ENV_VARS as $var) {
putenv($var);
}
}
#[Override]
protected function tearDown(): void
{
foreach (self::ENV_VARS as $var) {
putenv($var);
}
}
public function testReturnsFalseWithNoEnvVars(): void
{
$this->assertFalse(AgentDetector::isAgentDetected());
}
public function testReturnsTrueWithAiAgent(): void
{
putenv('AI_AGENT=test');
$this->assertTrue(AgentDetector::isAgentDetected());
}
public function testReturnsFalseWithEmptyAiAgent(): void
{
putenv('AI_AGENT=');
$this->assertFalse(AgentDetector::isAgentDetected());
}
public function testReturnsTrueWithClaudeCode(): void
{
putenv('CLAUDE_CODE=1');
$this->assertTrue(AgentDetector::isAgentDetected());
}
public function testReturnsTrueWithCursorTraceId(): void
{
putenv('CURSOR_TRACE_ID=abc');
$this->assertTrue(AgentDetector::isAgentDetected());
}
public function testReturnsTrueWithReplitAgent(): void
{
putenv('REPLIT_AGENT=1');
$this->assertTrue(AgentDetector::isAgentDetected());
}
}