calendar-ics-normalizer-stress.test.mjs
61 lines 1.8 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day ago
1 /**
2 * Tier 4 — STRESS: large and pathological ICS payloads within bounded limits.
3 */
4 import { describe, it } from 'node:test';
5 import assert from 'node:assert/strict';
6 import { parseIcsToEvents, unfoldIcsLines } from '../lib/calendar/ics-normalizer.mjs';
7
8 describe('Stress — many VEVENT components', () => {
9 it('parses 1000 events under default maxEvents cap', () => {
10 const chunks = ['BEGIN:VCALENDAR'];
11 for (let i = 0; i < 1000; i += 1) {
12 chunks.push(
13 'BEGIN:VEVENT',
14 `UID:evt-${i}@stress`,
15 'DTSTART:20260101T000000Z',
16 'DTEND:20260101T010000Z',
17 'END:VEVENT',
18 );
19 }
20 chunks.push('END:VCALENDAR');
21 const events = parseIcsToEvents(chunks.join('\n'));
22 assert.equal(events.length, 1000);
23 });
24
25 it('rejects payloads above maxEvents', () => {
26 const chunks = ['BEGIN:VCALENDAR'];
27 for (let i = 0; i < 11; i += 1) {
28 chunks.push(
29 'BEGIN:VEVENT',
30 `UID:x-${i}@s`,
31 'DTSTART:20260101T000000Z',
32 'DTEND:20260101T010000Z',
33 'END:VEVENT',
34 );
35 }
36 chunks.push('END:VCALENDAR');
37 assert.throws(() => parseIcsToEvents(chunks.join('\n'), { maxEvents: 10 }), /max is 10/);
38 });
39 });
40
41 describe('Stress — deep folding chains', () => {
42 it('handles many folded summary continuations', () => {
43 const parts = ['SUMMARY:Start'];
44 for (let i = 0; i < 50; i += 1) {
45 parts.push(` part${i}`);
46 }
47 const folded = parts.join('\r\n ');
48 const lines = unfoldIcsLines(`${folded}\r\nUID:x`);
49 assert.equal(lines.length, 2);
50 assert.match(lines[0], /part49/);
51 });
52 });
53
54 describe('Stress — malformed structure', () => {
55 it('throws on unclosed VEVENT', () => {
56 assert.throws(
57 () => parseIcsToEvents('BEGIN:VCALENDAR\nBEGIN:VEVENT\nUID:x\nDTSTART:20260101T000000Z\nEND:VCALENDAR'),
58 /Unclosed VEVENT/,
59 );
60 });
61 });
File History 1 commit
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 1 day ago