-
Notifications
You must be signed in to change notification settings - Fork 5
feat: report resources requested without their prerequisites #226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9c35ba5
c8bf05a
df77d69
331e7a9
b706748
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Tests\Unit\General; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Utopia\Migration\Resource; | ||
| use Utopia\Migration\Resources\Auth\Membership; | ||
| use Utopia\Migration\Resources\Auth\Team; | ||
| use Utopia\Migration\Resources\Auth\User; | ||
| use Utopia\Migration\Transfer; | ||
| use Utopia\Tests\Unit\Adapters\MockDestination; | ||
| use Utopia\Tests\Unit\Adapters\MockSource; | ||
|
|
||
| /** | ||
| * A resource requested without its prerequisites cannot be transferred: its | ||
| * exporter walks a cache the missing prerequisite never filled, or is only | ||
| * reached by the prerequisite's own exporter. Nothing throws, so without this | ||
| * check the transfer finishes reporting success having moved nothing. | ||
| */ | ||
| class ResourceDependenciesTest extends TestCase | ||
| { | ||
| protected Transfer $transfer; | ||
|
|
||
| protected MockSource $source; | ||
|
|
||
| protected MockDestination $destination; | ||
|
|
||
| public function setup(): void | ||
| { | ||
| $this->source = new MockSource(); | ||
| $this->destination = new MockDestination(); | ||
|
|
||
| $this->transfer = new Transfer( | ||
| $this->source, | ||
| $this->destination | ||
| ); | ||
|
|
||
| $this->source->setResourceDependencies([ | ||
| Resource::TYPE_MEMBERSHIP => [Resource::TYPE_USER, Resource::TYPE_TEAM], | ||
| ]); | ||
|
Comment on lines
+38
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These tests inject the exact membership prerequisites that the production Appwrite source is supposed to declare. A typo, omission, or incorrect Appwrite declaration therefore leaves every test green; the real declaration is never exercised. This violates the repository directive to test observable behavior instead of mirroring source code or configuration in assertions. Replace this setup with coverage that consumes Appwrite's actual dependency declarations. This repository requirement must be satisfied before merging. Context Used: Call out and harshly judge implementation-coupled ... (source) Prompt To Fix With AIThis is a comment left during a code review.
Path: tests/Migration/Unit/General/ResourceDependenciesTest.php
Line: 38-40
Comment:
**Tests mirror dependency configuration**
These tests inject the exact membership prerequisites that the production Appwrite source is supposed to declare. A typo, omission, or incorrect Appwrite declaration therefore leaves every test green; the real declaration is never exercised. This violates the repository directive to test observable behavior instead of mirroring source code or configuration in assertions. Replace this setup with coverage that consumes Appwrite's actual dependency declarations. This repository requirement must be satisfied before merging.
**Context Used:** Call out and harshly judge implementation-coupled ... ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| $team = new Team('team', 'Team'); | ||
| $user = new User('user', 'user@example.com'); | ||
|
|
||
| $this->source->pushMockResource($team); | ||
| $this->source->pushMockResource($user); | ||
| $this->source->pushMockResource(new Membership('membership', $team, $user)); | ||
| } | ||
|
|
||
| public function testMissingPrerequisitesAreReported(): void | ||
| { | ||
| $this->transfer->run([Resource::TYPE_MEMBERSHIP], function () { | ||
| }); | ||
|
|
||
| $errors = $this->source->getErrors(); | ||
|
|
||
| $this->assertCount(1, $errors); | ||
| $this->assertSame(Resource::TYPE_MEMBERSHIP, $errors[0]->getResourceName()); | ||
| $this->assertSame( | ||
| 'Cannot transfer membership without user and team.', | ||
| $errors[0]->getMessage() | ||
| ); | ||
| } | ||
|
|
||
| public function testOnlyTheAbsentPrerequisitesAreNamed(): void | ||
| { | ||
| $this->transfer->run( | ||
| [Resource::TYPE_USER, Resource::TYPE_MEMBERSHIP], | ||
| function () { | ||
| } | ||
| ); | ||
|
|
||
| $errors = $this->source->getErrors(); | ||
|
|
||
| $this->assertCount(1, $errors); | ||
| $this->assertSame( | ||
| 'Cannot transfer membership without team.', | ||
| $errors[0]->getMessage() | ||
| ); | ||
| } | ||
|
|
||
| public function testASatisfiedRequestIsNotReported(): void | ||
| { | ||
| $this->transfer->run( | ||
| [Resource::TYPE_USER, Resource::TYPE_TEAM, Resource::TYPE_MEMBERSHIP], | ||
| function () { | ||
| } | ||
| ); | ||
|
|
||
| $this->assertEmpty($this->source->getErrors()); | ||
| } | ||
|
|
||
| public function testAResourceWithNoPrerequisitesIsNotReported(): void | ||
| { | ||
| $this->transfer->run([Resource::TYPE_USER], function () { | ||
| }); | ||
|
|
||
| $this->assertEmpty($this->source->getErrors()); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The declaration deliberately omits
index,collection,attribute, anddocument, leaving the silent-success defect incomplete. These are requestable resources whose exporters depend on caches populated by their database or entity exporters. For example, requestingindexwithouttableorcollectionmakesexportIndexes()iterate an empty entity cache, transfer nothing, and record no dependency error. The dependency model needs to support valid alternative parents instead of exempting these resources from validation.Prompt To Fix With AI