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/CloudAgentSchemaContractTes...

59 lines
2.0 KiB
PHP

<?php
// The Go Agent control plane owns a fresh schema. This static contract keeps
// an accidental "migration" back to Python-engine/cipher columns from being
// introduced while the panel and agent are developed independently.
$root = dirname(__DIR__);
$schemaPath = $root . '/sql/cloud_agent_v1.sql';
$schema = file_get_contents($schemaPath);
if ($schema === false) {
throw new RuntimeException('Go Agent schema is missing or unreadable.');
}
$assert = static function ($condition, string $message): void {
if (!$condition) {
throw new RuntimeException($message);
}
};
$withoutComments = preg_replace('/^\s*--.*$/m', '', $schema);
$assert(is_string($withoutComments), 'Unable to strip SQL comments for the schema contract.');
foreach ([
'CREATE TABLE cloud_agents',
'CREATE TABLE cloud_agent_client_certificates',
'CREATE TABLE cloud_agent_operations',
'CREATE TABLE cloud_agent_instance_state',
'CREATE TABLE cloud_agent_artifacts',
'CREATE TABLE cloud_agent_schema_meta',
'virt-cloud-agent',
'schema_fingerprint CHAR(64)',
'UNIQUE KEY cloud_agent_operation_idempotency',
'desired_json JSON NOT NULL',
'observed_json JSON NULL',
'secret_ref VARCHAR(128)',
'client_certificate_fingerprint CHAR(64)',
] as $required) {
$assert(str_contains($withoutComments, $required),
'Go Agent schema lost required greenfield contract: ' . $required);
}
// These are implementation markers for the retired Python engine, not fields
// that may appear in the new control-plane schema. Comments are excluded so
// the explanatory boundary text can still mention why compatibility is not
// provided.
foreach ([
'engine_records',
'engine_jobs',
'public_key_cipher',
'private_key_cipher',
'password_cipher',
'secret_cipher',
] as $forbidden) {
$assert(!str_contains($withoutComments, $forbidden),
'Greenfield Go Agent schema unexpectedly contains a legacy field/table: ' . $forbidden);
}
echo "Go Agent greenfield schema contract passed.\n";