Repository navigation
fix(bb-file-bucket): reconcile current files after version deletion - #693
Conversation
🦋 Changeset detectedLatest commit: 46fdd5a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
belaboe
left a comment
There was a problem hiding this comment.
Thanks, verified red->green (8/34 new tests fail on main, all pass at head) and the S3 cases: deleting the newest version exposes the previous one in get/scan/listVersions/downloads, and deleting every version leaves nothing readable. Two non-blocking suggestions:
- The now-unguarded
unlinkSync(index.mock.ts L227) throws EISDIR whenreadVersionsreturns a directory (docswhiledocs/readme.txtexists; main swallowed it), which surfaces as a 500. #1141 fixes that filter and conflicts with this PR inlistVersions: whichever lands second, please move itswithFileTypes+isFile()filter intoreadVersionsrather than taking this side. - Rewrite
content/+meta/before unlinking the version file, so a failed write leaves state retryable (today it can leave v1's body with v2's content-type, and a retry is a no-op).
Nit: mention promote-on-delete in the delete() JSDoc. CI hasn't run on this PR yet (workflows await approval).
|
Thanks for checking the regression cases and catching the failure path. I've addressed all three suggestions:
DESIGN also makes clear that this is retryable reconciliation, not atomicity or rollback. The historical delete-marker limitation tracked in #1209 is unchanged. Build, lint, FileBucket tests, the full workspace unit suite, and local E2E all pass on the updated branch, including the nested-key deletion case through the frontend API. |
Conflict resolution: - packages/create-blocks-app/templates/auth/src/index.ts: #1239 edited templates/auth-cognito/src/index.ts, which this branch renamed to templates/auth and rewrote for the unified Auth block. Git applied the hunks to the renamed file; the one conflict was in refreshTodos()'s catch. Kept this branch's isBlocksError(error, 'NotAuthenticatedException') check and showError(el, unknown) call, and added #1239's boolean returns. #1239's mutateTodo() helper and the caught "Show last code" lookup are ported as-is, except that they use isBlocksError for the signed-out check and pass the error straight to this branch's showError, which already takes unknown, so #1239's errorMessage() helper is not needed. No templates/auth-cognito/ directory is re-created. - .changeset/auth-cognito-todo-errors.md renamed to auth-template-todo-errors.md, and its text now names the `auth` template. Package unchanged (@aws-blocks/create-blocks-app, patch).
Problem
Permanently deleting the newest stored data version of a local FileBucket removes its version-history entry but leaves its current body and metadata on disk. For histories containing only data versions,
listVersions()then identifies the previous version as current whileget(),scan(), and current presigned downloads still expose the deleted content. Deleting every stored data version leaves the same stale file accessible even thoughlistVersions()is empty.On S3, deleting the current data version exposes the next entry in the version history, which may be another data version or a delete marker: Restoring previous versions, Working with delete markers.
Issue #, if available: None for the original current-copy reconciliation fix.
Changes
__deleted__flag during version deletion.get()andscan()continue to honor an active flag; deleting an older or unknown version does not rewrite the current file.listVersions()without yielding during reconciliation. Count only regular files, ignoring nested-key directories. This overlaps with the listing filter in fix(bb-file-bucket): ignore nested key directories in mock version history #1141; its explicit-versionget()andrestoreVersion()guards remain separate.put(), so this is not full S3 version-history parity.Known limitation, not fixed here:
put(old)->delete()->put(replacement)-> permanent deletion of the replacement exposesoldwith this PR, whereas S3 would make the earlier delete marker current. This already diverges on main (which returns the stale replacement); current-copy reconciliation alone cannot recover the discarded marker history. The exact sequence and its effect onget(),scan(), andlistVersions()are documented under DESIGN's Mock vs AWS Behavior Differences. This is distinct from #1167, which makes local downloads honor a marker that is still present.The remaining historical-marker behavior is tracked separately in #1209; this PR does not resolve it.
The AWS implementation, public API signatures, conditional exports, and mock storage format are unchanged. The
delete()JSDoc now describes promotion and active-marker preservation. Historical marker support remains outside this PR.Validation
replacement; this PR returnsold; both listkand markv1current. This confirms the documented remaining limitation, not a fix for it. S3's expected deleted state is based on its documented versioning semantics; no AWS deployment was performed for this local-mock fix.npm run buildnpm run lintandnpm run lint:depsnpm test -w @aws-blocks/bb-file-bucketnpm testacross all workspaces, with serial test-file execution and all generate-client fixture cases run in separate processes; none excludednpm run test:e2e:local(comprehensive local E2E, vendorize, IAM-boundary synth, and background-suite regression tests)git diff --check upstream/mainThe latest review follow-up adds regression tests for nested-key directories, failed body/metadata promotion, failed last-version cleanup, failed version-sidecar removal, missing-file tolerance, and retrying after reopening the bucket. The new failure cases fail before this follow-up and pass after it, using real temporary filesystem obstructions rather than stubbing FileBucket behavior. The comprehensive frontend API suite also covers deletion against a prefix key without affecting its nested objects.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.