fix(host,client): review round 23 — create-path contract at every client declaration; close-edge resets; NFD tripwire; canonical double join

This commit is contained in:
creatixchu
2026-07-30 03:17:30 +08:00
parent de24461b91
commit df313b7531
10 changed files with 46 additions and 21 deletions

View File

@@ -143,14 +143,14 @@ export class TestWorkspaces implements IWorkspaces {
* @param path - absolute existing parent directory.
* @param name - single path segment.
* @returns the created directory's absolute path, in the shape
* `DirectoryPickerBrowseCapability.createDirectory` contracts (verbatim
* equal to the child's `entries[].path` in the parent's next listing).
* `IWorkspaces.createDirectory` contracts.
*/
async createDirectory(path: string, name: string): Promise<string> {
this.calls.push({ method: 'createDirectory', args: [path, name] })
const stub = this.stubs.get('createDirectory')
if (stub !== undefined) return await (stub(path, name) as Promise<string>)
return `${path}/${name}`
// Canonical join: a bare-root parent must not double the separator.
return path.endsWith('/') ? `${path}${name}` : `${path}/${name}`
}
/**

View File

@@ -329,12 +329,16 @@ describe('workspaces', () => {
await expect(runtime.workspaces.listDirectory()).resolves.toMatchObject({ path: '/home/test', entries: [] })
await expect(runtime.workspaces.listDirectory('/home/test')).resolves.toMatchObject({ path: '/home/test' })
await expect(runtime.workspaces.createDirectory('/home/test', 'fresh')).resolves.toBe('/home/test/fresh')
// Canonical join: a bare-root parent yields /top, not //top (the
// IWorkspaces contract's verbatim entries[].path equality).
await expect(runtime.workspaces.createDirectory('/', 'top')).resolves.toBe('/top')
// The recorded signal seat mirrors the production face (undefined here;
// cancellation tests pass and observe a real one).
expect(runtime.workspaces.calls).toEqual([
{ method: 'listDirectory', args: [undefined, undefined] },
{ method: 'listDirectory', args: ['/home/test', undefined] },
{ method: 'createDirectory', args: ['/home/test', 'fresh'] },
{ method: 'createDirectory', args: ['/', 'top'] },
])
// Stubs replace the defaults like every sibling method.
const listing = { path: '/x', home: '/x', crumbs: [], entries: [] }