Skip to content

Refactor logging and files#31

Merged
marcleblanc2 merged 2 commits into
mainfrom
refactor-logging-and-files
Jun 12, 2026
Merged

Refactor logging and files#31
marcleblanc2 merged 2 commits into
mainfrom
refactor-logging-and-files

Conversation

@marcleblanc2

Copy link
Copy Markdown
Collaborator

No description provided.

marcleblanc2 and others added 2 commits June 12, 2026 03:03
…lt objects

Implements dev/PLAN.md Track A (file handling) and Track B consumer wiring
(B5), against src-py-lib v0.3.0.

- shared/backups.py: frozen RunPaths resolved once per run
  (resolve_run_paths); absolute paths, exclusive run-directory creation
  with collision suffixes; artifact_path() family naming; the path
  ContextVars and cwd fallbacks are gone
- New flags: --artifacts-dir (root of the artifacts tree, default
  unchanged) and --no-files (write nothing; with --apply also requires
  --no-backup so giving up restore is stated explicitly twice)
- get now accepts --maps-path (symmetric with set)
- Org-sync snapshots renamed to saml-organizations-{before,after,diff}.json
  so combined set --sync-saml-orgs runs cannot collide with permission
  snapshots
- Module API: Get/Set/Restore/SyncSamlOrgs return result dataclasses
  (GetResult carries the auth provider and code host dicts in memory);
  optional event_sink receives structured wide events; module mode never
  touches stdlib logging handlers (CLI mode is selected by main() only)
- log.json is now OTel Logs Data Model JSONL via src-py-lib EventSink
- Tests: RunPaths unit coverage incl. path-escape safety, --no-files
  rejection matrix, module-mode isolation tests, no-files dry-run parity
  with files-enabled, fixture harness routed through temp artifact dirs

Verification: tests/run.py 102/102 fast, 120/120 --live against the
sgdev test instance (apply + restore cycles with GraphQL read-back,
wheel install smoke against PyPI src-py-lib 0.3.0)

Amp-Thread-ID: https://ampcode.com/threads/T-019eba67-c19d-7166-9690-dcb2f0eed165
Co-authored-by: Amp <amp@ampcode.com>
@marcleblanc2 marcleblanc2 merged commit cefc83a into main Jun 12, 2026
6 checks passed
@marcleblanc2 marcleblanc2 deleted the refactor-logging-and-files branch June 12, 2026 10:08
marcleblanc2 added a commit that referenced this pull request Jun 12, 2026
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

Co-authored-by: Amp <amp@ampcode.com>
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