- title-util.cwdFromOsc7: parse cwd from OSC 7 (file:// URL); 4 unit tests - terminal-session: register OSC 7 handler → cwd getter; opts.cwd → sent in the attach frame on a fresh session - protocol/types: ClientMessage attach.cwd (absolute path); validated - session/manager/server: thread cwd → createSession spawn cwd (defaults homeDir) - tabs: '+' (newTab) opens in the active tab's reported cwd, falls back to home - Verified: server attach.cwd spawns there; cd /private/tmp → + → new tab pwd is /private/tmp. 212 tests green.
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { folderFromTitle, cwdFromOsc7 } from '../public/title-util.js'
|
|
|
|
describe('cwdFromOsc7', () => {
|
|
it('extracts the path from a file:// URL with a host', () => {
|
|
expect(cwdFromOsc7('file://mac.local/Users/me/web-terminal')).toBe('/Users/me/web-terminal')
|
|
})
|
|
it('extracts the path with an empty host (file:///)', () => {
|
|
expect(cwdFromOsc7('file:///Users/me/dir')).toBe('/Users/me/dir')
|
|
})
|
|
it('decodes percent-encoded spaces', () => {
|
|
expect(cwdFromOsc7('file://h/Users/me/my%20dir')).toBe('/Users/me/my dir')
|
|
})
|
|
it('returns null for non-file URLs', () => {
|
|
expect(cwdFromOsc7('http://x/y')).toBeNull()
|
|
expect(cwdFromOsc7('garbage')).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('folderFromTitle', () => {
|
|
it('extracts the folder from user@host:~/path', () => {
|
|
expect(folderFromTitle('yiukai@Mac:~/Documents/git/web-terminal')).toBe('web-terminal')
|
|
})
|
|
|
|
it('keeps ~ for the home directory', () => {
|
|
expect(folderFromTitle('yiukai@Yiukais-MacBook-Pro:~')).toBe('~')
|
|
})
|
|
|
|
it('takes the basename of an absolute path', () => {
|
|
expect(folderFromTitle('user@host:/Users/yiukai/web')).toBe('web')
|
|
})
|
|
|
|
it('strips a trailing slash', () => {
|
|
expect(folderFromTitle('user@host:~/web/')).toBe('web')
|
|
})
|
|
|
|
it('handles a title with no user@host: prefix', () => {
|
|
expect(folderFromTitle('web-terminal')).toBe('web-terminal')
|
|
})
|
|
|
|
it('returns the last path segment when the whole title is a path', () => {
|
|
expect(folderFromTitle('/var/log/nginx')).toBe('nginx')
|
|
})
|
|
|
|
it('returns null for an empty/whitespace title', () => {
|
|
expect(folderFromTitle(' ')).toBeNull()
|
|
expect(folderFromTitle('')).toBeNull()
|
|
})
|
|
})
|