mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
section 2: Phase 2: Terminal service, REST routes and cleanup
This commit is contained in:
1 parent
b494ee9f4a
commit
beab2646e7
15 files changed
+907
-57
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { formatTerminalTitle, 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' })
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user