/** * 자기 분석 트리거 + 인벤토리 자동 대조 회귀 테스트. * * 모든 케이스는 실제 사용자 세션에서 재현된 실패에서 가져왔다: * - "/Volumes/... 분석해줘" 프롬프트가 startsWith('/') 가드에 슬래시 명령으로 * 오인되어 분석 지시·인벤토리가 전부 미주입 (v2.2.239 까지의 버그) * - 이전 답변 전문(5천자+)을 붙여넣는 재검토 프롬프트가 길이 상한에 탈락 * - 모델이 이미 구현된 기능(Reflection/Decay/Correction)을 신규 도입 제안 */ import { isSelfAssessRequest, isAboutSelf } from '../src/lib/contextBuilders/selfAssessContext'; import { isAnalysisRequest, isSlashCommand } from '../src/lib/contextBuilders/promptDetection'; import { extractUrls } from '../src/features/web/webFetch'; import { detectReimplementedProposals, formatReimplementationFooter } from '../src/extension/featureConceptMap'; // 사용자가 실제로 입력한 프롬프트 원문 const P_PATH_ANALYSIS = '/Volumes/Data/project/Antigravity/ConnectAI 분석하고 어떻게 하면 우리 아스트라를 작업을하면서 스스로 배우고 필요한 지식을 요청해서 사용자로 하여금 해당 지식을 가져오게 할 수 있을까? 의견줘'; const P_LONG_PASTE = '아래 내용 검토해줘. 현재의 자기 진화(self-evolving) 기능은 지식 축적과 구조화 측면에서 ' + '내용 '.repeat(2000); describe('isSlashCommand — 명령 vs 절대경로 구분', () => { it('슬래시 명령은 true', () => { expect(isSlashCommand('/wikify https://a.com')).toBe(true); expect(isSlashCommand('/benchmark')).toBe(true); expect(isSlashCommand('/stocks discover')).toBe(true); }); it('절대경로는 false (v2.2.239 버그 회귀 방지)', () => { expect(isSlashCommand('/Volumes/Data/project 분석해줘')).toBe(false); expect(isSlashCommand('/Users/me/code 봐줘')).toBe(false); }); }); describe('실사용 프롬프트 트리거 (실패 재현 케이스)', () => { it('절대경로로 시작하는 분석 요청 → 분석 지시 발동', () => { expect(isAnalysisRequest(P_PATH_ANALYSIS)).toBe(true); expect(isSelfAssessRequest(P_PATH_ANALYSIS)).toBe(true); expect(isAboutSelf(P_PATH_ANALYSIS)).toBe(true); }); it('이전 답변 전문 붙여넣기(5천자+) → 길이 상한 없이 발동', () => { expect(P_LONG_PASTE.length).toBeGreaterThan(4000); expect(isSelfAssessRequest(P_LONG_PASTE)).toBe(true); }); it('자기 작동 방식 질문 ("어떻게 학습해?") → 인벤토리 주입 발동', () => { expect(isSelfAssessRequest('아스트라 너는 어떻게 학습하고 있어?')).toBe(true); expect(isSelfAssessRequest('아스트라가 학습하는 방식 설명해줘')).toBe(true); }); it('절대경로로 시작 + URL 포함 → URL 추출 정상', () => { expect(extractUrls('/Volumes/Data/proj 보고 koritips.com 도 분석해줘')).toEqual(['https://koritips.com']); }); }); describe('detectReimplementedProposals — 인벤토리 자동 대조', () => { it('실제 Astra 답변의 재구현 제안들을 감지', () => { // 사용자 세션에서 모델이 실제로 출력한 문장 발췌 const answer = [ '개선 제안: handlePrompt 파이프라인 내에 Reflection Layer(성찰 계층)를 추가할 것을 강력히 추천합니다.', '지식 노후화 감지 시스템 (Knowledge Decay): 축적된 지식이 더 이상 유효하지 않음을 판단하는 메커니즘이 필요합니다.', '피드백 루프 자동화: 성공/실패의 원인을 분석하여 lessons/ 폴더에 자동으로 교훈으로 저장해야 합니다.', '자기 검증 및 비판적 사고 루프 (Self-Critique Loop): SelfCritiqueHandler를 추가합니다.', ].join('\n'); const hits = detectReimplementedProposals(answer); const concepts = hits.map((h) => h.concept); expect(concepts.some((c) => c.includes('Reflection'))).toBe(true); expect(concepts.some((c) => c.includes('Decay'))).toBe(true); expect(concepts.some((c) => c.includes('Self-Critique'))).toBe(true); const footer = formatReimplementationFooter(hits); expect(footer).toContain('이미 구현되어 있습니다'); }); it('12B 답변의 변형 표현(Self-Correction/Reasoning Chain)도 감지', () => { // gemma-4-12b 가 실제로 출력한 문장 발췌 — 키워드 변형으로 정정기를 빗나갔던 케이스 const answer = [ 'Reasoning Chain 도입: AgentExecutor 내에 "생각 단계(Thought)"를 명시적으로 분리하는 구조를 강화해야 합니다.', 'Self-Correction 루프: 답변 생성 후 스스로 검토하는 단계를 추가하여 processFinalAnswer 단계에 강화해야 합니다.', ].join('\n'); const hits = detectReimplementedProposals(answer); const concepts = hits.map((h) => h.concept); expect(concepts.some((c) => c.includes('Multi-Step') || c.includes('멀티스텝'))).toBe(true); expect(concepts.some((c) => c.includes('Self-Critique'))).toBe(true); }); it('이미 구현됨을 인지한 문장은 정정하지 않음 (오탐 방지)', () => { const answer = 'Reflection Layer는 이미 Self-Reflector 3단계로 구현되어 있으므로, 이를 확장하는 방향을 제안합니다.'; expect(detectReimplementedProposals(answer)).toEqual([]); }); it('무관한 일반 답변에는 무반응', () => { const answer = '블로그 글 작성을 위한 SEO 키워드는 다음과 같이 추가해야 합니다: 메인 키워드 1개, 서브 키워드 3개.'; expect(detectReimplementedProposals(answer)).toEqual([]); expect(formatReimplementationFooter([])).toBe(''); }); });