mirror of
https://github.com/ModernRelay/omnigraph.git
synced 2026-06-24 02:38:06 +02:00
feat(config,cli): global-first layered config load
Add load_layered_config: load the global ~/.omnigraph/config.yaml layer under the project ./omnigraph.yaml (or --config) layer and merge them, returning the merged config, its provenance, and per-layer deprecation warnings. The CLI's load_cli_config now uses it — so a graph/server/defaults defined only in the global config is usable from any directory with no project file. The server stays single-layer (a deployment manifest must not pick up ambient $HOME state). Global and cwd-default files are optional (absent = no layer); an explicit project --config still errors if missing. base_dir stays the highest loaded layer's config dir so relative ad-hoc --query paths resolve as before. The CLI test harness pins OMNIGRAPH_HOME to an empty temp dir so tests never read the developer's real global config.
This commit is contained in:
parent
d3ebc29c05
commit
059fbe4c4a
4 changed files with 212 additions and 9 deletions
|
|
@ -4,6 +4,7 @@ use std::fs;
|
|||
use std::net::TcpListener;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Child, Command as StdCommand, Output, Stdio};
|
||||
use std::sync::OnceLock;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
@ -12,12 +13,26 @@ use reqwest::blocking::Client;
|
|||
use serde_json::Value;
|
||||
use tempfile::{TempDir, tempdir};
|
||||
|
||||
/// A process-wide empty temp dir used as `OMNIGRAPH_HOME` for every spawned CLI,
|
||||
/// so tests never pick up the developer's real `~/.omnigraph/config.yaml` (the
|
||||
/// global config layer). Tests exercising global-first set `OMNIGRAPH_CONFIG` /
|
||||
/// `OMNIGRAPH_HOME` explicitly to override this isolation.
|
||||
fn isolated_omnigraph_home() -> &'static Path {
|
||||
static HOME: OnceLock<TempDir> = OnceLock::new();
|
||||
HOME.get_or_init(|| tempdir().expect("isolated OMNIGRAPH_HOME"))
|
||||
.path()
|
||||
}
|
||||
|
||||
pub fn cli() -> Command {
|
||||
Command::cargo_bin("omnigraph").unwrap()
|
||||
let mut command = Command::cargo_bin("omnigraph").unwrap();
|
||||
command.env("OMNIGRAPH_HOME", isolated_omnigraph_home());
|
||||
command
|
||||
}
|
||||
|
||||
pub fn cli_process() -> StdCommand {
|
||||
StdCommand::new(assert_cmd::cargo::cargo_bin("omnigraph"))
|
||||
let mut command = StdCommand::new(assert_cmd::cargo::cargo_bin("omnigraph"));
|
||||
command.env("OMNIGRAPH_HOME", isolated_omnigraph_home());
|
||||
command
|
||||
}
|
||||
|
||||
fn server_process() -> StdCommand {
|
||||
|
|
@ -112,7 +127,7 @@ pub fn write_file(path: &Path, source: &str) {
|
|||
fs::write(path, source).unwrap();
|
||||
}
|
||||
|
||||
fn yaml_string(value: &str) -> String {
|
||||
pub fn yaml_string(value: &str) -> String {
|
||||
format!("'{}'", value.replace('\'', "''"))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue