Add test for sidecar + upversion intersection behavior#1650
Conversation
Pins the contract that re-importing a zip with a sidecar at an already-occupied corpus path: - creates a new Document in the same version_tree_id with parent=v1 - increments DocumentPath.version_number and links the path chain - attaches the new sidecar's title/description, text annotations, and doc-level labels to the NEW Document - leaves the prior version's annotations attached to the now-non-current Document (no migration, no deletion) — confirming annotations are not versioned themselves but tied by FK to a specific Document version - current-path query resolves only to the new version's annotations Existing upversion tests covered the path/version-tree mechanics; this test pins the sidecar-payload-meets-collision case that they did not exercise.
Code ReviewOverviewThis PR adds IssuesCritical — CLAUDE.md violationThe PR description ends with a bare Claude Code session URL: CLAUDE.md explicitly says "Never credit Claude or Claude Code in commit messages, PR messages, comments, or any other artifacts." Please remove this URL from the description before merging. Should Fix — DRY violation in helper methods
# TestSidecarImportTask (existing)
def _create_temp_file_handle(self, zip_buffer):
zip_content = ContentFile(zip_buffer.read(), name="test_sidecar_import.zip")
handle = TemporaryFileHandle.objects.create(file=zip_content)
return handle
# TestSidecarUpversioning (new) — nearly identical
def _create_temp_file_handle(self, zip_buffer):
zip_content = ContentFile(zip_buffer.read(), name="test_sidecar_upversion.zip")
return TemporaryFileHandle.objects.create(file=zip_content)CLAUDE.md calls out DRY as a first-class principle. A shared Should Fix — Local import inside test methoddef test_sidecar_metadata_and_annotations_attach_to_new_version(self):
from opencontractserver.documents.models import Document
SuggestionsMonolithic test methodAt ~250 lines, Example sketch: @classmethod
def setUpClass(cls):
super().setUpClass()
# run v1 import, capture cls.v1_doc / cls.v1_path
# run v2 import, capture cls.v2_doc / cls.v2_path
def test_path_tree_version_numbers(self): ...
def test_content_tree_parent_links(self): ...
def test_metadata_isolation(self): ...
def test_annotation_isolation(self): ...
def test_current_path_query_visibility(self): ...This is a "nice to have" — the existing single-method approach is functional and consistent with tests elsewhere in the file.
|
…versioning-1Bwse # Conflicts: # CHANGELOG.md
…behavior - Factor _SidecarImportTestMixin to eliminate duplicated zip/handle helpers across TestSidecarImportTask, TestMalformedLabelsImport, TestSidecarSchemaValidationIntegration, and TestSidecarUpversioning. - Hoist 'Document' import to module level (was inline in test method). - Apply black reformatting fix that the linter flagged. - Correct the test's assertions: sidecar title/description only attach to Document when skip_pipeline=True. Default pipeline upversion uses the bare filename as the title, so drop the title/description asserts and keep the annotation-ownership-across-versions assertions intact. Rename the test method accordingly. Update CHANGELOG to reflect the corrected scope.
Code ReviewOverviewThis PR adds The IssuesMinor —
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…name - Remove redundant handle_name override on TestSidecarImportTask (matches mixin default) - Add positive assertions for v2 annotations in visible_texts (guards against ghost / empty result) - Make _shared_labels_json a @staticmethod (no self references)
Code Review: PR #1650 — Sidecar + Upversion Intersection TestOverviewThis PR adds Strengths
Issues & SuggestionsMinor: Unnecessary nested
|
Summary
Adds test coverage for the intersection of sidecar import and document upversioning. Verifies that when a zip containing a document and its annotation sidecar is imported at a path that already has a Document, the system correctly creates a new Document version, attaches the sidecar's annotations to the new version, and preserves the prior version's annotations on the original Document row.
Changes
TestSidecarUpversioninginopencontractserver/tests/test_sidecar_import.py:skip_pipelineabsent / falsy)Documentin the sameversion_tree_idwithparentpointing to v1DocumentPath.version_numberincrements and the path chain is re-linked correctlyversion_tree_id_SidecarImportTestMixin— shared in-memory zip /TemporaryFileHandleplumbing previously duplicated acrossTestSidecarImportTask,TestMalformedLabelsImport, andTestSidecarSchemaValidationIntegration. The new class uses it too.Implementation Notes
Sidecar
title/descriptiononly land on the Document row via theskip_pipeline=Trueroute (already covered bytest_skip_pipeline_creates_document_from_export_data). The default-pipeline upversion flow used in this test uses the bare filename as the Document title, so this test does not assert on Document.title / Document.description. The contract being pinned is annotation ownership across versions, not metadata routing.Key assertions verify:
This pins the contract that annotations are not migrated between versions — each Document row owns its own annotation set via FK relationship.