@davoodmehraban89 / Aram-1 / commits / e95561f
Fork 0

fix(v1): block protected-year relationship reparenting

davoodmehraban89 committed Aug 26, 2026 at 19:11 UTC e95561f1c00d7d6c9f126f6ad5712b01abbe4a15
4 files changed +16 -3
backend/src/aram_backend/models.py
+1 -1
@@ -253,7 +253,7 @@ def enforce_audit_invariants(session: Session, _flush_context, _instances) -> No
253 f"Invalid fiscal-year transition: {old_status.value} -> {obj.status.value}"
254 )
255
256 - protected_metadata_changed = any(
256 + protected_metadata_changed = state.attrs.company.history.has_changes() or any(
257 state.attrs[field].history.has_changes() for field in ("company_id", "year")
258 )
259 if old_status in _PROTECTED_YEAR_STATUSES and protected_metadata_changed:
backend/tests/test_models.py
+13
@@ -208,6 +208,19 @@ def test_company_with_protected_year_cannot_be_deleted(session):
208 session.commit()
209
210
211 +def test_protected_year_cannot_be_reparented_through_relationship(session):
212 + year = make_year(session)
213 + replacement = Company(code="REPLACEMENT", name="Replacement Company")
214 + session.add(replacement)
215 + session.commit()
216 + year.status = FiscalYearStatus.APPROVED
217 + session.commit()
218 +
219 + year.company = replacement
220 + with pytest.raises(ValueError, match="identity cannot be mutated"):
221 + session.commit()
222 +
223 +
224 def test_draft_year_identity_and_deletion_remain_mutable(session):
225 year = make_year(session)
226 year.year = 1405
docs/PROJECT_LOG.md
+1 -1
@@ -266,7 +266,7 @@ Each new entry must record: UTC timestamp, actor, task/phase, base branch and SH
266 - Initial implementation commit SHA: `6d774e5dd7afb00b04e523ba255aeee4f13bfccc`; final reviewed head remains remote-state dependent
267 - Exact planned changed files: `index.html`, `PROJECT_STATUS.md`, `backend/src/aram_backend/models.py`, `backend/src/aram_backend/pilot_workbook.py`, `backend/tests/test_models.py`, `backend/tests/test_pilot_workbook.py`, `docs/PROJECT_LOG.md`, `docs/handoff/LATEST_HANDOFF.md`
268 - Implementation: prevent approved/locked fiscal-year identity mutation and deletion; prevent parent-company mutation/deletion when protected years exist; reject targetless, hierarchy-invalid, formula-code, review-evidence-deficient, and closing-delta-mismatched Pilot rows; replace the disconnected hard-coded root UI with an explicit quarantine page
269 -- Local tests: `cd backend && .venv/bin/pytest -q` -> 66 passed, 1 third-party deprecation warning
269 +- Local tests: `cd backend && .venv/bin/pytest -q` -> 67 passed, 1 third-party deprecation warning
270 - Focused static checks: `.venv/bin/ruff check src/aram_backend/models.py src/aram_backend/pilot_workbook.py` -> passed; `.venv/bin/mypy src/aram_backend/models.py src/aram_backend/pilot_workbook.py` -> passed
271 - Migration / compile: isolated SQLite `alembic upgrade head` and `alembic downgrade base` passed; `python -m compileall -q src tests scripts` passed
272 - Adversarial verification: the previously accepted targetless/`account_level=99`/`closing_delta=999` workbook is rejected; locked-year identity mutation and deletion are blocked
docs/handoff/LATEST_HANDOFF.md
+1 -1
@@ -96,7 +96,7 @@
96 - Initial implementation head: `6d774e5dd7afb00b04e523ba255aeee4f13bfccc`; fetch the live PR head before review.
97 - Purpose: close the independently reproduced protected-year deletion/mutation and Pilot-preflight false-negative defects before any Mapping/UI expansion.
98 - Planned changed files: `index.html`, `PROJECT_STATUS.md`, `backend/src/aram_backend/models.py`, `backend/src/aram_backend/pilot_workbook.py`, `backend/tests/test_models.py`, `backend/tests/test_pilot_workbook.py`, `docs/PROJECT_LOG.md`, `docs/handoff/LATEST_HANDOFF.md`.
99 -- Local evidence at preparation: 66 pytest tests passed; isolated Alembic upgrade/downgrade and compileall passed; focused Ruff and mypy checks passed.
99 +- Local evidence at preparation: 67 pytest tests passed; isolated Alembic upgrade/downgrade and compileall passed; focused Ruff and mypy checks passed.
100 - Protected boundary: no canonical financial data, workbook, PDF, database, financial value, binary, ZIP, EXE, tag, or release is in scope.
101 - Status: `IN_PROGRESS`; remote final head, CI, and independent review remain authoritative and pending.
102