From dc94af3a6a09c15bac5b5ddcaf493a63306e111b Mon Sep 17 00:00:00 2001 From: David Snelling Date: Tue, 16 Jun 2026 10:47:10 -0700 Subject: [PATCH] test(8.0): get() resolves null for absent custom ids instead of throwing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to accepting application-supplied ids (36b7216): get('not-a-uuid') and long ids are now valid lookups that miss → null, not "Invalid UUID format" throws. Empty / null / undefined still throw (structurally invalid input). Aligns the unit suite with the accept-any-id behaviour; the v5.1.0 "stricter UUID validation" rule these cases encoded is superseded. --- tests/unit/brainy/get.test.ts | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/unit/brainy/get.test.ts b/tests/unit/brainy/get.test.ts index b11b05d5..b39bf2e1 100644 --- a/tests/unit/brainy/get.test.ts +++ b/tests/unit/brainy/get.test.ts @@ -159,19 +159,18 @@ describe('Brainy.get()', () => { }) it('should handle invalid ID formats gracefully', async () => { - // v5.1.0: Invalid formats now throw errors instead of returning null - const invalidIds = [ - '', // Empty string - 'not-a-uuid', // Invalid format - '12345', // Too short + // 8.0: any non-empty string is a valid custom id (sharding hashes it), so + // a lookup that misses resolves to null — there is no "invalid format". + const missingIds = [ + 'not-a-uuid', // valid custom id, simply absent + '12345' // valid custom id, simply absent ] - - // Act & Assert - expect errors for invalid formats - for (const invalidId of invalidIds) { - await expect(brain.get(invalidId)).rejects.toThrow() + for (const id of missingIds) { + await expect(brain.get(id)).resolves.toBeNull() } - // Null/undefined should also throw + // Structurally-invalid input (empty / null / undefined) still throws. + await expect(brain.get('')).rejects.toThrow() await expect(brain.get(null as any)).rejects.toThrow() await expect(brain.get(undefined as any)).rejects.toThrow() }) @@ -215,11 +214,9 @@ describe('Brainy.get()', () => { describe('edge cases', () => { it('should handle very long IDs', async () => { - // v5.1.0: Stricter UUID validation - invalid IDs throw errors + // 8.0: a long string is a valid custom id; a miss resolves to null. const longId = 'x'.repeat(1000) - - // Expect error for invalid UUID format - await expect(brain.get(longId)).rejects.toThrow('Invalid UUID format') + await expect(brain.get(longId)).resolves.toBeNull() }) it('should handle special characters in IDs', async () => {