fix: DockerSecretsResolver - don't normalize absolute paths like /var/www/html/...
Some checks failed
Deploy Application / deploy (push) Has been cancelled
Some checks failed
Deploy Application / deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Framework\Discovery\Storage\Services;
|
||||
|
||||
use App\Framework\Discovery\Storage\Services\StalenessChecker;
|
||||
use App\Framework\Core\ValueObjects\Timestamp;
|
||||
use App\Framework\Discovery\Storage\ValueObjects\CacheEntry;
|
||||
use App\Framework\Discovery\Storage\ValueObjects\StalenessCheckResult;
|
||||
use App\Framework\Discovery\ValueObjects\DiscoveryContext;
|
||||
use App\Framework\Discovery\ValueObjects\DiscoveryOptions;
|
||||
use App\Framework\Discovery\ValueObjects\ScanType;
|
||||
use App\Framework\Discovery\Results\DiscoveryRegistry;
|
||||
use App\Framework\Discovery\Results\AttributeRegistry;
|
||||
use App\Framework\Discovery\Results\InterfaceRegistry;
|
||||
use App\Framework\Discovery\Results\TemplateRegistry;
|
||||
use App\Framework\Discovery\ValueObjects\CacheLevel;
|
||||
use App\Framework\Discovery\ValueObjects\CacheTier;
|
||||
use App\Framework\Filesystem\FileSystemService;
|
||||
use App\Framework\Filesystem\ValueObjects\FilePath;
|
||||
use App\Framework\Filesystem\ValueObjects\FileMetadata;
|
||||
|
||||
use Mockery;
|
||||
|
||||
describe('StalenessChecker', function () {
|
||||
beforeEach(function () {
|
||||
// Use real FileSystemService since it's final
|
||||
$this->fileSystemService = new FileSystemService();
|
||||
$this->checker = new StalenessChecker($this->fileSystemService);
|
||||
});
|
||||
|
||||
it('returns stale for incremental scan', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()),
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
$context = new DiscoveryContext(
|
||||
paths: ['/test/path'],
|
||||
scanType: ScanType::INCREMENTAL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
$result = $this->checker->check($context, $entry);
|
||||
|
||||
expect($result->isStale)->toBeTrue();
|
||||
expect($result->reason)->toBe('incremental_scan');
|
||||
});
|
||||
|
||||
it('checks staleness with real filesystem', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
// Use a past time to ensure cache is stale (directory was modified after cache creation)
|
||||
$createdAt = Timestamp::fromDateTime(new \DateTimeImmutable('2020-01-01 12:00:00'));
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: $createdAt,
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
// Use real existing path
|
||||
$basePath = file_exists('/var/www/html/src') ? '/var/www/html/src' : __DIR__ . '/../../../../src';
|
||||
$context = new DiscoveryContext(
|
||||
paths: [$basePath],
|
||||
scanType: ScanType::FULL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable('2020-01-01 13:00:00')
|
||||
);
|
||||
|
||||
$result = $this->checker->check($context, $entry);
|
||||
|
||||
// Should be stale (directory modified after cache creation)
|
||||
expect($result)->toBeInstanceOf(StalenessCheckResult::class);
|
||||
expect($result->isStale)->toBeTrue();
|
||||
});
|
||||
|
||||
it('handles non-existent paths gracefully', function () {
|
||||
$registry = new DiscoveryRegistry(
|
||||
attributes: new AttributeRegistry(),
|
||||
interfaces: new InterfaceRegistry(),
|
||||
templates: new TemplateRegistry()
|
||||
);
|
||||
|
||||
$entry = new CacheEntry(
|
||||
registry: $registry,
|
||||
createdAt: Timestamp::fromDateTime(new \DateTimeImmutable()),
|
||||
version: 'v1-abc12345',
|
||||
cacheLevel: CacheLevel::NORMAL,
|
||||
cacheTier: CacheTier::HOT
|
||||
);
|
||||
|
||||
$context = new DiscoveryContext(
|
||||
paths: ['/non/existent/path'],
|
||||
scanType: ScanType::FULL,
|
||||
options: new DiscoveryOptions(),
|
||||
startTime: new \DateTimeImmutable()
|
||||
);
|
||||
|
||||
$result = $this->checker->check($context, $entry);
|
||||
|
||||
// Should assume stale on error (conservative)
|
||||
expect($result->isStale)->toBeTrue();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user