yams/tests/benchmarks/test_retrieval_contract.py
Trevon e4b32e98bd
Some checks failed
Secret scan / gitleaks (push) Failing after 8s
Mirror source to Forgejo / mirror (push) Has been skipped
Release Candidate / Validate promotion and preview release (push) Has been cancelled
Tests / Static Analysis (push) Has been cancelled
Tests / Warm Conan & ccache (linux-arm64) (push) Has been cancelled
Tests / Warm Conan & ccache (macos-arm64) (push) Has been cancelled
Tests / Warm Conan & ccache (linux-x86_64) (push) Has been cancelled
Tests / Warm Conan & ccache (macos-x86_64) (push) Has been cancelled
Tests / Warm Conan & ccache (windows-x86_64) (push) Has been cancelled
Tests / warm (push) Has been cancelled
Tests / Tests (linux-arm64) (push) Has been cancelled
Tests / Tests (macos-arm64) (push) Has been cancelled
Tests / Tests (linux-x86_64-asan) (push) Has been cancelled
Tests / Tests (linux-x86_64-ubsan) (push) Has been cancelled
Tests / Tests (linux-x86_64) (push) Has been cancelled
Tests / Tests (windows-x86_64) (push) Has been cancelled
fix: fence enrichment completion and reconcile promotion prerequisites (#157)
* test(ci): stabilize main matrix (#112)

Signed-off-by: trvon <me@trevon.dev>

* ci(release): preview experimental promotion (#111)

Signed-off-by: trvon <me@trevon.dev>

* ci(release): reconcile draft promotion safely (#113)

* ci(release): reconcile draft promotion

Create promotion visibility independently of release readiness.
Leave existing PRs untouched to preserve concurrent maintainer edits.
Validate against current main without masking candidate rejection.

Signed-off-by: trvon <me@trevon.dev>

* ci: isolate hook Git environments

Prevent temporary Git fixtures from modifying the calling worktree.
Clear repository-local hook variables before the unchanged build gates,
and isolate validator and fixture Git subprocesses from caller overrides.
Exercise linked-worktree config, ref and index preservation offline.

Signed-off-by: trvon <me@trevon.dev>

---------

Signed-off-by: trvon <me@trevon.dev>

* fix(ci): reject invalid candidate evidence

Explain missing main history without mutating refs or weakening promotion validation. Match experiment boolean and aggregation parsing, respect candidate-limit precedence, and return issues for malformed configuration or metric values.

Signed-off-by: trvon <me@trevon.dev>

* fix: preserve completion and retrieval contracts

Propagate derivation SQL failures, invalidate KG status caches, and avoid unused preview reads. Align explicit hash validation and export standalone client dependencies. Keep secret exceptions fixture-scoped and remove undefined behavior from status fixtures.

Signed-off-by: trvon <me@trevon.dev>

* fix: fence asynchronous enrichment completion

Coordinate graph and NL commits before acknowledging enrichment. Atomically classify embedding reuse, fence repair status writes, and preserve newer vectors on old failures. Upgrade content readiness triggers and keep repository counters coherent. Six affected ASan suites pass; this does not provide restart replay or generation-scoped vector storage.

Signed-off-by: trvon <me@trevon.dev>

* fix: bound semantic graph output reservation

Use retained neighbors for admission and node capacity instead of mixing corpus and pair counts. Preserve single-neighbor output and avoid quadratic reservation. Characterization regression fails three assertions before the fix; full component ASan suite passes afterward.

Signed-off-by: trvon <me@trevon.dev>

* fix: fence standalone embedding repair completion

Mint attempt tokens before reading canonical repair input and publish only current persisted document embeddings. Do not skip stale physical vectors. Make SQLite preparation fault injection connection-local and deterministic. Full component and metadata ASan suites pass.

Signed-off-by: trvon <me@trevon.dev>

* fix: preserve enrichment failure reporting

Admit pending embedding attempts before provider failures while preserving completed results. Route title no-op acknowledgement through the writer so flush reports SQL failures and duplicate jobs can retry. Four affected full ASan suites pass; host configuration hashes unchanged.

Signed-off-by: trvon <me@trevon.dev>

* test: align explicit hash prefix boundaries

Reject five characters and accept the supported six-character minimum. Full hybrid_search suite passes. Separate daemon shutdown sanitizer failure remains under investigation despite a passing targeted rerun.

Signed-off-by: trvon <me@trevon.dev>

* test: align UI hash validation boundary

Signed-off-by: trvon <me@trevon.dev>

---------

Signed-off-by: trvon <me@trevon.dev>
2026-09-12 18:53:12 -06:00

113 lines
6.1 KiB
Python

import unittest
from retrieval_contract import validate_retrieval_configuration, validate_retrieval_metrics
class RetrievalConfigurationTests(unittest.TestCase):
def test_phss_pool_cannot_be_smaller_than_chunk_request(self):
issues = validate_retrieval_configuration(
{"YAMS_VECTOR_MAX_RESULTS": "32", "YAMS_VECTOR_VEC0_PHSS_ENABLED": "1",
"YAMS_VECTOR_VEC0_PHSS_CANDIDATES": "16"},
{}, {"ann_candidate_budget": 16})
self.assertTrue(any("96" in issue for issue in issues))
def test_distinct_effective_pool_is_accepted(self):
self.assertEqual(validate_retrieval_configuration(
{"YAMS_VECTOR_MAX_RESULTS": "32", "YAMS_VECTOR_VEC0_PHSS_ENABLED": "1",
"YAMS_VECTOR_VEC0_PHSS_CANDIDATES": "128"},
{}, {"ann_candidate_budget": 128}), [])
def test_phss_boolean_spellings_enforce_effective_pool(self):
for enabled in ("1", "true", "TRUE", "yes", "on"):
with self.subTest(enabled=enabled):
self.assertTrue(validate_retrieval_configuration(
{"YAMS_VECTOR_MAX_RESULTS": "32", "YAMS_VECTOR_VEC0_PHSS_ENABLED": enabled,
"YAMS_VECTOR_VEC0_PHSS_CANDIDATES": "16"},
{}, {"ann_candidate_budget": 16}))
def test_product_latency_accepts_disabled_boolean_spellings(self):
for disabled in ("0", "false", "FALSE", "no", "off"):
with self.subTest(disabled=disabled):
self.assertEqual(validate_retrieval_configuration(
{"YAMS_SEARCH_STAGE_TRACE": disabled}, {"latency_mode": "product"}, {}), [])
def test_aggregation_matches_runtime_case_rules(self):
for aggregation, budget in (("max", 32), ("MAX", 32), ("Max", 96)):
with self.subTest(aggregation=aggregation):
self.assertEqual(validate_retrieval_configuration(
{"YAMS_VECTOR_MAX_RESULTS": "32", "YAMS_VECTOR_VEC0_PHSS_ENABLED": "1",
"YAMS_SEARCH_CHUNK_AGGREGATION": aggregation,
"YAMS_VECTOR_VEC0_PHSS_CANDIDATES": "16"},
{}, {"ann_candidate_budget": budget}), [])
def test_candidate_multiplier_precedes_explicit_vector_override(self):
env = {"YAMS_VECTOR_VEC0_PHSS_ENABLED": "1", "YAMS_CANDIDATE_MULTIPLIER": "2.0"}
self.assertEqual(validate_retrieval_configuration(env, {}, {"ann_candidate_budget": 900}), [])
env["YAMS_VECTOR_MAX_RESULTS"] = "32"
self.assertEqual(validate_retrieval_configuration(env, {}, {"ann_candidate_budget": 96}), [])
def test_invalid_configuration_returns_issues_not_exceptions(self):
for key in ("YAMS_VECTOR_MAX_RESULTS", "YAMS_VECTOR_VEC0_PHSS_CANDIDATES",
"YAMS_CANDIDATE_MULTIPLIER"):
for value in ("invalid", None, "NaN", "-1"):
with self.subTest(key=key, value=value):
self.assertTrue(validate_retrieval_configuration(
{"YAMS_VECTOR_VEC0_PHSS_ENABLED": "1", key: value},
{}, {"ann_candidate_budget": 450}))
self.assertTrue(validate_retrieval_configuration(
{"YAMS_VECTOR_VEC0_PHSS_ENABLED": "1"}, {}, {"ann_candidate_budget": None}))
def test_invalid_metrics_return_issues_not_exceptions(self):
for value in (None, "invalid", {}, [], float("inf")):
with self.subTest(value=value):
self.assertTrue(validate_retrieval_metrics(
{"topology_shadow_evaluation_rate": value}, {"require_shadow_evaluation": True}))
self.assertTrue(validate_retrieval_metrics(
{"topology_candidate_rescue_exact_distance_evaluations_sum": value},
{"require_exact_shadow_control": True}))
def test_vec0_cannot_validate_fast_narrowing(self):
issues = validate_retrieval_configuration(
{"YAMS_VECTOR_SEARCH_ENGINE": "vec0"},
{"require_narrowing": True}, {})
self.assertTrue(any("simeon_pq_adc" in issue for issue in issues))
def test_narrowing_requires_bound_calibration(self):
issues = validate_retrieval_configuration(
{}, {"vector_search_engine": "simeon_pq_adc", "require_narrowing": True}, {})
self.assertTrue(any("calibration" in issue for issue in issues))
def test_artifact_name_alone_cannot_enable_unimplemented_calibration_loading(self):
issues = validate_retrieval_configuration(
{}, {"vector_search_engine": "simeon_pq_adc", "require_narrowing": True,
"route_calibration_artifact": "claimed-calibration.json"}, {})
self.assertTrue(any("calibration" in issue for issue in issues))
def test_product_latency_rejects_trace_work(self):
self.assertTrue(validate_retrieval_configuration(
{"YAMS_SEARCH_STAGE_TRACE": "1"}, {"latency_mode": "product"}, {}))
def test_product_latency_must_explicitly_disable_worker_trace_default(self):
self.assertTrue(validate_retrieval_configuration({}, {"latency_mode": "product"}, {}))
def test_shadow_cost_requires_actual_shadow_work(self):
for rate in (0, float("nan"), 2):
self.assertTrue(validate_retrieval_metrics(
{"topology_shadow_evaluation_rate": rate}, {"require_shadow_evaluation": True}))
self.assertEqual(validate_retrieval_metrics(
{"topology_shadow_evaluation_rate": 0.5,
"topology_candidate_rescue_attempt_rate": 0.5,
"topology_route_work_observation_rate": 0.5},
{"require_shadow_evaluation": True}), [])
def test_load_attempt_is_not_routed_work_or_exact_control(self):
self.assertTrue(validate_retrieval_metrics(
{"topology_shadow_evaluation_rate": 1.0}, {"require_shadow_evaluation": True}))
self.assertTrue(validate_retrieval_metrics({}, {"require_exact_shadow_control": True}))
self.assertEqual(validate_retrieval_metrics(
{"topology_candidate_rescue_exact_distance_evaluations_sum": 34},
{"require_exact_shadow_control": True}), [])
if __name__ == "__main__":
unittest.main()