import { readFileSync } from 'node:fs';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, it, expect } from 'vitest';
/**
 * The e2e assignability guard (packages/e2e/src/db-type-guard.ts) catches
 * model types that are WRONG (fields/delegates the real client doesn't have),
 * but `ActuateDB` is allowed to be narrower than the real client — so a model
 * or enum added to the schema without regenerating would slip through it.
 * This test closes that gap: every model and enum in the canonical schema
 * must appear in the generated `model-types.ts`.
 *
 * If it fails, run `node scripts/generate-db-types.mjs` from the repo root.
 */
const here = dirname(fileURLToPath(import.meta.url));
const schema = readFileSync(join(here, '../../../prisma/schema.prisma'), 'utf8');
const generated = readFileSync(join(here, '../../db/model-types.ts'), 'utf8');
function blockNames(kind) {
    const names = [];
    const re = new RegExp(`^${kind}\\s+(\\w+)\\s+\\{`, 'gm');
    let m;
    while ((m = re.exec(schema)) !== null)
        names.push(m[1]);
    return names;
}
describe('db/model-types.ts freshness', () => {
    it('has an interface and ActuateModelMap entry for every schema model', () => {
        const models = blockNames('model');
        expect(models.length).toBeGreaterThan(0);
        for (const model of models) {
            expect(generated, `missing interface for model ${model}`).toMatch(new RegExp(`^export interface ${model} \\{`, 'm'));
            const delegate = model.charAt(0).toLowerCase() + model.slice(1);
            expect(generated, `missing ActuateModelMap entry for ${delegate}`).toMatch(new RegExp(`^  ${delegate}: ${model}$`, 'm'));
        }
    });
    it('has a type alias for every schema enum', () => {
        const enums = blockNames('enum');
        expect(enums.length).toBeGreaterThan(0);
        for (const e of enums) {
            // Long unions are wrapped by prettier (`export type Foo =\n  | '...'`),
            // so only assert up to the `=`.
            expect(generated, `missing enum type ${e}`).toMatch(new RegExp(`^export type ${e} =`, 'm'));
        }
    });
});
//# sourceMappingURL=model-types-freshness.test.js.map