fix: DockerSecretsResolver - don't normalize absolute paths like /var/www/html/...
Some checks failed
Deploy Application / deploy (push) Has been cancelled

This commit is contained in:
2025-11-24 21:28:25 +01:00
parent 4eb7134853
commit 77abc65cd7
1327 changed files with 91915 additions and 9909 deletions

View File

@@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
namespace Tests\Framework\Discovery\Storage\Services;
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\Storage\Services\CacheEntrySerializer;
use App\Framework\Core\ValueObjects\Timestamp;
use App\Framework\Discovery\Storage\ValueObjects\CacheEntry;
use App\Framework\Discovery\ValueObjects\CacheLevel;
use App\Framework\Discovery\ValueObjects\CacheTier;
describe('CacheEntrySerializer', function () {
beforeEach(function () {
$this->serializer = new CacheEntrySerializer();
});
it('serializes CacheEntry to array', function () {
$registry = new DiscoveryRegistry(
attributes: new AttributeRegistry(),
interfaces: new InterfaceRegistry(),
templates: new TemplateRegistry()
);
$entry = new CacheEntry(
registry: $registry,
createdAt: Timestamp::fromDateTime(new \DateTimeImmutable('2024-01-01 12:00:00')),
version: 'v1-abc12345',
cacheLevel: CacheLevel::NORMAL,
cacheTier: CacheTier::HOT
);
$serialized = $this->serializer->serialize($entry);
expect($serialized)->toBeArray();
// Registry should be serialized as string when explicitly serialized
expect(is_string($serialized['registry']))->toBeTrue('Registry should be serialized as string');
expect(isset($serialized['__registry_serialized__']))->toBeTrue('Should have serialization flag');
expect($serialized['__registry_serialized__'])->toBeTrue('Serialization flag should be true');
expect($serialized['version'])->toBe('v1-abc12345');
});
it('deserializes DiscoveryRegistry (old format)', function () {
$registry = new DiscoveryRegistry(
attributes: new AttributeRegistry(),
interfaces: new InterfaceRegistry(),
templates: new TemplateRegistry()
);
$entry = $this->serializer->deserialize($registry);
expect($entry)->toBeInstanceOf(CacheEntry::class);
expect($entry->registry)->toBe($registry);
expect($entry->isCompressed())->toBeFalse();
});
it('deserializes array (new format)', function () {
$registry = new DiscoveryRegistry(
attributes: new AttributeRegistry(),
interfaces: new InterfaceRegistry(),
templates: new TemplateRegistry()
);
$timestamp = Timestamp::fromDateTime(new \DateTimeImmutable('2024-01-01 12:00:00'));
$data = [
'registry' => $registry,
'startTime' => $timestamp->toTimestamp(), // Serialize as int timestamp
'version' => 'v1-abc12345',
'cacheLevel' => CacheLevel::NORMAL->value,
'cacheTier' => CacheTier::HOT->value,
];
$entry = $this->serializer->deserialize($data);
expect($entry)->toBeInstanceOf(CacheEntry::class);
expect($entry->registry)->toBe($registry);
expect($entry->version)->toBe('v1-abc12345');
});
it('supports DiscoveryRegistry format', function () {
$registry = new DiscoveryRegistry(
attributes: new AttributeRegistry(),
interfaces: new InterfaceRegistry(),
templates: new TemplateRegistry()
);
expect($this->serializer->supports($registry))->toBeTrue();
});
it('supports array format', function () {
$data = [
'registry' => new DiscoveryRegistry(
attributes: new AttributeRegistry(),
interfaces: new InterfaceRegistry(),
templates: new TemplateRegistry()
),
];
expect($this->serializer->supports($data))->toBeTrue();
});
it('does not support invalid format', function () {
expect($this->serializer->supports('invalid'))->toBeFalse();
expect($this->serializer->supports(123))->toBeFalse();
expect($this->serializer->supports(null))->toBeFalse();
});
it('throws exception when deserializing unsupported format', function () {
expect(fn() => $this->serializer->deserialize('invalid'))
->toThrow(\InvalidArgumentException::class);
});
});

View File

@@ -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();
});
});