Search by

adachsoft / sandbox-tool-contract-tests

Arkadiusz Adach

PHPUnit security contract tests for tools operating within filesystem sandboxes.

Package info

gitlab.com/a.adach/sandbox-tool-contract-tests

Issues

pkg:composer/adachsoft/sandbox-tool-contract-tests

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-10-22 16:07 UTC

This package is not auto-updated.

Last update: 2026-10-23 12:28:29 UTC


README

adachsoft/sandbox-tool-contract-tests is a PHPUnit library for verifying that SPI tools respect filesystem sandbox boundaries.

Requirements

  • PHP 8.3 or newer
  • Composer
  • Tools implementing AdachSoft\AiToolCall\SPI\ToolInterface and factories implementing AdachSoft\AiToolCall\SPI\Factory\ToolFactoryInterface

Installation

composer require --dev adachsoft/sandbox-tool-contract-tests

The library provides a PHPUnit base test case, so PHPUnit is declared as a package dependency.

Usage

Extend AbstractSandboxToolTestCase and call assertSandboxToolPasses() from a PHPUnit test method:

<?php

declare(strict_types=1);

use AdachSoft\SandboxToolContractTests\AbstractSandboxToolTestCase;
use AdachSoft\SandboxToolContractTests\PublicApi\Dto\SandboxToolTestTargetDto;
use App\Tools\ReadFileToolFactory;

final class ReadFileSandboxContractTest extends AbstractSandboxToolTestCase
{
    public function testReadFileToolPassesSandboxContract(): void
    {
        $this->assertSandboxToolPasses(
            new SandboxToolTestTargetDto(new ReadFileToolFactory()),
        );
    }
}

Replace ReadFileToolFactory with a factory for your tool. The default verifier checks the configured base path, path traversal, leading-slash handling, path disclosure on success and I/O errors, and symlink escapes.

If a path parameter cannot be inferred from the tool definition, pass a PathParameterVoCollection to SandboxToolTestTargetDto. Use PathParameterKindEnum::SCALAR_STRING for a single path and PathParameterKindEnum::STRING_LIST for a list of paths. Configure result fields containing paths with the DTO's outputPathKeys argument.

Direct verification

For custom integrations, create a verifier and inspect its report:

<?php

declare(strict_types=1);

use AdachSoft\SandboxToolContractTests\PublicApi\Dto\SandboxToolTestTargetDto;
use AdachSoft\SandboxToolContractTests\SandboxToolContractVerifier;
use App\Tools\ReadFileToolFactory;

$target = new SandboxToolTestTargetDto(new ReadFileToolFactory());
$report = (new SandboxToolContractVerifier())->verifyTarget($target);

if (!$report->isPassed()) {
    throw new RuntimeException($report->formatFailureMessage());
}

SandboxVerificationReportDto contains the detected SandboxRuleViolationDto values. Use isPassed() to check the result and formatFailureMessage() to produce a diagnostic message.