455 lines
28 KiB
TypeScript
455 lines
28 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
import { parse } from 'yaml'
|
|
import { MEMORY_PLACEMENT_CAPABILITIES } from 'dsh-brain-mnemon-source-memory-spaces/contracts'
|
|
import { Config as RuntimeConfig } from 'dsh-brain-mnemon-source-runtime'
|
|
import { RUNTIME_MEMORY_LIMIT_MAX_BYTES, RUNTIME_MEMORY_LIMITS } from 'dsh-brain-mnemon-source-runtime/contracts'
|
|
import { Config, resolveConfig, resolveSkillsConfig } from "../src/host/config.ts"
|
|
import { mainStrategyTypeId, withMainStrategy } from '../src/host/main-strategy.ts'
|
|
|
|
afterEach(() => vi.unstubAllEnvs())
|
|
|
|
describe('Mnemon config and resolution', () => {
|
|
it('keeps low-priority Runtime projection deferral opt-in and validates it (#364)', () => {
|
|
expect(resolveConfig({}).runtimeMemory.deferLowPriority).toBe(false)
|
|
expect(resolveConfig({ runtimeMemory: { deferLowPriority: true } }).runtimeMemory.deferLowPriority).toBe(true)
|
|
expect(Config({ runtimeMemory: { deferLowPriority: true } }).runtimeMemory?.deferLowPriority).toBe(true)
|
|
expect(() => resolveConfig({ runtimeMemory: { deferLowPriority: 'yes' } } as never)).toThrow('deferLowPriority')
|
|
})
|
|
|
|
it('keeps creation roots opt-in and validates the whole preference atomically (#658)', () => {
|
|
expect(resolveSkillsConfig().skillRoots).toBeUndefined()
|
|
const skillRoots = { create: ['project-agents', 'user-agents'], default: 'project-agents' } as const
|
|
expect(resolveSkillsConfig({ skillRoots: { ...skillRoots, create: [...skillRoots.create] } }).skillRoots).toEqual(skillRoots)
|
|
for (const value of [{}, { create: [] }, { create: ['user-agents'], default: 'project-agents' }, { create: ['user-dsh', 'user-dsh'], default: 'user-dsh' }, { create: ['unknown'], default: 'unknown' }]) {
|
|
expect(() => resolveSkillsConfig({ skillRoots: value } as never)).toThrow()
|
|
}
|
|
})
|
|
it('defaults automatic adoption off and validates its persistent daily budget settings', () => {
|
|
expect(resolveSkillsConfig()).toMatchObject({ autoAdopt: false, autoAdoptDailyLimit: 2, autoAdoptTimeZone: 'local' })
|
|
expect(resolveSkillsConfig({ autoAdoptDailyLimit: 0, autoAdoptTimeZone: 'Asia/Shanghai' })).toMatchObject({ autoAdoptDailyLimit: 0, autoAdoptTimeZone: 'Asia/Shanghai' })
|
|
for (const value of [-1, 101, 1.5, NaN, Infinity]) expect(() => resolveSkillsConfig({ autoAdoptDailyLimit: value })).toThrow()
|
|
for (const value of ['', 'not/a-zone']) expect(() => resolveSkillsConfig({ autoAdoptTimeZone: value })).toThrow()
|
|
})
|
|
it('defaults and validates explicit draft budgets without forcing a larger retry budget', () => {
|
|
expect(resolveSkillsConfig()).toMatchObject({ draftMaxTokens: 32_768, draftRetryMaxTokens: 65_536 })
|
|
expect(Config({ skills: { draftMaxTokens: 98_304, draftRetryMaxTokens: 32_768 } }).skills)
|
|
.toMatchObject({ draftMaxTokens: 98_304, draftRetryMaxTokens: 32_768 })
|
|
for (const key of ['draftMaxTokens', 'draftRetryMaxTokens'] as const) {
|
|
for (const value of [128, 131_072]) expect(resolveSkillsConfig({ [key]: value })[key]).toBe(value)
|
|
for (const value of [0, 127, 131_073, 1.5, NaN, Infinity, '32768']) {
|
|
expect(() => resolveSkillsConfig({ [key]: value } as never)).toThrow()
|
|
}
|
|
}
|
|
})
|
|
it('defaults explicit subagent providers off and validates their configured names', () => {
|
|
expect(resolveConfig({}).subagentProviderNames).toEqual([])
|
|
expect(Config({ subagentProviderNames: ['custom'] }).subagentProviderNames).toEqual(['custom'])
|
|
expect(resolveConfig({ subagentProviderNames: [' custom ', 'custom', 'second'] }).subagentProviderNames).toEqual(['custom', 'second'])
|
|
for (const value of ['custom', [''], [12], Array.from({ length: 33 }, (_, index) => `provider-${index}`)]) {
|
|
expect(() => resolveConfig({ subagentProviderNames: value } as never)).toThrow('subagentProviderNames')
|
|
}
|
|
})
|
|
it('keeps memory write confirmation opt-in and validates its value (#140)', () => {
|
|
expect(resolveConfig({}).confirmWrites).toBe(false)
|
|
expect(resolveConfig({ confirmWrites: true }).confirmWrites).toBe(true)
|
|
expect(Config({ confirmWrites: true }).confirmWrites).toBe(true)
|
|
expect(() => resolveConfig({ confirmWrites: 'true' } as never)).toThrow('confirmWrites must be a boolean')
|
|
})
|
|
|
|
it('preserves the user skill destination for existing settings and validates explicit scopes', () => {
|
|
expect(resolveSkillsConfig().targetScope).toBe('user')
|
|
expect(resolveSkillsConfig().allowLinkedUpdates).toBe(false)
|
|
expect(resolveSkillsConfig({ allowLinkedUpdates: true }).allowLinkedUpdates).toBe(true)
|
|
expect(() => resolveSkillsConfig({ allowLinkedUpdates: 'true' } as never)).toThrow()
|
|
expect(resolveSkillsConfig({ evolution: true }).targetScope).toBe('user')
|
|
for (const targetScope of ['storage', 'user', 'project'] as const) expect(resolveSkillsConfig({ targetScope }).targetScope).toBe(targetScope)
|
|
expect(() => resolveSkillsConfig({ targetScope: 'cwd' } as never)).toThrow()
|
|
})
|
|
it('keeps both skill suggestion types enabled for old configurations and resolves each switch independently', () => {
|
|
expect(resolveSkillsConfig()).toMatchObject({ evolution: false, allowCreate: true, allowUpdate: true })
|
|
expect(resolveSkillsConfig({ evolution: true })).toMatchObject({ evolution: true, allowCreate: true, allowUpdate: true })
|
|
expect(resolveSkillsConfig({ allowCreate: false })).toMatchObject({ allowCreate: false, allowUpdate: true })
|
|
expect(resolveSkillsConfig({ allowUpdate: false })).toMatchObject({ allowCreate: true, allowUpdate: false })
|
|
expect(() => resolveSkillsConfig({ allowCreate: 'false' } as never)).toThrow()
|
|
expect(() => resolveSkillsConfig({ allowUpdate: 0 } as never)).toThrow()
|
|
})
|
|
it('defaults persistent review watermarks off and accepts an explicit opt-in', () => {
|
|
expect(resolveConfig({}).idleReview.persistWatermark).toBe(false)
|
|
expect(resolveConfig({ idleReview: { persistWatermark: true } } as never).idleReview.persistWatermark).toBe(true)
|
|
expect(() => resolveConfig({ idleReview: { persistWatermark: 'yes' } } as never)).toThrow()
|
|
})
|
|
|
|
it.each([{ maxPerSession: -1 }, { maxPerSession: 201 }, { minIntervalMs: 0 }, { maxContextChars: 1 }, { maxTokens: 0 }, { provider: 'unisolated' }, { agentTeams: 'unrestricted' }, { runtimeMemory: 'documents' }])('rejects invalid idle review policy %j', idleReview => {
|
|
expect(() => resolveConfig({ idleReview } as never)).toThrow()
|
|
})
|
|
it('keeps idle review to Documents only when runtime memory is off', () => {
|
|
expect(resolveConfig({ idleReview: { runtimeMemory: false } }).idleReview).toMatchObject({ enabled: true, silent: true, runtimeMemory: false, provider: 'spawn' })
|
|
expect(resolveConfig({ idleReview: { silent: false } }).idleReview).toMatchObject({ enabled: true, silent: false, runtimeMemory: true, provider: 'spawn' })
|
|
})
|
|
it('gives idle review a comfortable output budget by default (regression: max-tokens stop)', () => {
|
|
expect(resolveConfig({}).idleReview.maxTokens).toBe(16_384)
|
|
expect(resolveConfig({ idleReview: { maxTokens: 8_192 } }).idleReview.maxTokens).toBe(8_192)
|
|
})
|
|
it('materializes conservative defaults', () => {
|
|
expect(resolveConfig({})).toMatchObject({
|
|
storageScope: 'global',
|
|
runtimeUserScope: 'storage',
|
|
documentsScope: 'storage',
|
|
memorySpacesScope: 'storage',
|
|
timeoutMs: 10_000,
|
|
defaultRecallLimit: 10,
|
|
runtimeMemory: {
|
|
memoryLimitBytes: 10_240,
|
|
userLimitBytes: 4_096,
|
|
maintenanceMaxTokens: 8_192,
|
|
},
|
|
embedding: {
|
|
enabled: false,
|
|
endpoint: 'http://localhost:11434',
|
|
model: 'nomic-embed-text',
|
|
},
|
|
memoryTopology: {
|
|
id: 'default-three-tier',
|
|
strategyId: 'default-three-tier',
|
|
layers: {
|
|
runtime: { enabled: true, participation: { recall: 'automatic', write: 'automatic', projection: 'automatic', maintenance: 'automatic' }, adapterIds: [] },
|
|
documents: { enabled: true, participation: { recall: 'automatic', write: 'automatic', projection: 'automatic', maintenance: 'automatic' }, adapterIds: [] },
|
|
'memory-spaces': { enabled: true, participation: { recall: 'automatic', write: 'automatic', projection: 'automatic', maintenance: 'automatic' }, adapterIds: [] },
|
|
},
|
|
},
|
|
recallQuality: {
|
|
policy: 'strict-v1',
|
|
lowScoreThreshold: 0.25,
|
|
highScoreThreshold: 0.6,
|
|
candidateMultiplier: 3,
|
|
maxMediumResults: 4,
|
|
maxRankedResults: 4,
|
|
maxUnknownResults: 2,
|
|
},
|
|
routingGuidance: true,
|
|
lifecycleEnabled: true,
|
|
recallMode: 'guided',
|
|
writebackMode: 'guided',
|
|
idleReviewMs: 30_000,
|
|
idleReview: { enabled: true, silent: true, runtimeMemory: true, persistWatermark: false, provider: 'spawn', fallback: 'spawn', agentTeams: 'pause', minIntervalMs: 300_000, maxPerSession: 20, maxContextChars: 24_000, maxTokens: 16_384 },
|
|
displayMode: 'sidebar',
|
|
tabEnabled: true,
|
|
writeEnabled: true,
|
|
remoteAccess: 'read-only',
|
|
conversationInteraction: { turnBar: true, saveAction: true },
|
|
persistenceStrategy: {
|
|
mode: 'manual',
|
|
providerId: 'mnemon-native',
|
|
prompt: '',
|
|
rules: {
|
|
allowedProviderIds: ['mnemon-native'],
|
|
dataBoundary: 'allow-remote',
|
|
requiredCapabilities: [],
|
|
preference: 'balanced',
|
|
},
|
|
providerConnections: {},
|
|
},
|
|
taskAgentModel: { mode: 'inherit' },
|
|
})
|
|
})
|
|
|
|
it('resolves independently switchable memory layer participation without deleting bindings', () => {
|
|
expect(resolveConfig({
|
|
memoryTopology: {
|
|
layers: {
|
|
documents: {
|
|
enabled: false,
|
|
participation: { recall: 'manual', write: 'off' },
|
|
adapterIds: ['openviking', 'openviking'],
|
|
},
|
|
},
|
|
},
|
|
}).memoryTopology.layers.documents).toEqual({
|
|
enabled: false,
|
|
participation: { recall: 'manual', write: 'off', projection: 'automatic', maintenance: 'automatic' },
|
|
adapterIds: ['openviking'],
|
|
})
|
|
expect(() => resolveConfig({ memoryTopology: { strategyId: '../unsafe' } })).toThrow('memory strategy id')
|
|
})
|
|
|
|
it('resolves all eight built-in Layer switch combinations without changing the fixed default policy', () => {
|
|
const ids = ['runtime', 'documents', 'memory-spaces'] as const
|
|
for (let mask = 0; mask < 8; mask += 1) {
|
|
const layers = Object.fromEntries(ids.map((id, index) => [id, { enabled: (mask & (1 << index)) !== 0 }]))
|
|
const resolved = resolveConfig({ memoryTopology: { layers } }).memoryTopology.layers
|
|
for (const id of ids) {
|
|
expect(resolved[id]).toEqual({
|
|
enabled: layers[id]!.enabled,
|
|
participation: { recall: 'automatic', write: 'automatic', projection: 'automatic', maintenance: 'automatic' },
|
|
adapterIds: [],
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
it('resolves bounded Runtime Memory capacity and maintenance budgets', () => {
|
|
expect(resolveConfig({
|
|
runtimeMemory: {
|
|
memoryLimitBytes: 20_480,
|
|
userLimitBytes: 10_240,
|
|
maintenanceMaxTokens: 32_768,
|
|
},
|
|
}).runtimeMemory).toEqual({
|
|
bm25Recall: false,
|
|
indexPush: false,
|
|
deferLowPriority: false,
|
|
inheritToSubagents: false,
|
|
snapshotRefresh: 'on-change',
|
|
memoryLimitBytes: 20_480,
|
|
userLimitBytes: 10_240,
|
|
maintenanceMaxTokens: 32_768,
|
|
})
|
|
expect(() => resolveConfig({ runtimeMemory: { memoryLimitBytes: 0 } })).toThrow('MEMORY.md limit')
|
|
expect(() => resolveConfig({ runtimeMemory: { userLimitBytes: 1.5 } })).toThrow('USER.md limit')
|
|
expect(() => resolveConfig({ runtimeMemory: { maintenanceMaxTokens: 1_000_001 } })).toThrow('maintenance maxTokens')
|
|
})
|
|
|
|
it('requires an explicit boolean to enable experimental BM25 recall', () => {
|
|
expect(resolveConfig({}).runtimeMemory.bm25Recall).toBe(false)
|
|
expect(resolveConfig({ runtimeMemory: { bm25Recall: false } }).runtimeMemory.bm25Recall).toBe(false)
|
|
expect(Config({ runtimeMemory: { bm25Recall: true } }).runtimeMemory?.bm25Recall).toBe(true)
|
|
expect(resolveConfig({ runtimeMemory: { bm25Recall: true } }).runtimeMemory.bm25Recall).toBe(true)
|
|
expect(() => resolveConfig({ runtimeMemory: { bm25Recall: 'on' } } as never)).toThrow('bm25Recall')
|
|
})
|
|
|
|
it('requires an explicit boolean to enable experimental index push (issue 701)', () => {
|
|
expect(resolveConfig({}).runtimeMemory.indexPush).toBe(false)
|
|
expect(resolveConfig({ runtimeMemory: { indexPush: false } }).runtimeMemory.indexPush).toBe(false)
|
|
expect(Config({ runtimeMemory: { indexPush: true } }).runtimeMemory?.indexPush).toBe(true)
|
|
expect(resolveConfig({ runtimeMemory: { indexPush: true } }).runtimeMemory.indexPush).toBe(true)
|
|
expect(() => resolveConfig({ runtimeMemory: { indexPush: 'on' } } as never)).toThrow('indexPush')
|
|
})
|
|
|
|
it('defaults Runtime snapshotRefresh to on-change and validates opt-in session-start', () => {
|
|
expect(resolveConfig({}).runtimeMemory.snapshotRefresh).toBe('on-change')
|
|
expect(Config({}).runtimeMemory?.snapshotRefresh).toBe('on-change')
|
|
for (const snapshotRefresh of ['on-change', 'session-start'] as const) {
|
|
expect(resolveConfig({ runtimeMemory: { snapshotRefresh } }).runtimeMemory.snapshotRefresh).toBe(snapshotRefresh)
|
|
expect(Config({ runtimeMemory: { snapshotRefresh } }).runtimeMemory?.snapshotRefresh).toBe(snapshotRefresh)
|
|
}
|
|
for (const snapshotRefresh of ['never', 'frozen', true, 1]) {
|
|
expect(() => resolveConfig({ runtimeMemory: { snapshotRefresh } } as never)).toThrow('snapshotRefresh')
|
|
expect(() => Config({ runtimeMemory: { snapshotRefresh } } as never)).toThrow()
|
|
}
|
|
expect(Config({ runtimeMemory: { snapshotRefresh: null } } as never).runtimeMemory?.snapshotRefresh).toBe('on-change')
|
|
expect(resolveConfig({ runtimeMemory: { snapshotRefresh: null } } as never).runtimeMemory.snapshotRefresh).toBe('on-change')
|
|
})
|
|
|
|
it('defaults child Runtime inheritance off and accepts only explicit booleans', () => {
|
|
expect(resolveConfig({}).runtimeMemory.inheritToSubagents).toBe(false)
|
|
expect(Config({}).runtimeMemory?.inheritToSubagents).toBe(false)
|
|
expect(resolveConfig({ runtimeMemory: { memoryLimitBytes: 20480 } }).runtimeMemory.inheritToSubagents).toBe(false)
|
|
for (const inheritToSubagents of [false, true]) {
|
|
expect(resolveConfig({ runtimeMemory: { inheritToSubagents } }).runtimeMemory.inheritToSubagents).toBe(inheritToSubagents)
|
|
expect(Config({ runtimeMemory: { inheritToSubagents } }).runtimeMemory?.inheritToSubagents).toBe(inheritToSubagents)
|
|
}
|
|
for (const inheritToSubagents of ['true', 1]) {
|
|
expect(() => resolveConfig({ runtimeMemory: { inheritToSubagents } } as never)).toThrow('inheritToSubagents must be a boolean')
|
|
expect(() => Config({ runtimeMemory: { inheritToSubagents } } as never)).toThrow()
|
|
}
|
|
// DSH's schema treats null as resetting a field to its default.
|
|
expect(Config({ runtimeMemory: { inheritToSubagents: null } } as never).runtimeMemory?.inheritToSubagents).toBe(false)
|
|
expect(resolveConfig({ runtimeMemory: { inheritToSubagents: null } } as never).runtimeMemory.inheritToSubagents).toBe(false)
|
|
})
|
|
|
|
it('defaults and bounds the Runtime limits as the Runtime Source does', () => {
|
|
// The values stored settings are checked against.
|
|
expect([RUNTIME_MEMORY_LIMITS.memory, RUNTIME_MEMORY_LIMITS.user, RUNTIME_MEMORY_LIMIT_MAX_BYTES]).toEqual([10_240, 4_096, 1_048_576])
|
|
expect(resolveConfig({}).runtimeMemory).toMatchObject({ memoryLimitBytes: RUNTIME_MEMORY_LIMITS.memory, userLimitBytes: RUNTIME_MEMORY_LIMITS.user })
|
|
expect(Config({}).runtimeMemory).toMatchObject({ memoryLimitBytes: RUNTIME_MEMORY_LIMITS.memory, userLimitBytes: RUNTIME_MEMORY_LIMITS.user })
|
|
for (const [key, file] of [['memoryLimitBytes', 'MEMORY.md'], ['userLimitBytes', 'USER.md']] as const) {
|
|
expect(resolveConfig({ runtimeMemory: { [key]: RUNTIME_MEMORY_LIMIT_MAX_BYTES } }).runtimeMemory[key]).toBe(RUNTIME_MEMORY_LIMIT_MAX_BYTES)
|
|
expect(RuntimeConfig({ [key]: RUNTIME_MEMORY_LIMIT_MAX_BYTES })[key]).toBe(RUNTIME_MEMORY_LIMIT_MAX_BYTES)
|
|
expect(() => resolveConfig({ runtimeMemory: { [key]: RUNTIME_MEMORY_LIMIT_MAX_BYTES + 1 } }))
|
|
.toThrow(`dsh-brain-mnemon: Runtime ${file} limit must be an integer within 1..${RUNTIME_MEMORY_LIMIT_MAX_BYTES} bytes`)
|
|
expect(() => Config({ runtimeMemory: { [key]: RUNTIME_MEMORY_LIMIT_MAX_BYTES + 1 } })).toThrow(`$.runtimeMemory.${key} expected number <= 1048576 but got 1048577`)
|
|
expect(() => RuntimeConfig({ [key]: RUNTIME_MEMORY_LIMIT_MAX_BYTES + 1 })).toThrow(`$.${key} expected number <= 1048576 but got 1048577`)
|
|
}
|
|
})
|
|
|
|
it('takes the placement capabilities Memory Spaces lists, and only those', () => {
|
|
const persistenceStrategy = { mode: 'automatic' as const, rules: { requiredCapabilities: [...MEMORY_PLACEMENT_CAPABILITIES] } }
|
|
expect(Config({ persistenceStrategy }).persistenceStrategy?.rules?.requiredCapabilities).toEqual([...MEMORY_PLACEMENT_CAPABILITIES])
|
|
expect(resolveConfig({ persistenceStrategy }).persistenceStrategy.rules.requiredCapabilities).toEqual([...MEMORY_PLACEMENT_CAPABILITIES])
|
|
expect(() => Config({ persistenceStrategy: { rules: { requiredCapabilities: ['telepathy' as never] } } }))
|
|
.toThrow('$.persistenceStrategy.rules.requiredCapabilities[0] expected "graph" | "entities" | "related" | "exact-write" | "link" | "forget" but got "telepathy"')
|
|
})
|
|
|
|
it('writes only the code defaults into the Starter patch', () => {
|
|
// The mnemon Entry of the bundle patch, its disabled expression kept as data.
|
|
const rows = parse(readFileSync(new URL('../cordis.patch.yml', import.meta.url), 'utf8'), {
|
|
customTags: [{ tag: 'tag:yaml.org,2002:js', resolve: (value: string) => ({ __jsExpr: value }) }],
|
|
}) as Array<{ insert: Array<{ config: Array<{ id: string; config?: Record<string, unknown> }> }> }>
|
|
const patched = rows[0]!.insert[0]!.config.find(row => row.id === 'mnemon')!.config!
|
|
expect(Object.keys(patched).sort()).toEqual(['defaultRecallLimit', 'embedding', 'idleReviewMs', 'lifecycleEnabled', 'recallMode', 'recallQuality',
|
|
'remoteAccess', 'routingGuidance', 'tabEnabled', 'timeoutMs', 'writeEnabled', 'writebackMode'])
|
|
// The defaults DSH's form shows, and the ones the Host applies, which take embedding and recall quality from Memory Spaces.
|
|
expect(Config({})).toMatchObject(patched)
|
|
expect(resolveConfig({})).toMatchObject(patched)
|
|
})
|
|
|
|
it('inherits the DSH new-session model by default and validates fixed task routes', () => {
|
|
expect(resolveConfig({}).taskAgentModel).toEqual({ mode: 'inherit' })
|
|
expect(resolveConfig({
|
|
taskAgentModel: { mode: 'fixed', provider: ' deepseek ', model: ' deepseek-chat ' },
|
|
}).taskAgentModel).toEqual({ mode: 'fixed', provider: 'deepseek', model: 'deepseek-chat' })
|
|
expect(() => resolveConfig({ taskAgentModel: { mode: 'fixed', provider: 'deepseek' } }))
|
|
.toThrow('provider and model')
|
|
})
|
|
|
|
it('lets an inherited task route follow its conversation only once that is switched on', () => {
|
|
expect(resolveConfig({ taskAgentModel: { mode: 'inherit', followConversation: true } }).taskAgentModel).toEqual({ mode: 'inherit', followConversation: true })
|
|
expect(resolveConfig({ taskAgentModel: { followConversation: false } }).taskAgentModel).toEqual({ mode: 'inherit' })
|
|
// A fixed route names its own model, so the switch has nothing to follow there.
|
|
expect(resolveConfig({
|
|
taskAgentModel: { mode: 'fixed', provider: 'deepseek', model: 'deepseek-chat', followConversation: true },
|
|
}).taskAgentModel).toEqual({ mode: 'fixed', provider: 'deepseek', model: 'deepseek-chat' })
|
|
expect(() => resolveConfig({ taskAgentModel: { mode: 'inherit', followConversation: 'yes' as unknown as boolean } }))
|
|
.toThrow('taskAgentModel.followConversation must be a boolean')
|
|
})
|
|
|
|
it('migrates the settings schema empty candidate list to the conservative manual default', () => {
|
|
expect(resolveConfig({ persistenceStrategy: { mode: 'manual', rules: { allowedProviderIds: [] } } }).persistenceStrategy.rules.allowedProviderIds)
|
|
.toEqual(['mnemon-native'])
|
|
expect(() => resolveConfig({ persistenceStrategy: { mode: 'automatic', rules: { allowedProviderIds: [] } } }))
|
|
.toThrow('at least one allowed provider')
|
|
})
|
|
|
|
it('keeps explicit conversation-surface opt-outs', () => {
|
|
expect(resolveConfig({ conversationInteraction: { turnBar: false, saveAction: false } }).conversationInteraction)
|
|
.toMatchObject({ turnBar: false, saveAction: false })
|
|
})
|
|
|
|
it('still accepts a stored toolviews preference and leaves it out of the resolved config', () => {
|
|
for (const toolviews of [true, false]) {
|
|
const stored = Config({ conversationInteraction: { toolviews, turnBar: false } })
|
|
expect(stored.conversationInteraction).toEqual({ toolviews, turnBar: false, saveAction: true })
|
|
expect(resolveConfig(stored).conversationInteraction).toEqual({ turnBar: false, saveAction: true })
|
|
}
|
|
expect(Config({}).conversationInteraction).toEqual({ toolviews: false, turnBar: true, saveAction: true })
|
|
expect(resolveConfig({}).conversationInteraction).toEqual({ turnBar: true, saveAction: true })
|
|
})
|
|
|
|
it('keeps toolviews declared in the schema DSH builds its form from', () => {
|
|
// Undeclared keys pass through the schema, so only this keeps the generated form as it was.
|
|
expect(Object.keys(Config.dict?.conversationInteraction?.dict ?? {})).toEqual(['toolviews', 'turnBar', 'saveAction'])
|
|
})
|
|
|
|
it.each(['builtin', 'sidebar'] as const)('preserves displayMode=%s without changing storage or visibility', displayMode => {
|
|
const legacy = { displayMode, storageScope: 'workspace' as const, tabEnabled: false, writeEnabled: false }
|
|
const parsed = Config(legacy)
|
|
expect(resolveConfig(parsed)).toMatchObject({ displayMode, storageScope: 'workspace', tabEnabled: false, writeEnabled: false })
|
|
expect(resolveConfig({}).displayMode).toBe('sidebar')
|
|
expect(Config({}).displayMode).toBe('sidebar')
|
|
expect(legacy).toEqual({ displayMode, storageScope: 'workspace', tabEnabled: false, writeEnabled: false })
|
|
})
|
|
|
|
it('normalizes legacy buildin input to builtin without changing storage, visibility, or caller data', () => {
|
|
const legacy = { displayMode: 'buildin' as const, storageScope: 'workspace' as const, tabEnabled: false }
|
|
expect(resolveConfig(Config(legacy))).toMatchObject({ displayMode: 'builtin', storageScope: 'workspace', tabEnabled: false })
|
|
expect(resolveConfig(legacy).displayMode).toBe('builtin')
|
|
expect(legacy.displayMode).toBe('buildin')
|
|
})
|
|
|
|
it.each(['built-in', 'Builtin', 'unknown', '', true])('rejects invalid displayMode=%s', displayMode => {
|
|
expect(() => Config({ displayMode } as never)).toThrow()
|
|
expect(() => resolveConfig({ displayMode } as never)).toThrow('displayMode')
|
|
})
|
|
|
|
it('resolves the one storage-scope setting and preserves legacy dataDir as custom', () => {
|
|
expect(resolveConfig({ storageScope: 'workspace' })).toMatchObject({ storageScope: 'workspace' })
|
|
expect(resolveConfig({ dataDir: '/memory/custom' })).toMatchObject({
|
|
storageScope: 'custom', dataDir: '/memory/custom',
|
|
})
|
|
expect(() => resolveConfig({ storageScope: 'custom' })).toThrow('custom dataDir')
|
|
expect(() => resolveConfig({ storageScope: 'custom', dataDir: 'relative/memory' })).toThrow('absolute')
|
|
})
|
|
|
|
it('keeps USER.md on the selected root by default and accepts an explicit global profile', () => {
|
|
expect(resolveConfig({ storageScope: 'workspace' })).toMatchObject({ storageScope: 'workspace', runtimeUserScope: 'storage' })
|
|
expect(resolveConfig({ storageScope: 'workspace', runtimeUserScope: 'global' })).toMatchObject({ storageScope: 'workspace', runtimeUserScope: 'global' })
|
|
expect(() => resolveConfig({ runtimeUserScope: 'workspace' as never })).toThrow('USER.md scope')
|
|
})
|
|
|
|
it('defaults documentsScope and memorySpacesScope to storage and validates split-root global overrides (issue 374)', () => {
|
|
expect(resolveConfig({ storageScope: 'workspaces' })).toMatchObject({
|
|
storageScope: 'workspaces', documentsScope: 'storage', memorySpacesScope: 'storage',
|
|
})
|
|
expect(resolveConfig({ storageScope: 'workspaces', documentsScope: 'global', memorySpacesScope: 'global' })).toMatchObject({
|
|
storageScope: 'workspaces', documentsScope: 'global', memorySpacesScope: 'global',
|
|
})
|
|
expect(Config({ documentsScope: 'global', memorySpacesScope: 'global' })).toMatchObject({
|
|
documentsScope: 'global', memorySpacesScope: 'global',
|
|
})
|
|
expect(() => resolveConfig({ documentsScope: 'workspace' as never })).toThrow('Documents scope')
|
|
expect(() => resolveConfig({ memorySpacesScope: 'workspace' as never })).toThrow('Memory Spaces scope')
|
|
})
|
|
|
|
it('migrates the selected root from the former named-Pack settings', () => {
|
|
expect(resolveConfig({
|
|
storageScope: 'custom',
|
|
customPackId: 'research',
|
|
customPacks: [
|
|
{ id: 'project', name: 'Project', dataDir: '/memory/project' },
|
|
{ id: 'research', name: 'Research', dataDir: '~/memory/research' },
|
|
],
|
|
})).toMatchObject({
|
|
storageScope: 'custom',
|
|
dataDir: '~/memory/research',
|
|
})
|
|
})
|
|
|
|
it('rejects duplicate, missing, and unsafe custom Pack definitions', () => {
|
|
expect(() => resolveConfig({ customPacks: [{ id: 'same', name: 'One', dataDir: '/one' }, { id: 'same', name: 'Two', dataDir: '/two' }] })).toThrow('duplicate')
|
|
expect(() => resolveConfig({ storageScope: 'custom', customPackId: 'missing', customPacks: [{ id: 'other', name: 'Other', dataDir: '/other' }] })).toThrow('unknown custom Pack')
|
|
expect(() => resolveConfig({ customPacks: [{ id: '../bad', name: 'Bad', dataDir: '/bad' }] })).toThrow('id')
|
|
})
|
|
|
|
it('rejects unsafe store names', () => {
|
|
expect(() => resolveConfig({ store: '../other' })).toThrow('store')
|
|
// A store names a Native space's directory, so it takes exactly a space id.
|
|
for (const store of ['default', 'A-1_b', '9lives']) expect(resolveConfig({ store }).store).toBe(store)
|
|
for (const store of ['-lead', '_lead', 'a.b', 'a/b', 'ä', 'a b']) {
|
|
expect(() => resolveConfig({ store }), store).toThrow('dsh-brain-mnemon: store must match [a-zA-Z0-9][a-zA-Z0-9_-]*')
|
|
}
|
|
})
|
|
|
|
})
|
|
|
|
describe('centralized workspace configuration', () => {
|
|
it('accepts default, home-relative and custom central roots with either USER.md scope', () => {
|
|
for (const runtimeUserScope of ['storage', 'global'] as const) {
|
|
for (const dataDir of [undefined, '', '~/central-memory', '/central-memory']) {
|
|
const input = { storageScope: 'workspaces' as const, runtimeUserScope, ...(dataDir === undefined ? {} : { dataDir }) }
|
|
expect(resolveConfig(Config(input))).toMatchObject({ storageScope: 'workspaces', runtimeUserScope })
|
|
}
|
|
}
|
|
expect(() => resolveConfig({ storageScope: 'workspaces', dataDir: 'relative' })).toThrow('absolute')
|
|
expect(() => resolveConfig({ storageScope: 'workspaces', dataDir: '/root\0' })).toThrow('null byte')
|
|
expect(() => resolveConfig({ storageScope: 'unknown' as never })).toThrow('storageScope')
|
|
})
|
|
})
|
|
|
|
describe('the main Strategy id', () => {
|
|
it('takes the profile plugin choice over the legacy topology id', () => {
|
|
const legacy = resolveConfig({ memoryTopology: { strategyId: 'scoped' } })
|
|
expect(mainStrategyTypeId(resolveConfig({}))).toBe('default-three-tier')
|
|
expect(mainStrategyTypeId(legacy)).toBe('scoped')
|
|
const chosen = withMainStrategy(legacy, { strategyTypeId: 'general' })
|
|
expect(mainStrategyTypeId(chosen)).toBe('general')
|
|
expect(chosen).toEqual({ ...legacy, memoryTopology: { ...legacy.memoryTopology, strategyId: 'general' } })
|
|
expect(mainStrategyTypeId(legacy)).toBe('scoped')
|
|
})
|
|
|
|
it('returns the resolved config itself when the profile has no choice', () => {
|
|
const config = resolveConfig({ memoryTopology: { strategyId: 'scoped' } })
|
|
expect(withMainStrategy(config, {})).toBe(config)
|
|
})
|
|
})
|