vomebook commited on
Commit ·
e65e1f9
1
Parent(s): 382e4d0
Gate search matching and corpus format mutations
Browse files
mutation-equivalent-data-formats.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tool": "mutmut 3.8.1",
|
| 3 |
+
"source": "backend/data_formats.py",
|
| 4 |
+
"source_sha256": "8a24ba52d935bdaa182534c939448ba849527a8d04bb1890648a70cdd47ccfa0",
|
| 5 |
+
"equivalent": {
|
| 6 |
+
"backend.data_formats.x_decode_search_payload__mutmut_3": {
|
| 7 |
+
"sha256": "c6951d627a59938b6585811b64ad2e196537469423d0b953b4139a0b68be2371",
|
| 8 |
+
"rationale": "typing.cast returns its second argument unchanged; CompactCorpus and None are evaluated as type hints but neither is applied to data at runtime."
|
| 9 |
+
},
|
| 10 |
+
"backend.data_formats.x_decode_search_payload__mutmut_34": {
|
| 11 |
+
"sha256": "e748938294ba1fce6ccc1779ade46157439a5cf96c56830ccf9da0d7f9d02aee",
|
| 12 |
+
"rationale": "typing.cast returns raw_item unchanged irrespective of its first argument; list[object] and None have no effect on the decoded record."
|
| 13 |
+
},
|
| 14 |
+
"backend.data_formats.x_decode_tree_node__mutmut_20": {
|
| 15 |
+
"sha256": "c622274f9e191d799182add121af74b01a99bb3d5a43096dec3f8120e83a703d",
|
| 16 |
+
"rationale": "The recursive is_root argument changes from False to None. decode_tree_node only tests its truth value when deriving path and isRoot, so either makes the child non-root and is not retained in the output."
|
| 17 |
+
},
|
| 18 |
+
"backend.data_formats.x_decode_tree_node__mutmut_23": {
|
| 19 |
+
"sha256": "5e04c65ca5d5c8b0ff27e942b10f3f1f74a977096680ae2045ba34a892e1c3ef",
|
| 20 |
+
"rationale": "Removing the recursive is_root positional argument selects decode_tree_node's own default False, the same value originally supplied."
|
| 21 |
+
},
|
| 22 |
+
"backend.data_formats.x_decode_folder_tree_data__mutmut_2": {
|
| 23 |
+
"sha256": "1ed43a1586faa962b242cad733260b1985476c9ca48ffc02453c39e583337681",
|
| 24 |
+
"rationale": "parent_path changes from empty string to None only in a decode_tree_node call with is_root=True. That branch sets path to empty string without inspecting parent_path; all child calls receive that path instead."
|
| 25 |
+
},
|
| 26 |
+
"backend.data_formats.x_decode_folder_tree_data__mutmut_7": {
|
| 27 |
+
"sha256": "f325f18da7ccfc29bb4998eab690a1a648614775090ee38f239663f5342cf00a",
|
| 28 |
+
"rationale": "parent_path changes from empty string to XXXX only in a decode_tree_node call with is_root=True. That branch sets path to empty string without inspecting parent_path; all child calls receive that path instead."
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
}
|
mutation-equivalent-search-matching.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tool": "mutmut 3.8.1",
|
| 3 |
+
"source": "backend/search_matching.py",
|
| 4 |
+
"source_sha256": "3869dca4057d86a7f7176e53c968f7f6bff19d5fd76977ae961b64dcde5a8843",
|
| 5 |
+
"equivalent": {
|
| 6 |
+
"backend.search_matching.x_compile_exact_matcher__mutmut_91": {
|
| 7 |
+
"sha256": "88464ddfa3e5fcc94b5681a967aee983093b6eb490e57b1a5e7cef7ec16fd1a9",
|
| 8 |
+
"rationale": "When wildcard is false the changed conditional value is ORed with 1 immediately afterwards; 0 | 1 and 1 | 1 both equal 1. When wildcard is true the changed branch is not evaluated."
|
| 9 |
+
},
|
| 10 |
+
"backend.search_matching.x_is_fuzzy_match__mutmut_7": {
|
| 11 |
+
"sha256": "a84aa6cfb4f4dc48730fb5a727365b0409a94ae0f7eaae9881da2aced97d03a9",
|
| 12 |
+
"rationale": "The omitted positional argument uses could_be_fuzzy's own default max_dist=2, identical to the explicit 2 at this call site."
|
| 13 |
+
},
|
| 14 |
+
"backend.search_matching.x_is_fuzzy_match__mutmut_14": {
|
| 15 |
+
"sha256": "a147bc5ffa719411ca99154af9e21b0ecfb620a846b13e14d38f928b5ed8df67",
|
| 16 |
+
"rationale": "The omitted keyword uses edit_distance's own default max_dist=2, identical to the explicit max_dist=2 at this call site."
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
}
|
scripts/check_search_words_mutation.py
CHANGED
|
@@ -1,20 +1,21 @@
|
|
| 1 |
-
"""Run pinned mutation
|
| 2 |
from __future__ import annotations
|
| 3 |
|
|
|
|
| 4 |
import ast
|
| 5 |
import hashlib
|
|
|
|
| 6 |
import json
|
| 7 |
import os
|
| 8 |
from pathlib import Path
|
|
|
|
| 9 |
import shutil
|
| 10 |
import subprocess
|
| 11 |
import sys
|
| 12 |
import tempfile
|
| 13 |
|
| 14 |
ROOT = Path(__file__).resolve().parents[1]
|
| 15 |
-
|
| 16 |
-
SOURCE = ROOT / "backend/search_words.py"
|
| 17 |
-
TEST = ROOT / "tests/test_search_words_contract.py"
|
| 18 |
SELECTED_TESTS = [
|
| 19 |
"test_ascii_cjk_and_punctuation_tokens_with_injected_segmenter",
|
| 20 |
"test_all_cjk_inclusive_boundaries_are_independent_tokens",
|
|
@@ -23,22 +24,44 @@ SELECTED_TESTS = [
|
|
| 23 |
"test_missing_file_and_folder_defaults_are_empty",
|
| 24 |
"test_records_digest_uses_order_and_field_delimiters",
|
| 25 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
def mutation_errors(stats: dict[str, int], outcomes: dict[str, int],
|
| 29 |
current_hashes: dict[str, str], reviewed: dict[str, dict[str, str]]) -> list[str]:
|
| 30 |
errors: list[str] = []
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
errors.append("mutation results are incomplete or contain unexpected outcomes")
|
| 33 |
-
for status in
|
| 34 |
if stats.get(status, 0):
|
| 35 |
errors.append(f"mutation results contain {status}: {stats[status]}")
|
| 36 |
survived = {key for key, code in outcomes.items() if code == 0}
|
| 37 |
-
if any(code not in (0, 1) for code in outcomes.values()):
|
| 38 |
errors.append("mutation outcomes contain errors or timeouts")
|
| 39 |
for key in sorted(survived):
|
| 40 |
entry = reviewed.get(key)
|
| 41 |
-
if not entry or entry.get("sha256") != current_hashes.get(key)
|
|
|
|
| 42 |
errors.append(f"unreviewed surviving mutation: {key}")
|
| 43 |
for key in sorted(set(reviewed) - survived):
|
| 44 |
errors.append(f"stale equivalent-mutation review: {key}")
|
|
@@ -46,23 +69,34 @@ def mutation_errors(stats: dict[str, int], outcomes: dict[str, int],
|
|
| 46 |
|
| 47 |
|
| 48 |
def main() -> int:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
print("Mutation equivalent review must match the exact source and tool version", file=sys.stderr)
|
| 53 |
return 1
|
| 54 |
-
with tempfile.TemporaryDirectory(prefix="reader-
|
| 55 |
temp = Path(directory)
|
| 56 |
(temp / "backend").mkdir()
|
| 57 |
(temp / "tests").mkdir()
|
| 58 |
shutil.copyfile(ROOT / "backend/__init__.py", temp / "backend/__init__.py")
|
| 59 |
-
shutil.copyfile(
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
(temp / "tests/__init__.py").write_text("")
|
| 62 |
-
selections = ["tests/
|
| 63 |
-
|
| 64 |
(temp / "pyproject.toml").write_text(
|
| 65 |
-
'[tool.mutmut]\nsource_paths = ["backend/"]\
|
|
|
|
| 66 |
+ 'pytest_add_cli_args_test_selection = ' + json.dumps(selections) + '\n'
|
| 67 |
+ 'use_git_change_detection = false\nuse_setproctitle = false\n')
|
| 68 |
env = os.environ.copy()
|
|
@@ -71,9 +105,10 @@ def main() -> int:
|
|
| 71 |
command = [sys.executable, "-B", "-m", "mutmut", *args]
|
| 72 |
subprocess.run(command, cwd=temp, env=env, check=True, timeout=600) # noqa: S603
|
| 73 |
stats = json.loads((temp / "mutants/mutmut-cicd-stats.json").read_text())
|
| 74 |
-
meta = json.loads((temp / "mutants/backend/
|
| 75 |
-
generated = (temp / "mutants/backend/
|
| 76 |
functions = {node.name: node for node in ast.parse(generated).body if isinstance(node, ast.FunctionDef)}
|
|
|
|
| 77 |
hashes = {}
|
| 78 |
for key, code in meta["exit_code_by_key"].items():
|
| 79 |
if code == 0:
|
|
@@ -82,8 +117,12 @@ def main() -> int:
|
|
| 82 |
raise RuntimeError(f"missing generated source for {key}")
|
| 83 |
hashes[key] = hashlib.sha256(segment.encode()).hexdigest()
|
| 84 |
errors = mutation_errors(stats, meta["exit_code_by_key"], hashes, review["equivalent"])
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
if errors:
|
| 88 |
print("\n".join(errors), file=sys.stderr)
|
| 89 |
return 1
|
|
|
|
| 1 |
+
"""Run pinned pure-backend mutation gates in a temporary copy of the checkout."""
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
+
import argparse
|
| 5 |
import ast
|
| 6 |
import hashlib
|
| 7 |
+
from importlib.metadata import version
|
| 8 |
import json
|
| 9 |
import os
|
| 10 |
from pathlib import Path
|
| 11 |
+
import re
|
| 12 |
import shutil
|
| 13 |
import subprocess
|
| 14 |
import sys
|
| 15 |
import tempfile
|
| 16 |
|
| 17 |
ROOT = Path(__file__).resolve().parents[1]
|
| 18 |
+
TOOL_VERSION = "3.8.1"
|
|
|
|
|
|
|
| 19 |
SELECTED_TESTS = [
|
| 20 |
"test_ascii_cjk_and_punctuation_tokens_with_injected_segmenter",
|
| 21 |
"test_all_cjk_inclusive_boundaries_are_independent_tokens",
|
|
|
|
| 24 |
"test_missing_file_and_folder_defaults_are_empty",
|
| 25 |
"test_records_digest_uses_order_and_field_delimiters",
|
| 26 |
]
|
| 27 |
+
MATCHING_TESTS = [
|
| 28 |
+
"test_matching_helpers_keep_wildcard_results_after_large_character_cache",
|
| 29 |
+
"test_fuzzy_precheck_and_distance_are_bounded",
|
| 30 |
+
"test_exact_and_wildcard_matchers_keep_unicode_and_newline_semantics",
|
| 31 |
+
"test_wildcards_agree_with_independent_regular_expression_reference",
|
| 32 |
+
"test_fuzzy_helpers_match_independent_distance_and_multiset_references",
|
| 33 |
+
"test_wildcard_cache_keeps_repeated_characters_and_clears_at_limit",
|
| 34 |
+
"test_wildcard_cache_reuses_literal_scans_across_matches",
|
| 35 |
+
"test_fuzzy_match_stops_at_the_two_edit_work_bound",
|
| 36 |
+
]
|
| 37 |
+
SPECS: dict[str, tuple[str, list[str], list[str]]] = {
|
| 38 |
+
"search_words": ("test_search_words_contract.py", SELECTED_TESTS, []),
|
| 39 |
+
"search_matching": ("test_search_words_contract.py", MATCHING_TESTS, ["search_words.py"]),
|
| 40 |
+
"data_formats": ("test_data_formats_contract.py", [], []),
|
| 41 |
+
}
|
| 42 |
+
EMPTY_STATUSES = ("no_tests", "skipped", "suspicious", "timeout", "check_was_interrupted_by_user", "segfault")
|
| 43 |
|
| 44 |
|
| 45 |
def mutation_errors(stats: dict[str, int], outcomes: dict[str, int],
|
| 46 |
current_hashes: dict[str, str], reviewed: dict[str, dict[str, str]]) -> list[str]:
|
| 47 |
errors: list[str] = []
|
| 48 |
+
required = ("total", "killed", "survived", *EMPTY_STATUSES)
|
| 49 |
+
if any(type(stats.get(key)) is not int or stats[key] < 0 for key in required):
|
| 50 |
+
return ["mutation statistics are missing or invalid"]
|
| 51 |
+
if (stats.get("total", 0) <= 0 or stats.get("total") != len(outcomes)
|
| 52 |
+
or stats.get("killed") != sum(code == 1 for code in outcomes.values())
|
| 53 |
+
or stats.get("survived") != sum(code == 0 for code in outcomes.values())):
|
| 54 |
errors.append("mutation results are incomplete or contain unexpected outcomes")
|
| 55 |
+
for status in EMPTY_STATUSES:
|
| 56 |
if stats.get(status, 0):
|
| 57 |
errors.append(f"mutation results contain {status}: {stats[status]}")
|
| 58 |
survived = {key for key, code in outcomes.items() if code == 0}
|
| 59 |
+
if any(type(code) is not int or code not in (0, 1) for code in outcomes.values()):
|
| 60 |
errors.append("mutation outcomes contain errors or timeouts")
|
| 61 |
for key in sorted(survived):
|
| 62 |
entry = reviewed.get(key)
|
| 63 |
+
if (not entry or not current_hashes.get(key) or entry.get("sha256") != current_hashes.get(key)
|
| 64 |
+
or not entry.get("rationale")):
|
| 65 |
errors.append(f"unreviewed surviving mutation: {key}")
|
| 66 |
for key in sorted(set(reviewed) - survived):
|
| 67 |
errors.append(f"stale equivalent-mutation review: {key}")
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
def main() -> int:
|
| 72 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 73 |
+
parser.add_argument("--module", choices=tuple(SPECS), default="search_words")
|
| 74 |
+
module = parser.parse_args().module
|
| 75 |
+
test_name, selected, dependencies = SPECS[module]
|
| 76 |
+
source = ROOT / "backend" / f"{module}.py"
|
| 77 |
+
test = ROOT / "tests" / test_name
|
| 78 |
+
equivalent = ROOT / f"mutation-equivalent-{module.replace('_', '-')}.json"
|
| 79 |
+
review = json.loads(equivalent.read_text())
|
| 80 |
+
source_hash = hashlib.sha256(source.read_bytes()).hexdigest()
|
| 81 |
+
if (version("mutmut") != TOOL_VERSION or review.get("tool") != f"mutmut {TOOL_VERSION}"
|
| 82 |
+
or review.get("source") != f"backend/{module}.py" or review.get("source_sha256") != source_hash):
|
| 83 |
print("Mutation equivalent review must match the exact source and tool version", file=sys.stderr)
|
| 84 |
return 1
|
| 85 |
+
with tempfile.TemporaryDirectory(prefix=f"reader-{module}-mutation-") as directory:
|
| 86 |
temp = Path(directory)
|
| 87 |
(temp / "backend").mkdir()
|
| 88 |
(temp / "tests").mkdir()
|
| 89 |
shutil.copyfile(ROOT / "backend/__init__.py", temp / "backend/__init__.py")
|
| 90 |
+
shutil.copyfile(source, temp / "backend" / f"{module}.py")
|
| 91 |
+
for dependency in dependencies:
|
| 92 |
+
shutil.copyfile(ROOT / "backend" / dependency, temp / "backend" / dependency)
|
| 93 |
+
shutil.copyfile(test, temp / "tests" / test_name)
|
| 94 |
(temp / "tests/__init__.py").write_text("")
|
| 95 |
+
selections = ([f"tests/{test_name}::SearchWordsContractTests::{name}" for name in selected]
|
| 96 |
+
if selected else [f"tests/{test_name}"])
|
| 97 |
(temp / "pyproject.toml").write_text(
|
| 98 |
+
'[tool.mutmut]\nsource_paths = ["backend/"]\n'
|
| 99 |
+
+ f'only_mutate = ["backend/{module}.py"]\n'
|
| 100 |
+ 'pytest_add_cli_args_test_selection = ' + json.dumps(selections) + '\n'
|
| 101 |
+ 'use_git_change_detection = false\nuse_setproctitle = false\n')
|
| 102 |
env = os.environ.copy()
|
|
|
|
| 105 |
command = [sys.executable, "-B", "-m", "mutmut", *args]
|
| 106 |
subprocess.run(command, cwd=temp, env=env, check=True, timeout=600) # noqa: S603
|
| 107 |
stats = json.loads((temp / "mutants/mutmut-cicd-stats.json").read_text())
|
| 108 |
+
meta = json.loads((temp / "mutants/backend" / f"{module}.py.meta").read_text())
|
| 109 |
+
generated = (temp / "mutants/backend" / f"{module}.py").read_text()
|
| 110 |
functions = {node.name: node for node in ast.parse(generated).body if isinstance(node, ast.FunctionDef)}
|
| 111 |
+
generated_keys = {f"backend.{module}.{name}" for name in functions if re.search(r"__mutmut_\d+$", name)}
|
| 112 |
hashes = {}
|
| 113 |
for key, code in meta["exit_code_by_key"].items():
|
| 114 |
if code == 0:
|
|
|
|
| 117 |
raise RuntimeError(f"missing generated source for {key}")
|
| 118 |
hashes[key] = hashlib.sha256(segment.encode()).hexdigest()
|
| 119 |
errors = mutation_errors(stats, meta["exit_code_by_key"], hashes, review["equivalent"])
|
| 120 |
+
if generated_keys != set(meta["exit_code_by_key"]):
|
| 121 |
+
errors.append("generated mutant inventory does not match recorded outcomes")
|
| 122 |
+
print(json.dumps({"tool": review["tool"], "source": review["source"], "source_sha256": source_hash,
|
| 123 |
+
"test": test_name, "test_sha256": hashlib.sha256(test.read_bytes()).hexdigest(), **stats,
|
| 124 |
+
"reviewed_equivalent_survivors": len(set(review["equivalent"]) & set(hashes))},
|
| 125 |
+
sort_keys=True))
|
| 126 |
if errors:
|
| 127 |
print("\n".join(errors), file=sys.stderr)
|
| 128 |
return 1
|
tests/test_data_formats_contract.py
CHANGED
|
@@ -4,6 +4,19 @@ import unittest
|
|
| 4 |
from backend import data_formats
|
| 5 |
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
class CompactDataFormatsTests(unittest.TestCase):
|
| 8 |
def test_corpus_ignores_non_mapping_and_invalid_rows(self):
|
| 9 |
for payload in (None, [], "bad", 42):
|
|
@@ -22,6 +35,15 @@ class CompactDataFormatsTests(unittest.TestCase):
|
|
| 22 |
{"Repo": "", "File": "boundary", "Extension": "pdf", "Folder": [], "Size": 1, "HasTxt": True},
|
| 23 |
])
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def test_tree_paths_directories_and_toggles(self):
|
| 26 |
tree = {"n": "root", "c": 3, "df": True, "ch": [
|
| 27 |
{"n": "docs", "c": 2, "df": True, "ch": [{"n": "nested", "c": 1}]},
|
|
@@ -42,6 +64,13 @@ class CompactDataFormatsTests(unittest.TestCase):
|
|
| 42 |
self.assertEqual((only_child["path"], only_child["hasChildren"], only_child["showSelfToggle"]),
|
| 43 |
("branch", True, False))
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
def test_browser_entry_retains_paths_names_extensions_sizes_and_flags(self):
|
| 46 |
source = {"d": [{"n": "part", "c": 3}], "f": [
|
| 47 |
{"n": "poster.jpg", "e": "jpg", "s": 0, "t": True},
|
|
|
|
| 4 |
from backend import data_formats
|
| 5 |
|
| 6 |
|
| 7 |
+
class FallbackDict(dict):
|
| 8 |
+
"""Mapping with legacy defaults only when no explicit fallback is supplied."""
|
| 9 |
+
|
| 10 |
+
def __init__(self, values, fallback):
|
| 11 |
+
super().__init__(values)
|
| 12 |
+
self.fallback = fallback
|
| 13 |
+
|
| 14 |
+
def get(self, key, default=None):
|
| 15 |
+
if key not in self and default is None:
|
| 16 |
+
return self.fallback.get(key)
|
| 17 |
+
return super().get(key, default)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
class CompactDataFormatsTests(unittest.TestCase):
|
| 21 |
def test_corpus_ignores_non_mapping_and_invalid_rows(self):
|
| 22 |
for payload in (None, [], "bad", 42):
|
|
|
|
| 35 |
{"Repo": "", "File": "boundary", "Extension": "pdf", "Folder": [], "Size": 1, "HasTxt": True},
|
| 36 |
])
|
| 37 |
|
| 38 |
+
def test_corpus_explicit_defaults_do_not_activate_mapping_fallbacks(self):
|
| 39 |
+
row = [0, "book", "pdf", 0, 1, False]
|
| 40 |
+
repo_missing = FallbackDict({"fd": [[]], "rc": [row]}, {"rp": ["legacy"]})
|
| 41 |
+
folder_missing = FallbackDict({"rp": ["A"], "rc": [row]}, {"fd": [["legacy"]]})
|
| 42 |
+
records_missing = FallbackDict({"rp": ["A"], "fd": [[]]}, {"rc": [row]})
|
| 43 |
+
self.assertEqual(data_formats.decode_search_payload(repo_missing)[0]["Repo"], "")
|
| 44 |
+
self.assertEqual(data_formats.decode_search_payload(folder_missing)[0]["Folder"], [])
|
| 45 |
+
self.assertEqual(data_formats.decode_search_payload(records_missing), [])
|
| 46 |
+
|
| 47 |
def test_tree_paths_directories_and_toggles(self):
|
| 48 |
tree = {"n": "root", "c": 3, "df": True, "ch": [
|
| 49 |
{"n": "docs", "c": 2, "df": True, "ch": [{"n": "nested", "c": 1}]},
|
|
|
|
| 64 |
self.assertEqual((only_child["path"], only_child["hasChildren"], only_child["showSelfToggle"]),
|
| 65 |
("branch", True, False))
|
| 66 |
|
| 67 |
+
def test_tree_missing_direct_files_uses_explicit_false_default(self):
|
| 68 |
+
node = FallbackDict({"n": "branch", "ch": [{"n": "leaf"}]}, {"df": True})
|
| 69 |
+
decoded = data_formats.decode_tree_node(node)
|
| 70 |
+
self.assertTrue(decoded["hasChildren"])
|
| 71 |
+
self.assertFalse(decoded["hasDirectFiles"])
|
| 72 |
+
self.assertFalse(decoded["showSelfToggle"])
|
| 73 |
+
|
| 74 |
def test_browser_entry_retains_paths_names_extensions_sizes_and_flags(self):
|
| 75 |
source = {"d": [{"n": "part", "c": 3}], "f": [
|
| 76 |
{"n": "poster.jpg", "e": "jpg", "s": 0, "t": True},
|
tests/test_quality_inventory.py
CHANGED
|
@@ -5,7 +5,7 @@ import tempfile
|
|
| 5 |
import unittest
|
| 6 |
|
| 7 |
from scripts.check_backend_coverage import coverage_errors
|
| 8 |
-
from scripts.check_search_words_mutation import mutation_errors
|
| 9 |
from scripts.check_strict_inventory import inventory_errors
|
| 10 |
|
| 11 |
|
|
@@ -134,18 +134,34 @@ class QualityInventoryTests(unittest.TestCase):
|
|
| 134 |
self.assertIn("new or changed backend branches lack tests: backend/old.py", errors)
|
| 135 |
|
| 136 |
def test_mutation_survivors_need_exact_review_and_no_other_outcomes(self):
|
| 137 |
-
stats = {"total": 2, "killed": 1, "survived": 1}
|
| 138 |
outcomes = {"killed": 1, "survivor": 0}
|
| 139 |
reviewed = {"survivor": {"sha256": "abc", "rationale": "equivalent"}}
|
| 140 |
self.assertEqual(mutation_errors(stats, outcomes, {"survivor": "abc"}, reviewed), [])
|
| 141 |
self.assertIn("unreviewed surviving mutation: survivor",
|
| 142 |
mutation_errors(stats, outcomes, {"survivor": "changed"}, reviewed))
|
|
|
|
|
|
|
| 143 |
self.assertIn("mutation results contain timeout: 1",
|
| 144 |
mutation_errors({**stats, "timeout": 1}, outcomes, {"survivor": "abc"}, reviewed))
|
| 145 |
self.assertIn("stale equivalent-mutation review: survivor",
|
| 146 |
-
mutation_errors({
|
| 147 |
{"killed": 1, "survivor": 1}, {}, reviewed))
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
if __name__ == "__main__":
|
| 151 |
unittest.main()
|
|
|
|
| 5 |
import unittest
|
| 6 |
|
| 7 |
from scripts.check_backend_coverage import coverage_errors
|
| 8 |
+
from scripts.check_search_words_mutation import EMPTY_STATUSES, mutation_errors
|
| 9 |
from scripts.check_strict_inventory import inventory_errors
|
| 10 |
|
| 11 |
|
|
|
|
| 134 |
self.assertIn("new or changed backend branches lack tests: backend/old.py", errors)
|
| 135 |
|
| 136 |
def test_mutation_survivors_need_exact_review_and_no_other_outcomes(self):
|
| 137 |
+
stats = {"total": 2, "killed": 1, "survived": 1, **dict.fromkeys(EMPTY_STATUSES, 0)}
|
| 138 |
outcomes = {"killed": 1, "survivor": 0}
|
| 139 |
reviewed = {"survivor": {"sha256": "abc", "rationale": "equivalent"}}
|
| 140 |
self.assertEqual(mutation_errors(stats, outcomes, {"survivor": "abc"}, reviewed), [])
|
| 141 |
self.assertIn("unreviewed surviving mutation: survivor",
|
| 142 |
mutation_errors(stats, outcomes, {"survivor": "changed"}, reviewed))
|
| 143 |
+
self.assertIn("unreviewed surviving mutation: survivor",
|
| 144 |
+
mutation_errors(stats, outcomes, {}, {"survivor": {"rationale": "not enough"}}))
|
| 145 |
self.assertIn("mutation results contain timeout: 1",
|
| 146 |
mutation_errors({**stats, "timeout": 1}, outcomes, {"survivor": "abc"}, reviewed))
|
| 147 |
self.assertIn("stale equivalent-mutation review: survivor",
|
| 148 |
+
mutation_errors({**stats, "killed": 2, "survived": 0},
|
| 149 |
{"killed": 1, "survivor": 1}, {}, reviewed))
|
| 150 |
|
| 151 |
+
def test_mutation_inventory_rejects_empty_missing_and_inconsistent_results(self):
|
| 152 |
+
self.assertIn("mutation statistics are missing or invalid", mutation_errors({}, {}, {}, {}))
|
| 153 |
+
zero = {"total": 0, "killed": 0, "survived": 0, **dict.fromkeys(EMPTY_STATUSES, 0)}
|
| 154 |
+
self.assertIn("mutation results are incomplete or contain unexpected outcomes",
|
| 155 |
+
mutation_errors(zero, {}, {}, {}))
|
| 156 |
+
inconsistent = {**zero, "total": 2, "killed": 2}
|
| 157 |
+
self.assertIn("mutation results are incomplete or contain unexpected outcomes",
|
| 158 |
+
mutation_errors(inconsistent, {"a": 1, "b": 0}, {"b": "hash"},
|
| 159 |
+
{"b": {"sha256": "hash", "rationale": "review"}}))
|
| 160 |
+
missing_status = {**zero, "total": 1, "killed": 1}
|
| 161 |
+
del missing_status["no_tests"]
|
| 162 |
+
self.assertIn("mutation statistics are missing or invalid",
|
| 163 |
+
mutation_errors(missing_status, {"a": 1}, {}, {}))
|
| 164 |
+
|
| 165 |
|
| 166 |
if __name__ == "__main__":
|
| 167 |
unittest.main()
|
tests/test_search_words_contract.py
CHANGED
|
@@ -201,5 +201,55 @@ class SearchWordsContractTests(unittest.TestCase):
|
|
| 201 |
self.assertEqual(len(masks), 1)
|
| 202 |
self.assertEqual(masks, {"D": 16})
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
if __name__ == "__main__":
|
| 205 |
unittest.main()
|
|
|
|
| 201 |
self.assertEqual(len(masks), 1)
|
| 202 |
self.assertEqual(masks, {"D": 16})
|
| 203 |
|
| 204 |
+
def test_wildcard_cache_reuses_literal_scans_across_matches(self):
|
| 205 |
+
from backend import search_matching
|
| 206 |
+
calls = []
|
| 207 |
+
original_compile = search_matching.re.compile
|
| 208 |
+
|
| 209 |
+
class CountingPattern:
|
| 210 |
+
def __init__(self, pattern, flags):
|
| 211 |
+
self.pattern = original_compile(pattern, flags)
|
| 212 |
+
|
| 213 |
+
def search(self, text):
|
| 214 |
+
return self.pattern.search(text)
|
| 215 |
+
|
| 216 |
+
def fullmatch(self, char):
|
| 217 |
+
calls.append((self.pattern.pattern, char))
|
| 218 |
+
return self.pattern.fullmatch(char)
|
| 219 |
+
|
| 220 |
+
with patch.object(search_matching.re, "compile", side_effect=CountingPattern):
|
| 221 |
+
matcher = search_matching.compile_exact_matcher("a*z")
|
| 222 |
+
self.assertTrue(matcher("a" + "b" * 100 + "z"))
|
| 223 |
+
self.assertTrue(matcher("a" + "b" * 50 + "z"))
|
| 224 |
+
|
| 225 |
+
# Each of the two literals is scanned once per distinct character,
|
| 226 |
+
# not once for every occurrence or every subsequent match.
|
| 227 |
+
self.assertCountEqual(calls, [(literal, char) for literal in ("a", "z") for char in "abz"])
|
| 228 |
+
|
| 229 |
+
def test_fuzzy_match_stops_at_the_two_edit_work_bound(self):
|
| 230 |
+
from backend.search_matching import is_fuzzy_match
|
| 231 |
+
|
| 232 |
+
class TrackedText(str):
|
| 233 |
+
def __new__(cls, value):
|
| 234 |
+
result = super().__new__(cls, value)
|
| 235 |
+
result.visits = 0
|
| 236 |
+
return result
|
| 237 |
+
|
| 238 |
+
def __iter__(self):
|
| 239 |
+
for char in super().__iter__():
|
| 240 |
+
self.visits += 1
|
| 241 |
+
yield char
|
| 242 |
+
|
| 243 |
+
# The character-count precheck can reject after five mismatches.
|
| 244 |
+
different = TrackedText("b" * 100)
|
| 245 |
+
self.assertFalse(is_fuzzy_match("a" * 100, different))
|
| 246 |
+
self.assertEqual(different.visits, 5)
|
| 247 |
+
|
| 248 |
+
# Equal character multisets pass the precheck; the distance calculation
|
| 249 |
+
# must still terminate early once more than two edits are unavoidable.
|
| 250 |
+
reordered = TrackedText("ddccbbaa")
|
| 251 |
+
self.assertFalse(is_fuzzy_match("aabbccdd", reordered))
|
| 252 |
+
self.assertEqual(reordered.visits, 32)
|
| 253 |
+
|
| 254 |
if __name__ == "__main__":
|
| 255 |
unittest.main()
|