mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 11:24:43 +00:00
feat(cli): add runner start with bundled SRT sandboxing (#535)
* refactor(agent): expose runner bash without skill gating * feat(cli): add runner start with optional SRT sandboxing * refactor(cli): remove runner Python dependency * feat(cli): bundle SRT and use platform-native runner shells * refactor(cli): delegate runner processes to Execa
This commit is contained in:
@@ -55,6 +55,41 @@ describe('RunnerService', () => {
|
||||
})
|
||||
|
||||
describe('Key & workspace path helpers', () => {
|
||||
it('keeps validated OS and shell metadata only for the current connection', async () => {
|
||||
const { runner, key } = await service.createRunner(teamId, { name: 'Windows runner' })
|
||||
const connection = createMockWs()
|
||||
const authenticated = {
|
||||
id: runner.id,
|
||||
teamId,
|
||||
name: runner.name,
|
||||
keyHash: hashRunnerKey(key),
|
||||
}
|
||||
expect(service.getRunnerEnvironment(runner.id)).toBeUndefined()
|
||||
await service.registerConnection(authenticated, connection.ws)
|
||||
const environment = { platform: 'win32', shell: 'C:\\Windows\\System32\\cmd.exe' }
|
||||
const reconcile = {
|
||||
type: 'reconcile',
|
||||
environment,
|
||||
activeExecutions: [],
|
||||
completedExecutions: [],
|
||||
}
|
||||
service.handleMessage(runner.id, connection.ws, JSON.stringify(reconcile))
|
||||
expect(service.getRunnerEnvironment(runner.id)).toEqual(environment)
|
||||
service.handleMessage(
|
||||
runner.id,
|
||||
connection.ws,
|
||||
JSON.stringify({ ...reconcile, environment: { platform: 'invalid', shell: '' } }),
|
||||
)
|
||||
expect(service.getRunnerEnvironment(runner.id)).toEqual(environment)
|
||||
const replacement = createMockWs()
|
||||
await service.registerConnection(authenticated, replacement.ws)
|
||||
service.handleMessage(runner.id, connection.ws, JSON.stringify(reconcile))
|
||||
expect(service.getRunnerEnvironment(runner.id)).toBeUndefined()
|
||||
service.handleMessage(runner.id, replacement.ws, JSON.stringify(reconcile))
|
||||
service.handleDisconnect(runner.id, replacement.ws)
|
||||
expect(service.getRunnerEnvironment(runner.id)).toBeUndefined()
|
||||
})
|
||||
|
||||
it('generates and hashes runner keys', () => {
|
||||
const { key, keyPrefix, keyHash } = generateRunnerKey()
|
||||
expect(key).toMatch(/^shm_rn_[0-9a-f]{48}$/)
|
||||
@@ -599,6 +634,7 @@ describe('RunnerService', () => {
|
||||
conn2.ws,
|
||||
JSON.stringify({
|
||||
type: 'reconcile',
|
||||
environment: { platform: 'linux', shell: '/bin/sh' },
|
||||
activeExecutions: [{ executionId: startMsg.executionId, nextOffset: 0 }],
|
||||
completedExecutions: [],
|
||||
}),
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
RunnerFileStatResultMessage,
|
||||
RunnerFileUploadResultMessage,
|
||||
RunnerInfo,
|
||||
RunnerEnvironment,
|
||||
RunnerToServerMessage,
|
||||
runnerToServerMessageSchema,
|
||||
ServerToRunnerMessage,
|
||||
@@ -42,6 +43,7 @@ interface ActiveRunnerSession {
|
||||
lastPongAt: number
|
||||
stagedSkills: Map<string, string>
|
||||
stagedGeneratedFiles: Set<string>
|
||||
environment?: RunnerEnvironment
|
||||
}
|
||||
|
||||
interface PendingExecOperation {
|
||||
@@ -174,6 +176,10 @@ export class RunnerService {
|
||||
return this.sessions.has(runnerId)
|
||||
}
|
||||
|
||||
getRunnerEnvironment(runnerId: string): RunnerEnvironment | undefined {
|
||||
return this.sessions.get(runnerId)?.environment
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Runner CRUD & Default Runner Invariant
|
||||
// ----------------------------------------------------------------------
|
||||
@@ -428,11 +434,11 @@ export class RunnerService {
|
||||
if (!this.isRunnerConnected(resolved.runner.id)) {
|
||||
if (resolved.isBoundToAgent) {
|
||||
throw new Error(
|
||||
`Runner "${resolved.runner.name}" is currently offline. Please start the runner ("shumai runner start") and try again.`,
|
||||
`Runner "${resolved.runner.name}" is currently offline. Please start the runner ("shumai-cli runner start") and try again.`,
|
||||
)
|
||||
}
|
||||
throw new Error(
|
||||
`Default runner "${resolved.runner.name}" is currently offline. Please start the runner ("shumai runner start") and try again.`,
|
||||
`Default runner "${resolved.runner.name}" is currently offline. Please start the runner ("shumai-cli runner start") and try again.`,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -559,6 +565,7 @@ export class RunnerService {
|
||||
case 'pong':
|
||||
break
|
||||
case 'reconcile':
|
||||
session.environment = msg.environment
|
||||
this.handleReconcileMessage(session, msg)
|
||||
break
|
||||
case 'exec.output':
|
||||
|
||||
Reference in New Issue
Block a user