feat(stores): pluggable per-artifact backends via typing.Protocol - #396
Open
mlieberman85 wants to merge 2 commits into
Open
feat(stores): pluggable per-artifact backends via typing.Protocol#396mlieberman85 wants to merge 2 commits into
mlieberman85 wants to merge 2 commits into
Conversation
Adds `darnit.stores` sub-package with four @runtime_checkable Protocols
(ProjectStateStore, AttestationStore, ReportStore, AuditCacheStore),
filesystem-default backends shipped in darnit-core, and
entry-point-based discovery so third-party packages can distribute
alternative backends without patching darnit.
Motivation: darnit-core is filesystem-only by design (constitution I),
but downstream users need to point specific artifact classes at other
targets (project state to a shared Postgres, attestations to S3, etc.)
without forking. This lays the seam without changing zero-config
behavior: with no [stores.*] block in .baseline.toml, every artifact
class continues to land on the same filesystem paths as before.
Key mechanics:
* `resolve_stores` validates selections eagerly (SC-007) via a
class-shape Protocol check but defers construction to first access
(SC-004). A backend whose kind the run never touches is never
instantiated.
* Backends are discovered via importlib.metadata under four groups:
darnit.stores.{project,attestation,report,cache}. Discovery is
cached per-process.
* `.baseline.toml` composes over the framework TOML using the same
per-kind replacement rule as feature 031's mcp_servers.
* No new runtime dependencies. No product-package modifications
outside darnit-core / darnit-baseline / darnit-testchecks.
Migrations:
* Attestation generator gains an optional `attestation_store` kwarg;
legacy `output_path` filesystem path stays default for backward
compat.
* DotProjectReader + DotProjectMapper accept an optional
ProjectStateStore; unset -> pre-feature filesystem read.
* Audit driver calls resolve_stores + close_all around each run.
Deferred to follow-up features (documented in tasks.md): audit-cache
module migration (T026), DotProjectWriter refactor (T022), and the
report-store integration (blocked on darnitdevorg#341's report consumer). All
follow the surface established here.
Tests: 30 protocol/discovery/selection tests, 7 US1 (equivalence +
isolation + lazy), 6 US2 (zero-config + backward-compat), 5 US3
(discovery + selection + errors), 6 US4 (fault injection), 2
import-isolation guards (SC-008 + FR-017). Full workspace sweep:
2928 pass, 0 fail.
Includes plugin-author docs at docs/plugin-authoring/stores.md.
Was created after the per-file ruff pass and slipped through. No behavior change.
mlieberman85
force-pushed
the
033-pluggable-stores
branch
from
August 26, 2026 14:31
d5ee81d to
c4b5aa7
Compare
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
Introduces
darnit.stores-- four per-artifacttyping.Protocols(
ProjectStateStore,AttestationStore,ReportStore,AuditCacheStore) plus filesystem-default backends shipped indarnit-core. Third-party packages register alternatives via
importlib.metadataentry points underdarnit.stores.{project,attestation,report,cache}.Motivation (see spec.md User
Stories 1-4): darnit-core stays filesystem-only per constitution I,
but downstream users need to point specific artifact classes at
alternative targets (project state to shared Postgres, attestations to
S3, ...) without forking. This lays the seam without touching
zero-config behavior.
Key mechanics
resolve_storesvalidates selections eagerly (SC-007) via aclass-shape Protocol check but defers construction to first access
(SC-004). A backend whose kind the run never touches is never
instantiated.
close_all()runs at audit-boundary teardown, onlyfor stores actually accessed.
StoreNameCollision; broken entry-points are logged and skipped..baseline.tomlcomposes over the framework TOML usingper-kind replacement (mirrors feature 031's
mcp_servers).$VARsubstitution helper factored todarnit.core.env_substandreused by feature 025 exec / 031 MCP paths.
outside
darnit-core,darnit-baseline,darnit-testchecks.Migrations
attestation_storekwarg;legacy
output_pathfilesystem path is the default.DotProjectReader+DotProjectMapperaccept an optionalProjectStateStore; unset means pre-feature filesystem read(backward-compat locked by
test_backward_compat.py).resolve_stores+close_allaround eachaudit run.
Deferred (documented in tasks.md)
(system-tempdir + repo hash) need a separate design conversation.
DotProjectWriterrefactor -- read seam is what US1 needs;write seam lands with T029's control-side integration.
compat means they still pass unchanged.
report-store -- blocked on control-side integration / darnit audit cannot emit SARIF or Markdown from the CLI #341.
All follow the surface established in this PR.
Test plan
-- SC-002 + SC-004)
shapes)
uv run ruff check .clean on touched filesuv run python scripts/validate_sync.py --verbosecleangit diff main..HEAD -- pyproject.toml packages/*/pyproject.tomladds no new
[project.dependencies]entry (FR-014)Plugin author guide at
docs/plugin-authoring/stores.mdincludes aworked S3-backed
AttestationStoreexample.