push-guard.test.ts
Language TypeScript3.8 KB103 lines
/*** `pnpm push` writes straight into the Worker's KV, which is what the team reads.* There is no review step between a laptop and that page, so the checks that* would normally be a person noticing have to live in code.** The one that matters most: `pnpm dashboard --fixtures` writes the SAME* filenames as a live run. A push straight after one would put sample orders on* the production board under four confident "live" source pills, the exact* failure `Snapshot.mode` was introduced to prevent, except now with an audience.*/import { describe, expect, it } from 'vitest'import { checkPush, type PushInputs } from '../src/push-guard.js'const live = (over: Partial<PushInputs> = {}): PushInputs => ({payloadMode: 'live',payloadGeneratedAt: '2026-08-25T20:27:27.386Z',htmlBytes: 105_707,briefingsMode: 'live',briefingsPayloadGeneratedAt: '2026-08-25T20:27:27.386Z',briefingCount: 9,...over,})describe('fixtures never reach the deployed board', () => {it('refuses a fixture payload', () => {const v = checkPush(live({ payloadMode: 'fixtures' }))expect(v.ok).toBe(false)expect(v.refusals.join(' ')).toMatch(/FIXTURE/)})it('refuses fixture briefings even when the payload is live', () => {// Possible in practice: a live sync, then brief.py run with --allow-fixtures// against an older payload. The prose would name people as holding work they// finished.const v = checkPush(live({ briefingsMode: 'fixtures' }))expect(v.ok).toBe(false)})it('refuses a mode it does not recognise rather than assuming it is real', () => {for (const mode of ['demo', '', null, undefined, 'LIVE']) {expect(checkPush(live({ payloadMode: mode })).ok, String(mode)).toBe(false)}})it('allows a live push', () => {const v = checkPush(live())expect(v.ok).toBe(true)expect(v.refusals).toEqual([])})})describe('a broken render is not published', () => {it('refuses a page far too small to be a dashboard', () => {// A failed render still writes a file. 500 bytes is an error page, not a board.expect(checkPush(live({ htmlBytes: 500 })).ok).toBe(false)})it('refuses a missing page', () => {expect(checkPush(live({ htmlBytes: 0 })).ok).toBe(false)})it('accepts a real render', () => {expect(checkPush(live({ htmlBytes: 105_707 })).ok).toBe(true)})it('refuses a payload with no timestamp, since nothing on it can be dated', () => {expect(checkPush(live({ payloadGeneratedAt: null })).ok).toBe(false)})})describe('things worth saying but not worth stopping for', () => {it('warns when there are no briefings rather than refusing', () => {// Numbers-only is a legitimate push; the page says the written briefing was// not generated. But a silent one looks identical to a complete push.const v = checkPush(live({ briefingCount: 0 }))expect(v.ok).toBe(true)expect(v.warnings.join(' ')).toMatch(/No written briefings/)})it('warns when the briefings describe a different sync than the page', () => {const v = checkPush(live({ briefingsPayloadGeneratedAt: '2026-08-25T06:00:00.000Z' }))expect(v.ok).toBe(true)expect(v.warnings.join(' ')).toMatch(/EARLIER sync/)})it('does not warn when they are paired', () => {expect(checkPush(live()).warnings.join(' ')).not.toMatch(/EARLIER sync/)})it('is silent on a clean, paired, complete push', () => {expect(checkPush(live()).warnings).toEqual([])})})describe('every refusal explains itself', () => {it('names what to do, not just what is wrong', () => {const v = checkPush(live({ payloadMode: 'fixtures', htmlBytes: 10 }))expect(v.refusals.length).toBeGreaterThan(1)// A refusal a reader cannot act on gets worked around rather than fixed.for (const r of v.refusals) expect(r).toMatch(/`?pnpm|Run|Regenerate|Refusing/)})})