import '../assert_dev_env.js';
import { bootstrap_backend } from './bootstrap_backend.js';
import { serialize_bootstrapped_handle } from './setup.js';
/**
 * Build a vitest `globalSetup` default export that spawns both backends.
 */
export const create_schema_parity_global_setup = ({ configs, provide_keys = { a: 'parity_handle_a', b: 'parity_handle_b' }, }) => {
    return async (project) => {
        const a = await bootstrap_backend(configs.a());
        // Tear `a` down if `b` fails to spawn — no orphaned child process.
        let b;
        try {
            b = await bootstrap_backend(configs.b());
        }
        catch (err) {
            await a.teardown();
            throw err;
        }
        const provide = project.provide;
        provide(provide_keys.a, serialize_bootstrapped_handle(a));
        provide(provide_keys.b, serialize_bootstrapped_handle(b));
        return async () => {
            await b.teardown();
            await a.teardown();
        };
    };
};
