Skip to content

Let module callers pass in-memory mapping rules to Set#32

Merged
marcleblanc2 merged 1 commit into
mainfrom
in-memory-mapping-rules
Jun 12, 2026
Merged

Let module callers pass in-memory mapping rules to Set#32
marcleblanc2 merged 1 commit into
mainfrom
in-memory-mapping-rules

Conversation

@marcleblanc2

Copy link
Copy Markdown
Collaborator

Completes dev/PLAN.md Track A Phase A4 (the one piece deferred from #31).

What

src.Set(config, mapping_rules=[...]) runs permission sync from parsed rules with no maps YAML file. Combined with GetResult data and no_files=True, the full get -> assemble -> dry-run loop never touches disk.

Guarantees

  • In-memory rules pass through the same structural validation as file-loaded rules, at the edge, before any network or path resolution
  • With files enabled, the rules actually used are serialized into the run directory as the maps.yaml audit copy - a stale customer maps file is never copied
  • Reversibility invariant unchanged: snapshots still gate apply; no_files + apply keeps requiring no_backup
  • Module-mode diagnostics: swallowed SystemExit messages now surface through the package logger so host applications can see why a run failed
  • MappingRule exported for caller typing

Tests

  • Rules resolution/validation matrix (file fallback, decoy-file ignored, no file needed, empty rules, invalid structures rejected)
  • Audit serializer round-trip through the standard loader
  • e2e parity: file vs in-memory vs in-memory+no_files produce identical mutations and end state on both dry-run and apply fixture cases; audit copy content equals the rules used; invalid rules fail fast with zero mutations
  • Module-API: falsy results without exceptions, diagnostic on the package logger, no maps file needed (proven via HTTP-attempt counters on the run-end event)

Verification

  • uv run tests/run.py - 102/102
  • uv run tests/run.py --live - 120/120 against the sgdev test instance
  • pyright strict 0 errors, ruff + markdownlint clean

Completes dev/PLAN.md Track A Phase A4: Set(config, mapping_rules=[...])
runs permission sync from parsed rules with no maps YAML file, so the
full get -> assemble -> dry-run loop never touches disk under no_files.

- In-memory rules go through the same structural validation as
  file-loaded rules (validate_mapping_rules), at the edge before any
  network or path resolution
- With files enabled, the rules actually used are serialized into the
  run directory as the maps.yaml audit copy, keeping the audit trail
  faithful (a stale customer maps file is never copied)
- Snapshots still gate apply: no_files + apply keeps requiring
  no_backup; reversibility invariant unchanged
- MappingRule exported from the package for caller typing
- Module-mode diagnostics: swallowed SystemExit messages now surface
  through the package logger so host applications can see why a run
  failed

Tests: rules resolution/validation unit matrix; audit serializer
round-trip; e2e parity (file vs in-memory vs in-memory+no_files produce
identical mutations and instance state on dry-run and apply fixtures);
audit-copy content equality; invalid-rules fail-fast with zero
mutations; module-API falsy-result and logger-diagnostic guarantees.

Verification: tests/run.py 102/102 fast, 120/120 --live against the
sgdev test instance.

Amp-Thread-ID: https://ampcode.com/threads/T-019eba67-c19d-7166-9690-dcb2f0eed165
Co-authored-by: Amp <amp@ampcode.com>
@marcleblanc2 marcleblanc2 merged commit 7662c50 into main Jun 12, 2026
6 checks passed
@marcleblanc2 marcleblanc2 deleted the in-memory-mapping-rules branch June 12, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant