also looking at this
fix(reports): honour reports.enabled and reports.period, drop the key nothing could read
#1429
7 files
+118
-9
| @@ -0,0 +1,44 @@ | ||
| 1 | import { describe, expect, it } from 'bun:test' | |
| 2 | import { shouldPublishReport } from '../src/reports/publish-gate' | |
| 3 | import { generateUnifiedWorkflow } from '../src/setup' | |
| 4 | ||
| 5 | /** | |
| 6 | * `reports.enabled` was documented as the opt-in for scheduled reports and | |
| 7 | * defaulted to `false`, and nothing read it — the generated workflow published | |
| 8 | * every week regardless. `reports.period` was documented, defaulted and never | |
| 9 | * consulted; only the `--period` flag was. | |
| 10 | */ | |
| 11 | describe('publishing a scheduled report', () => { | |
| 12 | it('failure case - the scheduled run does not publish by default', () => { | |
| 13 | // The documented default, enforced for the first time. | |
| 14 | const gate = shouldPublishReport({ scheduled: true, enabled: undefined }) | |
| 15 | ||
| 16 | expect(gate.publish).toBe(false) | |
| 17 | expect(gate.reason).toContain('opt-in') | |
| 18 | }) | |
| 19 | ||
| 20 | it('failure case - the scheduled run honours an explicit false', () => { | |
| 21 | expect(shouldPublishReport({ scheduled: true, enabled: false }).publish).toBe(false) | |
| 22 | }) | |
| 23 | ||
| 24 | it('success case - the scheduled run publishes once enabled', () => { | |
| 25 | expect(shouldPublishReport({ scheduled: true, enabled: true })).toEqual({ publish: true }) | |
| 26 | }) | |
| 27 | ||
| 28 | it('success case - a person at a terminal is not second-guessed', () => { | |
| 29 | // `--publish` typed by hand is a decision already made; the setting exists | |
| 30 | // to govern the run nobody typed. | |
| 31 | expect(shouldPublishReport({ scheduled: false, enabled: false }).publish).toBe(true) | |
| 32 | expect(shouldPublishReport({ scheduled: false, enabled: undefined }).publish).toBe(true) | |
| 33 | }) | |
| 34 | }) | |
| 35 | ||
| 36 | describe('the generated report job', () => { | |
| 37 | it('success case - marks its run as scheduled', () => { | |
| 38 | // Without this the command cannot tell the cron from a person, and the | |
| 39 | // opt-in has nothing to bite on. | |
| 40 | const yaml = generateUnifiedWorkflow(false) | |
| 41 | ||
| 42 | expect(yaml).toContain('buddy report --publish --scheduled') | |
| 43 | }) | |
| 44 | }) | |