/** * 벡터 기억 중복 판정(2026-10-25) — 실측 쌍으로 고정. */ import { describe, test } from 'node:test'; import assert from 'node:assert/strict'; import { isNearDuplicateFact, dedupeFacts } from '../src/gateway/memory/memory-vector'; describe('isNearDuplicateFact', () => { test('같은 사실의 다른 문장 — 거리(실측)로', () => { assert.equal(isNearDuplicateFact('클로서버(Claw-Server)의 대시보드 주소는 `http://192.168.0.5:18789`이다.', '클로서버 웹 대시보드 주소는 http://192.168.0.5:18789(LAN 내부) 또는 http://localhost:18789(로컬)이다.', 0.1536), true); assert.equal(isNearDuplicateFact('클로서버는 Dell T5810(Xeon E5-2683 v4, 40GB RAM, RTX 3060 12GB ×2) 사양을 사용한다.', '클로서버(Claw-Server)는 Dell Precision T5810 모델이며, CPU는 Xeon E5-2683 v4, RAM 40GB, GPU는 RTX 3060 12GB 2개를 사용한다.', 0.1206), true); }); test('가깝지만 숫자가 다르면 다른 사실', () => { assert.equal(isNearDuplicateFact('로봇청소기 1호기의 IP는 192.168.0.76이다.', '로봇청소기 2호기의 IP는 192.168.0.87이다.', 0.142), false); assert.equal(isNearDuplicateFact('NVIDIA RTX 5090의 메모리 대역폭은 1,790 GB/s이다.', 'NVIDIA RTX 3090의 메모리 대역폭은 936.2 GB/s이다.', 0.1886), false); }); test('거리 없이 글자 유사도로(회상 결과끼리)', () => { assert.equal(isNearDuplicateFact('클로서버의 웹 대시보드 주소는 http://192.168.0.5:18789이다.', '클로서버 대시보드 주소는 http://192.168.0.5:18789이다.'), true); assert.equal(isNearDuplicateFact('클로서버(Claw-Server)의 RAM 용량은 40GB이다.', '클로서버(Claw-Server)의 GPU는 RTX 3060 12GB 2장(총 VRAM 24GB)이 장착되어 있다.'), false); }); test('식별자가 2개 이상 겹치면 느슨하게, 숫자 없는 문장은 엄격하게', () => { assert.equal(isNearDuplicateFact('클로서버(Claw-Server)의 대시보드 주소는 `http://192.168.0.5:18789`이다.', '클로서버 웹 대시보드: http://192.168.0.5:18789 (LAN) 또는 http://localhost:18789. "클로서버.local"이나 ":3000" 포트는 실재하지 않음 — 지어내지 말 것.'), true); assert.equal(isNearDuplicateFact('사용자는 파이썬을 선호한다.', '사용자는 커피를 좋아한다.'), false); assert.equal(isNearDuplicateFact('온실 서버는 MQTT로 HA에 연결된다.', '로봇청소기는 Valetudo로 HA에 연결된다.'), false); assert.equal(isNearDuplicateFact('클로서버(Claw-Server)의 RAM 용량은 40GB이다.', '지서버의 RAM 용량은 64GB이다.'), false); }); test('서버 이름이 다르면 다른 사실(10-25 지서버 CPU가 지워진 사례)', () => { assert.equal(isNearDuplicateFact('지서버(HP Z840)의 CPU는 Intel Xeon E5-2683 v4 (Dual 구성)이다.', '클로서버의 CPU는 Intel Xeon E5-2683 v4이다.'), false); assert.equal(isNearDuplicateFact('지서버(HP Z840)의 CPU는 Intel Xeon E5-2683 v4 (Dual 구성)이다.', '지서버의 CPU는 Intel Xeon E5-2683 v4 듀얼 구성이다.', 0.1), true); }); test('짧은 사실이 긴 사실의 일부면 중복 아님 — 자세한 쪽이 지워지지 않게(10-25 실제 손실 5건)', () => { assert.equal(isNearDuplicateFact('클로서버의 CPU는 Intel Xeon E5-2683 v4이다.', '클로서버는 Dell T5810 기반이며, Xeon E5-2683 v4와 RTX 3060 12GB 조합으로 구성되어 있고 소비전력은 약 70W이다.'), false); assert.equal(isNearDuplicateFact('지서버(HP Z840)의 파워 서플라이 용량은 1125W이다.', 'HP Z840의 1125W 파워 서플라이는 기본적으로 6핀 보조전원 케이블 3개를 제공한다.'), false); assert.equal(isNearDuplicateFact('지서버(Z-Server)의 GPU는 RTX 5060 Ti 16GB 2장(총 VRAM 32GB)을 탑재하고 있다.', 'RTX 5060 Ti 16GB 2장(32GB VRAM) 구성에서 qwen3-coder-30b 모델 사용 시 105 token/sec의 속도가 나온다.'), false); }); }); describe('dedupeFacts', () => { test('앞쪽(더 관련 있는 것)을 남긴다', () => { const out = dedupeFacts([ { text: '클로서버 대시보드 주소는 http://192.168.0.5:18789이다.' }, { text: '클로서버의 웹 대시보드 주소는 http://192.168.0.5:18789이다.' }, { text: '클로서버 웹 대시보드 주소는 http://192.168.0.5:18789 이다.' }, { text: '클로서버(Claw-Server)의 RAM 용량은 40GB이다.' }, ]); assert.deepEqual(out.map(o => o.text), ['클로서버 대시보드 주소는 http://192.168.0.5:18789이다.', '클로서버(Claw-Server)의 RAM 용량은 40GB이다.']); }); }); import { buildSkillToolFilter } from '../src/gateway/chat/tool-scope'; describe('비공개 앱은 장기 기억에 쓰지 않는다(10-25)', () => { const on = (sessionId: string) => buildSkillToolFilter({ message: '이거 기억해둬', recentUserText: '이거 기억해둬', lastAssistantMsg: '', sessionId, userWorkspace: null, isSkillEnabledForUser: () => true, } as any)('memory_write'); test('탐정·닥터·법률 세션엔 memory_write가 없다', () => { assert.equal(on('dt_case_case_x'), false); assert.equal(on('dr_case_case_x'), false); assert.equal(on('lw_case_case_x'), false); assert.equal(on('4545cbaf-x'), true); }); });