feat(runner): replace server-side bash sandbox with remote runner

This commit is contained in:
yiling
2026-11-14 13:12:19 +08:00
parent 2be1093b91
commit c56ad79213
77 changed files with 7083 additions and 4992 deletions
+36
View File
@@ -0,0 +1,36 @@
import { Hono } from 'hono'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { runnerService } from '@shumai/core/src/runner'
import runnerWsRoute from './runner-ws'
vi.mock('@shumai/core/src/runner', () => ({
runnerService: {
authenticateRunnerKey: vi.fn(),
registerConnection: vi.fn(),
handleMessage: vi.fn(),
handleDisconnect: vi.fn(),
},
}))
describe('runnerWsRoute', () => {
const app = new Hono().route('/', runnerWsRoute)
beforeEach(() => {
vi.clearAllMocks()
})
it('returns 401 when runner key is missing', async () => {
const res = await app.request('/runners/ws')
expect(res.status).toBe(401)
expect(await res.json()).toEqual({ message: 'Missing runner key' })
})
it('returns 401 when runner key is invalid', async () => {
vi.mocked(runnerService.authenticateRunnerKey).mockResolvedValue(null)
const res = await app.request('/runners/ws', {
headers: { Authorization: 'Bearer shm_rn_invalid' },
})
expect(res.status).toBe(401)
expect(await res.json()).toEqual({ message: 'Invalid runner key' })
})
})