Skip to content

Commit fd805e2

Browse files
committed
test: reclassify sandbox integration coverage
Move file- and process-based sandbox tests from Unit and Regression into Integration. Add executable preflight checks so missing sandbox binaries fail consistently across CI and local environments.
1 parent 89ed6e5 commit fd805e2

13 files changed

+37
-15
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
"psalm": "@php ./vendor/bin/psalm -c packages/instructor/psalm.xml",
8080
"psalm-unused": "@php ./vendor/bin/psalm --find-unused-code",
8181
"tell": "bin/tell",
82-
"test": "@php -d memory_limit=512M ./vendor/bin/pest --compact --testsuite=Unit,Feature,Regression --exclude-group=docs-qa",
83-
"tests": "@php -d memory_limit=512M ./vendor/bin/pest --compact --testsuite=Unit,Feature,Regression --exclude-group=docs-qa",
82+
"test": "@php -d memory_limit=512M ./vendor/bin/pest --compact --testsuite=Unit,Feature,Integration,Regression --exclude-group=docs-qa",
83+
"tests": "@php -d memory_limit=512M ./vendor/bin/pest --compact --testsuite=Unit,Feature,Integration,Regression --exclude-group=docs-qa",
8484
"test:docs-qa": "@php -d memory_limit=512M ./vendor/bin/pest --compact --group=docs-qa",
8585
"test-all": "@php ./vendor/bin/pest",
8686
"dead-code": "@php ./vendor/bin/phpstan analyse -c phpstan-unused.neon --no-progress --error-format=table",

packages/sandbox/src/Drivers/BubblewrapSandbox.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ private function makeProcRunner(): CanRunProcess {
6363
* @return list<string>
6464
*/
6565
private function buildCommand(string $workDir, array $innerArgv): array {
66-
$cmd = [$this->bwrapBin, '--die-with-parent'];
66+
$bwrapBin = ProcUtils::requireExecutable($this->bwrapBin, 'bwrap');
67+
$cmd = [$bwrapBin, '--die-with-parent'];
6768
$cmd = [...$cmd, '--unshare-pid', '--unshare-uts', '--unshare-ipc', '--unshare-cgroup'];
6869
if (!$this->policy->networkEnabled()) {
6970
$cmd[] = '--unshare-net';

packages/sandbox/src/Drivers/DockerSandbox.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ private function makeProcRunner(): CanRunProcess {
6464
* @return list<string>
6565
*/
6666
private function buildContainerCommand(string $workDir, array $argv): array {
67-
$builder = ContainerCommandBuilder::docker($this->dockerBin)
67+
$dockerBin = ProcUtils::requireExecutable($this->dockerBin, 'docker');
68+
69+
$builder = ContainerCommandBuilder::docker($dockerBin)
6870
->withImage($this->image)
6971
->withNetwork($this->policy->networkEnabled())
7072
->withPidsLimit(20)

packages/sandbox/src/Drivers/FirejailSandbox.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ private function makeProcRunner(): CanRunProcess {
6363
* @return list<string>
6464
*/
6565
private function buildCommand(string $workDir, array $innerArgv): array {
66+
$firejailBin = ProcUtils::requireExecutable($this->firejailBin, 'firejail');
6667
$cmd = [
67-
$this->firejailBin,
68+
$firejailBin,
6869
];
6970
if (!$this->policy->networkEnabled()) {
7071
$cmd[] = '--net=none';

packages/sandbox/src/Drivers/PodmanSandbox.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ private function makeProcRunner(): CanRunProcess {
6565
*/
6666
private function buildContainerCommand(string $workDir, array $argv): array {
6767
$isWSL2 = $this->isWSL2Environment();
68+
$podmanBin = ProcUtils::requireExecutable($this->podmanBin, 'podman');
6869

69-
$builder = ContainerCommandBuilder::podman($this->podmanBin)
70+
$builder = ContainerCommandBuilder::podman($podmanBin)
7071
->withImage($this->image)
7172
->withNetwork($this->policy->networkEnabled())
7273
->withPidsLimit(20)

packages/sandbox/src/Utils/ProcUtils.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@ public static function findSetSidPath(): ?string {
1414
return null;
1515
}
1616

17+
public static function requireExecutable(string $binaryName, string $nameForError): string {
18+
if ($binaryName === '') {
19+
throw new \RuntimeException('Failed to start ' . $nameForError);
20+
}
21+
22+
if (basename($binaryName) !== $binaryName) {
23+
if (!is_executable($binaryName)) {
24+
throw new \RuntimeException('Failed to start ' . $nameForError);
25+
}
26+
return $binaryName;
27+
}
28+
29+
$resolved = self::findOnPath($binaryName, self::defaultBinPaths());
30+
if ($resolved === null) {
31+
throw new \RuntimeException('Failed to start ' . $nameForError);
32+
}
33+
return $resolved;
34+
}
35+
1736
/**
1837
* Locate an executable on PATH and optional extra directories.
1938
*

packages/sandbox/tests/Unit/DriverWorkdirCleanupOnFailureTest.php renamed to packages/sandbox/tests/Integration/DriverWorkdirCleanupOnFailureTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Cognesy\Sandbox\Tests\Unit;
3+
namespace Cognesy\Sandbox\Tests\Integration;
44

55
use Cognesy\Sandbox\Config\ExecutionPolicy;
66
use Cognesy\Sandbox\Contracts\CanExecuteCommand;

packages/sandbox/tests/Unit/FirejailSecurityPolicyTest.php renamed to packages/sandbox/tests/Integration/FirejailSecurityPolicyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Cognesy\Sandbox\Tests\Unit;
3+
namespace Cognesy\Sandbox\Tests\Integration;
44

55
use Cognesy\Sandbox\Config\ExecutionPolicy;
66
use Cognesy\Sandbox\Drivers\FirejailSandbox;

packages/sandbox/tests/Regression/MissingBinaryDiagnosticsTest.php renamed to packages/sandbox/tests/Integration/MissingBinaryDiagnosticsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Cognesy\Sandbox\Tests\Regression;
3+
namespace Cognesy\Sandbox\Tests\Integration;
44

55
use Cognesy\Sandbox\Config\ExecutionPolicy;
66
use Cognesy\Sandbox\Contracts\CanExecuteCommand;

packages/sandbox/tests/Unit/ProcRunnerTest.php renamed to packages/sandbox/tests/Integration/ProcRunnerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Cognesy\Sandbox\Tests\Unit;
3+
namespace Cognesy\Sandbox\Tests\Integration;
44

55
use Cognesy\Sandbox\Runners\ProcRunner;
66
use Cognesy\Sandbox\Utils\TimeoutTracker;

0 commit comments

Comments
 (0)