{{ header }}import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { existsSync } from 'fs';

// Change to the configured test-documents directory so that fixture file
// paths like "pdf/fake_memo.pdf" resolve correctly when running vitest
// from e2e/node/. setup.ts lives in e2e/node/; the fixtures dir lives at
// the repository root, two directories up: e2e/node/ -> e2e/ -> root.
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const testDocumentsDir = join(__dirname, '..', '..', '{{ test_documents_dir }}');

// Validate that the test documents directory exists before changing into it.
// If it doesn't exist, log the error to stderr so the before hook failure
// is visible rather than failing silently.
if (!existsSync(testDocumentsDir)) {
	console.error(
		`[E2E Setup] test_documents directory not found: ${testDocumentsDir}\n` +
		`Check that alef.toml [crates.e2e] test_documents_dir is configured correctly.\n` +
		`Fixture file paths will not resolve correctly.`
	);
	process.exit(1);
}

try {
	process.chdir(testDocumentsDir);
} catch (error) {
	console.error(`[E2E Setup] Failed to change directory to ${testDocumentsDir}: ${error}`);
	process.exit(1);
}

// Mark this file as a module so vitest recognizes the setup
export {};
