| 401 | } |
| 402 | |
| 403 | async fn start_fixture(seed: FixtureSeed) -> Fixture { |
| 404 | let tmp = TempDir::new().expect("temp dir"); |
| 405 | let project_root = tmp.path().join("project"); |
| 406 | std::fs::create_dir_all(&project_root).expect("project dir"); |
| 407 | std::fs::write( |
| 408 | project_root.join("lib.rs"), |
| 409 | "pub fn savings_fixture() -> u32 { 7 }\n", |
| 410 | ) |
| 411 | .expect("seed source file"); |
| 412 | |
| 413 | let global_db_path = tmp.path().join("global").join("global.db"); |
| 414 | let env_guards = vec![ |
| 415 | EnvVarGuard::set("TRACEDECAY_GLOBAL_DB", &global_db_path), |
| 416 | // `.cargo/config.toml` disables global accounting for cargo-launched |
| 417 | // processes; opt back in so the recording state reads "enabled". |
| 418 | EnvVarGuard::set("TRACEDECAY_ENABLE_GLOBAL_DB", "1"), |
| 419 | EnvVarGuard::set("TRACEDECAY_OFFLINE", "1"), |
| 420 | // Point the pricing cache at a path that never exists → the bundled |
| 421 | // fallback snapshot must serve. |
| 422 | EnvVarGuard::set( |
| 423 | "TRACEDECAY_MODEL_PRICES_PATH", |
| 424 | tmp.path().join("no-such-prices.json"), |
| 425 | ), |
| 426 | ]; |
| 427 | |
| 428 | // Pre-create both GlobalDb-schema stores from the cached empty template |
| 429 | // so seeding and dashboard startup open existing DBs instead of paying a |
| 430 | // full schema creation each (slow on Windows). |
| 431 | write_empty_global_db_schema(&global_db_path).await; |
| 432 | |
| 433 | let now = now_unix(); |
| 434 | let day_start = now - (now % 86_400); |
| 435 | match seed { |
| 436 | FixtureSeed::Base => seed_global_db(&global_db_path, &project_root, day_start).await, |
| 437 | FixtureSeed::LedgerOnly => seed_ledger_db(&global_db_path, &project_root, day_start).await, |
| 438 | FixtureSeed::DailyLimitRegression => {} |
| 439 | } |
| 440 | |
| 441 | let cg = TraceDecay::init(&project_root) |
| 442 | .await |
| 443 | .expect("tracedecay init"); |
| 444 | let session_db_path = project_session_db_path(&project_root); |
| 445 | if !session_db_path.exists() { |
| 446 | write_empty_global_db_schema(&session_db_path).await; |
| 447 | } |
| 448 | match seed { |
| 449 | FixtureSeed::Base => seed_global_db(&session_db_path, &project_root, day_start).await, |
| 450 | FixtureSeed::LedgerOnly => {} |
| 451 | FixtureSeed::DailyLimitRegression => { |
| 452 | seed_daily_limit_regression( |
| 453 | &session_db_path, |
| 454 | &global_db_path, |
| 455 | &project_root, |
| 456 | day_start, |
| 457 | ) |
| 458 | .await; |
| 459 | } |
| 460 | } |