The scenario: two attachments look similar but contain different evidence
A person can photograph the same document twice. Two genuinely different documents can also share a date, provider and selected amounts. A record merger needs a useful way to surface likely repetition while preserving enough evidence for review when the similarity is misleading or incomplete.
The inspected Movo-X episode merger creates duplicate candidates and retains the documents. It does not silently delete a receipt or declare a financial total authoritative. This case examines the matching key, attachment ordering, validation of duplicate references and separate expense-review signals using two existing tests and three supplemental synthetic fixtures.
Name the exact similarity rule before calling it identity
For the selected receipt path, the matching key combines document kind, printed date, normalized provider and selected amount fields including currency. Provider normalization removes certain formatting differences after case folding and Unicode normalization. The fixture checks that a punctuation and case variation can still produce a candidate.
This is a deterministic similarity rule, not optical image equality or proof of a shared real-world receipt number. The key does not incorporate every possible source detail. Two documents sharing these selected fields can therefore require human distinction. Presenting a candidate as a confirmed duplicate would give the heuristic more authority than the implementation establishes.
Document order determines the reference direction
The merger sorts successful readings according to the supplied source-photo order before recording duplicate references. The first matching document becomes the reference for a later candidate. The supplemental fixture deliberately reverses the stored-reading input and checks that this selection follows photo order rather than incidental input order.
Reversing the supplied photo order reverses the reference direction in the fixture. That is a reproducible implementation decision; it does not establish which photo was first captured, uploaded or issued. A product that needs a different canonical document policy should define that policy explicitly instead of interpreting this reference as chronological or legal precedence.
Missing match evidence does not prove documents are distinct
The selected algorithm requires a printed document date before making its duplicate key. One supplemental example removes that date and checks that no candidate is produced. Another changes currency while retaining the other selected receipt amounts and checks the same refusal to match.
These negative cases establish the heuristic’s boundary. An unflagged document is not certified unique: it may lack a usable date or contain an extraction difference. Conversely, a flag is not permission to discard evidence. A review interface should make candidate status inspectable without implying that every possible repetition has been detected.
Retain payment differences even when the candidate key matches
The receipt key does not use payment status or paid amount. The supplemental fixtures therefore use matching selected receipt fields with different payment evidence. A duplicate reference is produced, but both expense entries and their separate paid values remain present.
One example preserves an unknown paid amount beside a documented zero. Those are distinct representations: missing evidence is not the same as an explicitly recorded zero. This is software contract behaviour in a synthetic fixture, not an assessment of an actual transaction. Resolving whether the source documents describe one payment, multiple payments or a reading error remains outside the matching function.
Validate duplicate relationships as a graph
A duplicate reference needs more than a plausible identifier. The shared import-record validator checks that referenced attachments belong to the supplied source set, rejects self-reference and follows the document links to reject cycles or missing referenced documents.
The selected existing graph test constructs a cycle and checks refusal, then checks the valid relationship alongside expense-review output. This keeps the record internally traversable. It does not prove that the supplied source set was authorized by the production database; that authority belongs to the caller and database path, which these pure fixtures do not exercise.
Keep review signals separate from totals and deletion
The expense-review helper reports selected issues such as duplicate receipt candidates, multiple currencies, unknown payment evidence and arithmetic conflicts. The inspected code explicitly avoids aggregating currencies or removing repeated receipt photos as part of this helper.
That separation is useful when evidence is incomplete. A reader can inspect the attachments and discrepancies without a background deduplication step making the decision irreversible. Any later reviewed total needs its own receipt-identity resolution and calculation contract. Neither a candidate flag nor a clean issue list is proof that an actual financial record has been reconciled.
A concrete duplicate-review acceptance package
Use fixtures that vary source order, normalized provider spelling, missing dates, currencies and payment evidence. Assert both the candidate references and the continued presence of the original expense entries. Add graph-invalid cases so reference integrity is tested independently from similarity matching.
For a CTO, the resulting design has a clear responsibility: it helps reviewers find possible repetition while preserving the evidence required to decide. The five scoped cases establish selected deterministic behaviour in the pinned merger. Real document identity, interface decisions, deletion policy, database permissions and reviewed totals retain their own acceptance and evidence.
Compare the reviewed boundaries
Candidate matching versus authoritative resolution
On smaller screens, scroll across to compare every column. Keyboard users can focus the table and use the arrow keys.
| Condition | Selected merge result | Meaning for review |
|---|---|---|
| Selected normalized receipt fields match | Duplicate reference recorded | Candidate similarity, not proven identity |
| Date absent or selected currency differs | No match in these fixtures | Not proof of uniqueness |
| Paid evidence differs | Both expense entries retained | Resolve payment meaning separately |
| Duplicate references form a cycle | Record validation refuses it | Internal graph integrity, not source authenticity |
Illustrative control flow
Pseudocode summarizing the decision boundary. It is not copied production code or a deployment instruction.
ordered_documents = sort_by_authorized_source_order(readings)
candidates = mark_selected_similarity_matches(ordered_documents)
record = validate_attachment_references_and_acyclic_links(candidates)
keep_each_original_expense_and_its_payment_evidence(record)
issues = describe_review_conditions(record)
# Candidate marking does not delete receipts or reconcile a total.About this engineering series
Written by Omer Muneer Qazi from a review of Movo-X implementation and dated engineering records. This article explains source behaviour and historical observations; current production, clinical outcomes and store availability require their own verification. Examples are synthetic and proposed test cases are identified as such.
Explore the Movo-X engineering series → · Related implementation experience →
Discuss a similar engineering problem
Send the workflow, current platform and the decision your team needs to make. I can help define an implementation or review scope with concrete acceptance evidence.
Discuss your project on WhatsApp ↗