mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat(ocm): let the assistant clone repos through POST /repos
This commit is contained in:
1 parent
33be4afeb7
commit
c9be507f4e
16 files changed
+127
-20
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import { Hono } from 'hono'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { createInternalRoutes } from '../../src/routes/internal'
|
||||
@@ -45,7 +46,7 @@ describe('internal/assistant routes', () => {
|
||||
notificationService = new NotificationService(db)
|
||||
settingsService = new SettingsService(db)
|
||||
app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
token = getOrCreateInternalToken(db)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'bun:test'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import { Hono } from 'hono'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { createInternalRoutes } from '../../src/routes/internal'
|
||||
@@ -31,7 +32,7 @@ describe('internal/notifications routes', () => {
|
||||
notificationService = new NotificationService(db)
|
||||
settingsService = new SettingsService(db)
|
||||
app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
token = getOrCreateInternalToken(db)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'bun:test'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import { Hono } from 'hono'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { readFile, writeFile } from 'fs/promises'
|
||||
@@ -61,7 +62,7 @@ describe('internal/opencode-config routes', () => {
|
||||
const notificationService = new NotificationService(db)
|
||||
const settingsService = new SettingsService(db)
|
||||
app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
token = getOrCreateInternalToken(db)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import { Hono } from 'hono'
|
||||
import type { Database } from 'bun:sqlite'
|
||||
import { createInternalRoutes } from '../../src/routes/internal'
|
||||
@@ -84,7 +85,7 @@ describe('internal-opencode-workspaces routes', () => {
|
||||
forwardRaw: vi.fn(),
|
||||
} as unknown as OpenCodeClient
|
||||
app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(mockDb, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(mockDb, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
token = 'test-internal-token'
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import { Hono } from 'hono'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { createInternalRoutes } from '../../src/routes/internal'
|
||||
@@ -32,7 +33,7 @@ describe('internal-repos routes', () => {
|
||||
notificationService = new NotificationService(db)
|
||||
settingsService = new SettingsService(db)
|
||||
app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
token = getOrCreateInternalToken(db)
|
||||
})
|
||||
|
||||
@@ -109,6 +110,46 @@ describe('internal-repos routes', () => {
|
||||
expect(body.repos[1]?.id).toBe(repo1.id)
|
||||
})
|
||||
|
||||
it('POST /api/internal/repos returns 401 without bearer token', async () => {
|
||||
const res = await app.request('/api/internal/repos', {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ repoUrl: 'https://github.com/owner/name' }),
|
||||
})
|
||||
expect(res.status).toBe(401)
|
||||
})
|
||||
|
||||
it('POST /api/internal/repos rejects a missing repoUrl, unknown keys, and invalid JSON', async () => {
|
||||
const bodies = [JSON.stringify({}), JSON.stringify({ repoUrl: 'https://github.com/owner/name', localPath: '/etc' }), 'not json']
|
||||
for (const body of bodies) {
|
||||
const res = await app.request('/api/internal/repos', {
|
||||
method: 'POST',
|
||||
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
|
||||
body,
|
||||
})
|
||||
expect(res.status).toBe(400)
|
||||
}
|
||||
})
|
||||
|
||||
it('POST /api/internal/repos returns the already registered repo for the same URL', async () => {
|
||||
const existing = createRepo(db, {
|
||||
repoUrl: 'https://github.com/owner/name',
|
||||
localPath: 'name',
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready',
|
||||
clonedAt: Date.now(),
|
||||
})
|
||||
|
||||
const res = await app.request('/api/internal/repos', {
|
||||
method: 'POST',
|
||||
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ repoUrl: 'https://github.com/owner/name.git' }),
|
||||
})
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json() as { id: number }
|
||||
expect(body.id).toBe(existing.id)
|
||||
})
|
||||
|
||||
it('GET /api/internal/repos/:id/schedules still works after adding repos route', async () => {
|
||||
const repoInput: CreateRepoInput = {
|
||||
localPath: 'test-repo',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, mock, vi } from 'bun:test'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import { Hono } from 'hono'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { mkdirSync, rmSync } from 'node:fs'
|
||||
@@ -95,7 +96,7 @@ describe('internal sandbox routes', () => {
|
||||
const notificationService = new NotificationService(db)
|
||||
settingsService = new SettingsService(db)
|
||||
app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
token = getOrCreateInternalToken(db)
|
||||
repoDir = path.join(getReposPath(), 'sandbox-route-test')
|
||||
mkdirSync(repoDir, { recursive: true })
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import { Hono } from 'hono'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { createInternalRoutes } from '../../src/routes/internal'
|
||||
@@ -30,7 +31,7 @@ describe('internal-schedules routes', () => {
|
||||
notificationService = new NotificationService(db)
|
||||
settingsService = new SettingsService(db)
|
||||
app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
token = getOrCreateInternalToken(db)
|
||||
})
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { SettingsService } from '../../src/services/settings'
|
||||
import type { OpenCodeClient } from '../../src/services/opencode/client'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import type { Repo } from '../../src/types/repo'
|
||||
|
||||
const mockDb = {
|
||||
@@ -157,7 +158,7 @@ describe('internal-sessions routes', () => {
|
||||
app = new Hono()
|
||||
app.route(
|
||||
'/api/internal',
|
||||
createInternalRoutes(mockDb, scheduleService, notificationService, settingsService, openCodeClient, permissionModes, {} as unknown as RepoWorkspaceService),
|
||||
createInternalRoutes(mockDb, scheduleService, notificationService, settingsService, openCodeClient, permissionModes, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService),
|
||||
)
|
||||
token = 'test-internal-token'
|
||||
})
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, beforeEach } from 'bun:test'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import { Hono } from 'hono'
|
||||
import { Database } from 'bun:sqlite'
|
||||
import { createInternalRoutes } from '../../src/routes/internal'
|
||||
@@ -31,7 +32,7 @@ describe('internal/settings routes', () => {
|
||||
notificationService = new NotificationService(db)
|
||||
settingsService = new SettingsService(db)
|
||||
app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, openCodeClient, {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
token = getOrCreateInternalToken(db)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it, beforeEach, afterEach } from 'bun:test'
|
||||
import type { SessionPermissionModeService } from '../../src/services/session-permission-modes'
|
||||
import type { RepoWorkspaceService } from '../../src/services/repo-workspace'
|
||||
import type { GitAuthService } from '../../src/services/git-auth'
|
||||
import path from 'path'
|
||||
import { access, readFile, writeFile } from 'fs/promises'
|
||||
import { Hono } from 'hono'
|
||||
@@ -310,7 +311,7 @@ describe('ensureAssistantMode', () => {
|
||||
|
||||
const reposSkillContent = await readFile(reposSkillPath, 'utf8')
|
||||
expect(reposSkillContent).toContain('name: repo-management')
|
||||
expect(reposSkillContent).toContain('List repos available')
|
||||
expect(reposSkillContent).toContain('List and clone repos')
|
||||
|
||||
const sessionsSkillContent = await readFile(sessionsSkillPath, 'utf8')
|
||||
expect(sessionsSkillContent).toContain('name: session-management')
|
||||
@@ -687,7 +688,7 @@ describe('assistant-mode end-to-end', () => {
|
||||
const notificationService = new NotificationService(db)
|
||||
const settingsService = new SettingsService(db)
|
||||
const app = new Hono()
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, createOpenCodeClient(), {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService))
|
||||
app.route('/api/internal', createInternalRoutes(db, scheduleService, notificationService, settingsService, createOpenCodeClient(), {} as SessionPermissionModeService, {} as unknown as RepoWorkspaceService, {} as unknown as GitAuthService))
|
||||
|
||||
const unauth = await app.request('/api/internal/schedules/all')
|
||||
expect(unauth.status).toBe(401)
|
||||
|
||||
Reference in new issue
Block a user