cbpr-validate 1.0.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. cbpr_validate-1.2.0/ARCHITECTURE.md +223 -0
  2. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/BUILD_PLAN.md +18 -2
  3. cbpr_validate-1.2.0/CHANGELOG.md +98 -0
  4. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/CLAUDE.md +17 -1
  5. cbpr_validate-1.2.0/KNOWN_ISSUES.md +94 -0
  6. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/PKG-INFO +84 -10
  7. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/README.md +83 -9
  8. cbpr_validate-1.2.0/add_currencies.py +20 -0
  9. cbpr_validate-1.2.0/iso4217_currencies.json +172 -0
  10. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/pyproject.toml +5 -0
  11. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/__init__.py +1 -1
  12. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/api/main.py +14 -1
  13. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/cli.py +33 -6
  14. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/codesets/data/iso20022_codesets.json +446 -276
  15. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/core.py +156 -132
  16. cbpr_validate-1.2.0/src/cbpr_validate/model/finding.py +67 -0
  17. cbpr_validate-1.2.0/src/cbpr_validate/model/validation_result.py +35 -0
  18. cbpr_validate-1.2.0/src/cbpr_validate/profiles.py +103 -0
  19. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/report/json_report.py +65 -57
  20. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/report/junit_report.py +25 -2
  21. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/report/text_report.py +15 -1
  22. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/rules/address.py +42 -0
  23. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/rules/amounts.py +93 -87
  24. cbpr_validate-1.2.0/src/cbpr_validate/rules/registry.py +82 -0
  25. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/conftest.py +4 -2
  26. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_api.py +7 -2
  27. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_cli.py +29 -9
  28. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_core.py +14 -13
  29. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_interface_parity.py +63 -18
  30. cbpr_validate-1.2.0/tests/test_profiles.py +382 -0
  31. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_report.py +5 -2
  32. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_rules_address.py +2 -1
  33. cbpr_validate-1.0.0/src/cbpr_validate/model/finding.py +0 -21
  34. cbpr_validate-1.0.0/src/cbpr_validate/model/validation_result.py +0 -21
  35. cbpr_validate-1.0.0/src/cbpr_validate/rules/registry.py +0 -58
  36. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/.claude/settings.local.json +0 -0
  37. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/.claude/settings.local.json.tmp.31316.7bec411697e7 +0 -0
  38. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/.github/workflows/ci.yml +0 -0
  39. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/.github/workflows/release.yml +0 -0
  40. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/.gitignore +0 -0
  41. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/api/__init__.py +0 -0
  42. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/codesets/__init__.py +0 -0
  43. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/codesets/loader.py +0 -0
  44. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/config.py +0 -0
  45. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/match/__init__.py +0 -0
  46. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/match/matcher.py +0 -0
  47. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/match/result.py +0 -0
  48. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/model/__init__.py +0 -0
  49. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/model/payment.py +0 -0
  50. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/parsers/__init__.py +0 -0
  51. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/parsers/_common.py +0 -0
  52. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/parsers/detect.py +0 -0
  53. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/parsers/pacs002.py +0 -0
  54. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/parsers/pacs004.py +0 -0
  55. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/parsers/pacs008.py +0 -0
  56. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/parsers/pacs009.py +0 -0
  57. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/parsers/parse.py +0 -0
  58. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/report/__init__.py +0 -0
  59. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/rules/__init__.py +0 -0
  60. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/rules/agents.py +0 -0
  61. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/rules/codes.py +0 -0
  62. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/rules/returns.py +0 -0
  63. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/rules/structural.py +0 -0
  64. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/schema/__init__.py +0 -0
  65. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/src/cbpr_validate/schema/xsd.py +0 -0
  66. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/__init__.py +0 -0
  67. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/fixtures/pacs008_valid_hybrid_ro.xml +0 -0
  68. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_addr004_country_codes.py +0 -0
  69. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_bicfi_agents.py +0 -0
  70. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_cod004_pacs002.py +0 -0
  71. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_golden_valid.py +0 -0
  72. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_match_correlation.py +0 -0
  73. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_misc_coverage.py +0 -0
  74. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_parsers.py +0 -0
  75. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_parsers_edgecases.py +0 -0
  76. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_parsers_phase4.py +0 -0
  77. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_phase3_rules.py +0 -0
  78. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_rules_agents.py +0 -0
  79. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_rules_returns.py +0 -0
  80. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_schema_xsd.py +0 -0
  81. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_smoke.py +0 -0
  82. {cbpr_validate-1.0.0 → cbpr_validate-1.2.0}/tests/test_str003_mandatory_amount.py +0 -0
@@ -0,0 +1,223 @@
1
+ # Architecture
2
+
3
+ <!-- TODO: one or two sentences in your own voice. Suggested seed below — edit freely. -->
4
+ `cbpr-validate` validates ISO 20022 CBPR+ payment messages against the **usage
5
+ guidelines**, not just the XSD schema. This document explains how it is built and
6
+ why the key decisions were made — the schema tells you a message is *well-formed*;
7
+ this tool tells you whether it is *CBPR+-compliant*.
8
+
9
+ ---
10
+
11
+ ## 1. The problem: XSD-valid ≠ CBPR+-compliant
12
+
13
+ <!-- TODO: 3–5 sentences. This is the thesis of the whole project — say it in your own words.
14
+ Points to hit:
15
+ - An XSD checks structure/data types. It passes messages that still violate CBPR+ usage rules.
16
+ - Concrete examples the tool catches that XSD cannot: unstructured-only postal address (invalid under SR2026),
17
+ the pacs.009 COV reimbursement-vs-intermediary agent distinction, cross-message drift between a pacs.004
18
+ return and the pacs.008 it reverses.
19
+ - Why this matters operationally: these gaps are what cause manual repair, reconciliation, and last-mile delay. -->
20
+
21
+ ---
22
+
23
+ ## 2. Design goals
24
+
25
+ <!-- TODO: keep or trim. These are the principles the rest of the doc should visibly follow. -->
26
+ - **Traceable** — every finding carries a stable `rule_id`, a plain-English message, a field location, a
27
+ remediation hint, and a `spec_reference` back to the guideline.
28
+ - **Version-decoupled** — a rule is written once and runs against any supported message version, because rules
29
+ operate on an internal normalized model, not on raw XML.
30
+ - **One core, many interfaces** — library, CLI, and REST API all go through the same parse → validate → report
31
+ path, so they cannot disagree about what a message means.
32
+ - **Honest failure** — "we could not evaluate this message" is never reported as "this message is compliant."
33
+ - **No licensed material in the repo** — SWIFT XSDs and guideline text are never redistributed; rules are
34
+ implemented in code and cite their source.
35
+
36
+ ---
37
+
38
+ ## 3. High-level architecture
39
+
40
+ A layered pipeline. Each stage is independently testable, and the internal model is the seam that decouples
41
+ everything downstream from message-version specifics.
42
+
43
+ ```
44
+ ┌─────────── interfaces ───────────┐
45
+ │ library (core.py) CLI REST API │
46
+ └─────────────────┬─────────────────┘
47
+ │ (one shared core) profile
48
+ │ │
49
+ raw bytes ──► detect ──► parse ──► normalized model ──► rules engine ──► severity ──► findings ──┐
50
+ (namespace) (per type) (Pydantic) correlation override ──► matches ─┤
51
+ (profiles) ▼
52
+ report: text / JSON / JUnit
53
+ ```
54
+
55
+ **The severity-override layer** sits between the rules engine and the reporters,
56
+ inside `rules/registry.run_all()` — the one place every interface reaches the
57
+ rules through. Rules emit their own declared severity and know nothing about
58
+ profiles; `profiles.apply_profile()` then rewrites the severities a profile
59
+ names, keeping the original in `Finding.base_severity`. Because this happens
60
+ before anything reads `ValidationResult.is_compliant`, a profile can change the
61
+ verdict and the exit code without any rule's detection logic changing. See
62
+ §4.3.
63
+
64
+ <!-- TODO: if you draw a nicer diagram later (e.g. a PNG or mermaid), drop it in here. Optional. -->
65
+
66
+ ---
67
+
68
+ ## 4. The layers
69
+
70
+ ### 4.1 Detection & parsing (`parsers/`)
71
+ - `detect.py` identifies the message type by namespace (root element or child of a SWIFT envelope), covering
72
+ `pacs.008 / .009 / .002 / .004`.
73
+ - `parse.py` (`parse_message`) dispatches to the per-type parser; individual parsers
74
+ (`pacs008.py`, `pacs009.py`, `pacs002.py`, `pacs004.py`, shared `_common.py`) turn XML into the model.
75
+ - The pacs.009 COV parser captures the embedded `UndrlygCstmrCdtTrf` as a nested `Payment`, so the COV rule
76
+ and cross-message correlation can reach the underlying transaction.
77
+
78
+ ### 4.2 Internal normalized model (`model/`)
79
+ - Pydantic v2 models — `Payment`, `Party`, `Agent`, `PostalAddress`, `Amount` — version-agnostic by design.
80
+ - `Finding` (with `Severity` = ERROR | WARN | INFO) and `ValidationResult` (`is_compliant`, `errors`,
81
+ `warnings`) are the output units for single-message validation.
82
+ - **This is the key architectural seam:** a `pacs.008.001.08` and its SR2026 variant both normalise to the
83
+ same shape, so every rule is written once. (See ADR-003.)
84
+
85
+ ### 4.3 Rule engine (`rules/`)
86
+ - `registry.py` — decorator-based registration; `run_all()` executes every registered rule against a parsed
87
+ message and aggregates `Finding`s.
88
+ - Rule groups, each a module: `structural.py`, `address.py`, `codes.py`, `amounts.py`, `agents.py`,
89
+ `returns.py`.
90
+ - Rule ID families: `CBPR-STR-*`, `CBPR-ADDR-*`, `CBPR-COD-*`, `CBPR-AMT-*`, `CBPR-AGT-*`, `CBPR-RTN-*`.
91
+ - Headline rule: `CBPR-AGT-002` — the pacs.009 COV reimbursement-vs-intermediary agent distinction.
92
+ - Code-set checks (`codes.py`) validate against a committed, version-stamped snapshot of the ISO 20022
93
+ External Code Sets (`codesets/loader.py` + `codesets/data/`), so validation is reproducible offline.
94
+
95
+ **Severity profiles (`profiles.py`).** `run_all()` takes a keyword-only `profile` and applies it as the last
96
+ step, after every rule has run and before anything reads `is_compliant`. A profile is data — a flat
97
+ `rule_id -> severity` map — not branching inside a rule: `current` reports `CBPR-ADDR-001/002` as WARN
98
+ (what the network accepts today, SR2026 having been deferred with no new date), `sr2026` reports them as
99
+ ERROR. Rules emit their declared severity and never see the profile. An overridden finding keeps the rule's
100
+ severity in `Finding.base_severity`, so `severity != base_severity` identifies an SR2026 readiness gap, and
101
+ `ValidationResult.profile` records which rulebook produced the verdict.
102
+
103
+ This is deliberately the *only* override site. `run_all()` is the single point every interface reaches the
104
+ rules through — the library via `core.py`, the CLI's `check`, and the API's `/validate` — so no front door can
105
+ disagree with another about what a profile means. Applying a profile is idempotent: it compares against
106
+ `base_severity`, not the current severity.
107
+
108
+ ### 4.4 Correlation engine (`match/`)
109
+ - Separate from rules because it evaluates a relationship **between two messages**, not a property of one.
110
+ - `correlate(a, b, direction=None)` infers the scenario from the message-type pair (either argument order):
111
+ - `CBPR-COR-001` pacs.009 COV ↔ originating pacs.008
112
+ - `CBPR-COR-002` pacs.002 ↔ pacs.008 (`direction` **required** — identity is never inferred from BICs)
113
+ - `CBPR-COR-003` pacs.004 return ↔ original pacs.008
114
+ - Primary match key is always **UETR**; `OrgnlTxId` / `OrgnlEndToEndId` are fallbacks only when a UETR is
115
+ absent, and the result flags that fallback. Two UETRs that *disagree* are a real non-match, never a reason
116
+ to try a weaker key.
117
+ - Output is `MatchResult` (distinct from `ValidationResult`; exposes `is_consistent`). (See ADR-005.)
118
+ - **v1 is deliberately pairwise and stateless** — you hand it the two messages to compare; there is no message
119
+ store. (See ADR-004.)
120
+
121
+ ### 4.5 Reporting (`report/`)
122
+ - Three formatters — `text_report.py`, `json_report.py`, `junit_report.py` — all fed from the same result
123
+ objects.
124
+ - Only `ERROR` becomes a JUnit `<failure>`, so a CI build fails exactly when `is_compliant` / `is_consistent`
125
+ is false. All emitted text is ASCII and XML-escaped, so a non-Latin party name or an `&` in a field can
126
+ never corrupt or crash a report.
127
+
128
+ ### 4.6 Optional XSD layer (`schema/xsd.py`)
129
+ - Off by default; enabled by pointing `CBPR_VALIDATE_XSD_DIR` at a **locally licensed** copy of the schemas.
130
+ - No schema is shipped or committed. If the layer is requested but a schema cannot be found, it raises rather
131
+ than returning "clean" — the caller asked for structural validation, so silently skipping it would be a lie.
132
+
133
+ ### 4.7 Interfaces
134
+ - **Library** (`core.py`): `validate_file` / `validate_string` / `validate_bytes`. These **never raise** —
135
+ unreadable, malformed, and unrecognised inputs each return a `ValidationResult` carrying a single
136
+ `ORCH-READ-ERROR` / `ORCH-PARSE-ERROR` / `ORCH-UNSUPPORTED` finding, so a caller has exactly one shape to
137
+ handle. (See ADR-006.)
138
+ - **CLI** (`cli.py`, Typer): `validate`, `check`, `match`, `version`; `--format text|json|junit`,
139
+ `--fail-on error|warn|never`, `--xsd`/`--xsd-dir`, and `--direction` for a pacs.002 pair. Exit codes are a
140
+ stable contract: `0` clean, `1` findings at/above threshold (or a pair that does not correlate), `2`
141
+ unusable input.
142
+ - **REST API** (`api/main.py`, FastAPI): `POST /validate`, `POST /correlate`, `GET /health`, OpenAPI at
143
+ `/docs`. A correlation that fails is a `200` with `is_consistent: false` — a result, not an HTTP error; only
144
+ unusable input is a `400`.
145
+ - Parity is **tested, not asserted** (`tests/test_interface_parity.py`): library, CLI, and API outputs are
146
+ compared across the same messages and correlation scenarios.
147
+
148
+ ---
149
+
150
+ ## 5. Error-handling philosophy
151
+
152
+ <!-- TODO: you can tighten this, but the substance is real and worth stating explicitly — it's a maturity signal. -->
153
+ - **"Cannot evaluate" ≠ "not compliant".** Orchestration failures use an `ORCH-` prefix and are kept distinct
154
+ from usage-guideline violations.
155
+ - **The library core never raises.** Every failure mode returns a `ValidationResult`, so callers integrate one
156
+ contract.
157
+ - **Exit codes are an API.** The CLI's `0 / 1 / 2` contract is what lets the tool act as a CI gate.
158
+
159
+ ---
160
+
161
+ ## 6. Key design decisions (ADRs)
162
+
163
+ <!-- TODO: write these up as short ADRs under docs/adr/ (context → decision → consequences, ~1 page each).
164
+ This section is just the index. The four marked ★ are the ones the build plan told you not to skip. -->
165
+ - **ADR-001 ★** — Rules in code, not a rules DSL.
166
+ - **ADR-002 ★** — Do not ship SWIFT XSDs; cite sources, let users supply their own licensed copy.
167
+ - **ADR-003 ★** — An internal normalized (Pydantic) model to decouple rules from message version.
168
+ - **ADR-004 ★** — Correlation is pairwise/stateless in v1, not a stored ledger.
169
+ - **ADR-005** — `MatchResult` is a distinct type from `ValidationResult` (relationship vs. property).
170
+ - **ADR-006** — The library core never raises; orchestration errors are findings with an `ORCH-` prefix.
171
+ - **ADR-007** — Severity profiles are data applied once in `run_all()`, not conditionals inside rules; `current`
172
+ is the default because SR2026 was deferred with no confirmed date.
173
+ - **ADR-008** — A bad *profile name* raises (CLI exit 2 / API 422) even though a bad *document* does not:
174
+ silently judging against an unintended rulebook is worse than failing loudly.
175
+
176
+ ---
177
+
178
+ ## 7. Extensibility — how to add a rule
179
+
180
+ <!-- TODO: verify the exact function signature against rules/registry.py before publishing. Seed: -->
181
+ 1. Add a function to the relevant `rules/<group>.py`, register it with the registry decorator.
182
+ 2. Return `Finding`s with a stable `rule_id`, a `severity`, a `location`, a `remediation`, and a
183
+ `spec_reference` citing the guideline.
184
+ 3. Add adversarial fixtures (a message that should fire it and one that should not) under `tests/`.
185
+ 4. `run_all()` picks it up automatically — no interface change needed.
186
+
187
+ ---
188
+
189
+ ## 8. Testing strategy
190
+
191
+ - **192 tests, 99% coverage**, `ruff` and `mypy` clean. <!-- TODO: update these numbers when they change. -->
192
+ - **Adversarial fixtures**: every rule has both a clean case and a deliberately broken one (wrong UETR, amount
193
+ drift, currency/party drift, mis-echoed references, missing mandatory fields).
194
+ - **Interface parity tests** guarantee library / CLI / API cannot silently diverge.
195
+ - CI (`.github/workflows/ci.yml`) gates lint, type-check, and tests on every change.
196
+
197
+ ---
198
+
199
+ ## 9. Scope & non-goals (v1)
200
+
201
+ **In scope:** `pacs.008`, `pacs.009` (core + COV), `pacs.002`, `pacs.004`; usage-guideline rules; External
202
+ Code Set checks; pairwise cross-message correlation; text/JSON/JUnit output.
203
+
204
+ **Out of scope (v1):** camt.05x / camt.110-111 (E&I); message *generation*; a stateful message store /
205
+ live-stream correlation; network/transport; redistribution of licensed schemas; proprietary regional schemes.
206
+
207
+ ---
208
+
209
+ ## 10. Performance
210
+
211
+ <!-- TODO: this is the one number you still owe the README/architecture doc. Run a quick benchmark
212
+ (N messages through validate_bytes in a loop, wall-clock) and state throughput here, e.g. "~X messages/sec
213
+ single-threaded on <machine>". It's a small task that signals you thought about scale. -->
214
+ _Benchmark: TODO._
215
+
216
+ ---
217
+
218
+ ## 11. Roadmap (v2)
219
+
220
+ camt.053/054 and camt.110/111 (E&I) · a hosted web playground · a reusable GitHub Action (CI step) · message
221
+ generation (pairs with the agentic project) · pluggable rule packs (HVPS+, regional) · a stateful
222
+ `MessageStore` so messages can be ingested one at a time (`ingest`) and correlations queried later (`query
223
+ --uetr ...`) instead of always pairwise.
@@ -144,8 +144,13 @@ Implement each as a registered rule with a stable ID. Group + severity below. **
144
144
  - `CBPR-STR-004` Settlement method / clearing system consistency — WARN
145
145
 
146
146
  **Address / SR2026 (`address.py`)** — the headline group
147
- - `CBPR-ADDR-001` Unstructured-only address (AdrLine, no TwnNm/Ctry) — ERROR *(invalid after 14 Nov 2026)*
148
- - `CBPR-ADDR-002` Minimum gate: structured TwnNm **and** Ctry present — ERROR if missing
147
+
148
+ > **Severity is profile-dependent as of v1.2.0.** SWIFT deferred the SR2026 payments changes and no new date
149
+ > is confirmed, so `ADDR-001` and `ADDR-002` are **WARN** under the default `current` profile and **ERROR**
150
+ > under `sr2026`. The severities below are the `sr2026` (strict) reading. See `profiles.py`.
151
+
152
+ - `CBPR-ADDR-001` Unstructured-only address (AdrLine, no TwnNm/Ctry) — ERROR under `sr2026`, WARN under `current`
153
+ - `CBPR-ADDR-002` Minimum gate: structured TwnNm **and** Ctry present — ERROR under `sr2026`, WARN under `current`
149
154
  - `CBPR-ADDR-003` Hybrid address line-count within cap *(verify exact cap)* — WARN
150
155
  - `CBPR-ADDR-004` Ctry is ISO 3166-1 alpha-2 — ERROR
151
156
  - `CBPR-ADDR-005` Classify & report: fully-structured / hybrid / unstructured — INFO
@@ -451,6 +456,17 @@ Dockerfile, mkdocs site, README polish, badges, benchmark, TestPyPI → PyPI, ta
451
456
 
452
457
  ---
453
458
 
459
+ ### Post-v1 increments (outside the original phase plan)
460
+
461
+ - **v1.1.0** — `CBPR-ADDR-006` (AdrLine length/count), ISO 4217 currency validation fix, `ARCHITECTURE.md`.
462
+ - **v1.2.0** — **Severity profiles** (`current` / `sr2026`), in response to SWIFT deferring the SR2026
463
+ payments changes. Behaviour change: unstructured addresses are WARN by default. Adds `--profile` to the CLI,
464
+ `profile=` to the library, a `profile` field to `POST /validate`, `Finding.base_severity`, and the profile in
465
+ all three reporters. `--fail-on` now accepts `warn` and `warning` on both commands.
466
+ Deferred work is logged in `KNOWN_ISSUES.md`.
467
+
468
+ ---
469
+
454
470
  ## 11. Senior-signal artifacts (do not skip)
455
471
 
456
472
  These convert "a repo" into "an architect's portfolio":
@@ -0,0 +1,98 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. This project adheres
4
+ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
+
6
+ ## [1.2.0] - 2026-10-12
7
+
8
+ ### Changed — BEHAVIOUR CHANGE, please read
9
+
10
+ **Unstructured postal addresses are now reported as `WARN`, not `ERROR`, by
11
+ default. A message that was `NOT COMPLIANT` in 1.1.0 may now be `COMPLIANT`,
12
+ and a CLI call that exited `1` may now exit `0`.**
13
+
14
+ `CBPR-ADDR-001` (unstructured-only address) and `CBPR-ADDR-002` (TownName and
15
+ Country required) are the two affected rules. Nothing else changed severity.
16
+
17
+ **To restore the previous strict behaviour, select the `sr2026` profile:**
18
+
19
+ ```bash
20
+ cbpr-validate validate payment.xml --profile sr2026 # exits 1, as 1.1.0 did
21
+ ```
22
+
23
+ ```python
24
+ validate_file("payment.xml", profile="sr2026") # is_compliant False, as 1.1.0
25
+ ```
26
+
27
+ ```bash
28
+ curl -d '{"message": "...", "profile": "sr2026"}' localhost:8000/validate
29
+ ```
30
+
31
+ Alternatively keep the default profile and tighten the gate instead, which
32
+ fails the build on the readiness gap while still reporting it as a warning:
33
+
34
+ ```bash
35
+ cbpr-validate validate payment.xml --fail-on warn # exits 1 on a WARN
36
+ ```
37
+
38
+ **Why.** SWIFT deferred every payments change in Standards Release 2026,
39
+ including the removal of fully unstructured postal addresses in CBPR+
40
+ (originally 14 Nov 2026). **A new date has not been confirmed.** The network
41
+ accepts these addresses today, so reporting them as hard errors overstated the
42
+ position: it told users their live, working traffic was non-compliant. They are
43
+ now a visible readiness gap by default, and a rejection only when you ask for
44
+ the future rulebook.
45
+
46
+ ### Added
47
+
48
+ - **Severity profiles.** `current` (the new default) and `sr2026`. A profile is
49
+ a flat `rule_id -> severity` mapping applied once after the rules run; no
50
+ rule's detection logic is profile-aware.
51
+ - CLI: `--profile current|sr2026` on `validate` and `check`.
52
+ - Library: `profile=` on `validate_file`, `validate_string`, `validate_bytes`
53
+ and `rules.registry.run_all`.
54
+ - API: optional `"profile"` field on `POST /validate`.
55
+ - An unknown profile name is an input error: CLI exit `2` (listing the valid
56
+ names), API `422`, `ValueError` from the library.
57
+ - **`Finding.base_severity`** — the severity the rule itself declared, always
58
+ populated. `severity != base_severity` means the active profile moved that
59
+ finding, i.e. it is an SR2026 readiness gap.
60
+ - **`ValidationResult.profile`** records which rulebook produced the verdict,
61
+ and `.overridden` lists the findings the profile moved.
62
+ - The profile is surfaced by every reporter: a `(profile: ...)` suffix on the
63
+ text summary (plus an `N SR2026 address gaps` note when any fired), a
64
+ top-level `"profile"` field in JSON, and a `<property name="profile">` in
65
+ JUnit.
66
+ - `--fail-on` now accepts both `warn` and `warning` on **both** `validate` and
67
+ `check`. Previously `check` accepted only `warn` and `validate` only
68
+ `warning`, and the other spelling exited `2`. Both old spellings still work.
69
+
70
+ ### Notes
71
+
72
+ - JUnit still maps only `ERROR` to `<failure>`, so under the default profile an
73
+ address gap no longer fails a build. Use `--profile sr2026` or
74
+ `--fail-on warn` if you want it to.
75
+ - No new dependencies. No rule's detection logic changed.
76
+
77
+ ## [1.1.0] - 2026-09-27
78
+
79
+ ### Added
80
+
81
+ - `CBPR-ADDR-006` — `AdrLine` length and count validation (`Max70Text`,
82
+ `maxOccurs=7`).
83
+ - `ARCHITECTURE.md`.
84
+
85
+ ### Fixed
86
+
87
+ - `CBPR-AMT-001/002` — currency validated against the full ISO 4217 list, with
88
+ decimal-place checking separated from validity.
89
+
90
+ ## [1.0.0] - 2026-09
91
+
92
+ ### Added
93
+
94
+ - Initial release: version-agnostic payment model; `pacs.008`, `pacs.009`
95
+ (core + COV), `pacs.002` and `pacs.004` parsers; the structural, address,
96
+ code-set, amount, agent and return rule groups; pairwise correlation
97
+ (`CBPR-COR-001/002/003`); the Typer CLI, FastAPI service and text/JSON/JUnit
98
+ reporters; and the optional XSD layer.
@@ -38,6 +38,20 @@ TestPyPI -> PyPI, tag v1.0.0).
38
38
  - `CBPR-ADDR-003` (hybrid line-count cap) is **intentionally unregistered** —
39
39
  the cap is ambiguous in available guideline material and we refuse to guess.
40
40
  Leave it unregistered until the cap is confirmed.
41
+ - **Severity profiles** (v1.2.0): `current` is the DEFAULT and reports
42
+ `CBPR-ADDR-001/002` as WARN; `sr2026` reports them as ERROR. This is because
43
+ SWIFT deferred the SR2026 payments changes with no confirmed new date. Do not
44
+ "fix" the default back to ERROR — a message the network accepts today must
45
+ not be reported as non-compliant. Profiles are data in `profiles.py` applied
46
+ ONCE at the end of `rules/registry.run_all()`; never add profile conditionals
47
+ inside a rule. `sr2026` restates the address severities explicitly rather
48
+ than inheriting them, on purpose.
49
+ - `Finding.base_severity` is **always populated** (defaulted from `severity` by
50
+ a pre-validator, so rules keep passing only `severity=`). It is not optional;
51
+ `severity != base_severity` is the signal that a profile moved a finding.
52
+ - `--fail-on` accepts BOTH `warn` and `warning` on both `validate` and `check`.
53
+ They used to disagree (`check` took `warn`, `validate` took `warning`); both
54
+ spellings now work on both and must keep working.
41
55
  - `CBPR-COD-004` now runs against a real parsed `pacs.002`; the Phase 3
42
56
  direct-construction workaround was removed in Phase 4. Done — don't revisit.
43
57
  - Correlation returns `MatchResult`, **not** `ValidationResult`, and lives
@@ -79,7 +93,9 @@ TestPyPI -> PyPI, tag v1.0.0).
79
93
  Phase 5 ONLY. If you catch yourself cross-referencing two messages or
80
94
  building an interface before then, stop — it's the next phase.
81
95
  7. **Stay in scope for the current phase.** If you find an out-of-scope gap,
82
- log it in `KNOWN_ISSUES.md` rather than expanding scope.
96
+ log it in `KNOWN_ISSUES.md` rather than expanding scope. That file exists as
97
+ of v1.2.0 and already records the batch/folder summary, TOML config
98
+ overrides, the `check`-bypasses-`core` divergence, and `CBPR-ADDR-003`.
83
99
  8. **Definition of done for any phase:** all listed rules implemented AND
84
100
  registered; adversarial tests present; `pytest` green; coverage ≥ 90% on
85
101
  new modules; ruff + mypy clean; README + BUILD_PLAN updated; one commit.
@@ -0,0 +1,94 @@
1
+ # Known issues and deferred work
2
+
3
+ Gaps found while building a phase that were deliberately left out of scope
4
+ rather than silently expanded into it (CLAUDE.md operating rule 7). Each entry
5
+ says what it is, why it was deferred, and what it would take.
6
+
7
+ ---
8
+
9
+ ## 1. No batch / folder readiness summary
10
+
11
+ **What.** There is no way to point the tool at a directory of messages and get
12
+ an aggregate readiness report ("412 messages, 38 with SR2026 address gaps,
13
+ across 6 debtor BICs"). Today you validate one message per invocation and
14
+ aggregate the JSON yourself.
15
+
16
+ **Why deferred.** Out of scope for the severity-profiles change, which is about
17
+ *which rulebook* a single message is judged against. Batch reporting is a
18
+ separate concern with its own design questions — output shape, grouping keys,
19
+ memory behaviour on large folders, partial-failure semantics — and bolting a
20
+ loop onto the CLI would pre-empt those choices badly.
21
+
22
+ **What it would take.** A new `cbpr-validate scan <dir>` command, an aggregate
23
+ result type (counts and groupings, not a concatenated `ValidationResult`), and
24
+ a reporter for it. The per-message path needs no changes.
25
+
26
+ ---
27
+
28
+ ## 2. No TOML config overrides
29
+
30
+ **What.** Profiles are the only way to change a severity, and the profile table
31
+ is in code (`src/cbpr_validate/profiles.py`). A bank cannot supply its own
32
+ `cbpr-validate.toml` declaring, say, that `CBPR-RTN-004` is an ERROR in their
33
+ environment.
34
+
35
+ **Why deferred.** Deliberate for now. A committed profile table is auditable
36
+ and reproducible: a finding's severity is a property of the released version,
37
+ not of whatever file happened to be on the machine. User-supplied overrides
38
+ need answers on precedence, validation of unknown rule IDs, and provenance in
39
+ the report (a result would have to record *which* config produced it) before
40
+ they are safe to add.
41
+
42
+ **What it would take.** A loader producing the same `rule_id -> severity`
43
+ mapping shape `profiles.py` already uses, layered over the selected profile,
44
+ plus provenance recorded on `ValidationResult` so a report can say where a
45
+ severity came from. The override mechanism itself would not change.
46
+
47
+ ---
48
+
49
+ ## 3. `check` bypasses `core`, so there are two roads to the rules
50
+
51
+ **What.** The documented design is "one shared core", but two different paths
52
+ exist:
53
+
54
+ | | Road A | Road B |
55
+ | --- | --- | --- |
56
+ | Used by | library `validate_*`, CLI `validate` | CLI `check`, API `POST /validate` |
57
+ | Entry | `core.validate_bytes` | caller reads and parses for itself |
58
+ | Bad input | an `ORCH-*` ERROR finding, never raises | CLI exit 2 / HTTP 400 |
59
+
60
+ So `check` and the API do not get `core`'s no-raise orchestration contract, and
61
+ error handling for an unreadable or unrecognised document differs between
62
+ `validate` and `check`.
63
+
64
+ **Why deferred.** Unifying them is a refactor of the CLI and API error paths
65
+ with its own behaviour changes (exit codes and HTTP statuses would move for
66
+ malformed input), and it is unrelated to severity profiles. It was safe to
67
+ leave alone here because the profile override lives in
68
+ `rules.registry.run_all()` — the one function *both* roads pass through — so
69
+ every interface already agrees on what a profile means.
70
+
71
+ **Guard in place.** `tests/test_interface_parity.py::test_check_and_validate_agree_on_the_verdict`
72
+ pins that `check` and `validate` return the same verdict and the same JSON for
73
+ the same profile, so the divergence cannot quietly widen while it remains.
74
+
75
+ **What it would take.** Route `check` and the API through `core.validate_bytes`,
76
+ then decide deliberately whether a malformed document should be an `ORCH-*`
77
+ finding (exit 1) or an input error (exit 2) — and change the documented exit-code
78
+ contract to match whichever is chosen.
79
+
80
+ ---
81
+
82
+ ## 4. `CBPR-ADDR-003` is unregistered
83
+
84
+ **What.** The hybrid-address line-count cap is implemented nowhere; the rule ID
85
+ is reserved and the function is not registered.
86
+
87
+ **Why deferred.** The cap value is ambiguous in the public CBPR+ guideline
88
+ material available, and guessing a threshold would produce confident-looking
89
+ wrong findings (CLAUDE.md operating rule 3). Note this is distinct from
90
+ `CBPR-ADDR-006`, which enforces the two caps that *are* unambiguous because
91
+ they come from the ISO 20022 schema itself (`Max70Text`, `maxOccurs=7`).
92
+
93
+ **What it would take.** Confirmation of the cap from the usage guidelines, then
94
+ a registered rule plus a passing and an adversarial fixture.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: cbpr-validate
3
- Version: 1.0.0
3
+ Version: 1.2.0
4
4
  Summary: Validate ISO 20022 CBPR+ payment messages against the usage guidelines, not just the XSD.
5
5
  Author: Tarun Pandya
6
6
  Requires-Python: >=3.11
@@ -33,11 +33,27 @@ cbpr-validate validate payment.xml
33
33
  ```text
34
34
  CBPR-ADDR-005 | INFO | Address classification for Dbtr: structured | Dbtr.PstlAdr
35
35
  CBPR-ADDR-005 | INFO | Address classification for Cdtr: unstructured | Cdtr.PstlAdr
36
+ CBPR-ADDR-001 | WARN | Unstructured-only address (AdrLine without TwnNm/Ctry) | Cdtr.PstlAdr
37
+ CBPR-ADDR-002 | WARN | Minimum gate: TownName and Country must be present | Cdtr.PstlAdr
38
+ 4 finding(s): 0 error, 2 warn, 2 info - COMPLIANT (profile: current) - 2 SR2026 address gaps
39
+ ```
40
+
41
+ That unstructured address is a **WARN**, not an error, because the default
42
+ `current` profile describes what the network accepts today. Ask the same
43
+ question against the strict future rulebook and the verdict flips:
44
+
45
+ ```bash
46
+ cbpr-validate validate payment.xml --profile sr2026
47
+ ```
48
+
49
+ ```text
36
50
  CBPR-ADDR-001 | ERROR | Unstructured-only address (AdrLine without TwnNm/Ctry) | Cdtr.PstlAdr
37
51
  CBPR-ADDR-002 | ERROR | Minimum gate: TownName and Country must be present | Cdtr.PstlAdr
38
- 4 finding(s): 2 error, 0 warn, 2 info - NOT COMPLIANT
52
+ 4 finding(s): 2 error, 0 warn, 2 info - NOT COMPLIANT (profile: sr2026)
39
53
  ```
40
54
 
55
+ See [Profiles](#profiles) for why there are two answers.
56
+
41
57
  Exit code is `0` when clean and `1` when anything at or above the `--fail-on`
42
58
  threshold fires (default `error`), so it drops straight into a pipeline. Add
43
59
  `--json` for machine-readable output.
@@ -48,14 +64,65 @@ From Python, one call does the same thing:
48
64
  from cbpr_validate import validate_file
49
65
 
50
66
  result = validate_file("payment.xml")
51
- result.is_compliant # False
52
- [f.rule_id for f in result.errors]
67
+ result.is_compliant # True under the default 'current' profile
68
+ [f.rule_id for f in result.warnings]
69
+
70
+ strict = validate_file("payment.xml", profile="sr2026")
71
+ strict.is_compliant # False
72
+ [f.rule_id for f in strict.errors]
53
73
  ```
54
74
 
55
75
  `validate_file`, `validate_string` and `validate_bytes` never raise: an
56
76
  unreadable, malformed or unrecognised document comes back as a result carrying a
57
77
  single `ORCH-*` ERROR finding, so there is one shape to handle.
58
78
 
79
+ ## Profiles
80
+
81
+ SWIFT **deferred every payments change in Standards Release 2026**, including
82
+ the removal of fully unstructured postal addresses in CBPR+ (originally 14 Nov
83
+ 2026). **A new date has not been confirmed.** So there are two honest answers
84
+ about an unstructured address, and which one you want depends on the question
85
+ you are asking:
86
+
87
+ | Profile | `CBPR-ADDR-001` / `CBPR-ADDR-002` | Use it to ask |
88
+ | --- | --- | --- |
89
+ | `current` (default) | **WARN** - message can still be compliant | "would the network accept this today?" |
90
+ | `sr2026` | **ERROR** - message is not compliant | "will this still work once the strict rules land?" |
91
+
92
+ Every other rule keeps its severity in both profiles. A profile is a flat
93
+ `rule_id -> severity` mapping, applied once after the rules have run; no rule's
94
+ detection logic is profile-aware.
95
+
96
+ ```bash
97
+ cbpr-validate validate payment.xml # current (default)
98
+ cbpr-validate validate payment.xml --profile sr2026 # strict
99
+ cbpr-validate check payment.xml --profile sr2026 --format junit
100
+ ```
101
+
102
+ Readiness gaps stay visible without breaking today's builds, and a team that
103
+ wants to block on them now still can:
104
+
105
+ ```bash
106
+ cbpr-validate validate payment.xml --fail-on warn # exit 1 on a WARN
107
+ ```
108
+
109
+ Every finding carries both severities, so a report can explain the difference
110
+ rather than just asserting it:
111
+
112
+ ```json
113
+ {
114
+ "rule_id": "CBPR-ADDR-001",
115
+ "severity": "WARN",
116
+ "base_severity": "ERROR"
117
+ }
118
+ ```
119
+
120
+ `severity != base_severity` means the active profile moved that finding - i.e.
121
+ it is an SR2026 readiness gap. The profile is reported everywhere: a
122
+ `(profile: ...)` suffix in text, a top-level `"profile"` field in JSON, and a
123
+ `<property name="profile">` in JUnit. An unknown profile name is an input
124
+ error: exit `2` from the CLI, `422` from the API.
125
+
59
126
  ## Status
60
127
 
61
128
  Phase 5 is now implemented and verified. On top of the Phase 0–4.5 foundation
@@ -122,11 +189,13 @@ and fails if they ever diverge.
122
189
  cbpr-validate validate message.xml # single-file front door
123
190
  cbpr-validate validate message.xml --json
124
191
  cbpr-validate validate message.xml --fail-on warning
192
+ cbpr-validate validate message.xml --profile sr2026 # strict SR2026 rulebook
125
193
 
126
194
  cbpr-validate check message.xml # human-readable
127
195
  cbpr-validate check message.xml --format json # machine-readable
128
196
  cbpr-validate check message.xml --format junit # CI gate
129
197
  cbpr-validate check message.xml --fail-on warn # tighten the gate
198
+ cbpr-validate check message.xml --profile sr2026 # strict SR2026 rulebook
130
199
  cbpr-validate check message.xml --xsd --xsd-dir ./schemas
131
200
 
132
201
  cbpr-validate match pacs009.xml pacs008.xml
@@ -138,9 +207,12 @@ cbpr-validate match pacs004.xml pacs008.xml
138
207
  the fuller command that adds `--format junit` and the optional `--xsd` pass, and
139
208
  `match` correlates two messages.
140
209
 
210
+ Both commands take `--profile`, and both accept `warn` and `warning` as the
211
+ `--fail-on` threshold.
212
+
141
213
  Exit codes are part of the contract: `0` clean, `1` findings at or above the
142
214
  `--fail-on` threshold (or the two messages do not correlate), `2` the input
143
- could not be used. Only `ERROR` findings become JUnit `<failure>` elements, so a
215
+ could not be used (including an unknown `--profile`). Only `ERROR` findings become JUnit `<failure>` elements, so a
144
216
  build fails exactly when the message is non-compliant.
145
217
 
146
218
  ### API
@@ -149,13 +221,14 @@ build fails exactly when the message is non-compliant.
149
221
  uvicorn cbpr_validate.api.main:app --reload
150
222
  ```
151
223
 
152
- `POST /validate` runs every rule against one message; `POST /correlate` takes two
153
- messages plus an optional `direction`. OpenAPI docs are served at `/docs`.
224
+ `POST /validate` runs every rule against one message and takes an optional
225
+ `profile`; `POST /correlate` takes two messages plus an optional `direction`.
226
+ OpenAPI docs are served at `/docs`.
154
227
 
155
228
  ```bash
156
229
  curl -X POST localhost:8000/validate \
157
230
  -H 'content-type: application/json' \
158
- -d '{"message": "<Document ...>"}'
231
+ -d '{"message": "<Document ...>", "profile": "sr2026"}'
159
232
  ```
160
233
 
161
234
  ### Library
@@ -164,8 +237,9 @@ curl -X POST localhost:8000/validate \
164
237
  from cbpr_validate.parsers.parse import parse_message
165
238
  from cbpr_validate.rules.registry import run_all
166
239
 
167
- result = run_all(parse_message(xml_bytes))
240
+ result = run_all(parse_message(xml_bytes), profile="sr2026")
168
241
  result.is_compliant, result.errors, result.warnings
242
+ result.profile, result.overridden # which rulebook, and the gaps it moved
169
243
  ```
170
244
 
171
245
  ## The optional XSD layer
@@ -184,7 +258,7 @@ guidelines are the bar.
184
258
  | Group | Rules |
185
259
  | --- | --- |
186
260
  | Structural | `CBPR-STR-001..004` |
187
- | Address (SR2026) | `CBPR-ADDR-001/002/004/005` (`ADDR-003` intentionally unregistered) |
261
+ | Address (SR2026) | `CBPR-ADDR-001/002/004/005/006` (`ADDR-003` intentionally unregistered). Severity of `ADDR-001/002` is **profile-dependent** - see [Profiles](#profiles) |
188
262
  | Codes | `CBPR-COD-001..004` |
189
263
  | Amounts | `CBPR-AMT-001..003` |
190
264
  | Agents / COV | `CBPR-AGT-001` (WARN), `CBPR-AGT-002` (ERROR), `CBPR-AGT-003` (INFO) |