fix(teacher): 区分词元预算与传输字节避免短问题被拦截
This commit is contained in:
@@ -43,8 +43,7 @@ describe('teacher read scope', () => {
|
||||
expect(await f.read('write', { path: 'src/game.ts', content: 'overwrite' })).toContain('Read failed');
|
||||
expect(await readFile(path.join(f.project, 'src/game.ts'), 'utf8')).toBe('const gravity = 0.6;\nconst score = 7;');
|
||||
});
|
||||
it.each(['../other-project.txt', '.makelore/conversations.json', ' .makelore/conversations.json ', 'src/../.makelore/conversations.json'])
|
||||
('refuses out-of-scope path %s', async target => {
|
||||
it.each(['../other-project.txt', '.makelore/conversations.json', ' .makelore/conversations.json ', 'src/../.makelore/conversations.json'])('refuses out-of-scope path %s', async target => {
|
||||
const f = await fixture();
|
||||
expect(await f.read('read_project_file', { path: target })).toContain('Read failed');
|
||||
});
|
||||
@@ -118,7 +117,7 @@ describe('teacher read rounds', () => {
|
||||
await writeFile(path.join(f.project, 'src/game.ts'), 'x'.repeat(10000));
|
||||
const fetch = vi.fn(async (_url: string | URL, init?: RequestInit) => {
|
||||
const body = JSON.parse(String(init?.body));
|
||||
expect(estimateTeacherTokens(body.messages) + Buffer.byteLength(JSON.stringify(body.tools)) + 64).toBeLessThanOrEqual(8000);
|
||||
expect(estimateTeacherTokens(body.messages) + Math.ceil(Buffer.byteLength(JSON.stringify(body.tools)) / 2) + 64).toBeLessThanOrEqual(8000);
|
||||
if (body.tool_choice === 'none') return new Response(streamEvent({ choices: [{ delta: { content: '已完成阅读' }, finish_reason: 'stop' }] }));
|
||||
return toolResponse();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user