test(storage-json): reach the unreadable-record branch on every platform
The per-record contract test forced readFile to fail via chmod 0o000, which is a no-op on win32, so the readRecord catch stayed uncovered on the windows native coverage gate. Route record documents without an isFile pre-filter: a directory where the document should be throws EISDIR on every platform, and readRecord's existing contract already reads an unreadable document as absent. Drop the win32 skip.
This commit is contained in:
parent
4760c40e84
commit
87c01d9966
2 changed files with 6 additions and 8 deletions
|
|
@ -143,7 +143,7 @@ async function migrateLegacyUnit(descriptor: KvUnitDescriptor, dir: string, stat
|
|||
/** Read one declared table's record documents into `records`. */
|
||||
async function loadTableRecords(records: Map<string, unknown>, version: number, dir: string): Promise<void> {
|
||||
for (const file of await readdir(dir, { withFileTypes: true })) {
|
||||
if (!file.isFile() || !file.name.endsWith('.json')) continue
|
||||
if (!file.name.endsWith('.json')) continue
|
||||
const key = file.name.slice(0, -'.json'.length)
|
||||
if (!SAFE_KEY_RE.test(key)) continue
|
||||
const record = await readRecord(join(dir, file.name), version)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { chmod, mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises'
|
||||
import { mkdir, mkdtemp, readFile, readdir, rename, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterAll, describe, expect, it } from 'vitest'
|
||||
|
|
@ -327,17 +327,15 @@ describe('per-record layout', () => {
|
|||
await backend.close()
|
||||
})
|
||||
|
||||
it.skipIf(process.platform === 'win32')('reads an unreadable record document as absent (per-record contract)', async () => {
|
||||
it('reads an unreadable record document as absent (per-record contract)', async () => {
|
||||
const root = await freshRoot()
|
||||
const path = recordPath(root, 'locked')
|
||||
await mkdir(join(root, 'recs', 't'), { recursive: true })
|
||||
await writeFile(path, JSON.stringify({ version: 2, record: { v: 1 } }), 'utf8')
|
||||
await chmod(path, 0o000)
|
||||
// A directory where the record document should be: readFile fails with
|
||||
// EISDIR on every platform (permission bits are unenforceable on win32).
|
||||
await mkdir(join(root, 'recs', 't', 'locked.json'), { recursive: true })
|
||||
const backend = new JsonStorageBackend(root)
|
||||
const unit = await backend.kv.open(descriptor)
|
||||
expect(await unit.loadAll()).toEqual({ tables: { t: {} }, global: null })
|
||||
await backend.close()
|
||||
await chmod(path, 0o600)
|
||||
})
|
||||
|
||||
it('migrates a legacy whole-unit file once, new records win, then deletes it', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue