A test that redirects production includes with jw.include-map can silently
read a real production path when the map misses a spec, making the test
depend on the host's /etc without any warning.
Add a jw.include-map-no-absolute key next to the map. When true, an
absolute include spec that matched no map entry raises ValueError, 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.
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.6.0
This 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
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.0
The parse_opts test is a plain script that constructs an Options from
sys.argv and crashed on the first get() call, because the by_index
condition in Options.get() is inverted and raises KeyError for an integer
index. It has several shortcomings, though:
- "make test" doesn't execute it, only make -C test/parse_opts run, so CI
doesn't run it
- It doesn't adhere to standard janware directory layout
- It's very basic
Replace the script with a pytest module under
test/unit/python/jw/util/Options, following the layout of the sibling
unit test directories: a Makefile including py-test.mk and a test.py
discovered by pytest. The module covers parsing of option strings, repeated
keys, JSON values, flags, get() with defaults and the by_index parameter,
__contains__, __iter__, keys(), str() and update().
Signed-off-by: Jan Lindemann <jan@janware.com>
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
The test tree needs to be aligned with type checking, too, because jw-pkg
is going to required it for test, too. The load_yaml and StringTree tests
receive their fixtures as bare Callable and Generator without type
arguments, and the StringTree tests pass the st fixture without an
annotation. The cast script suppresses errors with un-coded type ignore
comments, and the parse_opts script declares its loop variable as
"str | int", so indexing the Options object with it is rejected.
Introduce _YamlFile, _TempDir, and _St aliases for the fixture types and
give the st parameters an annotation. Code the type ignore comments with
the argument mismatch they suppress, and split the parse_opts loop variable
into i for the index loops and k for the key loops.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1
Signed-off-by: Jan Lindemann <jan@janware.com>
An optional include with a target path that points to a missing
file leaves a trace in the output: _load_yaml() still calls
_merge_at_path() with the empty document, which creates the target
key as an empty mapping. A root-level optional include of the same
file contributes nothing, so the outcome depends on whether the
spec names a target path.
Skip included documents that are empty: an empty document
contributes nothing, at the root as well as at a target path, and
creates no key. Update the module docstring accordingly and add
tests covering a missing optional include with a target path.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
The jw.include file spec is resolved as a single literal file name,
so a set of files under one directory has to be listed one by one.
Let the file part of a spec use glob characters (*, ?, [...]).
_normalize_include_specs() expands every match into its own
IncludeSpec entry, so matches are loaded and deep-merged in lexical
order: at the root, later files win; at a target path, the existing
content wins as with a single include. A non-optional glob that
matches no files raises ValueError; the leading - prefix keeps a
glob optional. Document the globbing in the module docstring,
including the YAML quoting requirement for specs that start with a
glob character, and add tests covering the glob syntax, lexical
order, the no-match and optional cases, target-path merging,
absolute paths, and self-inclusion.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
The memoisation cache in _expand_links_recursive() stores the expanded
value of a link node. A link node that is first reached via another
link, and later visited by the normal tree walk, is expanded only
once; the cached result object is then returned as-is for the second
location. Both places in the output tree end up holding the same
dict, so mutating one of them silently mutates the other.
Deepcopy the value on every cache read so that each place in the
output tree holds an independent object. Add a regression test that
mutates one cached location and checks the others stay untouched.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
_INCLUDE_PATH_RE allows the pipe character in the target-path part of
a jw.include spec such as 'target.path|file.yaml'. The greedy match
then consumes further pipes, so a file name that itself contains a
pipe is misparsed: the target swallows part of the file name and the
remainder becomes the (nonexistent) file to open. Dots are needed in
the target part for nested paths, but a pipe can never be part of a
target path.
Drop the pipe from the character class so that the first pipe always
separates the target path from the file name. Add a regression test
with a pipe in the file name.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
A link value that is not a string (for example a number parsed from
YAML) is passed to the regular expression in _parse_link(), which
crashes with a bare TypeError from the regex engine that does not
mention the offending value or the link kind.
Make _resolve_link() validate the spec type up front and raise
TypeError naming the link kind and the value. Add tests for both
jw.link and jw.inplace-link.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
When a link's target path cannot be resolved, the raw KeyError from
_resolve_path() propagates to the caller (or a raw TypeError when a
path segment hits a list), without saying which link or which
document location caused the failure. The parse-and-resolve
sequence is also duplicated in the jw.link and jw.inplace-link
branches of _expand_links_recursive().
Extract the sequence into _resolve_link() and wrap navigation
failures in ValueError naming the link kind, the spec, and the
location in the document. Document that path navigation operates on
the unexpanded tree, so intermediate segments must not be link nodes
themselves. Update the tests that pinned KeyError and add coverage
for the list-navigation case and the error message content.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
A jw.inplace-link node deep-merges its sibling keys into the resolved
target. When the target resolves to a non-dict value, the merge is
skipped and the sibling keys are silently discarded, losing document
data without any warning.
Raise ValueError when the resolved target is not a mapping and the
node carries sibling keys, and add regression tests for scalar and
list targets.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
When jw.include specifies a target path, _merge_at_path() walks the
existing document to that path. If an intermediate key holds a
non-dict value, that value is silently replaced by an empty dict; if
the leaf key holds a non-dict value, it is silently replaced by the
included mapping. Both cases discard local document data without
warning, and the leaf case even inverts the documented precedence in
which local content wins over included content (which holds for the
dict-versus-dict case).
Make _merge_at_path() raise ValueError when an existing value on or
at the target path is not a mapping, and add regression tests for
both the intermediate and the leaf case.
Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
When jw.include merges content at a target path, the local content in
the main document should take precedence over the included content
(siblings win, and the main file is the ultimate source of truth).
Fix _merge_at_path so that root's existing content at the target path
wins over the value being merged in.
Also update the test_include_override_existing test to reflect the
correct semantics: local content overrides included content.
Signed-off-by: Jan Lindemann <jan@janware.com>
jw.include now supports specifying a target path where the included
content should be merged, using syntax similar to named links:
jw.include: "path.to.target|/path/to/file.yaml"
The file's contents are deep-merged into the target path in the
resulting document tree. If the target path doesn't exist,
intermediate dicts are created automatically.
Original behavior (plain string) still works:
jw.include: "/path/to/file.yaml"
This merges the file at the root of the document.
Mixed usage is supported:
jw.include:
- "/path/to/plain.yaml"
- section|/path/to/target.yaml
Added 8 unit tests covering: plain includes, nested paths, deep paths,
merge with existing, override existing, multiple paths, optional
includes, and mixed plain/path includes.
Signed-off-by: Jan Lindemann <jan@janware.com>
jw.inplace-link behaves like jw.link but can have sibling keys that
are deep-merged into the resolved target dict (siblings override target
on conflict).
Usage:
entry:
jw.inplace-link: path.to.target
sibling_key: value
Expands to:
entry:
<merged result of path.to.target + sibling_key: value>
This solves the common use case of pulling in a dict from elsewhere
while overriding specific keys inline.
Added 12 unit tests covering: no siblings, dict siblings, scalar
siblings, non-dict targets, relative paths, cycle detection, chains,
list siblings, list items, deep nesting, sibling override, and
integration with jw.include.
Signed-off-by: Jan Lindemann <jan@janware.com>
The include directive was previously triggered by a bare "include"
key in YAML files. This could collide with user-defined keys.
Rename it to "jw.include" so that:
jw.include: file.yaml
jw.include:
- file1.yaml
- file2.yaml
is used instead of just "include:". This follows the convention
established by "jw.link" for link expansion markers.
Signed-off-by: Jan Lindemann <jan@janware.com>
Implement link expansion in _expand_links() to resolve jw.link markers
in YAML documents after the include/merge phase. Two link forms are
supported:
- Inplace links jw.link: "path.to.target" replace the marker entirely
with the resolved value at the target path.
- Named links jw.link: "name|path.to.target" replace the marker with
{name: resolved_value}, using the first path segment as the key.
Paths use dot-separated segments. Relative paths start with ".."
(like Python imports): "." stays at the current level, ".." goes up
one level, "..." two, and so on. A single pipe character in the link
value separates the link name from the target path for named links.
The implementation includes:
- _parse_link(): splits a link value into (is_named, name, path)
- _resolve_path(): resolves an absolute or relative path to a value
- _expand_links_recursive(): walks the structure, expands links,
detects cycles via a resolving set, and memoises via a resolved dict.
Cyclic links and missing targets both raise ValueError/KeyError.
jw.link markers with sibling keys are left unexpanded.
Add 86 unit tests covering the entire load_yaml module:
- Basic YAML loading, optional loading, root type checking
- Include directive (single, multiple, deep merge, circular detect)
- Inplace links, named links, relative paths (up, descend, same level)
- Transitive links, cycle detection, missing targets
- Regression tests, combined include+links, edge cases, type preservation
Signed-off-by: Jan Lindemann <jan@janware.com>
Add pytest-style unit tests for the StringTree class.
This commit also adds the needed infrastructure: Dependency on
python3-pytest, the unit test directory structure and conftest.py in
.gitignore.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.80.2
Signed-off-by: Jan Lindemann <jan@janware.com>