commit compras5 2911
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-29 19:49:19 +02:00
parent a935499d64
commit 96b30368bc
96 changed files with 3397 additions and 111 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
use App\Services\DeadlineTaskGuiAction;
function syntheticDeadlineGuiXml(): string
{
return '<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>'
.'<ExecutionTimeLimit>PT1M</ExecutionTimeLimit></Settings><Actions><Exec><Command>C:/synthetic/php.exe</Command>'
.'<Arguments>"C:/synthetic/deadlines.php" --once</Arguments><WorkingDirectory>C:/synthetic</WorkingDirectory></Exec></Actions></Task>';
}
test('silent deadline correction preserves arguments working directory overlap and limits', function () {
$xml = syntheticDeadlineGuiXml();
$after = DeadlineTaskGuiAction::replacement($xml, 'C:/synthetic/php.exe', 'C:/synthetic/php-win.exe');
expect($after)->toContain('php-win.exe')->toContain('"C:/synthetic/deadlines.php" --once')->toContain('IgnoreNew')->toContain('PT1M');
DeadlineTaskGuiAction::assertConserved($xml, $after, 'C:/synthetic/php.exe', 'C:/synthetic/php-win.exe');
DeadlineTaskGuiAction::assertConserved($xml, str_replace('><', ">\r\n <", $after), 'C:/synthetic/php.exe', 'C:/synthetic/php-win.exe');
expect(DeadlineTaskGuiAction::canonical(str_replace('><', ">\r\n <", $xml)))->toBe(DeadlineTaskGuiAction::canonical($xml));
expect(fn () => DeadlineTaskGuiAction::assertConserved($xml, str_replace('PT1M', 'PT5M', $after), 'C:/synthetic/php.exe', 'C:/synthetic/php-win.exe'))
->toThrow(LogicException::class, 'DEADLINE_TASK_GUI_UNRELATED_DEFINITION_CHANGE');
});
test('silent deadline correction refuses another executable directory or multiple actions', function () {
$xml = syntheticDeadlineGuiXml();
expect(fn () => DeadlineTaskGuiAction::replacement($xml, 'C:/synthetic/php.exe', 'C:/other/php-win.exe'))->toThrow(LogicException::class, 'DEADLINE_TASK_GUI_EXECUTABLE_PAIR');
expect(fn () => DeadlineTaskGuiAction::replacement(str_replace('</Actions>', '<Exec><Command>other</Command></Exec></Actions>', $xml), 'C:/synthetic/php.exe', 'C:/synthetic/php-win.exe'))
->toThrow(LogicException::class, 'DEADLINE_TASK_GUI_ACTION_MISMATCH');
});
@@ -0,0 +1,53 @@
<?php
use App\Services\InventoryConversionRuntime;
test('inventory archive validates exact entry names independently of insertion order', function () {
$path = sys_get_temp_dir().'/compras-inventory-entries-'.bin2hex(random_bytes(8)).'.zip';
$zip = new ZipArchive;
try {
expect($zip->open($path, ZipArchive::CREATE | ZipArchive::EXCL))->toBeTrue();
foreach (['src/ReceiptMovementWriter.php', 'src/QuantityConversion.php', 'bootstrap.php', 'manifest.json'] as $name) {
$zip->addFromString($name, 'synthetic archive entry');
}
$zip->close();
$zip->open($path);
InventoryConversionRuntime::assertArchiveEntries($zip);
expect($zip->numFiles)->toBe(4);
$zip->addFromString('../unexpected.php', 'synthetic forbidden entry');
expect(fn () => InventoryConversionRuntime::assertArchiveEntries($zip))->toThrow(LogicException::class, 'COMPRAS_INVENTORY_ARCHIVE_ENTRIES');
$zip->deleteName('../unexpected.php');
$zip->deleteName('bootstrap.php');
expect(fn () => InventoryConversionRuntime::assertArchiveEntries($zip))->toThrow(LogicException::class, 'COMPRAS_INVENTORY_ARCHIVE_ENTRIES');
} finally {
$zip->close();
if (is_file($path)) {
unlink($path);
}
}
});
test('inventory candidate rejects changed component bytes and manifests before loading PHP', function () {
$source = dirname(__DIR__, 2).'/packages/inventory-write/releases/0.2.0-rc.1';
$root = sys_get_temp_dir().'/compras-inventory-artifact-'.bin2hex(random_bytes(8));
mkdir($root.'/src', 0700, true);
$files = ['manifest.json', 'bootstrap.php', 'src/QuantityConversion.php', 'src/ReceiptMovementWriter.php'];
try {
foreach ($files as $file) {
copy($source.'/'.$file, $root.'/'.$file);
}
InventoryConversionRuntime::verifyArtifact($root);
expect(hash_file('sha256', $root.'/manifest.json'))->toBe(InventoryConversionRuntime::MANIFEST_SHA256);
file_put_contents($root.'/src/QuantityConversion.php', "\n// altered", FILE_APPEND);
expect(fn () => InventoryConversionRuntime::verifyArtifact($root))->toThrow(LogicException::class, 'COMPRAS_INVENTORY_FILE:src/QuantityConversion.php');
copy($source.'/src/QuantityConversion.php', $root.'/src/QuantityConversion.php');
file_put_contents($root.'/manifest.json', "\n", FILE_APPEND);
expect(fn () => InventoryConversionRuntime::verifyArtifact($root))->toThrow(LogicException::class, 'COMPRAS_INVENTORY_MANIFEST');
} finally {
foreach ($files as $file) {
unlink($root.'/'.$file);
}
rmdir($root.'/src');
rmdir($root);
}
});
@@ -0,0 +1,13 @@
<?php
use App\Services\ReplenishmentTaskDefinition;
test('native omitted limited run level remains equivalent but elevation and frequency changes are refused', function () {
$xml = '<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"><Triggers><TimeTrigger><Repetition><Interval>PT1M</Interval></Repetition></TimeTrigger><LogonTrigger><UserId>S-1-5-21-1</UserId></LogonTrigger></Triggers><Principals><Principal><UserId>S-1-5-21-1</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals><Actions><Exec><Command>C:/synthetic/php-win.exe</Command></Exec></Actions></Task>';
$xml = str_replace('<Actions>', '<Settings><AllowHardTerminate>true</AllowHardTerminate></Settings><Actions>', $xml);
ReplenishmentTaskDefinition::assertMatches($xml, str_replace(['<RunLevel>LeastPrivilege</RunLevel>', '<AllowHardTerminate>true</AllowHardTerminate>'], '', $xml));
expect(true)->toBeTrue();
foreach ([str_replace('LeastPrivilege', 'HighestAvailable', $xml), str_replace('PT1M', 'PT5M', $xml), str_replace('S-1-5-21-1', 'S-1-5-18', $xml), str_replace('<AllowHardTerminate>true', '<AllowHardTerminate>false', $xml)] as $changed) {
expect(fn () => ReplenishmentTaskDefinition::assertMatches($xml, $changed))->toThrow(LogicException::class);
}
});