Adapt to two contract changes master introduced: - The generated Remote face now wraps every business result in RemoteResult, folding carrier failures into an ok:false branch instead of rejecting. The controller reads that envelope at its three call sites and maps a carrier failure onto the same settled shape the controls already render; three specs cover the new branch. - Client packages split their tsconfig into host and client halves, and the host aggregate now compiles any test not named *.client.spec.*. Rename this package's specs to the client convention and drop the ../connection project reference, which pointed at a solution file that no longer carries the client sources. Keep master's mount loop with its rollback-on-failure in api-remotes and add messageFeedbackRemote to it.
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
// @vitest-environment jsdom
|
|
/**
|
|
* Session-log export browser delivery: safe filename derivation and a native
|
|
* download handoff that leaves the streamed response outside JavaScript.
|
|
*/
|
|
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { downloadSessionLog, sessionLogZipFilename } from '../src/client/export-log.ts'
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
describe('sessionLogZipFilename', () => {
|
|
it('keeps safe session ids verbatim', () => {
|
|
expect(sessionLogZipFilename('session-abc_1-2')).toBe('dsh-session-session-abc_1-2.zip')
|
|
})
|
|
|
|
it('neutralizes unsafe id characters that could shape the filename', () => {
|
|
expect(sessionLogZipFilename('../evil')).toBe('dsh-session-___evil.zip')
|
|
expect(sessionLogZipFilename('a/b')).toBe('dsh-session-a_b.zip')
|
|
})
|
|
|
|
it('strips dots so a dot-only id cannot shape a dot segment', () => {
|
|
expect(sessionLogZipFilename('..')).toBe('dsh-session-__.zip')
|
|
})
|
|
})
|
|
|
|
describe('downloadSessionLog', () => {
|
|
it('hands the descendant-inclusive endpoint directly to the browser', async () => {
|
|
const click = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
|
|
|
await downloadSessionLog('session/with spaces')
|
|
|
|
expect(click).toHaveBeenCalledOnce()
|
|
const anchor = click.mock.contexts[0] as HTMLAnchorElement
|
|
const url = new URL(anchor.href)
|
|
expect(url.pathname).toBe('/api/session.export')
|
|
expect(url.searchParams.get('sessionId')).toBe('session/with spaces')
|
|
expect(url.searchParams.get('includeDescendants')).toBe('true')
|
|
expect(anchor.download).toBe('dsh-session-session_with_spaces.zip')
|
|
})
|
|
|
|
it('rejects when the browser download handoff fails', async () => {
|
|
vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {
|
|
throw new Error('download denied')
|
|
})
|
|
|
|
await expect(downloadSessionLog('session-root')).rejects.toThrow('download denied')
|
|
})
|
|
})
|