mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
loop: om-179-finish-adopting-op completed after 19 iterations
This commit is contained in:
1 parent
7c4cfd858c
commit
49bb4ebd36
25 files changed
+362
-198
No files matched your search
@@ -236,6 +236,23 @@ describe('opencode server proxy routes', () => {
|
||||
expect(receivedSignal?.aborted).toBe(false)
|
||||
})
|
||||
|
||||
it('does not time out a bodyless POST that takes longer than the headers timeout', async () => {
|
||||
let receivedSignal: AbortSignal | null | undefined
|
||||
const fetchMock = vi.fn(async (_url: string, init: RequestInit) => {
|
||||
receivedSignal = init.signal
|
||||
await new Promise((resolve) => setTimeout(resolve, 40))
|
||||
return new Response('ok', { status: 200 })
|
||||
})
|
||||
const app = buildApp(fetchMock as unknown as typeof fetch, passThroughAuth, 10)
|
||||
|
||||
const res = await app.request('/api/opencode/servers/srv_1/api/session/ses_1/abort', {
|
||||
method: 'POST',
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(receivedSignal?.aborted).toBe(false)
|
||||
})
|
||||
|
||||
it('keeps streaming the upstream body after headers arrive', async () => {
|
||||
const encoder = new TextEncoder()
|
||||
let receivedSignal: AbortSignal | null | undefined
|
||||
|
||||
@@ -162,6 +162,15 @@ describe('buildSettingsSkill', () => {
|
||||
expect(skill).toContain('never copy this response into a save')
|
||||
})
|
||||
|
||||
it('names v2 config keys and documents the unreachable server response', () => {
|
||||
const skill = buildSettingsSkill()
|
||||
expect(skill).toContain('`plugins`')
|
||||
expect(skill).toContain('`mcp.servers`')
|
||||
expect(skill).toContain('`providers`')
|
||||
expect(skill).not.toContain('including `plugin`')
|
||||
expect(skill).toContain('GET /opencode-config/mcp returns `503`')
|
||||
})
|
||||
|
||||
it('documents the assistant reload as rebuilding every loaded location', () => {
|
||||
const skill = buildSettingsSkill()
|
||||
expect(skill).toContain('rebuilding every loaded location')
|
||||
@@ -445,6 +454,22 @@ describe('ensureAssistantMode', () => {
|
||||
expect(result.files.opencodeJson?.created).toBe(false)
|
||||
})
|
||||
|
||||
it('writes the generated v2 config over a v1 config when overwrite is requested', async () => {
|
||||
await ensureAssistantMode(mockRepo)
|
||||
const opencodeJsonPath = path.join(ws.assistantDir, 'opencode.json')
|
||||
const v1Config = `{
|
||||
"permission": { "read": "allow", "shell": "ask" },
|
||||
"agent": { "assistant": { "mode": "primary", "prompt": "Custom v1 prompt" } }
|
||||
}
|
||||
`
|
||||
await writeFile(opencodeJsonPath, v1Config)
|
||||
|
||||
const result = await ensureAssistantMode(mockRepo, { overwriteOpenCodeConfig: true })
|
||||
|
||||
expect(JSON.parse(await readFile(opencodeJsonPath, 'utf8'))).toEqual(buildAssistantOpenCodeConfig())
|
||||
expect(result.files.opencodeJson?.created).toBe(true)
|
||||
})
|
||||
|
||||
it('migrates generated legacy AGENTS.md and assistant.md to the new split', async () => {
|
||||
await ensureAssistantMode(mockRepo)
|
||||
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { getWorkspacePath } from '@opencode-manager/shared/config/env'
|
||||
import { ClientError, openCodeLocation, type OpenCodeApi } from '@opencode-manager/shared/opencode'
|
||||
import { readManagedOpenCodeConfig } from '../../src/services/opencode-config-effective'
|
||||
import { readManagedOpenCodeConfig, readOpenCodeConfigDocuments } from '../../src/services/opencode-config-effective'
|
||||
|
||||
function stubApi(entries: unknown[]) {
|
||||
const get = vi.fn(async () => entries)
|
||||
return { api: { config: { get } } as unknown as OpenCodeApi, get }
|
||||
}
|
||||
|
||||
describe('readOpenCodeConfigDocuments', () => {
|
||||
it('keys document entries by resolved path for the requested directory', async () => {
|
||||
const { api, get } = stubApi([
|
||||
{ type: 'document', path: '/directory/./opencode.json', info: { theme: 'dark' } },
|
||||
{ type: 'document', info: { theme: 'pathless' } },
|
||||
{ type: 'directory', path: '/directory' },
|
||||
])
|
||||
|
||||
const documents = await readOpenCodeConfigDocuments(api, '/directory')
|
||||
|
||||
expect([...documents.keys()]).toEqual(['/directory/opencode.json'])
|
||||
expect(documents.get('/directory/opencode.json')).toEqual({ theme: 'dark' })
|
||||
expect(get).toHaveBeenCalledWith(openCodeLocation('/directory'))
|
||||
})
|
||||
})
|
||||
|
||||
describe('readManagedOpenCodeConfig', () => {
|
||||
it('merges only the documents whose path is a Manager source, in source order', async () => {
|
||||
const { api, get } = stubApi([
|
||||
|
||||
@@ -833,6 +833,60 @@ describe('opencode-config-file', () => {
|
||||
expect(onDisk).toContain('// keep this comment')
|
||||
})
|
||||
|
||||
it('keeps the v2 mcp timeout when saving an MCP server named like a v2 mcp key', async () => {
|
||||
await writeFile(
|
||||
sourcePath('opencode.json'),
|
||||
JSON.stringify({ mcp: { timeout: { connect: 5000 }, servers: {} } }),
|
||||
'utf8',
|
||||
)
|
||||
|
||||
const updated = await updateOpenCodeConfigFile(
|
||||
{ mcp: { servers: { timeout: { type: 'remote', url: 'https://timeout.example.com' } } } },
|
||||
{ mode: 'merge' },
|
||||
)
|
||||
|
||||
expect(updated.content).toEqual({
|
||||
mcp: {
|
||||
timeout: { connect: 5000 },
|
||||
servers: { timeout: { type: 'remote', url: 'https://timeout.example.com' } },
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the v2 mcp servers when saving an MCP server named like the v2 servers map', async () => {
|
||||
await writeFile(
|
||||
sourcePath('opencode.json'),
|
||||
JSON.stringify({ mcp: { servers: { linear: { type: 'remote', url: 'https://linear.example.com' } } } }),
|
||||
'utf8',
|
||||
)
|
||||
|
||||
const updated = await updateOpenCodeConfigFile(
|
||||
{ mcp: { servers: { servers: { type: 'remote', url: 'https://s.example.com' } } } },
|
||||
{ mode: 'merge' },
|
||||
)
|
||||
|
||||
expect(updated.content).toEqual({
|
||||
mcp: {
|
||||
servers: {
|
||||
linear: { type: 'remote', url: 'https://linear.example.com' },
|
||||
servers: { type: 'remote', url: 'https://s.example.com' },
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the v2 mcp object when the whole servers map is removed', async () => {
|
||||
await writeFile(
|
||||
sourcePath('opencode.json'),
|
||||
JSON.stringify({ mcp: { timeout: { connect: 5000 }, servers: { linear: { type: 'remote', url: 'https://linear.example.com' } } } }),
|
||||
'utf8',
|
||||
)
|
||||
|
||||
const updated = await updateOpenCodeConfigFile({ mcp: { servers: null } }, { mode: 'merge' })
|
||||
|
||||
expect(updated.content).toEqual({ mcp: { timeout: { connect: 5000 } } })
|
||||
})
|
||||
|
||||
it('keeps a comment that leads the sibling after the removed v1 container', async () => {
|
||||
const raw = '{\n // lead\n "agent": {"reviewer":{"description":"Legacy reviewer"}},\n // theme comment\n "theme": "dark"\n}\n'
|
||||
await writeFile(sourcePath('opencode.json'), raw, 'utf8')
|
||||
|
||||
@@ -45,13 +45,12 @@ const deletedSession = {
|
||||
} satisfies V2Event
|
||||
|
||||
describe('routeOpenCodeEvent', () => {
|
||||
it('serializes the event payload and remembers its directory by session', () => {
|
||||
it('remembers the directory of a located event by session', () => {
|
||||
const directories = new Map<string, string>()
|
||||
|
||||
const routed = routeOpenCodeEvent(locatedStatus, directories)
|
||||
|
||||
expect(routed.event).toBe(locatedStatus)
|
||||
expect(routed.payloadJson).toBe(JSON.stringify(locatedStatus))
|
||||
expect(routed.directory).toBe('/work/alpha')
|
||||
expect(routed.resolvedDirectory).toBe('/work/alpha')
|
||||
expect(directories.get('ses_1')).toBe('/work/alpha')
|
||||
|
||||
@@ -67,9 +67,13 @@ async function flushReplay(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const PAYLOAD = '{"id":"evt_1","created":1,"type":"session.idle","location":{"directory":"/repo"},"data":{"sessionID":"ses_1"}}'
|
||||
|
||||
const LOCAL_EVENT = JSON.parse(PAYLOAD) as V2Event
|
||||
const LOCAL_EVENT = {
|
||||
id: 'evt_1',
|
||||
created: 1,
|
||||
type: 'session.idle',
|
||||
location: { directory: '/repo' },
|
||||
data: { sessionID: 'ses_1' },
|
||||
} satisfies V2Event
|
||||
|
||||
describe('SSEAggregator remote envelope delivery', () => {
|
||||
beforeEach(() => {
|
||||
@@ -90,9 +94,9 @@ describe('SSEAggregator remote envelope delivery', () => {
|
||||
sseAggregator.addClient('local-dir', local.callback, local.writeFrame, ['/repo'])
|
||||
sseAggregator.addClient('no-directories', unsubscribed.callback, unsubscribed.writeFrame, [])
|
||||
|
||||
sseAggregator.deliverRemoteEnvelope('srv_a', '/repo', PAYLOAD)
|
||||
sseAggregator.deliverRemoteEnvelope('srv_a', '/repo', LOCAL_EVENT)
|
||||
|
||||
const expected = { directory: '/repo', serverId: 'srv_a', payload: JSON.parse(PAYLOAD) }
|
||||
const expected = { directory: '/repo', serverId: 'srv_a', payload: LOCAL_EVENT }
|
||||
expect(subscribed.frames.map(parseFrame)).toEqual([expected])
|
||||
expect(otherDirectory.frames.map(parseFrame)).toEqual([expected])
|
||||
expect(otherServer.frames.map(parseFrame)).toEqual([expected])
|
||||
@@ -110,9 +114,9 @@ describe('SSEAggregator remote envelope delivery', () => {
|
||||
sseAggregator.addClient('any-c', otherServer.callback, otherServer.writeFrame, ['srv_b|/repo'])
|
||||
sseAggregator.addClient('any-d', local.callback, local.writeFrame, ['/repo'])
|
||||
|
||||
sseAggregator.deliverRemoteEnvelope('srv_a', null, PAYLOAD)
|
||||
sseAggregator.deliverRemoteEnvelope('srv_a', null, LOCAL_EVENT)
|
||||
|
||||
const expected = { directory: null, serverId: 'srv_a', payload: JSON.parse(PAYLOAD) }
|
||||
const expected = { directory: null, serverId: 'srv_a', payload: LOCAL_EVENT }
|
||||
expect(first.frames.map(parseFrame)).toEqual([expected])
|
||||
expect(second.frames.map(parseFrame)).toEqual([expected])
|
||||
expect(otherServer.frames.map(parseFrame)).toEqual([expected])
|
||||
@@ -124,7 +128,7 @@ describe('SSEAggregator remote envelope delivery', () => {
|
||||
sseAggregator.addClient('targeted', client.callback, client.writeFrame, ['srv_a|/repo'])
|
||||
sseAggregator.removeDirectories('targeted', ['srv_a|/repo'])
|
||||
|
||||
sseAggregator.deliverRemoteEnvelopeToClient('targeted', 'srv_a', '/repo', PAYLOAD)
|
||||
sseAggregator.deliverRemoteEnvelopeToClient('targeted', 'srv_a', '/repo', LOCAL_EVENT)
|
||||
|
||||
expect(client.frames).toHaveLength(0)
|
||||
})
|
||||
@@ -133,10 +137,10 @@ describe('SSEAggregator remote envelope delivery', () => {
|
||||
const client = createCapturingClient()
|
||||
sseAggregator.addClient('targeted-ok', client.callback, client.writeFrame, ['srv_a|/repo'])
|
||||
|
||||
sseAggregator.deliverRemoteEnvelopeToClient('targeted-ok', 'srv_a', '/repo', PAYLOAD)
|
||||
sseAggregator.deliverRemoteEnvelopeToClient('targeted-ok', 'srv_a', '/repo', LOCAL_EVENT)
|
||||
|
||||
expect(client.frames.map(parseFrame)).toEqual([
|
||||
{ directory: '/repo', serverId: 'srv_a', payload: JSON.parse(PAYLOAD) },
|
||||
{ directory: '/repo', serverId: 'srv_a', payload: LOCAL_EVENT },
|
||||
])
|
||||
})
|
||||
|
||||
@@ -218,8 +222,21 @@ describe('SSEAggregator remote envelope delivery', () => {
|
||||
sseAggregator.addClient('removed', client.callback, client.writeFrame, ['srv_a|/repo'])
|
||||
sseAggregator.removeClient('removed')
|
||||
|
||||
sseAggregator.deliverRemoteEnvelope('srv_a', null, PAYLOAD)
|
||||
sseAggregator.deliverRemoteEnvelope('srv_a', null, LOCAL_EVENT)
|
||||
|
||||
expect(client.frames).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('does not serialize an envelope that no client receives', () => {
|
||||
const stringify = vi.spyOn(JSON, 'stringify')
|
||||
|
||||
try {
|
||||
sseAggregator.deliverRemoteEnvelope('srv_a', '/repo', LOCAL_EVENT)
|
||||
sseAggregator.deliverRemoteEnvelopeToClient('absent', 'srv_a', '/repo', LOCAL_EVENT)
|
||||
|
||||
expect(stringify).not.toHaveBeenCalledWith(LOCAL_EVENT)
|
||||
} finally {
|
||||
stringify.mockRestore()
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user