feat(commands): multi-select ordered command pipeline with step reordering and single-pass composition (AI-05, AI-07)

This commit is contained in:
Yun Chan 2026-10-31 02:54:54 +09:00
parent f49acf0105
commit 10af20a0ad
157 changed files with 29455 additions and 913 deletions

View file

@ -1,6 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ErrorCode } from '@d3ro/core/errors'
import { initInMemoryConfig, resetInMemoryConfig } from '../../../src/main/services/ConfigService'
import { configSet, initInMemoryConfig, resetInMemoryConfig } from '../../../src/main/services/ConfigService'
import { availableParallelism } from 'node:os'
import { inferenceCpuThreads } from '../../../src/main/utils/inference-cpu-budget'
import {
getLocalLLMService,
resetLocalLLMServiceForTests,
@ -44,6 +46,36 @@ describe('LocalLLMService request lifecycle', () => {
vi.useRealTimers()
})
it.each(['http://127.0.0.1:11434', 'http://192.168.1.2:11434'])(
'applies CPU headroom across generate, warm-up streaming and chat only for loopback (%s)', async (serverUrl) => {
configSet('ollamaServerUrl', serverUrl)
const bodies: Array<{ options: { num_thread?: number }; stream: boolean }> = []
vi.stubGlobal('fetch', vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
const body = JSON.parse(String(init?.body)) as (typeof bodies)[number]
bodies.push(body)
if (!body.stream) return completedGenerateResponse()
const frame = String(input).endsWith('/api/chat')
? { message: { content: 'ok' }, done: true }
: { model: 'gemma4:e4b', response: 'ok', done: true }
return new Response(completedStream([JSON.stringify(frame)]), { status: 200 })
}))
const service = getLocalLLMService()
await service.generate('hello')
for await (const token of service.streamGenerate('hi', { maxTokens: 1 })) void token
for await (const token of service.chatStream([{ role: 'user', content: 'hello' }])) void token
expect(bodies).toHaveLength(3)
for (const body of bodies) {
if (serverUrl.includes('127.0.0.1')) {
expect(body.options.num_thread).toBe(inferenceCpuThreads(availableParallelism()))
} else {
expect(body.options).not.toHaveProperty('num_thread')
}
}
}
)
it('sends the bounded default num_predict to chat requests', async () => {
const cancel = vi.fn()
const fetchMock = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {