feat: load neutral workflow config

This commit is contained in:
lda
2026-06-03 08:33:33 +07:00 Verified
parent a071ba1085
commit 1a3fe5916e
3 changed files with 78 additions and 0 deletions
+2
View File
@@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
from .loader import load_workflow_config
from .models import ( from .models import (
ClientConfig, ClientConfig,
FilesystemStoreConfig, FilesystemStoreConfig,
@@ -12,6 +13,7 @@ from .models import (
) )
__all__ = [ __all__ = [
"load_workflow_config",
"ClientConfig", "ClientConfig",
"FilesystemStoreConfig", "FilesystemStoreConfig",
"LocalTargetConfig", "LocalTargetConfig",
+32
View File
@@ -0,0 +1,32 @@
from __future__ import annotations
import json
from pathlib import Path
from .models import FilesystemStoreConfig, WorkflowConfigFile
def load_workflow_config(path: str | Path) -> WorkflowConfigFile:
"""Load neutral workflow config and resolve local filesystem paths.
Relative filesystem store roots are config-file relative so `wf --config`
behaves the same regardless of the caller's current working directory.
"""
config_path = Path(path)
data = json.loads(config_path.read_text(encoding="utf-8"))
config = WorkflowConfigFile.model_validate(data)
store = config.server.store
if isinstance(store, FilesystemStoreConfig) and not store.root.is_absolute():
config = config.model_copy(
update={
"server": config.server.model_copy(
update={
"store": store.model_copy(
update={"root": (config_path.parent / store.root).resolve()}
)
}
)
}
)
return config
+44
View File
@@ -87,3 +87,47 @@ def test_workflow_config_rejects_unknown_target_kind() -> None:
"client": {"target": {"kind": "mcp"}}, "client": {"target": {"kind": "mcp"}},
} }
) )
import json
from wf_config import load_workflow_config
def test_load_workflow_config_resolves_filesystem_store_relative_to_config(
tmp_path,
) -> None:
config_path = tmp_path / "wf.json"
config_path.write_text(
json.dumps(
{
"version": 1,
"server": {
"store": {"kind": "filesystem", "root": ".wf_store"},
},
}
),
encoding="utf-8",
)
config = load_workflow_config(config_path)
assert config.server.store.root == (tmp_path / ".wf_store").resolve()
def test_load_workflow_config_preserves_absolute_filesystem_store(tmp_path) -> None:
absolute_root = (tmp_path / "absolute-store").resolve()
config_path = tmp_path / "wf.json"
config_path.write_text(
json.dumps(
{
"version": 1,
"server": {
"store": {"kind": "filesystem", "root": str(absolute_root)},
},
}
),
encoding="utf-8",
)
config = load_workflow_config(config_path)
assert config.server.store.root == absolute_root