mattrguerra/meridian-ops-boardmainPrivate on GitHub, published here in full

push-guard.test.ts

Language TypeScript3.8 KB103 lines

apps/dashboard/test/push-guard.test.ts

  1. /**
  2. * `pnpm push` writes straight into the Worker's KV, which is what the team reads.
  3. * There is no review step between a laptop and that page, so the checks that
  4. * would normally be a person noticing have to live in code.
  5. *
  6. * The one that matters most: `pnpm dashboard --fixtures` writes the SAME
  7. * filenames as a live run. A push straight after one would put sample orders on
  8. * the production board under four confident "live" source pills, the exact
  9. * failure `Snapshot.mode` was introduced to prevent, except now with an audience.
  10. */
  11. import { describe, expect, it } from 'vitest'
  12. import { checkPush, type PushInputs } from '../src/push-guard.js'
  13. const live = (over: Partial<PushInputs> = {}): PushInputs => ({
  14. payloadMode: 'live',
  15. payloadGeneratedAt: '2026-08-25T20:27:27.386Z',
  16. htmlBytes: 105_707,
  17. briefingsMode: 'live',
  18. briefingsPayloadGeneratedAt: '2026-08-25T20:27:27.386Z',
  19. briefingCount: 9,
  20. ...over,
  21. })
  22. describe('fixtures never reach the deployed board', () => {
  23. it('refuses a fixture payload', () => {
  24. const v = checkPush(live({ payloadMode: 'fixtures' }))
  25. expect(v.ok).toBe(false)
  26. expect(v.refusals.join(' ')).toMatch(/FIXTURE/)
  27. })
  28. it('refuses fixture briefings even when the payload is live', () => {
  29. // Possible in practice: a live sync, then brief.py run with --allow-fixtures
  30. // against an older payload. The prose would name people as holding work they
  31. // finished.
  32. const v = checkPush(live({ briefingsMode: 'fixtures' }))
  33. expect(v.ok).toBe(false)
  34. })
  35. it('refuses a mode it does not recognise rather than assuming it is real', () => {
  36. for (const mode of ['demo', '', null, undefined, 'LIVE']) {
  37. expect(checkPush(live({ payloadMode: mode })).ok, String(mode)).toBe(false)
  38. }
  39. })
  40. it('allows a live push', () => {
  41. const v = checkPush(live())
  42. expect(v.ok).toBe(true)
  43. expect(v.refusals).toEqual([])
  44. })
  45. })
  46. describe('a broken render is not published', () => {
  47. it('refuses a page far too small to be a dashboard', () => {
  48. // A failed render still writes a file. 500 bytes is an error page, not a board.
  49. expect(checkPush(live({ htmlBytes: 500 })).ok).toBe(false)
  50. })
  51. it('refuses a missing page', () => {
  52. expect(checkPush(live({ htmlBytes: 0 })).ok).toBe(false)
  53. })
  54. it('accepts a real render', () => {
  55. expect(checkPush(live({ htmlBytes: 105_707 })).ok).toBe(true)
  56. })
  57. it('refuses a payload with no timestamp, since nothing on it can be dated', () => {
  58. expect(checkPush(live({ payloadGeneratedAt: null })).ok).toBe(false)
  59. })
  60. })
  61. describe('things worth saying but not worth stopping for', () => {
  62. it('warns when there are no briefings rather than refusing', () => {
  63. // Numbers-only is a legitimate push; the page says the written briefing was
  64. // not generated. But a silent one looks identical to a complete push.
  65. const v = checkPush(live({ briefingCount: 0 }))
  66. expect(v.ok).toBe(true)
  67. expect(v.warnings.join(' ')).toMatch(/No written briefings/)
  68. })
  69. it('warns when the briefings describe a different sync than the page', () => {
  70. const v = checkPush(live({ briefingsPayloadGeneratedAt: '2026-08-25T06:00:00.000Z' }))
  71. expect(v.ok).toBe(true)
  72. expect(v.warnings.join(' ')).toMatch(/EARLIER sync/)
  73. })
  74. it('does not warn when they are paired', () => {
  75. expect(checkPush(live()).warnings.join(' ')).not.toMatch(/EARLIER sync/)
  76. })
  77. it('is silent on a clean, paired, complete push', () => {
  78. expect(checkPush(live()).warnings).toEqual([])
  79. })
  80. })
  81. describe('every refusal explains itself', () => {
  82. it('names what to do, not just what is wrong', () => {
  83. const v = checkPush(live({ payloadMode: 'fixtures', htmlBytes: 10 }))
  84. expect(v.refusals.length).toBeGreaterThan(1)
  85. // A refusal a reader cannot act on gets worked around rather than fixed.
  86. for (const r of v.refusals) expect(r).toMatch(/`?pnpm|Run|Regenerate|Refusing/)
  87. })
  88. })