From e5430ad4caa73d73fa7155f10090299b67e7f2ab Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 25 Sep 2026 14:07:07 +0200 Subject: [PATCH] refactor(lint): read the AI model vars through the cache in the quant check test_local_model_quant_pinned opened group_vars/all/16_ai.yml twice per run, once with yaml.safe_load for the entries and once with read_text to find an alias line, so the file was parsed again for a check that several other lints already read it for. test_no_uncached_file_reads rejects that, and it rejected this module: restoring the previous version fails test_modules_in_scope_use_cached_read_text, and the current one passes it. load_yaml and read_text from utils.cache memoise by absolute path. The 'or {}' guard goes with the raw loader rather than being dropped silently: load_yaml returns a mapping or raises TypeError on any other root, so .get cannot meet None, and a malformed file now fails at this lint instead of reading as an empty model list that the check would pass over. d7bd200da1 on feature/store-i18n applies the same idiom to five other modules. The two do not overlap: that branch cannot carry this file, which 499f8a4445 created here, so the sweep there and this commit together leave one pattern rather than two. Co-Authored-By: Claude Opus 5 (1M context) --- .../variables/test_local_model_quant_pinned.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/lint/ansible/variables/test_local_model_quant_pinned.py b/tests/lint/ansible/variables/test_local_model_quant_pinned.py index badd3baf65..255ca79527 100644 --- a/tests/lint/ansible/variables/test_local_model_quant_pinned.py +++ b/tests/lint/ansible/variables/test_local_model_quant_pinned.py @@ -29,9 +29,9 @@ from __future__ import annotations import unittest from typing import ClassVar -import yaml - from utils.annotations.suppress import is_suppressed_at +from utils.cache.files import read_text +from utils.cache.yaml import load_yaml from . import PROJECT_ROOT @@ -41,15 +41,12 @@ _KEY = "AI_LOCAL_MODELS" def _entries() -> list[dict]: - data = yaml.safe_load(_VARS_FILE.read_text(encoding="utf-8")) or {} - declared = data.get(_KEY) + declared = load_yaml(_VARS_FILE).get(_KEY) return [entry for entry in (declared or []) if isinstance(entry, dict)] def _line_of(alias: str) -> int: - for number, line in enumerate( - _VARS_FILE.read_text(encoding="utf-8").splitlines(), 1 - ): + for number, line in enumerate(read_text(str(_VARS_FILE)).splitlines(), 1): if f"alias: {alias}" in line: return number return 0