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

540 lines
24 KiB
PHP

<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Models\User;
use App\Services\UserDataDeletionService;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Schema\Blueprint;
$System_Config = ['enable_log' => 'false'];
if (!defined('BASE_PATH')) {
define('BASE_PATH', sys_get_temp_dir() . '/virt-cloud-account-delete-test-' . bin2hex(random_bytes(6)));
}
$attachmentDirectory = BASE_PATH . '/storage/ticket-attachments';
if (!mkdir($attachmentDirectory, 0700, true) && !is_dir($attachmentDirectory)) {
throw new RuntimeException('Could not create account deletion attachment fixture directory.');
}
$assert = static function ($condition, $message) {
if (!$condition) {
throw new RuntimeException($message);
}
};
$capsule = new Capsule();
$capsule->addConnection(['driver' => 'sqlite', 'database' => ':memory:'], 'default');
$capsule->setAsGlobal();
$capsule->bootEloquent();
$schema = $capsule->getConnection('default')->getSchemaBuilder();
$schema->create('user', static function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->boolean('is_admin')->default(false);
$table->integer('login_session_version')->default(0);
$table->integer('ref_by')->default(0);
});
$schema->create('ticket', static function (Blueprint $table) {
$table->increments('id');
$table->integer('userid');
$table->integer('rootid')->default(0);
});
$schema->create('ticket_attachments', static function (Blueprint $table) {
$table->increments('id');
$table->integer('ticket_id');
$table->integer('message_id');
$table->integer('user_id');
$table->string('storage_key');
});
$schema->create('ticket_telegram_deliveries', static function (Blueprint $table) {
$table->increments('id');
$table->integer('ticket_id');
$table->integer('bound_admin_id');
});
$schema->create('yipay_orders', static function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->string('order_no')->unique();
});
foreach (['yipay_callback_events', 'yipay_refunds'] as $tableName) {
$schema->create($tableName, static function (Blueprint $table) {
$table->increments('id');
$table->string('order_no');
});
}
$schema->create('cloud_instances', static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id'); $table->string('status');
});
$schema->create('cloud_orders', static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id'); $table->string('status');
});
$schema->create('cloud_jobs', static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id');
$table->integer('order_id')->nullable();
$table->integer('instance_id')->nullable();
$table->integer('snapshot_id')->nullable();
$table->string('kind')->nullable();
$table->string('execution_mode')->default('agent');
$table->string('phase')->default('terminal');
$table->string('outcome')->nullable()->default('succeeded');
$table->string('status')->default('succeeded');
$table->boolean('effect_may_have_applied')->default(false);
$table->boolean('safe_to_resubmit')->default(false);
$table->string('effect_resolution')->default('not_applicable');
$table->boolean('finalization_incident')->default(0);
$table->string('finalization_error_code')->nullable();
$table->text('sealed_payload')->nullable();
});
$schema->create('cloud_instance_snapshots', static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id');
$table->integer('instance_id');
});
$schema->create('cloud_instance_firewalls', static function (Blueprint $table) {
$table->integer('instance_id')->primary(); $table->integer('user_id');
});
$schema->create('cloud_instance_firewall_versions', static function (Blueprint $table) {
$table->increments('id'); $table->integer('instance_id');
});
$schema->create('cloud_instance_firewall_rules', static function (Blueprint $table) {
$table->increments('id'); $table->integer('version_id');
});
foreach (['cloud_service_periods', 'cloud_renewals'] as $tableName) {
$schema->create($tableName, static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id');
});
}
$schema->create('cloud_backup_period_entitlements', static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id');
});
foreach (['cloud_instance_network_restrictions',
'cloud_traffic_instance_cursors', 'cloud_traffic_ledger_events',
'cloud_traffic_entitlements', 'cloud_traffic_pools'] as $tableName) {
$schema->create($tableName, static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id');
});
}
$schema->create('cloud_traffic_scan_failures', static function (Blueprint $table) {
$table->increments('id'); $table->string('scan_kind');
$table->integer('subject_id');
});
$schema->create('cloud_invoices', static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id');
});
$schema->create('cloud_invoice_payments', static function (Blueprint $table) {
$table->increments('id'); $table->integer('user_id'); $table->string('status');
});
$schema->create('cloud_mail_outbox', static function (Blueprint $table) {
$table->increments('id'); $table->integer('invoice_id');
});
$schema->create('cloud_service_compensations', static function (Blueprint $table) {
$table->increments('id'); $table->integer('requested_by_user_id');
$table->string('state'); $table->string('scope_type')->nullable();
$table->integer('scope_id')->nullable();
$table->text('scope_snapshot_json')->nullable();
});
$schema->create('cloud_service_compensation_items', static function (Blueprint $table) {
$table->increments('id'); $table->integer('batch_id');
$table->integer('user_id'); $table->string('state');
});
$schema->create('cloud_service_compensation_recipients', static function (Blueprint $table) {
$table->increments('id'); $table->integer('batch_id');
$table->integer('user_id'); $table->string('status');
});
$schema->create('email_verify', static function (Blueprint $table) {
$table->increments('id');
$table->string('email');
});
$schema->create('configurations', static function (Blueprint $table) {
$table->increments('id');
$table->string('name')->unique();
$table->text('value');
});
Capsule::table('user')->insert([
['id' => 1, 'email' => 'deleted@example.com', 'is_admin' => 0, 'ref_by' => 0],
['id' => 2, 'email' => 'admin@example.com', 'is_admin' => 1, 'ref_by' => 0],
['id' => 3, 'email' => 'other@example.com', 'is_admin' => 0, 'ref_by' => 1],
]);
Capsule::table('ticket')->insert([
['id' => 10, 'userid' => 1, 'rootid' => 0],
['id' => 11, 'userid' => 2, 'rootid' => 10],
['id' => 20, 'userid' => 3, 'rootid' => 0],
]);
$attachmentFiles = [
'deleted-user.png' => 'deleted user attachment',
'deleted-admin-reply.png' => 'administrator reply attachment',
'retained-user.png' => 'retained user attachment',
];
foreach ($attachmentFiles as $storageKey => $contents) {
if (file_put_contents($attachmentDirectory . '/' . $storageKey, $contents) === false) {
throw new RuntimeException('Could not create ticket attachment fixture.');
}
}
Capsule::table('ticket_attachments')->insert([
['id' => 1, 'ticket_id' => 10, 'message_id' => 10, 'user_id' => 1,
'storage_key' => 'deleted-user.png'],
['id' => 2, 'ticket_id' => 10, 'message_id' => 11, 'user_id' => 2,
'storage_key' => 'deleted-admin-reply.png'],
['id' => 3, 'ticket_id' => 20, 'message_id' => 20, 'user_id' => 3,
'storage_key' => 'retained-user.png'],
]);
Capsule::table('ticket_telegram_deliveries')->insert([
['id' => 1, 'ticket_id' => 10, 'bound_admin_id' => 2],
['id' => 2, 'ticket_id' => 20, 'bound_admin_id' => 2],
]);
Capsule::table('yipay_orders')->insert([
['user_id' => 1, 'order_no' => 'deleted-order'],
['user_id' => 3, 'order_no' => 'retained-order'],
]);
foreach (['yipay_callback_events', 'yipay_refunds'] as $tableName) {
Capsule::table($tableName)->insert([
['order_no' => 'deleted-order'], ['order_no' => 'retained-order'],
]);
}
Capsule::table('cloud_instances')->insert([
['id' => 101, 'user_id' => 1, 'status' => 'deleted'],
['id' => 301, 'user_id' => 3, 'status' => 'active'],
]);
Capsule::table('cloud_orders')->insert([
['id' => 102, 'user_id' => 1, 'status' => 'completed'],
['id' => 302, 'user_id' => 3, 'status' => 'completed'],
]);
Capsule::table('cloud_instance_snapshots')->insert([
['id' => 104, 'user_id' => 1, 'instance_id' => 101],
['id' => 304, 'user_id' => 3, 'instance_id' => 301],
]);
Capsule::table('cloud_instance_firewalls')->insert([
['instance_id' => 101, 'user_id' => 1],
['instance_id' => 301, 'user_id' => 3],
]);
Capsule::table('cloud_instance_firewall_versions')->insert([
['id' => 106, 'instance_id' => 101],
['id' => 306, 'instance_id' => 301],
]);
Capsule::table('cloud_instance_firewall_rules')->insert([
['id' => 107, 'version_id' => 106],
['id' => 307, 'version_id' => 306],
]);
Capsule::table('cloud_jobs')->insert([
['id' => 105, 'user_id' => 1, 'instance_id' => 101,
'snapshot_id' => 104, 'sealed_payload' => 'owner-job'],
['id' => 205, 'user_id' => 2, 'instance_id' => 101,
'snapshot_id' => 104, 'sealed_payload' => 'delegated-admin-job'],
['id' => 206, 'user_id' => 2, 'instance_id' => null,
'snapshot_id' => null, 'sealed_payload' => 'unrelated-admin-job'],
['id' => 305, 'user_id' => 3, 'instance_id' => 301,
'snapshot_id' => 304, 'sealed_payload' => 'other-user-job'],
]);
foreach (['cloud_service_periods', 'cloud_renewals'] as $tableName) {
Capsule::table($tableName)->insert([
['user_id' => 1], ['user_id' => 3],
]);
}
Capsule::table('cloud_backup_period_entitlements')->insert([
['user_id' => 1], ['user_id' => 3],
]);
foreach (['cloud_instance_network_restrictions',
'cloud_traffic_instance_cursors', 'cloud_traffic_ledger_events',
'cloud_traffic_entitlements', 'cloud_traffic_pools'] as $tableName) {
Capsule::table($tableName)->insert([
['user_id' => 1], ['user_id' => 3],
]);
}
Capsule::table('cloud_traffic_scan_failures')->insert([
['scan_kind' => 'instance', 'subject_id' => 101],
['scan_kind' => 'instance', 'subject_id' => 301],
]);
Capsule::table('cloud_invoices')->insert([
['id' => 103, 'user_id' => 1], ['id' => 303, 'user_id' => 3],
]);
Capsule::table('cloud_invoice_payments')->insert([
['user_id' => 1, 'status' => 'paid_invoice'],
['user_id' => 3, 'status' => 'paid_invoice'],
]);
Capsule::table('cloud_mail_outbox')->insert([
['invoice_id' => 103], ['invoice_id' => 303],
]);
Capsule::table('cloud_service_compensations')->insert([
'id' => 1, 'requested_by_user_id' => 2, 'state' => 'completed',
'scope_type' => 'instance', 'scope_id' => 501,
'scope_snapshot_json' => json_encode([
'type' => 'instance', 'id' => 501, 'label' => 'tenant-secret-vm',
'instance_id' => 501, 'user_id' => 1, 'host_id' => 5,
], JSON_THROW_ON_ERROR),
]);
Capsule::table('cloud_service_compensation_items')->insert([
['id' => 1, 'batch_id' => 1, 'user_id' => 1, 'state' => 'applied'],
['id' => 2, 'batch_id' => 1, 'user_id' => 3, 'state' => 'applied'],
]);
Capsule::table('cloud_service_compensation_recipients')->insert([
['id' => 1, 'batch_id' => 1, 'user_id' => 1, 'status' => 'sent'],
['id' => 2, 'batch_id' => 1, 'user_id' => 3, 'status' => 'sent'],
]);
Capsule::table('email_verify')->insert([
['email' => 'deleted@example.com'], ['email' => 'other@example.com'],
]);
Capsule::table('configurations')->insert([
'name' => 'email_blacklist', 'value' => "deleted@example.com\n@blocked.example",
]);
$result = (new UserDataDeletionService())->deleteUsers([1, '2', 999], false);
$assert($result['deleted_user_ids'] === [1], 'Expected only the ordinary selected account to be deleted.');
$assert($result['skipped_user_ids'] === [2, 999], 'Administrator or missing account was not excluded.');
$assert(User::find(1) === null && User::find(2) !== null && User::find(3) !== null, 'User deletion was not isolated.');
$assert((int) User::find(3)->ref_by === 0, 'Deleted referrer was not cleared.');
$assert(Capsule::table('ticket')->pluck('id')->all() === [20], 'Ticket replies from the deleted thread were retained.');
$assert(Capsule::table('ticket_attachments')->pluck('id')->all() === [3],
'Ticket attachment deletion was not isolated.');
$assert(Capsule::table('ticket_telegram_deliveries')->pluck('id')->all() === [2],
'Telegram ticket delivery mapping deletion was not isolated.');
$assert(!is_file($attachmentDirectory . '/deleted-user.png')
&& !is_file($attachmentDirectory . '/deleted-admin-reply.png')
&& is_file($attachmentDirectory . '/retained-user.png'),
'Ticket attachment files were not cleaned after a committed account deletion.');
foreach (['yipay_orders', 'yipay_callback_events', 'yipay_refunds'] as $tableName) {
$assert(Capsule::table($tableName)->pluck('order_no')->all() === ['retained-order'], 'Payment relation deletion was not isolated.');
}
foreach (['cloud_instances', 'cloud_orders', 'cloud_instance_snapshots',
'cloud_instance_firewalls', 'cloud_service_periods', 'cloud_renewals',
'cloud_backup_period_entitlements', 'cloud_invoices',
'cloud_invoice_payments', 'cloud_instance_network_restrictions',
'cloud_traffic_instance_cursors', 'cloud_traffic_ledger_events',
'cloud_traffic_entitlements', 'cloud_traffic_pools'] as $tableName) {
$assert(Capsule::table($tableName)->pluck('user_id')->all() === [3],
'Cloud account history deletion was not isolated: ' . $tableName);
}
$assert(Capsule::table('cloud_traffic_scan_failures')
->pluck('subject_id')->all() === [301],
'Cloud traffic scan quarantine deletion was not isolated.');
$assert(Capsule::table('cloud_instance_firewall_versions')->pluck('id')->all()
=== [306]
&& Capsule::table('cloud_instance_firewall_rules')->pluck('id')->all()
=== [307],
'Tenant deletion orphaned or over-deleted firewall policy history.');
$assert(Capsule::table('cloud_jobs')->orderBy('id')->pluck('id')->all()
=== [206, 305],
'Tenant deletion retained delegated jobs or removed unrelated administrator jobs.');
$assert(Capsule::table('cloud_mail_outbox')->pluck('invoice_id')->all() === [303],
'Cloud invoice mail history deletion was not isolated.');
$assert(Capsule::table('cloud_service_compensations')->pluck('id')->all() === [1],
'Account deletion removed the immutable compensation batch audit.');
$retainedCompensationScope = json_decode((string) Capsule::table(
'cloud_service_compensations'
)->where('id', 1)->value('scope_snapshot_json'), true, 16,
JSON_THROW_ON_ERROR);
$assert($retainedCompensationScope === [
'type' => 'instance', 'id' => 501, 'label' => '单实例 #501',
'instance_id' => 501,
], 'Account deletion retained tenant PII in compensation batch audit.');
$assert(Capsule::table('cloud_service_compensation_items')->pluck('user_id')->all()
=== [3]
&& Capsule::table('cloud_service_compensation_recipients')
->pluck('user_id')->all() === [3],
'Compensation tenant details were not deleted in isolation.');
$assert(Capsule::table('email_verify')->pluck('email')->all() === ['other@example.com'], 'Email verification cleanup was not isolated.');
$assert(Capsule::table('configurations')->where('name', 'email_blacklist')->value('value') === "deleted@example.com\n@blocked.example", 'Manual blacklist was changed.');
$assert($result['cache_error'] === false && $result['log_rows_deleted'] === 0, 'Disabled optional services were accessed.');
Capsule::table('user')->insert([
'id' => 4, 'email' => 'payment-pending@example.com', 'is_admin' => 0, 'ref_by' => 0,
]);
Capsule::table('cloud_invoice_payments')->insert([
'user_id' => 4, 'status' => 'creation_unknown',
]);
try {
(new UserDataDeletionService())->deleteUsers([4], false);
throw new RuntimeException('Account with an unresolved payment was deleted.');
} catch (RuntimeException $error) {
$assert(str_contains($error->getMessage(), '支付安全栅栏'),
'Unresolved-payment deletion returned the wrong error.');
}
$assert(User::find(4) !== null, 'Unresolved-payment deletion was not rolled back.');
Capsule::table('user')->insert([
'id' => 5, 'email' => 'provision-invoice@example.com',
'is_admin' => 0, 'ref_by' => 0,
]);
Capsule::table('cloud_orders')->insert([
'id' => 502, 'user_id' => 5, 'status' => 'awaiting_payment',
]);
try {
(new UserDataDeletionService())->deleteUsers([5], false);
throw new RuntimeException('Account with an unpaid provisioning invoice was deleted.');
} catch (RuntimeException $error) {
$assert(str_contains($error->getMessage(), '开通中的订单'),
'Unpaid-provisioning deletion returned the wrong error.');
}
$assert(User::find(5) !== null
&& Capsule::table('cloud_orders')->where('id', 502)->exists(),
'Unpaid-provisioning deletion was not rolled back.');
Capsule::table('user')->insert([
'id' => 6, 'email' => 'provision-fenced@example.com',
'is_admin' => 0, 'ref_by' => 0,
]);
Capsule::table('cloud_orders')->insert([
'id' => 602, 'user_id' => 6, 'status' => 'failed',
]);
Capsule::table('cloud_jobs')->insert([
'id' => 605, 'user_id' => 6, 'order_id' => 602,
'instance_id' => null, 'snapshot_id' => null,
'kind' => 'create', 'execution_mode' => 'agent',
'phase' => 'terminal', 'outcome' => 'failed', 'status' => 'failed',
'effect_may_have_applied' => true, 'safe_to_resubmit' => false,
'effect_resolution' => 'unknown',
'sealed_payload' => 'unknown-effect-create-audit',
]);
try {
(new UserDataDeletionService())->deleteUsers([6], false);
throw new RuntimeException(
'Account with an unknown-effect terminal task was deleted.');
} catch (RuntimeException $error) {
$assert(str_contains($error->getMessage(), '资源安全栅栏'),
'Unknown-effect terminal task deletion returned the wrong error.');
}
$fencedJob = Capsule::table('cloud_jobs')->where('id', 605)->first();
$assert(User::find(6) !== null
&& Capsule::table('cloud_orders')->where('id', 602)
->where('status', 'failed')->exists()
&& $fencedJob !== null
&& $fencedJob->order_id === 602
&& $fencedJob->instance_id === null
&& $fencedJob->kind === 'create'
&& $fencedJob->phase === 'terminal'
&& $fencedJob->outcome === 'failed'
&& $fencedJob->status === 'failed'
&& (int) $fencedJob->effect_may_have_applied === 1
&& (int) $fencedJob->safe_to_resubmit === 0
&& $fencedJob->effect_resolution === 'unknown'
&& $fencedJob->sealed_payload === 'unknown-effect-create-audit',
'Unknown-effect terminal provisioning fence lost its order or job audit.');
Capsule::table('user')->insert([
'id' => 8, 'email' => 'compensation-applying@example.com',
'is_admin' => 0, 'ref_by' => 0,
]);
Capsule::table('cloud_service_compensations')->insert([
'id' => 2, 'requested_by_user_id' => 2, 'state' => 'applying',
]);
Capsule::table('cloud_service_compensation_items')->insert([
'id' => 8, 'batch_id' => 2, 'user_id' => 8, 'state' => 'applying',
]);
try {
(new UserDataDeletionService())->deleteUsers([8], false);
throw new RuntimeException('Account with an applying compensation was deleted.');
} catch (RuntimeException $error) {
$assert(str_contains($error->getMessage(), '进行中的实例补偿'),
'Applying-compensation deletion returned the wrong error.');
}
$assert(User::find(8) !== null
&& Capsule::table('cloud_service_compensation_items')->where('id', 8)->exists()
&& Capsule::table('cloud_service_compensations')->where('id', 2)->exists(),
'Applying-compensation deletion fence did not preserve its audit rows.');
Capsule::table('user')->insert([
'id' => 9, 'email' => 'compensation-sending@example.com',
'is_admin' => 0, 'ref_by' => 0,
]);
Capsule::table('cloud_service_compensations')->insert([
'id' => 3, 'requested_by_user_id' => 2, 'state' => 'completed',
]);
Capsule::table('cloud_service_compensation_recipients')->insert([
'id' => 9, 'batch_id' => 3, 'user_id' => 9, 'status' => 'sending',
]);
try {
(new UserDataDeletionService())->deleteUsers([9], false);
throw new RuntimeException('Account with a sending compensation notice was deleted.');
} catch (RuntimeException $error) {
$assert(str_contains($error->getMessage(), '投递中的补偿通知'),
'Sending-compensation deletion returned the wrong error.');
}
$assert(User::find(9) !== null
&& Capsule::table('cloud_service_compensation_recipients')
->where('id', 9)->exists()
&& Capsule::table('cloud_service_compensations')->where('id', 3)->exists(),
'Sending-compensation deletion fence did not preserve its audit rows.');
Capsule::table('user')->insert([
'id' => 10, 'email' => 'compensation-pending@example.com',
'is_admin' => 0, 'ref_by' => 0,
]);
Capsule::table('cloud_service_compensations')->insert([
'id' => 4, 'requested_by_user_id' => 2, 'state' => 'pending',
]);
Capsule::table('cloud_service_compensation_items')->insert([
'id' => 10, 'batch_id' => 4, 'user_id' => 10, 'state' => 'pending',
]);
try {
(new UserDataDeletionService())->deleteUsers([10], false);
throw new RuntimeException('Account in a pending compensation batch was deleted.');
} catch (RuntimeException $error) {
$assert(str_contains($error->getMessage(), '进行中的实例补偿'),
'Pending-compensation deletion returned the wrong error.');
}
$assert(User::find(10) !== null
&& Capsule::table('cloud_service_compensation_items')
->where('id', 10)->exists(),
'Pending-compensation deletion fence removed its item.');
Capsule::table('user')->insert([
'id' => 11, 'email' => 'compensation-mail-pending@example.com',
'is_admin' => 0, 'ref_by' => 0,
]);
Capsule::table('cloud_service_compensations')->insert([
'id' => 5, 'requested_by_user_id' => 2, 'state' => 'completed',
]);
Capsule::table('cloud_service_compensation_recipients')->insert([
'id' => 11, 'batch_id' => 5, 'user_id' => 11, 'status' => 'pending',
]);
$pendingMailDeletion = (new UserDataDeletionService())
->deleteUsers([11], false);
$assert($pendingMailDeletion['deleted_user_ids'] === [11]
&& User::find(11) === null
&& !Capsule::table('cloud_service_compensation_recipients')
->where('id', 11)->exists()
&& Capsule::table('cloud_service_compensations')->where('id', 5)->exists(),
'Locked pending compensation mail was not safely removed with the account.');
Capsule::table('user')->insert([
'id' => 7, 'email' => 'rollback-attachment@example.com',
'is_admin' => 0, 'ref_by' => 0,
]);
Capsule::table('ticket')->insert([
'id' => 70, 'userid' => 7, 'rootid' => 0,
]);
Capsule::table('ticket_attachments')->insert([
'id' => 7, 'ticket_id' => 70, 'message_id' => 70, 'user_id' => 7,
'storage_key' => 'rollback-user.png',
]);
Capsule::table('ticket_telegram_deliveries')->insert([
'id' => 7, 'ticket_id' => 70, 'bound_admin_id' => 2,
]);
$rollbackAttachment = $attachmentDirectory . '/rollback-user.png';
if (file_put_contents($rollbackAttachment, 'rollback attachment') === false) {
throw new RuntimeException('Could not create rollback attachment fixture.');
}
Capsule::statement(
"CREATE TRIGGER prevent_user_7_delete BEFORE DELETE ON user "
. "WHEN OLD.id = 7 BEGIN SELECT RAISE(ABORT, 'forced user deletion failure'); END"
);
try {
(new UserDataDeletionService())->deleteUsers([7], false);
throw new RuntimeException('Forced account deletion failure did not abort.');
} catch (Throwable $error) {
$assert(str_contains($error->getMessage(), 'forced user deletion failure'),
'Forced account deletion returned the wrong error.');
}
$assert(User::find(7) !== null
&& Capsule::table('ticket')->where('id', 70)->exists()
&& Capsule::table('ticket_attachments')->where('id', 7)->exists()
&& Capsule::table('ticket_telegram_deliveries')->where('id', 7)->exists(),
'Database rows did not roll back after the forced account deletion failure.');
$assert(is_file($rollbackAttachment),
'Ticket attachment file was deleted before the account transaction committed.');
Capsule::statement('DROP TRIGGER prevent_user_7_delete');
@unlink($rollbackAttachment);
@unlink($attachmentDirectory . '/retained-user.png');
@rmdir($attachmentDirectory);
@rmdir(BASE_PATH . '/storage');
@rmdir(BASE_PATH);
echo 'Manual account deletion SQLite checks passed.' . PHP_EOL;