dsh-memory-vault/tests/memory-smoke.mjs

75 lines
4.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** Смоук-тест хостовой части: node memory-smoke.mjs local|server|fallback */
import { apply } from '../index.js'
const mode = process.argv[2] ?? 'local'
const CWD = 'C:\\Users\\denis\\Documents\\deepseek-harness\\default-workspace'
const tools = new Map()
const contexts = []
const sections = []
const ctx = {
logger: { warn: (...a) => console.error('[warn]', ...a), info: (...a) => console.error('[info]', ...a) },
get(name) {
if (name === 'workingDirectory') return { get: () => CWD }
if (name === 'commands') return { register: () => () => {} }
return undefined
},
tools: { register(definition) { tools.set(definition.name, definition); return () => {} } },
systemPrompt: {
context(definition) { contexts.push(definition); return () => {} },
section(definition) { sections.push(definition); return () => {} },
},
on() { return () => {} },
effect(callback) { callback() },
}
const config = mode === 'local'
? { mode: 'local', host: '127.0.0.1', port: 1, database: 'x', user: 'x', password: 'x' }
: mode === 'mirror'
? { mode: 'local', host: '192.168.31.4', port: 5434, database: 'dsh_memory', user: 'dsh_memory' }
: mode === 'fallback'
? { mode: 'server', host: '127.0.0.1', port: 1, database: 'x', user: 'x', password: 'x', autoFallback: true }
: { mode: 'server', host: '192.168.31.4', port: 5434, database: 'dsh_memory', user: 'dsh_memory' }
await apply(ctx, config)
const exec = { agent: { session: {} }, signal: new AbortController().signal }
const call = async (name, args) => tools.get(name).execute(args, exec)
const out = (...a) => console.log(...a)
if (mode === 'local') {
out('TOOLS:', [...tools.keys()].join(','))
out('CONTEXTS:', contexts.map(c => c.name).join(','))
const rulesText = sections[0]?.text?.({}) ?? ''
out('RULES:', rulesText.length, JSON.stringify(rulesText.slice(0, 120)))
const saved = await call('memory_save', { text: 'Локальная заметка перед миграцией: проверка фолбэка и переноса.', tags: ['migrate'], scope: 'global', collection: 'home-server', pinned: true })
out('SAVE:', saved)
const id = /mem-[0-9a-f]+/.exec(saved)?.[0]
out('UPDATE:', await call('memory_update', { id, text: 'Локальная заметка обновлена: проверка memory_update.', tags: ['updated'] }))
out('SEARCH_NEW:', await call('memory_search', { query: 'обновлена', collection: 'home-server' }))
out('SEARCH_OTHER_COLLECTION:', await call('memory_search', { query: 'обновлена', collection: 'personal' }))
out('SEARCH_OLD:', await call('memory_search', { query: 'фолбэка' }))
out('LIST_COLLECTION:', await call('memory_list', { collection: 'home-server', limit: 5 }))
out('SAVE_PERSONAL:', await call('memory_save', { text: 'Личная заметка пользователя: предпочитает короткие ответы.', scope: 'global', collection: 'personal' }))
await new Promise(r => setTimeout(r, 300))
out('RECALL:', JSON.stringify(contexts[0].text({ agent: { session: {} } }).slice(0, 200)))
out('SECRET_SAVE:', await call('secret_save', { name: 'Тест: db admin', value: 'SuperSecret123', username: 'admin', url: 'db.local', notes: 'тест', tags: ['test'] }))
out('SECRET_LIST:', await call('secret_list', { limit: 5 }))
out('SECRET_GET:', await call('secret_get', { match: 'Тест: db admin' }))
out('SECRET_FORGET:', await call('secret_forget', { match: 'Тест: db admin' }))
out('SECRET_LIST_AFTER:', await call('secret_list', { limit: 5 }))
} else if (mode === 'server') {
out('SAVE_SERVER:', await call('memory_save', { text: 'Серверная заметка: проверка записи в обе базы.', tags: ['server'], scope: 'global' }))
out('SECRET_SAVE_SERVER:', await call('secret_save', { name: 'Тест: server token', value: 'tok_abc123', url: 'https://example.test', tags: ['test'] }))
out('LIST_SERVER:', await call('memory_list', { limit: 10 }))
} else if (mode === 'mirror') {
out('MIRROR_NOTE:', await call('memory_save', { text: 'Заметка в локальном режиме должна уйти и на сервер.', tags: ['mirror'], scope: 'global' }))
out('MIRROR_SECRET:', await call('secret_save', { name: 'Тест: mirror secret', value: 'mirror_value', tags: ['mirror'] }))
out('MIRROR_LIST:', await call('secret_list', { limit: 10 }))
} else {
out('FALLBACK_SAVE:', await call('memory_save', { text: 'Заметка при недоступном сервере: должна уйти в локальную SQLite.', scope: 'global' }))
out('FALLBACK_LIST:', await call('memory_list', { limit: 5 }))
}
process.exit(0)