feat(events): schedule, recurrence and the calendar (Phase 4)
The four closed recurrence shapes computed in the definition's own IANA zone, a fourteen-day materialisation horizon with projections beyond it, series as a managed thing, and the admin calendar that replaces the plugin this feature exists to replace. An event now happens on its own. No schema change: Phase 1 built every column this needed. - events/recurrence.js is the ONE place an occurrence is computed, so the runner's expansion and the calendar's forecast cannot disagree. No date library added — Node ships the tzdata one would vendor, behind Intl. - The runner's materialise leg is now two halves: expand, then sweep. The window starts at `now - grace`, so an occurrence nobody could have seen is never invented retroactively; the horizon is what makes the missed sweep mean anything for a recurrence. - Publishing is the schedule switch and archiving turns it off, and publishing re-pins every occurrence that has not started. - A projection is never drawn over an instant a run occupies, so a cancelled occurrence does not reappear as a forecast. 54 new tests, incl. the DST fixture set the plan asked for and three new statements proved against a real MariaDB. Suite 1768/1711/56 skipped/1 fail (pre-existing CRLF). Walked end to end on the local review stack. Docs: RunicGateway/docs#PENDING Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -192,13 +192,104 @@ test('a key a later phase owns is refused, not silently preserved', () => {
|
||||
assert.match(phase.errors.join('\n'), /unknown key\(s\) advance .*Phase 5/)
|
||||
})
|
||||
|
||||
test('only the manual schedule exists in this phase', () => {
|
||||
const weekly = spec.validate({
|
||||
schedule: { kind: 'weekly', days: ['fri'], time: '20:00' },
|
||||
phases: [{ key: 'main', label: 'Main', steps: [] }],
|
||||
// ── The schedule shapes (Phase 4) ────────────────────────────────────
|
||||
//
|
||||
// Every check here is on SHAPE. What the shapes MEAN — the zone arithmetic, the
|
||||
// DST rules — is `eventRecurrence.test.js`. The split is deliberate: this file
|
||||
// answers "may this be saved", that one answers "when does it happen", and the
|
||||
// second question is only worth asking of something that passed the first.
|
||||
|
||||
const withSchedule = (schedule) =>
|
||||
spec.validate({ schedule, phases: [{ key: 'main', label: 'Main', steps: [] }] })
|
||||
|
||||
test('the four closed shapes are accepted and normalised', () => {
|
||||
assert.deepEqual(withSchedule({ kind: 'manual' }).spec.schedule, { kind: 'manual' })
|
||||
assert.deepEqual(withSchedule({ kind: 'once', at: '2026-10-31T20:00' }).spec.schedule, {
|
||||
kind: 'once',
|
||||
at: '2026-10-31T20:00',
|
||||
})
|
||||
assert.equal(weekly.ok, false)
|
||||
assert.match(weekly.errors.join('\n'), /recurrence arrives in Phase 4/)
|
||||
assert.deepEqual(withSchedule({ kind: 'weekly', days: ['friday'], time: '20:00' }).spec.schedule, {
|
||||
kind: 'weekly',
|
||||
days: ['friday'],
|
||||
time: '20:00',
|
||||
})
|
||||
assert.deepEqual(
|
||||
withSchedule({ kind: 'monthly', nth: -1, weekday: 'friday', time: '19:30' }).spec.schedule,
|
||||
{ kind: 'monthly', nth: -1, weekday: 'friday', time: '19:30' },
|
||||
)
|
||||
})
|
||||
|
||||
test('the validator accepts its own output for every shape', () => {
|
||||
// Phase 1's rule, and it is a rule about the SECOND save of any definition
|
||||
// rather than about a round trip for its own sake: `validate` normalises, and
|
||||
// publish re-validates what a save wrote. A normaliser that refuses what it
|
||||
// emits makes a published definition uneditable.
|
||||
for (const schedule of [
|
||||
{ kind: 'manual' },
|
||||
{ kind: 'once', at: '2026-10-31T20:00' },
|
||||
{ kind: 'weekly', days: ['friday', 'monday'], time: '20:00' },
|
||||
{ kind: 'monthly', nth: 4, weekday: 'friday', time: '19:30' },
|
||||
]) {
|
||||
const first = withSchedule(schedule)
|
||||
assert.equal(first.ok, true, JSON.stringify(schedule))
|
||||
const second = withSchedule(first.spec.schedule)
|
||||
assert.equal(second.ok, true, JSON.stringify(first.spec.schedule))
|
||||
assert.deepEqual(second.spec.schedule, first.spec.schedule)
|
||||
}
|
||||
})
|
||||
|
||||
test('weekly days are normalised into week order and deduped', () => {
|
||||
// Not tidiness. The spec is snapshotted into a version and diffed, so two
|
||||
// orderings of the same schedule would show as an edit nobody made.
|
||||
const result = withSchedule({ kind: 'weekly', days: ['Friday', 'monday', 'FRIDAY'], time: '20:00' })
|
||||
assert.deepEqual(result.spec.schedule.days, ['monday', 'friday'])
|
||||
})
|
||||
|
||||
test('a shape may not carry another shape keys', () => {
|
||||
const result = withSchedule({ kind: 'weekly', days: ['friday'], time: '20:00', at: '2026-01-01T00:00' })
|
||||
assert.equal(result.ok, false)
|
||||
assert.match(result.errors.join('\n'), /unknown key\(s\) at for kind "weekly"/)
|
||||
})
|
||||
|
||||
test('an unknown kind is refused, and the message names the four', () => {
|
||||
const result = withSchedule({ kind: 'daily', time: '20:00' })
|
||||
assert.equal(result.ok, false)
|
||||
assert.match(result.errors.join('\n'), /manual, once, weekly, monthly/)
|
||||
})
|
||||
|
||||
test('a date that is not a real day is refused', () => {
|
||||
// The regex admits 2026-02-30 quite happily. A schedule that parses and then
|
||||
// resolves to some other day is worse than one that is refused.
|
||||
const result = withSchedule({ kind: 'once', at: '2026-02-30T20:00' })
|
||||
assert.equal(result.ok, false)
|
||||
assert.match(result.errors.join('\n'), /is not a real date/)
|
||||
})
|
||||
|
||||
test('every malformed schedule field is named, not merely rejected', () => {
|
||||
assert.match(withSchedule({ kind: 'once', at: 'soon' }).errors.join('\n'), /YYYY-MM-DDTHH:MM/)
|
||||
assert.match(withSchedule({ kind: 'weekly', days: [], time: '20:00' }).errors.join('\n'), /non-empty array/)
|
||||
assert.match(withSchedule({ kind: 'weekly', days: ['froday'], time: '20:00' }).errors.join('\n'), /unknown weekday/)
|
||||
assert.match(withSchedule({ kind: 'weekly', days: ['friday'], time: '25:00' }).errors.join('\n'), /24-hour time/)
|
||||
assert.match(
|
||||
withSchedule({ kind: 'monthly', nth: 5, weekday: 'friday', time: '19:30' }).errors.join('\n'),
|
||||
/1, 2, 3, 4 or -1/,
|
||||
)
|
||||
assert.match(
|
||||
withSchedule({ kind: 'monthly', nth: 1, weekday: 'froday', time: '19:30' }).errors.join('\n'),
|
||||
/expected one of sunday/,
|
||||
)
|
||||
})
|
||||
|
||||
test('a refused schedule leaves a manual one behind rather than half a recurrence', () => {
|
||||
// `validate` collects every error and carries on, so the spec object exists
|
||||
// even when the answer is no. A caller reading `schedule.days` of it must not
|
||||
// find a partially built weekly.
|
||||
const result = spec.validate({
|
||||
schedule: { kind: 'weekly', days: ['froday'], time: '20:00' },
|
||||
phases: [{ key: 'BAD KEY', label: '', steps: [] }],
|
||||
})
|
||||
assert.equal(result.ok, false)
|
||||
assert.ok(result.errors.length > 1)
|
||||
})
|
||||
|
||||
test('every problem is reported, not just the first', () => {
|
||||
|
||||
Reference in New Issue
Block a user