Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(bb-file-bucket): return null from get() for a key that is only a …
…prefix of other keys
  • Loading branch information
xyos committed Nov 8, 2026
commit 66e5dbd597dc1f97445703543edfc4424006e8ee
2 changes: 1 addition & 1 deletion .changeset/bb-file-bucket-mock-phantom-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@aws-blocks/bb-file-bucket': patch
---

The local `FileBucket` mock no longer reports phantom versions for a key that is a prefix of another key. `listVersions('docs')` now returns `[]` when only `docs/readme.txt` was written, `get('docs', { versionId: 'readme.txt' })` returns `null` instead of throwing `EISDIR`, and `restoreVersion` throws `VersionNotFound`, matching AWS.
The local `FileBucket` mock now treats a key that is only a prefix of other keys as missing, matching AWS. With only `docs/readme.txt` written, `get('docs')` and `get('docs', { versionId: 'readme.txt' })` return `null` instead of throwing `EISDIR`, `listVersions('docs')` returns `[]`, and `restoreVersion('docs', ...)` throws `VersionNotFound`.
2 changes: 1 addition & 1 deletion packages/bb-file-bucket/src/index.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class FileBucket<O extends FileBucketOptions = FileBucketOptions> extends
return { body, contentType: meta.contentType, metadata: meta.metadata, size: body.length };
}
const filePath = contentPath(this.dataDir, path);
if (!existsSync(filePath)) return null;
if (!statSync(filePath, { throwIfNoEntry: false })?.isFile()) return null;
// Check for delete marker
if (this.versioned && existsSync(deleteMarkerPath(this.dataDir, path))) return null;

Expand Down
7 changes: 7 additions & 0 deletions packages/bb-file-bucket/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ test('nested paths work', async () => {
assert.strictEqual(file.body.toString(), 'nested');
});

test('get on a key that is a prefix of another key returns null', async () => {
const bucket = new FileBucket(scope, 'test');
await bucket.put('prefix-docs/readme.txt', 'nested');
assert.strictEqual(await bucket.get('prefix-docs'), null);
});

// ── scan() ──────────────────────────────────────────────────────────────────

test('scan yields all files', async () => {
Expand Down Expand Up @@ -329,6 +335,7 @@ test('versioned: key that is a prefix of another key has no phantom versions', a
await bucket.put('docs/readme.txt', 'v1');
await bucket.put('docs/readme.txt', 'v2');
assert.deepStrictEqual(await bucket.listVersions('docs'), []);
assert.strictEqual(await bucket.get('docs'), null);
assert.strictEqual(await bucket.get('docs', { versionId: 'readme.txt' }), null);
await assert.rejects(
bucket.restoreVersion('docs', 'readme.txt'),
Expand Down