style(13-03): apply Prettier formatting across repo
Mechanical reformat — no logic changes. 398 files changed, 19125 insertions(+), 16457 deletions(-). Prettier 3.8.4 with .prettierrc (singleQuote:true, semi:true, tabWidth:2, trailingComma:all, printWidth:100). Isolated per D-13-08 for reviewability.
This commit is contained in:
@@ -13,23 +13,22 @@
|
||||
* duration derives from DTSTART→DTEND (not the recurrence span) (D-06 invariant).
|
||||
*/
|
||||
|
||||
import 'temporal-polyfill/global'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { readFileSync } from 'fs'
|
||||
import { join, dirname } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import 'temporal-polyfill/global';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
import { expandOccurrences } from '../../src/broker/expand.js'
|
||||
import { expandOccurrences } from '../../src/broker/expand.js';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const FIXTURES = join(__dirname, '../fixtures')
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const FIXTURES = join(__dirname, '../fixtures');
|
||||
|
||||
function loadFixture(name: string): string {
|
||||
return readFileSync(join(FIXTURES, name), 'utf8')
|
||||
return readFileSync(join(FIXTURES, name), 'utf8');
|
||||
}
|
||||
|
||||
describe('expandOccurrences', () => {
|
||||
|
||||
describe('DST correctness — weekly-dst.ics', () => {
|
||||
it('returns 10:00 America/New_York wall-clock time on BOTH sides of March 2026 DST boundary', () => {
|
||||
// The fixture has DTSTART;TZID=America/New_York:20260301T100000 RRULE:FREQ=WEEKLY.
|
||||
@@ -38,62 +37,62 @@ describe('expandOccurrences', () => {
|
||||
// 2026-03-15 (EDT, UTC-4) must ALL show hour === 10 in America/New_York.
|
||||
// A broken implementation that falls back to UTC would show hour === 10 UTC before
|
||||
// transition and hour === 11 local after transition — off by one DST hour.
|
||||
const rawVevent = loadFixture('weekly-dst.ics')
|
||||
const windowStart = new Date('2026-03-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-04-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('weekly-dst.ics');
|
||||
const windowStart = new Date('2026-03-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-04-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
windowStart,
|
||||
windowEnd,
|
||||
1, // calendarId
|
||||
1, // calendarId
|
||||
'My Calendar', // calendarName
|
||||
1, // ownerUserId
|
||||
'Alice', // ownerName
|
||||
'#4A90D9', // color
|
||||
false, // isShared
|
||||
)
|
||||
1, // ownerUserId
|
||||
'Alice', // ownerName
|
||||
'#4A90D9', // color
|
||||
false, // isShared
|
||||
);
|
||||
|
||||
// Should return several weekly occurrences in March
|
||||
expect(occurrences.length).toBeGreaterThan(0)
|
||||
expect(occurrences.length).toBeGreaterThan(0);
|
||||
|
||||
// The key contract: every occurrence must have local hour === 10 in America/New_York.
|
||||
// We verify this by checking the ISO string — before DST: '...T10:00:00-05:00[America/New_York]'
|
||||
// after DST: '...T10:00:00-04:00[America/New_York]'. Both include the IANA bracket.
|
||||
for (const occ of occurrences) {
|
||||
expect(occ.allDay).toBe(false)
|
||||
expect(occ.allDay).toBe(false);
|
||||
// ownerName must be threaded through to every occurrence
|
||||
expect(occ.ownerName).toBe('Alice')
|
||||
expect(occ.ownerName).toBe('Alice');
|
||||
// start must be IANA-annotated: '2026-03-01T10:00:00-05:00[America/New_York]'
|
||||
expect(occ.start).toMatch(/T10:00:00/)
|
||||
expect(occ.start).toMatch(/T10:00:00/);
|
||||
// Must include IANA bracket — offset-only strings fail Temporal.ZonedDateTime.from()
|
||||
expect(occ.start).toContain('[America/New_York]')
|
||||
expect(occ.start).toContain('[America/New_York]');
|
||||
}
|
||||
|
||||
// Explicitly check one pre-transition occurrence (EST) and one post-transition (EDT)
|
||||
const preTransition = occurrences.find(o => o.start.includes('2026-03-01'))
|
||||
const postTransition = occurrences.find(o => o.start.includes('2026-03-15'))
|
||||
const preTransition = occurrences.find((o) => o.start.includes('2026-03-01'));
|
||||
const postTransition = occurrences.find((o) => o.start.includes('2026-03-15'));
|
||||
|
||||
expect(preTransition).toBeDefined()
|
||||
expect(postTransition).toBeDefined()
|
||||
expect(preTransition).toBeDefined();
|
||||
expect(postTransition).toBeDefined();
|
||||
|
||||
// Pre-transition occurrence: EST — '2026-03-01T10:00:00-05:00[America/New_York]'
|
||||
expect(preTransition!.start).toContain('T10:00:00')
|
||||
expect(preTransition!.start).toContain('-05:00[America/New_York]')
|
||||
expect(preTransition!.start).toContain('T10:00:00');
|
||||
expect(preTransition!.start).toContain('-05:00[America/New_York]');
|
||||
// Post-transition occurrence: EDT — '2026-03-15T10:00:00-04:00[America/New_York]'
|
||||
expect(postTransition!.start).toContain('T10:00:00')
|
||||
expect(postTransition!.start).toContain('-04:00[America/New_York]')
|
||||
})
|
||||
})
|
||||
expect(postTransition!.start).toContain('T10:00:00');
|
||||
expect(postTransition!.start).toContain('-04:00[America/New_York]');
|
||||
});
|
||||
});
|
||||
|
||||
describe('All-day events — allday-birthday.ics', () => {
|
||||
it('returns allDay:true with start as YYYY-MM-DD and no time component', () => {
|
||||
// The fixture has DTSTART;VALUE=DATE:20260615 with RRULE:FREQ=YEARLY.
|
||||
// The all-day occurrence should have allDay:true and start === '2026-06-15' (DATE format).
|
||||
// A broken implementation returning '2026-06-15T00:00:00Z' would fail on date-shift.
|
||||
const rawVevent = loadFixture('allday-birthday.ics')
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-07-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('allday-birthday.ics');
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-07-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -102,20 +101,20 @@ describe('expandOccurrences', () => {
|
||||
1,
|
||||
'My Calendar',
|
||||
1,
|
||||
null, // ownerName
|
||||
null, // ownerName
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
expect(occurrences.length).toBe(1)
|
||||
expect(occurrences.length).toBe(1);
|
||||
|
||||
const occ = occurrences[0]
|
||||
expect(occ.allDay).toBe(true)
|
||||
const occ = occurrences[0];
|
||||
expect(occ.allDay).toBe(true);
|
||||
// start must be plain date string 'YYYY-MM-DD' — no 'T' time component
|
||||
expect(occ.start).toBe('2026-06-15')
|
||||
expect(occ.start).not.toContain('T')
|
||||
})
|
||||
})
|
||||
expect(occ.start).toBe('2026-06-15');
|
||||
expect(occ.start).not.toContain('T');
|
||||
});
|
||||
});
|
||||
|
||||
describe('EXDATE exclusions — exdate-series.ics', () => {
|
||||
it('omits the EXDATE-excluded occurrence (array length is one fewer than un-excluded)', () => {
|
||||
@@ -123,9 +122,9 @@ describe('expandOccurrences', () => {
|
||||
// Without EXDATE: 5 occurrences (Jun 1, Jun 8, Jun 15, Jun 22, Jun 29).
|
||||
// With EXDATE on Jun 15: 4 occurrences returned.
|
||||
// ICAL.RecurExpansion handles EXDATE internally — no manual filtering needed.
|
||||
const rawVevent = loadFixture('exdate-series.ics')
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-07-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('exdate-series.ics');
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-07-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -134,28 +133,28 @@ describe('expandOccurrences', () => {
|
||||
1,
|
||||
'My Calendar',
|
||||
1,
|
||||
null, // ownerName
|
||||
null, // ownerName
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
// 5 total occurrences minus 1 EXDATE = 4
|
||||
expect(occurrences.length).toBe(4)
|
||||
expect(occurrences.length).toBe(4);
|
||||
|
||||
// The June 15 occurrence must be absent
|
||||
const june15 = occurrences.find(o => o.start.includes('2026-06-15'))
|
||||
expect(june15).toBeUndefined()
|
||||
})
|
||||
})
|
||||
const june15 = occurrences.find((o) => o.start.includes('2026-06-15'));
|
||||
expect(june15).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Non-recurring DURATION-only event — single-duration.ics', () => {
|
||||
it('BUG-1 regression: non-recurring event with DURATION but no DTEND has end strictly after start', () => {
|
||||
// Real Fastmail events use DURATION (not DTEND). Before the fix, the NON-RECURRING branch
|
||||
// used getFirstPropertyValue('dtend') ?? dtstart, which returned dtstart when DTEND was absent,
|
||||
// producing zero-duration occurrences (invisible in week/day views).
|
||||
const rawVevent = loadFixture('single-duration.ics')
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-07-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('single-duration.ics');
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-07-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -164,33 +163,33 @@ describe('expandOccurrences', () => {
|
||||
1,
|
||||
'My Calendar',
|
||||
1,
|
||||
null, // ownerName
|
||||
null, // ownerName
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
expect(occurrences.length).toBe(1)
|
||||
expect(occurrences.length).toBe(1);
|
||||
|
||||
const occ = occurrences[0]
|
||||
expect(occ.allDay).toBe(false)
|
||||
const occ = occurrences[0];
|
||||
expect(occ.allDay).toBe(false);
|
||||
|
||||
// Parse both via Temporal.ZonedDateTime and assert end > start
|
||||
const startZdt = Temporal.ZonedDateTime.from(occ.start)
|
||||
const endZdt = Temporal.ZonedDateTime.from(occ.end)
|
||||
expect(Temporal.ZonedDateTime.compare(endZdt, startZdt)).toBeGreaterThan(0)
|
||||
const startZdt = Temporal.ZonedDateTime.from(occ.start);
|
||||
const endZdt = Temporal.ZonedDateTime.from(occ.end);
|
||||
expect(Temporal.ZonedDateTime.compare(endZdt, startZdt)).toBeGreaterThan(0);
|
||||
|
||||
// Verify the actual duration is correct: DURATION:PT1H → end is 1 hour after start
|
||||
expect(endZdt.hour - startZdt.hour).toBe(1)
|
||||
expect(endZdt.minute).toBe(startZdt.minute)
|
||||
})
|
||||
})
|
||||
expect(endZdt.hour - startZdt.hour).toBe(1);
|
||||
expect(endZdt.minute).toBe(startZdt.minute);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasRrule field — D-08 (recurring series detection)', () => {
|
||||
it('recurring event occurrence has hasRrule === true', () => {
|
||||
// weekly-dst.ics has RRULE:FREQ=WEEKLY — all occurrences must have hasRrule === true
|
||||
const rawVevent = loadFixture('weekly-dst.ics')
|
||||
const windowStart = new Date('2026-03-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-04-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('weekly-dst.ics');
|
||||
const windowStart = new Date('2026-03-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-04-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -202,19 +201,19 @@ describe('expandOccurrences', () => {
|
||||
null,
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
expect(occurrences.length).toBeGreaterThan(0)
|
||||
expect(occurrences.length).toBeGreaterThan(0);
|
||||
for (const occ of occurrences) {
|
||||
expect(occ.hasRrule).toBe(true)
|
||||
expect(occ.hasRrule).toBe(true);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it('non-recurring event occurrence has hasRrule === false', () => {
|
||||
// single-duration.ics has no RRULE — the single occurrence must have hasRrule === false
|
||||
const rawVevent = loadFixture('single-duration.ics')
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-07-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('single-duration.ics');
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-07-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -226,20 +225,20 @@ describe('expandOccurrences', () => {
|
||||
null,
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
expect(occurrences.length).toBe(1)
|
||||
expect(occurrences[0].hasRrule).toBe(false)
|
||||
})
|
||||
})
|
||||
expect(occurrences.length).toBe(1);
|
||||
expect(occurrences[0].hasRrule).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Bounded RRULE (COUNT=3) — D-06 invariant', () => {
|
||||
it('expands to exactly 3 occurrences within a wide window (COUNT terminates expansion)', () => {
|
||||
// weekly-count3.ics has RRULE:FREQ=WEEKLY;COUNT=3 starting 2026-06-01.
|
||||
// A 6-month window must return exactly 3 occurrences — not more.
|
||||
const rawVevent = loadFixture('weekly-count3.ics')
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-12-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('weekly-count3.ics');
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-12-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -251,17 +250,17 @@ describe('expandOccurrences', () => {
|
||||
null,
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
expect(occurrences.length).toBe(3)
|
||||
})
|
||||
expect(occurrences.length).toBe(3);
|
||||
});
|
||||
|
||||
it('each bounded occurrence duration derives from DTSTART→DTEND (1 hour), not recurrence span', () => {
|
||||
// Each occurrence must have end exactly 1 hour after start.
|
||||
// The recurrence span is many weeks; duration must be per-event, not recurrence-level.
|
||||
const rawVevent = loadFixture('weekly-count3.ics')
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-12-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('weekly-count3.ics');
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-12-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -273,23 +272,23 @@ describe('expandOccurrences', () => {
|
||||
null,
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
expect(occurrences.length).toBe(3)
|
||||
expect(occurrences.length).toBe(3);
|
||||
for (const occ of occurrences) {
|
||||
const startZdt = Temporal.ZonedDateTime.from(occ.start)
|
||||
const endZdt = Temporal.ZonedDateTime.from(occ.end)
|
||||
const startZdt = Temporal.ZonedDateTime.from(occ.start);
|
||||
const endZdt = Temporal.ZonedDateTime.from(occ.end);
|
||||
// Each occurrence must be exactly 1 hour (3 600 000 ms).
|
||||
// Use epochMilliseconds which is a regular number in the polyfill.
|
||||
const durationMs = endZdt.epochMilliseconds - startZdt.epochMilliseconds
|
||||
expect(durationMs).toBe(3_600_000)
|
||||
const durationMs = endZdt.epochMilliseconds - startZdt.epochMilliseconds;
|
||||
expect(durationMs).toBe(3_600_000);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it('bounded occurrences have hasRrule === true', () => {
|
||||
const rawVevent = loadFixture('weekly-count3.ics')
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-12-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('weekly-count3.ics');
|
||||
const windowStart = new Date('2026-06-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-12-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -301,14 +300,14 @@ describe('expandOccurrences', () => {
|
||||
null,
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
expect(occurrences.length).toBe(3)
|
||||
expect(occurrences.length).toBe(3);
|
||||
for (const occ of occurrences) {
|
||||
expect(occ.hasRrule).toBe(true)
|
||||
expect(occ.hasRrule).toBe(true);
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('Cross-contract: expand output → Temporal.ZonedDateTime.from (regression guard)', () => {
|
||||
it('timed event start/end strings from weekly-dst.ics parse via Temporal.ZonedDateTime.from without throwing', () => {
|
||||
@@ -319,9 +318,9 @@ describe('expandOccurrences', () => {
|
||||
// Previously, serializeTime emitted offset-only strings like '2026-03-01T10:00:00-05:00'
|
||||
// which caused Temporal.ZonedDateTime.from() to throw RangeError: Cannot parse.
|
||||
// Now it emits IANA-annotated strings like '2026-03-01T10:00:00-05:00[America/New_York]'.
|
||||
const rawVevent = loadFixture('weekly-dst.ics')
|
||||
const windowStart = new Date('2026-03-01T00:00:00Z')
|
||||
const windowEnd = new Date('2026-04-01T00:00:00Z')
|
||||
const rawVevent = loadFixture('weekly-dst.ics');
|
||||
const windowStart = new Date('2026-03-01T00:00:00Z');
|
||||
const windowEnd = new Date('2026-04-01T00:00:00Z');
|
||||
|
||||
const occurrences = expandOccurrences(
|
||||
rawVevent,
|
||||
@@ -330,23 +329,23 @@ describe('expandOccurrences', () => {
|
||||
1,
|
||||
'My Calendar',
|
||||
1,
|
||||
null, // ownerName
|
||||
null, // ownerName
|
||||
'#4A90D9',
|
||||
false,
|
||||
)
|
||||
);
|
||||
|
||||
expect(occurrences.length).toBeGreaterThan(0)
|
||||
expect(occurrences.length).toBeGreaterThan(0);
|
||||
|
||||
for (const occ of occurrences) {
|
||||
// These must not throw — this is the cross-service contract
|
||||
expect(() => Temporal.ZonedDateTime.from(occ.start)).not.toThrow()
|
||||
expect(() => Temporal.ZonedDateTime.from(occ.end)).not.toThrow()
|
||||
expect(() => Temporal.ZonedDateTime.from(occ.start)).not.toThrow();
|
||||
expect(() => Temporal.ZonedDateTime.from(occ.end)).not.toThrow();
|
||||
|
||||
// Parsed ZonedDateTime must round-trip the wall-clock hour
|
||||
const startZdt = Temporal.ZonedDateTime.from(occ.start)
|
||||
expect(startZdt.hour).toBe(10)
|
||||
expect(startZdt.timeZoneId).toBe('America/New_York')
|
||||
const startZdt = Temporal.ZonedDateTime.from(occ.start);
|
||||
expect(startZdt.hour).toBe(10);
|
||||
expect(startZdt.timeZoneId).toBe('America/New_York');
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user