Files
eleith bf20865fe5
ci/woodpecker/pr/config Pipeline was successful
ci/woodpecker/pr/hledger Pipeline was successful
ci/woodpecker/pr/jobs Pipeline was successful
ci/woodpecker/pr/snapshots Pipeline was successful
ci/woodpecker/pr/web Pipeline was successful
ci/woodpecker/pr/worker Pipeline was successful
ci/woodpecker/push/config Pipeline was successful
ci/woodpecker/push/hledger Pipeline was successful
ci/woodpecker/push/jobs Pipeline was successful
ci/woodpecker/push/snapshots Pipeline was successful
ci/woodpecker/push/web Pipeline was successful
ci/woodpecker/push/worker Pipeline was successful
test: reduce redundant consumer coverage
Keep detailed rules at their owning boundaries and retain real native, SQLite, publication and service-lifetime integrations. Production code and financial format remain unchanged.
2026-11-06 14:48:56 -08:00

58 lines
2.2 KiB
TypeScript

import { mkdtemp, readFile, rm, stat, utimes, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, expect, it } from 'vitest';
import { configEditorSchema } from '../src/schema.js';
import { generateSchema } from './generate-schema.js';
const directories: string[] = [];
afterEach(async () => {
await Promise.all(
directories.splice(0).map((directory) => rm(directory, { recursive: true, force: true }))
);
});
async function fixture() {
const directory = await mkdtemp(join(tmpdir(), 'config-schema-'));
directories.push(directory);
return join(directory, 'schema.json');
}
it('generation serializes the source schema and check preserves exact bytes and mtime', async () => {
const path = await fixture();
await generateSchema([], path);
const generated = await readFile(path, 'utf8');
expect(JSON.parse(generated)).toEqual(JSON.parse(JSON.stringify(configEditorSchema)));
await utimes(path, 1, 1);
const before = await stat(path);
await generateSchema(['--check'], path);
expect(await readFile(path, 'utf8')).toBe(generated);
expect((await stat(path)).mtimeMs).toBe(before.mtimeMs);
});
it('check rejects byte-only drift without rewriting the artifact', async () => {
const path = await fixture();
await generateSchema([], path);
const drifted = (await readFile(path, 'utf8')) + '\n';
await writeFile(path, drifted);
await utimes(path, 1, 1);
const before = await stat(path);
await expect(generateSchema(['--check'], path)).rejects.toThrow(/out of date/);
expect(await readFile(path, 'utf8')).toBe(drifted);
expect((await stat(path)).mtimeMs).toBe(before.mtimeMs);
});
it('check rejects a missing artifact without creating it', async () => {
const path = await fixture();
await expect(generateSchema(['--check'], path)).rejects.toMatchObject({ code: 'ENOENT' });
await expect(stat(path)).rejects.toMatchObject({ code: 'ENOENT' });
});
it('invalid --check arguments leave the existing artifact untouched', async () => {
const path = await fixture();
await writeFile(path, 'unchanged');
await expect(generateSchema(['--check', 'extra'], path)).rejects.toThrow(/Usage:/);
expect(await readFile(path, 'utf8')).toBe('unchanged');
});