Repository navigation
Description
Story 1 of epic #359.
Context
The wire ports call _ContractStorePort, which calls a DatastoreModule. Before anything else can be passed into that constructor, the contract between them has to be written down as tests — not as a reading of the code. These are characterization tests in Feathers' sense (Working Effectively with Legacy Code, ch. 13, p. 186): they record what the code does today, not what it should do.
The behaviour that matters is that failure arrives as a return value, not an exception. upload_data never raises; it returns an OperationResult with .success, .error and .data["file_id"]. The port's guard at store_port.py:82-105 exists for exactly that, and refuses unless success is True.
Check first
Run the existing tests/test_store_port.py and read _FakeStore at line 60 and _port(...) at line 84. If a fake already covers one of the cases below, extend it rather than writing a second one.
Files
tests/test_store_port.py— the existing fake and helperviews_postprocessing/{crafd,unfao}/store_port.py:82-105— the guard under test- for reference only:
views-pipeline-coreviews_pipeline_core/modules/datastore/datastore.py:17-22, 287
What to record
For each of the five adapted calls, what comes back on success and on each failure the code already distinguishes:
upload_data— success;success=Falsewith an error string; a result object missingdata;datapresent but withoutfile_iddownload_prediction— bytes; a result whose payload isNonewhen the key is present (the defectstore_port.pyalready documents from views-crafdapi#44)get_latest_file_id— a file id; no matchget_predictions_by_metadata— a list; an empty listget_file_metadata— note in the test that this one has no live caller in this repository; record the shape anyway, because the port declares it
Acceptance
- The full test suite passes.
- Every route, output and file a partner receives is unchanged — this story adds tests only.
- Each test asserts observed behaviour, with no "should" in its name or docstring.
Validation
pytest tests/test_store_port.py -v and the full suite. Each new test should fail if the asserted field is renamed.
Budget
Vendor copies: unchanged. Net lines: positive, and that is correct for a characterization story.
Rollback
Revert the commit. Nothing else depends on it yet.
Activity
Polichinel commentedon Nov 28, 2026
Merged in #365.
tests/test_store_port.py: 77 passed, was 43. Ten mutations applied to production code and reverted, ten caught.Every item on the story's "what to record" list is covered, with two additions the story did not ask for and the review turned up:
get_predictions_by_metadataraisesMetadataSearchIncompleterather than reporting failure by return value. That is the exception to this epic's headline fact, and my first draft asserted the opposite for that method.The parked finding stands:
file_metadatahas no caller on the delivery path. Recorded in the test that now covers it, and left for #363 to decide.