fix(walkthrough): address review of agent-opened walkthrough

- Wait for the model catalog once per walkthrough generation instead of before every model call
- Report open_walkthrough as requested, not opened, and drop its unused metadata
- Share the ocm tool and action names through @opencode-manager/shared
- Remove the unused source-request nonce and duplicate session check
- Scan only new messages when auto-opening the walkthrough
- Assert the request action cannot reach the internal change-walkthroughs route
This commit is contained in:
Chris Scott committed 2026-10-09 11:25:26 -04:00
1 parent aa1da8d608
commit c497df5161
14 files changed
+146 -122

No files matched your search

@@ -1252,6 +1252,26 @@ describe('ChangeWalkthroughService', () => {
).toBe(true)
})
it('waits for an explicit model once per generation, not per stop', async () => {
sessions[SESSION_ID]!.changes = LARGE_CHANGES
sessions[SESSION_ID]!.info = {
id: SESSION_ID,
title: 'Title',
model: { providerID: 'openai', id: 'gpt-5-mini' },
} as SessionInfo
fake.setGenerateImpl((prompt) =>
Promise.resolve(prompt.includes(PLAN_MARKER) ? LARGE_PLAN_REPLY : EXPLANATION_REPLY),
)
await service.generate(SESSION_ID, {})
expect(fake.generateModels).toHaveLength(4)
expect(
fake.generateModels.every((model) => model?.providerID === 'openai' && model.id === 'gpt-5-mini'),
).toBe(true)
expect(vi.mocked(fake.client.api.model.list)).toHaveBeenCalledTimes(1)
})
it('includes the resolved default model in the explanation key', async () => {
fake.setGenerateImpl(async () => modelReply([{ title: 'A', explanation: 'x', hunkIds: THREE_HUNK_IDS }]))
@@ -5,8 +5,8 @@ import http from 'http'
import type { AddressInfo } from 'net'
import path from 'path'
import os from 'os'
import { ASSISTANT_NOTIFICATION_LIMITS, AssistantNotificationRequestSchema } from '@opencode-manager/shared/schemas'
import { MANAGER_TOOL_NAME, MANAGER_TOOL_ALLOWED_ROUTES, parseAllowedRoute } from '../../src/services/opencode-manager-tool-plugin'
import { ASSISTANT_NOTIFICATION_LIMITS, AssistantNotificationRequestSchema, MANAGER_TOOL_NAME } from '@opencode-manager/shared/schemas'
import { MANAGER_TOOL_ALLOWED_ROUTES, parseAllowedRoute } from '../../src/services/opencode-manager-tool-plugin'
import { installManagedPlugins, getOpenCodePluginDir } from '../../src/services/opencode/plugin-registry'
import { loadGeneratedPlugin, type GeneratedTool } from '../helpers/opencode-plugin-context'
import { resolveOpenCode2Binary, runOpenCodeStandalone } from '../helpers/opencode-binary'
@@ -132,7 +132,8 @@ describe('ocm-manager plugin', () => {
const tool = await loadTool(configHome)
expect(tool.description).toContain('open_walkthrough')
expect(tool.description).toContain("open the change Walkthrough panel for the current session in the user's Manager window")
expect(tool.description).toContain('request the change Walkthrough for the current session')
expect(tool.description).toContain('when this session is open on desktop')
})
it('enforces the notification limits the internal API enforces', async () => {
@@ -242,8 +243,10 @@ describe('ocm-manager plugin', () => {
expect(init.headers.Authorization).toBe('Bearer secret-token')
expect(init.headers['content-type']).toBe('application/json')
expect(JSON.parse(init.body)).toEqual({ source: { kind: 'staged' } })
expect(result.content).toBe('Opened the walkthrough (2 stops).')
expect(result.metadata).toEqual({ openPanel: 'walkthrough', source: { kind: 'staged' } })
expect(result.content).toBe(
'Requested the walkthrough (2 stops). It opens in the Manager window when this session is open on desktop; otherwise the user can open it from this tool call.',
)
expect(result.metadata).toBeUndefined()
})
it('reports that the walkthrough is generating', async () => {
@@ -252,8 +255,10 @@ describe('ocm-manager plugin', () => {
const result = await runToolResult(tool, { action: 'open_walkthrough', params: {} }, { sessionID: 'ses_abc' })
expect(result.content).toBe('Opened the walkthrough. It is generating; the user can page through it as stops are explained.')
expect(result.metadata).toEqual({ openPanel: 'walkthrough' })
expect(result.content).toBe(
'Requested the walkthrough; it is generating. It opens in the Manager window when this session is open on desktop; otherwise the user can open it from this tool call.',
)
expect(result.metadata).toBeUndefined()
})
it('opens the walkthrough without a body when no source is given', async () => {
@@ -376,6 +381,8 @@ describe('ocm-manager plugin', () => {
['POST', '/multi-runs'],
['POST', '/multi-runs/1/fusions'],
['POST', '/multi-runs/1/entries/2/discard'],
['GET', '/change-walkthroughs/x'],
['POST', '/change-walkthroughs/x'],
] as const
for (const [method, path] of deniedRoutes) {
@@ -3,7 +3,7 @@ import { getOpenCodeGlobalConfigPath } from '@opencode-manager/shared/config/env
import type { ModelInfo, ModelRef } from '@opencode-manager/shared/opencode'
import type { OpenCodeClient } from '../../../src/services/opencode/client'
import { GenerateTextTimeoutError, generateTextWithTimeout } from '../../../src/services/opencode/generate-text'
import { MODEL_LOAD_POLL_MS, MODEL_LOAD_TIMEOUT_MS } from '../../../src/services/opencode-models'
import { MODEL_LOAD_POLL_MS } from '../../../src/services/opencode-models'
interface GenerateCall {
input: { prompt: string; model?: ModelRef }
@@ -77,35 +77,14 @@ describe('generateTextWithTimeout', () => {
expect(calls[0]?.input.model).toEqual({ providerID: 'openai', id: 'gpt-5-mini' })
})
it('waits for the provided model to load before generating', async () => {
vi.useFakeTimers()
const model: ModelRef = { providerID: 'anthropic', id: 'claude-sonnet-4', variant: 'high' }
const { client, calls } = makeClient(async () => ({ text: 'hello' }), [
[],
[{ providerID: 'anthropic', id: 'claude-sonnet-4', enabled: true } as ModelInfo],
])
const promise = generateTextWithTimeout(client, { prompt: 'write', model }, 10_000)
await vi.advanceTimersByTimeAsync(0)
expect(calls).toHaveLength(0)
await vi.advanceTimersByTimeAsync(MODEL_LOAD_POLL_MS)
await expect(promise).resolves.toBe('hello')
expect(calls).toHaveLength(1)
expect(calls[0]?.input).toEqual({ prompt: 'write', model })
})
it('generates with the provided model when its catalog never loads', async () => {
vi.useFakeTimers()
it('forwards the model when provided without reading the catalog', async () => {
const { client, calls, modelList } = makeClient(async () => ({ text: 'hello' }))
const model: ModelRef = { providerID: 'anthropic', id: 'claude-sonnet-4' }
const { client, calls } = makeClient(async () => ({ text: 'hello' }), [[]])
const promise = generateTextWithTimeout(client, { prompt: 'write', model }, 100_000)
await vi.advanceTimersByTimeAsync(MODEL_LOAD_TIMEOUT_MS)
await expect(promise).resolves.toBe('hello')
await generateTextWithTimeout(client, { prompt: 'write', model }, 1000)
expect(calls).toHaveLength(1)
expect(calls[0]?.input).toEqual({ prompt: 'write', model })
expect(modelList).not.toHaveBeenCalled()
})
it('rejects with GenerateTextTimeoutError and aborts the request after the timeout', async () => {