fix(embeddings): honour 0 for decayRate and driftThreshold in embeddings_neural init

This commit is contained in:
MentaNew committed 2026-11-05 13:53:58 -05:00
1 parent 03e381eaa2
commit f35a94aca0
1 file changed
+30 -1
@@ -1,5 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { mkdtempSync, rmSync } from 'node:fs';
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
@@ -18,6 +18,7 @@ vi.mock('../src/memory/memory-initializer.js', () => ({
const { embeddingsTools } = await import('../src/mcp-tools/embeddings-tools.js');
const init = embeddingsTools.find(tool => tool.name === 'embeddings_init')!;
const search = embeddingsTools.find(tool => tool.name === 'embeddings_search')!;
const neural = embeddingsTools.find(tool => tool.name === 'embeddings_neural')!;
let originalCwd: string;
let workdir: string;
@@ -48,3 +49,31 @@ describe('embeddings_search threshold', () => {
expect(result.metadata.threshold).toBe(0.5);
});
});
describe('embeddings_neural init', () => {
it('honours an explicit 0 for decayRate and driftThreshold', async () => {
const result = await neural.handler({ action: 'init', decayRate: 0, driftThreshold: 0 }) as any;
expect(result.success).toBe(true);
expect(result.neural.decayRate).toBe(0);
expect(result.neural.driftThreshold).toBe(0);
});
it('persists the 0 values to the embeddings config', async () => {
await neural.handler({ action: 'init', decayRate: 0, driftThreshold: 0 });
const saved = JSON.parse(readFileSync(join(workdir, '.claude-flow', 'embeddings.json'), 'utf-8'));
expect(saved.neural.decayRate).toBe(0);
expect(saved.neural.driftThreshold).toBe(0);
});
it('still defaults to 0.3 and 0.01 when the values are omitted', async () => {
const result = await neural.handler({ action: 'init' }) as any;
expect(result.neural.driftThreshold).toBe(0.3);
expect(result.neural.decayRate).toBe(0.01);
});
it('keeps non-zero values as given', async () => {
const result = await neural.handler({ action: 'init', decayRate: 0.05, driftThreshold: 0.7 }) as any;
expect(result.neural.decayRate).toBe(0.05);
expect(result.neural.driftThreshold).toBe(0.7);
});
});