fix(host): review round 20 — canonical shape declared at the interface; hermetic home-shape spec; single resolve
This commit is contained in:
@@ -2,19 +2,33 @@
|
||||
* The wire contract's home shape: a decorated HOME (trailing/repeated
|
||||
* separators, dot segments — homedir() ships it verbatim) still leaves the
|
||||
* listing carrying the resolved form, matching `path` and `crumbs[].path`.
|
||||
* The mock points homedir at a scratch tree so the probe never scans the
|
||||
* running machine's real home (same hermetic reasoning as service.spec's
|
||||
* temporary tree); the mock spreads the actual module, so tmpdir stays real.
|
||||
*/
|
||||
|
||||
import { resolve } from 'node:path'
|
||||
import { expect, it, vi } from 'vitest'
|
||||
import { mkdtemp, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { afterAll, beforeAll, expect, it, vi } from 'vitest'
|
||||
import { Context } from 'cordis'
|
||||
|
||||
let scratch: string
|
||||
|
||||
vi.mock('node:os', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('node:os')>()
|
||||
return { ...actual, homedir: () => `${actual.homedir()}/.//.` }
|
||||
return { ...actual, homedir: () => `${scratch}/.//.` }
|
||||
})
|
||||
|
||||
beforeAll(async () => {
|
||||
scratch = await mkdtemp(join(tmpdir(), 'dsh-home-shape-'))
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await rm(scratch, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('resolves a decorated homedir before stamping listing.home', async () => {
|
||||
const { homedir } = await vi.importActual<typeof import('node:os')>('node:os')
|
||||
const { default: BrowseDirectoryPicker } = await import('../src/index.ts')
|
||||
const ctx = new Context()
|
||||
const fiber = ctx.plugin(BrowseDirectoryPicker)
|
||||
@@ -22,7 +36,7 @@ it('resolves a decorated homedir before stamping listing.home', async () => {
|
||||
const picked = ctx.get('directoryPicker')!.capability()
|
||||
if (picked.kind !== 'browse') throw new Error('browse backend must advertise the browse capability')
|
||||
const listing = await picked.list()
|
||||
expect(listing.home).toBe(resolve(homedir()))
|
||||
expect(listing.home).toBe(resolve(scratch))
|
||||
expect(listing.path).toBe(listing.home)
|
||||
await fiber.dispose()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user