feat: rewrite core layer (errors, template, paths, platform, console, runtime, config)

Complete rewrite of all core modules with proper abstractions:
- FlowError hierarchy with PlanConflict and ExecutionError
- Pure template substitution ($VAR, ${VAR}, {{expr}})
- XDG path constants
- Frozen PlatformInfo dataclass with context detection
- Console with color/quiet/TTY support
- Runtime primitives (CommandRunner, FileSystem, GitClient, SystemRuntime)
- Config loading with target parsing and manifest merging

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-16 04:48:14 +02:00
parent 327201a0ed
commit 6bb41aa001
14 changed files with 823 additions and 407 deletions

46
tests/test_template.py Normal file
View File

@@ -0,0 +1,46 @@
"""Tests for flow.core.template."""
import os
from flow.core.template import substitute, substitute_template
class TestSubstitute:
def test_replaces_dollar_var(self):
assert substitute("hello $NAME", {"NAME": "world"}) == "hello world"
def test_replaces_braced_var(self):
assert substitute("hello ${NAME}", {"NAME": "world"}) == "hello world"
def test_falls_back_to_env(self, monkeypatch):
monkeypatch.setenv("FOO", "bar")
assert substitute("$FOO", {}) == "bar"
def test_preserves_unknown_vars(self):
assert substitute("$UNKNOWN", {}) == "$UNKNOWN"
def test_non_string_passthrough(self):
assert substitute(42, {}) == 42
class TestSubstituteTemplate:
def test_replaces_double_braces(self):
assert substitute_template("nvim-{{os}}", {"os": "linux"}) == "nvim-linux"
def test_env_dot_notation(self, monkeypatch):
monkeypatch.setenv("USER", "tomas")
result = substitute_template("{{ env.USER }}", {"env": dict(os.environ)})
assert result == "tomas"
def test_nested_dict_lookup(self):
ctx = {"platform": {"arch": "arm64"}}
assert substitute_template("{{ platform.arch }}", ctx) == "arm64"
def test_preserves_unknown_templates(self):
assert substitute_template("{{ unknown }}", {}) == "{{ unknown }}"
def test_non_string_passthrough(self):
assert substitute_template(42, {}) == 42
def test_whitespace_in_braces(self):
assert substitute_template("{{ os }}", {"os": "linux"}) == "linux"