bricksentry 0.1.22__tar.gz → 0.1.23__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.
- {bricksentry-0.1.22 → bricksentry-0.1.23}/CHANGELOG.md +10 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/PKG-INFO +24 -7
- {bricksentry-0.1.22 → bricksentry-0.1.23}/README.md +21 -4
- bricksentry-0.1.23/deploy/databricks-app/requirements.txt +1 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry_check_my_table.ipynb +1 -1
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry_check_my_table.py +1 -1
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry_quickstart.ipynb +1 -1
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry_quickstart.py +1 -1
- {bricksentry-0.1.22 → bricksentry-0.1.23}/pyproject.toml +3 -2
- {bricksentry-0.1.22 → bricksentry-0.1.23}/server.json +2 -2
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/__init__.py +1 -1
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/assess.py +22 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/backends/base.py +16 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/backends/databricks_backend.py +3 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/backends/duckdb_backend.py +3 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/diff.py +46 -17
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/models.py +14 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/policy.py +6 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/report.py +8 -1
- {bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/databricks_template_schema.json +2 -2
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_0114.py +3 -1
- bricksentry-0.1.23/tests/test_0123.py +121 -0
- bricksentry-0.1.22/deploy/databricks-app/requirements.txt +0 -1
- {bricksentry-0.1.22 → bricksentry-0.1.23}/.gitignore +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/LICENSE +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/SECURITY.md +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/action.yml +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/deploy/container/Dockerfile +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/deploy/databricks-app/README.md +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/deploy/databricks-app/app.yaml +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/deploy/databricks-app/bricksentry.yml +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/deploy/databricks-app/databricks.yml +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/deploy/databricks-app/grants.sql +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/scripts/build_notebook.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/scripts/render_demo_image.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/__main__.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/agent_tools.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/cli.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/config.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/demo.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/explain.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/github.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/history.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/job.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/job_demo.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/lineage.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/netguard.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/notify.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/policy_templates.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/README.md +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/conftest.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_0110.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_0112.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_0120.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_0121.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_0122.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_018.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_019.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_check_notebook.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_demo.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_diff.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_hr_notebook.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_notify_templates.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.22 → bricksentry-0.1.23}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.23 (2026-11-16)
|
|
4
|
+
|
|
5
|
+
From a review of accuracy, auditability and documentation:
|
|
6
|
+
|
|
7
|
+
- **Exact totals.** Sums of decimal and integer columns are added as `DECIMAL(38, x)` instead of `DOUBLE`, so totals on large tables don't drift by cents and big integer columns can't overflow. Floating-point columns are still summed as `DOUBLE`.
|
|
8
|
+
- **Duplicated keys are matched one to one.** When a key appears more than once (including many rows with a NULL key, which match each other), copies are numbered and copy *n* is matched with copy *n*. Before, every copy matched every other copy: 2,000 NULL-key rows on each side joined into 4,000,000 pairs, and a duplicated row counted as a second match instead of an added row. A bad MERGE that duplicates rows now shows them as added, and the diff notes that copies were paired. Tables without duplicate keys run exactly as before.
|
|
9
|
+
- **Audit trail on every assessment:** `created_at` (UTC), `bricksentry_version`, `policy_sha256` (a fingerprint of the rules behind the verdict) and `triggered_by` (`BRICKSENTRY_ACTOR`, or the GitHub actor in GitHub Actions). In the JSON and the pull-request report footer. Older saved assessments still load.
|
|
10
|
+
- README: permissions needed per feature, what a check costs, and the audit trail.
|
|
11
|
+
- Links to the agent docs no longer end in `).` where READMEs and notebooks are shown as plain text (some directories turned them into a broken link). Package description and keywords mention change impact analysis and deployment guardrails.
|
|
12
|
+
|
|
3
13
|
## 0.1.22 (2026-11-15)
|
|
4
14
|
|
|
5
15
|
Security hardening, following a review on the Canopii MCP Trust Index:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: Change
|
|
3
|
+
Version: 0.1.23
|
|
4
|
+
Summary: Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans.
|
|
5
5
|
Project-URL: Homepage, https://bricksentry.org
|
|
6
6
|
Project-URL: Documentation, https://bricksentry.org/docs
|
|
7
7
|
Project-URL: Source, https://github.com/bricksentry/bricksentry
|
|
@@ -10,7 +10,7 @@ Project-URL: Changelog, https://github.com/bricksentry/bricksentry/blob/main/CHA
|
|
|
10
10
|
Author: Brahma
|
|
11
11
|
License-Expression: Apache-2.0
|
|
12
12
|
License-File: LICENSE
|
|
13
|
-
Keywords: ai-agents,ci,data-diff,data-engineering,data-quality,databricks,delta-lake,impact-analysis,lineage,mcp,unity-catalog
|
|
13
|
+
Keywords: ai-agents,change-impact-analysis,ci,data-diff,data-engineering,data-quality,databricks,delta-lake,deployment-guardrails,impact-analysis,lineage,mcp,rollback,unity-catalog
|
|
14
14
|
Classifier: Development Status :: 3 - Alpha
|
|
15
15
|
Classifier: Intended Audience :: Developers
|
|
16
16
|
Classifier: Operating System :: OS Independent
|
|
@@ -432,10 +432,27 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
432
432
|
|
|
433
433
|
## Permissions needed on Databricks
|
|
434
434
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
435
|
+
Grant only what the features you use need. Everything is read-only except the scratch schema.
|
|
436
|
+
|
|
437
|
+
| Feature | Needs |
|
|
438
|
+
|---|---|
|
|
439
|
+
| Any check | `CAN USE` on a SQL warehouse |
|
|
440
|
+
| Data diff (`diff`, `assess`, pull-request checks) | `SELECT` on the tables and their candidates |
|
|
441
|
+
| `check-last-change`, the job task | `SELECT` on the table and its Delta history (versions not yet removed by `VACUUM`), and `CREATE TABLE` on `sandbox_schema` for two short-lived shallow clones |
|
|
442
|
+
| `preview_write` (agents) | `CREATE TABLE` on `sandbox_schema`; the write only ever runs on a clone there |
|
|
443
|
+
| Blast radius | `SELECT` on `system.access.table_lineage` |
|
|
444
|
+
| Column-level impact | `SELECT` on `system.access.column_lineage` |
|
|
445
|
+
| Owners and tags | `SELECT` on `system.information_schema` (tables, table tags, column tags) |
|
|
446
|
+
|
|
447
|
+
Without lineage access bricksentry still diffs, and adds a `lineage-unavailable` warning (blast radius unknown) instead of guessing. A dedicated service principal with exactly these grants is the recommended setup for jobs and the MCP server.
|
|
448
|
+
|
|
449
|
+
## What a check costs
|
|
450
|
+
|
|
451
|
+
The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries: a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. Lineage lookups are one query per depth level, bounded by `lookback_days`.
|
|
452
|
+
|
|
453
|
+
## Audit trail
|
|
454
|
+
|
|
455
|
+
Every assessment records when it ran (UTC), the bricksentry version, a SHA-256 fingerprint of the policy rules that produced the verdict, and who triggered it (`BRICKSENTRY_ACTOR`, or the GitHub actor in GitHub Actions). They're in the JSON and in the footer of the pull-request report, so a verdict can be traced to the exact rules behind it. Assessments are saved as JSON under `assessment_store`; point it at a shared, access-controlled folder to keep a history.
|
|
439
456
|
|
|
440
457
|
## Known limits (v0.1.x)
|
|
441
458
|
|
|
@@ -385,10 +385,27 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
385
385
|
|
|
386
386
|
## Permissions needed on Databricks
|
|
387
387
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
388
|
+
Grant only what the features you use need. Everything is read-only except the scratch schema.
|
|
389
|
+
|
|
390
|
+
| Feature | Needs |
|
|
391
|
+
|---|---|
|
|
392
|
+
| Any check | `CAN USE` on a SQL warehouse |
|
|
393
|
+
| Data diff (`diff`, `assess`, pull-request checks) | `SELECT` on the tables and their candidates |
|
|
394
|
+
| `check-last-change`, the job task | `SELECT` on the table and its Delta history (versions not yet removed by `VACUUM`), and `CREATE TABLE` on `sandbox_schema` for two short-lived shallow clones |
|
|
395
|
+
| `preview_write` (agents) | `CREATE TABLE` on `sandbox_schema`; the write only ever runs on a clone there |
|
|
396
|
+
| Blast radius | `SELECT` on `system.access.table_lineage` |
|
|
397
|
+
| Column-level impact | `SELECT` on `system.access.column_lineage` |
|
|
398
|
+
| Owners and tags | `SELECT` on `system.information_schema` (tables, table tags, column tags) |
|
|
399
|
+
|
|
400
|
+
Without lineage access bricksentry still diffs, and adds a `lineage-unavailable` warning (blast radius unknown) instead of guessing. A dedicated service principal with exactly these grants is the recommended setup for jobs and the MCP server.
|
|
401
|
+
|
|
402
|
+
## What a check costs
|
|
403
|
+
|
|
404
|
+
The work runs on your SQL warehouse as plain SQL; nothing large is copied out. One table diff runs about five queries: a duplicate-key count on each side, one full outer join on the key columns, and one profile (row count, nulls, totals) per side, plus up to ten small queries for example values. Each reads both versions of the table, so cost grows with table size: seconds for millions of rows, minutes and real warehouse cost for hundreds of millions. For big tables, set `sample_pct` (a fixed hash sample of keys, checked against a full-table checksum so a change outside the sample isn't missed), or check only the tables that matter. Lineage lookups are one query per depth level, bounded by `lookback_days`.
|
|
405
|
+
|
|
406
|
+
## Audit trail
|
|
407
|
+
|
|
408
|
+
Every assessment records when it ran (UTC), the bricksentry version, a SHA-256 fingerprint of the policy rules that produced the verdict, and who triggered it (`BRICKSENTRY_ACTOR`, or the GitHub actor in GitHub Actions). They're in the JSON and in the footer of the pull-request report, so a verdict can be traced to the exact rules behind it. Assessments are saved as JSON under `assessment_store`; point it at a shared, access-controlled folder to keep a history.
|
|
392
409
|
|
|
393
410
|
## Known limits (v0.1.x)
|
|
394
411
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bricksentry[databricks,mcp]==0.1.23
|
{bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry_check_my_table.ipynb
RENAMED
|
@@ -287,7 +287,7 @@
|
|
|
287
287
|
"source": [
|
|
288
288
|
"## Next steps\n",
|
|
289
289
|
"- **Check every change before it ships:** run the same check in CI on pull requests. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).\n",
|
|
290
|
-
"- **Let AI agents check their own changes:** `uvx bricksentry-mcp
|
|
290
|
+
"- **Let AI agents check their own changes:** `uvx bricksentry-mcp`, docs at <https://bricksentry.org/docs/agents>\n",
|
|
291
291
|
"- **Get alerts:** set a Slack or Teams webhook and run `bricksentry test-alert`. See [bricksentry.org/docs/configuration](https://bricksentry.org/docs/configuration)."
|
|
292
292
|
]
|
|
293
293
|
}
|
|
@@ -229,5 +229,5 @@ print("Share what it found:\nhttps://github.com/bricksentry/bricksentry/issues/n
|
|
|
229
229
|
# MAGIC %md
|
|
230
230
|
# MAGIC ## Next steps
|
|
231
231
|
# MAGIC - **Check every change before it ships:** run the same check in CI on pull requests. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).
|
|
232
|
-
# MAGIC - **Let AI agents check their own changes:** `uvx bricksentry-mcp
|
|
232
|
+
# MAGIC - **Let AI agents check their own changes:** `uvx bricksentry-mcp`, docs at <https://bricksentry.org/docs/agents>
|
|
233
233
|
# MAGIC - **Get alerts:** set a Slack or Teams webhook and run `bricksentry test-alert`. See [bricksentry.org/docs/configuration](https://bricksentry.org/docs/configuration).
|
|
@@ -343,7 +343,7 @@
|
|
|
343
343
|
"source": [
|
|
344
344
|
"## Next steps\n",
|
|
345
345
|
"- **In CI:** `bricksentry init` writes `bricksentry.yml` and `policy.yml`; add `bricksentry assess --from-git origin/main --comment` to your pull-request workflow. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).\n",
|
|
346
|
-
"- **For AI agents:** `bricksentry mcp` exposes these same tools over MCP
|
|
346
|
+
"- **For AI agents:** `bricksentry mcp` exposes these same tools over MCP, docs at <https://bricksentry.org/docs/agents>\n",
|
|
347
347
|
"- **Feedback and bugs:** [github.com/bricksentry/bricksentry/issues](https://github.com/bricksentry/bricksentry/issues)"
|
|
348
348
|
]
|
|
349
349
|
}
|
|
@@ -257,5 +257,5 @@ agent_tools.set_sentry(None)
|
|
|
257
257
|
# MAGIC %md
|
|
258
258
|
# MAGIC ## Next steps
|
|
259
259
|
# MAGIC - **In CI:** `bricksentry init` writes `bricksentry.yml` and `policy.yml`; add `bricksentry assess --from-git origin/main --comment` to your pull-request workflow. See [bricksentry.org/docs/ci](https://bricksentry.org/docs/ci).
|
|
260
|
-
# MAGIC - **For AI agents:** `bricksentry mcp` exposes these same tools over MCP
|
|
260
|
+
# MAGIC - **For AI agents:** `bricksentry mcp` exposes these same tools over MCP, docs at <https://bricksentry.org/docs/agents>
|
|
261
261
|
# MAGIC - **Feedback and bugs:** [github.com/bricksentry/bricksentry/issues](https://github.com/bricksentry/bricksentry/issues)
|
|
@@ -4,8 +4,8 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bricksentry"
|
|
7
|
-
version = "0.1.
|
|
8
|
-
description = "Change
|
|
7
|
+
version = "0.1.23"
|
|
8
|
+
description = "Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = "Apache-2.0"
|
|
@@ -13,6 +13,7 @@ authors = [{ name = "Brahma" }]
|
|
|
13
13
|
keywords = [
|
|
14
14
|
"databricks", "delta-lake", "unity-catalog", "data-engineering", "data-diff",
|
|
15
15
|
"lineage", "impact-analysis", "ci", "mcp", "ai-agents", "data-quality",
|
|
16
|
+
"change-impact-analysis", "deployment-guardrails", "rollback",
|
|
16
17
|
]
|
|
17
18
|
classifiers = [
|
|
18
19
|
"Development Status :: 3 - Alpha",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
10
|
"websiteUrl": "https://bricksentry.org",
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.23",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"identifier": "bricksentry-mcp",
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.23",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
+
import os
|
|
6
7
|
import re
|
|
7
8
|
import uuid
|
|
9
|
+
from datetime import datetime, timezone
|
|
8
10
|
from typing import Any
|
|
9
11
|
|
|
10
12
|
from bricksentry.backends.base import Backend, make_backend
|
|
@@ -138,6 +140,10 @@ class Sentry:
|
|
|
138
140
|
tables=results,
|
|
139
141
|
verdict=Verdict.worst([t.verdict for t in results]),
|
|
140
142
|
notify=sorted(notify),
|
|
143
|
+
created_at=datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
|
144
|
+
bricksentry_version=_version(),
|
|
145
|
+
policy_sha256=self.policy.sha256,
|
|
146
|
+
triggered_by=_actor(),
|
|
141
147
|
)
|
|
142
148
|
self._assessments[a.id] = a
|
|
143
149
|
self._save(a)
|
|
@@ -255,6 +261,22 @@ class Sentry:
|
|
|
255
261
|
return self._diffs.get(table)
|
|
256
262
|
|
|
257
263
|
|
|
264
|
+
def _version() -> str:
|
|
265
|
+
from bricksentry import __version__ # imported late: bricksentry/__init__ imports this module
|
|
266
|
+
|
|
267
|
+
return __version__
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def _actor() -> str | None:
|
|
271
|
+
"""Who asked for the check: BRICKSENTRY_ACTOR if set, else the GitHub actor in
|
|
272
|
+
GitHub Actions. Nothing is read from the machine itself."""
|
|
273
|
+
if os.environ.get("BRICKSENTRY_ACTOR"):
|
|
274
|
+
return os.environ["BRICKSENTRY_ACTOR"].strip()[:200]
|
|
275
|
+
if os.environ.get("GITHUB_ACTOR"):
|
|
276
|
+
return "github:" + os.environ["GITHUB_ACTOR"].strip()[:200]
|
|
277
|
+
return None
|
|
278
|
+
|
|
279
|
+
|
|
258
280
|
def _first_line(e: Exception, limit: int = 200) -> str:
|
|
259
281
|
"""A short, single-line error for verdict reasons and alerts."""
|
|
260
282
|
text = (str(e).strip().splitlines() or [type(e).__name__])[0]
|
|
@@ -54,6 +54,22 @@ class Backend(ABC):
|
|
|
54
54
|
backend has no cheap row hash, and the guard is skipped."""
|
|
55
55
|
return None
|
|
56
56
|
|
|
57
|
+
def row_hash(self, columns: list[str]) -> str | None:
|
|
58
|
+
"""SQL for a hash of one row's ``columns``; orders copies of a duplicated key
|
|
59
|
+
so identical copies pair up. ``None`` means unsupported (copies are paired in
|
|
60
|
+
no particular order)."""
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
def exact_sum(self, expr: str, type_name: str) -> str:
|
|
64
|
+
"""SUM that doesn't drift on large tables: decimals and integers are added as
|
|
65
|
+
DECIMAL(38, x), only floating-point columns as DOUBLE."""
|
|
66
|
+
t = type_name.lower()
|
|
67
|
+
if t.startswith(("decimal", "numeric")):
|
|
68
|
+
return f"SUM({expr})"
|
|
69
|
+
if t.startswith(("float", "double", "real")):
|
|
70
|
+
return f"SUM(CAST({expr} AS DOUBLE))"
|
|
71
|
+
return f"SUM(CAST({expr} AS DECIMAL(38, 0)))"
|
|
72
|
+
|
|
57
73
|
@abstractmethod
|
|
58
74
|
def days_ago(self, days: int) -> str:
|
|
59
75
|
"""SQL expression for the date ``days`` days ago."""
|
|
@@ -109,6 +109,9 @@ class DatabricksBackend(Backend):
|
|
|
109
109
|
cols = ", ".join(self.quote(c) for c in columns)
|
|
110
110
|
return f"SUM(CAST(xxhash64({cols}) AS DECIMAL(38, 0)))"
|
|
111
111
|
|
|
112
|
+
def row_hash(self, columns: list[str]) -> str | None:
|
|
113
|
+
return f"xxhash64({', '.join(self.quote(c) for c in columns)})"
|
|
114
|
+
|
|
112
115
|
def sample_predicate(self, keys: list[str], pct: float, alias: str | None = None) -> str:
|
|
113
116
|
pre = f"{alias}." if alias else ""
|
|
114
117
|
cols = ", ".join(f"{pre}{self.quote(k)}" for k in keys)
|
|
@@ -38,6 +38,9 @@ class DuckDBBackend(Backend):
|
|
|
38
38
|
cols = ", ".join(self.quote(c) for c in columns)
|
|
39
39
|
return f"SUM(CAST(hash({cols}) AS HUGEINT))"
|
|
40
40
|
|
|
41
|
+
def row_hash(self, columns: list[str]) -> str | None:
|
|
42
|
+
return f"hash({', '.join(self.quote(c) for c in columns)})"
|
|
43
|
+
|
|
41
44
|
def sample_predicate(self, keys: list[str], pct: float, alias: str | None = None) -> str:
|
|
42
45
|
pre = f"{alias}." if alias else ""
|
|
43
46
|
cols = ", ".join(f"{pre}{self.quote(k)}" for k in keys)
|
|
@@ -114,14 +114,50 @@ def _diff(
|
|
|
114
114
|
# A marker column says whether a joined row exists on each side. Testing the key
|
|
115
115
|
# for NULL instead would count a NULL-key row as both added and removed.
|
|
116
116
|
present = q("__bs_present")
|
|
117
|
+
occ = q("__bs_occ")
|
|
118
|
+
kc = ", ".join(q(k) for k in keys)
|
|
117
119
|
|
|
118
|
-
def
|
|
119
|
-
|
|
120
|
-
return f"{alias} AS (SELECT *, 1 AS {present} FROM {backend.qualified(tbl)}{where})"
|
|
120
|
+
def sample_where() -> str:
|
|
121
|
+
return f" WHERE {backend.sample_predicate(keys, sample_pct)}" if sample_pct else ""
|
|
121
122
|
|
|
122
|
-
|
|
123
|
+
def raw_cte(tbl: str, alias: str) -> str:
|
|
124
|
+
return f"{alias} AS (SELECT *, 1 AS {present} FROM {backend.qualified(tbl)}{sample_where()})"
|
|
125
|
+
|
|
126
|
+
# Duplicate keys first: a key that appears more than once (including many NULL
|
|
127
|
+
# keys, which match each other) would multiply rows in the key join.
|
|
128
|
+
raw_ctes = f"WITH {raw_cte(base, 'b_src')}, {raw_cte(candidate, 'c_src')}"
|
|
129
|
+
|
|
130
|
+
def dupes(tbl_cte: str) -> int:
|
|
131
|
+
sql = (
|
|
132
|
+
f"{raw_ctes} SELECT COUNT(*) AS n FROM "
|
|
133
|
+
f"(SELECT {kc} FROM {tbl_cte} GROUP BY {kc} HAVING COUNT(*) > 1) d"
|
|
134
|
+
)
|
|
135
|
+
return int(backend.scalar(sql) or 0)
|
|
136
|
+
|
|
137
|
+
dup_b, dup_c = dupes("b_src"), dupes("c_src")
|
|
138
|
+
notes: list[str] = []
|
|
139
|
+
pair_copies = bool(dup_b or dup_c)
|
|
140
|
+
if pair_copies:
|
|
141
|
+
# Number the copies of each key and match copy n to copy n, so the join stays
|
|
142
|
+
# one to one: an extra copy counts as added (or removed), not as a second match.
|
|
143
|
+
# Ordering by a row hash pairs identical copies with each other.
|
|
144
|
+
order = backend.row_hash([c for c in b_cols if c in c_cols and c not in schema.type_changed]) or kc
|
|
145
|
+
|
|
146
|
+
def side(tbl: str, alias: str) -> str:
|
|
147
|
+
return (f"{alias} AS (SELECT *, 1 AS {present}, ROW_NUMBER() OVER (PARTITION BY {kc} "
|
|
148
|
+
f"ORDER BY {order}) AS {occ} FROM {backend.qualified(tbl)}{sample_where()})")
|
|
149
|
+
|
|
150
|
+
ctes = f"WITH {side(base, 'b_src')}, {side(candidate, 'c_src')}"
|
|
151
|
+
notes.append(
|
|
152
|
+
"Some keys appear more than once, so copies of the same key were paired one to one "
|
|
153
|
+
"(an extra copy counts as added or removed, not as another match)."
|
|
154
|
+
)
|
|
155
|
+
else:
|
|
156
|
+
ctes = raw_ctes
|
|
123
157
|
# Null-safe key match: a NULL key in production matches a NULL key in the candidate.
|
|
124
158
|
join_on = " AND ".join(f"b.{q(k)} IS NOT DISTINCT FROM c.{q(k)}" for k in keys)
|
|
159
|
+
if pair_copies:
|
|
160
|
+
join_on += f" AND b.{occ} = c.{occ}"
|
|
125
161
|
in_b, in_c = f"b.{present} IS NOT NULL", f"c.{present} IS NOT NULL"
|
|
126
162
|
|
|
127
163
|
def cmp(col: str) -> str:
|
|
@@ -149,27 +185,19 @@ def _diff(
|
|
|
149
185
|
)
|
|
150
186
|
j = backend.query(join_sql)[0]
|
|
151
187
|
|
|
152
|
-
# Row counts, nulls, numeric sums per side.
|
|
188
|
+
# Row counts, nulls, numeric sums per side. Sums are exact for decimals and integers.
|
|
153
189
|
def profile(tbl_cte: str, cols: dict[str, str]) -> dict:
|
|
154
190
|
any_null_key = " OR ".join(f"{q(k)} IS NULL" for k in keys)
|
|
155
191
|
parts = ["COUNT(*) AS n_rows", f"SUM(CASE WHEN {any_null_key} THEN 1 ELSE 0 END) AS null_keys"]
|
|
156
192
|
for i, col in enumerate(common):
|
|
157
193
|
parts.append(f"SUM(CASE WHEN {q(col)} IS NULL THEN 1 ELSE 0 END) AS nul_{i}")
|
|
158
194
|
if backend.is_numeric(cols[col]):
|
|
159
|
-
parts.append(f"
|
|
160
|
-
return backend.query(f"{
|
|
195
|
+
parts.append(f"{backend.exact_sum(q(col), cols[col])} AS sum_{i}")
|
|
196
|
+
return backend.query(f"{raw_ctes} SELECT {', '.join(parts)} FROM {tbl_cte}")[0]
|
|
161
197
|
|
|
162
198
|
pb = profile("b_src", b_cols)
|
|
163
199
|
pc = profile("c_src", c_cols)
|
|
164
200
|
|
|
165
|
-
def dupes(tbl_cte: str) -> int:
|
|
166
|
-
kc = ", ".join(q(k) for k in keys)
|
|
167
|
-
sql = (
|
|
168
|
-
f"{ctes} SELECT COUNT(*) AS n FROM "
|
|
169
|
-
f"(SELECT {kc} FROM {tbl_cte} GROUP BY {kc} HAVING COUNT(*) > 1) d"
|
|
170
|
-
)
|
|
171
|
-
return int(backend.scalar(sql) or 0)
|
|
172
|
-
|
|
173
201
|
col_changes: list[ColumnChange] = []
|
|
174
202
|
for i, col in enumerate(common):
|
|
175
203
|
changed = int(j.get(f"chg_{i}") or 0)
|
|
@@ -225,12 +253,13 @@ def _diff(
|
|
|
225
253
|
unchanged_rows=int(j.get("unchanged_rows") or 0),
|
|
226
254
|
schema=schema,
|
|
227
255
|
columns=col_changes,
|
|
228
|
-
duplicate_keys_base=
|
|
229
|
-
duplicate_keys_candidate=
|
|
256
|
+
duplicate_keys_base=dup_b,
|
|
257
|
+
duplicate_keys_candidate=dup_c,
|
|
230
258
|
null_keys_base=int(pb.get("null_keys") or 0),
|
|
231
259
|
null_keys_candidate=int(pc.get("null_keys") or 0),
|
|
232
260
|
segments=segments,
|
|
233
261
|
sampled_pct=sample_pct,
|
|
262
|
+
notes=notes,
|
|
234
263
|
)
|
|
235
264
|
|
|
236
265
|
|
|
@@ -91,6 +91,7 @@ class TableDiff:
|
|
|
91
91
|
sampled_pct: float | None = None
|
|
92
92
|
sample_note: str | None = None
|
|
93
93
|
error: str | None = None
|
|
94
|
+
notes: list[str] = field(default_factory=list)
|
|
94
95
|
|
|
95
96
|
def _pct(self, n: int) -> float:
|
|
96
97
|
denom = max(self.base_rows, 1)
|
|
@@ -260,6 +261,11 @@ class Assessment:
|
|
|
260
261
|
tables: list[TableAssessment]
|
|
261
262
|
verdict: Verdict
|
|
262
263
|
notify: list[str] = field(default_factory=list)
|
|
264
|
+
# Audit trail: when, with which bricksentry and policy, and who asked.
|
|
265
|
+
created_at: str | None = None # UTC, ISO 8601
|
|
266
|
+
bricksentry_version: str | None = None
|
|
267
|
+
policy_sha256: str | None = None # fingerprint of the policy rules that produced the verdict
|
|
268
|
+
triggered_by: str | None = None # BRICKSENTRY_ACTOR, or the GitHub actor in GitHub Actions
|
|
263
269
|
|
|
264
270
|
@property
|
|
265
271
|
def hits(self) -> list[RuleHit]:
|
|
@@ -272,6 +278,10 @@ class Assessment:
|
|
|
272
278
|
"risk_tier": self.verdict.risk_tier,
|
|
273
279
|
"safe_to_ship": self.verdict in (Verdict.PASS, Verdict.WARN),
|
|
274
280
|
"notify": self.notify,
|
|
281
|
+
"created_at": self.created_at,
|
|
282
|
+
"bricksentry_version": self.bricksentry_version,
|
|
283
|
+
"policy_sha256": self.policy_sha256,
|
|
284
|
+
"triggered_by": self.triggered_by,
|
|
275
285
|
"rule_hits": [h.to_dict() for h in self.hits],
|
|
276
286
|
"tables": [t.to_dict() for t in self.tables],
|
|
277
287
|
}
|
|
@@ -283,4 +293,8 @@ class Assessment:
|
|
|
283
293
|
tables=[TableAssessment.from_dict(t) for t in d.get("tables") or []],
|
|
284
294
|
verdict=Verdict(d["verdict"]),
|
|
285
295
|
notify=list(d.get("notify") or []),
|
|
296
|
+
created_at=d.get("created_at"),
|
|
297
|
+
bricksentry_version=d.get("bricksentry_version"),
|
|
298
|
+
policy_sha256=d.get("policy_sha256"),
|
|
299
|
+
triggered_by=d.get("triggered_by"),
|
|
286
300
|
)
|
|
@@ -40,6 +40,8 @@ All conditions inside one ``when`` must hold (AND). Use several rules for OR.
|
|
|
40
40
|
from __future__ import annotations
|
|
41
41
|
|
|
42
42
|
import fnmatch
|
|
43
|
+
import hashlib
|
|
44
|
+
import json
|
|
43
45
|
from typing import Any
|
|
44
46
|
|
|
45
47
|
from bricksentry.measures import is_measure
|
|
@@ -104,6 +106,10 @@ def _tag_label(want: Any) -> str:
|
|
|
104
106
|
class Policy:
|
|
105
107
|
def __init__(self, spec: dict[str, Any] | None = None):
|
|
106
108
|
spec = spec if spec is not None else DEFAULT_POLICY
|
|
109
|
+
# A fingerprint of the rules, recorded on every assessment so a verdict can be
|
|
110
|
+
# traced to the exact policy that produced it.
|
|
111
|
+
canonical = json.dumps(spec, sort_keys=True, default=str, separators=(",", ":"))
|
|
112
|
+
self.sha256 = hashlib.sha256(canonical.encode()).hexdigest()
|
|
107
113
|
self.default = Verdict(spec.get("default", "pass"))
|
|
108
114
|
self.notify_on = Verdict(spec.get("notify_owners_on", "needs_human"))
|
|
109
115
|
self.rules = spec.get("rules") or []
|
|
@@ -38,7 +38,13 @@ def to_markdown(a: Assessment, max_downstream: int = 15) -> str:
|
|
|
38
38
|
lines.append("")
|
|
39
39
|
for t in a.tables:
|
|
40
40
|
lines += _table_section(t, max_downstream)
|
|
41
|
-
|
|
41
|
+
audit = " · ".join(x for x in (
|
|
42
|
+
f"bricksentry {a.bricksentry_version}" if a.bricksentry_version else "bricksentry",
|
|
43
|
+
f"policy `{a.policy_sha256[:12]}`" if a.policy_sha256 else "",
|
|
44
|
+
a.created_at.replace("T", " ").replace("+00:00", " UTC") if a.created_at else "",
|
|
45
|
+
f"triggered by {a.triggered_by}" if a.triggered_by else "",
|
|
46
|
+
) if x)
|
|
47
|
+
lines += ["", f"<sub>Generated by {audit}. Verdicts come from policy rules, not from an LLM.</sub>"]
|
|
42
48
|
return "\n".join(lines)
|
|
43
49
|
|
|
44
50
|
|
|
@@ -53,6 +59,7 @@ def _table_section(t: TableAssessment, max_downstream: int) -> list[str]:
|
|
|
53
59
|
f"{d.changed_rows:,} | {d.unchanged_rows:,} |",
|
|
54
60
|
"",
|
|
55
61
|
]
|
|
62
|
+
out += [f"> {_esc(n)}" for n in d.notes] + ([""] if d.notes else [])
|
|
56
63
|
changed_cols = [c for c in d.columns if c.changed_rows or (c.sum_change_pct and abs(c.sum_change_pct) > 0.01)]
|
|
57
64
|
if changed_cols:
|
|
58
65
|
out += ["<details><summary>Column changes</summary>", "",
|
{bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/databricks_template_schema.json
RENAMED
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
},
|
|
87
87
|
"bricksentry_version": {
|
|
88
88
|
"type": "string",
|
|
89
|
-
"default": "0.1.
|
|
89
|
+
"default": "0.1.23",
|
|
90
90
|
"description": "bricksentry version to install in the job (pinned; change it and redeploy to upgrade)",
|
|
91
91
|
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
|
92
|
-
"pattern_match_failure_message": "Use a version like 0.1.
|
|
92
|
+
"pattern_match_failure_message": "Use a version like 0.1.23.",
|
|
93
93
|
"order": 10
|
|
94
94
|
}
|
|
95
95
|
},
|
|
@@ -107,7 +107,9 @@ def test_check_change_end_to_end():
|
|
|
107
107
|
a, change = sentry(db).check_change("sales.orders")
|
|
108
108
|
t = a.tables[0]
|
|
109
109
|
assert change.version == 3 and change.base_version == 2
|
|
110
|
-
|
|
110
|
+
# The 4 duplicated copies count as added (0.1.23); before, each copy was counted
|
|
111
|
+
# as a second match of the same key, which reported 0 added for a table that grew.
|
|
112
|
+
assert t.diff.added_rows == 4 and t.diff.base_rows == 1800 and t.diff.candidate_rows == 1804
|
|
111
113
|
assert t.diff.duplicate_keys_candidate > 0
|
|
112
114
|
assert a.verdict.value == "block" # duplicate keys
|
|
113
115
|
assert t.rollback == 'RESTORE TABLE "sales"."orders" TO VERSION AS OF 2'
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""0.1.23: exact totals, one-to-one matching of duplicated keys, and an audit trail
|
|
2
|
+
on every assessment."""
|
|
3
|
+
|
|
4
|
+
from bricksentry import Config, Sentry, __version__
|
|
5
|
+
from bricksentry.backends.databricks_backend import DatabricksBackend
|
|
6
|
+
from bricksentry.diff import diff_tables
|
|
7
|
+
from bricksentry.lineage import StaticLineage
|
|
8
|
+
from bricksentry.models import Assessment
|
|
9
|
+
from bricksentry.policy import Policy
|
|
10
|
+
from bricksentry.report import to_markdown
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# --- exact totals ----------------------------------------------------------------
|
|
14
|
+
def test_decimal_totals_are_exact(backend):
|
|
15
|
+
backend.execute("CREATE SCHEMA m")
|
|
16
|
+
backend.execute("CREATE TABLE m.base AS SELECT i AS id, CAST(0.10 AS DECIMAL(18, 2)) AS amount "
|
|
17
|
+
"FROM range(1, 1000001) t(i)")
|
|
18
|
+
backend.execute("CREATE TABLE m.cand AS SELECT * FROM m.base")
|
|
19
|
+
d = diff_tables(backend, "m.base", "m.cand", ["id"])
|
|
20
|
+
amount = d.columns[0]
|
|
21
|
+
# Adding 0.1 a million times as DOUBLE drifts (100000.00000133...); as DECIMAL it doesn't.
|
|
22
|
+
assert amount.base_sum == 100000.0 and amount.candidate_sum == 100000.0
|
|
23
|
+
assert amount.sum_change_pct == 0
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def test_sum_sql_by_type():
|
|
27
|
+
b = DatabricksBackend(warehouse_id="wh", client=object())
|
|
28
|
+
assert b.exact_sum("`a`", "decimal(18,2)") == "SUM(`a`)"
|
|
29
|
+
assert b.exact_sum("`a`", "bigint") == "SUM(CAST(`a` AS DECIMAL(38, 0)))" # no BIGINT overflow
|
|
30
|
+
assert b.exact_sum("`a`", "double") == "SUM(CAST(`a` AS DOUBLE))"
|
|
31
|
+
assert b.row_hash(["a", "b"]) == "xxhash64(`a`, `b`)"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# --- duplicated keys are matched one to one --------------------------------------
|
|
35
|
+
def test_many_null_keys_do_not_multiply(backend):
|
|
36
|
+
backend.execute("CREATE SCHEMA n")
|
|
37
|
+
backend.execute("CREATE TABLE n.base AS SELECT CASE WHEN i <= 2000 THEN NULL ELSE i END AS id, i AS v "
|
|
38
|
+
"FROM range(1, 3001) t(i)")
|
|
39
|
+
backend.execute("CREATE TABLE n.cand AS SELECT * FROM n.base")
|
|
40
|
+
d = diff_tables(backend, "n.base", "n.cand", ["id"])
|
|
41
|
+
# 2,000 NULL keys on each side used to join into 4,000,000 pairs.
|
|
42
|
+
assert (d.added_rows, d.removed_rows, d.changed_rows, d.unchanged_rows) == (0, 0, 0, 3000)
|
|
43
|
+
assert d.null_keys_base == 2000 and d.is_identical
|
|
44
|
+
assert d.notes and "paired one to one" in d.notes[0]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_a_new_copy_of_a_key_counts_as_added(backend):
|
|
48
|
+
backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders "
|
|
49
|
+
"UNION ALL SELECT order_id, region, amount, status FROM sales.orders WHERE order_id <= 3")
|
|
50
|
+
d = diff_tables(backend, "sales.orders", "sales_ci.orders", ["order_id"])
|
|
51
|
+
assert (d.added_rows, d.removed_rows, d.changed_rows, d.unchanged_rows) == (3, 0, 0, 1000)
|
|
52
|
+
assert d.duplicate_keys_candidate == 3
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_changed_copy_of_a_duplicated_key(backend):
|
|
56
|
+
backend.execute("CREATE SCHEMA k")
|
|
57
|
+
backend.execute("CREATE TABLE k.base AS SELECT * FROM (VALUES (1, 'a'), (1, 'b'), (2, 'c')) t(id, v)")
|
|
58
|
+
backend.execute("CREATE TABLE k.cand AS SELECT * FROM (VALUES (1, 'a'), (1, 'z'), (2, 'c')) t(id, v)")
|
|
59
|
+
d = diff_tables(backend, "k.base", "k.cand", ["id"])
|
|
60
|
+
assert d.base_rows == d.candidate_rows == 3
|
|
61
|
+
assert d.added_rows == d.removed_rows == 0
|
|
62
|
+
assert d.changed_rows == 1 and d.unchanged_rows == 2
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_no_note_without_duplicates(backend):
|
|
66
|
+
backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders")
|
|
67
|
+
assert diff_tables(backend, "sales.orders", "sales_ci.orders", ["order_id"]).notes == []
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# --- audit trail ------------------------------------------------------------------
|
|
71
|
+
def _sentry(backend, policy=None):
|
|
72
|
+
cfg = Config.from_dict({"assessment_store": False, "policy": policy,
|
|
73
|
+
"tables": {"sales.orders": {"keys": ["order_id"]}}})
|
|
74
|
+
return Sentry(cfg, backend=backend, lineage=StaticLineage({}))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_assessment_records_when_what_and_who(backend, monkeypatch):
|
|
78
|
+
backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders")
|
|
79
|
+
monkeypatch.delenv("GITHUB_ACTOR", raising=False)
|
|
80
|
+
monkeypatch.setenv("BRICKSENTRY_ACTOR", "nightly-orders-job")
|
|
81
|
+
a = _sentry(backend).assess(["sales.orders"], candidates={"sales.orders": "sales_ci.orders"})
|
|
82
|
+
assert a.created_at and a.created_at.endswith("+00:00")
|
|
83
|
+
assert a.bricksentry_version == __version__
|
|
84
|
+
assert a.policy_sha256 == Policy().sha256 and len(a.policy_sha256) == 64
|
|
85
|
+
assert a.triggered_by == "nightly-orders-job"
|
|
86
|
+
|
|
87
|
+
d = a.to_dict()
|
|
88
|
+
assert {"created_at", "bricksentry_version", "policy_sha256", "triggered_by"} <= set(d)
|
|
89
|
+
again = Assessment.from_dict(d)
|
|
90
|
+
assert (again.created_at, again.policy_sha256, again.triggered_by) == (
|
|
91
|
+
a.created_at, a.policy_sha256, "nightly-orders-job")
|
|
92
|
+
|
|
93
|
+
md = to_markdown(a)
|
|
94
|
+
assert f"bricksentry {__version__}" in md and f"policy `{a.policy_sha256[:12]}`" in md
|
|
95
|
+
assert "triggered by nightly-orders-job" in md and " UTC" in md
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_github_actor_and_nobody(backend, monkeypatch):
|
|
99
|
+
backend.execute("CREATE TABLE sales_ci.orders AS SELECT * FROM sales.orders")
|
|
100
|
+
monkeypatch.delenv("BRICKSENTRY_ACTOR", raising=False)
|
|
101
|
+
monkeypatch.setenv("GITHUB_ACTOR", "octocat")
|
|
102
|
+
a = _sentry(backend).assess(["sales.orders"], candidates={"sales.orders": "sales_ci.orders"})
|
|
103
|
+
assert a.triggered_by == "github:octocat"
|
|
104
|
+
monkeypatch.delenv("GITHUB_ACTOR")
|
|
105
|
+
a = _sentry(backend).assess(["sales.orders"], candidates={"sales.orders": "sales_ci.orders"})
|
|
106
|
+
assert a.triggered_by is None
|
|
107
|
+
assert "triggered by" not in to_markdown(a)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_policy_fingerprint_changes_with_the_rules():
|
|
111
|
+
a = Policy({"rules": [{"name": "x", "when": {"duplicate_keys": True}, "then": "block"}]})
|
|
112
|
+
b = Policy({"rules": [{"name": "x", "when": {"duplicate_keys": True}, "then": "warn"}]})
|
|
113
|
+
c = Policy({"rules": [{"then": "block", "when": {"duplicate_keys": True}, "name": "x"}]}) # same, reordered
|
|
114
|
+
assert a.sha256 != b.sha256
|
|
115
|
+
assert a.sha256 == c.sha256
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_old_saved_assessments_still_load():
|
|
119
|
+
old = {"id": "abc", "verdict": "pass", "tables": [], "notify": []}
|
|
120
|
+
a = Assessment.from_dict(old)
|
|
121
|
+
assert a.created_at is None and a.policy_sha256 is None
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bricksentry[databricks,mcp]==0.1.22
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.22 → bricksentry-0.1.23}/examples/databricks/bricksentry_hr_walkthrough.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.22 → bricksentry-0.1.23}/templates/job-check/template/{{.project_name}}/.gitignore
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|