Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions tests/test_findability.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,41 @@ def test_the_preflight_queries_the_declared_name_not_the_path_managers(partner):
f"{partner} lost the read-back store builder; without it "
"`get_latest_file_id` merges the path manager's model name into the query"
)
builder = source[source.index("def _build_partner_read_store"):source.index("class ")]
assert "store.model_path = None" in builder, (
f"{partner}'s read-back store no longer suppresses pipeline-core's automatic "
"`name == model_name` filter, so the preflight verifies the views-models "
"directory name instead of the declared consumer name. A rename there would "
"leave this check green while the delivery went dark (C-77)."
# The suppression used to be asserted here by searching this builder's source for
# the literal `store.model_path = None`. #362 moved that line into the `_datastore`
# factory, which broke the check without changing any behaviour — the weakness of a
# textual guard, which fails on a harmless rewrite and would equally have stayed
# green had the line moved somewhere it never ran.
#
# The property is now asserted BEHAVIOURALLY, on the store the builder actually
# returns, by
# tests/test_store_construction.py::test_the_partner_read_back_store_is_built_with_the_name_filter_suppressed
# which is mutation-verified: deleting the suppression, or flipping this call's
# argument, reddens it for both partners.
#
# That test needs pipeline-core, so it SKIPS where pipeline-core is absent, and this
# file's checks do not. Review found that removing the textual assertion therefore
# left C-77 guarded by nothing at all in an environment without the dependency. So a
# structural check stays here as the cheap local backstop — on the call's argument,
# not on a line of text, so the move that broke the old one cannot break this one.
builder_ast = next(
n for n in ast.walk(ast.parse(source))
if isinstance(n, ast.FunctionDef) and n.name == "_build_partner_read_store"
)
suppressed = [
kw for call in ast.walk(builder_ast)
if isinstance(call, ast.Call) and getattr(call.func, "id", None) == "_datastore"
for kw in call.keywords
if kw.arg == "keep_model_path"
and isinstance(kw.value, ast.Constant)
and kw.value.value is False
]
assert suppressed, (
f"{partner}'s read-back store is no longer built with keep_model_path=False, so "
"pipeline-core's automatic `name == model_name` filter is live and the preflight "
"verifies the views-models directory name instead of the declared consumer name "
"(C-77). The behavioural proof is in tests/test_store_construction.py; this is "
"the structural backstop for environments where that file skips."
)

preflight = _function_source(source, "_assert_delivery_is_findable")
Expand Down
34 changes: 24 additions & 10 deletions views_postprocessing/crafd/managers/crafd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@



def _datastore(config: AppwriteConfig, *, keep_model_path: bool) -> DatastoreModule:
"""The ONE place this package constructs a prediction store (#362, epic #359).

*A seam you cannot switch from outside the code is not a seam* (Feathers, ch. 4).

``keep_model_path`` has no default: the two settings are two different query
behaviours and the wrong one is silent. ``False`` clears ``model_path``, suppressing
pipeline-core's automatic ``name == model_name`` filter, which **overwrites** a name
the caller supplied rather than narrowing it (C-77). ``True`` keeps it — only the
partner WRITE store wants that, because ``upload_data`` falls back to
``model_path.model_name`` when ``name`` is ``None``. Both measured on the real store
in ``tests/test_store_construction.py``, which is where that reasoning lives.
"""
store = DatastoreModule(appwrite_file_manager_config=config)
if not keep_model_path:
store.model_path = None
return store


def _build_prod_forecasts_store(ensemble_name: str | None) -> DatastoreModule:
"""The shared internal store (ADR-013's "shared shelf"), built from the
launcher-assembled environment (validated fail-loud; þing-01 #134 — no dotenv is
Expand Down Expand Up @@ -72,12 +91,8 @@ def _build_prod_forecasts_store(ensemble_name: str | None) -> DatastoreModule:
database_id=os.getenv("APPWRITE_METADATA_DATABASE_ID"),
database_name=os.getenv("APPWRITE_METADATA_DATABASE_NAME"),
)
datastore = DatastoreModule(appwrite_file_manager_config=appwrite_config)
# Suppress the automatic name==model_name filter (see docstring). model_path is used
# by DatastoreModule only for that injection and for uploads; the contract read
# neither uploads nor performs any model-scoped lookup.
datastore.model_path = None
return datastore
# The contract read neither uploads nor looks anything up by model name.
return _datastore(appwrite_config, keep_model_path=False)


def _build_partner_store(*, config: AppwriteConfig) -> DatastoreModule:
Expand All @@ -86,7 +101,8 @@ def _build_partner_store(*, config: AppwriteConfig) -> DatastoreModule:
Takes the config, not the path manager, so one delivery resolves the audience
connection once and the C-94 read-back verifies what the write used (vpp_018 §3).
"""
return DatastoreModule(appwrite_file_manager_config=config)
# The one store in this package that keeps its model_path; `_datastore` says why.
return _datastore(config, keep_model_path=True)


def _partner_appwrite_config(model_path) -> AppwriteConfig:
Expand Down Expand Up @@ -138,9 +154,7 @@ def _build_partner_read_store(*, config: AppwriteConfig) -> DatastoreModule:
views-models directory name, which equals the declared consumer name only by
coincidence (**C-77**). C-94 records why it reuses the write key.
"""
store = DatastoreModule(appwrite_file_manager_config=config)
store.model_path = None
return store
return _datastore(config, keep_model_path=False)


def _assert_delivery_is_findable(
Expand Down
34 changes: 24 additions & 10 deletions views_postprocessing/unfao/managers/unfao.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@



def _datastore(config: AppwriteConfig, *, keep_model_path: bool) -> DatastoreModule:
"""The ONE place this package constructs a prediction store (#362, epic #359).

*A seam you cannot switch from outside the code is not a seam* (Feathers, ch. 4).

``keep_model_path`` has no default: the two settings are two different query
behaviours and the wrong one is silent. ``False`` clears ``model_path``, suppressing
pipeline-core's automatic ``name == model_name`` filter, which **overwrites** a name
the caller supplied rather than narrowing it (C-77). ``True`` keeps it — only the
partner WRITE store wants that, because ``upload_data`` falls back to
``model_path.model_name`` when ``name`` is ``None``. Both measured on the real store
in ``tests/test_store_construction.py``, which is where that reasoning lives.
"""
store = DatastoreModule(appwrite_file_manager_config=config)
if not keep_model_path:
store.model_path = None
return store


def _build_prod_forecasts_store(ensemble_name: str | None) -> DatastoreModule:
"""The shared internal store (ADR-013's "shared shelf"), built from the
launcher-assembled environment (validated fail-loud; þing-01 #134 — no dotenv is
Expand Down Expand Up @@ -72,12 +91,8 @@ def _build_prod_forecasts_store(ensemble_name: str | None) -> DatastoreModule:
database_id=os.getenv("APPWRITE_METADATA_DATABASE_ID"),
database_name=os.getenv("APPWRITE_METADATA_DATABASE_NAME"),
)
datastore = DatastoreModule(appwrite_file_manager_config=appwrite_config)
# Suppress the automatic name==model_name filter (see docstring). model_path is used
# by DatastoreModule only for that injection and for uploads; the contract read
# neither uploads nor performs any model-scoped lookup.
datastore.model_path = None
return datastore
# The contract read neither uploads nor looks anything up by model name.
return _datastore(appwrite_config, keep_model_path=False)


def _build_partner_store(model_path) -> DatastoreModule:
Expand All @@ -87,7 +102,8 @@ def _build_partner_store(model_path) -> DatastoreModule:
reached for. That is the whole difference between this and a method, and it is what
lets the environment contract be checked without standing up a manager.
"""
return DatastoreModule(appwrite_file_manager_config=_partner_appwrite_config(model_path))
# The one store in this package that keeps its model_path; `_datastore` says why.
return _datastore(_partner_appwrite_config(model_path), keep_model_path=True)


def _partner_appwrite_config(model_path) -> AppwriteConfig:
Expand Down Expand Up @@ -119,9 +135,7 @@ def _build_partner_read_store(model_path) -> DatastoreModule:
views-models directory name, which equals the declared consumer name only by
coincidence (**C-77**). C-94 records why it reuses the write key.
"""
store = DatastoreModule(appwrite_file_manager_config=_partner_appwrite_config(model_path))
store.model_path = None
return store
return _datastore(_partner_appwrite_config(model_path), keep_model_path=False)


def _assert_delivery_is_findable(
Expand Down
Loading