import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
/**
 * Guard against the Phase 5.5 regression where `relationLoadStrategy:
 * 'join'` was added to the dashboard / versions / bench queries
 * without the `relationJoins` Preview-feature flag in the schema.
 * Prisma silently rejects the option as an "Unknown argument" when
 * the flag is missing — for `safeFindMany` callers that surfaces as
 * an empty result and for the versions endpoint as a 500 to the
 * client. Either failure mode is hard to spot without a deliberate
 * bench run, so pin the schema's preview-feature set with a tiny
 * test rather than a code-review-only convention.
 *
 * If the preview-feature set legitimately needs to change, update
 * the assertion below in the same commit — that way the rationale
 * surfaces in the diff.
 */
describe('Prisma schema preview features', () => {
    const here = dirname(fileURLToPath(import.meta.url));
    const schemaPath = resolve(here, '..', '..', 'prisma', 'schema.prisma');
    const schema = readFileSync(schemaPath, 'utf8');
    it('declares relationJoins so `relationLoadStrategy: "join"` is honoured', () => {
        const match = schema.match(/previewFeatures\s*=\s*\[([^\]]*)\]/);
        expect(match, 'schema.prisma must declare a previewFeatures array').not.toBeNull();
        const features = (match[1] ?? '')
            .split(',')
            .map((s) => s.trim().replace(/^"|"$/g, ''))
            .filter(Boolean);
        expect(features).toContain('relationJoins');
    });
    it('still declares fullTextSearchPostgres (search uses it)', () => {
        const match = schema.match(/previewFeatures\s*=\s*\[([^\]]*)\]/);
        const features = (match[1] ?? '')
            .split(',')
            .map((s) => s.trim().replace(/^"|"$/g, ''))
            .filter(Boolean);
        expect(features).toContain('fullTextSearchPostgres');
    });
});
//# sourceMappingURL=schema-preview-features.test.js.map