|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * The call-site census of the vouched-reference mark (`vouchForReference`, |
| 5 | + * `./vouched-reference.ts`), run where `Test Core` runs it: the gate's own |
| 6 | + * self-test (its red and green cases, with the battery floor and the verdict |
| 7 | + * handshake), then the scan of this tree, which must be green — every |
| 8 | + * production file that sets the mark is in the gate's `ALLOWED_CALLERS` with |
| 9 | + * its exact call-site count. The gate's header is the authority on the rule. |
| 10 | + */ |
| 11 | + |
| 12 | +import { describe, expect, it } from 'vitest'; |
| 13 | +import { spawnSync } from 'node:child_process'; |
| 14 | +import { dirname, resolve } from 'node:path'; |
| 15 | +import { fileURLToPath } from 'node:url'; |
| 16 | + |
| 17 | +const HERE = dirname(fileURLToPath(import.meta.url)); |
| 18 | +const REPO_ROOT = resolve(HERE, '../../../..'); |
| 19 | +const GATE = resolve(HERE, '../../../../scripts/check-vouch-for-reference-callers.mjs'); |
| 20 | + |
| 21 | +const run = (...args: string[]) => |
| 22 | + spawnSync(process.execPath, [GATE, ...args], { cwd: REPO_ROOT, encoding: 'utf8' }); |
| 23 | + |
| 24 | +describe('check:vouch-for-reference-callers', () => { |
| 25 | + it('its self-test reaches its verdict: every red and green case holds, and no battery fell below its floor', () => { |
| 26 | + const out = run('--self-test'); |
| 27 | + expect(out.stderr).toBe(''); |
| 28 | + expect(out.status).toBe(0); |
| 29 | + expect(out.stdout).toMatch(/self-test: \d+ cases pass/); |
| 30 | + }); |
| 31 | + |
| 32 | + it('this tree is green: the only production caller is the file-attachments writer, at its pinned count', () => { |
| 33 | + const out = run(); |
| 34 | + expect(out.stderr).toBe(''); |
| 35 | + expect(out.status).toBe(0); |
| 36 | + expect(out.stdout).toContain('packages/services/service-storage/src/file-attachment-service.ts (2)'); |
| 37 | + }); |
| 38 | +}); |
0 commit comments