fix: ignore malformed reload entries

This commit is contained in:
lucaronin
2026-05-02 10:00:50 +02:00
parent 6532ee125a
commit ba41854f0e
3 changed files with 84 additions and 12 deletions

View File

@@ -0,0 +1,40 @@
import { describe, expect, it } from 'vitest'
import { normalizeVaultEntries } from './vaultMetadataNormalization'
describe('normalizeVaultEntries', () => {
it('repairs missing string metadata when the entry path is present', () => {
const entries = normalizeVaultEntries([
{
path: '/vault/alpha-project.md',
filename: undefined,
title: undefined,
aliases: undefined,
},
], '/vault')
expect(entries).toHaveLength(1)
expect(entries[0]).toMatchObject({
path: '/vault/alpha-project.md',
filename: 'alpha-project.md',
title: 'alpha-project',
aliases: [],
})
})
it('drops malformed reload entries that do not include a usable path', () => {
const entries = normalizeVaultEntries([
{ path: '/vault/valid.md', filename: 'valid.md', title: 'Valid' },
{ filename: 'missing-path.md', title: 'Missing Path' },
{ path: '', filename: 'empty-path.md', title: 'Empty Path' },
{ path: 42, filename: 'numeric-path.md', title: 'Numeric Path' },
null,
], '/vault')
expect(entries).toHaveLength(1)
expect(entries[0]).toMatchObject({
path: '/vault/valid.md',
filename: 'valid.md',
title: 'Valid',
})
})
})