Skip to content

🚧 Validate files comparable to importing#1187

Draft
laritakr wants to merge 9 commits into
mainfrom
validate-files-comparable-to-importing
Draft

🚧 Validate files comparable to importing#1187
laritakr wants to merge 9 commits into
mainfrom
validate-files-comparable-to-importing

Conversation

@laritakr

Copy link
Copy Markdown
Contributor

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix patch-ver for release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant