* chore(merge): resolve conflicts, fix mockWs error, and apply refactor standards * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * fix(ci): Stabilize github actions and resolve test failures - fix(tests): update WsClient mock to use standard function for Vitest constructor compatibility - fix(db): correct PrismaClient import path to use generated output directory - fix(e2e): add predev database boot step to playwright CI workflow - chore: sync pnpm-lock.yaml after merge conflict resolution * refactor(plugins): decouple GeoJSON plugin and implement data bus lifecycle - feat(sdk): [Minor] Added dynamicPluginCreate, dynamicPluginRemove, and pluginUnregistered to DataBusEvents. - feat(core): [Minor] Implemented unregisterPlugin in PluginManager.ts for automated IndexedDB caching cleanup and polling teardown. - feat(core): [Minor] Added removeLayer to layersSlice.ts to support safe removal of plugin states. - refactor(plugins): [Patch] Refactored useGeoJsonImport.ts and ImportedLayerList.tsx to decouple from direct manager imports, utilizing DataBus for lifecycle events. - refactor(core): [Patch] Added pluginUnregistered listener to DataBusSubscriber.tsx to handle state and cache cleanup synchronously via event. * fix(types): resolve PluginManager type errors * refactor(core): decouple PluginManager and fix rendering invariants - refactor(core): Replace Zustand mutations in PluginManager with DataBus events (Patch) - refactor(sdk): Add layerLoadingChanged, pluginError, pluginUnregistered to DataBusEvents (Patch) - refactor(ui): Subscribe to new DataBus events in DataBusSubscriber (Patch) - fix(plugins): Remove size from BaseAviationPlugin to fix model rendering clipping (Patch) - fix(plugins): Migrate BaseIncidentPlugin from size to iconScale to fix billboard clipping (Patch) * chore: resolve lockfile conflict * fix: restore BottomPanelManager in AppShell and fix vitest config * fix(layout): restore bottom panel positioning and transition styling This commit corrects the missing bottom panel issue by resolving CSS aggregation errors and fixing transition logic. The version is bumped to 2.15.5. * refactor(core): harden typescript and fix linting violations This commit addresses the remaining any types and linting errors across the core engine. * fix(eslint): resolve react-hook immutability and cascading render violations --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
153 lines
4.9 KiB
TypeScript
153 lines
4.9 KiB
TypeScript
/* eslint-disable no-console */
|
|
import { chromium, type FullConfig } from '@playwright/test';
|
|
import { PrismaClient } from '../src/generated/prisma/index.js';
|
|
import { PrismaPg } from "@prisma/adapter-pg";
|
|
import { Pool } from "pg";
|
|
import bcrypt from 'bcryptjs';
|
|
import crypto from 'crypto';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
export const TEST_USER_EMAIL = '[email protected]';
|
|
|
|
function loadEnv() {
|
|
try {
|
|
const envPath = path.resolve(process.cwd(), '.env');
|
|
if (fs.existsSync(envPath)) {
|
|
const content = fs.readFileSync(envPath, 'utf8');
|
|
content.split('\n').forEach(line => {
|
|
const match = line.match(/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/);
|
|
if (match) {
|
|
const key = match[1];
|
|
let value = match[2] || '';
|
|
if (value.startsWith('"') && value.endsWith('"')) value = value.slice(1, -1);
|
|
if (value.startsWith("'") && value.endsWith("'")) value = value.slice(1, -1);
|
|
process.env[key] = value;
|
|
}
|
|
});
|
|
}
|
|
} catch {
|
|
// Ignore read errors
|
|
}
|
|
}
|
|
|
|
async function globalSetup(config: FullConfig) {
|
|
loadEnv();
|
|
const { storageState, baseURL } = config.projects[0].use;
|
|
|
|
if (!baseURL) {
|
|
throw new Error('baseURL is not defined in Playwright config');
|
|
}
|
|
|
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL || "postgresql://postgres:[email protected]:5432/worldwideview?schema=public" });
|
|
const adapter = new PrismaPg(pool);
|
|
const prisma = new PrismaClient({ adapter });
|
|
|
|
try {
|
|
// 1. Retry/poll mechanism for database connectivity
|
|
let dbConnected = false;
|
|
for (let i = 0; i < 5; i++) {
|
|
try {
|
|
await prisma.$queryRaw`SELECT 1`;
|
|
dbConnected = true;
|
|
break;
|
|
} catch {
|
|
console.log(`[Setup] Waiting for database (attempt ${i + 1}/5)...`);
|
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
}
|
|
}
|
|
|
|
if (!dbConnected) {
|
|
throw new Error('[Setup] Could not connect to database after 5 attempts.');
|
|
}
|
|
|
|
// 2. Generate a secure random password and hash it
|
|
const password = crypto.randomUUID();
|
|
const hashedPassword = await bcrypt.hash(password, 10);
|
|
|
|
// 2.5 Defensive Cleanup for Mock Plugin
|
|
console.log(`[Setup] Cleaning up any existing mock plugins...`);
|
|
await prisma.installedPlugin.deleteMany({
|
|
where: { pluginId: { in: ['e2e-mock-plugin', 'e2e-mock-bottom-panel'] } }
|
|
});
|
|
|
|
// 3. Clean up any orphaned user and create the test user
|
|
console.log(`[Setup] Upserting test user: ${TEST_USER_EMAIL}`);
|
|
await prisma.user.deleteMany({
|
|
where: { email: TEST_USER_EMAIL }
|
|
});
|
|
|
|
await prisma.user.create({
|
|
data: {
|
|
email: TEST_USER_EMAIL,
|
|
name: 'Playwright E2E Tester',
|
|
hashedPassword: hashedPassword,
|
|
role: 'ADMIN',
|
|
},
|
|
});
|
|
|
|
// 3.5 Inject the mock plugin for the test environment
|
|
console.log(`[Setup] Injecting mock plugin into database...`);
|
|
const manifestPath = path.join(process.cwd(), 'public', 'e2e-fixtures', 'manifest.json');
|
|
const manifestStr = fs.readFileSync(manifestPath, 'utf-8');
|
|
await prisma.installedPlugin.create({
|
|
data: {
|
|
pluginId: 'e2e-mock-plugin',
|
|
version: '1.0.0',
|
|
config: manifestStr,
|
|
enabled: true
|
|
}
|
|
});
|
|
|
|
const bottomManifestPath = path.join(process.cwd(), 'public', 'e2e-fixtures', 'e2e-mock-bottom-panel-manifest.json');
|
|
const bottomManifestStr = fs.readFileSync(bottomManifestPath, 'utf-8');
|
|
await prisma.installedPlugin.create({
|
|
data: {
|
|
pluginId: 'e2e-mock-bottom-panel',
|
|
version: '1.0.0',
|
|
config: bottomManifestStr,
|
|
enabled: true
|
|
}
|
|
});
|
|
|
|
// Ensure playwright auth directory exists
|
|
if (typeof storageState === 'string') {
|
|
const authDir = path.dirname(storageState);
|
|
if (!fs.existsSync(authDir)) {
|
|
fs.mkdirSync(authDir, { recursive: true });
|
|
}
|
|
}
|
|
|
|
// 4. Perform UI Login
|
|
console.log(`[Setup] Logging in via UI to generate storage state...`);
|
|
const browser = await chromium.launch();
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto(`${baseURL}/login`);
|
|
await page.fill('input[name="email"]', TEST_USER_EMAIL);
|
|
await page.fill('input[name="password"]', password);
|
|
await page.click('button[type="submit"]');
|
|
|
|
// Wait for redirect to home
|
|
await page.waitForURL(baseURL);
|
|
|
|
// 5. Save storage state
|
|
if (typeof storageState === 'string') {
|
|
await page.context().storageState({ path: storageState });
|
|
} else {
|
|
console.warn("Storage state path is not a string, skipping saving context.")
|
|
}
|
|
|
|
await browser.close();
|
|
console.log(`[Setup] Global setup complete.`);
|
|
} catch (error) {
|
|
console.error(`[Setup] Error during global setup:`, error);
|
|
throw error;
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
export default globalSetup;
|