climate_ref_core.regression
#
Regression-baseline primitives for diagnostic test cases.
This package holds the building blocks for the two-bundle regression model, where we capture and commit a small, sanitised committed bundle of artefacts for a test case. These committed bundles are tracked in git and form the regression baseline for the test case.
We also snapshot the native files persisted by the execution. These files are typically large and not always portable, so we keep them out of git and refer to them by their sha256 digest in the committed bundle. These data will be able to be fetched from an object store in CI and replayed locally for debugging.
COMMITTED_BUNDLE_FILES = ('series.json', 'diagnostic.json', 'output.json')
module-attribute
#
The committed CMEC artefacts tracked in git.
Their digests are tracked in :attr:Manifest.committed.
SCHEMA_VERSION = 1
module-attribute
#
Current manifest schema version.
Action
#
Bases: Enum
The verification action the CI gate selects for a single test case.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/gate.py
EXECUTE = 'execute'
class-attribute
instance-attribute
#
Re-run the diagnostic end-to-end and compare to the committed bundle.
FAIL = 'fail'
class-attribute
instance-attribute
#
The change is not permissible (unauthorised baseline change or bad version).
REPLAY = 'replay'
class-attribute
instance-attribute
#
Replay the cached native baseline and compare to the committed bundle.
SKIP = 'skip'
class-attribute
instance-attribute
#
Nothing relevant changed, or the case is not under regression management.
GateDecision
#
The gate's decision for one test case: an :class:Action and why.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/gate.py
LocalFilesystemStore
#
Content-addressed blob store backed by a local filesystem directory.
Intended for tests and development. Supports both read and write without credentials.
Blobs are stored under root using a two-level layout::
<root>/<digest[:2]>/<digest>
This mirrors the git object-store convention, keeping individual subdirectories manageable for large collections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Root directory for the content-addressed store. Created on first write if it does not exist. |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
fetch(digest, dest)
#
Copy the blob to dest and verify its sha256 matches digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob to fetch. |
required |
dest
|
Path
|
Destination path to write the blob to. Parent directories are created if they do not exist. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the blob is not present in the store. |
ValueError
|
If the blob's sha256 does not match |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
has(digest)
#
Return True if the blob is present on disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
preflight()
#
Verify the store root exists (creating it if needed) and is writable.
Raises:
| Type | Description |
|---|---|
NativeStoreUnavailableError
|
If the root cannot be created or is not writable. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
put(path)
#
Store the file at path in the content-addressed store.
Computes the sha256 digest, copies the file to its canonical location, and returns the digest. If a blob with the same digest already exists, the copy is skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the file to store. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The sha256 hex digest of the stored blob. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
Manifest
#
The on-disk manifest for a test case regression bundle.
Serialised as manifest.json with stable key ordering and a trailing newline,
so repeated dumps are byte-identical.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
catalog_hash = None
class-attribute
instance-attribute
#
Hash of the test case input catalog.yaml (its _metadata.hash) that produced this baseline.
This couples the baseline to its inputs.
The CI gate fails a case whose live catalog hash no longer matches this value.
committed
instance-attribute
#
Digests of committed regression JSON artefacts: {relpath: sha256}.
native
instance-attribute
#
Digests of curated native output files: {relpath: NativeEntry}.
schema
instance-attribute
#
Manifest schema version; equals :data:SCHEMA_VERSION for current manifests.
test_case_version
instance-attribute
#
Monotonic, author-bumped version coupling the bundle to its native outputs.
dump(path)
#
Write the manifest to manifest.json.
Keys are stably ordered (sort_keys=True) and a trailing newline is added,
so dump followed by load round-trips byte-identically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to write the manifest to. |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
load(path)
classmethod
#
Load a manifest from manifest.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the manifest file. |
required |
Returns:
| Type | Description |
|---|---|
Manifest
|
The parsed manifest. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the manifest is missing required keys or has malformed native entries (e.g. hand-edited or written by an incompatible version). |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
loads(text, *, source='<string>')
classmethod
#
Parse a manifest from its JSON text.
Used when the manifest does not live on disk at parse time,
e.g. when reading the base-branch copy via git show for the CI coupling gate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The manifest JSON. |
required |
source
|
str
|
A label for the text's origin, used in error messages. |
'<string>'
|
Returns:
| Type | Description |
|---|---|
Manifest
|
The parsed manifest. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the manifest is missing required keys or has malformed native entries (e.g. hand-edited or written by an incompatible version). |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
seed_v1(committed_digests, catalog_hash=None)
classmethod
#
Create an initial manifest at test_case_version == 1 with no native outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
committed_digests
|
dict[str, str]
|
Digests of the committed regression JSON artefacts. |
required |
catalog_hash
|
str | None
|
Hash of the input |
None
|
Returns:
| Type | Description |
|---|---|
Manifest
|
A fresh manifest with |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
NativeEntry
#
A single curated native output file recorded in the manifest.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
NativeStore
#
Bases: Protocol
Protocol for a content-addressed native-bundle blob store.
Blobs are keyed by their sha256 hex digest.
Read operations (has, fetch) are anonymous and credential-free.
put requires write credentials and raises :class:NotImplementedError on read-only implementations.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
fetch(digest, dest)
#
Fetch the blob identified by digest and write it to dest.
The sha256 of the written file is verified to equal digest.
Raises :class:ValueError on hash mismatch and
:class:FileNotFoundError if the blob is not found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob to fetch. |
required |
dest
|
Path
|
Destination path to write the blob to. Parent directories are created if they do not exist. |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
has(digest)
#
Return True if the blob identified by digest is available in the store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
preflight()
#
Verify the store is reachable and usable before relying on it.
For writable stores this checks the credentials and target (bucket, or that the local
directory is writable); for anonymous read-only stores it may be a no-op. Intended to
be called once up front (e.g. before a slow mint run) so a misconfiguration is
caught early.
Raises:
| Type | Description |
|---|---|
NativeStoreUnavailableError
|
If the store cannot be reached or used, with an operator-facing message. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
put(path)
#
Store the file at path and return its sha256 hex digest.
Requires write credentials.
Read-only implementations raise :class:NotImplementedError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the file to store. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The sha256 hex digest of the stored blob. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
NativeStoreUnavailableError
#
Bases: RuntimeError
Raised when a native store cannot be reached or used.
Covers rejected credentials, a missing bucket, or an unwritable local directory. The message is operator-facing and actionable (it names the env vars / path to check), so callers can surface it directly.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
PoochReadStore
#
Anonymous public-read blob store backed by a remote URL.
Uses :mod:pooch for caching, retry, and hash verification,
mirroring the pattern in :mod:climate_ref_core.dataset_registry.
Blobs are fetched from {base_url}/{digest} and cached under cache_dir.
put is intentionally unsupported; minting uses the write backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
Base URL from which blobs are served (no trailing slash).
Example: |
required | |
cache_dir
|
Local directory used by pooch to cache downloaded blobs. |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
fetch(digest, dest)
#
Download the blob from {base_url}/{digest} and write it to dest.
Uses pooch for caching and retry.
Verifies the sha256 of the downloaded file against digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob to fetch. |
required |
dest
|
Path
|
Destination path to write the blob to. Parent directories are created if they do not exist. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the downloaded blob's sha256 does not match |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
has(digest)
#
Return True if the blob is already in the local pooch cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
preflight()
#
No-op: an anonymous public-read store has nothing to verify up front.
It has no credentials, and every read is hash-checked per blob; this exists only to
satisfy the :class:NativeStore protocol.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
put(path)
#
Not supported on this read-only store.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always; minting uses the write backend, not the read store. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
R2WriteStore
#
Credentialed S3-compatible write backend for a Cloudflare R2 bucket.
Used by the mint verb to upload native blobs. Reads in CI and for local replay go
through :class:PoochReadStore against the public read URL, so this store's fetch /
has exist mainly for mint-time idempotence and verification.
Blobs are content-addressed with a flat key layout (object key == key_prefix +
digest), so a blob is served at {public_url}/{key_prefix}{digest}. The public read
domain is expected to map to the bucket root, so key_prefix defaults to "".
boto3 is imported lazily (see :func:_s3_client); constructing this store does not
require boto3, only the endpoint and bucket. Credentials are passed in explicitly and
are never sourced from the persisted config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint_url
|
S3 API endpoint for the bucket's account, without the bucket
(e.g. |
required | |
bucket
|
Name of the R2 bucket (e.g. |
required | |
access_key_id
|
R2 access-key id, or |
required | |
secret_access_key
|
R2 secret-access-key, or |
required | |
profile
|
Named AWS/R2 profile to authenticate with, or |
required | |
key_prefix
|
Optional object-key prefix. Defaults to |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
__attrs_post_init__()
#
Fail fast at construction (mint startup) when routing config is missing.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
fetch(digest, dest)
#
Download the blob to dest and verify its sha256 matches digest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob to fetch. |
required |
dest
|
Path
|
Destination path to write the blob to. Parent directories are created if they do not exist. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the blob is not present in the bucket. |
ValueError
|
If the downloaded blob's sha256 does not match |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
has(digest)
#
Return True if the blob is present in the bucket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
digest
|
str
|
The sha256 hex digest of the blob. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
preflight()
#
Verify the bucket is reachable and the credentials are accepted, before any upload.
Performs a cheap authenticated HEAD on a sentinel key (expected to be absent). A
404 means the request authenticated and the store is usable; 401 / 403 are
translated into actionable :class:NativeStoreUnavailableError messages so a
misconfigured credential is caught before the (slow) diagnostic run rather than after.
head_object is used rather than head_bucket so the check works with
least-privilege, object-scoped tokens (which cannot perform bucket-level operations).
Raises:
| Type | Description |
|---|---|
NativeStoreUnavailableError
|
If the credentials are rejected (401), access is denied (403), or the probe otherwise fails. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
put(path)
#
Upload the file at path to the bucket and return its sha256 hex digest.
The blob is content-addressed: the upload is skipped when an object with the same digest already exists, so minting is idempotent and re-mints are cheap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the file to store. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The sha256 hex digest of the stored blob. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
Tolerance
#
Float comparison tolerance for bundle regression checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rtol
|
Relative tolerance — the allowed proportional difference between expected
and actual float values (default |
required | |
atol
|
Absolute tolerance — the floor difference always permitted,
regardless of magnitude (default |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/compare.py
assert_bundle_regression(expected_path, actual_path, *, slug, tol=Tolerance(), replacements)
#
Assert that a regenerated committed-bundle JSON file matches the committed copy.
Algorithm:
- Byte-equal fast path — if the raw bytes of both files are identical, return immediately.
- Parse both files as JSON.
- Rewrite both dict keys and leaf string values in the regenerated
(
actual) document usingreplacements, applied longest-key-first so that a shorter placeholder cannot pre-empt a longer overlapping one. - Call :func:
compare_json_contentwith the given tolerance. - Raise
AssertionErrorwith the full mismatch list and a remediation hint if any mismatches are found.
The replacements map follows the convention used throughout the testing
infrastructure: keys are real runtime values (absolute paths, recipe-dir
timestamps), values are the committed-bundle placeholders (e.g.
"<OUTPUT_DIR>", "<TEST_DATA_DIR>", "<RECIPE_RUN>").
Only the actual document is rewritten: the committed expected file is
assumed to already contain placeholders, which
:func:~climate_ref_core.regression.capture.write_committed_bundle guarantees
at capture time. A hand-edited baseline with raw paths will surface as ordinary
value mismatches.
Both <OUTPUT_DIR> and <RECIPE_RUN> participate in dict-KEY rewriting
because ESMValTool's output.json embeds absolute paths as object keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_path
|
Path
|
Path to the committed (on-disk) bundle file containing placeholders. |
required |
actual_path
|
Path
|
Path to the regenerated bundle file containing real runtime paths. |
required |
slug
|
str
|
Diagnostic slug used in error messages. |
required |
tol
|
Tolerance
|
Float comparison tolerance. |
Tolerance()
|
replacements
|
dict[str, str]
|
Mapping of |
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the bundles differ beyond tolerance after sanitisation. |
Notes
If expected_path does not exist (a legacy regression without a committed bundle),
the comparison is skipped silently and the function returns.
Source code in packages/climate-ref-core/src/climate_ref_core/regression/compare.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
build_native_snapshot(base_dir, relpaths)
#
Record a sha256 + size snapshot of each persisted native file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_dir
|
Path
|
The per-execution results directory the relpaths are resolved against. |
required |
relpaths
|
list[Path]
|
The persisted files (relative to |
required |
Returns:
| Type | Description |
|---|---|
dict[str, NativeEntry]
|
Mapping of POSIX relpath -> :class: |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/capture.py
build_native_store(config, *, writable)
#
Build an appropriate :class:NativeStore from a native-store config object.
Accepts any object that exposes url: str and cache_dir: Path
(satisfying :class:_NativeStoreConfigProtocol), so callers pass
config.native_store rather than the full :class:~climate_ref.config.Config.
With writable=False the returned store is always anonymous and
credential-free (suitable for CI read/replay paths).
With writable=True and a local URL/path a :class:LocalFilesystemStore is returned;
with a remote (http(s)) URL a credentialed :class:R2WriteStore is returned. The S3
endpoint and bucket come from the config; authentication is read from the environment
(REF_NATIVE_STORE_ACCESS_KEY_ID / REF_NATIVE_STORE_SECRET_ACCESS_KEY, else
REF_NATIVE_STORE_PROFILE, else boto3's default chain), so secrets never live in the
persisted config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
_NativeStoreConfigProtocol
|
A config object providing |
required |
writable
|
bool
|
When |
required |
Returns:
| Type | Description |
|---|---|
NativeStore
|
A :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URL scheme is unrecognised, or a writable remote store is requested without an S3 endpoint / bucket configured. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/store.py
capture_execution(scratch_directory, results_directory, fragment, result, *, regression_dir, output_dir, test_data_dir, include_log=False)
#
Persist a successful execution and capture its committed bundle + native snapshot.
Copies the curated output set from scratch to results via
:func:~climate_ref_core.output_files.copy_execution_outputs
(the production persistence path),
then writes the committed bundle and snapshots every persisted native file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scratch_directory
|
Path
|
Base scratch directory the diagnostic wrote into. |
required |
results_directory
|
Path
|
Base results directory to persist the curated subset into. |
required |
fragment
|
Path | str
|
The per-execution fragment under both base directories. |
required |
result
|
ExecutionResult
|
The successful execution result (must carry a metric bundle filename). |
required |
regression_dir
|
Path
|
The test case |
required |
output_dir
|
Path
|
The absolute execution output directory, for path substitution. |
required |
test_data_dir
|
Path
|
The absolute provider test-data directory, for path substitution. |
required |
include_log
|
bool
|
If True, the execution log is included in the persisted/native set. Defaults to False, matching the behaviour of
:func: |
False
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, str], dict[str, NativeEntry]]
|
A |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/capture.py
compare_json_content(expected, actual, *, tol, path='')
#
Recursively compare two parsed JSON values with float tolerance.
Rules:
- Floats: compared with relative tolerance tol.rtol
and absolute tolerance tol.atol.
- Ints, strings, bools, None: exact equality.
- Lists: element-by-element, same length required.
- Dicts: key sets must match; values compared recursively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected
|
Any
|
The reference (committed) parsed JSON value. |
required |
actual
|
Any
|
The regenerated parsed JSON value. |
required |
tol
|
Tolerance
|
Float comparison tolerance. |
required |
path
|
str
|
Dot-/bracket-notation path prefix for error messages (empty at top level). |
''
|
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of human-readable mismatch descriptions. An empty list means the values are equivalent within tolerance. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/compare.py
compute_committed_digests(regression_dir)
#
Compute sha256 digests of the committed regression JSON artefacts.
The digests are taken over the bytes exactly as they sit on disk (placeholder text included), so a CI recompute is deterministic. Only files that exist are included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regression_dir
|
Path
|
The test case |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Mapping of |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
decide_coupling(manifest, base_manifest, *, extraction_changed=False, committed_integrity_ok=True, catalog_integrity_ok=True)
#
Decide how CI should verify a single test case's regression baseline.
The decision is pure: it performs no I/O. All on-disk reality is summarised by its arguments — the two manifests, whether the diagnostic's extraction code changed, and whether the committed bundle on disk still matches the current manifest's digests.
The gate fails if any state cannot be positively verified. A deleted managed manifest, a committed bundle that drifted from its manifest, an input catalog that drifted from its manifest is a failure rather than a silent skip.
Changes to the native baseline are not failures.
This is due to the workflow for minting requires credentials.
This means fork contributors cannot author or edit native blobs.
replay is therefore only selected when native blobs actually exist to replay;
an absent or removed native baseline downgrades to skip (with a warning in the reason),
never fail.
See the module docstring for the meaning of each :class:Action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
Manifest | None
|
The current |
required |
base_manifest
|
Manifest | None
|
The |
required |
extraction_changed
|
bool
|
Whether code that influences |
False
|
committed_integrity_ok
|
bool
|
Whether the committed bundle on disk matches the current manifest's Ignored when |
True
|
catalog_integrity_ok
|
bool
|
Whether the test case's input Always |
True
|
Returns:
| Type | Description |
|---|---|
GateDecision
|
The gate's decision, pairing an :class: |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/gate.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
materialise_native(native, store, dest)
#
Materialise a native snapshot from a store into a destination directory.
For each (relpath, entry) the blob is fetched from store (keyed by its
sha256 digest) to dest / relpath, creating parent directories as needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native
|
dict[str, NativeEntry]
|
Mapping of relpath -> :class: |
required |
store
|
NativeStore
|
A content-addressed :class: |
required |
dest
|
Path
|
The destination directory the snapshot is materialised into. |
required |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/capture.py
paths_under(changed_files, roots)
#
Return whether any changed file lies within one of the given directory roots.
A small helper for deriving the extraction_changed signal from a pull request's changed-file list.
Paths are compared textually as POSIX-style, repo-relative strings,
so callers must normalise both changed_files and roots to the same convention
(e.g. git diff --name-only output and a package source directory relative to the repo root).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
changed_files
|
Iterable[str]
|
Repo-relative paths changed in the pull request. |
required |
roots
|
Iterable[str]
|
Repo-relative directory prefixes to test against. A trailing slash is optional; an empty root never matches. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in packages/climate-ref-core/src/climate_ref_core/regression/gate.py
sha256_bytes(data)
#
sha256_file(path)
#
Compute the sha256 digest of a file.
Reuses :func:pooch.hashes.file_hash so the digest agrees with pooch elsewhere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the file to hash. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The hex-encoded sha256 digest. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
verify_committed_integrity(manifest, regression_dir)
#
Check that the committed regression artefacts match the manifest digests.
Used by the CI integrity check. An empty return value means the bundle is intact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
Manifest
|
The manifest holding the expected committed digests. |
required |
regression_dir
|
Path
|
The test case |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of human-readable mismatch descriptions; empty when everything matches. |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/manifest.py
write_committed_bundle(source_dir, regression_dir, *, output_dir, test_data_dir)
#
Write the sanitised committed CMEC bundle into regression_dir.
Copies each committed artefact present in source_dir into regression_dir,
then rewrites absolute paths to portable placeholders in place
(:func:~climate_ref_core.output_files.to_placeholders).
When a committed artefact is absent from source_dir,
any stale copy left in regression_dir from a previous capture is removed so it is not re-digested.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_dir
|
Path
|
Directory holding the freshly persisted CMEC artefacts (the per-execution results directory). |
required |
regression_dir
|
Path
|
The destination |
required |
output_dir
|
Path
|
The absolute execution output directory, for path substitution. |
required |
test_data_dir
|
Path
|
The absolute provider test-data directory, for path substitution. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
The committed digests |
Source code in packages/climate-ref-core/src/climate_ref_core/regression/capture.py
sub-packages#
| Sub-package | Description |
|---|---|
| _quantise | Float quantisation for committed regression bundles. |
| capture | Capture of regression baselines from a diagnostic execution. |
| compare | Content comparison utilities for regression testing. |
| gate | CI coupling gate for test case regression bundles. |
| manifest | Manifest model and digest utilities for test case regression bundles. |
| store | Data store for native bundles. |