deploy-history.test.ts56 lines · main
1/**
2 * Unit tests for deploy-history boundary behaviour — pin the rules
3 * around what does and doesn't get recorded, and the listDeploys
4 * limit clamping. The DB write path is exercised by the post-deploy
5 * smoke and by the boot itself; this file covers the pure decisions.
6 */
7
8import { describe, expect, test } from 'bun:test';
9
10// Local mirror of the "skip dev sentinel" rule in deploy-history.ts.
11// Keeping the rule + its test side-by-side means a change to one
12// without the other shows up as a red test.
13function shouldRecord(buildSha: string): boolean {
14 return buildSha !== 'dev';
15}
16
17function clampLimit(limit: number | undefined): number {
18 return Math.min(Math.max(limit ?? 50, 1), 500);
19}
20
21describe('shouldRecord', () => {
22 test('skips the dev sentinel so local boots don\'t pollute the timeline', () => {
23 expect(shouldRecord('dev')).toBe(false);
24 });
25
26 test('records a real sha', () => {
27 expect(shouldRecord('a75e2b1b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f')).toBe(true);
28 });
29
30 test('short shas still record (resolveShaFromGit may return a 7-char if HEAD is detached)', () => {
31 // We don't enforce a length minimum because git itself doesn't —
32 // `git checkout abc1234` is valid and HEAD becomes that 7-char sha.
33 expect(shouldRecord('abc1234')).toBe(true);
34 });
35});
36
37describe('clampLimit', () => {
38 test('default is 50 when not specified', () => {
39 expect(clampLimit(undefined)).toBe(50);
40 });
41
42 test('floors at 1 — listDeploys({ limit: 0 }) is nonsensical', () => {
43 expect(clampLimit(0)).toBe(1);
44 expect(clampLimit(-100)).toBe(1);
45 });
46
47 test('caps at 500 — operator-visible bound on result-set growth', () => {
48 expect(clampLimit(1000)).toBe(500);
49 expect(clampLimit(500)).toBe(500);
50 });
51
52 test('passes through valid values', () => {
53 expect(clampLimit(10)).toBe(10);
54 expect(clampLimit(200)).toBe(200);
55 });
56});