-
Notifications
You must be signed in to change notification settings - Fork 2
fix(media-uploads): null private_url for missing Dropbox files and backoff for pending upload retries #601
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
Draft
smarcet
wants to merge
2
commits into
main
Choose a base branch
from
fix/pending-media-upload-retry-and-private-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| <?php namespace Tests\Unit\Services; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Services\FileSystem\Dropbox\DropboxAdapter; | ||
| use GuzzleHttp\Psr7\Response; | ||
| use Illuminate\Container\Container; | ||
| use Illuminate\Support\Facades\Facade; | ||
| use Mockery; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Psr\Log\NullLogger; | ||
| use Spatie\Dropbox\Client as DropboxClient; | ||
| use Spatie\Dropbox\Exceptions\BadRequest; | ||
|
|
||
| /** | ||
| * Class DropboxAdapterGetUrlTest | ||
| * | ||
| * Unit tests for {@see DropboxAdapter::getUrl()}: the value handed to | ||
| * PresentationMediaUpload serializers as `private_url`. | ||
| * | ||
| * @package Tests\Unit\Services | ||
| */ | ||
| class DropboxAdapterGetUrlTest extends TestCase | ||
| { | ||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| // Minimal facade application so Log:: calls in the SUT resolve | ||
| // without a full Laravel app (same setup as ProcessPendingMediaUploadsTest). | ||
| Facade::clearResolvedInstances(); | ||
| $app = new Container(); | ||
| $app->singleton('log', fn() => new NullLogger()); | ||
| Container::setInstance($app); | ||
| Facade::setFacadeApplication($app); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| Facade::setFacadeApplication(null); | ||
| Facade::clearResolvedInstances(); | ||
| Container::setInstance(null); | ||
| Mockery::close(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| /** | ||
| * The file never reached Dropbox (e.g. the pending upload failed), so | ||
| * sharing/create_shared_link_with_settings answers path/not_found. | ||
| * The adapter must report "no link" as an empty string (the parent declares getUrl(): string, | ||
| * so null is not allowed), never as a placeholder like "#" | ||
| * that clients would treat as a real URL. AbstractFileDownloadStrategy turns it into null. | ||
| */ | ||
| public function testGetUrlReturnsEmptyStringWhenSharedLinkCannotBeCreated(): void | ||
| { | ||
| $path = 'PresentationMediaUploads/Private/73/9121/missing.pptx'; | ||
|
|
||
| $client = Mockery::mock(DropboxClient::class); | ||
| $client->shouldReceive('createSharedLinkWithSettings') | ||
| ->once() | ||
| ->with($path) | ||
| ->andThrow(new BadRequest(new Response(409, [], json_encode([ | ||
| 'error_summary' => 'path/not_found/', | ||
| 'error' => ['.tag' => 'path', 'path' => ['.tag' => 'not_found']], | ||
| ])))); | ||
| $client->shouldNotReceive('listSharedLinks'); | ||
|
|
||
| $adapter = new DropboxAdapter($client); | ||
|
|
||
| $this->assertSame('', $adapter->getUrl($path)); | ||
| } | ||
|
|
||
| /** | ||
| * Anti-regression: when Dropbox creates the shared link, its URL is returned as-is. | ||
| */ | ||
| public function testGetUrlReturnsSharedLinkUrlOnSuccess(): void | ||
| { | ||
| $path = 'PresentationMediaUploads/Private/73/9082/deck.pptx'; | ||
| $url = 'https://www.dropbox.com/scl/fi/abc123/deck.pptx?dl=0'; | ||
|
|
||
| $client = Mockery::mock(DropboxClient::class); | ||
| $client->shouldReceive('createSharedLinkWithSettings') | ||
| ->once() | ||
| ->with($path) | ||
| ->andReturn(['url' => $url]); | ||
|
|
||
| $adapter = new DropboxAdapter($client); | ||
|
|
||
| $this->assertSame($url, $adapter->getUrl($path)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| <?php namespace Tests\Unit\Services; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use App\Services\FileSystem\Dropbox\DropboxStorageFileDownloadStrategy; | ||
| use Illuminate\Container\Container; | ||
| use Illuminate\Support\Facades\Facade; | ||
| use Mockery; | ||
| use Mockery\MockInterface; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Psr\Log\NullLogger; | ||
|
|
||
| /** | ||
| * Class FileDownloadStrategyGetUrlTest | ||
| * | ||
| * Unit tests for {@see \App\Services\FileSystem\AbstractFileDownloadStrategy::getUrl()} | ||
| * through the Dropbox strategy: the value serializers expose as `private_url`. | ||
| * | ||
| * @package Tests\Unit\Services | ||
| */ | ||
| class FileDownloadStrategyGetUrlTest extends TestCase | ||
| { | ||
| /** @var MockInterface */ | ||
| private $cache; | ||
|
|
||
| /** @var MockInterface */ | ||
| private $filesystem; | ||
|
|
||
| /** @var MockInterface */ | ||
| private $config; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| // Minimal facade application: Log -> NullLogger, Cache / Storage / Config -> mocks. | ||
| Facade::clearResolvedInstances(); | ||
| $app = new Container(); | ||
| $app->singleton('log', fn() => new NullLogger()); | ||
| $this->cache = Mockery::mock(); | ||
| $this->filesystem = Mockery::mock(); | ||
| $this->config = Mockery::mock(); | ||
| $app->instance('cache', $this->cache); | ||
| $app->instance('filesystem', $this->filesystem); | ||
| $app->instance('config', $this->config); | ||
| Container::setInstance($app); | ||
| Facade::setFacadeApplication($app); | ||
| } | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| Facade::setFacadeApplication(null); | ||
| Facade::clearResolvedInstances(); | ||
| Container::setInstance(null); | ||
| Mockery::close(); | ||
| parent::tearDown(); | ||
| } | ||
|
|
||
| /** | ||
| * The Dropbox adapter reports "no link" as an empty string (its parent forbids null). | ||
| * The strategy must hand serializers null, and must not cache the miss. | ||
| */ | ||
| public function testGetUrlReturnsNullAndDoesNotCacheWhenDiskHasNoUrl(): void | ||
| { | ||
| $path = 'PresentationMediaUploads/Private/73/9121/missing.pptx'; | ||
|
|
||
| $disk = Mockery::mock(); | ||
| $disk->shouldReceive('url')->once()->with($path)->andReturn(''); | ||
| $this->filesystem->shouldReceive('disk')->with('dropbox')->andReturn($disk); | ||
| $this->cache->shouldReceive('get')->once()->andReturn(null); | ||
| $this->cache->shouldNotReceive('add'); | ||
|
|
||
| $strategy = new DropboxStorageFileDownloadStrategy(); | ||
|
|
||
| $this->assertNull($strategy->getUrl($path)); | ||
| } | ||
|
|
||
| /** | ||
| * Anti-regression: a real URL is returned and cached for the configured lifetime. | ||
| */ | ||
| public function testGetUrlReturnsAndCachesDiskUrl(): void | ||
| { | ||
| $path = 'PresentationMediaUploads/Private/73/9082/deck.pptx'; | ||
| $url = 'https://www.dropbox.com/scl/fi/abc123/deck.pptx?dl=0'; | ||
|
|
||
| $disk = Mockery::mock(); | ||
| $disk->shouldReceive('url')->once()->with($path)->andReturn($url); | ||
| $this->filesystem->shouldReceive('disk')->with('dropbox')->andReturn($disk); | ||
| $this->cache->shouldReceive('get')->once()->andReturn(null); | ||
| $this->config->shouldReceive('get')->with('cache_api_response.file_url_lifetime', 3600)->andReturn(3600); | ||
| $this->cache->shouldReceive('add')->once()->with(Mockery::type('string'), $url, 3600); | ||
|
|
||
| $strategy = new DropboxStorageFileDownloadStrategy(); | ||
|
|
||
| $this->assertSame($url, $strategy->getUrl($path)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Capture and restore the pending-upload checkpoint before setting
Processing.processPendingMediaUploadssetsSTATUS_PROCESSINGbefore reading$currentStatus.DoctrinePendingMediaUploadRepository::getPendingUploads()excludesProcessing, so a non-exhausted failure before the next checkpoint leaves the row unselectable untilresetStuckProcessingRows(10)resets it. The assignment also changes partial rows toProcessing, which can repeat completed storage phases. Save the checkpoint first, use it for phase selection, update it after each successful phase, and restore it on retryable failure. Add regressions for failures before public storage and after public storage succeeds but private storage fails.🤖 Prompt for AI Agents