Isolate test state and inject the restart-pending check into config routes

This commit is contained in:
Chris Scott committed 2026-11-13 03:26:58 -05:00
1 parent 26fd21250a
commit 76ca65ec5e
10 files changed
+39 -37

No files matched your search

+3 -1
View File
@@ -33,6 +33,7 @@ import { logger } from '../utils/logger'
interface OpenCodeConfigRoutesOptions {
redactSecrets?: boolean
isRestartPending?: () => boolean
}
async function readMcpStatus(openCodeClient: OpenCodeClient): Promise<McpStatusMap> {
@@ -70,6 +71,7 @@ export function createOpenCodeConfigRoutes(
options: OpenCodeConfigRoutesOptions = {},
) {
const app = new Hono()
const isRestartPending = options.isRestartPending ?? (() => opencodeServerManager.isRestartPending())
app.get('/', async (c) => {
try {
@@ -173,7 +175,7 @@ export function createOpenCodeConfigRoutes(
return c.json({ error: 'Invalid config data', details: parsed.error.issues }, 400)
}
if (opencodeServerManager.isRestartPending() && patchNamesOpenCodeConfigEntities(parsed.data.patch)) {
if (isRestartPending() && patchNamesOpenCodeConfigEntities(parsed.data.patch)) {
return c.json({
error: 'OpenCode has not loaded the saved configuration yet. Restart OpenCode before editing entries.',
}, 409)
+1
View File
@@ -65,6 +65,7 @@ function createSettingsDeps(): SettingsRouteDependencies {
clearStartupError: () => undefined,
getLastStartupError: () => null,
markRestartPending: vi.fn(),
isRestartPending: () => false,
restart: async () => undefined,
checkHealth: async () => true,
},
+4 -2
View File
@@ -74,7 +74,7 @@ import {
export interface SettingsRouteDependencies {
openCodeManager: Pick<
typeof opencodeServerManager,
'getVersion' | 'fetchVersion' | 'clearStartupError' | 'getLastStartupError' | 'markRestartPending' | 'restart' | 'checkHealth'
'getVersion' | 'fetchVersion' | 'clearStartupError' | 'getLastStartupError' | 'markRestartPending' | 'isRestartPending' | 'restart' | 'checkHealth'
>
installOpenCodeVersion: (version: string) => Promise<string>
detectSandboxCapability: () => SandboxCapability
@@ -528,7 +528,9 @@ export function createSettingsRoutes(db: Database, gitAuthService: GitAuthServic
}
})
app.route('/opencode-config', createOpenCodeConfigRoutes(settingsService, openCodeClient))
app.route('/opencode-config', createOpenCodeConfigRoutes(settingsService, openCodeClient, {
isRestartPending: () => deps.openCodeManager.isRestartPending(),
}))
app.route('/remote-access-headers', createRemoteAccessHeaderRoutes(new RemoteAccessHeadersService(db)))
app.post('/opencode-restart', async (c) => {
@@ -379,7 +379,7 @@ class OpenCodeServerManager {
this.db = db
}
setOpenCodeClient(client: OpenCodeClient) {
setOpenCodeClient(client: OpenCodeClient | null) {
this.openCodeClient = client
}