load_yaml: Redirect and parameterize includes for tests #6
Loading…
Reference in a new issue
No description provided.
Delete branch "jan/feature/20261120-load-yaml-redirect-and-parameterize-includes-for-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Test wrappers that mimic production invocations need to run production-style
YAML documents against repository-local copies, without modifying the files
meant to be installed as is. This PR adds the include machinery for that:
$(VAR)expansion in top-level include specs, ajw.include-maptable thatrewrites include specs to tree-local targets, and
jw.include-map-no-absoluteto fail loudly when the map misses an absolute spec.
load_yaml: Expand variables in top-level include specs
Test wrappers that mimic production invocations redirect the includes of production documents to tree-local copies; the target location depends on where the tree is checked out, so it would be nice if the wrapper could take
TOPDIRfrom the environment instead of hardcoding it.Allow the file part of a top-level include spec to reference environment variables as
$(VAR)or${VAR}._load_yaml()receives a depth counter, zero at the top level and one per include level, and threads it to_normalize_include_specs()and_parse_include_spec(); the file part passes through_expand_include_vars()only at depth zero, after the optional marker and the target path have been split off. Specs in included documents keep their literal behaviour. An undefined variable raisesValueError, naming the reference and the file it came from.load_yaml: Add jw.include-map
This commit adds support for interpreting a new syntax:
Production configs include absolute paths outside the repository tree, so a test that runs a production-style document against repository-local copies must redirect those includes, ideally without modifying the files meant to be installed as is.
Add a
jw.include-mapkey to the top-level document: an ordered list of single-key mappings from LHS pattern to RHS pattern or list of RHS patterns. Before resolution, the file part of each include spec is qualified against the including file's directory and matched against the LHS patterns in table order; the first match rewrites the spec to every RHS pattern of that entry. Relative LHS and RHS values are interpreted against the directory of the document that declares the map, so matching runs on canonical paths and same-named includes from different directories stay distinguishable. The optional marker and the target path are decomposed before the rewrite: every rewritten source inherits the spec's optionality, and the target path applies to the merged result._parse_include_map(): parse and validate the table; only*is supported in an LHS, a RHS may not have more*than its LHS, and RHS values expand$(VAR)and${VAR}from the environment_canonicalize_path(): join a relative path with a base directory and normalize, without disk access_compile_lhs_pattern(): compile a canonical LHS into an anchored regex whose*groups match runs that are not/_apply_include_map(): match the first entry and fill the LHS captures into every RHS pattern; log the rewrite atDEBUG_load_yaml(): parse the map once in the top-level document, reject it in included documents, thread it through the include treeload_yaml: Support jw.include-map-no-absolute
A test that redirects production includes with
jw.include-mapcan silently read a real production path when the map misses a spec, making the test depend on the host's/etcwithout any warning.Add a
jw.include-map-no-absolutekey next to the map. When true, an absolute include spec that matched no map entry raisesValueError, naming the spec and the including file; an identity entry whitelists an absolute path that may be read. The key defaults to false and applies to the whole include tree:_load_yaml()pops it in the top-level document, rejects it in included documents, and threads it to_parse_include_spec(), where the check runs before the normal disk lookup.Test wrappers that mimic production invocations redirect the includes of production documents to tree-local copies; the target location depends on where the tree is checked out, so it would be nice if the wrapper could take TOPDIR from the environment instead of hardcoding it. Allow the file part of a top-level include spec to reference environment variables as $(VAR) or ${VAR}. _load_yaml() receives a depth counter, zero at the top level and one per include level, and threads it to _normalize_include_specs() and _parse_include_spec(); the file part passes through _expand_include_vars() only at depth zero, after the optional marker and the target path have been split off. Specs in included documents keep their literal behaviour. An undefined variable raises ValueError, naming the reference and the file it came from. Signed-off-by: Jan Lindemann <jan@janware.com> Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.6.0This commit adds support for interpreting a new syntax: jw.include-map: - /etc/some/file.conf: ../../../file.conf - /opt/blah/another/config.yaml: ../../../config.yaml Production configs include absolute paths outside the repository tree, so a test that runs a production-style document against repository-local copies must redirect those includes, ideally without modifying the files meant to be installed as is. Add a jw.include-map key to the top-level document: an ordered list of single-key mappings from LHS pattern to RHS pattern or list of RHS patterns. Before resolution, the file part of each include spec is qualified against the including file's directory and matched against the LHS patterns in table order; the first match rewrites the spec to every RHS pattern of that entry. Relative LHS and RHS values are interpreted against the directory of the document that declares the map, so matching runs on canonical paths and same-named includes from different directories stay distinguishable. The optional marker and the target path are decomposed before the rewrite: every rewritten source inherits the spec's optionality, and the target path applies to the merged result. - _parse_include_map(): parse and validate the table; only '*' is supported in an LHS, a RHS may not have more '*' than its LHS, and RHS values expand $(VAR) and ${VAR} from the environment - _canonicalize_path(): join a relative path with a base directory and normalize, without disk access - _compile_lhs_pattern(): compile a canonical LHS into an anchored regex whose '*' groups match runs that are not '/' - _apply_include_map(): match the first entry and fill the LHS captures into every RHS pattern; log the rewrite at DEBUG - _load_yaml(): parse the map once in the top-level document, reject it in included documents, thread it through the include tree Signed-off-by: Jan Lindemann <jan@janware.com> Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.6.0