🚧 Validate files comparable to importing#1187
Draft
laritakr wants to merge 9 commits into
Draft
Conversation
One implementation of from: resolution (Bulkrax::FieldResolver) replaces what had been two divergent copies — HasMatchers#field_to for import and various .first / dig(key, :from) sites for validation. HasMatchers#field_to now delegates to it, so any future changes to alias resolution affect both sides simultaneously. That's the guarantee that "validation mirrors import" becomes durable instead of being a one-time patch.
Some code paths resolve file column headers by taking the first alias from the mapping's `from:` array, while others consider all aliases. This causes problems when a mapping has multiple aliases for a file column. Route both through `FieldResolver.headers_for_field` so they consider every alias (and the canonical key) the way import does.
Extract the zip-entry-to-destination-path logic already in `CsvParser#unzip_*` into a shared `Bulkrax::ZipPlacementPlanner`, then add a `Bulkrax::CsvRow::FileReference` row validator that compares each row's referenced paths against the plan's `available_paths`. Per-row errors flow through the existing rowErrors pipe, so validation now fails (with row attribution) for cases import would fail on. FileValidator is left in place. Its aggregate `missingFiles` / `fileReferences` / `foundFiles` / `zipIncluded` output still feeds the existing UI accordion. Retiring it (along with the bespoke accordion) is a follow-up once the UI consumes the new row-level errors.
Previously we fixed alias resolution for the file column. This commit fixes the same alias-resolution bug for the other three multi-alias columns (parents, children, source_identifier) so the validator agrees with the import on which CSV column to read in all four cases.
Add a test so a future refactor that changes
which alias the template emits still produces *some* valid header
for a multi-alias mapping like `file: { from: ['item','file'] }`.
Replaces all four callers of MappingManager#key_to_mapped_column with FieldResolver.headers_for_field(mapping, key).first, then deletes the method.
Bulkrax field mappings reach runtime from three sources with different key shapes: the default lambda emits inner values with symbol keys (`from:`, `split:`); persisted tenant JSON merged through HashWithIndifferentAccess works either way; direct test setup is mixed. This commit makes FieldResolver and MappingManager tolerant of both symbol- and string-keyed mappings, and routes each direct `from:` read through them. This fixes ApplicationParser#model_field_mappings, which was the one siteactually broken in production for plain-string-keyed configs. Most readers were specific to one shape and silently produced nil under the wrong shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Aligns the guided-import validator with the actual import pipeline so multi-alias
from:mappings (and string-vs-symbol key shapes) resolve to the same CSV columns at validation as at import.