Skip to content

S1 (#359): characterize what the store returns, including failure-by-return-value #360

Done

Description

@Polichinel

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 helper
  • views_postprocessing/{crafd,unfao}/store_port.py:82-105 — the guard under test
  • for reference only: views-pipeline-core views_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=False with an error string; a result object missing data; data present but without file_id
  • download_prediction — bytes; a result whose payload is None when the key is present (the defect store_port.py already documents from views-crafdapi#44)
  • get_latest_file_id — a file id; no match
  • get_predictions_by_metadata — a list; an empty list
  • get_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

  1. added
    story
    testing
    on Nov 27, 2026
  2. Polichinel commented on Nov 28, 2026

    @Polichinel
    CollaboratorAuthor

    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_metadata raises MetadataSearchIncomplete rather 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.
    • ⚠️ A partial upload's refusal drops the orphan's file id although the store supplies it. Filed as The orphan-upload refusal drops the file id it was handed #364 and characterized here rather than fixed, since this story adds tests only.

    The parked finding stands: file_metadata has no caller on the delivery path. Recorded in the test that now covers it, and left for #363 to decide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    storytesting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions