Re: [PATCH v2 05/11] kconfig-audit: Split policy schema for component reuse
From: sashiko-bot
Date: Fri Dec 04 2026 - 17:50:26 EST
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] kconfig-audit: deprecated RefResolver in
SchemaFile._create_validator()
- [Low] kconfig-audit: symlinked schemas break $ref in
SchemaFile.parse()
- [Low] kconfig-audit: uncaught RefResolutionError in
Helpers.validate_yaml()
--
commit 754cf81ebb9a7fce9acd73e9326b44ad0a081fd7
Author: Ahmed S. Darwish <darwi@xxxxxxxxxxxxx>
kconfig-audit: Split policy schema for component reuse
This commit extracts the common rule schema into schema/rule.yml so
policy-v1.yml can reference it via $ref, and updates audit.py to build a
Draft7Validator with a local file:// RefResolver for sibling schema
files.
> diff --git a/tools/kconfig-audit/audit.py b/tools/kconfig-audit/audit.py
> index eac25740becab..94ff427715d11 100755
> --- a/tools/kconfig-audit/audit.py
> +++ b/tools/kconfig-audit/audit.py
[ ... ]
> @@ -249,12 +249,7 @@ class Helpers:
> def validate_yaml(yaml: YamlDict, schema: Schema, f_name: str) -> None:
> """Validate a parsed YAML mapping against passed JSON Schema"""
> try:
> - # For regex validation, manually enforce a format checker
> - jsonschema.validate(
> - yaml,
> - schema,
> - format_checker=jsonschema.FormatChecker(),
> - )
> + schema.validator.validate(yaml)
> except jsonschema.exceptions.ValidationError as e:
> error(
> f'{f_name} does not match its schema\n'
[Severity: Low]
Should validate_yaml() also catch jsonschema.exceptions.RefResolutionError?
Draft7Validator.check_schema() only validates metaschema grammar, so $ref
targets are resolved lazily during schema.validator.validate(). Because
RefResolutionError does not inherit from ValidationError, a broken $ref
escapes with a traceback and exit status 1 instead of os.EX_DATAERR.
[ ... ]
> def parse(self) -> Schema:
> """Parse and validate a policy schema file"""
>
> - schema = Schema(self.yaml)
> + rule_schema_f = self.schema_f.parent / 'rule.yml'
> + rule_schema_y = Helpers.load_yaml(rule_schema_f)
> +
> + self._check_schema(rule_schema_f, rule_schema_y)
> + self._check_schema(self.schema_f, self.schema_y)
> +
> + validator = self._create_validator({
> + rule_schema_f.resolve().as_uri(): rule_schema_y,
> + })
[Severity: Low]
Can resolving rule_schema_f and self.schema_f independently break $ref
lookup when schema files are symlinked?
If policy-v1.yml or rule.yml is individually symlinked to a different
directory or basename (as in Nix or symlink-farm packaging), resolving
rule.yml relative to base_uri in _create_validator() will miss the
preloaded store key and fall back to remote loading, failing validation.
Resolving self.schema_f.parent once and deriving both URIs from that
directory would keep base_uri and the store keys aligned.
[ ... ]
> + def _create_validator(self, store: dict[str, YamlDict]) -> YamlValidator:
> + """Create a schema validator for resolving sibling '$ref' entries"""
> +
> + resolver = jsonschema.RefResolver(
> + base_uri=self.schema_f.resolve().as_uri(),
> + referrer=self.schema_y,
> + store=store,
> + )
> +
> + return jsonschema.Draft7Validator(
> + self.schema_y,
> + resolver=resolver,
> + # For regex entries validation, manually enforce a format checker
> + format_checker=jsonschema.FormatChecker(),
> + )
[Severity: Low]
Will jsonschema.RefResolver and the resolver= argument emit deprecation
warnings on jsonschema >= 4.18.0?
Both were deprecated in favor of referencing.Registry passed via registry=.
Because audit.py runs as __main__, Python's default warning filter prints
both DeprecationWarning messages to stderr on every run, and fails under
python3 -W error or once jsonschema removes RefResolver.
Preferring referencing.Registry when available and falling back to
RefResolver for older jsonschema would avoid the warnings while keeping
compatibility.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203224916.118064-1-darwi@xxxxxxxxxxxxx?part=5