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.
92 lines
4.8 KiB
TypeScript
92 lines
4.8 KiB
TypeScript
import { mkdtemp, mkdir, rm, symlink, writeFile } from 'node:fs/promises'
|
|
import { FileOutputBacking, outputFixtureRoot } from '../../../tests/support/paged-output-backing'
|
|
import { join } from 'node:path'
|
|
import { rgPath } from '@vscode/ripgrep'
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
import { LocalWorkspaceAccess } from '../workspace'
|
|
import { LocalDirectModelProcessService } from './direct-model-process-service'
|
|
import { searchWorkspaceWithRipgrep } from './direct-model-ripgrep'
|
|
|
|
let root: string
|
|
let workspace: LocalWorkspaceAccess
|
|
let service: LocalDirectModelProcessService
|
|
let backingStore: FileOutputBacking
|
|
beforeEach(async () => {
|
|
await mkdir(outputFixtureRoot, { recursive: true })
|
|
root = await mkdtemp(join(outputFixtureRoot, 'rg-'))
|
|
workspace = new LocalWorkspaceAccess(root)
|
|
backingStore = new FileOutputBacking()
|
|
service = new LocalDirectModelProcessService({ outputStore: { backingStore } })
|
|
await writeFile(join(root, 'valid.txt'), 'before\ntarget\nafter\n')
|
|
})
|
|
afterEach(async () => {
|
|
await service.dispose()
|
|
await backingStore.dispose()
|
|
await rm(root, { recursive: true, force: true })
|
|
})
|
|
const search = (args: string[], signal = new AbortController().signal) =>
|
|
searchWorkspaceWithRipgrep(rgPath, { args }, workspace, signal, service, 'owner')
|
|
|
|
describe('native ripgrep', () => {
|
|
it('preserves native context, file listing, JSON and multiple expressions', async () => {
|
|
expect((await search(['-A1', '-B1', '-e', 'target', '-e', 'absent', '.'])).stdout).toContain('after')
|
|
expect((await search(['--files', '-g', '*.txt'])).stdout).toContain('valid.txt')
|
|
expect((await search(['--json', 'target', '.'])).stdout).toContain('"type":"match"')
|
|
})
|
|
it('preserves no matches, regex errors and partial results with exit codes', async () => {
|
|
expect(await search(['absent', '.'])).toMatchObject({ exitCode: 1, stdout: '' })
|
|
expect(await search(['[', '.'])).toMatchObject({ exitCode: 2, stderr: expect.stringContaining('regex parse error') })
|
|
expect(await search(['target', 'valid.txt', 'missing.txt'])).toMatchObject({
|
|
exitCode: 2, stdout: expect.stringContaining('target'), stderr: expect.stringContaining('missing.txt')
|
|
})
|
|
})
|
|
it('retains more than the former 4 MiB capture and resumes through EOF', async () => {
|
|
const text = 'target '.repeat(700_000) + 'END-MARKER\n'
|
|
await writeFile(join(root, 'large.txt'), text)
|
|
const result = await search(['--no-line-number', 'target', 'large.txt'])
|
|
expect(result.exitCode).toBe(0)
|
|
expect(result.stdoutTruncated).toBe(true)
|
|
const reference = result.stdoutReference!
|
|
let output = result.stdout
|
|
let cursor = reference.nextCursor
|
|
while (cursor < reference.totalBytes) {
|
|
const page = await service.readOutput('owner', reference.handle, cursor)
|
|
output += page.content
|
|
cursor = page.nextCursor
|
|
}
|
|
expect(output).toBe(text)
|
|
await expect(service.readOutput('another', reference.handle)).rejects.toThrow()
|
|
await service.releaseConversation('owner')
|
|
await expect(service.readOutput('owner', reference.handle)).rejects.toThrow()
|
|
})
|
|
it.each(['-L', '-z'])('accepts native option %s without a mode', async (option) => {
|
|
expect((await search([option, 'target', 'valid.txt'])).exitCode).toBe(0)
|
|
})
|
|
it('supports cwd and literal shell characters while ignoring external config', async () => {
|
|
await mkdir(join(root, 'nested'))
|
|
await writeFile(join(root, 'nested', 'text.txt'), '$(echo unexpected); target\n')
|
|
await writeFile(join(root, 'config'), '--invalid-config-option\n')
|
|
const configured = new LocalDirectModelProcessService({ environment: { ...process.env, RIPGREP_CONFIG_PATH: join(root, 'config') } })
|
|
try {
|
|
const result = await searchWorkspaceWithRipgrep(rgPath, {
|
|
args: ['-F', '$(echo unexpected);', '.'], cwd: 'nested'
|
|
}, workspace, new AbortController().signal, configured, 'owner')
|
|
expect(result).toMatchObject({ exitCode: 0, stdout: expect.stringContaining('$(echo unexpected); target') })
|
|
} finally { await configured.dispose() }
|
|
})
|
|
it('allows external paths and directory links with current-user permissions', async () => {
|
|
const outside = await mkdtemp(join(outputFixtureRoot, 'rg-outside-'))
|
|
try {
|
|
await writeFile(join(outside, 'outside.txt'), 'target\n')
|
|
await symlink(outside, join(root, 'linked'), process.platform === 'win32' ? 'junction' : 'dir')
|
|
expect((await search(['target', outside])).exitCode).toBe(0)
|
|
expect((await search(['target', 'linked'])).exitCode).toBe(0)
|
|
} finally { await rm(outside, { recursive: true, force: true }) }
|
|
})
|
|
it('preserves cancellation', async () => {
|
|
const controller = new AbortController()
|
|
controller.abort(new Error('cancelled'))
|
|
await expect(search(['target'], controller.signal)).rejects.toThrow('cancelled')
|
|
})
|
|
})
|