Files
Chris Scott c60a9b35f2 fix(terminal-dev-loop): address branch review findings
Security:
- Reject same-site and cross-site state-changing requests on cookie-authenticated routes unless the origin is trusted
- Drop Manager and ocm_preview Set-Cookie headers from preview responses
- Show and hash the full executable content of .ocm/project.json at trust time
- Restrict action URLs to http(s) and refuse symlinked repo config paths
- Keep the preview start redirect on the gateway origin

Lifecycle:
- Stop terminals in OpenCode workspace siblings when a repo is deleted
- Report preview as unavailable instead of crashing when the gateway port cannot be bound

Performance:
- Skip branch lookups when validating terminal and project-config directories
- Stop the /proc scan once all listening sockets are mapped and pause port polling while a preview is open
- Close slow WebSocket clients with 1013 so they reconnect with replay
- Lazy-load the xterm terminal view and skip unchanged resize requests
- Request uncompressed responses from preview targets

Cleanup:
- Share one repo directory resolver, trusted-origins parser, cookie prefix, WebSocket frame forwarder, header filter, icon map and dialog-param helper
- Remove unused props, options and exports

Docs: update terminal, preview, project actions, sandboxing, internal API and environment pages
2026-10-03 10:00:33 -04:00

81 lines
3.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { formatTerminalTitle, isRunningActionTerminal, parseTerminalTitle } from '@opencode-manager/shared/utils'
describe('terminal-title', () => {
describe('formatTerminalTitle', () => {
it('encodes a plain shell title as the name', () => {
expect(formatTerminalTitle({ kind: 'shell', name: 'Terminal' })).toBe('Terminal')
})
it('encodes a setup title with the setup prefix', () => {
expect(formatTerminalTitle({ kind: 'setup', name: 'Worktree setup' })).toBe('ocm:setup:Worktree setup')
})
it('encodes an action title with the action id', () => {
expect(formatTerminalTitle({ kind: 'action', name: 'Dev server', actionId: 'dev' })).toBe('ocm:action:dev:Dev server')
})
it('rejects an action without a valid action id', () => {
expect(() => formatTerminalTitle({ kind: 'action', name: 'Dev server' })).toThrow()
expect(() => formatTerminalTitle({ kind: 'action', name: 'Dev server', actionId: 'bad id' })).toThrow()
})
})
describe('parseTerminalTitle', () => {
it('round-trips a shell title', () => {
expect(parseTerminalTitle(formatTerminalTitle({ kind: 'shell', name: 'My shell' }))).toEqual({
kind: 'shell',
title: 'My shell',
})
})
it('round-trips a setup title', () => {
expect(parseTerminalTitle(formatTerminalTitle({ kind: 'setup', name: 'Worktree setup' }))).toEqual({
kind: 'setup',
title: 'Worktree setup',
})
})
it('round-trips an action title including a colon in the name', () => {
expect(parseTerminalTitle(formatTerminalTitle({ kind: 'action', name: 'Dev: server', actionId: 'dev_1' }))).toEqual({
kind: 'action',
title: 'Dev: server',
actionId: 'dev_1',
})
})
it('treats an untagged title as a shell', () => {
expect(parseTerminalTitle('plain title')).toEqual({ kind: 'shell', title: 'plain title' })
})
it('treats a malformed action id as a shell', () => {
expect(parseTerminalTitle('ocm:action:bad id:Dev server')).toEqual({
kind: 'shell',
title: 'ocm:action:bad id:Dev server',
})
})
it('treats an action prefix without a name as a shell', () => {
expect(parseTerminalTitle('ocm:action:dev')).toEqual({ kind: 'shell', title: 'ocm:action:dev' })
})
})
describe('isRunningActionTerminal', () => {
it('matches a running action terminal for the action id', () => {
expect(isRunningActionTerminal({ kind: 'action', actionId: 'dev', status: 'running' }, 'dev')).toBe(true)
})
it('rejects a terminal for a different action id', () => {
expect(isRunningActionTerminal({ kind: 'action', actionId: 'other', status: 'running' }, 'dev')).toBe(false)
})
it('rejects a non-action terminal', () => {
expect(isRunningActionTerminal({ kind: 'shell', status: 'running' }, 'dev')).toBe(false)
})
it('rejects an exited action terminal', () => {
expect(isRunningActionTerminal({ kind: 'action', actionId: 'dev', status: 'exited' }, 'dev')).toBe(false)
})
})
})