Skip to content

paths

paths

Path validation checks.

Validates that paths referenced in the configuration exist and are accessible.

Classes

ValidationPathScopeCheck

Check static path_in_scope rules resolve inside their allowed root (V306).

Methods:
check
check(config, config_path, raw_yaml)

Check path_in_scope rule paths when they are statically resolvable.

Source code in src/marianne/validation/checks/paths.py
def check(
    self,
    config: JobConfig,
    config_path: Path,
    raw_yaml: str,
) -> list[ValidationIssue]:
    """Check path_in_scope rule paths when they are statically resolvable."""
    issues: list[ValidationIssue] = []
    workspace = _workspace_path(config, config_path)

    for rule in config.validations:
        if rule.type != "path_in_scope" or not rule.path:
            continue
        scope_raw = rule.path_scope or "{workspace}"
        path = _expand_scope_template(rule.path, workspace)
        scope = _expand_scope_template(scope_raw, workspace)
        if path is None or scope is None:
            continue

        if not path.is_relative_to(scope):
            issues.append(
                ValidationIssue(
                    check_id=self.check_id,
                    severity=self.severity,
                    message=(
                        f"path_in_scope validation resolves outside its allowed scope: {path}"
                    ),
                    line=find_line_in_yaml(raw_yaml, rule.path),
                    suggestion=(
                        "Use a path under the workspace/scope, or fix "
                        "symlinks and '..' segments that resolve outside it"
                    ),
                    metadata={
                        "path": str(path),
                        "scope": str(scope),
                    },
                )
            )

    return issues

WorkspaceParentExistsCheck

Check that workspace parent directory exists (V002).

The workspace itself will be created, but its parent must exist. This is auto-fixable by creating the parent directories.

Methods:
check
check(config, config_path, raw_yaml)

Check workspace parent exists.

Source code in src/marianne/validation/checks/paths.py
def check(
    self,
    config: JobConfig,
    config_path: Path,
    raw_yaml: str,
) -> list[ValidationIssue]:
    """Check workspace parent exists."""
    issues: list[ValidationIssue] = []

    workspace = resolve_path(config.workspace, config_path)
    parent = workspace.parent

    if not parent.exists():
        issues.append(
            ValidationIssue(
                check_id=self.check_id,
                severity=self.severity,
                message=f"Workspace parent directory does not exist: {parent}",
                line=find_line_in_yaml(raw_yaml, "workspace:"),
                suggestion=f"Create parent directory: mkdir -p {parent}",
                auto_fixable=True,
                metadata={
                    "path": str(parent),
                    "workspace": str(workspace),
                },
            )
        )

    return issues

AbsoluteHomePathCheck

Flag machine-absolute paths under the user's home (V004).

Absolute /home/<user>/... (or equivalent) paths make scores non-portable and leak personal layout into shared artifacts. The portable forms are ~-relative, {workspace}/{score_dir} templates, and relative paths.

Judged against the RAW YAML, not the model: the model pre-resolves a ~/ workspace into an absolute-under-home Path at load time, which would false-positive the explicitly-portable tilde form. Movement cadenzas (movements.<n>.cadenzas) are scanned the same way (GH #571).

Methods:
check
check(config, config_path, raw_yaml)

Check workspace, prelude/cadenza paths, hook job_paths, variables.

Source code in src/marianne/validation/checks/paths.py
def check(
    self,
    config: JobConfig,
    config_path: Path,
    raw_yaml: str,
) -> list[ValidationIssue]:
    """Check workspace, prelude/cadenza paths, hook job_paths, variables."""
    data = parsed_document(raw_yaml)
    if data is None:
        return []

    home_prefix = str(Path.home())
    issues: list[ValidationIssue] = []

    def _is_home_absolute(value: str) -> bool:
        return value.startswith(home_prefix)

    def _flag(field: str, value: str) -> None:
        issues.append(
            ValidationIssue(
                check_id=self.check_id,
                severity=self.severity,
                message=(
                    f"Absolute home path in {field}: {value}. Scores must "
                    "stay portable — use ~, {score_dir}, {workspace}, or "
                    "a relative path."
                ),
                line=find_line_in_yaml(raw_yaml, value),
                suggestion=(
                    f"Replace the absolute path in {field} with a "
                    "portable form (~/, {score_dir}/, {workspace}/, or "
                    "score-relative)."
                ),
                metadata={"field": field, "path": value},
            )
        )

    def _scan_items(items: object, field: str) -> None:
        if not isinstance(items, list):
            return
        for item in items:
            if not isinstance(item, dict):
                continue
            for key in ("file", "directory"):
                val = item.get(key)
                if isinstance(val, str) and _is_home_absolute(val):
                    _flag(f"{field}.{key}", val)

    # workspace — judged from raw (model pre-resolves ~/ to absolute)
    ws = data.get("workspace")
    if isinstance(ws, str) and _is_home_absolute(ws):
        _flag("workspace", ws)

    sheet_cfg = data.get("sheet")
    if isinstance(sheet_cfg, dict):
        _scan_items(sheet_cfg.get("prelude"), "prelude")
        cadenzas = sheet_cfg.get("cadenzas")
        if isinstance(cadenzas, dict):
            for items in cadenzas.values():
                _scan_items(items, "cadenzas")
        stdout_to = sheet_cfg.get("stdout_to")
        if isinstance(stdout_to, dict):
            for num, target in stdout_to.items():
                if isinstance(target, str) and _is_home_absolute(target):
                    _flag(f"sheet.stdout_to.{num}", target)

    # Movement cadenzas (#571): scan the raw declarations too, so a
    # home-absolute path in a movement cadenza cannot escape V004.
    movements_cfg = data.get("movements")
    if isinstance(movements_cfg, dict):
        for stage, movement in movements_cfg.items():
            if not isinstance(movement, dict):
                continue
            movement_items = movement.get("cadenzas")
            if isinstance(movement_items, list):
                _scan_items(movement_items, f"movements.{stage}.cadenzas")

    prompt_cfg = data.get("prompt")
    if isinstance(prompt_cfg, dict):
        variables = prompt_cfg.get("variables")
        if isinstance(variables, dict):
            for key, val in variables.items():
                values = val if isinstance(val, list) else [val]
                for v in values:
                    if isinstance(v, str) and _is_home_absolute(v):
                        _flag(f"prompt.variables.{key}", v)

    hooks = data.get("on_success")
    if isinstance(hooks, list):
        for hook in hooks:
            if not isinstance(hook, dict):
                continue
            job_path = hook.get("job_path")
            if isinstance(job_path, str) and _is_home_absolute(job_path):
                _flag("on_success.job_path", job_path)

    return issues

TemplateFileExistsCheck

Check that template_file exists if specified (V003).

Methods:
check
check(config, config_path, raw_yaml)

Check template_file exists.

Source code in src/marianne/validation/checks/paths.py
def check(
    self,
    config: JobConfig,
    config_path: Path,
    raw_yaml: str,
) -> list[ValidationIssue]:
    """Check template_file exists."""
    issues: list[ValidationIssue] = []

    if config.prompt.template_file:
        template_path = resolve_path(config.prompt.template_file, config_path)

        if not template_path.exists():
            issues.append(
                ValidationIssue(
                    check_id=self.check_id,
                    severity=self.severity,
                    message=f"Template file not found: {template_path}",
                    line=find_line_in_yaml(raw_yaml, "template_file:"),
                    suggestion="Create the template file or fix the path",
                    metadata={
                        "expected_path": str(template_path),
                    },
                )
            )
        elif not template_path.is_file():
            issues.append(
                ValidationIssue(
                    check_id=self.check_id,
                    severity=self.severity,
                    message=f"Template path is not a file: {template_path}",
                    line=find_line_in_yaml(raw_yaml, "template_file:"),
                    suggestion="Ensure template_file points to a file, not a directory",
                )
            )

    return issues

InjectionSizeCheck

A static injection item already exceeds its max_bytes (V334).

The runtime refuses (required) or drops (optional) an over-cap item at every sheet; this is the same measurement taken once, before the run, for paths that need no templating. A snapshot, not the contract — a ledger that is under the cap now can cross it on sheet 40 (GH #474).

A REQUIRED item over its cap is an ERROR: the sheet cannot run, and a warning let nine fleet scores through every static gate to fail at sheet 1 (GH #515). An optional item stays a WARNING (it will be dropped). A movement cadenza item is measured once per declaration, under the source label cadenza (stage N) (GH #571).

PreludeCadenzaFileCheck

Check that prelude/cadenza files exist when paths are static (V108).

Only checks non-templated paths (no Jinja {{). Templated paths are resolved at execution time and cannot be validated statically. Definite input files must exist before execution.

Movement cadenzas (movements.<n>.cadenzas, GH #571) are checked like sheet cadenzas: once per (stage, item), under the source label cadenza (stage N), with the same declared-product exemption.

Methods:
check
check(config, config_path, raw_yaml)

Check prelude and cadenza file/directory paths.

Source code in src/marianne/validation/checks/paths.py
def check(
    self,
    config: JobConfig,
    config_path: Path,
    raw_yaml: str,
) -> list[ValidationIssue]:
    """Check prelude and cadenza file/directory paths."""
    issues: list[ValidationIssue] = []

    # Files a stage is declared to produce at runtime are not expected
    # on disk now — suppress the
    # not-found warning for them on cadenzas (#137 point 5). Whether they
    # are produced EARLY ENOUGH is V109's job, not this disk check's.
    produced = set(_infer_producers(config))

    for item in config.sheet.prelude:
        # Prelude injects before any sheet runs — no producer can precede
        # it, so no suppression applies.
        issues.extend(self._check_item(item, "prelude", config, config_path, raw_yaml, set()))
    for sheet_num, items in config.sheet.cadenzas.items():
        for item in items:
            issues.extend(
                self._check_item(
                    item,
                    f"cadenza (sheet {sheet_num})",
                    config,
                    config_path,
                    raw_yaml,
                    produced,
                )
            )
    for stage, movement_items in movement_cadenzas(config).items():
        # One finding per (stage, item) — not one per voice (#571).
        for movement_item in movement_items:
            issues.extend(
                self._check_item(
                    movement_item,
                    f"cadenza (stage {stage})",
                    config,
                    config_path,
                    raw_yaml,
                    produced,
                )
            )

    return issues

CadenzaOrderingCheck

V109: a cadenza reads a file whose producer runs later (#137).

Uses three signals: - CONSUMER: cadenzas (which sheet injects/reads which file). A movement cadenza (movements.<n>.cadenzas, GH #571) is read by each voice it reaches, so it is judged per voice, with at most one finding per (stage, item). - PRODUCER: movement produces, stdout_to, or the sheet-gated file_exists proxy (in descending ownership priority). - ORDER: the dependency DAG (which sheet is guaranteed to run first).

Warns when a cadenza on sheet M reads a file F that some sheet P is declared to produce, but P is NOT a DAG-ancestor of M — so F is not guaranteed to exist when M's cadenza fires. WARNING only: declared output is not proof that a file exists at cadenza time. F is matched to the producers by file name as written, so a per-voice path such as unit-{{ voice }}.md matches only a producer declared under that same name.

Functions: