Files
goodbuddy/src/main/agent/ripgrep-provider.test.ts
T
mesalogo d80d42b032 feat(storage): move desktop SQLite ownership into a storage utility process
Main no longer opens desktop business SQLite. A single utility-process
storage owner holds the Assistant, Knowledge, attachment, document-result,
remote-binding and native model-ledger databases and runs whole domain
transactions; Main and Runtime callers use explicit async domain operations.

- Remove the Main readWithFallback path and the supervision worker's
  separate business write connection; manifests are scanned read-only and
  committed by the sole writer.
- Remote events are ACKed only after commit; process loss reports
  unconfirmed writes instead of replaying them.
- Use native utilityProcess messaging with one in-flight bound (32) and
  ordered waiting instead of capacity rejection and retries.
- Start the storage process before the window so startup overlaps.
- Keep short tool output in memory and store full output once in owned
  storage; paging, branching, restart and deletion reuse that copy.
- Put required runtime launch files under goodbuddy-prefixed owned temp
  directories and reclaim confirmed stale ones; stop writing duplicate
  parsed.md.
- Add lint guards for SQLite ownership and architecture, concurrency
  acceptance fixtures, and maintenance/architecture documentation.

Validation: typecheck and lint pass. Alternating baseline (edf019aa) vs
candidate runs show no regression on single-session, C01, C02, C04 and a
5-minute C06; Main p99 drops from ~21 ms to ~16.7 ms under concurrency.
Fresh portable copy (1.75M events) upgrade content unchanged; real-model
output paging passes with 4 external requests. Full npm test runs had
1-9 different timing-sensitive failures per run that pass when rerun.
Not covered: C03 review publication, C07 source body, app-level C05.
2026-10-06 15:40:18 +08:00

58 lines
2.9 KiB
TypeScript

import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { rgPath } from '@vscode/ripgrep'
import { expect, it } from 'vitest'
import { FileOutputBacking, outputFixtureRoot } from '../../../tests/support/paged-output-backing'
import { ModelToolProvider, type ModelToolResult } from './model-tool-provider'
it('pages native rg output through the production provider and releases it', async () => {
await mkdir(outputFixtureRoot, { recursive: true })
const root = await mkdtemp(join(tmpdir(), 'goodbuddy-rg-provider-'))
const backingStore = new FileOutputBacking()
const provider = new ModelToolProvider(root, [], undefined, undefined, false, {
ripgrepExecutablePath: rgPath,
outputStore: { backingStore }
})
const context = { conversationId: 'rg-pages', runtimeTarget: 'model' as const, }
const signal = new AbortController().signal
const parse = (result: ModelToolResult) => {
expect(result.contextBytes).toBeLessThanOrEqual(256 * 1024)
const part = result.parts[0]!
if (part.type !== 'text') throw new Error('Expected text')
return JSON.parse(part.text)
}
try {
const text = 'target 你好\\"'.repeat(30_000) + 'tail\n'
await writeFile(join(root, 'large.txt'), text)
expect(await provider.listTools(context, signal)).toEqual(expect.arrayContaining([
expect.objectContaining({ name: 'workspace_rg', inputSchema: expect.objectContaining({ required: ['args'] }) }),
expect.objectContaining({ name: 'output_read' })
]))
const result = parse(await provider.callTool('workspace_rg', { args: ['--no-line-number', 'target', 'large.txt'] }, signal, context))
let output = result.stdout
const reference = result.stdoutReference
let cursor = reference.nextCursor
while (cursor < reference.totalBytes) {
const page = parse(await provider.callTool('output_read', { handle: reference.handle, cursor }, signal, context))
output += page.content
expect(page.nextCursor).toBeGreaterThan(cursor)
cursor = page.nextCursor
}
expect(output).toBe(text)
const error = parse(await provider.callTool('workspace_rg', { args: ['[', '.'] }, signal, context))
expect(error).toMatchObject({ exitCode: 2, stderr: expect.stringContaining('regex parse error') })
const preprocessed = parse(await provider.callTool('workspace_rg', {
args: ['--pre=goodbuddy-nonexistent-preprocessor', 'target', 'large.txt']
}, signal, context))
expect(preprocessed.exitCode).toBe(2)
expect(preprocessed.stderr).toContain('goodbuddy-nonexistent-preprocessor')
await provider.releaseConversation(context.conversationId)
await expect(provider.callTool('output_read', { handle: reference.handle }, signal, context)).rejects.toThrow('不存在')
} finally {
await provider.dispose()
await backingStore.dispose()
await rm(root, { recursive: true, force: true })
}
})