repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { describe, it, expect, vi } from 'vitest'; |
| #2 | import { findExistingMoltbotProcess } from './process'; |
| #3 | import type { Sandbox, Process } from '@cloudflare/sandbox'; |
| #4 | import { createMockSandbox } from '../test-utils'; |
| #5 | |
| #6 | // Helper to create a full mock process (with methods needed for process tests) |
| #7 | function createFullMockProcess(overrides: Partial<Process> = {}): Process { |
| #8 | return { |
| #9 | id: 'test-id', |
| #10 | command: 'clawdbot gateway', |
| #11 | status: 'running', |
| #12 | startTime: new Date(), |
| #13 | endTime: undefined, |
| #14 | exitCode: undefined, |
| #15 | waitForPort: vi.fn(), |
| #16 | kill: vi.fn(), |
| #17 | getLogs: vi.fn().mockResolvedValue({ stdout: '', stderr: '' }), |
| #18 | ...overrides, |
| #19 | } as Process; |
| #20 | } |
| #21 | |
| #22 | describe('findExistingMoltbotProcess', () => { |
| #23 | it('returns null when no processes exist', async () => { |
| #24 | const { sandbox } = createMockSandbox({ processes: [] }); |
| #25 | const result = await findExistingMoltbotProcess(sandbox); |
| #26 | expect(result).toBeNull(); |
| #27 | }); |
| #28 | |
| #29 | it('returns null when only CLI commands are running', async () => { |
| #30 | const processes = [ |
| #31 | createFullMockProcess({ command: 'clawdbot devices list --json', status: 'running' }), |
| #32 | createFullMockProcess({ command: 'clawdbot --version', status: 'completed' }), |
| #33 | ]; |
| #34 | const { sandbox, listProcessesMock } = createMockSandbox(); |
| #35 | listProcessesMock.mockResolvedValue(processes); |
| #36 | |
| #37 | const result = await findExistingMoltbotProcess(sandbox); |
| #38 | expect(result).toBeNull(); |
| #39 | }); |
| #40 | |
| #41 | it('returns gateway process when running', async () => { |
| #42 | const gatewayProcess = createFullMockProcess({ |
| #43 | id: 'gateway-1', |
| #44 | command: 'clawdbot gateway --port 18789', |
| #45 | status: 'running' |
| #46 | }); |
| #47 | const processes = [ |
| #48 | createFullMockProcess({ command: 'clawdbot devices list', status: 'completed' }), |
| #49 | gatewayProcess, |
| #50 | ]; |
| #51 | const { sandbox, listProcessesMock } = createMockSandbox(); |
| #52 | listProcessesMock.mockResolvedValue(processes); |
| #53 | |
| #54 | const result = await findExistingMoltbotProcess(sandbox); |
| #55 | expect(result).toBe(gatewayProcess); |
| #56 | }); |
| #57 | |
| #58 | it('returns gateway process when starting', async () => { |
| #59 | const gatewayProcess = createFullMockProcess({ |
| #60 | id: 'gateway-1', |
| #61 | command: '/usr/local/bin/start-moltbot.sh', |
| #62 | status: 'starting' |
| #63 | }); |
| #64 | const { sandbox, listProcessesMock } = createMockSandbox(); |
| #65 | listProcessesMock.mockResolvedValue([gatewayProcess]); |
| #66 | |
| #67 | const result = await findExistingMoltbotProcess(sandbox); |
| #68 | expect(result).toBe(gatewayProcess); |
| #69 | }); |
| #70 | |
| #71 | it('ignores completed gateway processes', async () => { |
| #72 | const processes = [ |
| #73 | createFullMockProcess({ command: 'clawdbot gateway', status: 'completed' }), |
| #74 | createFullMockProcess({ command: 'start-moltbot.sh', status: 'failed' }), |
| #75 | ]; |
| #76 | const { sandbox, listProcessesMock } = createMockSandbox(); |
| #77 | listProcessesMock.mockResolvedValue(processes); |
| #78 | |
| #79 | const result = await findExistingMoltbotProcess(sandbox); |
| #80 | expect(result).toBeNull(); |
| #81 | }); |
| #82 | |
| #83 | it('handles listProcesses errors gracefully', async () => { |
| #84 | const sandbox = { |
| #85 | listProcesses: vi.fn().mockRejectedValue(new Error('Network error')), |
| #86 | } as unknown as Sandbox; |
| #87 | |
| #88 | const result = await findExistingMoltbotProcess(sandbox); |
| #89 | expect(result).toBeNull(); |
| #90 | }); |
| #91 | |
| #92 | it('matches start-moltbot.sh command', async () => { |
| #93 | const gatewayProcess = createFullMockProcess({ |
| #94 | id: 'gateway-1', |
| #95 | command: '/usr/local/bin/start-moltbot.sh', |
| #96 | status: 'running' |
| #97 | }); |
| #98 | const { sandbox, listProcessesMock } = createMockSandbox(); |
| #99 | listProcessesMock.mockResolvedValue([gatewayProcess]); |
| #100 | |
| #101 | const result = await findExistingMoltbotProcess(sandbox); |
| #102 | expect(result).toBe(gatewayProcess); |
| #103 | }); |
| #104 | |
| #105 | it('returns first matching gateway process', async () => { |
| #106 | const firstGateway = createFullMockProcess({ |
| #107 | id: 'gateway-1', |
| #108 | command: 'clawdbot gateway', |
| #109 | status: 'running' |
| #110 | }); |
| #111 | const secondGateway = createFullMockProcess({ |
| #112 | id: 'gateway-2', |
| #113 | command: 'start-moltbot.sh', |
| #114 | status: 'starting' |
| #115 | }); |
| #116 | const { sandbox, listProcessesMock } = createMockSandbox(); |
| #117 | listProcessesMock.mockResolvedValue([firstGateway, secondGateway]); |
| #118 | |
| #119 | const result = await findExistingMoltbotProcess(sandbox); |
| #120 | expect(result?.id).toBe('gateway-1'); |
| #121 | }); |
| #122 | }); |
| #123 |