You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/tests/CloudAgentOperationReposito...

85 lines
4.0 KiB
PHP

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
// Static contract test: PHP is not available in this development shell, so
// keep this check independent of Composer/DB while still making the CAS
// boundary reviewable in CI.
$root = dirname(__DIR__);
$repository = file_get_contents($root . '/app/Services/Cloud/CloudAgentOperationRepository.php');
$model = file_get_contents($root . '/app/Models/CloudAgentOperation.php');
$claim = file_get_contents($root . '/app/Services/Cloud/CloudAgentOperationClaim.php');
$exception = file_get_contents($root . '/app/Services/Cloud/CloudAgentOperationException.php');
$schema = file_get_contents($root . '/sql/cloud_agent_v1.sql');
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
foreach (['repository' => $repository, 'model' => $model, 'claim' => $claim, 'exception' => $exception, 'schema' => $schema] as $name => $source) {
$assert(is_string($source) && $source !== '', 'Missing Agent operation ' . $name . ' source.');
}
$assert(str_contains($model, "cloud_agent_operations")
&& str_contains($model, "desired_json")
&& str_contains($model, "lease_owner"),
'CloudAgentOperation model lost the fresh journal mapping.');
$assert(str_contains($repository, "private const TABLE = 'cloud_agent_operations'")
&& str_contains($repository, "function reserve")
&& str_contains($repository, "function claim")
&& str_contains($repository, "function finalize")
&& str_contains($repository, "function setCommitBoundary")
&& str_contains($repository, "function renew")
&& str_contains($repository, "function markUncertain")
&& str_contains($repository, "function get"),
'Agent operation repository is missing a required state transition.');
foreach ([
"->where('version'",
"->where('status'",
"->where('lease_owner'",
"->where('lease_expires_at'",
"'attempt_count' =>",
"'version' =>",
"lockForUpdate()",
'if ((int) $updated !== 1)',
"lease_lost",
"lease_expired",
"ä¸<EFBFBD>确定æ“<EFBFBD>作ç¦<EFBFBD>æ­¢é‡<EFBFBD>æ–°æ´¾å<EFBFBD>‘",
] as $required) {
$assert(str_contains($repository, $required),
'Agent repository lost CAS/lease guard: ' . $required);
}
$assert(str_contains($claim, 'must not be serialized')
&& str_contains($claim, '__unserialize')
&& str_contains($claim, 'dispatch\' && $this->status === \'running')
&& str_contains($claim, 'reconcile\' && $this->status === \'uncertain'),
'Agent operation claim can cross a queue serialization boundary.');
$assert(str_contains($exception, 'public readonly string $errorCode')
&& !str_contains($exception, 'public readonly string $code'),
'Agent operation exception must not redeclare Exception::$code.');
$assert(str_contains($repository, 'array_is_list($input[\'desired\'])')
&& str_contains($repository, 'validJsonKey')
&& str_contains($repository, 'isDigestValue')
&& str_contains($repository, "\$trimmed[0] !== '{'")
&& str_contains($repository, 'array_is_list($decoded)')
&& str_contains($repository, 'array_is_list($result) || $result === []')
&& str_contains($repository, 'if ($value === null)')
&& str_contains($repository, "Agent æ“<C3A6>作 JSON 内容已æ<C2B2>Ÿå<C5B8><C3A5>")
&& !str_contains($repository, "if (!is_string(\$value) || \$value === '') {\n return [];")
&& str_contains($repository, 'æˆ<C3A6>功æ“<C3A6>作必须有宿主 commit boundary'),
'Agent operation desired/result JSON needs an object and key-shape boundary.');
$assert(str_contains($schema, 'version BIGINT UNSIGNED NOT NULL DEFAULT 1')
&& str_contains($schema, 'attempt_count INT UNSIGNED')
&& str_contains($schema, 'lease_owner VARCHAR(96)')
&& str_contains($schema, 'lease_expires_at BIGINT UNSIGNED'),
'Fresh schema lacks operation CAS/lease columns.');
foreach (['CloudJob', 'CloudEngineClient', 'ssh', 'curl_exec', 'shell_exec', 'CloudSecrets'] as $forbidden) {
$assert(!str_contains($repository, $forbidden),
'Fresh Agent repository crossed a legacy/transport boundary: ' . $forbidden);
}
echo "Cloud Agent operation repository contract checks passed.\n";