movilba
MOVILBA-782
getCurrentHistorial has 3 write-path callers, wrong-row risk not exercised
Done normal
cmcoder04-mba-l-ca
Split from MOVILBA-542 per audit's 2026-10-09 01:53Z correction: getCurrentHistorial has exactly three callers, all write paths - two copy its result into createHistorialRecord, one decides whether to assign. A wrong selected row could be copied forward into a new historial record. Not exercised; no affected-row search done. R1/R3 resolver pair, distinct from 542's R2 TS/SQL tie-break duplication.
Activity
-
Taking the R3 write-path finding after MOVILBA-542 closed. Next measure the values the three getCurrentHistorial callers would preserve from R3 versus canonical R1, before deciding whether the write resolver should change. No code edit yet.
-
SELECT-only R3-vs-R1 field census run with .env.local read roles (PROD svc_nextjs, DEV movilba_user). R3 row-ID mismatch: 2/2424 PROD, 40/2469 DEV. Joined canonical R1 ids back to normalized history to compare state_id (the view does not project it): differing fields PROD entidad 0/linea 0/estado 1; DEV entidad 1/linea 1/estado 14. Entity/line write-path preservation risk population: 1 PROD/14 DEV; edit entity/line decision population: 0 PROD/1 DEV. No write paths exercised. First query attempt incorrectly assumed R1 exposed estado_id and failed at parse before reading rows; corrected query joins through R1.id. Candidate changes getCurrentHistorial to join normalized data to R1's selected id and removes its parallel eligibility/order logic. Added structural regression test; pins c2c5eec355601876c443d906a4abd36265eb949fbc9510578e32f01c6f0edc6f and 2d17edc9fd7e7cd61306f3cdf8b82bf01c1495c815f2d4527dbc7e38af39308a. diff --check clean; no gates or write tests run by author.
-
# MOVILBA-782 R3 - audit verdict: PASS. Author coder04-mba-l-ca. audit-mba-l-cc, 2026-10-09 Scope: getCurrentHistorial (src/repositories/vehiculos.ts:1085) stops running its own independent eligibility+ranking rule (origen app OR import-at-latest-snapshot, ORDER BY fecha_alta/creado_en/id) and instead inner-joins the selected row from rutap.v_vehiculo_historial_actual (R1, established canonical in MOVILBA-542) by id+vehiculo_id, keeping LIMIT 1. R1 does not project estado_id, so the join-back exists only to recover that one column from the matched normalizado row - R1 still owns which row. ## Pins confirmed exact src/repositories/vehiculos.ts c2c5eec3, tools/tests/current-historial-r3-single-source.test.cjs 2d17edc9. ## Gates, run fresh by me typecheck rc=0. test:source 68/0 (unchanged, no src-side fixture for this). test:tools 121/0 (+1, the new structural test). The new test is structural only - asserts the join shape, the three eq() predicates, no orderBy, no reference to the old eligibility constants, and that exactly 3 callers remain in src/services/vehiculos.ts. It does not run against data; the gates are the only exercise this item gets before ship. ## Diff and all 3 callers read src/services/vehiculos.ts:640 (assignToEntidad, preserves lineaId/estadoId), :735 (assignToLinea, preserves entidadId/estadoId), :861 (update path, decides entidadChanged/lineaChanged by comparing against currentHistorialForAssignments). All three feed write-path decisions - this is not a read-only display field. ## Impact census, run independently (not copied from coder04's report) Built my own old-vs-new comparison query from the removed code (same eligibility/order predicate, read before the diff landed, vs the new R1-join) and ran it fresh on both bases: PROD: 2424 vehicles compared, row_id_diff=2, entidad_diff=0, linea_diff=0, estado_diff=1 - exact match to coder04's reported 2/2424 and 0/0/1. DEV: 2469 vehicles compared, row_id_diff=40, entidad_diff=1, linea_diff=1, estado_diff=14 - exact match to coder04's reported 40/2469 and 1/1/14. These are the vehicles where the old ad-hoc rule and the canonical R1 ranking already disagreed before this patch - i.e. the write-preservation bug this item exists to close. Consistent with the project's own named recurring defect (multiple surfaces resolving "current period" differently) and with MOVILBA-542 R2, already PASSed, which gave R1 the same authority on four other surfaces. ## NOT EXERCISED No write path run - no assignToEntidad/assignToLinea/update call was actually invoked against the 1 PROD / 14 DEV vehicles with an estado_id (or entidad/linea) difference, so the preserved-value-on-next-edit claim is derived from the SELECT census, not observed on a live write. No UI/form exercised. No DB object changed - this is pure app code, no DDL, no migration to rehearse.
-
audit pass: Diffs+3 callers read, gates run fresh (typecheck/68-0/121-0), impact census re-run independently from own query, not copied
payload
{"scope":"Diffs+3 callers read, gates run fresh (typecheck/68-0/121-0), impact census re-run independently from own query, not copied","outcome":"pass","evidence":"census exact match PROD 2-2424 0-0-1, DEV 40-2469 1-1-14; pins c2c5eec3/2d17edc9 confirmed","reportRef":null} -
Audit PASS on exact pins; audit independently reproduced the R3/R1 impact counts. Fresh gates: typecheck 0, test:source 68/0, test:tools 121/0. No live write path exercised. Handed to coder03 for ship; item remains open pending ship.
-
R3 shipped dev f05fae8e + prod ece698b6, patch 231. Audit PASS on exact pins, gates green, no write path exercised live.
bug
1w ago by coder03-mba-l-cc
1w ago
2026-10-09 03:56