bricksentry 0.1.16__tar.gz → 0.1.18__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.16 → bricksentry-0.1.18}/CHANGELOG.md +15 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/PKG-INFO +24 -9
- {bricksentry-0.1.16 → bricksentry-0.1.18}/README.md +23 -8
- bricksentry-0.1.18/deploy/databricks-app/requirements.txt +1 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/pyproject.toml +1 -1
- bricksentry-0.1.18/scripts/render_demo_image.py +115 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/server.json +2 -2
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/__init__.py +1 -1
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/demo.py +80 -15
- bricksentry-0.1.18/src/bricksentry/job_demo.py +71 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/templates/job-check/databricks_template_schema.json +18 -8
- {bricksentry-0.1.16 → bricksentry-0.1.18}/templates/job-check/template/{{.project_name}}/README.md.tmpl +20 -2
- {bricksentry-0.1.16 → bricksentry-0.1.18}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +53 -0
- bricksentry-0.1.18/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +7 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_0114.py +97 -10
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_demo.py +6 -0
- bricksentry-0.1.16/deploy/databricks-app/requirements.txt +0 -1
- {bricksentry-0.1.16 → bricksentry-0.1.18}/.gitignore +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/LICENSE +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/SECURITY.md +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/action.yml +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/deploy/databricks-app/README.md +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/deploy/databricks-app/app.yaml +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/deploy/databricks-app/bricksentry.yml +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/deploy/databricks-app/databricks.yml +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/deploy/databricks-app/grants.sql +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/bricksentry_check_my_table.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/bricksentry_quickstart.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/databricks/policy.yml +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/scripts/build_notebook.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/__main__.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/agent_tools.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/assess.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/backends/base.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/backends/databricks_backend.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/backends/duckdb_backend.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/cli.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/config.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/diff.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/explain.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/github.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/history.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/job.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/lineage.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/models.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/notify.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/policy.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/policy_templates.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/src/bricksentry/report.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/templates/job-check/README.md +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/conftest.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_0110.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_0112.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_018.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_019.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_check_notebook.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_diff.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_hr_notebook.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_notify_templates.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.16 → bricksentry-0.1.18}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.18 (2026-11-12)
|
|
4
|
+
|
|
5
|
+
See a block in your own workspace within minutes of `bundle init`.
|
|
6
|
+
|
|
7
|
+
- The job template asks whether to add a **demo job** (default yes). `databricks bundle run bricksentry_demo` creates a 20,000-row demo table in your scratch schema, runs a MERGE whose ON condition compares region case-sensitively (so 25 orders are inserted again as duplicates), then checks that change. The run ends red with BLOCK, the rules that fired and the `RESTORE` that undoes it, plus the Slack alert if you set one up. It writes only to `bricksentry_demo_*` tables.
|
|
8
|
+
- `python -m bricksentry.job_demo`: the task that makes the demo change.
|
|
9
|
+
- Slack is now presented as optional in the template prompt, and the success message lists the next commands.
|
|
10
|
+
- The template README no longer says the trigger is paused in the dev target: the job sets `pause_status: UNPAUSED` on its trigger, which development mode respects.
|
|
11
|
+
|
|
12
|
+
## 0.1.17 (2026-11-12)
|
|
13
|
+
|
|
14
|
+
- `bricksentry demo` now ends with a pipeline commit: a nightly MERGE with a wrong match condition lands, `check-last-change` finds it in the table history (skipping the OPTIMIZE after it), blocks it for 25 duplicate keys, prints the `RESTORE` and applies it. It replaces the old step 2, which only described a rollback because DuckDB has no table history; the demo now keeps versions itself. It still runs offline in about a second and ends with the one-command Databricks setup.
|
|
15
|
+
- The README opens with three steps, each on more real data: the 30-second demo on your laptop (`uvx --from "bricksentry[duckdb]" bricksentry demo`, nothing to install first), checking every change to your tables on Databricks with the bundle template, and stopping bad changes inside your pipeline job, in CI or for AI agents.
|
|
16
|
+
- New demo screenshot, generated from the real output by `scripts/render_demo_image.py`.
|
|
17
|
+
|
|
3
18
|
## 0.1.16 (2026-11-11)
|
|
4
19
|
|
|
5
20
|
From the live test of 0.1.15 on Databricks serverless:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.18
|
|
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
|
|
@@ -55,22 +55,37 @@ Description-Content-Type: text/markdown
|
|
|
55
55
|
|
|
56
56
|
Change-safety for Databricks pipelines and the AI agents that edit them: know what a change does to your data before it ships.
|
|
57
57
|
|
|
58
|
-
**[Try it in 30 seconds](#try-it-in-30-seconds-
|
|
58
|
+
**[Try it in 30 seconds](#1-try-it-in-30-seconds-on-your-laptop)** · **[Check every change on Databricks](#2-check-every-change-to-your-tables-on-databricks)** · **[Docs: bricksentry.org](https://bricksentry.org)** · **[LinkedIn](https://www.linkedin.com/company/bricksentry-org/)**
|
|
59
59
|
|
|
60
60
|
Built by Brahmareddy, Databricks Champion. Open source under Apache-2.0.
|
|
61
61
|
|
|
62
62
|
*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.
|
|
63
63
|
|
|
64
|
-
##
|
|
64
|
+
## Three steps, each on more real data
|
|
65
|
+
|
|
66
|
+
### 1. Try it in 30 seconds, on your laptop
|
|
65
67
|
|
|
66
68
|
```bash
|
|
67
|
-
|
|
68
|
-
bricksentry demo
|
|
69
|
+
uvx --from "bricksentry[duckdb]" bricksentry demo
|
|
69
70
|
```
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
(Or `pip install "bricksentry[duckdb]"` and then `bricksentry demo`.) No Databricks account and nothing leaves your machine: it runs on a 20,000-row revenue table in local DuckDB. An AI agent previews a DELETE on a clone (production untouched), gets its pull request **blocked** for a join that duplicates 40 orders, fixes it, and is routed to the owners of a certified table downstream. Then a nightly pipeline commits a bad MERGE anyway: bricksentry finds it in the table history, skips the OPTIMIZE after it, **blocks** it for 25 duplicate keys, prints the `RESTORE` and applies it.
|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+
### 2. Check every change to your tables, on Databricks
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
databricks bundle init https://github.com/bricksentry/bricksentry --template-dir templates/job-check
|
|
80
|
+
cd bricksentry_check && databricks bundle deploy
|
|
81
|
+
databricks bundle run bricksentry_demo # optional: see a block on a demo table in about 2 minutes
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
One command and a few prompts give you a serverless job that runs after every commit to the tables you pick: the same check as the demo's last step, on your data, with the `RESTORE` that undoes a bad change and an optional Slack alert. The optional demo job writes a known-bad MERGE to a demo table in your scratch schema and checks it, so your first run ends red with a block. [Details below](#check-every-pipeline-run-automatically-asset-bundle).
|
|
85
|
+
|
|
86
|
+
### 3. Stop bad changes before anything reads them
|
|
72
87
|
|
|
73
|
-
|
|
88
|
+
Put the check inside your pipeline job, right after the task that writes the table: a `block` fails that task and the tasks downstream don't run. Or run it on pull requests with the [GitHub Action](#for-data-engineers-cli-and-ci), and give AI agents the same checks through the [MCP server](#for-ai-agents-the-mcp-server).
|
|
74
89
|
|
|
75
90
|
## Run it in your Databricks workspace
|
|
76
91
|
|
|
@@ -83,14 +98,14 @@ Point the [check-my-table notebook](examples/databricks/bricksentry_check_my_tab
|
|
|
83
98
|
|
|
84
99
|
If it shows you something, please [share what it found](https://github.com/bricksentry/bricksentry/issues/new?template=it_caught_this.yml) (no table names needed). Real results decide what gets built next.
|
|
85
100
|
|
|
86
|
-
### Check every pipeline run automatically (Asset Bundle
|
|
101
|
+
### Check every pipeline run automatically (Asset Bundle)
|
|
87
102
|
|
|
88
103
|
```bash
|
|
89
104
|
databricks bundle init https://github.com/bricksentry/bricksentry --template-dir templates/job-check
|
|
90
105
|
cd bricksentry_check && databricks bundle deploy -t prod
|
|
91
106
|
```
|
|
92
107
|
|
|
93
|
-
Answer a few prompts (tables to watch, SQL warehouse, scratch schema, policy, optional Slack webhook secret). You get a serverless job with a **table update trigger**: whenever a watched table changes, it checks the change, sends the alert and logs the `RESTORE` that undoes it. To stop downstream tasks when a change is bad, add the same check as a task inside your pipeline job, right after the write (the generated README shows the YAML): with `--since {{job.start_time.iso_datetime}}` it checks everything the run wrote, and a `block` verdict fails the task so the tasks after it don't run.
|
|
108
|
+
Answer a few prompts (tables to watch, key columns if they have no primary key, SQL warehouse, scratch schema, whether to add the demo job, policy, optional Slack webhook secret). You get a serverless job with a **table update trigger**: whenever a watched table changes, it checks the change, sends the alert and logs the `RESTORE` that undoes it. To stop downstream tasks when a change is bad, add the same check as a task inside your pipeline job, right after the write (the generated README shows the YAML): with `--since {{job.start_time.iso_datetime}}` it checks everything the run wrote, and a `block` verdict fails the task so the tasks after it don't run.
|
|
94
109
|
|
|
95
110
|
From the command line, the same check is one command:
|
|
96
111
|
|
|
@@ -8,22 +8,37 @@
|
|
|
8
8
|
|
|
9
9
|
Change-safety for Databricks pipelines and the AI agents that edit them: know what a change does to your data before it ships.
|
|
10
10
|
|
|
11
|
-
**[Try it in 30 seconds](#try-it-in-30-seconds-
|
|
11
|
+
**[Try it in 30 seconds](#1-try-it-in-30-seconds-on-your-laptop)** · **[Check every change on Databricks](#2-check-every-change-to-your-tables-on-databricks)** · **[Docs: bricksentry.org](https://bricksentry.org)** · **[LinkedIn](https://www.linkedin.com/company/bricksentry-org/)**
|
|
12
12
|
|
|
13
13
|
Built by Brahmareddy, Databricks Champion. Open source under Apache-2.0.
|
|
14
14
|
|
|
15
15
|
*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.
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## Three steps, each on more real data
|
|
18
|
+
|
|
19
|
+
### 1. Try it in 30 seconds, on your laptop
|
|
18
20
|
|
|
19
21
|
```bash
|
|
20
|
-
|
|
21
|
-
bricksentry demo
|
|
22
|
+
uvx --from "bricksentry[duckdb]" bricksentry demo
|
|
22
23
|
```
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
(Or `pip install "bricksentry[duckdb]"` and then `bricksentry demo`.) No Databricks account and nothing leaves your machine: it runs on a 20,000-row revenue table in local DuckDB. An AI agent previews a DELETE on a clone (production untouched), gets its pull request **blocked** for a join that duplicates 40 orders, fixes it, and is routed to the owners of a certified table downstream. Then a nightly pipeline commits a bad MERGE anyway: bricksentry finds it in the table history, skips the OPTIMIZE after it, **blocks** it for 25 duplicate keys, prints the `RESTORE` and applies it.
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
### 2. Check every change to your tables, on Databricks
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
databricks bundle init https://github.com/bricksentry/bricksentry --template-dir templates/job-check
|
|
33
|
+
cd bricksentry_check && databricks bundle deploy
|
|
34
|
+
databricks bundle run bricksentry_demo # optional: see a block on a demo table in about 2 minutes
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
One command and a few prompts give you a serverless job that runs after every commit to the tables you pick: the same check as the demo's last step, on your data, with the `RESTORE` that undoes a bad change and an optional Slack alert. The optional demo job writes a known-bad MERGE to a demo table in your scratch schema and checks it, so your first run ends red with a block. [Details below](#check-every-pipeline-run-automatically-asset-bundle).
|
|
38
|
+
|
|
39
|
+
### 3. Stop bad changes before anything reads them
|
|
25
40
|
|
|
26
|
-
|
|
41
|
+
Put the check inside your pipeline job, right after the task that writes the table: a `block` fails that task and the tasks downstream don't run. Or run it on pull requests with the [GitHub Action](#for-data-engineers-cli-and-ci), and give AI agents the same checks through the [MCP server](#for-ai-agents-the-mcp-server).
|
|
27
42
|
|
|
28
43
|
## Run it in your Databricks workspace
|
|
29
44
|
|
|
@@ -36,14 +51,14 @@ Point the [check-my-table notebook](examples/databricks/bricksentry_check_my_tab
|
|
|
36
51
|
|
|
37
52
|
If it shows you something, please [share what it found](https://github.com/bricksentry/bricksentry/issues/new?template=it_caught_this.yml) (no table names needed). Real results decide what gets built next.
|
|
38
53
|
|
|
39
|
-
### Check every pipeline run automatically (Asset Bundle
|
|
54
|
+
### Check every pipeline run automatically (Asset Bundle)
|
|
40
55
|
|
|
41
56
|
```bash
|
|
42
57
|
databricks bundle init https://github.com/bricksentry/bricksentry --template-dir templates/job-check
|
|
43
58
|
cd bricksentry_check && databricks bundle deploy -t prod
|
|
44
59
|
```
|
|
45
60
|
|
|
46
|
-
Answer a few prompts (tables to watch, SQL warehouse, scratch schema, policy, optional Slack webhook secret). You get a serverless job with a **table update trigger**: whenever a watched table changes, it checks the change, sends the alert and logs the `RESTORE` that undoes it. To stop downstream tasks when a change is bad, add the same check as a task inside your pipeline job, right after the write (the generated README shows the YAML): with `--since {{job.start_time.iso_datetime}}` it checks everything the run wrote, and a `block` verdict fails the task so the tasks after it don't run.
|
|
61
|
+
Answer a few prompts (tables to watch, key columns if they have no primary key, SQL warehouse, scratch schema, whether to add the demo job, policy, optional Slack webhook secret). You get a serverless job with a **table update trigger**: whenever a watched table changes, it checks the change, sends the alert and logs the `RESTORE` that undoes it. To stop downstream tasks when a change is bad, add the same check as a task inside your pipeline job, right after the write (the generated README shows the YAML): with `--since {{job.start_time.iso_datetime}}` it checks everything the run wrote, and a `block` verdict fails the task so the tasks after it don't run.
|
|
47
62
|
|
|
48
63
|
From the command line, the same check is one command:
|
|
49
64
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bricksentry[databricks,mcp]==0.1.18
|
|
@@ -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.18"
|
|
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"
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""Render `bricksentry demo` output as docs/images/demo.png (terminal-window style).
|
|
2
|
+
|
|
3
|
+
python scripts/render_demo_image.py # needs: playwright + chromium
|
|
4
|
+
|
|
5
|
+
Runs the demo with colors on, converts the ANSI output to HTML and screenshots it.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import html
|
|
11
|
+
import io
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
from contextlib import redirect_stdout
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
OUT = Path(__file__).resolve().parents[1] / "docs" / "images" / "demo.png"
|
|
18
|
+
COMMAND = 'uvx --from "bricksentry[duckdb]" bricksentry demo'
|
|
19
|
+
|
|
20
|
+
BASIC = {30: "#1e293b", 31: "#e5484d", 32: "#22c55e", 33: "#e5a93b", 34: "#60a5fa", 35: "#c084fc",
|
|
21
|
+
36: "#22c4c4", 37: "#e2e8f0", 90: "#7d8794", 91: "#f87171", 92: "#4ade80", 93: "#facc15",
|
|
22
|
+
94: "#93c5fd", 95: "#e879f9", 96: "#67e8f9", 97: "#ffffff"}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def capture() -> str:
|
|
26
|
+
import click
|
|
27
|
+
|
|
28
|
+
from bricksentry.demo import run_demo
|
|
29
|
+
|
|
30
|
+
buf = io.StringIO()
|
|
31
|
+
orig = click.echo
|
|
32
|
+
|
|
33
|
+
def echo(message=None, **kw): # keep ANSI codes when writing to a StringIO
|
|
34
|
+
kw["color"] = True
|
|
35
|
+
return orig(message, **kw)
|
|
36
|
+
|
|
37
|
+
click.echo = echo
|
|
38
|
+
try:
|
|
39
|
+
with redirect_stdout(buf):
|
|
40
|
+
run_demo()
|
|
41
|
+
finally:
|
|
42
|
+
click.echo = orig
|
|
43
|
+
return buf.getvalue()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def ansi_to_html(text: str) -> str:
|
|
47
|
+
out: list[str] = []
|
|
48
|
+
state: dict[str, str] = {}
|
|
49
|
+
pos = 0
|
|
50
|
+
for m in re.finditer(r"\x1b\[([0-9;]*)m", text):
|
|
51
|
+
out.append(_span(text[pos:m.start()], state))
|
|
52
|
+
codes = [int(c) for c in m.group(1).split(";") if c] or [0]
|
|
53
|
+
i = 0
|
|
54
|
+
while i < len(codes):
|
|
55
|
+
c = codes[i]
|
|
56
|
+
if c == 0:
|
|
57
|
+
state = {}
|
|
58
|
+
elif c == 1:
|
|
59
|
+
state["font-weight"] = "700"
|
|
60
|
+
elif c == 4:
|
|
61
|
+
state["text-decoration"] = "underline"
|
|
62
|
+
elif c in BASIC:
|
|
63
|
+
state["color"] = BASIC[c]
|
|
64
|
+
elif c in (38, 48) and codes[i + 1:i + 2] == [2]:
|
|
65
|
+
r, g, b = codes[i + 2:i + 5]
|
|
66
|
+
key = "color" if c == 38 else "background"
|
|
67
|
+
state[key] = f"rgb({r},{g},{b})"
|
|
68
|
+
if c == 48:
|
|
69
|
+
state["padding"] = "0 2px"
|
|
70
|
+
i += 4
|
|
71
|
+
i += 1
|
|
72
|
+
pos = m.end()
|
|
73
|
+
out.append(_span(text[pos:], state))
|
|
74
|
+
return "".join(out)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _span(s: str, state: dict[str, str]) -> str:
|
|
78
|
+
if not s:
|
|
79
|
+
return ""
|
|
80
|
+
s = html.escape(s)
|
|
81
|
+
if not state:
|
|
82
|
+
return s
|
|
83
|
+
return f'<span style="{";".join(f"{k}:{v}" for k, v in state.items())}">{s}</span>'
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
PAGE = """<!doctype html><html><head><meta charset="utf-8"><style>
|
|
87
|
+
body{{margin:0;background:transparent}}
|
|
88
|
+
.win{{width:1180px;background:#0f172a;border-radius:12px;overflow:hidden;font:15px/1.6 'DejaVu Sans Mono',monospace;color:#e2e8f0}}
|
|
89
|
+
.bar{{background:#1a2740;padding:10px 16px;display:flex;gap:8px;align-items:center;color:#94a3b8;font-size:13px}}
|
|
90
|
+
.dot{{width:12px;height:12px;border-radius:50%;display:inline-block}}
|
|
91
|
+
pre{{margin:0;padding:18px 24px 26px;white-space:pre-wrap;font:inherit}}
|
|
92
|
+
.cmd{{color:#a5b4fc}}
|
|
93
|
+
</style></head><body><div class="win"><div class="bar"><span class="dot" style="background:#ff5f57"></span>
|
|
94
|
+
<span class="dot" style="background:#e5a93b"></span><span class="dot" style="background:#28c840"></span>
|
|
95
|
+
<span style="margin-left:12px">bricksentry demo</span></div><pre><span class="cmd">$ {cmd}</span>
|
|
96
|
+
|
|
97
|
+
{body}</pre></div></body></html>"""
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def main() -> None:
|
|
101
|
+
from playwright.sync_api import sync_playwright
|
|
102
|
+
|
|
103
|
+
body = ansi_to_html(capture().rstrip("\n"))
|
|
104
|
+
page_html = PAGE.format(cmd=html.escape(COMMAND), body=body)
|
|
105
|
+
with sync_playwright() as p:
|
|
106
|
+
b = p.chromium.launch()
|
|
107
|
+
page = b.new_page(device_scale_factor=2, viewport={"width": 1180, "height": 800})
|
|
108
|
+
page.set_content(page_html)
|
|
109
|
+
page.locator(".win").screenshot(path=str(OUT), omit_background=True)
|
|
110
|
+
b.close()
|
|
111
|
+
print(f"wrote {OUT}", file=sys.stderr)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
if __name__ == "__main__":
|
|
115
|
+
main()
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
10
|
"websiteUrl": "https://bricksentry.org",
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.18",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"identifier": "bricksentry-mcp",
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.18",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
"""``bricksentry demo``: the whole
|
|
1
|
+
"""``bricksentry demo``: the whole safety loop in about 30 seconds, locally.
|
|
2
2
|
|
|
3
3
|
Runs on an in-memory DuckDB database with a 20,000-row orders table and a small
|
|
4
4
|
lineage graph, so it needs no Databricks workspace and no data leaves your machine.
|
|
5
|
+
Steps 1-4: an AI agent previews a delete, gets its pull request blocked, fixes it.
|
|
6
|
+
Step 5: a bad pipeline commit lands anyway; ``check-last-change`` catches it from the
|
|
7
|
+
table history and the undo is applied. DuckDB has no table history, so the demo keeps
|
|
8
|
+
versions itself; on Databricks the same check reads Delta history.
|
|
5
9
|
"""
|
|
6
10
|
|
|
7
11
|
from __future__ import annotations
|
|
@@ -16,6 +20,7 @@ from bricksentry.assess import Sentry
|
|
|
16
20
|
from bricksentry.config import Config
|
|
17
21
|
|
|
18
22
|
DOCS_URL = "https://bricksentry.org/docs"
|
|
23
|
+
BUNDLE_CMD = "databricks bundle init https://github.com/bricksentry/bricksentry --template-dir templates/job-check"
|
|
19
24
|
|
|
20
25
|
CONFIG: dict[str, Any] = {
|
|
21
26
|
"sandbox_schema": "sandbox",
|
|
@@ -65,6 +70,13 @@ FROM sales.orders
|
|
|
65
70
|
|
|
66
71
|
DELETE_SQL = "DELETE FROM sales.orders WHERE status <> 'paid'"
|
|
67
72
|
|
|
73
|
+
# A nightly pipeline whose MERGE matches on the wrong column: 25 existing orders come
|
|
74
|
+
# back as new rows (duplicate keys) instead of updating in place.
|
|
75
|
+
BAD_MERGE_SQL = """
|
|
76
|
+
INSERT INTO sales.orders
|
|
77
|
+
SELECT order_id, region, round(amount * 1.05, 2), status FROM sales.orders WHERE order_id % 800 = 0
|
|
78
|
+
"""
|
|
79
|
+
|
|
68
80
|
# Same verdict colors as the website: pass green, warn amber, needs_human orange, block red.
|
|
69
81
|
_COLORS: dict[str, Any] = {"pass": (29, 160, 100), "warn": (214, 160, 40), "needs_human": (235, 115, 40), "block": (210, 40, 50)}
|
|
70
82
|
|
|
@@ -97,12 +109,45 @@ def _hits(rule_hits: list[dict[str, Any]]) -> None:
|
|
|
97
109
|
_line(click.style(f"[{h['verdict']}]", fg=_COLORS.get(h["verdict"], "white")) + f" {h['rule']}: {h['reason']}")
|
|
98
110
|
|
|
99
111
|
|
|
112
|
+
def _versioned_backend():
|
|
113
|
+
"""DuckDB plus a minimal table history (snapshots), so step 5 can run offline."""
|
|
114
|
+
from bricksentry.backends.duckdb_backend import DuckDBBackend
|
|
115
|
+
|
|
116
|
+
class VersionedDuckDB(DuckDBBackend):
|
|
117
|
+
supports_time_travel = True
|
|
118
|
+
|
|
119
|
+
def __init__(self) -> None:
|
|
120
|
+
super().__init__()
|
|
121
|
+
self._history: list[dict[str, Any]] = []
|
|
122
|
+
|
|
123
|
+
def commit(self, table: str, operation: str, sql: str | None = None) -> int:
|
|
124
|
+
if sql:
|
|
125
|
+
self.execute(sql)
|
|
126
|
+
v = len(self._history)
|
|
127
|
+
self.execute(f"CREATE SCHEMA IF NOT EXISTS _history; "
|
|
128
|
+
f"CREATE OR REPLACE TABLE _history.{table.replace('.', '__')}_v{v} AS SELECT * FROM {table}")
|
|
129
|
+
self._history.append({"version": v, "operation": operation, "timestamp": ""})
|
|
130
|
+
return v
|
|
131
|
+
|
|
132
|
+
def history(self, table: str, limit: int = 50) -> list[dict[str, Any]]:
|
|
133
|
+
return list(reversed(self._history))[:limit]
|
|
134
|
+
|
|
135
|
+
def clone_version(self, source: str, target: str, version: int) -> None:
|
|
136
|
+
self.execute(f"CREATE OR REPLACE TABLE {target} AS "
|
|
137
|
+
f"SELECT * FROM _history.{source.replace('.', '__')}_v{int(version)}")
|
|
138
|
+
|
|
139
|
+
def restore(self, table: str, version: int) -> int:
|
|
140
|
+
self.execute(f"CREATE OR REPLACE TABLE {table} AS "
|
|
141
|
+
f"SELECT * FROM _history.{table.replace('.', '__')}_v{int(version)}")
|
|
142
|
+
return self.commit(table, "RESTORE")
|
|
143
|
+
|
|
144
|
+
return VersionedDuckDB()
|
|
145
|
+
|
|
146
|
+
|
|
100
147
|
def run_demo(report_path: str | None = None) -> dict[str, Any]:
|
|
101
148
|
"""Run the demo, print it, and return the key results (used by tests)."""
|
|
102
149
|
try:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
backend = DuckDBBackend()
|
|
150
|
+
backend = _versioned_backend()
|
|
106
151
|
except ImportError:
|
|
107
152
|
# Raised without the inner traceback so a notebook shows one clear line.
|
|
108
153
|
raise ImportError(
|
|
@@ -112,6 +157,7 @@ def run_demo(report_path: str | None = None) -> dict[str, Any]:
|
|
|
112
157
|
|
|
113
158
|
backend.execute("CREATE SCHEMA sales; CREATE SCHEMA sales_pr_42")
|
|
114
159
|
backend.execute(SEED_SQL)
|
|
160
|
+
backend.commit("sales.orders", "CREATE TABLE AS SELECT")
|
|
115
161
|
sentry = Sentry(Config.from_dict({**CONFIG, "assessment_store": False}), backend=backend)
|
|
116
162
|
previous = agent_tools._SENTRY
|
|
117
163
|
agent_tools.set_sentry(sentry)
|
|
@@ -121,7 +167,8 @@ def run_demo(report_path: str | None = None) -> dict[str, Any]:
|
|
|
121
167
|
click.style("bricksentry demo", bold=True)
|
|
122
168
|
+ click.style(" · 20,000-row sales.orders on local DuckDB; nothing leaves your machine", fg="bright_black")
|
|
123
169
|
)
|
|
124
|
-
click.echo(click.style("An AI agent
|
|
170
|
+
click.echo(click.style("An AI agent changes a revenue table, then a pipeline does. Watch what bricksentry says.",
|
|
171
|
+
fg="bright_black"))
|
|
125
172
|
total = 5
|
|
126
173
|
|
|
127
174
|
_step(1, total, "Before editing: what depends on sales.orders?", "whats_downstream")
|
|
@@ -146,12 +193,7 @@ def run_demo(report_path: str | None = None) -> dict[str, Any]:
|
|
|
146
193
|
walk("sales.orders", "")
|
|
147
194
|
results["downstream_count"] = ds["count"]
|
|
148
195
|
|
|
149
|
-
_step(2, total, "
|
|
150
|
-
_line("On Databricks this returns the exact command, e.g.", fg="bright_black")
|
|
151
|
-
_line("RESTORE TABLE `main`.`sales`.`orders` TO VERSION AS OF 41")
|
|
152
|
-
_line("(DuckDB has no table history, so the demo skips it.)", fg="bright_black")
|
|
153
|
-
|
|
154
|
-
_step(3, total, "Agent wants to delete refunded orders. It previews first", "preview_write")
|
|
196
|
+
_step(2, total, "Agent wants to delete refunded orders. It previews first", "preview_write")
|
|
155
197
|
_line(DELETE_SQL, fg="bright_black")
|
|
156
198
|
p = agent_tools.preview_write(DELETE_SQL, "sales.orders")
|
|
157
199
|
_line(_verdict(p["verdict"]) + " " + _short(p["tables"][0]["summary"]))
|
|
@@ -161,7 +203,7 @@ def run_demo(report_path: str | None = None) -> dict[str, Any]:
|
|
|
161
203
|
results["preview_verdict"] = p["verdict"]
|
|
162
204
|
results["production_rows_after_preview"] = prod_rows
|
|
163
205
|
|
|
164
|
-
_step(
|
|
206
|
+
_step(3, total, "Agent opens PR #42 instead. Its join has a fan-out bug", "assess_change")
|
|
165
207
|
backend.execute(BUGGY_SQL)
|
|
166
208
|
a = agent_tools.assess_change(["sales.orders"], pr="42")
|
|
167
209
|
_line(_verdict(a["verdict"]) + f" risk {a['risk_tier']}")
|
|
@@ -170,7 +212,7 @@ def run_demo(report_path: str | None = None) -> dict[str, Any]:
|
|
|
170
212
|
_line("next_step: " + gate["next_step"], fg="cyan")
|
|
171
213
|
results["buggy_verdict"] = a["verdict"]
|
|
172
214
|
|
|
173
|
-
_step(
|
|
215
|
+
_step(4, total, "Agent fixes the join, rebuilds and checks again", "assess_change → safe_to_ship")
|
|
174
216
|
backend.execute(FIXED_SQL)
|
|
175
217
|
a2 = agent_tools.assess_change(["sales.orders"], pr="42")
|
|
176
218
|
explanation = agent_tools.explain_diff(assessment_id=a2["id"])["explanations"]["sales.orders"]
|
|
@@ -181,6 +223,26 @@ def run_demo(report_path: str | None = None) -> dict[str, Any]:
|
|
|
181
223
|
results["fixed_verdict"] = a2["verdict"]
|
|
182
224
|
results["notify"] = gate2["notify"]
|
|
183
225
|
|
|
226
|
+
_step(5, total, "Later, a nightly pipeline commits a bad MERGE", "check-last-change")
|
|
227
|
+
backend.commit("sales.orders", "MERGE", BAD_MERGE_SQL)
|
|
228
|
+
backend.commit("sales.orders", "OPTIMIZE")
|
|
229
|
+
a3, change = sentry.check_change("sales.orders")
|
|
230
|
+
t3 = a3.tables[0]
|
|
231
|
+
_line(f"History: v2 OPTIMIZE (skipped, no data change) · v1 MERGE, checked against v{change.base_version}",
|
|
232
|
+
fg="bright_black")
|
|
233
|
+
_line(_verdict(a3.verdict.value) + " " + _short(t3.summary.split(": ", 1)[-1]))
|
|
234
|
+
_hits([{"verdict": h.verdict.value, "rule": h.rule, "reason": h.reason} for h in t3.hits
|
|
235
|
+
if h.verdict.value in ("block", "needs_human")])
|
|
236
|
+
undo = t3.rollback.replace('"', "")
|
|
237
|
+
_line("Undo: " + undo, fg="cyan")
|
|
238
|
+
backend.restore("sales.orders", change.base_version)
|
|
239
|
+
rows = backend.scalar("SELECT COUNT(*) FROM sales.orders")
|
|
240
|
+
dups = backend.scalar("SELECT COUNT(*) - COUNT(DISTINCT order_id) FROM sales.orders")
|
|
241
|
+
_line(f"Applied the undo: sales.orders is back to {rows:,} rows, {dups} duplicate keys.", fg="green")
|
|
242
|
+
results["commit_verdict"] = a3.verdict.value
|
|
243
|
+
results["undo"] = undo
|
|
244
|
+
results["rows_after_undo"] = rows
|
|
245
|
+
|
|
184
246
|
if report_path:
|
|
185
247
|
from bricksentry.report import to_markdown
|
|
186
248
|
|
|
@@ -189,8 +251,11 @@ def run_demo(report_path: str | None = None) -> dict[str, Any]:
|
|
|
189
251
|
click.echo(f"Wrote {report_path}: the pull-request comment a reviewer would see.")
|
|
190
252
|
|
|
191
253
|
click.echo()
|
|
192
|
-
click.echo(click.style("The agent was stopped
|
|
193
|
-
|
|
254
|
+
click.echo(click.style("The agent was stopped, fixed its change and handed the call to the owners. "
|
|
255
|
+
"The bad commit was caught and undone.", bold=True))
|
|
256
|
+
click.echo("On Databricks, check every change to your tables with one command:")
|
|
257
|
+
click.echo(" " + click.style(BUNDLE_CMD, fg="cyan"))
|
|
258
|
+
click.echo("Docs: " + click.style(DOCS_URL, underline=True))
|
|
194
259
|
finally:
|
|
195
260
|
agent_tools.set_sentry(previous)
|
|
196
261
|
return results
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Make a known-bad change to a demo table, so the first bricksentry check you see is a block.
|
|
2
|
+
|
|
3
|
+
Used by the ``bricksentry_demo`` job in the bundle template (``templates/job-check``)::
|
|
4
|
+
|
|
5
|
+
python -m bricksentry.job_demo --table main.bricksentry_scratch.bricksentry_demo_orders --warehouse-id abc123
|
|
6
|
+
|
|
7
|
+
It (re)creates a 20,000-row orders table, then runs a MERGE whose ON condition compares
|
|
8
|
+
region case-sensitively ('apac' vs 'APAC'). Nothing matches, so 25 orders that should have
|
|
9
|
+
been updated are inserted again as duplicates. The next task checks that change.
|
|
10
|
+
Only the table named by ``--table`` is written to.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import os
|
|
17
|
+
import re
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
SEED_SQL = """CREATE OR REPLACE TABLE {t} AS
|
|
21
|
+
SELECT id AS order_id,
|
|
22
|
+
element_at(array('APAC', 'EMEA', 'AMER'), CAST(1 + id % 3 AS INT)) AS region,
|
|
23
|
+
CAST(round(20 + (id % 97) * 3.1, 2) AS DOUBLE) AS amount,
|
|
24
|
+
CASE WHEN id % 10 = 0 THEN 'refunded' ELSE 'paid' END AS status
|
|
25
|
+
FROM range(1, 20001)"""
|
|
26
|
+
|
|
27
|
+
# Late price corrections for 25 orders. The bug: the source has region in lower case and
|
|
28
|
+
# the ON condition compares it case-sensitively, so no row matches and all 25 are inserted.
|
|
29
|
+
BAD_MERGE_SQL = """MERGE INTO {t} AS t
|
|
30
|
+
USING (
|
|
31
|
+
SELECT order_id, lower(region) AS region, round(amount * 1.05, 2) AS amount, status
|
|
32
|
+
FROM {t} WHERE order_id % 800 = 0
|
|
33
|
+
) AS s
|
|
34
|
+
ON t.order_id = s.order_id AND t.region = s.region
|
|
35
|
+
WHEN MATCHED THEN UPDATE SET t.amount = s.amount
|
|
36
|
+
WHEN NOT MATCHED THEN INSERT (order_id, region, amount, status)
|
|
37
|
+
VALUES (s.order_id, upper(s.region), s.amount, s.status)"""
|
|
38
|
+
|
|
39
|
+
_NAME = re.compile(r"[A-Za-z0-9_]+\.[A-Za-z0-9_]+\.[A-Za-z0-9_]+")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def run(argv: list[str] | None = None, backend: Any = None, out=print) -> int:
|
|
43
|
+
p = argparse.ArgumentParser(prog="python -m bricksentry.job_demo", description=__doc__.split("\n\n")[0])
|
|
44
|
+
p.add_argument("--table", required=True, help="catalog.schema.table for the demo (created or replaced)")
|
|
45
|
+
p.add_argument("--warehouse-id", default=os.environ.get("DATABRICKS_WAREHOUSE_ID"))
|
|
46
|
+
args = p.parse_args(argv)
|
|
47
|
+
if not _NAME.fullmatch(args.table):
|
|
48
|
+
raise SystemExit(f"--table must be catalog.schema.table, got {args.table!r}")
|
|
49
|
+
if not args.table.split(".")[-1].startswith("bricksentry_demo"):
|
|
50
|
+
raise SystemExit("For safety the demo only writes to a table whose name starts with bricksentry_demo.")
|
|
51
|
+
if backend is None: # pragma: no cover - needs Databricks
|
|
52
|
+
from bricksentry.backends.databricks_backend import DatabricksBackend
|
|
53
|
+
|
|
54
|
+
backend = DatabricksBackend(warehouse_id=args.warehouse_id)
|
|
55
|
+
t = backend.qualified(args.table)
|
|
56
|
+
backend.ensure_schema(".".join(args.table.split(".")[:2]))
|
|
57
|
+
backend.execute(SEED_SQL.format(t=t))
|
|
58
|
+
out(f"Created {args.table}: 20,000 orders, one row per order_id.")
|
|
59
|
+
backend.execute(BAD_MERGE_SQL.format(t=t))
|
|
60
|
+
out("Ran a MERGE with a bug: its ON condition compares region case-sensitively ('apac' vs 'APAC'),")
|
|
61
|
+
out("so 25 orders it should have updated were inserted again as duplicates.")
|
|
62
|
+
out("The next task checks this change. Expect BLOCK (duplicate-keys), and the RESTORE that undoes it.")
|
|
63
|
+
return 0
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def main(argv: list[str] | None = None) -> None: # pragma: no cover - thin wrapper
|
|
67
|
+
run(argv) # no sys.exit on success: Databricks marks SystemExit(0) as a failed task
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__": # pragma: no cover
|
|
71
|
+
main()
|
{bricksentry-0.1.16 → bricksentry-0.1.18}/templates/job-check/databricks_template_schema.json
RENAMED
|
@@ -39,6 +39,16 @@
|
|
|
39
39
|
"pattern_match_failure_message": "Use catalog.schema.",
|
|
40
40
|
"order": 5
|
|
41
41
|
},
|
|
42
|
+
"demo": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"default": "yes",
|
|
45
|
+
"enum": [
|
|
46
|
+
"yes",
|
|
47
|
+
"no"
|
|
48
|
+
],
|
|
49
|
+
"description": "Add a demo job that makes a known-bad change to a demo table in the scratch schema, so your first run shows a block (recommended)",
|
|
50
|
+
"order": 6
|
|
51
|
+
},
|
|
42
52
|
"policy": {
|
|
43
53
|
"type": "string",
|
|
44
54
|
"default": "default",
|
|
@@ -51,15 +61,15 @@
|
|
|
51
61
|
"agent-safe"
|
|
52
62
|
],
|
|
53
63
|
"description": "Policy for the verdict",
|
|
54
|
-
"order":
|
|
64
|
+
"order": 7
|
|
55
65
|
},
|
|
56
66
|
"slack_secret": {
|
|
57
67
|
"type": "string",
|
|
58
68
|
"default": "",
|
|
59
|
-
"description": "Slack webhook as
|
|
69
|
+
"description": "Optional: Slack webhook secret as scope/key (e.g. bricksentry/slack_webhook). Leave empty now and add it later",
|
|
60
70
|
"pattern": "^([A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+)?$",
|
|
61
71
|
"pattern_match_failure_message": "Use scope/key, or leave empty.",
|
|
62
|
-
"order":
|
|
72
|
+
"order": 8
|
|
63
73
|
},
|
|
64
74
|
"fail_on": {
|
|
65
75
|
"type": "string",
|
|
@@ -71,16 +81,16 @@
|
|
|
71
81
|
"never"
|
|
72
82
|
],
|
|
73
83
|
"description": "Mark the run failed when the verdict is at least",
|
|
74
|
-
"order":
|
|
84
|
+
"order": 9
|
|
75
85
|
},
|
|
76
86
|
"bricksentry_version": {
|
|
77
87
|
"type": "string",
|
|
78
|
-
"default": "0.1.
|
|
88
|
+
"default": "0.1.18",
|
|
79
89
|
"description": "bricksentry version to install in the job (pinned; change it and redeploy to upgrade)",
|
|
80
90
|
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
|
81
|
-
"pattern_match_failure_message": "Use a version like 0.1.
|
|
82
|
-
"order":
|
|
91
|
+
"pattern_match_failure_message": "Use a version like 0.1.18.",
|
|
92
|
+
"order": 10
|
|
83
93
|
}
|
|
84
94
|
},
|
|
85
|
-
"success_message": "
|
|
95
|
+
"success_message": "\nCreated {{.project_name}}. Next:\n cd {{.project_name}}\n databricks bundle deploy\n{{if eq .demo \"yes\"}} databricks bundle run bricksentry_demo # about 2 minutes; ends red with BLOCK, which is the point\n{{end}}Then any change to the watched tables is checked automatically. See {{.project_name}}/README.md."
|
|
86
96
|
}
|
|
@@ -16,11 +16,29 @@ The run is marked failed when the verdict is `{{.fail_on}}` or worse.
|
|
|
16
16
|
## Deploy
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
databricks bundle deploy
|
|
20
|
-
databricks bundle deploy -t prod
|
|
19
|
+
databricks bundle deploy # dev target: jobs are named "[dev you] ..."
|
|
20
|
+
databricks bundle deploy -t prod # prod target
|
|
21
21
|
databricks bundle run bricksentry_check # run once now (checks the last 60 minutes)
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
The table update trigger is set to run in both targets. Each change waits 2 minutes
|
|
25
|
+
(`wait_after_last_change_seconds`) so a pipeline's several commits are checked together.
|
|
26
|
+
{{if eq .demo "yes"}}
|
|
27
|
+
## See a block first (2 minutes)
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
databricks bundle run bricksentry_demo
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
It creates `{{.scratch_schema}}.bricksentry_demo_orders` (20,000 orders), runs a MERGE whose
|
|
34
|
+
ON condition compares region case-sensitively, so 25 orders are inserted again as duplicates,
|
|
35
|
+
then checks that change. The run ends **red with BLOCK**: that's the expected result. Open
|
|
36
|
+
the `bricksentry_check` task's output to see the verdict, the rules that fired, and the
|
|
37
|
+
`RESTORE` that undoes the change.{{if .slack_secret}} The Slack alert links back to the run.{{end}}
|
|
38
|
+
When you're done, delete the demo table and the `bricksentry_demo` job from
|
|
39
|
+
`resources/bricksentry_check.job.yml`.
|
|
40
|
+
{{end}}
|
|
41
|
+
|
|
24
42
|
The job's identity needs `SELECT` on the tables, `USE` and `CREATE TABLE` on
|
|
25
43
|
`{{.scratch_schema}}`, `CAN USE` on the warehouse, `SELECT` on `system.access.table_lineage` (for
|
|
26
44
|
lineage){{if .slack_secret}}, and `READ` on the secret scope{{end}}. Table history must still be there
|
|
@@ -57,3 +57,56 @@ resources:
|
|
|
57
57
|
# Pinned: serverless resolves the dependencies once and caches them, so a range
|
|
58
58
|
# would not pick up new releases. To upgrade, change the version and redeploy.
|
|
59
59
|
- bricksentry[databricks]=={{.bricksentry_version}}
|
|
60
|
+
{{- if eq .demo "yes"}}
|
|
61
|
+
|
|
62
|
+
# Demo: makes a known-bad change to a demo table in {{.scratch_schema}}, then checks it.
|
|
63
|
+
# `databricks bundle run bricksentry_demo` ends red with BLOCK (duplicate keys): that is
|
|
64
|
+
# the expected result. Delete this job once you have seen it.
|
|
65
|
+
bricksentry_demo:
|
|
66
|
+
name: bricksentry demo ({{.project_name}})
|
|
67
|
+
tasks:
|
|
68
|
+
- task_key: make_bad_change
|
|
69
|
+
environment_key: default
|
|
70
|
+
max_retries: 0
|
|
71
|
+
disable_auto_optimization: true
|
|
72
|
+
spark_python_task:
|
|
73
|
+
python_file: ../src/bricksentry_demo.py
|
|
74
|
+
parameters:
|
|
75
|
+
- --table
|
|
76
|
+
- "{{.scratch_schema}}.bricksentry_demo_orders"
|
|
77
|
+
- --warehouse-id
|
|
78
|
+
- "{{.warehouse_id}}"
|
|
79
|
+
- task_key: bricksentry_check
|
|
80
|
+
depends_on:
|
|
81
|
+
- task_key: make_bad_change
|
|
82
|
+
environment_key: default
|
|
83
|
+
max_retries: 0
|
|
84
|
+
disable_auto_optimization: true
|
|
85
|
+
spark_python_task:
|
|
86
|
+
python_file: ../src/bricksentry_check.py
|
|
87
|
+
parameters:
|
|
88
|
+
- --tables
|
|
89
|
+
- "{{.scratch_schema}}.bricksentry_demo_orders"
|
|
90
|
+
- --key
|
|
91
|
+
- order_id
|
|
92
|
+
- --warehouse-id
|
|
93
|
+
- "{{.warehouse_id}}"
|
|
94
|
+
- --scratch-schema
|
|
95
|
+
- "{{.scratch_schema}}"
|
|
96
|
+
- --policy
|
|
97
|
+
- "{{.policy}}"
|
|
98
|
+
- --fail-on
|
|
99
|
+
- block
|
|
100
|
+
{{- if .slack_secret}}
|
|
101
|
+
- --slack-secret
|
|
102
|
+
- "{{.slack_secret}}"
|
|
103
|
+
{{- end}}
|
|
104
|
+
- --run-url
|
|
105
|
+
- "{{`{{workspace.url}}/jobs/{{job.id}}/runs/{{job.run_id}}`}}"
|
|
106
|
+
environments:
|
|
107
|
+
- environment_key: default
|
|
108
|
+
spec:
|
|
109
|
+
environment_version: "2"
|
|
110
|
+
dependencies:
|
|
111
|
+
- bricksentry[databricks]=={{.bricksentry_version}}
|
|
112
|
+
{{- end}}
|
|
@@ -303,18 +303,38 @@ def test_bundle_template_files():
|
|
|
303
303
|
|
|
304
304
|
# --- render the bundle template (a small subset of Go templates is used on purpose) ---
|
|
305
305
|
def _render(text: str, values: dict) -> str:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
"""Render the subset of Go templates the bundle uses: {{.x}}, {{`raw`}}, nested
|
|
307
|
+
{{if .x}} / {{if eq .x "y"}} ... {{end}}, with optional {{- trimming."""
|
|
308
|
+
text = re.sub(r"\{\{`(.*?)`\}\}", lambda m: m.group(1).replace("{{", "\x00").replace("}}", "\x01"), text)
|
|
309
|
+
tok = re.compile(r"(\s*)\{\{(-?) ?(if (?:eq )?\.\w+(?: \"[^\"]*\")?|end)\}\}")
|
|
310
|
+
|
|
311
|
+
def cond(expr: str) -> bool:
|
|
312
|
+
m = re.fullmatch(r"if (eq )?\.(\w+)(?: \"([^\"]*)\")?", expr)
|
|
313
|
+
assert m, expr
|
|
314
|
+
v = values[m.group(2)]
|
|
315
|
+
return v == m.group(3) if m.group(1) else bool(v)
|
|
316
|
+
|
|
317
|
+
out, stack, pos = [], [True], 0
|
|
318
|
+
for m in tok.finditer(text):
|
|
319
|
+
if all(stack):
|
|
320
|
+
out.append(text[pos:m.start()] + ("" if m.group(2) else m.group(1)))
|
|
321
|
+
expr = m.group(3)
|
|
322
|
+
if expr == "end":
|
|
323
|
+
stack.pop()
|
|
324
|
+
else:
|
|
325
|
+
stack.append(cond(expr))
|
|
326
|
+
pos = m.end()
|
|
327
|
+
assert stack == [True], "unbalanced if/end"
|
|
328
|
+
out.append(text[pos:])
|
|
329
|
+
text = "".join(out)
|
|
311
330
|
text = re.sub(r"\{\{\.(\w+)\}\}", lambda m: str(values[m.group(1)]), text)
|
|
312
|
-
assert "{{
|
|
313
|
-
return text
|
|
331
|
+
assert "{{" not in text, text[text.index("{{") - 80:text.index("{{") + 80]
|
|
332
|
+
return text.replace("\x00", "{{").replace("\x01", "}}")
|
|
314
333
|
|
|
315
334
|
|
|
316
|
-
@pytest.mark.parametrize("slack,keys", [("bricksentry/slack_webhook", "main.sales.orders=order_id"
|
|
317
|
-
|
|
335
|
+
@pytest.mark.parametrize("slack,keys,demo", [("bricksentry/slack_webhook", "main.sales.orders=order_id", "yes"),
|
|
336
|
+
("", "", "no"), ("", "", "yes")])
|
|
337
|
+
def test_bundle_template_renders(slack, keys, demo):
|
|
318
338
|
from pathlib import Path
|
|
319
339
|
|
|
320
340
|
import yaml
|
|
@@ -324,7 +344,7 @@ def test_bundle_template_renders(slack, keys):
|
|
|
324
344
|
values = {k: p.get("default", "") for k, p in schema["properties"].items()}
|
|
325
345
|
assert values["bricksentry_version"] == __import__("bricksentry").__version__
|
|
326
346
|
values.update(tables="main.sales.orders, main.sales.customers", warehouse_id="abc123", slack_secret=slack,
|
|
327
|
-
keys=keys)
|
|
347
|
+
keys=keys, demo=demo)
|
|
328
348
|
for k, p in schema["properties"].items():
|
|
329
349
|
if "pattern" in p:
|
|
330
350
|
assert re.fullmatch(p["pattern"], values[k]), k
|
|
@@ -347,7 +367,23 @@ def test_bundle_template_renders(slack, keys):
|
|
|
347
367
|
# the job task's argv parses, and an unresolved trigger value falls back to --default-tables
|
|
348
368
|
args = job.build_parser().parse_args(params)
|
|
349
369
|
assert args.fail_on == "block" and args.since_minutes == 60
|
|
370
|
+
jobs = job_yml["resources"]["jobs"]
|
|
371
|
+
assert ("bricksentry_demo" in jobs) == (demo == "yes")
|
|
372
|
+
if demo == "yes":
|
|
373
|
+
dj = jobs["bricksentry_demo"]
|
|
374
|
+
make, check = dj["tasks"]
|
|
375
|
+
assert make["spark_python_task"]["python_file"] == "../src/bricksentry_demo.py"
|
|
376
|
+
assert check["depends_on"] == [{"task_key": "make_bad_change"}]
|
|
377
|
+
dargs = job.build_parser().parse_args(check["spark_python_task"]["parameters"])
|
|
378
|
+
assert dargs.tables == "main.bricksentry_scratch.bricksentry_demo_orders" and dargs.key == ["order_id"]
|
|
379
|
+
assert dargs.since is None and dargs.since_minutes is None and dargs.fail_on == "block"
|
|
380
|
+
assert (dargs.slack_secret is not None) == bool(slack)
|
|
381
|
+
assert all(t["max_retries"] == 0 and t["disable_auto_optimization"] for t in dj["tasks"])
|
|
382
|
+
assert dj["environments"] == j["environments"]
|
|
383
|
+
msg = _render(schema["success_message"], values)
|
|
384
|
+
assert ("bundle run bricksentry_demo" in msg) == (demo == "yes")
|
|
350
385
|
readme = _render((proj / "README.md.tmpl").read_text(), values)
|
|
386
|
+
assert ("See a block first" in readme) == (demo == "yes")
|
|
351
387
|
assert "{{job.start_time.iso_datetime}}" in readme
|
|
352
388
|
assert (proj / "src" / "bricksentry_check.py").exists()
|
|
353
389
|
|
|
@@ -388,3 +424,54 @@ def test_concurrent_checks_use_different_clones():
|
|
|
388
424
|
sentry(db).check_change("sales.orders")
|
|
389
425
|
sentry(db).check_change("sales.orders")
|
|
390
426
|
assert len(set(db.dropped)) == 4
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
# --- demo job: the known-bad change ---------------------------------------------------
|
|
430
|
+
class RecordingBackend:
|
|
431
|
+
def __init__(self):
|
|
432
|
+
self.sql: list[str] = []
|
|
433
|
+
self.schemas: list[str] = []
|
|
434
|
+
|
|
435
|
+
def qualified(self, t):
|
|
436
|
+
return ".".join(f"`{p}`" for p in t.split("."))
|
|
437
|
+
|
|
438
|
+
def ensure_schema(self, s):
|
|
439
|
+
self.schemas.append(s)
|
|
440
|
+
|
|
441
|
+
def execute(self, q):
|
|
442
|
+
self.sql.append(q)
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def test_job_demo_sql_and_guard():
|
|
446
|
+
from bricksentry import job_demo
|
|
447
|
+
|
|
448
|
+
b, lines = RecordingBackend(), []
|
|
449
|
+
assert job_demo.run(["--table", "main.scratch.bricksentry_demo_orders"], backend=b, out=lines.append) == 0
|
|
450
|
+
assert b.schemas == ["main.scratch"]
|
|
451
|
+
seed, merge = b.sql
|
|
452
|
+
assert seed.startswith("CREATE OR REPLACE TABLE `main`.`scratch`.`bricksentry_demo_orders` AS")
|
|
453
|
+
assert "MERGE INTO `main`.`scratch`.`bricksentry_demo_orders` AS t" in merge
|
|
454
|
+
assert "t.region = s.region" in merge and "lower(region)" in merge
|
|
455
|
+
assert "Expect BLOCK" in lines[-1]
|
|
456
|
+
for bad in ("main.sales.orders", "orders", "main.scratch.x; DROP TABLE y"):
|
|
457
|
+
with pytest.raises(SystemExit):
|
|
458
|
+
job_demo.run(["--table", bad], backend=RecordingBackend())
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
def test_job_demo_change_is_blocked_end_to_end():
|
|
462
|
+
"""The demo's bad MERGE, replayed on DuckDB history, is a block with the right undo."""
|
|
463
|
+
db = FakeDelta()
|
|
464
|
+
db.execute("CREATE TABLE sales.demo_v1 AS SELECT * FROM sales.orders_v1")
|
|
465
|
+
# the MERGE's effect: 25 orders inserted again (ON never matches)
|
|
466
|
+
db.execute("CREATE TABLE sales.demo_v2 AS SELECT * FROM sales.demo_v1 "
|
|
467
|
+
"UNION ALL SELECT order_id, round(amount * 1.05, 2) FROM sales.demo_v1 WHERE order_id % 80 = 0")
|
|
468
|
+
db._history = [{"version": 2, "operation": "MERGE", "timestamp": "2026-11-12 10:00:00"},
|
|
469
|
+
{"version": 1, "operation": "CREATE OR REPLACE TABLE AS SELECT", "timestamp": "2026-11-12 09:59:00"},
|
|
470
|
+
{"version": 0, "operation": "CREATE TABLE AS SELECT", "timestamp": "2026-11-01 00:00:00"}]
|
|
471
|
+
db.execute("CREATE TABLE sales.demo AS SELECT * FROM sales.demo_v2")
|
|
472
|
+
lines: list[str] = []
|
|
473
|
+
code = job.run(["--tables", "sales.demo", "--key", "order_id", "--scratch-schema", "scratch"],
|
|
474
|
+
backend=db, out=lines.append)
|
|
475
|
+
text = "\n".join(lines)
|
|
476
|
+
assert code == 1 and "BLOCK" in text and "duplicate-keys: 25" in text
|
|
477
|
+
assert 'TO VERSION AS OF 1' in text
|
|
@@ -13,8 +13,14 @@ def test_demo_results(capsys):
|
|
|
13
13
|
assert r["buggy_verdict"] == "block"
|
|
14
14
|
assert r["fixed_verdict"] == "needs_human"
|
|
15
15
|
assert r["notify"] == ["finance-analytics", "sales-data-eng"]
|
|
16
|
+
assert r["commit_verdict"] == "block"
|
|
17
|
+
assert r["undo"] == "RESTORE TABLE sales.orders TO VERSION AS OF 0"
|
|
18
|
+
assert r["rows_after_undo"] == 20000
|
|
16
19
|
out = capsys.readouterr().out
|
|
17
20
|
assert "duplicate-keys" in out and "Production still has 20,000 rows" in out
|
|
21
|
+
assert "v2 OPTIMIZE (skipped" in out and "back to 20,000 rows, 0 duplicate keys" in out
|
|
22
|
+
assert "--template-dir templates/job-check" in out
|
|
23
|
+
assert "[5/5]" in out and "[6/" not in out
|
|
18
24
|
assert agent_tools._SENTRY is None # demo restores global agent state
|
|
19
25
|
|
|
20
26
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bricksentry[databricks,mcp]==0.1.16
|
|
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.16 → bricksentry-0.1.18}/examples/databricks/bricksentry_check_my_table.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.16 → bricksentry-0.1.18}/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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.16 → bricksentry-0.1.18}/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
|