@davoodmehraban89 / Aram / commits / e4b2608
Fork 0

test(mapping): expose bool/int duplicate ambiguity and locator injection

davoodmehraban89 committed Oct 30, 2026 at 19:03 UTC e4b2608bd827f249755a5280142fb1c12a78174c
1 file changed +35
backend/tests/test_mapping_batch_review.py
+35
@@ -221,3 +221,38 @@ def test_malformed_row_is_diagnostic_not_parser_crash(session):
221 ])
222 assert result.counts == {"invalid": 1, "new": 1}
223 assert result.ready_for_review is False
224 +
225 +
226 +def test_bool_target_id_cannot_coalesce_with_integer_id(session):
227 + year, cash, _ = setup_year(session, "BATCH-TYPE-ID")
228 + result = preview_mapping_batch(session, year_id=year.id, rows=[
229 + row("M!2", "cash", cash),
230 + row("M!3", "cash", cash, target_note_id=True),
231 + ])
232 + assert [item.status for item in result.rows] == ["conflict", "conflict"]
233 + assert result.ready_for_review is False
234 + assert session.scalars(select(MappingRule)).all() == []
235 +
236 +
237 +def test_bool_base_version_cannot_coalesce_with_integer_version(session):
238 + year, cash, other = setup_year(session, "BATCH-TYPE-VERSION")
239 + save_mapping_rule(
240 + session, year_id=year.id, rule_key="cash", account_code="001",
241 + target_note_id=cash.id, mapping_type="manual", version=1,
242 + )
243 + session.commit()
244 + result = preview_mapping_batch(session, year_id=year.id, rows=[
245 + row("M!2", "cash", other, expected_base_version=1),
246 + row("M!3", "cash", other, expected_base_version=True),
247 + ])
248 + assert [item.status for item in result.rows] == ["conflict", "conflict"]
249 + assert result.ready_for_review is False
250 +
251 +
252 +@pytest.mark.parametrize("locator", ["M!2\nM!3", "M!2\rM!3", "M!2\tsecret", "M!2\x00hidden"])
253 +def test_control_characters_in_source_locator_are_rejected(session, locator):
254 + year, cash, _ = setup_year(session, "BATCH-CTRL")
255 + with pytest.raises(MappingValidationError, match="source locator"):
256 + preview_mapping_batch(session, year_id=year.id, rows=[
257 + row(locator, "cash", cash),
258 + ])