vomebook commited on
Commit ·
a7939d1
1
Parent(s): e93f91e
Organize search domain and strengthen type contracts
Browse files- backend/search/domain/projection.py +37 -0
- backend/search_projection.py +7 -37
- pyrightconfig.strict.json +1 -0
- quality/mutation-reviews/mutation-equivalent-search-projection.json +2 -2
- scripts/check_search_words_mutation.py +13 -7
- static/search/requests/application/response-store.js +1 -1
- tests/gates/test_mutation_gate_main.py +18 -7
- tests/gates/test_quality_inventory.py +2 -2
- tests/search/backend/test_search_projection_contract.py +7 -0
- tests/search/backend/test_search_projection_mutation_contract.py +1 -1
- typings/search-response-store.d.ts +2 -2
backend/search/domain/projection.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Project search records using caller-owned link and path builders."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
from collections.abc import Callable, Iterable, Mapping
|
| 5 |
+
from typing import cast
|
| 6 |
+
|
| 7 |
+
SearchRecord = dict[str, object]
|
| 8 |
+
RecordUrlBuilder = Callable[[SearchRecord], str]
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def public_record(record: SearchRecord, build_link: RecordUrlBuilder, build_path: RecordUrlBuilder) -> SearchRecord:
|
| 12 |
+
item = {
|
| 13 |
+
key: value
|
| 14 |
+
for key, value in cast(Mapping[object, object], record).items()
|
| 15 |
+
if isinstance(key, str) and not key.startswith("_")
|
| 16 |
+
}
|
| 17 |
+
item.setdefault("Repo", "")
|
| 18 |
+
item.setdefault("File", "")
|
| 19 |
+
item.setdefault("Extension", "")
|
| 20 |
+
item.setdefault("Folder", [])
|
| 21 |
+
item.setdefault("Size", "")
|
| 22 |
+
item.setdefault("HasTxt", False)
|
| 23 |
+
item["Link"] = record.get("Link") or build_link(record)
|
| 24 |
+
item["Path"] = record.get("Path") or build_path(record)
|
| 25 |
+
return item
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def trim_results(raw: Iterable[SearchRecord], project: Callable[[SearchRecord], SearchRecord]) -> list[SearchRecord]:
|
| 29 |
+
# Fixed field reads avoid a per-record key loop. Keep their order, defaults
|
| 30 |
+
# and per-record projection boundary: callers may supply custom mappings.
|
| 31 |
+
return [
|
| 32 |
+
{"Repo": public.get("Repo", ""), "File": public.get("File", ""),
|
| 33 |
+
"Extension": public.get("Extension", ""), "Link": public.get("Link", ""),
|
| 34 |
+
"Path": public.get("Path", ""), "Folder": public.get("Folder", []),
|
| 35 |
+
"Size": public.get("Size", ""), "HasTxt": public.get("HasTxt", "")}
|
| 36 |
+
for public in (project(record) for record in raw)
|
| 37 |
+
]
|
backend/search_projection.py
CHANGED
|
@@ -1,37 +1,7 @@
|
|
| 1 |
-
"""
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
RecordUrlBuilder = Callable[[SearchRecord], str]
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def public_record(record: SearchRecord, build_link: RecordUrlBuilder, build_path: RecordUrlBuilder) -> SearchRecord:
|
| 12 |
-
item = {
|
| 13 |
-
key: value
|
| 14 |
-
for key, value in cast(Mapping[object, object], record).items()
|
| 15 |
-
if isinstance(key, str) and not key.startswith("_")
|
| 16 |
-
}
|
| 17 |
-
item.setdefault("Repo", "")
|
| 18 |
-
item.setdefault("File", "")
|
| 19 |
-
item.setdefault("Extension", "")
|
| 20 |
-
item.setdefault("Folder", [])
|
| 21 |
-
item.setdefault("Size", "")
|
| 22 |
-
item.setdefault("HasTxt", False)
|
| 23 |
-
item["Link"] = record.get("Link") or build_link(record)
|
| 24 |
-
item["Path"] = record.get("Path") or build_path(record)
|
| 25 |
-
return item
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def trim_results(raw: Iterable[SearchRecord], project: Callable[[SearchRecord], SearchRecord]) -> list[SearchRecord]:
|
| 29 |
-
# Fixed field reads avoid a per-record key loop. Keep their order, defaults
|
| 30 |
-
# and per-record projection boundary: callers may supply custom mappings.
|
| 31 |
-
return [
|
| 32 |
-
{"Repo": public.get("Repo", ""), "File": public.get("File", ""),
|
| 33 |
-
"Extension": public.get("Extension", ""), "Link": public.get("Link", ""),
|
| 34 |
-
"Path": public.get("Path", ""), "Folder": public.get("Folder", []),
|
| 35 |
-
"Size": public.get("Size", ""), "HasTxt": public.get("HasTxt", "")}
|
| 36 |
-
for public in (project(record) for record in raw)
|
| 37 |
-
]
|
|
|
|
| 1 |
+
"""Compatibility exports for search projection."""
|
| 2 |
+
from backend.search.domain.projection import (
|
| 3 |
+
RecordUrlBuilder as RecordUrlBuilder,
|
| 4 |
+
SearchRecord as SearchRecord,
|
| 5 |
+
public_record as public_record,
|
| 6 |
+
trim_results as trim_results,
|
| 7 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pyrightconfig.strict.json
CHANGED
|
@@ -28,6 +28,7 @@
|
|
| 28 |
"backend/search/application/cached.py",
|
| 29 |
"backend/search/domain/__init__.py",
|
| 30 |
"backend/search/domain/ordering.py",
|
|
|
|
| 31 |
"backend/search/http/__init__.py",
|
| 32 |
"backend/search/http/schemas.py",
|
| 33 |
"backend/search/http/responses.py",
|
|
|
|
| 28 |
"backend/search/application/cached.py",
|
| 29 |
"backend/search/domain/__init__.py",
|
| 30 |
"backend/search/domain/ordering.py",
|
| 31 |
+
"backend/search/domain/projection.py",
|
| 32 |
"backend/search/http/__init__.py",
|
| 33 |
"backend/search/http/schemas.py",
|
| 34 |
"backend/search/http/responses.py",
|
quality/mutation-reviews/mutation-equivalent-search-projection.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
{
|
| 2 |
"tool": "mutmut 3.8.1",
|
| 3 |
-
"source": "backend/
|
| 4 |
"source_sha256": "4113f825a0da936fdee125e304ffd8e611c50671947b6f517f3fc45e454ba23a",
|
| 5 |
"scope": "Review covers observable results, exceptions and callback behavior for ordinary built-in mappings and records. It excludes monkeypatching typing.cast, tracing and reflection. This is an equivalent survivor within this scope, not a killed mutation.",
|
| 6 |
"equivalent": {
|
| 7 |
-
"backend.
|
| 8 |
"sha256": "0a3fec0b966f9d0a3c2251e60c1387b3bacd23d8485f939fd90ebd59f28f423b",
|
| 9 |
"rationale": "Only the type argument to typing.cast changes; with the standard cast implementation it returns the original record unchanged. Evaluating the type expression is outside the stated scope."
|
| 10 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"tool": "mutmut 3.8.1",
|
| 3 |
+
"source": "backend/search/domain/projection.py",
|
| 4 |
"source_sha256": "4113f825a0da936fdee125e304ffd8e611c50671947b6f517f3fc45e454ba23a",
|
| 5 |
"scope": "Review covers observable results, exceptions and callback behavior for ordinary built-in mappings and records. It excludes monkeypatching typing.cast, tracing and reflection. This is an equivalent survivor within this scope, not a killed mutation.",
|
| 6 |
"equivalent": {
|
| 7 |
+
"backend.search.domain.projection.x_public_record__mutmut_2": {
|
| 8 |
"sha256": "0a3fec0b966f9d0a3c2251e60c1387b3bacd23d8485f939fd90ebd59f28f423b",
|
| 9 |
"rationale": "Only the type argument to typing.cast changes; with the standard cast implementation it returns the original record unchanged. Evaluating the type expression is outside the stated scope."
|
| 10 |
}
|
scripts/check_search_words_mutation.py
CHANGED
|
@@ -161,13 +161,14 @@ def main() -> int:
|
|
| 161 |
parser.add_argument("--module", choices=tuple(SPECS), default="search_words")
|
| 162 |
module = parser.parse_args().module
|
| 163 |
test_name, selected, dependencies = SPECS[module]
|
| 164 |
-
|
|
|
|
| 165 |
test = ROOT / "tests" / test_name
|
| 166 |
equivalent = ROOT / "quality/mutation-reviews" / f"mutation-equivalent-{module.replace('_', '-')}.json"
|
| 167 |
review = json.loads(equivalent.read_text())
|
| 168 |
source_hash = hashlib.sha256(source.read_bytes()).hexdigest()
|
| 169 |
if (version("mutmut") != TOOL_VERSION or review.get("tool") != f"mutmut {TOOL_VERSION}"
|
| 170 |
-
or review.get("source") != f"backend/{
|
| 171 |
print("Mutation equivalent review must match the exact source and tool version", file=sys.stderr)
|
| 172 |
return 1
|
| 173 |
with tempfile.TemporaryDirectory(prefix=f"reader-{module}-mutation-") as directory:
|
|
@@ -175,7 +176,12 @@ def main() -> int:
|
|
| 175 |
(temp / "backend").mkdir()
|
| 176 |
(temp / "tests").mkdir()
|
| 177 |
shutil.copyfile(ROOT / "backend/__init__.py", temp / "backend/__init__.py")
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
for dependency in dependencies:
|
| 180 |
shutil.copyfile(ROOT / "backend" / dependency, temp / "backend" / dependency)
|
| 181 |
target_test = temp / "tests" / test_name
|
|
@@ -195,7 +201,7 @@ def main() -> int:
|
|
| 195 |
if module == "search_indexes" else f"tests/{test_name}"])
|
| 196 |
(temp / "pyproject.toml").write_text(
|
| 197 |
'[tool.mutmut]\nsource_paths = ["backend/"]\n'
|
| 198 |
-
+ f'only_mutate = ["backend/{
|
| 199 |
+ ('also_copy = ["static/"]\n' if module == "record_metadata" else '')
|
| 200 |
+ 'pytest_add_cli_args_test_selection = ' + json.dumps(selections) + '\n'
|
| 201 |
+ 'use_git_change_detection = false\nuse_setproctitle = false\n')
|
|
@@ -205,9 +211,9 @@ def main() -> int:
|
|
| 205 |
command = [sys.executable, "-B", "-m", "mutmut", *args]
|
| 206 |
subprocess.run(command, cwd=temp, env=env, check=True, timeout=600) # noqa: S603
|
| 207 |
stats = json.loads((temp / "mutants/mutmut-cicd-stats.json").read_text())
|
| 208 |
-
meta = json.loads((temp / "mutants/backend" / f"{
|
| 209 |
-
generated = (temp / "mutants/backend" / f"{
|
| 210 |
-
functions = generated_mutations(
|
| 211 |
generated_keys = set(functions)
|
| 212 |
hashes = {}
|
| 213 |
for key, code in meta["exit_code_by_key"].items():
|
|
|
|
| 161 |
parser.add_argument("--module", choices=tuple(SPECS), default="search_words")
|
| 162 |
module = parser.parse_args().module
|
| 163 |
test_name, selected, dependencies = SPECS[module]
|
| 164 |
+
module_path = "search/domain/projection" if module == "search_projection" else module
|
| 165 |
+
source = ROOT / "backend" / f"{module_path}.py"
|
| 166 |
test = ROOT / "tests" / test_name
|
| 167 |
equivalent = ROOT / "quality/mutation-reviews" / f"mutation-equivalent-{module.replace('_', '-')}.json"
|
| 168 |
review = json.loads(equivalent.read_text())
|
| 169 |
source_hash = hashlib.sha256(source.read_bytes()).hexdigest()
|
| 170 |
if (version("mutmut") != TOOL_VERSION or review.get("tool") != f"mutmut {TOOL_VERSION}"
|
| 171 |
+
or review.get("source") != f"backend/{module_path}.py" or review.get("source_sha256") != source_hash):
|
| 172 |
print("Mutation equivalent review must match the exact source and tool version", file=sys.stderr)
|
| 173 |
return 1
|
| 174 |
with tempfile.TemporaryDirectory(prefix=f"reader-{module}-mutation-") as directory:
|
|
|
|
| 176 |
(temp / "backend").mkdir()
|
| 177 |
(temp / "tests").mkdir()
|
| 178 |
shutil.copyfile(ROOT / "backend/__init__.py", temp / "backend/__init__.py")
|
| 179 |
+
target_source = temp / "backend" / f"{module_path}.py"
|
| 180 |
+
target_source.parent.mkdir(parents=True, exist_ok=True)
|
| 181 |
+
if module == "search_projection":
|
| 182 |
+
for package in ("search", "search/domain"):
|
| 183 |
+
shutil.copyfile(ROOT / "backend" / package / "__init__.py", temp / "backend" / package / "__init__.py")
|
| 184 |
+
shutil.copyfile(source, target_source)
|
| 185 |
for dependency in dependencies:
|
| 186 |
shutil.copyfile(ROOT / "backend" / dependency, temp / "backend" / dependency)
|
| 187 |
target_test = temp / "tests" / test_name
|
|
|
|
| 201 |
if module == "search_indexes" else f"tests/{test_name}"])
|
| 202 |
(temp / "pyproject.toml").write_text(
|
| 203 |
'[tool.mutmut]\nsource_paths = ["backend/"]\n'
|
| 204 |
+
+ f'only_mutate = ["backend/{module_path}.py"]\n'
|
| 205 |
+ ('also_copy = ["static/"]\n' if module == "record_metadata" else '')
|
| 206 |
+ 'pytest_add_cli_args_test_selection = ' + json.dumps(selections) + '\n'
|
| 207 |
+ 'use_git_change_detection = false\nuse_setproctitle = false\n')
|
|
|
|
| 211 |
command = [sys.executable, "-B", "-m", "mutmut", *args]
|
| 212 |
subprocess.run(command, cwd=temp, env=env, check=True, timeout=600) # noqa: S603
|
| 213 |
stats = json.loads((temp / "mutants/mutmut-cicd-stats.json").read_text())
|
| 214 |
+
meta = json.loads((temp / "mutants/backend" / f"{module_path}.py.meta").read_text())
|
| 215 |
+
generated = (temp / "mutants/backend" / f"{module_path}.py").read_text()
|
| 216 |
+
functions = generated_mutations(module_path.replace("/", "."), generated)
|
| 217 |
generated_keys = set(functions)
|
| 218 |
hashes = {}
|
| 219 |
for key, code in meta["exit_code_by_key"].items():
|
static/search/requests/application/response-store.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
| 12 |
/** @type {ReturnType<typeof setTimeout> | null} */
|
| 13 |
let writeTimer = null;
|
| 14 |
|
| 15 |
-
/** @template T @param {T} data @returns {T} */
|
| 16 |
function cloneSearchData(data) {
|
| 17 |
const page = /** @type {T & {results?: unknown[], total?: unknown, page?: unknown, page_size?: unknown}} */ (data);
|
| 18 |
if (!page || !Array.isArray(page.results)) return data;
|
|
|
|
| 12 |
/** @type {ReturnType<typeof setTimeout> | null} */
|
| 13 |
let writeTimer = null;
|
| 14 |
|
| 15 |
+
/** @template {VoiceOfMLSearchWindowPageData} T @param {T} data @returns {T} */
|
| 16 |
function cloneSearchData(data) {
|
| 17 |
const page = /** @type {T & {results?: unknown[], total?: unknown, page?: unknown, page_size?: unknown}} */ (data);
|
| 18 |
if (!page || !Array.isArray(page.results)) return data;
|
tests/gates/test_mutation_gate_main.py
CHANGED
|
@@ -58,7 +58,11 @@ class MutationGateMainTests(unittest.TestCase):
|
|
| 58 |
self.assertEqual([path.relative_to(cwd) for path in (Path(cwd) / 'static').rglob('*')
|
| 59 |
if path.is_file()], [fixture])
|
| 60 |
self.assertEqual({path.name for path in Path(cwd).iterdir()}, expected_entries)
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
f'tests/{gate.SPECS[self.module][0]}'):
|
| 63 |
self.assertEqual((Path(cwd) / rel).read_bytes(), (self.root / rel).read_bytes())
|
| 64 |
self.assertEqual((Path(cwd) / 'tests/__init__.py').read_bytes(), b'')
|
|
@@ -69,20 +73,21 @@ class MutationGateMainTests(unittest.TestCase):
|
|
| 69 |
self.assertEqual((Path(cwd) / 'tests/support/reader-contract-vectors.json').read_bytes(),
|
| 70 |
(self.root / 'tests/support/reader-contract-vectors.json').read_bytes())
|
| 71 |
if command[-1] == 'export-cicd-stats':
|
|
|
|
| 72 |
folder = Path(cwd) / 'mutants/backend'
|
| 73 |
-
folder.mkdir(parents=True)
|
| 74 |
stats = {'total': self.count, 'killed': int(self.outcome == 1),
|
| 75 |
'survived': int(self.outcome == 0), **dict.fromkeys(gate.EMPTY_STATUSES, 0)}
|
| 76 |
if self.unknown_status:
|
| 77 |
stats[self.unknown_status] = 1
|
| 78 |
(folder.parent / 'mutmut-cicd-stats.json').write_text(json.dumps(stats))
|
| 79 |
-
meta = {'exit_code_by_key': {f'backend.{
|
| 80 |
if self.include_timings:
|
| 81 |
timings = {'durations_by_key': self.durations, 'estimated_durations_by_key': self.estimates}
|
| 82 |
meta.update({key: value for key, value in timings.items()
|
| 83 |
if self.timing_fields is None or key in self.timing_fields})
|
| 84 |
-
(folder / f'{
|
| 85 |
-
(folder / f'{
|
| 86 |
return None
|
| 87 |
|
| 88 |
if self.reviewed:
|
|
@@ -110,12 +115,18 @@ class MutationGateMainTests(unittest.TestCase):
|
|
| 110 |
self.args = ['--module', module]
|
| 111 |
test_name, _, dependencies = gate.SPECS[module]
|
| 112 |
source = b'def synthetic(value):\n return value\n'
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
target_test = self.root / 'tests' / test_name
|
| 115 |
target_test.parent.mkdir(parents=True, exist_ok=True)
|
| 116 |
target_test.write_text('def test_fixture(): pass\n')
|
| 117 |
(self.root / 'quality/mutation-reviews' / f'mutation-equivalent-{module.replace("_", "-")}.json').write_text(json.dumps({
|
| 118 |
-
'tool': 'mutmut 3.8.1', 'source': f'backend/{
|
| 119 |
'source_sha256': hashlib.sha256(source).hexdigest(), 'equivalent': {}}))
|
| 120 |
for dependency in dependencies:
|
| 121 |
(self.root / 'backend' / dependency).write_text(f'# synthetic dependency {dependency}\n')
|
|
|
|
| 58 |
self.assertEqual([path.relative_to(cwd) for path in (Path(cwd) / 'static').rglob('*')
|
| 59 |
if path.is_file()], [fixture])
|
| 60 |
self.assertEqual({path.name for path in Path(cwd).iterdir()}, expected_entries)
|
| 61 |
+
module_path = 'search/domain/projection' if self.module == 'search_projection' else self.module
|
| 62 |
+
if self.module == 'search_projection':
|
| 63 |
+
self.assertEqual(self.configurations[-1]['tool']['mutmut']['only_mutate'],
|
| 64 |
+
['backend/search/domain/projection.py'])
|
| 65 |
+
for rel in ('backend/__init__.py', f'backend/{module_path}.py',
|
| 66 |
f'tests/{gate.SPECS[self.module][0]}'):
|
| 67 |
self.assertEqual((Path(cwd) / rel).read_bytes(), (self.root / rel).read_bytes())
|
| 68 |
self.assertEqual((Path(cwd) / 'tests/__init__.py').read_bytes(), b'')
|
|
|
|
| 73 |
self.assertEqual((Path(cwd) / 'tests/support/reader-contract-vectors.json').read_bytes(),
|
| 74 |
(self.root / 'tests/support/reader-contract-vectors.json').read_bytes())
|
| 75 |
if command[-1] == 'export-cicd-stats':
|
| 76 |
+
module_path = 'search/domain/projection' if self.module == 'search_projection' else self.module
|
| 77 |
folder = Path(cwd) / 'mutants/backend'
|
| 78 |
+
(folder / module_path).parent.mkdir(parents=True)
|
| 79 |
stats = {'total': self.count, 'killed': int(self.outcome == 1),
|
| 80 |
'survived': int(self.outcome == 0), **dict.fromkeys(gate.EMPTY_STATUSES, 0)}
|
| 81 |
if self.unknown_status:
|
| 82 |
stats[self.unknown_status] = 1
|
| 83 |
(folder.parent / 'mutmut-cicd-stats.json').write_text(json.dumps(stats))
|
| 84 |
+
meta = {'exit_code_by_key': {f'backend.{module_path.replace("/", ".")}.x_example__mutmut_1': self.outcome}}
|
| 85 |
if self.include_timings:
|
| 86 |
timings = {'durations_by_key': self.durations, 'estimated_durations_by_key': self.estimates}
|
| 87 |
meta.update({key: value for key, value in timings.items()
|
| 88 |
if self.timing_fields is None or key in self.timing_fields})
|
| 89 |
+
(folder / f'{module_path}.py.meta').write_text(json.dumps(meta))
|
| 90 |
+
(folder / f'{module_path}.py').write_text(self.generated)
|
| 91 |
return None
|
| 92 |
|
| 93 |
if self.reviewed:
|
|
|
|
| 115 |
self.args = ['--module', module]
|
| 116 |
test_name, _, dependencies = gate.SPECS[module]
|
| 117 |
source = b'def synthetic(value):\n return value\n'
|
| 118 |
+
module_path = 'search/domain/projection' if module == 'search_projection' else module
|
| 119 |
+
source_file = self.root / 'backend' / f'{module_path}.py'
|
| 120 |
+
source_file.parent.mkdir(parents=True, exist_ok=True)
|
| 121 |
+
source_file.write_bytes(source)
|
| 122 |
+
if module == 'search_projection':
|
| 123 |
+
for package in ('search', 'search/domain'):
|
| 124 |
+
(self.root / 'backend' / package / '__init__.py').write_text('')
|
| 125 |
target_test = self.root / 'tests' / test_name
|
| 126 |
target_test.parent.mkdir(parents=True, exist_ok=True)
|
| 127 |
target_test.write_text('def test_fixture(): pass\n')
|
| 128 |
(self.root / 'quality/mutation-reviews' / f'mutation-equivalent-{module.replace("_", "-")}.json').write_text(json.dumps({
|
| 129 |
+
'tool': 'mutmut 3.8.1', 'source': f'backend/{module_path}.py',
|
| 130 |
'source_sha256': hashlib.sha256(source).hexdigest(), 'equivalent': {}}))
|
| 131 |
for dependency in dependencies:
|
| 132 |
(self.root / 'backend' / dependency).write_text(f'# synthetic dependency {dependency}\n')
|
tests/gates/test_quality_inventory.py
CHANGED
|
@@ -1520,12 +1520,12 @@ class Example:
|
|
| 1520 |
root = Path(__file__).resolve().parents[2]
|
| 1521 |
review = json.loads((root / "quality/mutation-reviews/mutation-equivalent-search-projection.json").read_text())
|
| 1522 |
self.assertEqual(review["tool"], "mutmut 3.8.1")
|
| 1523 |
-
self.assertEqual(review["source"], "backend/
|
| 1524 |
self.assertEqual(review["source_sha256"], hashlib.sha256((root / review["source"]).read_bytes()).hexdigest())
|
| 1525 |
self.assertTrue(review["scope"])
|
| 1526 |
for name, entry in review["equivalent"].items():
|
| 1527 |
with self.subTest(mutant=name):
|
| 1528 |
-
self.assertTrue(name.startswith("backend.
|
| 1529 |
self.assertRegex(entry["sha256"], r"^[0-9a-f]{64}$")
|
| 1530 |
self.assertTrue(entry["rationale"])
|
| 1531 |
|
|
|
|
| 1520 |
root = Path(__file__).resolve().parents[2]
|
| 1521 |
review = json.loads((root / "quality/mutation-reviews/mutation-equivalent-search-projection.json").read_text())
|
| 1522 |
self.assertEqual(review["tool"], "mutmut 3.8.1")
|
| 1523 |
+
self.assertEqual(review["source"], "backend/search/domain/projection.py")
|
| 1524 |
self.assertEqual(review["source_sha256"], hashlib.sha256((root / review["source"]).read_bytes()).hexdigest())
|
| 1525 |
self.assertTrue(review["scope"])
|
| 1526 |
for name, entry in review["equivalent"].items():
|
| 1527 |
with self.subTest(mutant=name):
|
| 1528 |
+
self.assertTrue(name.startswith("backend.search.domain.projection."))
|
| 1529 |
self.assertRegex(entry["sha256"], r"^[0-9a-f]{64}$")
|
| 1530 |
self.assertTrue(entry["rationale"])
|
| 1531 |
|
tests/search/backend/test_search_projection_contract.py
CHANGED
|
@@ -3,9 +3,16 @@ from unittest import TestCase
|
|
| 3 |
from unittest.mock import patch
|
| 4 |
|
| 5 |
from backend import app, search_projection
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
class SearchProjectionContractTests(TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def test_public_projection_filters_private_keys_but_preserves_explicit_values(self):
|
| 10 |
folder = ["chapter"]
|
| 11 |
original = {"Repo": "A", "File": "name", "Folder": folder, "Size": None,
|
|
|
|
| 3 |
from unittest.mock import patch
|
| 4 |
|
| 5 |
from backend import app, search_projection
|
| 6 |
+
from backend.search.domain import projection
|
| 7 |
|
| 8 |
|
| 9 |
class SearchProjectionContractTests(TestCase):
|
| 10 |
+
def test_compatibility_exports_are_canonical(self):
|
| 11 |
+
self.assertIs(search_projection.public_record, projection.public_record)
|
| 12 |
+
self.assertIs(search_projection.trim_results, projection.trim_results)
|
| 13 |
+
self.assertIs(search_projection.SearchRecord, projection.SearchRecord)
|
| 14 |
+
self.assertIs(search_projection.RecordUrlBuilder, projection.RecordUrlBuilder)
|
| 15 |
+
|
| 16 |
def test_public_projection_filters_private_keys_but_preserves_explicit_values(self):
|
| 17 |
folder = ["chapter"]
|
| 18 |
original = {"Repo": "A", "File": "name", "Folder": folder, "Size": None,
|
tests/search/backend/test_search_projection_mutation_contract.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""Pure projection contracts for the complete isolated mutation inventory."""
|
| 2 |
import unittest
|
| 3 |
|
| 4 |
-
from backend import
|
| 5 |
|
| 6 |
|
| 7 |
class SearchProjectionMutationContractTests(unittest.TestCase):
|
|
|
|
| 1 |
"""Pure projection contracts for the complete isolated mutation inventory."""
|
| 2 |
import unittest
|
| 3 |
|
| 4 |
+
from backend.search.domain import projection
|
| 5 |
|
| 6 |
|
| 7 |
class SearchProjectionMutationContractTests(unittest.TestCase):
|
typings/search-response-store.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ interface SearchResponseStoreDependencies {
|
|
| 2 |
limit: number;
|
| 3 |
ttl: number;
|
| 4 |
getSearchViewKey(): string;
|
| 5 |
-
rememberSearchPageMetadata(data:
|
| 6 |
}
|
| 7 |
interface SearchResponseStore {
|
| 8 |
cache: BoundedResponseCache<{time: number; data: VoiceOfMLSearchWindowPageData}>;
|
| 9 |
pendingWrites: Map<string, {data: VoiceOfMLSearchWindowPageData; viewKey: string; acquiredAt: number}>;
|
| 10 |
identities: WeakMap<object, object>;
|
| 11 |
-
cloneSearchData<T>(data: T): T;
|
| 12 |
getCachedSearchResponse(key: string): VoiceOfMLSearchWindowPageData | null;
|
| 13 |
cancelPendingSearchCacheWrites(): void;
|
| 14 |
setCachedSearchResponse(key: string, data: VoiceOfMLSearchWindowPageData, defer?: boolean, acquiredAt?: number): void;
|
|
|
|
| 2 |
limit: number;
|
| 3 |
ttl: number;
|
| 4 |
getSearchViewKey(): string;
|
| 5 |
+
rememberSearchPageMetadata(data: VoiceOfMLSearchWindowPageData): void;
|
| 6 |
}
|
| 7 |
interface SearchResponseStore {
|
| 8 |
cache: BoundedResponseCache<{time: number; data: VoiceOfMLSearchWindowPageData}>;
|
| 9 |
pendingWrites: Map<string, {data: VoiceOfMLSearchWindowPageData; viewKey: string; acquiredAt: number}>;
|
| 10 |
identities: WeakMap<object, object>;
|
| 11 |
+
cloneSearchData<T extends VoiceOfMLSearchWindowPageData>(data: T): T;
|
| 12 |
getCachedSearchResponse(key: string): VoiceOfMLSearchWindowPageData | null;
|
| 13 |
cancelPendingSearchCacheWrites(): void;
|
| 14 |
setCachedSearchResponse(key: string, data: VoiceOfMLSearchWindowPageData, defer?: boolean, acquiredAt?: number): void;
|