Skip to content

fix(bb-file-bucket): ignore nested key directories in mock version history - #1141

Open
xyos wants to merge 6 commits into
aws:mainfrom
xyos:fix/bb-file-bucket-mock-phantom-versions
Open

xyos wants to merge 6 commits into
aws:mainfrom
xyos:fix/bb-file-bucket-mock-phantom-versions

Conversation

@xyos

@xyos xyos commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Problem

The local FileBucket mock stores version history for a key under versions/<key>/, so version history for docs/readme.txt lives in versions/docs/readme.txt/. That makes versions/docs/ contain a directory entry named readme.txt, which the mock treats as a version of the key docs (packages/bb-file-bucket/src/index.mock.ts, listVersions):

  • listVersions('docs') returns [{ versionId: 'readme.txt', isCurrent: true, ... }] although docs was never written.
  • get('docs', { versionId: 'readme.txt' }) throws EISDIR instead of returning null.
  • restoreVersion('docs', 'readme.txt') passes the existence check and then throws EISDIR from readFileSync instead of VersionNotFound.

Against AWS, listVersions('docs') returns [] (index.aws.ts skips listed versions whose Key is not the requested path), and the other two calls behave as for any unknown version.

Issue #, if available:

Changes

  • packages/bb-file-bucket/src/index.mock.ts: listVersions only counts regular files as version entries. The versioned branch of get returns null and restoreVersion throws VersionNotFound when the version path is not a regular file.
  • packages/bb-file-bucket/src/index.test.ts: regression test for a key that is a prefix of another versioned key, with controls for the real key.
  • .changeset/bb-file-bucket-mock-phantom-versions.md: patch for @aws-blocks/bb-file-bucket.

Validation

  • New test versioned: key that is a prefix of another key has no phantom versions failed before the fix (listVersions('docs') returned [{ versionId: 'readme.txt', isCurrent: true, ... }] instead of []) and passes after it.
  • npm run build, packages/bb-file-bucket npm test (364 pass), npm run lint, npm run lint:deps: pass.
  • npm test (all workspaces) and npm run test:e2e:local from the repo root: pass.

Checklist

  • PR description included
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xyos
xyos requested a review from a team as a code owner October 29, 2026 21:49
@changeset-bot

changeset-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 887bbc7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-blocks/bb-file-bucket Patch

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
belaboe previously approved these changes Nov 2, 2026

@belaboe belaboe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The fix is correct and matches index.aws.ts for all three cases, and the on-disk format is unchanged. One thing worth folding in: the non-versioned branch of the same get() (index.mock.ts:188) still throws EISDIR for get('docs') when docs/readme.txt exists (AWS returns null). The same isFile() guard plus one assert in the new test would cover it.

Non-blocking follow-ups:

  • The mock doesn't validate versionId: 'readme.txt/v1' reads another key's v1, and restoreVersion with it leaves a phantom version. Reusing file-server's /^v\d+$/ would close that.
  • The file-server GET has the same dir-vs-file gap.
  • Nit: the changeset headline is broader than the fix, and DESIGN.md:24 "arbitrary keys ... matching S3" isn't true for a vs a/x.

@xyos

xyos commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! Folded in: get() now uses the same isFile() guard on the plain path, so get('docs') returns null when only docs/readme.txt exists. Both the versioned and non-versioned cases are asserted (they fail with EISDIR without the guard). I also narrowed the changeset to the prefix-key case. The DESIGN.md sentence is gone on main after the D-FB-2 rewrite, so there's nothing left to change there. I merged main: listVersions now delegates to main's readVersions(), which already has the same filter. I'll open follow-ups for versionId validation in the mock and for the file-server GET dir-vs-file gap.

@xyos
xyos requested a review from belaboe November 10, 2026 10:32

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants