|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import fs from 'fs'; |
| 18 | +import path from 'path'; |
| 19 | + |
| 20 | +import { test, expect } from './fixtures'; |
| 21 | + |
| 22 | +test('evicts oldest evictable files before write exceeds cap, pinned session.md survives', async ({ startClient, server }, testInfo) => { |
| 23 | + const outputDir = testInfo.outputPath('output'); |
| 24 | + const { client } = await startClient({ |
| 25 | + config: { |
| 26 | + outputDir, |
| 27 | + saveSession: true, |
| 28 | + outputMaxSize: 10_000, |
| 29 | + }, |
| 30 | + }); |
| 31 | + |
| 32 | + await client.callTool({ name: 'browser_navigate', arguments: { url: server.HELLO_WORLD } }); |
| 33 | + |
| 34 | + for (let i = 0; i < 8; i++) |
| 35 | + await client.callTool({ name: 'browser_take_screenshot' }); |
| 36 | + const pngs = fs.readdirSync(outputDir).filter(f => f.endsWith('.png')); |
| 37 | + expect(pngs.length).toBeLessThan(8); |
| 38 | + expect(pngs.reduce((acc, f) => acc + fs.statSync(path.join(outputDir, f)).size, 0)).toBeLessThanOrEqual(10_000); |
| 39 | + |
| 40 | + const sessionFolder = fs.readdirSync(outputDir).find(e => e.startsWith('session-')); |
| 41 | + expect(sessionFolder).toBeTruthy(); |
| 42 | + expect(fs.existsSync(path.join(outputDir, sessionFolder!, 'session.md'))).toBe(true); |
| 43 | +}); |
| 44 | + |
| 45 | +test('oversize single file evicts everything and still writes', async ({ startClient, server }, testInfo) => { |
| 46 | + const outputDir = testInfo.outputPath('output'); |
| 47 | + const { client } = await startClient({ |
| 48 | + config: { |
| 49 | + outputDir, |
| 50 | + outputMaxSize: 100, |
| 51 | + }, |
| 52 | + }); |
| 53 | + |
| 54 | + await client.callTool({ name: 'browser_navigate', arguments: { url: server.HELLO_WORLD } }); |
| 55 | + |
| 56 | + await client.callTool({ name: 'browser_take_screenshot' }); |
| 57 | + await client.callTool({ name: 'browser_take_screenshot' }); |
| 58 | + |
| 59 | + expect(fs.readdirSync(outputDir)).toHaveLength(1); |
| 60 | +}); |
0 commit comments