Skip to content

schema

schema

Unknown fields retained by the tolerant score loader (V010/V011).

Classes

Functions:

unknown_field_issue

unknown_field_issue(field, raw_yaml)

Classify one unknown key without rejecting the rest of the score.

Source code in src/marianne/validation/checks/schema.py
def unknown_field_issue(field: UnknownScoreField, raw_yaml: str) -> ValidationIssue:
    """Classify one unknown key without rejecting the rest of the score."""
    nearest = min(
        field.candidates, key=lambda key: (edit_distance(field.key, key), key), default=None
    )
    near = nearest is not None and edit_distance(field.key, nearest) <= 2
    # Curated onboarding hints fire at ANY depth (a `timeout:` next to a
    # trigger action is the same author mistake as a root `timeout:`); the
    # walk only emits keys that are unknown AT that location, so a curated
    # name can never collide with a legitimately known nested key.
    override = _KNOWN_TYPOS.get(field.key)
    if override is not None:
        override = _relative_hint(field, override)
    suggested = override or (nearest if near else None)
    # A curated onboarding hint is high-confidence even when the edit distance is high.
    severity = ValidationSeverity.WARNING if suggested else ValidationSeverity.INFO
    location = f"{field.path}.{field.key}" if field.path else field.key
    line = next(
        (
            i
            for i, text in enumerate(raw_yaml.splitlines(), 1)
            if text.lstrip().startswith(f"{field.key}:")
        ),
        None,
    )
    # D6: a correctly spelled key in the wrong place is a WARNING that names
    # its real path, not a hidden INFO. The bare name matching a known leaf
    # elsewhere (the walk already proved this spot unknown) means the author
    # moved a real key, not misspelled one.
    real_paths = _known_leaf_locations().get(field.key)
    if real_paths and not suggested:
        shown = " or ".join(f"`{p}`" for p in real_paths[:2])
        return ValidationIssue(
            check_id="V010",
            severity=ValidationSeverity.WARNING,
            message=f"Unknown field `{location}` will be ignored; "
            f"`{field.key}` is a score key that lives at {shown}",
            line=line,
            suggestion=f"Move `{field.key}` under {shown}",
            metadata={"field": location},
        )
    # A whole block at the root (`deliver: {1: {to: ...}}`) is not a typo
    # the author can be nudged on: it is a feature the score relies on and
    # the runtime does not implement (or a key from a branch that never
    # merged). INFO is hidden without --verbose, and a silently dropped
    # block is how a product learned at runtime that nothing wrote its
    # output file. A root block therefore warns.
    if field.block and not field.path and not suggested:
        return ValidationIssue(
            check_id="V010",
            severity=ValidationSeverity.WARNING,
            message=f"Unknown field `{location}` will be ignored — the runtime "
            "implements no such block, so nothing it configures will happen",
            line=line,
            suggestion=f"Remove `{field.key}` or move its intent to a key the "
            "runtime reads (see docs/configuration-reference.md)",
            metadata={"field": location},
        )
    return ValidationIssue(
        check_id="V010" if severity == ValidationSeverity.WARNING else "V011",
        severity=severity,
        message=f"Unknown field `{location}` will be ignored"
        + (f"; did you mean `{suggested}`?" if suggested else ""),
        line=line,
        suggestion=f"Use `{suggested}` instead" if suggested else None,
        metadata={"field": location},
    )