bb7cd6b879
- v2.2.292 메모리·발열: 헬스체크 워크스페이스 쓰기→fs.access(워처 연쇄 제거)·git 검사 비동기 30분 주기, 웹뷰 retainContextWhenHidden 정리(채팅만 유지), 브레인 인덱스 유휴 30분 TTL 해제, 채팅 DOM 200개 상한, @lmstudio/sdk 지연 로드 - v2.2.293 Pixel Office 시각화 폐기: astraOffice 모듈·사이드바 매니저 3종·스프라이트 17MB 삭제, sidebarProvider collector 섹션 통삭제 (기업 모드 판단 로직 무변경, vsix 12.2MB→1.3MB) - v2.2.294 도구 메뉴 'NotebookLM 백엔드 실행/종료' 버튼: OS 자동 감지, 프로젝트 자동 탐색+폴더 선택 저장, 포트 정리 폴백 (터미널 없이 Research 백엔드 켜고 끄기) - v2.2.295 추론 강화 1탄: [ACTION 16] <calculate> Python 계산 위임(결과 재주입·자가수정 루프), 단계별 지식 스코프(General+Specialty, 결정적 도메인 분류, 설정 지식·기억 탭 UI) - v2.2.296 추론 강화 2탄: [ACTION 17] <run_code> 실행 확인(stdout 회수→수정→재실행 루프), 문법 오류 재주입 자가수정, 도구 라우팅 힌트(dynamicBlocks), Grounding rescue 도메인 스코프 확장 - 검증: jest 818 통과(신규 29개), tsc 무오류, esbuild 정상 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
78 lines
3.6 KiB
TypeScript
78 lines
3.6 KiB
TypeScript
/**
|
|
* <calculate> 액션 — 수학·수치 계산의 Python 위임 검증.
|
|
*
|
|
* 소형 모델 추론 강화 전략의 1축: "모델은 코드로 변환만, 계산은 도구가".
|
|
* 실행 결과/에러가 chatHistory 에 internal system 메시지로 재주입되어
|
|
* agent 의 자동 후속 턴(자가수정 루프)을 트리거하는 계약을 검증한다.
|
|
*/
|
|
import { execFileSync } from 'child_process';
|
|
import { applyCalculateActions, _resetPythonCache } from '../src/agent/actions/calculate';
|
|
|
|
// vscode 런타임 의존 없음(type-only import) — 별도 mock 불필요.
|
|
|
|
function hasPython(): boolean {
|
|
for (const cmd of ['python3', 'python', 'py']) {
|
|
try { execFileSync(cmd, ['--version'], { timeout: 3000 }); return true; } catch { /* next */ }
|
|
}
|
|
return false;
|
|
}
|
|
const PY = hasPython();
|
|
const itPy = PY ? it : it.skip;
|
|
|
|
function makeCtx(aiMessage: string): any {
|
|
return { aiMessage, report: [], chatHistory: [] };
|
|
}
|
|
|
|
describe('applyCalculateActions', () => {
|
|
beforeEach(() => _resetPythonCache());
|
|
|
|
it('calculate 태그가 없으면 아무것도 하지 않는다', async () => {
|
|
const ctx = makeCtx('그냥 일반 답변입니다. 2+2=4 입니다.');
|
|
await applyCalculateActions(ctx);
|
|
expect(ctx.report).toEqual([]);
|
|
expect(ctx.chatHistory).toEqual([]);
|
|
});
|
|
|
|
itPy('정상 계산: stdout 이 internal system 메시지로 재주입된다', async () => {
|
|
const ctx = makeCtx('<calculate>print(1234 * 5678)</calculate>');
|
|
await applyCalculateActions(ctx);
|
|
expect(ctx.report.some((r: string) => r.includes('Calculated'))).toBe(true);
|
|
expect(ctx.chatHistory.length).toBe(1);
|
|
expect(ctx.chatHistory[0].role).toBe('system');
|
|
expect(ctx.chatHistory[0].internal).toBe(true);
|
|
expect(ctx.chatHistory[0].content).toContain('[Result of calculate]');
|
|
expect(ctx.chatHistory[0].content).toContain('7006652'); // 1234*5678
|
|
});
|
|
|
|
itPy('에러 코드: stderr 가 ERROR 블록으로 재주입되어 자가수정 루프를 유도한다', async () => {
|
|
const ctx = makeCtx('<calculate>print(undefined_variable_xyz)</calculate>');
|
|
await applyCalculateActions(ctx);
|
|
expect(ctx.report.some((r: string) => r.includes('failed'))).toBe(true);
|
|
expect(ctx.chatHistory[0].content).toContain('[Result of calculate — ERROR]');
|
|
expect(ctx.chatHistory[0].content).toContain('다시 emit');
|
|
});
|
|
|
|
itPy('print 누락: 빈 출력이면 print 힌트를 재주입한다', async () => {
|
|
const ctx = makeCtx('<calculate>x = 40 + 2</calculate>');
|
|
await applyCalculateActions(ctx);
|
|
expect(ctx.chatHistory[0].content).toContain('EMPTY OUTPUT');
|
|
expect(ctx.chatHistory[0].content).toContain('print');
|
|
});
|
|
|
|
itPy('여러 태그는 각각 실행되고, 한도(4개) 초과분은 건너뛴다', async () => {
|
|
const tags = Array.from({ length: 6 }, (_, i) => `<calculate>print(${i} + 1)</calculate>`).join('\n');
|
|
const ctx = makeCtx(tags);
|
|
await applyCalculateActions(ctx);
|
|
const results = ctx.chatHistory.filter((m: any) => m.content.includes('[Result of calculate]'));
|
|
expect(results.length).toBe(4);
|
|
expect(ctx.report.some((r: string) => r.includes('한도'))).toBe(true);
|
|
});
|
|
|
|
it('과도하게 긴 코드는 실행 전 차단한다', async () => {
|
|
const ctx = makeCtx(`<calculate>${'x=1\n'.repeat(3000)}print(x)</calculate>`);
|
|
await applyCalculateActions(ctx);
|
|
expect(ctx.report.some((r: string) => r.includes('너무 깁니다'))).toBe(true);
|
|
expect(ctx.chatHistory).toEqual([]);
|
|
});
|
|
});
|