Fix custom-domains E2E: assert WARNING for same-server domain conflict

This commit is contained in:
Prem Palanisamy
2026-05-21 12:37:51 +01:00
parent bb1f2d4998
commit 23a54b3c41
@@ -3058,6 +3058,20 @@ trait MigrationsBase
'x-appwrite-key' => $this->getDestinationProject()['apiKey'],
];
// Domains are globally unique across projects; orphans from prior failed runs
// poison both source list+report (returns extra rules) and destination create
// (409 conflict). Sweep both before creating the new rule.
foreach ([$sourceHeaders, $destinationHeaders] as $headers) {
$existing = $this->client->call(Client::METHOD_GET, '/proxy/rules', $headers);
if ($existing['headers']['status-code'] === 200) {
foreach ($existing['body']['rules'] ?? [] as $r) {
if (\str_ends_with($r['domain'] ?? '', '-migration-api.myapp.com')) {
$this->client->call(Client::METHOD_DELETE, '/proxy/rules/' . $r['$id'], $headers);
}
}
}
}
// Unique domain so re-runs and parallel suites can't collide on the
// global domain uniqueness check.
$domain = \uniqid() . '-migration-api.myapp.com';
@@ -3082,28 +3096,15 @@ trait MigrationsBase
$this->assertArrayHasKey(Resource::TYPE_RULE, $result['statusCounters']);
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_RULE]['error']);
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_RULE]['pending']);
$this->assertGreaterThanOrEqual(1, $result['statusCounters'][Resource::TYPE_RULE]['success']);
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_RULE]['processing']);
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_RULE]['warning']);
$listResp = $this->client->call(Client::METHOD_GET, '/proxy/rules', $destinationHeaders);
$this->assertEquals(200, $listResp['headers']['status-code']);
$foundRule = null;
foreach ($listResp['body']['rules'] as $r) {
if ($r['domain'] === $domain) {
$foundRule = $r;
break;
}
}
$this->assertNotNull($foundRule, 'Migrated rule not found on destination');
$this->assertEquals($domain, $foundRule['domain']);
$this->assertEquals('api', $foundRule['type']);
$this->assertEquals('manual', $foundRule['trigger']);
// Cleanup on destination
$this->client->call(Client::METHOD_DELETE, '/proxy/rules/' . $foundRule['$id'], $destinationHeaders);
// Domain uniqueness is enforced globally across projects. In this single-server
// E2E setup the source project still owns the domain when the migration runs,
// so the destination create hits the cross-project 409 — the destination must
// surface a WARNING, not a hard error, so the rest of the migration continues.
// (In a real self-hosted-to-cloud migration the source domain is on a separate
// server, so this conflict does not occur and we'd see `success` instead.)
$this->assertEquals(0, $result['statusCounters'][Resource::TYPE_RULE]['success']);
$this->assertGreaterThanOrEqual(1, $result['statusCounters'][Resource::TYPE_RULE]['warning']);
// Cleanup on source
$this->client->call(Client::METHOD_DELETE, '/proxy/rules/' . $sourceRule['$id'], $sourceHeaders);