mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix: refuse entity saves while a restart is pending and share replay payloads (OM-179)
This commit is contained in:
1 parent
8a6fd56e9a
commit
9fca96ecea
9 files changed
+82
-20
No files matched your search
@@ -558,7 +558,7 @@ describe('internal/opencode-config routes', () => {
|
||||
|
||||
it('GET /api/internal/opencode-config/managed merges only Manager source documents and redacts secrets', async () => {
|
||||
await writeOpenCodeConfigFile(JSON.stringify({ theme: 'light' }), 'opencode.json')
|
||||
const snapshot = await writeOpenCodeConfigFile(JSON.stringify({ theme: 'dark' }), 'opencode.jsonc')
|
||||
await writeOpenCodeConfigFile(JSON.stringify({ theme: 'dark' }), 'opencode.jsonc')
|
||||
configGetMock.mockImplementation(() => Promise.resolve([
|
||||
{
|
||||
type: 'document',
|
||||
@@ -585,7 +585,6 @@ describe('internal/opencode-config routes', () => {
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toEqual({
|
||||
revision: snapshot.revision,
|
||||
info: {
|
||||
theme: 'dark',
|
||||
providers: { example: { apiKey: '<redacted>' } },
|
||||
|
||||
@@ -476,7 +476,6 @@ describe('Settings Routes - OpenCode Upgrade', () => {
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(await res.json()).toEqual({
|
||||
revision: 'rev-managed',
|
||||
info: { theme: 'dark', model: 'a/b' },
|
||||
})
|
||||
expect(configGet).toHaveBeenCalledWith({ location: { directory: '/tmp/test-workspace' } })
|
||||
@@ -612,6 +611,21 @@ describe('Settings Routes - OpenCode Upgrade', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('refuses a PATCH entity save with 409 while an OpenCode restart is pending', async () => {
|
||||
vi.mocked(opencodeServerManager.isRestartPending).mockReturnValueOnce(true)
|
||||
|
||||
const res = await settingsApp.fetch(new Request('http://localhost/opencode-config', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ patch: { agents: { reviewer: { description: 'stale' } } } }),
|
||||
}))
|
||||
const json = await res.json() as Record<string, unknown>
|
||||
|
||||
expect(res.status).toBe(409)
|
||||
expect(json.error).toContain('Restart OpenCode')
|
||||
expect(mockApplyOpenCodeConfigUpdate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('returns 400 when the PUT body fails schema validation', async () => {
|
||||
const res = await settingsApp.fetch(new Request('http://localhost/opencode-config', {
|
||||
method: 'PUT',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { V2Event } from '@opencode-manager/shared/opencode'
|
||||
import { createReplayEventBuilder, routeOpenCodeEvent } from '../../src/services/opencode-event-routing'
|
||||
import { buildSessionStatusReplayEvent, createReplayEventBuilder, routeOpenCodeEvent } from '../../src/services/opencode-event-routing'
|
||||
|
||||
const locatedStatus = {
|
||||
id: 'evt_status_located',
|
||||
@@ -118,3 +118,36 @@ describe('createReplayEventBuilder', () => {
|
||||
expect([permission.id, form.id, status.id]).toEqual(['replay_1', 'replay_2', 'replay_3'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('buildSessionStatusReplayEvent', () => {
|
||||
it('builds idle and busy session status replays through the hub builder', () => {
|
||||
const buildEvent = createReplayEventBuilder('ocm_replay_')
|
||||
|
||||
const idle = buildSessionStatusReplayEvent(buildEvent, '/work/alpha', 'ses_1', 'idle')
|
||||
const busy = buildSessionStatusReplayEvent(buildEvent, '/work/beta', 'ses_2', 'busy')
|
||||
|
||||
expect(idle).toEqual({
|
||||
id: 'ocm_replay_1',
|
||||
created: expect.any(Number),
|
||||
type: 'session.status',
|
||||
location: { directory: '/work/alpha' },
|
||||
data: { sessionID: 'ses_1', status: { type: 'idle' } },
|
||||
})
|
||||
expect(busy).toEqual({
|
||||
id: 'ocm_replay_2',
|
||||
created: expect.any(Number),
|
||||
type: 'session.status',
|
||||
location: { directory: '/work/beta' },
|
||||
data: { sessionID: 'ses_2', status: { type: 'busy' } },
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the directory and id prefix owned by the caller', () => {
|
||||
const buildEvent = createReplayEventBuilder('ocm_replay_remote_')
|
||||
|
||||
const event = buildSessionStatusReplayEvent(buildEvent, '', 'ses_1', 'busy')
|
||||
|
||||
expect(event.id).toBe('ocm_replay_remote_1')
|
||||
expect(event.location?.directory).toBe('')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user