|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * #11529 — `os build` / `os compile` printed a fixed 50 author-time advisories |
| 5 | + * and then stopped, with NOTHING in the output saying the list had been cut. |
| 6 | + * |
| 7 | + * Measured on `objectstack-ai/hotcrm` with the published 17.1.0 CLI: two |
| 8 | + * `objectstack build` runs over the same tree, before and after a five-warning |
| 9 | + * fix, printed 50 detailed entries each — 184 output lines, 52 warning lines, |
| 10 | + * both times — while the summary line counted 80 and then 75. Removing five |
| 11 | + * warnings did not shorten the list; it made room, and five advisories that |
| 12 | + * had been present all along appeared for the first time. |
| 13 | + * |
| 14 | + * The defect is the SILENCE, not the cap. A truncated report that carries no |
| 15 | + * notice is indistinguishable from a complete one, so an author who reads it |
| 16 | + * and sees their file is clean has read a list that stopped early. Same shape |
| 17 | + * as the dropped summary rows pinned in `print-metadata-stats-zero-row.test.ts` |
| 18 | + * (#10504, #10952): output that cannot distinguish "none" from "not shown". |
| 19 | + * |
| 20 | + * WHAT THESE PINS ASSERT — the pair, not the cap. A test that only checked |
| 21 | + * "50 entries printed" passes on the silent tree and pins nothing. So the |
| 22 | + * behaviour is pinned from both ends: |
| 23 | + * |
| 24 | + * - over the limit -> the output states how many were withheld; |
| 25 | + * - at or under it -> no such line appears at all. |
| 26 | + * |
| 27 | + * ALTITUDE: this pins `printAuthoringAdvisories` — the function `os build`'s |
| 28 | + * advisory block now consists of — rather than spawning the CLI, following the |
| 29 | + * `printMetadataStats` precedent set by the sibling fixes in this same family |
| 30 | + * (`print-metadata-stats-zero-row.test.ts`) and the `formatZodErrors` pattern |
| 31 | + * in `format-zod-union.test.ts`. No child process, so nothing here touches |
| 32 | + * `check:cli-test-child-env`. |
| 33 | + */ |
| 34 | + |
| 35 | +import { describe, expect, it } from 'vitest'; |
| 36 | +import { |
| 37 | + AUTHORING_ADVISORY_PRINT_LIMIT, |
| 38 | + printAuthoringAdvisories, |
| 39 | + type AuthoringAdvisory, |
| 40 | +} from '../src/utils/format.js'; |
| 41 | + |
| 42 | +/** Drop SGR sequences so an assertion reads the words, not chalk's opinion. */ |
| 43 | +const stripAnsi = (s: string) => s.replace(/\u001B\[[0-9;]*m/g, ''); |
| 44 | + |
| 45 | +/** Run the printer and return everything it printed, as one string. */ |
| 46 | +function render(advisories: readonly AuthoringAdvisory[], limit?: number): string { |
| 47 | + const captured: string[] = []; |
| 48 | + const original = console.log; |
| 49 | + console.log = (...args: unknown[]) => { |
| 50 | + captured.push(args.map(String).join(' ')); |
| 51 | + }; |
| 52 | + try { |
| 53 | + if (limit === undefined) printAuthoringAdvisories(advisories); |
| 54 | + else printAuthoringAdvisories(advisories, limit); |
| 55 | + } finally { |
| 56 | + console.log = original; |
| 57 | + } |
| 58 | + return stripAnsi(captured.join('\n')); |
| 59 | +} |
| 60 | + |
| 61 | +/** One advisory in the shape the authoring-rule registry emits. */ |
| 62 | +const advisory = (i: number): AuthoringAdvisory => ({ |
| 63 | + where: `view "views[${i}]" form`, |
| 64 | + message: `absolute colSpan ${i}`, |
| 65 | + rule: 'absolute-colspan-discouraged', |
| 66 | + path: `views[${i}].form`, |
| 67 | + hint: 'use a fractional colSpan', |
| 68 | +}); |
| 69 | + |
| 70 | +const many = (n: number): AuthoringAdvisory[] => Array.from({ length: n }, (_, i) => advisory(i)); |
| 71 | + |
| 72 | +/** How many detail entries the output carries — one `rule:` line per entry. */ |
| 73 | +const detailCount = (out: string) => out.split('\n').filter((l) => l.includes('rule: ')).length; |
| 74 | + |
| 75 | +/** |
| 76 | + * The notice, recognised by what makes it honest rather than by its full |
| 77 | + * wording: it names a remainder and says that remainder was not shown. |
| 78 | + */ |
| 79 | +const NOTICE = /and (\d+) more author-time warning\(s\) not shown/; |
| 80 | + |
| 81 | +describe('[#11529] the author-time advisory printer names what it withheld', () => { |
| 82 | + it('OVER the limit: states how many were withheld, and how many of how many were printed', () => { |
| 83 | + // The card's own measured run: 80 advisories against the shipped cap. |
| 84 | + // Literal numbers on purpose — this is the reproduction, so changing the |
| 85 | + // cap has to be a deliberate edit here rather than a silently-passing one. |
| 86 | + expect(AUTHORING_ADVISORY_PRINT_LIMIT).toBe(50); |
| 87 | + |
| 88 | + const out = render(many(80)); |
| 89 | + |
| 90 | + // Before the fix the output simply ended after the 50th entry. |
| 91 | + expect(out).toMatch(NOTICE); |
| 92 | + expect(out).toContain('and 30 more author-time warning(s) not shown (50 of 80)'); |
| 93 | + // And it points at a path that really does carry the whole set today, |
| 94 | + // rather than inventing a flag: `--json` publishes `warnings`. |
| 95 | + expect(out).toContain('--json'); |
| 96 | + }); |
| 97 | + |
| 98 | + it('AT the limit: prints every advisory and NO withheld line — the other half of the pair', () => { |
| 99 | + const out = render(many(50)); |
| 100 | + expect(detailCount(out)).toBe(50); |
| 101 | + // "50 printed" is true here AND on the truncated run above; only the |
| 102 | + // absence of the notice tells the two apart. |
| 103 | + expect(out).not.toMatch(NOTICE); |
| 104 | + expect(out).not.toContain('not shown'); |
| 105 | + }); |
| 106 | + |
| 107 | + it('UNDER the limit: no withheld line', () => { |
| 108 | + const out = render(many(3), 10); |
| 109 | + expect(detailCount(out)).toBe(3); |
| 110 | + expect(out).not.toMatch(NOTICE); |
| 111 | + }); |
| 112 | + |
| 113 | + it('ONE over the limit: the notice appears and reads exactly 1 — the tightest edge', () => { |
| 114 | + const out = render(many(11), 10); |
| 115 | + expect(detailCount(out)).toBe(10); |
| 116 | + expect(NOTICE.exec(out)?.[1]).toBe('1'); |
| 117 | + expect(out).toContain('(10 of 11)'); |
| 118 | + }); |
| 119 | + |
| 120 | + it('the remainder is the EXACT count, not a fixed word', () => { |
| 121 | + const out = render(many(8), 5); |
| 122 | + expect(NOTICE.exec(out)?.[1]).toBe('3'); |
| 123 | + expect(out).toContain('(5 of 8)'); |
| 124 | + }); |
| 125 | + |
| 126 | + it('control: the detail entries are unchanged — the notice adds, it does not replace', () => { |
| 127 | + const out = render(many(80)); |
| 128 | + expect(detailCount(out)).toBe(50); |
| 129 | + expect(out).toContain('view "views[0]" form: absolute colSpan 0'); |
| 130 | + expect(out).toContain('use a fractional colSpan'); |
| 131 | + expect(out).toContain('rule: absolute-colspan-discouraged at views[0].form'); |
| 132 | + // The 50th entry is present and the 51st is not — the cap still caps. |
| 133 | + expect(out).toContain('at views[49].form'); |
| 134 | + expect(out).not.toContain('at views[50].form'); |
| 135 | + }); |
| 136 | + |
| 137 | + it('control: an empty set prints nothing at all — no notice, no blank advisory block', () => { |
| 138 | + expect(render([])).toBe(''); |
| 139 | + }); |
| 140 | +}); |
0 commit comments