various edits

This commit is contained in:
2026-07-21 16:43:22 -06:00
parent 88161a6f16
commit c1e453d962
16 changed files with 526 additions and 31 deletions
+207
View File
@@ -117,6 +117,213 @@ class DashboardExportTests(unittest.TestCase):
}
self.assertEqual(first_bytes, second_bytes)
def test_release_id_includes_publication_policy_version(self) -> None:
mart_digest = "a" * 64
provenance = [("model_v1", "b" * 64)]
release_id = dashboard_export._release_id(mart_digest, provenance)
with mock.patch.object(
dashboard_export,
"PUBLICATION_POLICY_VERSION",
dashboard_export.PUBLICATION_POLICY_VERSION + "_changed",
):
changed_release_id = dashboard_export._release_id(
mart_digest, provenance
)
self.assertNotEqual(release_id, changed_release_id)
def test_scorecards_fold_only_new_family_aliases_before_suppression(self) -> None:
connection = duckdb.connect(":memory:")
try:
connection.execute(
"""
CREATE TABLE safe_mart (
vehicle_token VARCHAR,
eligible_returning_target BOOLEAN,
target_nonpass INTEGER,
last_observed_make VARCHAR,
last_observed_model VARCHAR
)
"""
)
rows = []
def add_group(make: str, model: str, nonpass: int = 10) -> None:
group_number = len(rows)
for index in range(60):
rows.append(
(
"group-{}-vehicle-{}".format(group_number, index),
True,
1 if index < nonpass else 0,
make,
model,
)
)
# Every raw-string group is below the 100-vehicle threshold. Each
# approved pair reaches 120 only after its explicit aliases merge.
canonical_groups = {
("CHEVROLET", "SILVERADO 1500"): (
("CHEVROLET", "SILVERADO 1500 LT"),
("CHEVR", "K15 SILVERADO"),
),
("DODGE", "RAM 1500"): (
("DODGE", "RAM 1500 QUAD"),
("DODGE", "RAM PICKUP 1500"),
),
("HYUNDAI", "ELANTRA"): (
("HYUNDAI", "ELANTRA GLS"),
("HYUND", "ELANTRA"),
),
("NISSAN", "ALTIMA"): (
("NISSAN", "ALTIMA 2.5 S"),
("NISSA", "ALTIMA"),
),
("SUBARU", "OUTBACK"): (
("SUBARU", "LEGACY OUTBACK 2.5I AWD"),
("SUBAR", "OUTBACK"),
),
("TOYOTA", "4RUNNER"): (
("TOYOTA", "4RUNNER SR5"),
("TOYOT", "4RUNNER 4WD"),
),
("TOYOTA", "COROLLA"): (
("TOYOTA", "COROLLA CE LE S"),
("TOYOT", "COROLLA"),
),
("TOYOTA", "TACOMA"): (
("TOYOTA", "TACOMA V6"),
("TOYOT", "TACOMA 4WD"),
),
}
for variants in canonical_groups.values():
for make, model in variants:
add_group(make, model)
# These separately marketed lines share a prefix with a canonical
# family but must remain distinct and suppressed at this support.
for make, model in (
("HONDA", "ACCORD CROSS TOUR EXL"),
("HONDA", "ACCORD CROSSTOUR"),
("HONDA", "CIVIC CRX SI"),
("HONDA", "CIVIC DEL SOL SI"),
("TOYOT", "CAMRY SOLARA"),
("TOYOTA", "COROLLA IM"),
("DODGE", "RAM 1500 VAN"),
("FORD", "F1500"),
("NISSAN", "ALTIMAX"),
("TOYOTA", "CAMRYX"),
):
add_group(make, model, nonpass=30)
connection.executemany(
"INSERT INTO safe_mart VALUES (?, ?, ?, ?, ?)", rows
)
scorecards = dashboard_export._scorecard_rows(connection)
finally:
connection.close()
self.assertEqual(
[(row["prior_make"], row["prior_model"]) for row in scorecards],
sorted(canonical_groups),
)
self.assertTrue(
all(row["support_rounded"] == 100 for row in scorecards)
)
self.assertTrue(all(row["nonpass_rate"] == 0.167 for row in scorecards))
def test_legacy_scorecard_cells_are_not_broadened_by_aliases(self) -> None:
connection = duckdb.connect(":memory:")
try:
connection.execute(
"""
CREATE TABLE safe_mart (
vehicle_token VARCHAR,
eligible_returning_target BOOLEAN,
target_nonpass INTEGER,
last_observed_make VARCHAR,
last_observed_model VARCHAR
)
"""
)
rows = []
def add_group(
make: str,
model: str,
n: int,
nonpass: int,
) -> None:
group_number = len(rows)
for index in range(n):
rows.append(
(
"group-{}-vehicle-{}".format(group_number, index),
True,
1 if index < nonpass else 0,
make,
model,
)
)
legacy_cells = {
("FORD", "F150"): 12,
("HONDA", "ACCORD"): 18,
("HONDA", "CIVIC"): 24,
("TOYOTA", "CAMRY"): 30,
}
aliases = {
("FORD", "F150"): (
("FORD", "F150 4WD"),
("ford", "f150"),
),
("HONDA", "ACCORD"): (
("HONDA", "ACCORD LX"),
("honda", "accord"),
),
("HONDA", "CIVIC"): (
("HONDA", "CIVIC EX"),
("honda", "civic"),
),
("TOYOTA", "CAMRY"): (
("TOYOTA", "CAMRY LE"),
("TOYOT", "CAMRY"),
),
}
for (make, model), nonpass in legacy_cells.items():
add_group(make, model, 120, nonpass)
# This raw key renders as the legacy key after safe-category
# trimming. It must not become a second public identity.
add_group(" " + make + " ", " " + model + " ", 120, 60)
# Each alias is suppressed alone but would pass support if the
# two were folded together, making accidental broadening clear.
for alias_make, alias_model in aliases[(make, model)]:
add_group(alias_make, alias_model, 60, 30)
connection.executemany(
"INSERT INTO safe_mart VALUES (?, ?, ?, ?, ?)", rows
)
scorecards = dashboard_export._scorecard_rows(connection)
finally:
connection.close()
self.assertEqual(len(scorecards), len(legacy_cells))
by_cell = {
(row["prior_make"], row["prior_model"]): row
for row in scorecards
}
self.assertEqual(set(by_cell), set(legacy_cells))
for cell, nonpass in legacy_cells.items():
with self.subTest(cell=cell):
self.assertEqual(by_cell[cell]["support_rounded"], 100)
self.assertEqual(
by_cell[cell]["nonpass_rate"], round(nonpass / 120, 3)
)
def test_unlocked_model_manifest_is_refused(self) -> None:
manifest = self._read_json(self.model_manifest)
manifest["locked_test_evaluated"] = True