bricksentry 0.1.3__tar.gz → 0.1.5__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.3 → bricksentry-0.1.5}/.gitignore +3 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/CHANGELOG.md +11 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/PKG-INFO +60 -16
- {bricksentry-0.1.3 → bricksentry-0.1.5}/README.md +57 -15
- {bricksentry-0.1.3 → bricksentry-0.1.5}/pyproject.toml +22 -2
- {bricksentry-0.1.3 → bricksentry-0.1.5}/scripts/build_notebook.py +3 -3
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/__init__.py +1 -1
- bricksentry-0.1.5/src/bricksentry/agent_tools.py +228 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/assess.py +30 -1
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/backends/base.py +7 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/backends/databricks_backend.py +5 -1
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/backends/duckdb_backend.py +5 -1
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/config.py +18 -2
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/demo.py +1 -1
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/diff.py +50 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/explain.py +2 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/models.py +48 -2
- {bricksentry-0.1.3 → bricksentry-0.1.5}/tests/conftest.py +6 -0
- bricksentry-0.1.5/tests/test_sample_guard_and_store.py +84 -0
- bricksentry-0.1.3/src/bricksentry/agent_tools.py +0 -139
- {bricksentry-0.1.3 → bricksentry-0.1.5}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/LICENSE +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/SECURITY.md +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/action.yml +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/examples/databricks/bricksentry_quickstart.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/cli.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/github.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/lineage.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/policy.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/src/bricksentry/report.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/tests/test_demo.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/tests/test_diff.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.3 → bricksentry-0.1.5}/tests/test_preview_agents.py +0 -0
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.5 (2026-11-10)
|
|
4
|
+
|
|
5
|
+
- Clearer MCP tool definitions for agents. Each tool now says when to use it versus its sibling tools and what it returns, and every parameter has a description in the tool schema (for example the `candidates` map format for `assess_change`). No behavior changes.
|
|
6
|
+
|
|
7
|
+
## 0.1.4 (2026-11-10)
|
|
8
|
+
|
|
9
|
+
From a second end-to-end run on Databricks serverless against a 2-million-row table:
|
|
10
|
+
|
|
11
|
+
- Fix: a sampled diff (`sample_pct`) could report "no change" when the change sat outside the sample, for example one deleted row in 2 million at a 10% sample. A full-table checksum now guards every sampled diff: if the sample looks identical but the tables differ, the diff re-runs on all rows and says so in the summary (`sample_note`). Identical tables stay sampled and cheap. Turn it off with `sample_guard: false`.
|
|
12
|
+
- Fix: `explain_diff` and `safe_to_ship` returned "unknown assessment id" when called from a different `Sentry` instance or process. Assessments are now saved as JSON (default `~/.bricksentry/assessments`, or `assessment_store:` in bricksentry.yml, or env `BRICKSENTRY_STORE`) and loaded by id. Set `assessment_store: false` to keep them in memory only.
|
|
13
|
+
|
|
3
14
|
## 0.1.3 (2026-11-10)
|
|
4
15
|
|
|
5
16
|
- Blast radius no longer lists bricksentry's own `preview_write` clones, or tables that Unity Catalog lineage remembers but that no longer exist (when `information_schema` can confirm it). Before, every preview added a stale downstream entry. New lineage settings: `exclude` (name patterns, default `["*__preview_*"]`) and `exclude_dropped` (default true).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Change-safety for Databricks 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
|
|
@@ -36,20 +36,28 @@ Provides-Extra: dev
|
|
|
36
36
|
Requires-Dist: databricks-sdk>=0.30; extra == 'dev'
|
|
37
37
|
Requires-Dist: duckdb>=1.0; extra == 'dev'
|
|
38
38
|
Requires-Dist: mcp>=1.10; extra == 'dev'
|
|
39
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
39
40
|
Requires-Dist: pytest>=8; extra == 'dev'
|
|
41
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
40
42
|
Provides-Extra: duckdb
|
|
41
43
|
Requires-Dist: duckdb>=1.0; extra == 'duckdb'
|
|
42
44
|
Provides-Extra: mcp
|
|
43
45
|
Requires-Dist: mcp>=1.10; extra == 'mcp'
|
|
44
46
|
Description-Content-Type: text/markdown
|
|
45
47
|
|
|
46
|
-
# bricksentry
|
|
48
|
+
# Welcome to bricksentry
|
|
47
49
|
|
|
48
|
-
[](https://pypi.org/project/bricksentry/) [](https://pypi.org/project/bricksentry/) [](https://pypi.org/project/bricksentry/) [](https://pypi.org/project/bricksentry/) [](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [](https://github.com/bricksentry/bricksentry/actions/workflows/lint.yml) [](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [](LICENSE)
|
|
49
51
|
|
|
50
|
-
***
|
|
52
|
+
***The safety check for data changes in the AI era.***
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
Change-safety for Databricks pipelines and the AI agents that edit them: know what a change does to your data before it ships.
|
|
55
|
+
|
|
56
|
+
**[Try it in 30 seconds](#try-it-in-30-seconds-no-databricks-needed)** · **[Run the Databricks notebook](#run-it-in-your-databricks-workspace)** · **[Docs: bricksentry.org](https://bricksentry.org)** · **[LinkedIn](https://www.linkedin.com/company/bricksentry-org/)**
|
|
57
|
+
|
|
58
|
+
Built by Brahmareddy, Databricks Champion. Open source under Apache-2.0.
|
|
59
|
+
|
|
60
|
+
*Why the name?* Bricks plus entry. Your tables and pipelines are the bricks of the lakehouse, and every change to them is an entry. bricksentry checks each entry, reports what it does, and stands guard before it lands.
|
|
53
61
|
|
|
54
62
|
## Try it in 30 seconds (no Databricks needed)
|
|
55
63
|
|
|
@@ -62,15 +70,12 @@ An AI agent changes a 20,000-row revenue table. bricksentry previews its DELETE
|
|
|
62
70
|
|
|
63
71
|

|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
## Run it in your Databricks workspace
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
In Databricks: **Workspace → Import → URL**, and paste:
|
|
75
|
+
> **Databricks quickstart notebook:** in your workspace, go to **Workspace → Import → URL** and paste
|
|
76
|
+
> `https://raw.githubusercontent.com/bricksentry/bricksentry/main/examples/databricks/bricksentry_quickstart.py`
|
|
70
77
|
|
|
71
|
-
|
|
72
|
-
https://raw.githubusercontent.com/bricksentry/bricksentry/main/examples/databricks/bricksentry_quickstart.py
|
|
73
|
-
```
|
|
78
|
+
The [quickstart notebook](examples/databricks/bricksentry_quickstart.py) creates a small demo table in a schema you choose and runs the same loop on Databricks: Unity Catalog blast radius, a real `RESTORE` rollback plan, a preview on a shallow clone, a blocked pull request and the fix. Then it checks one of your own tables, read-only, and cleans up after itself.
|
|
74
79
|
|
|
75
80
|
You need a SQL warehouse, `CREATE TABLE` on the schema you pick, and `SELECT` on `system.access.table_lineage` for the blast radius. A Jupyter copy is in [`bricksentry_quickstart.ipynb`](examples/databricks/bricksentry_quickstart.ipynb).
|
|
76
81
|
|
|
@@ -119,7 +124,8 @@ Designed for agents:
|
|
|
119
124
|
- **The verdict never comes from an LLM.** Rules in `policy.yml` decide, so the same change always gets the same answer.
|
|
120
125
|
- **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements.
|
|
121
126
|
- **Errors come back as `{"error": ...}`**, so agents can recover instead of crashing.
|
|
122
|
-
- **Bounded cost:** deterministic hash sampling (`sample_pct`), capped samples, and lineage limited by depth and lookback window.
|
|
127
|
+
- **Bounded cost:** deterministic hash sampling (`sample_pct`), capped samples, and lineage limited by depth and lookback window. A full-table checksum guards the sample: if the sample shows no change but the tables differ, the diff re-runs on every row, so a one-row change can't slip through.
|
|
128
|
+
- **Assessments are saved** as JSON (default `~/.bricksentry/assessments`), so `explain_diff` and `safe_to_ship` work from another process or a fresh `Sentry`.
|
|
123
129
|
|
|
124
130
|
The same tools are plain Python functions in `bricksentry.agent_tools`, so you can use them from LangGraph, the OpenAI Agents SDK or the Databricks Agent Framework without MCP.
|
|
125
131
|
|
|
@@ -190,7 +196,8 @@ s.preview_write("DELETE FROM main.sales.orders WHERE status = 'test'", "main.sal
|
|
|
190
196
|
backend: {type: databricks, warehouse_id: abc123} # auth: standard Databricks SDK chain
|
|
191
197
|
sandbox_schema: main.bricksentry_sandbox
|
|
192
198
|
candidate_pattern: "{catalog}.{schema}_pr_{pr}.{table}"
|
|
193
|
-
sample_pct: 10
|
|
199
|
+
sample_pct: 10 # sample_guard re-checks the whole table (on by default)
|
|
200
|
+
assessment_store: ~/.bricksentry/assessments # or false to keep assessments in memory
|
|
194
201
|
lineage: {type: databricks, depth: 3, lookback_days: 90} # also: exclude, exclude_dropped
|
|
195
202
|
tables:
|
|
196
203
|
main.sales.orders:
|
|
@@ -200,6 +207,37 @@ tables:
|
|
|
200
207
|
policy: policy.yml
|
|
201
208
|
```
|
|
202
209
|
|
|
210
|
+
### Policy example
|
|
211
|
+
|
|
212
|
+
A small `policy.yml` with one rule per severity. `pass` is the default: a change gets it when no rule matches.
|
|
213
|
+
|
|
214
|
+
```yaml
|
|
215
|
+
default: pass # no rule matched -> pass
|
|
216
|
+
notify_owners_on: needs_human # tag downstream owners from this level up
|
|
217
|
+
|
|
218
|
+
rules:
|
|
219
|
+
- name: type-change # a column changed type -> warn
|
|
220
|
+
when: {column_type_changed: true}
|
|
221
|
+
then: warn
|
|
222
|
+
|
|
223
|
+
- name: revenue-moved # total revenue moved more than 2% -> a human signs off
|
|
224
|
+
when: {column: amount, sum_change_pct_gt: 2}
|
|
225
|
+
then: needs_human
|
|
226
|
+
|
|
227
|
+
- name: duplicate-keys # a join fanned out and duplicated keys -> block the PR
|
|
228
|
+
when: {duplicate_keys: true}
|
|
229
|
+
then: block
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
| The change | Verdict |
|
|
233
|
+
|---|---|
|
|
234
|
+
| A filter fix that changes 40 rows, nothing else | `pass` |
|
|
235
|
+
| `order_date` goes from `STRING` to `DATE` | `warn` |
|
|
236
|
+
| A pricing fix moves `SUM(amount)` by 3.1% | `needs_human` |
|
|
237
|
+
| A new join duplicates 40 `order_id`s | `block` |
|
|
238
|
+
|
|
239
|
+
If several rules match, the most severe one wins. The full starter policy is in [`examples/databricks/policy.yml`](examples/databricks/policy.yml), and `bricksentry init` writes one for you.
|
|
240
|
+
|
|
203
241
|
### Policy conditions
|
|
204
242
|
|
|
205
243
|
`table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `any_change` · `diff_error`
|
|
@@ -218,11 +256,13 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
218
256
|
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping.
|
|
219
257
|
- **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
|
|
220
258
|
- **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
|
|
221
|
-
- **Validated on one Databricks workspace so far** (serverless, November 2026): lineage, Delta rollback plans, previews on shallow clones, every verdict level and sampling. The automated tests use DuckDB and a mocked SDK, so please [open an issue](https://github.com/bricksentry/bricksentry/issues) if something behaves differently on yours.
|
|
259
|
+
- **Validated on one Databricks workspace so far** (serverless, November 2026, on a 2-million-row table with 0.1.4): lineage, Delta rollback plans, previews on shallow clones, every verdict level, and the sampling guard catching a single changed row. The automated tests use DuckDB and a mocked SDK, so please [open an issue](https://github.com/bricksentry/bricksentry/issues) if something behaves differently on yours.
|
|
222
260
|
|
|
223
261
|
## Roadmap
|
|
224
262
|
|
|
225
|
-
|
|
263
|
+
**Top priority: validation across more workspaces.** Classic and serverless compute, AWS, Azure and GCP, and workspaces with restricted system-table access. If you run the quickstart notebook, please [share what you see](https://github.com/bricksentry/bricksentry/issues), whether it works or not.
|
|
264
|
+
|
|
265
|
+
Next: Asset Bundle parsing for automatic table detection · column-level blast radius from `system.access.column_lineage` · an aggregate diff for keyless tables · Lakeflow expectations in the verdict · `bricksentry watch` for scheduled drift checks · a Databricks App UI.
|
|
226
266
|
|
|
227
267
|
## Contributing
|
|
228
268
|
|
|
@@ -231,3 +271,7 @@ Bug reports from real pipelines help the most. See [CONTRIBUTING.md](CONTRIBUTIN
|
|
|
231
271
|
## License
|
|
232
272
|
|
|
233
273
|
Apache-2.0. Created and maintained by Brahma - Databricks Champion.
|
|
274
|
+
|
|
275
|
+
## Trademarks
|
|
276
|
+
|
|
277
|
+
bricksentry is an independent open-source project. It is not affiliated with, endorsed by, or sponsored by Databricks, Inc. or Functional Software, Inc. (Sentry). Databricks, Unity Catalog and Lakeflow are trademarks of Databricks, Inc. Delta Lake is a trademark of the Linux Foundation, and Apache Spark and PySpark are trademarks of the Apache Software Foundation. All other names are the trademarks of their respective owners and are used here only to describe compatibility. Thank you.
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
# bricksentry
|
|
1
|
+
# Welcome to bricksentry
|
|
2
2
|
|
|
3
|
-
[](https://pypi.org/project/bricksentry/) [](https://pypi.org/project/bricksentry/) [](https://pypi.org/project/bricksentry/) [](https://pypi.org/project/bricksentry/) [](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [](https://github.com/bricksentry/bricksentry/actions/workflows/lint.yml) [](https://github.com/bricksentry/bricksentry/actions/workflows/ci.yml) [](LICENSE)
|
|
4
4
|
|
|
5
|
-
***
|
|
5
|
+
***The safety check for data changes in the AI era.***
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Change-safety for Databricks pipelines and the AI agents that edit them: know what a change does to your data before it ships.
|
|
8
|
+
|
|
9
|
+
**[Try it in 30 seconds](#try-it-in-30-seconds-no-databricks-needed)** · **[Run the Databricks notebook](#run-it-in-your-databricks-workspace)** · **[Docs: bricksentry.org](https://bricksentry.org)** · **[LinkedIn](https://www.linkedin.com/company/bricksentry-org/)**
|
|
10
|
+
|
|
11
|
+
Built by Brahmareddy, Databricks Champion. Open source under Apache-2.0.
|
|
12
|
+
|
|
13
|
+
*Why the name?* Bricks plus entry. Your tables and pipelines are the bricks of the lakehouse, and every change to them is an entry. bricksentry checks each entry, reports what it does, and stands guard before it lands.
|
|
8
14
|
|
|
9
15
|
## Try it in 30 seconds (no Databricks needed)
|
|
10
16
|
|
|
@@ -17,15 +23,12 @@ An AI agent changes a 20,000-row revenue table. bricksentry previews its DELETE
|
|
|
17
23
|
|
|
18
24
|

|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
## Run it in your Databricks workspace
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
In Databricks: **Workspace → Import → URL**, and paste:
|
|
28
|
+
> **Databricks quickstart notebook:** in your workspace, go to **Workspace → Import → URL** and paste
|
|
29
|
+
> `https://raw.githubusercontent.com/bricksentry/bricksentry/main/examples/databricks/bricksentry_quickstart.py`
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
https://raw.githubusercontent.com/bricksentry/bricksentry/main/examples/databricks/bricksentry_quickstart.py
|
|
28
|
-
```
|
|
31
|
+
The [quickstart notebook](examples/databricks/bricksentry_quickstart.py) creates a small demo table in a schema you choose and runs the same loop on Databricks: Unity Catalog blast radius, a real `RESTORE` rollback plan, a preview on a shallow clone, a blocked pull request and the fix. Then it checks one of your own tables, read-only, and cleans up after itself.
|
|
29
32
|
|
|
30
33
|
You need a SQL warehouse, `CREATE TABLE` on the schema you pick, and `SELECT` on `system.access.table_lineage` for the blast radius. A Jupyter copy is in [`bricksentry_quickstart.ipynb`](examples/databricks/bricksentry_quickstart.ipynb).
|
|
31
34
|
|
|
@@ -74,7 +77,8 @@ Designed for agents:
|
|
|
74
77
|
- **The verdict never comes from an LLM.** Rules in `policy.yml` decide, so the same change always gets the same answer.
|
|
75
78
|
- **Read-only by default.** Only `preview_write` writes, and only to a sandbox clone. It accepts a single INSERT / MERGE / UPDATE / DELETE / CREATE OR REPLACE whose target must be the clone, and it refuses DROP, TRUNCATE, ALTER, GRANT and multiple statements.
|
|
76
79
|
- **Errors come back as `{"error": ...}`**, so agents can recover instead of crashing.
|
|
77
|
-
- **Bounded cost:** deterministic hash sampling (`sample_pct`), capped samples, and lineage limited by depth and lookback window.
|
|
80
|
+
- **Bounded cost:** deterministic hash sampling (`sample_pct`), capped samples, and lineage limited by depth and lookback window. A full-table checksum guards the sample: if the sample shows no change but the tables differ, the diff re-runs on every row, so a one-row change can't slip through.
|
|
81
|
+
- **Assessments are saved** as JSON (default `~/.bricksentry/assessments`), so `explain_diff` and `safe_to_ship` work from another process or a fresh `Sentry`.
|
|
78
82
|
|
|
79
83
|
The same tools are plain Python functions in `bricksentry.agent_tools`, so you can use them from LangGraph, the OpenAI Agents SDK or the Databricks Agent Framework without MCP.
|
|
80
84
|
|
|
@@ -145,7 +149,8 @@ s.preview_write("DELETE FROM main.sales.orders WHERE status = 'test'", "main.sal
|
|
|
145
149
|
backend: {type: databricks, warehouse_id: abc123} # auth: standard Databricks SDK chain
|
|
146
150
|
sandbox_schema: main.bricksentry_sandbox
|
|
147
151
|
candidate_pattern: "{catalog}.{schema}_pr_{pr}.{table}"
|
|
148
|
-
sample_pct: 10
|
|
152
|
+
sample_pct: 10 # sample_guard re-checks the whole table (on by default)
|
|
153
|
+
assessment_store: ~/.bricksentry/assessments # or false to keep assessments in memory
|
|
149
154
|
lineage: {type: databricks, depth: 3, lookback_days: 90} # also: exclude, exclude_dropped
|
|
150
155
|
tables:
|
|
151
156
|
main.sales.orders:
|
|
@@ -155,6 +160,37 @@ tables:
|
|
|
155
160
|
policy: policy.yml
|
|
156
161
|
```
|
|
157
162
|
|
|
163
|
+
### Policy example
|
|
164
|
+
|
|
165
|
+
A small `policy.yml` with one rule per severity. `pass` is the default: a change gets it when no rule matches.
|
|
166
|
+
|
|
167
|
+
```yaml
|
|
168
|
+
default: pass # no rule matched -> pass
|
|
169
|
+
notify_owners_on: needs_human # tag downstream owners from this level up
|
|
170
|
+
|
|
171
|
+
rules:
|
|
172
|
+
- name: type-change # a column changed type -> warn
|
|
173
|
+
when: {column_type_changed: true}
|
|
174
|
+
then: warn
|
|
175
|
+
|
|
176
|
+
- name: revenue-moved # total revenue moved more than 2% -> a human signs off
|
|
177
|
+
when: {column: amount, sum_change_pct_gt: 2}
|
|
178
|
+
then: needs_human
|
|
179
|
+
|
|
180
|
+
- name: duplicate-keys # a join fanned out and duplicated keys -> block the PR
|
|
181
|
+
when: {duplicate_keys: true}
|
|
182
|
+
then: block
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
| The change | Verdict |
|
|
186
|
+
|---|---|
|
|
187
|
+
| A filter fix that changes 40 rows, nothing else | `pass` |
|
|
188
|
+
| `order_date` goes from `STRING` to `DATE` | `warn` |
|
|
189
|
+
| A pricing fix moves `SUM(amount)` by 3.1% | `needs_human` |
|
|
190
|
+
| A new join duplicates 40 `order_id`s | `block` |
|
|
191
|
+
|
|
192
|
+
If several rules match, the most severe one wins. The full starter policy is in [`examples/databricks/policy.yml`](examples/databricks/policy.yml), and `bricksentry init` writes one for you.
|
|
193
|
+
|
|
158
194
|
### Policy conditions
|
|
159
195
|
|
|
160
196
|
`table` (glob) · `tag` · `downstream_tag` · `downstream_kind` · `downstream_count_gt` · `removed_pct_gt` · `added_pct_gt` · `changed_pct_gt` · `row_count_change_pct_gt` · `row_count_drop_pct_gt` · `column_removed` · `column_added` · `column_type_changed` · `duplicate_keys` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `any_change` · `diff_error`
|
|
@@ -173,11 +209,13 @@ All conditions in a `when` must hold. The most severe matching rule sets the ver
|
|
|
173
209
|
- **Lineage is recorded at runtime.** Brand-new tables have no downstream history yet. Unity Catalog doesn't capture RDD operations, and UDFs hide column-level mapping.
|
|
174
210
|
- **Keys are required.** Tables without a stable key can't be diffed row by row yet (an aggregate-profile mode is planned).
|
|
175
211
|
- **Changed-table detection uses path globs** from config. It doesn't parse Asset Bundles yet.
|
|
176
|
-
- **Validated on one Databricks workspace so far** (serverless, November 2026): lineage, Delta rollback plans, previews on shallow clones, every verdict level and sampling. The automated tests use DuckDB and a mocked SDK, so please [open an issue](https://github.com/bricksentry/bricksentry/issues) if something behaves differently on yours.
|
|
212
|
+
- **Validated on one Databricks workspace so far** (serverless, November 2026, on a 2-million-row table with 0.1.4): lineage, Delta rollback plans, previews on shallow clones, every verdict level, and the sampling guard catching a single changed row. The automated tests use DuckDB and a mocked SDK, so please [open an issue](https://github.com/bricksentry/bricksentry/issues) if something behaves differently on yours.
|
|
177
213
|
|
|
178
214
|
## Roadmap
|
|
179
215
|
|
|
180
|
-
|
|
216
|
+
**Top priority: validation across more workspaces.** Classic and serverless compute, AWS, Azure and GCP, and workspaces with restricted system-table access. If you run the quickstart notebook, please [share what you see](https://github.com/bricksentry/bricksentry/issues), whether it works or not.
|
|
217
|
+
|
|
218
|
+
Next: Asset Bundle parsing for automatic table detection · column-level blast radius from `system.access.column_lineage` · an aggregate diff for keyless tables · Lakeflow expectations in the verdict · `bricksentry watch` for scheduled drift checks · a Databricks App UI.
|
|
181
219
|
|
|
182
220
|
## Contributing
|
|
183
221
|
|
|
@@ -186,3 +224,7 @@ Bug reports from real pipelines help the most. See [CONTRIBUTING.md](CONTRIBUTIN
|
|
|
186
224
|
## License
|
|
187
225
|
|
|
188
226
|
Apache-2.0. Created and maintained by Brahma - Databricks Champion.
|
|
227
|
+
|
|
228
|
+
## Trademarks
|
|
229
|
+
|
|
230
|
+
bricksentry is an independent open-source project. It is not affiliated with, endorsed by, or sponsored by Databricks, Inc. or Functional Software, Inc. (Sentry). Databricks, Unity Catalog and Lakeflow are trademarks of Databricks, Inc. Delta Lake is a trademark of the Linux Foundation, and Apache Spark and PySpark are trademarks of the Apache Software Foundation. All other names are the trademarks of their respective owners and are used here only to describe compatibility. Thank you.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "bricksentry"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.5"
|
|
8
8
|
description = "Change-safety for Databricks 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"
|
|
@@ -38,7 +38,7 @@ databricks = ["databricks-sdk>=0.30"]
|
|
|
38
38
|
duckdb = ["duckdb>=1.0"]
|
|
39
39
|
mcp = ["mcp>=1.10"]
|
|
40
40
|
all = ["databricks-sdk>=0.30", "duckdb>=1.0", "mcp>=1.10"]
|
|
41
|
-
dev = ["pytest>=8", "duckdb>=1.0", "mcp>=1.10", "databricks-sdk>=0.30"]
|
|
41
|
+
dev = ["pytest>=8", "pytest-cov>=5", "ruff>=0.6", "duckdb>=1.0", "mcp>=1.10", "databricks-sdk>=0.30"]
|
|
42
42
|
|
|
43
43
|
[project.scripts]
|
|
44
44
|
bricksentry = "bricksentry.cli:entry"
|
|
@@ -58,3 +58,23 @@ packages = ["src/bricksentry"]
|
|
|
58
58
|
|
|
59
59
|
[tool.pytest.ini_options]
|
|
60
60
|
testpaths = ["tests"]
|
|
61
|
+
|
|
62
|
+
[tool.ruff]
|
|
63
|
+
line-length = 120
|
|
64
|
+
target-version = "py310"
|
|
65
|
+
builtins = ["dbutils", "spark", "display"] # Databricks notebook globals
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint]
|
|
68
|
+
select = ["E", "F", "W", "I", "UP", "B"]
|
|
69
|
+
ignore = ["E501"]
|
|
70
|
+
|
|
71
|
+
[tool.coverage.run]
|
|
72
|
+
source = ["bricksentry"]
|
|
73
|
+
branch = true
|
|
74
|
+
|
|
75
|
+
[tool.coverage.report]
|
|
76
|
+
show_missing = true
|
|
77
|
+
skip_covered = true
|
|
78
|
+
|
|
79
|
+
[tool.ruff.lint.per-file-ignores]
|
|
80
|
+
"examples/**" = ["E402"] # notebooks import after %pip install cells
|
|
@@ -23,8 +23,8 @@ def cells_from_source(text: str) -> list[dict]:
|
|
|
23
23
|
lines = raw.strip("\n").splitlines()
|
|
24
24
|
if not lines:
|
|
25
25
|
continue
|
|
26
|
-
if all(
|
|
27
|
-
stripped = [
|
|
26
|
+
if all(ln.startswith("# MAGIC") for ln in lines):
|
|
27
|
+
stripped = [ln[len("# MAGIC"):].removeprefix(" ") for ln in lines]
|
|
28
28
|
if stripped[0].startswith("%md"):
|
|
29
29
|
md = stripped[1:]
|
|
30
30
|
cells.append({"cell_type": "markdown", "metadata": {}, "source": _src(md)})
|
|
@@ -36,7 +36,7 @@ def cells_from_source(text: str) -> list[dict]:
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
def _src(lines: list[str]) -> list[str]:
|
|
39
|
-
return [
|
|
39
|
+
return [ln + "\n" for ln in lines[:-1]] + ([lines[-1]] if lines else [])
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
def _code(lines: list[str]) -> dict:
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Agent tools as plain Python functions returning JSON-safe dicts.
|
|
2
|
+
|
|
3
|
+
The MCP server registers these, but they work in any agent framework
|
|
4
|
+
(LangGraph, OpenAI Agents SDK, Databricks Agent Framework...): import and wrap.
|
|
5
|
+
|
|
6
|
+
Errors come back as ``{"error": "..."}`` instead of exceptions, so an agent
|
|
7
|
+
can read them and recover.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import functools
|
|
13
|
+
from typing import Annotated, Any
|
|
14
|
+
|
|
15
|
+
from bricksentry.assess import Sentry
|
|
16
|
+
from bricksentry.explain import explain_diff as _explain_diff
|
|
17
|
+
|
|
18
|
+
try: # pydantic ships with the `mcp` extra; parameter descriptions are optional without it
|
|
19
|
+
from pydantic import Field as _Field
|
|
20
|
+
except ImportError: # pragma: no cover
|
|
21
|
+
_Field = None
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _desc(text: str):
|
|
25
|
+
"""Parameter description that MCP servers expose in the tool schema."""
|
|
26
|
+
return _Field(description=text) if _Field is not None else text
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
_SENTRY: Sentry | None = None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def get_sentry() -> Sentry:
|
|
33
|
+
global _SENTRY
|
|
34
|
+
if _SENTRY is None:
|
|
35
|
+
_SENTRY = Sentry()
|
|
36
|
+
return _SENTRY
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def set_sentry(sentry: Sentry | None) -> None:
|
|
40
|
+
global _SENTRY
|
|
41
|
+
_SENTRY = sentry
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _safe(fn):
|
|
45
|
+
@functools.wraps(fn)
|
|
46
|
+
def wrapper(*args, **kwargs):
|
|
47
|
+
try:
|
|
48
|
+
return fn(*args, **kwargs)
|
|
49
|
+
except Exception as e:
|
|
50
|
+
return {"error": f"{type(e).__name__}: {e}"}
|
|
51
|
+
|
|
52
|
+
return wrapper
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@_safe
|
|
56
|
+
def whats_downstream(
|
|
57
|
+
table: Annotated[str, _desc("Fully qualified table name, e.g. main.sales.orders.")],
|
|
58
|
+
depth: Annotated[int, _desc("How many lineage hops to follow downstream (default 3).")] = 3,
|
|
59
|
+
) -> dict[str, Any]:
|
|
60
|
+
"""List what depends on a table, so you know the blast radius BEFORE you edit it.
|
|
61
|
+
|
|
62
|
+
Use this first, when planning a change. It reads Unity Catalog lineage and
|
|
63
|
+
returns every downstream table, job, notebook, pipeline, dashboard and query,
|
|
64
|
+
up to `depth` hops, with owners and tags. Dropped tables are filtered out.
|
|
65
|
+
Read-only; changes nothing. To check a change you have already made, use
|
|
66
|
+
assess_change instead.
|
|
67
|
+
|
|
68
|
+
Returns {table, owner, tags, count, downstream: [{kind, name, depth, via,
|
|
69
|
+
owner, tags}]}, or {error} if the table or lineage cannot be read."""
|
|
70
|
+
s = get_sentry()
|
|
71
|
+
nodes = s.downstream(table, depth)
|
|
72
|
+
owner, tags = s.lineage.owner_and_tags(table)
|
|
73
|
+
return {
|
|
74
|
+
"table": table,
|
|
75
|
+
"owner": owner,
|
|
76
|
+
"tags": tags,
|
|
77
|
+
"count": len(nodes),
|
|
78
|
+
"downstream": [n.to_dict() for n in nodes],
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@_safe
|
|
83
|
+
def assess_change(
|
|
84
|
+
tables: Annotated[list[str], _desc("Production tables your change affects, fully qualified.")],
|
|
85
|
+
candidates: Annotated[
|
|
86
|
+
dict[str, str] | None,
|
|
87
|
+
_desc(
|
|
88
|
+
"Optional map of production table -> candidate table your change built "
|
|
89
|
+
"(e.g. {'main.sales.orders': 'dev.sales.orders'}). Omit to use the "
|
|
90
|
+
"candidate pattern from bricksentry.yml."
|
|
91
|
+
),
|
|
92
|
+
] = None,
|
|
93
|
+
pr: Annotated[str | None, _desc("Optional pull request number or id, used to name candidates and the report.")] = None,
|
|
94
|
+
) -> dict[str, Any]:
|
|
95
|
+
"""Assess a change that has already been built into candidate tables.
|
|
96
|
+
|
|
97
|
+
Use this after your pipeline change has written candidate (dev/PR) tables.
|
|
98
|
+
For a single SQL write that has not run yet, use preview_write instead.
|
|
99
|
+
For each table it diffs production against the candidate (row, column and
|
|
100
|
+
schema changes, null-safe keys), walks downstream lineage and applies the
|
|
101
|
+
rules in policy.yml. The verdict is deterministic: rules decide, not an LLM.
|
|
102
|
+
Read-only on production and candidates.
|
|
103
|
+
|
|
104
|
+
Returns {id, verdict: pass|warn|needs_human|block, risk_tier, safe_to_ship,
|
|
105
|
+
notify, rule_hits, tables: [{table, verdict, summary, diff, downstream,
|
|
106
|
+
rollback}]}. Pass `id` to safe_to_ship (and optionally explain_diff)."""
|
|
107
|
+
a = get_sentry().assess(list(tables), candidates=candidates, pr=pr)
|
|
108
|
+
return a.to_dict()
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@_safe
|
|
112
|
+
def preview_write(
|
|
113
|
+
sql: Annotated[
|
|
114
|
+
str,
|
|
115
|
+
_desc(
|
|
116
|
+
"Exactly one INSERT, MERGE, UPDATE, DELETE or CREATE OR REPLACE TABLE "
|
|
117
|
+
"statement. Write {{target}} where the table name goes, or use the literal name."
|
|
118
|
+
),
|
|
119
|
+
],
|
|
120
|
+
target: Annotated[str, _desc("Fully qualified production table the statement would write to.")],
|
|
121
|
+
keys: Annotated[
|
|
122
|
+
list[str] | None, _desc("Optional key columns for the row diff. Omit to use keys from bricksentry.yml.")
|
|
123
|
+
] = None,
|
|
124
|
+
) -> dict[str, Any]:
|
|
125
|
+
"""Dry-run ONE write statement on a disposable shallow clone of `target`,
|
|
126
|
+
never on production, and report what it would change plus the policy verdict.
|
|
127
|
+
|
|
128
|
+
Use this before running any direct write. It clones the table, rewrites the
|
|
129
|
+
statement to hit the clone, runs it, diffs clone vs production, applies policy
|
|
130
|
+
and drops the clone, even on failure. DROP, TRUNCATE, ALTER, GRANT and
|
|
131
|
+
multiple statements are refused.
|
|
132
|
+
|
|
133
|
+
Returns the same shape as assess_change (with an `id` for safe_to_ship), or
|
|
134
|
+
{error} if the statement is refused or fails."""
|
|
135
|
+
return get_sentry().preview_write(sql, target, keys=keys)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@_safe
|
|
139
|
+
def explain_diff(
|
|
140
|
+
assessment_id: Annotated[
|
|
141
|
+
str | None, _desc("Id returned by assess_change or preview_write. Give this or `table`.")
|
|
142
|
+
] = None,
|
|
143
|
+
table: Annotated[
|
|
144
|
+
str | None, _desc("Table name, to explain its most recent diff in this session. Give this or `assessment_id`.")
|
|
145
|
+
] = None,
|
|
146
|
+
) -> dict[str, Any]:
|
|
147
|
+
"""Explain in plain English what a diff changed, for a PR description or a
|
|
148
|
+
human reviewer.
|
|
149
|
+
|
|
150
|
+
Use after assess_change or preview_write when you need readable text rather
|
|
151
|
+
than raw numbers, e.g. "removed 1 row (0.00%); revenue sum -3.1%". Read-only.
|
|
152
|
+
Works across processes because assessments are saved to disk.
|
|
153
|
+
|
|
154
|
+
Returns {assessment_id, explanations: {table: text}} when given an id, or
|
|
155
|
+
{table, explanation} when given a table, or {error} if nothing matches."""
|
|
156
|
+
s = get_sentry()
|
|
157
|
+
if assessment_id:
|
|
158
|
+
a = s.get_assessment(assessment_id)
|
|
159
|
+
if a is None:
|
|
160
|
+
return {"error": f"unknown assessment id {assessment_id}"}
|
|
161
|
+
return {"assessment_id": a.id, "explanations": {t.table: t.summary for t in a.tables}}
|
|
162
|
+
if table:
|
|
163
|
+
d = s.get_diff(table)
|
|
164
|
+
if d is None:
|
|
165
|
+
return {"error": f"no diff for {table} yet; call assess_change or preview_write first"}
|
|
166
|
+
return {"table": table, "explanation": _explain_diff(d)}
|
|
167
|
+
return {"error": "pass assessment_id or table"}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@_safe
|
|
171
|
+
def safe_to_ship(
|
|
172
|
+
assessment_id: Annotated[str, _desc("Id returned by assess_change or preview_write.")],
|
|
173
|
+
) -> dict[str, Any]:
|
|
174
|
+
"""Final gate: decide whether to merge or apply a change. Call this last,
|
|
175
|
+
and follow `next_step` exactly.
|
|
176
|
+
|
|
177
|
+
safe_to_ship is true only for pass and warn. For needs_human, do not merge:
|
|
178
|
+
open the PR with the report and request review from the listed owners. For
|
|
179
|
+
block, stop and fix the issues in rule_hits. Never bypass needs_human or
|
|
180
|
+
block. Read-only.
|
|
181
|
+
|
|
182
|
+
Returns {assessment_id, safe_to_ship: bool, verdict, risk_tier, rule_hits:
|
|
183
|
+
[{rule, verdict, table, reason}], notify, next_step}, or {error} if the id
|
|
184
|
+
is unknown."""
|
|
185
|
+
a = get_sentry().get_assessment(assessment_id)
|
|
186
|
+
if a is None:
|
|
187
|
+
return {"error": f"unknown assessment id {assessment_id}"}
|
|
188
|
+
v = a.verdict.value
|
|
189
|
+
next_step = {
|
|
190
|
+
"pass": "Proceed: open or merge the pull request.",
|
|
191
|
+
"warn": "Proceed, but include the warnings in the pull request description.",
|
|
192
|
+
"needs_human": "Do not merge. Open the pull request with the report and request review from: "
|
|
193
|
+
+ (", ".join(a.notify) or "a data owner") + ".",
|
|
194
|
+
"block": "Stop. Fix the blocking issues listed in rule_hits, rebuild the candidate and assess again.",
|
|
195
|
+
}[v]
|
|
196
|
+
return {
|
|
197
|
+
"assessment_id": a.id,
|
|
198
|
+
"safe_to_ship": v in ("pass", "warn"),
|
|
199
|
+
"verdict": v,
|
|
200
|
+
"risk_tier": a.verdict.risk_tier,
|
|
201
|
+
"rule_hits": [h.to_dict() for h in a.hits],
|
|
202
|
+
"notify": a.notify,
|
|
203
|
+
"next_step": next_step,
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
@_safe
|
|
208
|
+
def rollback_plan(
|
|
209
|
+
table: Annotated[str, _desc("Fully qualified Delta table name.")],
|
|
210
|
+
) -> dict[str, Any]:
|
|
211
|
+
"""Get the exact SQL to restore `table` to its current Delta version.
|
|
212
|
+
|
|
213
|
+
Call this BEFORE applying a change and keep the SQL (e.g. in the PR or job
|
|
214
|
+
log), so undo is one statement if the change goes wrong. Read-only: it reads
|
|
215
|
+
DESCRIBE HISTORY and runs nothing.
|
|
216
|
+
|
|
217
|
+
Returns {table, current_version, rollback_sql}, e.g. "RESTORE TABLE
|
|
218
|
+
main.sales.orders TO VERSION AS OF 42", or {error}."""
|
|
219
|
+
s = get_sentry()
|
|
220
|
+
return {
|
|
221
|
+
"table": table,
|
|
222
|
+
"current_version": s.backend.current_version(table),
|
|
223
|
+
"rollback_sql": s.rollback_plan(table),
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
TOOLS = [whats_downstream, assess_change, preview_write, explain_diff, safe_to_ship, rollback_plan]
|
|
228
|
+
READ_ONLY = {"whats_downstream", "assess_change", "explain_diff", "safe_to_ship", "rollback_plan"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
5
7
|
import uuid
|
|
6
8
|
from typing import Any
|
|
7
9
|
|
|
@@ -49,6 +51,7 @@ class Sentry:
|
|
|
49
51
|
sample_pct=sample_pct if sample_pct is not None else self.config.sample_pct,
|
|
50
52
|
segment_by=spec.segment_by,
|
|
51
53
|
max_samples=self.config.max_samples,
|
|
54
|
+
sample_guard=self.config.sample_guard,
|
|
52
55
|
)
|
|
53
56
|
self._diffs[d.table] = d
|
|
54
57
|
return d
|
|
@@ -126,6 +129,32 @@ class Sentry:
|
|
|
126
129
|
notify=sorted(notify),
|
|
127
130
|
)
|
|
128
131
|
self._assessments[a.id] = a
|
|
132
|
+
self._save(a)
|
|
133
|
+
return a
|
|
134
|
+
|
|
135
|
+
# --- saved assessments -------------------------------------------------
|
|
136
|
+
def _save(self, a: Assessment) -> None:
|
|
137
|
+
"""Save an assessment as JSON so another Sentry (another process, the MCP
|
|
138
|
+
server, a later notebook cell) can look it up by id. Best effort."""
|
|
139
|
+
folder = self.config.store_dir()
|
|
140
|
+
if folder is None:
|
|
141
|
+
return
|
|
142
|
+
try:
|
|
143
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
144
|
+
(folder / f"{a.id}.json").write_text(json.dumps(a.to_dict(), default=str))
|
|
145
|
+
except OSError:
|
|
146
|
+
pass
|
|
147
|
+
|
|
148
|
+
def _load(self, assessment_id: str) -> Assessment | None:
|
|
149
|
+
folder = self.config.store_dir()
|
|
150
|
+
if folder is None or not re.fullmatch(r"[0-9a-f]{1,64}", assessment_id or ""):
|
|
151
|
+
return None
|
|
152
|
+
f = folder / f"{assessment_id}.json"
|
|
153
|
+
try:
|
|
154
|
+
a = Assessment.from_dict(json.loads(f.read_text()))
|
|
155
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
156
|
+
return None
|
|
157
|
+
self._assessments[a.id] = a
|
|
129
158
|
return a
|
|
130
159
|
|
|
131
160
|
def preview_write(
|
|
@@ -159,7 +188,7 @@ class Sentry:
|
|
|
159
188
|
|
|
160
189
|
# --- lookups for agents -------------------------------------------------
|
|
161
190
|
def get_assessment(self, assessment_id: str) -> Assessment | None:
|
|
162
|
-
return self._assessments.get(assessment_id)
|
|
191
|
+
return self._assessments.get(assessment_id) or self._load(assessment_id)
|
|
163
192
|
|
|
164
193
|
def get_diff(self, table: str) -> TableDiff | None:
|
|
165
194
|
return self._diffs.get(table)
|