From 34259fe66046a73229241bea3ed2a7f88eb008cf Mon Sep 17 00:00:00 2001 From: codex Date: Sat, 31 Oct 2026 05:45:53 +0800 Subject: [PATCH] test(admin): lock object storage operations contract --- ...oudObjectStorageOperationsContractTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 web/tests/CloudObjectStorageOperationsContractTest.php diff --git a/web/tests/CloudObjectStorageOperationsContractTest.php b/web/tests/CloudObjectStorageOperationsContractTest.php new file mode 100644 index 00000000..58d5cf2e --- /dev/null +++ b/web/tests/CloudObjectStorageOperationsContractTest.php @@ -0,0 +1,81 @@ + 'save', 'test' => 'test', 'disable' => 'disable'] as $path => $action) { + $assert(str_contains($routes, + "post('/object-storage/{$path}', 'App\\Controllers\\Admin\\ObjectStorageController:{$action}')->add(new SuperAdmin())"), + 'Object-storage mutation route lost its SuperAdmin gate: ' . $action); +} +$assert(str_contains($routes, + "post('/object-storage/cleanup-debts/{backup_id:[0-9]+}/retry', 'App\\Controllers\\Admin\\ObjectStorageController:retryCleanup')->add(new SuperAdmin())"), + 'Cleanup-debt retry lost its SuperAdmin gate.'); + +$publicState = preg_match( + '/private static function publicState\\(array \\$raw\\): array[\\s\\S]*?(?=\\n private static function )/', + $config, + $publicStateMatch +) === 1 ? $publicStateMatch[0] : ''; +$assert($publicState !== '' + && str_contains($publicState, "'credentials_configured'") + && str_contains($publicState, "'tested_revision'") + && !str_contains($publicState, "'sealed_credentials' =>") + && !str_contains($publicState, "'access_key_id' =>") + && !str_contains($publicState, "'secret_access_key' =>"), + 'Browser-visible object-storage state may expose credentials or lost readiness metadata.'); + +$save = $method($config, 'save', 'testAndEnable'); +$test = $method($config, 'testAndEnable', 'disable'); +$disable = $method($config, 'disable', 'runtime'); +$assert(str_contains($save, "'expected_revision'") + && str_contains($save, 'lockForUpdate()') + && str_contains($save, 'invalidateReadiness()'), + 'Saving object storage must remain revision-locked and invalidate readiness.'); +$assert(str_contains($test, 'headBucket(') + && str_contains($test, "self::set('tested_revision', (string) \$expected)") + && str_contains($test, "self::set('enabled', 'true')"), + 'Connection validation must remain read-only and enable the tested revision only.'); +$assert(str_contains($disable, 'lockForUpdate()') + && str_contains($disable, "self::set('enabled', 'false')") + && !str_contains($disable, "self::set('sealed_credentials'"), + 'Disabling object storage must preserve encrypted credentials.'); + +$cleanupDebt = $method($backups, 'cleanupDebt', 'retryCleanup'); +$retryCleanup = $method($backups, 'retryCleanup', 'create'); +$assert(str_contains($cleanupDebt, "'next_check_at'") + && str_contains($cleanupDebt, "'attention_at'") + && str_contains($cleanupDebt, "'can_retry'") + && !str_contains($cleanupDebt, "'object_key'") + && !str_contains($cleanupDebt, "'object_version_id'"), + 'Cleanup-debt view must expose scheduling metadata without remote object identity.'); +$assert(str_contains($retryCleanup, 'inspectObject(') + && str_contains($retryCleanup, "'delete_uncertain'") + && str_contains($retryCleanup, 'manual_retry_awaiting_stable_probe') + && !str_contains($retryCleanup, 'deleteObject('), + 'Manual cleanup retry must restart stable inspection without replaying DELETE.'); + +echo "Object-storage operations and cleanup safety contract passed.\n";