| 317 | } |
| 318 | |
| 319 | async fn start_fixture(external_payload: bool) -> DashboardFixture { |
| 320 | let tmp = tempdir_or_panic(); |
| 321 | let project_root = tmp.path().join("project"); |
| 322 | let global_db_path = tmp.path().join("global").join("global.db"); |
| 323 | let env_guard = EnvVarGuard::set(GLOBAL_DB_ENV, &global_db_path); |
| 324 | // Pre-create both GlobalDb-schema stores from the cached empty template |
| 325 | // so seeding and dashboard startup open existing DBs instead of paying a |
| 326 | // full schema creation each (slow on Windows). |
| 327 | write_empty_global_db_schema(&global_db_path).await; |
| 328 | |
| 329 | let cg = setup_project(&project_root).await; |
| 330 | let session_db_path = project_session_db_path(&project_root); |
| 331 | write_empty_global_db_schema(&session_db_path).await; |
| 332 | |
| 333 | let global_db = match GlobalDb::open_at(&session_db_path).await { |
| 334 | Some(db) => db, |
| 335 | None => panic!( |
| 336 | "failed to open temporary session DB at {}", |
| 337 | session_db_path.display() |
| 338 | ), |
| 339 | }; |
| 340 | let storage_root = session_db_path |
| 341 | .parent() |
| 342 | .unwrap_or_else(|| panic!("session DB has no parent: {}", session_db_path.display())); |
| 343 | if let Err(err) = std::fs::create_dir_all(storage_root) { |
| 344 | panic!("failed to create LCM storage root: {err}"); |
| 345 | } |
| 346 | let linked_node_id = |
| 347 | seed_lcm_fixture(&global_db, storage_root, &project_root, external_payload).await; |
| 348 | drop(global_db); |
| 349 | |
| 350 | if external_payload { |
| 351 | plant_external_needle(&session_db_path).await; |
| 352 | } |
| 353 | let port = pick_free_port(); |
| 354 | let base_url = format!("http://127.0.0.1:{port}"); |
| 355 | let server = tokio::spawn(async move { |
| 356 | let _ = dashboard::run(&cg, "127.0.0.1", port, false).await; |
| 357 | }); |
| 358 | |
| 359 | let agent = http_agent(); |
| 360 | wait_for_dashboard(&agent, &base_url).await; |
| 361 | |
| 362 | DashboardFixture { |
| 363 | _tmp: tmp, |
| 364 | _env_guard: env_guard, |
| 365 | base_url, |
| 366 | server, |
| 367 | global_db_path: session_db_path, |
| 368 | linked_node_id, |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | fn as_array<'a>(value: &'a Value, what: &str) -> &'a Vec<Value> { |
| 373 | value |