bricksentry 0.1.33__tar.gz → 0.1.35__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.33 → bricksentry-0.1.35}/CHANGELOG.md +13 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/PKG-INFO +23 -2
- {bricksentry-0.1.33 → bricksentry-0.1.35}/README.md +22 -1
- bricksentry-0.1.35/deploy/databricks-app/requirements.txt +1 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/policy.yml +1 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/pyproject.toml +2 -2
- {bricksentry-0.1.33 → bricksentry-0.1.35}/server.json +2 -2
- bricksentry-0.1.35/skills/bricksentry-safe-write/SKILL.md +87 -0
- bricksentry-0.1.35/skills/bricksentry-safe-write/references/setup.md +69 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/__init__.py +1 -1
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/diff.py +19 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/explain.py +3 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/job.py +17 -2
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/models.py +5 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/policy.py +14 -1
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/policy_templates.py +3 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/databricks_template_schema.json +2 -2
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0131.py +1 -1
- bricksentry-0.1.35/tests/test_0134.py +38 -0
- bricksentry-0.1.35/tests/test_0135.py +82 -0
- bricksentry-0.1.35/tests/test_skill.py +57 -0
- bricksentry-0.1.33/deploy/databricks-app/requirements.txt +0 -1
- {bricksentry-0.1.33 → bricksentry-0.1.35}/.gitignore +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/CONTRIBUTING.md +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/LICENSE +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/SECURITY.md +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/action.yml +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/deploy/container/Dockerfile +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/deploy/databricks-app/README.md +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/deploy/databricks-app/app.yaml +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/deploy/databricks-app/bricksentry.yml +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/deploy/databricks-app/databricks.yml +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/deploy/databricks-app/grants.sql +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry.yml +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_check_my_table.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_quickstart.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_validation.ipynb +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_validation.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/databricks/github-workflow.yml +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/examples/demo/agent_loop_demo.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/scripts/build_notebook.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/scripts/render_demo_image.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/__main__.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/agent_tools.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/agent_view.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/assess.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/backends/__init__.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/backends/base.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/backends/databricks_backend.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/backends/duckdb_backend.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/changes.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/cleanup.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/cli.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/config.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/demo.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/github.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/governed.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/history.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/job_demo.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/lineage.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/mcp_server.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/measures.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/netguard.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/notify.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/preview.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/py.typed +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/report.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/src/bricksentry/validation.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/README.md +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/conftest.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0110.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0112.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0114.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0120.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0121.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0122.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0123.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0126.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0127.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0128.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0129.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0130.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_0132.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_018.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_019.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_assess_policy.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_check_notebook.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_databricks_and_uc.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_demo.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_diff.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_hr_notebook.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_notebook.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_notify_templates.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_preview_agents.py +0 -0
- {bricksentry-0.1.33 → bricksentry-0.1.35}/tests/test_sample_guard_and_store.py +0 -0
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.35 (2026-11-30)
|
|
4
|
+
|
|
5
|
+
- **A key chosen too wide no longer hides duplicates.** In a Genie Code test of the new Agent Skill, the agent previewed a MERGE with `keys: [order_id, region]`, the MERGE's match columns. The MERGE inserted a second row for 25 existing order_ids; by the pair nothing repeated, so the preview said `pass`. bricksentry now also checks each column of a composite key that was unique before the change, and reports any that repeat after it (`key_column_duplicates` in the diff, and a warning in the summary). A new policy condition, `key_column_duplicates`, and rule, `key-column-duplicates`, act on it: `needs_human` in the built-in templates, `block` in `strict` and `agent-safe`. A column that already repeated (such as `order_id` in `[order_id, line_no]`) is never flagged. The extra cost is one grouped count per key column on the candidate, and on the base only when the candidate has repeats.
|
|
6
|
+
- **New: the `bricksentry-safe-write` Agent Skill** (`skills/bricksentry-safe-write`). It teaches coding agents (Genie Code, Claude Code, Codex, Cursor, Copilot) to check every write to an existing table with bricksentry first and follow the verdict, including how to choose the key. Tested in Genie Code: with the key rule, the agent previewed the bad MERGE, got `block` for 25 duplicate keys and left the table unchanged.
|
|
7
|
+
|
|
8
|
+
## 0.1.34 (2026-11-25)
|
|
9
|
+
|
|
10
|
+
From GitHub code scanning (CodeQL):
|
|
11
|
+
|
|
12
|
+
- **A webhook URL passed where a secret reference belongs is never printed.** The job's `--slack-secret` and `--teams-secret` take a Databricks secret reference, `scope/key`. If the webhook URL itself was passed by mistake, the error that said the secret couldn't be read repeated the value, so the URL (which is itself the credential for posting to the channel) appeared in the job's log. A value that isn't two plain names separated by `/` is now refused with a message that doesn't include it.
|
|
13
|
+
|
|
14
|
+
The other code-scanning alerts were false positives: CodeQL treats table names such as `bricksentry_hr_employees` and `bricksentry_hr_compensation` as private data, so printing those names in the HR walkthrough notebook and writing them to the agent audit log was flagged. Neither prints any of the tables' values.
|
|
15
|
+
|
|
3
16
|
## 0.1.33 (2026-11-23)
|
|
4
17
|
|
|
5
18
|
From a round of 15 previously untested areas on 0.1.32 on a Free Edition workspace. Thirteen were verified for the first time (NOT NULL and generated columns, empty tables, unicode names, INSERT OVERWRITE, duplicate and NULL keys in both directions, OPTIMIZE and RESTORE as the latest commit, bad job arguments, and the `wide-blast-radius` and `pii-table` rules firing on real Unity Catalog lineage and tags). It found one defect:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: bricksentry
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.35
|
|
4
4
|
Summary: Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans.
|
|
5
5
|
Project-URL: Homepage, https://bricksentry.org
|
|
6
6
|
Project-URL: Documentation, https://bricksentry.org/docs
|
|
@@ -245,6 +245,21 @@ databricks bundle run bricksentry_mcp
|
|
|
245
245
|
|
|
246
246
|
Agents connect to `https://<app-url>/mcp`. The kit starts the server with `--read-only`, which leaves out `preview_write`, so the app never writes. On any other host, `bricksentry mcp --transport streamable-http --port 8000` serves the same endpoint (on 127.0.0.1 unless you pass `--host`). To run it isolated, use the container image in [`deploy/container`](deploy/container/Dockerfile): non-root, config mounted read-only. [SECURITY.md](SECURITY.md) explains what bricksentry may reach over the network. Unity Catalog *MCP Services* are for servers hosted outside Databricks, so a Databricks App is the recommended way to run bricksentry inside it; see the [kit's README](deploy/databricks-app/README.md).
|
|
247
247
|
|
|
248
|
+
### Teach your coding agent the habit (Agent Skill)
|
|
249
|
+
|
|
250
|
+
[`skills/bricksentry-safe-write`](skills/bricksentry-safe-write/SKILL.md) is an [Agent Skill](https://agentskills.io): a short instruction file that tells an agent to check every write to a production table with bricksentry first. It plans with `whats_downstream`, keeps the `rollback_plan`, previews with `preview_write`, and follows `safe_to_ship` exactly: it stops on `needs_human` and `block`, and never treats an error as a pass. The same folder works in any agent that supports Agent Skills. Copy it into the agent's skills folder:
|
|
251
|
+
|
|
252
|
+
| Agent | Folder |
|
|
253
|
+
|---|---|
|
|
254
|
+
| Genie Code (Agent mode) | `/Workspace/.assistant/skills/` for everyone in the workspace, or `/Users/<you>/.assistant/skills/` for yourself |
|
|
255
|
+
| Claude Code | `.claude/skills/` in your project, or `~/.claude/skills/` |
|
|
256
|
+
| Codex | `.agents/skills/` |
|
|
257
|
+
| Other agents | Their skills folder; the format is the same |
|
|
258
|
+
|
|
259
|
+
An agent loads a skill when your request matches its description, so it isn't a hard rule: a general SQL skill can be picked instead. To make the check mandatory, add one line to the agent's always-on instructions (Genie Code custom instructions, `CLAUDE.md`, `AGENTS.md`): *Before any INSERT, MERGE, UPDATE or DELETE on an existing table, use the bricksentry-safe-write skill.*
|
|
260
|
+
|
|
261
|
+
The agent also needs a way to run the checks: the MCP server above, or, in a Databricks notebook, the Python functions in `bricksentry.agent_tools` ([setup](skills/bricksentry-safe-write/references/setup.md)).
|
|
262
|
+
|
|
248
263
|
## For data engineers: CLI and CI
|
|
249
264
|
|
|
250
265
|
```bash
|
|
@@ -439,8 +454,14 @@ rules:
|
|
|
439
454
|
- name: duplicate-keys # a join fanned out and duplicated keys -> block the PR
|
|
440
455
|
when: {duplicate_keys: true}
|
|
441
456
|
then: block
|
|
457
|
+
|
|
458
|
+
- name: key-column-duplicates # with a composite key, a column that was unique now repeats
|
|
459
|
+
when: {key_column_duplicates: true}
|
|
460
|
+
then: needs_human
|
|
442
461
|
```
|
|
443
462
|
|
|
463
|
+
`key_column_duplicates` guards against a key chosen too wide. With `keys: [order_id, region]`, a MERGE that matches on both columns can insert a second row for an existing `order_id`; by the pair nothing repeats, so `duplicate_keys` stays quiet. bricksentry also checks each column of a composite key that was unique before the change, and this condition fires when one stops being unique. A column that already repeated (such as `order_id` in `[order_id, line_no]`) is never flagged. The built-in templates send it to a human, and `strict` and `agent-safe` block it.
|
|
464
|
+
|
|
444
465
|
| The change | Verdict |
|
|
445
466
|
|---|---|
|
|
446
467
|
| A filter fix that changes 40 rows, nothing else | `pass` |
|
|
@@ -469,7 +490,7 @@ Use one directly with `policy: builtin:finance`, or write an editable copy with
|
|
|
469
490
|
|
|
470
491
|
### Policy conditions
|
|
471
492
|
|
|
472
|
-
`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`) · `changed_column` (glob) · `changed_column_tag` · `downstream_column_tag` · `any_change` · `diff_error` · `lineage_error`
|
|
493
|
+
`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` · `key_column_duplicates` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `changed_column` (glob) · `changed_column_tag` · `downstream_column_tag` · `any_change` · `diff_error` · `lineage_error`
|
|
473
494
|
|
|
474
495
|
**The pii and certified gates skip changes that change nothing.** In the default policy, `pii-table` (the table is tagged `pii`) and `certified-downstream` (it feeds something tagged `certified`) fire only when the diff shows a change: rows added, removed or changed, a schema change or new duplicate keys. A rebuild identical to production passes. A failed or missing diff still counts as a possible change. To require a review of every pull request touching a PII table regardless, add a rule without `any_change`: `{name: pii-review, when: {tag: pii}, then: needs_human}`.
|
|
475
496
|
|
|
@@ -197,6 +197,21 @@ databricks bundle run bricksentry_mcp
|
|
|
197
197
|
|
|
198
198
|
Agents connect to `https://<app-url>/mcp`. The kit starts the server with `--read-only`, which leaves out `preview_write`, so the app never writes. On any other host, `bricksentry mcp --transport streamable-http --port 8000` serves the same endpoint (on 127.0.0.1 unless you pass `--host`). To run it isolated, use the container image in [`deploy/container`](deploy/container/Dockerfile): non-root, config mounted read-only. [SECURITY.md](SECURITY.md) explains what bricksentry may reach over the network. Unity Catalog *MCP Services* are for servers hosted outside Databricks, so a Databricks App is the recommended way to run bricksentry inside it; see the [kit's README](deploy/databricks-app/README.md).
|
|
199
199
|
|
|
200
|
+
### Teach your coding agent the habit (Agent Skill)
|
|
201
|
+
|
|
202
|
+
[`skills/bricksentry-safe-write`](skills/bricksentry-safe-write/SKILL.md) is an [Agent Skill](https://agentskills.io): a short instruction file that tells an agent to check every write to a production table with bricksentry first. It plans with `whats_downstream`, keeps the `rollback_plan`, previews with `preview_write`, and follows `safe_to_ship` exactly: it stops on `needs_human` and `block`, and never treats an error as a pass. The same folder works in any agent that supports Agent Skills. Copy it into the agent's skills folder:
|
|
203
|
+
|
|
204
|
+
| Agent | Folder |
|
|
205
|
+
|---|---|
|
|
206
|
+
| Genie Code (Agent mode) | `/Workspace/.assistant/skills/` for everyone in the workspace, or `/Users/<you>/.assistant/skills/` for yourself |
|
|
207
|
+
| Claude Code | `.claude/skills/` in your project, or `~/.claude/skills/` |
|
|
208
|
+
| Codex | `.agents/skills/` |
|
|
209
|
+
| Other agents | Their skills folder; the format is the same |
|
|
210
|
+
|
|
211
|
+
An agent loads a skill when your request matches its description, so it isn't a hard rule: a general SQL skill can be picked instead. To make the check mandatory, add one line to the agent's always-on instructions (Genie Code custom instructions, `CLAUDE.md`, `AGENTS.md`): *Before any INSERT, MERGE, UPDATE or DELETE on an existing table, use the bricksentry-safe-write skill.*
|
|
212
|
+
|
|
213
|
+
The agent also needs a way to run the checks: the MCP server above, or, in a Databricks notebook, the Python functions in `bricksentry.agent_tools` ([setup](skills/bricksentry-safe-write/references/setup.md)).
|
|
214
|
+
|
|
200
215
|
## For data engineers: CLI and CI
|
|
201
216
|
|
|
202
217
|
```bash
|
|
@@ -391,8 +406,14 @@ rules:
|
|
|
391
406
|
- name: duplicate-keys # a join fanned out and duplicated keys -> block the PR
|
|
392
407
|
when: {duplicate_keys: true}
|
|
393
408
|
then: block
|
|
409
|
+
|
|
410
|
+
- name: key-column-duplicates # with a composite key, a column that was unique now repeats
|
|
411
|
+
when: {key_column_duplicates: true}
|
|
412
|
+
then: needs_human
|
|
394
413
|
```
|
|
395
414
|
|
|
415
|
+
`key_column_duplicates` guards against a key chosen too wide. With `keys: [order_id, region]`, a MERGE that matches on both columns can insert a second row for an existing `order_id`; by the pair nothing repeats, so `duplicate_keys` stays quiet. bricksentry also checks each column of a composite key that was unique before the change, and this condition fires when one stops being unique. A column that already repeated (such as `order_id` in `[order_id, line_no]`) is never flagged. The built-in templates send it to a human, and `strict` and `agent-safe` block it.
|
|
416
|
+
|
|
396
417
|
| The change | Verdict |
|
|
397
418
|
|---|---|
|
|
398
419
|
| A filter fix that changes 40 rows, nothing else | `pass` |
|
|
@@ -421,7 +442,7 @@ Use one directly with `policy: builtin:finance`, or write an editable copy with
|
|
|
421
442
|
|
|
422
443
|
### Policy conditions
|
|
423
444
|
|
|
424
|
-
`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`) · `changed_column` (glob) · `changed_column_tag` · `downstream_column_tag` · `any_change` · `diff_error` · `lineage_error`
|
|
445
|
+
`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` · `key_column_duplicates` · `null_keys` · `sum_change_pct_gt` / `null_increase_gt` (optionally with `column`) · `changed_column` (glob) · `changed_column_tag` · `downstream_column_tag` · `any_change` · `diff_error` · `lineage_error`
|
|
425
446
|
|
|
426
447
|
**The pii and certified gates skip changes that change nothing.** In the default policy, `pii-table` (the table is tagged `pii`) and `certified-downstream` (it feeds something tagged `certified`) fire only when the diff shows a change: rows added, removed or changed, a schema change or new duplicate keys. A rebuild identical to production passes. A failed or missing diff still counts as a possible change. To require a review of every pull request touching a PII table regardless, add a rule without `any_change`: `{name: pii-review, when: {tag: pii}, then: needs_human}`.
|
|
427
448
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bricksentry[databricks,mcp]==0.1.35
|
|
@@ -6,6 +6,7 @@ notify_owners_on: needs_human
|
|
|
6
6
|
rules:
|
|
7
7
|
- {name: diff-failed, when: {diff_error: true}, then: needs_human}
|
|
8
8
|
- {name: duplicate-keys, when: {duplicate_keys: true}, then: block}
|
|
9
|
+
- {name: key-column-duplicates, when: {key_column_duplicates: true}, then: needs_human}
|
|
9
10
|
- {name: null-keys, when: {null_keys: true}, then: warn}
|
|
10
11
|
- {name: dropped-column, when: {column_removed: true}, then: needs_human}
|
|
11
12
|
- {name: type-change, when: {column_type_changed: true}, then: warn}
|
|
@@ -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.35"
|
|
8
8
|
description = "Change impact analysis and deployment guardrails for data changes on Databricks, for pipelines and the AI agents that edit them: data diffs, Unity Catalog blast radius, policy verdicts and rollback plans."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -53,7 +53,7 @@ Issues = "https://github.com/bricksentry/bricksentry/issues"
|
|
|
53
53
|
Changelog = "https://github.com/bricksentry/bricksentry/blob/main/CHANGELOG.md"
|
|
54
54
|
|
|
55
55
|
[tool.hatch.build.targets.sdist]
|
|
56
|
-
include = ["/src", "/tests", "/examples", "/scripts", "/templates", "/deploy", "/README.md", "/LICENSE", "/CHANGELOG.md", "/CONTRIBUTING.md", "/SECURITY.md", "/action.yml", "/server.json"]
|
|
56
|
+
include = ["/src", "/tests", "/examples", "/scripts", "/templates", "/deploy", "/skills", "/README.md", "/LICENSE", "/CHANGELOG.md", "/CONTRIBUTING.md", "/SECURITY.md", "/action.yml", "/server.json"]
|
|
57
57
|
|
|
58
58
|
[tool.hatch.build.targets.wheel]
|
|
59
59
|
packages = ["src/bricksentry"]
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
10
|
"websiteUrl": "https://bricksentry.org",
|
|
11
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.35",
|
|
12
12
|
"packages": [
|
|
13
13
|
{
|
|
14
14
|
"registryType": "pypi",
|
|
15
15
|
"identifier": "bricksentry-mcp",
|
|
16
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.35",
|
|
17
17
|
"runtimeHint": "uvx",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: bricksentry-safe-write
|
|
3
|
+
description: Preview a data change with bricksentry before it runs. Use whenever you are about to run MERGE INTO, UPDATE, DELETE, INSERT INTO or CREATE OR REPLACE TABLE on an existing Delta table in Unity Catalog or Databricks, in any schema, and when asked whether a data change is safe to ship or how to undo one. Use it alongside general SQL-writing guidance, before the write runs.
|
|
4
|
+
license: Apache-2.0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Safe writes with bricksentry
|
|
8
|
+
|
|
9
|
+
bricksentry runs a write on a disposable clone of the table, diffs the result against
|
|
10
|
+
production, checks Unity Catalog lineage for what reads the table, and applies the team's
|
|
11
|
+
policy. It returns one verdict: `pass`, `warn`, `needs_human` or `block`. Rules decide the
|
|
12
|
+
verdict, not a model, so follow it exactly.
|
|
13
|
+
|
|
14
|
+
How to reach bricksentry depends on where you run: MCP tools, Python in a Databricks
|
|
15
|
+
notebook, or the `bricksentry` CLI. See [references/setup.md](references/setup.md). The steps
|
|
16
|
+
below use the MCP tool names; the Python functions in `bricksentry.agent_tools` have the same
|
|
17
|
+
names and arguments.
|
|
18
|
+
|
|
19
|
+
## The loop, for every write to a production table
|
|
20
|
+
|
|
21
|
+
1. **Plan.** `whats_downstream(table)` before you edit. Note the owners and any downstream
|
|
22
|
+
assets tagged `certified` or `pii`. Pass `columns=[...]` when you will change specific columns.
|
|
23
|
+
An empty list doesn't always mean nothing reads the table: Unity Catalog can take 10 to 15
|
|
24
|
+
minutes to record lineage for new tables and jobs. For a table created recently, say so.
|
|
25
|
+
2. **Keep the undo.** `rollback_plan(table)` and keep the returned `rollback_sql` in your reply,
|
|
26
|
+
the PR or the job log. Do this before anything is applied.
|
|
27
|
+
3. **Preview.** `preview_write(sql, target)` for a single statement that has not run yet.
|
|
28
|
+
Write `{{target}}` where the table name goes, or the full three-part name. For a pipeline
|
|
29
|
+
change already built into candidate (dev or PR) tables, use `assess_change(tables)` instead.
|
|
30
|
+
|
|
31
|
+
**Get the key right; the verdict depends on it.** The key is the column or columns that
|
|
32
|
+
identify one row in the table *as it is now* (usually its business id, such as `order_id`).
|
|
33
|
+
If it's in `bricksentry.yml` under `tables:`, use that; otherwise pass `keys=[...]`.
|
|
34
|
+
- It is **not** the MERGE's `ON` columns. A MERGE that matches on `order_id AND region` can
|
|
35
|
+
insert a second row for an existing `order_id`; with `region` in the key, that duplicate is
|
|
36
|
+
invisible and the change looks like clean new rows.
|
|
37
|
+
- Check it before previewing: `SELECT COUNT(*), COUNT(DISTINCT order_id) FROM <table>` must give
|
|
38
|
+
equal counts. Use the smallest set of columns that passes. If no column is unique, or you're
|
|
39
|
+
unsure, ask the user. Never guess: a wrong key hides duplicates or makes every row look changed.
|
|
40
|
+
- Say which key you used when you report the verdict. If the result has a
|
|
41
|
+
`key-column-duplicates` hit, a column you included in the key was unique and now repeats:
|
|
42
|
+
the key was too wide, so treat it like duplicate keys.
|
|
43
|
+
4. **Decide.** `safe_to_ship(id)` with the `id` from step 3, then do exactly what `next_step` says:
|
|
44
|
+
- `pass`: go ahead.
|
|
45
|
+
- `warn`: go ahead, and put every warning in your reply or the PR description.
|
|
46
|
+
- `needs_human`: do not apply it. Show the user the report and the reviewers listed in the
|
|
47
|
+
result's `notify` field (it's a field, not a tool), and wait for a person to approve.
|
|
48
|
+
- `block`: do not apply it. Fix the causes in `rule_hits`, then preview again.
|
|
49
|
+
5. **Apply** only after `pass` or `warn`, the same statement you previewed, unchanged. If you
|
|
50
|
+
change the statement, preview it again.
|
|
51
|
+
6. **Report** the verdict, the row counts (added, removed, changed), what is downstream, and
|
|
52
|
+
the `rollback_sql`. `explain_diff(assessment_id)` turns the diff into plain sentences for a
|
|
53
|
+
PR description or a reviewer.
|
|
54
|
+
|
|
55
|
+
## Never
|
|
56
|
+
|
|
57
|
+
- Never run a write on production before its preview verdict is `pass` or `warn`.
|
|
58
|
+
- Never treat an error, a refusal or a missing verdict as `pass`. If bricksentry can't check a
|
|
59
|
+
change, a person decides. Say so plainly.
|
|
60
|
+
- Never work around a verdict: don't edit `policy.yml`, `bricksentry.yml` or `agent_tables`,
|
|
61
|
+
split a statement, rename the target or switch tables to get a better answer.
|
|
62
|
+
- Never run a `RESTORE` without showing the user what it also undoes. `check-last-change`
|
|
63
|
+
warns when newer writes landed after the change.
|
|
64
|
+
- Never copy row values from production into your reply. bricksentry gives agents counts,
|
|
65
|
+
columns and verdicts on purpose.
|
|
66
|
+
|
|
67
|
+
## What bricksentry refuses, and what to do instead
|
|
68
|
+
|
|
69
|
+
- **DROP, TRUNCATE, ALTER, GRANT, or more than one statement:** preview one statement at a time.
|
|
70
|
+
Schema and permission changes need a person.
|
|
71
|
+
- **A write wrapped in a CTE (`WITH ... INSERT`):** move the CTE into the statement's `SELECT`
|
|
72
|
+
(`INSERT INTO t WITH x AS (...) SELECT ...`).
|
|
73
|
+
- **A table outside `agent_tables`:** you aren't allowed to check it. Ask the user; don't edit the list.
|
|
74
|
+
- **Tables with column masks or row filters:** Databricks can't clone them, so they can't be
|
|
75
|
+
previewed. Tell the user and suggest previewing on the table that feeds it, or a dev copy.
|
|
76
|
+
|
|
77
|
+
## After a pipeline has run
|
|
78
|
+
|
|
79
|
+
To check a change that already landed, for example after a scheduled MERGE, run
|
|
80
|
+
`bricksentry check-last-change <table>`. It compares the table before and after its latest data
|
|
81
|
+
change and prints the verdict and the `RESTORE` to undo it.
|
|
82
|
+
|
|
83
|
+
## Reading the CLI's exit code
|
|
84
|
+
|
|
85
|
+
`bricksentry preview` exits 1 only at `--fail-on` (default `block`), so a `needs_human` verdict
|
|
86
|
+
exits 0. Pass `--fail-on needs_human` in scripts, or read the verdict from `--format json`;
|
|
87
|
+
don't rely on the exit code alone.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Reaching bricksentry
|
|
2
|
+
|
|
3
|
+
Use whichever is available. Check for MCP tools named `preview_write` and `safe_to_ship` first.
|
|
4
|
+
|
|
5
|
+
## 1. MCP tools (Claude Code, Cursor, Copilot, Codex, Agent Bricks)
|
|
6
|
+
|
|
7
|
+
If the bricksentry MCP server is connected, call its tools directly: `whats_downstream`,
|
|
8
|
+
`rollback_plan`, `preview_write`, `assess_change`, `explain_diff`, `safe_to_ship`.
|
|
9
|
+
|
|
10
|
+
A server started with `--read-only` (the default in the Databricks App template) leaves out
|
|
11
|
+
`preview_write`. Then you can plan and assess, but you can't preview a write: ask the user to
|
|
12
|
+
preview it, or to connect a server that allows previews.
|
|
13
|
+
|
|
14
|
+
Not connected yet? The user starts one with:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install "bricksentry[databricks,mcp]"
|
|
18
|
+
bricksentry mcp # stdio, reads ./bricksentry.yml
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 2. Python in a Databricks notebook (Genie Code)
|
|
22
|
+
|
|
23
|
+
Install once per session, then restart Python in the next cell:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
%pip install "bricksentry[databricks]"
|
|
27
|
+
dbutils.library.restartPython()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from bricksentry import Config, Sentry, agent_tools
|
|
34
|
+
|
|
35
|
+
sentry = Sentry(Config.from_dict({
|
|
36
|
+
"backend": {"type": "databricks", "warehouse_id": "<sql-warehouse-id>"},
|
|
37
|
+
"sandbox_schema": "<catalog>.bricksentry_sandbox", # clones go here, then are dropped
|
|
38
|
+
"tables": {"<catalog>.<schema>.<table>": {"keys": ["<key column>"]}},
|
|
39
|
+
"lineage": {"type": "databricks"},
|
|
40
|
+
"policy": "builtin:agent-safe",
|
|
41
|
+
}))
|
|
42
|
+
agent_tools.set_sentry(sentry)
|
|
43
|
+
|
|
44
|
+
agent_tools.whats_downstream("<catalog>.<schema>.<table>")
|
|
45
|
+
plan = agent_tools.rollback_plan("<catalog>.<schema>.<table>")
|
|
46
|
+
result = agent_tools.preview_write(
|
|
47
|
+
"UPDATE {{target}} SET status = 'shipped' WHERE order_id = 42",
|
|
48
|
+
"<catalog>.<schema>.<table>",
|
|
49
|
+
)
|
|
50
|
+
decision = agent_tools.safe_to_ship(result["id"]) # follow decision["next_step"]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Ask the user for the warehouse ID, the sandbox schema and the table's key columns if you don't
|
|
54
|
+
know them. Don't guess keys: a wrong key makes every row look changed. If the workspace already
|
|
55
|
+
has a `bricksentry.yml`, use `Config.load("<path>")` instead.
|
|
56
|
+
|
|
57
|
+
## 3. The command line
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
bricksentry impact main.sales.orders
|
|
61
|
+
bricksentry rollback main.sales.orders
|
|
62
|
+
bricksentry preview main.sales.orders \
|
|
63
|
+
--sql "UPDATE {{target}} SET status = 'shipped' WHERE order_id = 42" \
|
|
64
|
+
--format json --fail-on needs_human
|
|
65
|
+
bricksentry check-last-change main.sales.orders # after a pipeline has already written
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Exit codes: 0 below `--fail-on`, 1 at or above it, 2 for errors (treat 2 as "couldn't check",
|
|
69
|
+
never as safe).
|
|
@@ -270,7 +270,25 @@ def _diff(
|
|
|
270
270
|
return int(backend.scalar(sql) or 0)
|
|
271
271
|
|
|
272
272
|
dup_b, dup_c = dupes("b_src"), dupes("c_src")
|
|
273
|
+
|
|
274
|
+
# A composite key can hide duplicates: with (order_id, region) as the key, a second row for
|
|
275
|
+
# an existing order_id looks like a new row. So each key column that was unique in base is
|
|
276
|
+
# checked again in candidate. The candidate side runs first; base only when it finds copies.
|
|
277
|
+
def col_dupes(col: str, tbl_cte: str) -> int:
|
|
278
|
+
sql = (f"{raw_ctes} SELECT COUNT(*) AS n FROM "
|
|
279
|
+
f"(SELECT {q(col)} FROM {tbl_cte} GROUP BY {q(col)} HAVING COUNT(*) > 1) d")
|
|
280
|
+
return int(backend.scalar(sql) or 0)
|
|
281
|
+
|
|
282
|
+
key_col_dups: dict[str, int] = {}
|
|
283
|
+
if len(keys) > 1:
|
|
284
|
+
for k in keys:
|
|
285
|
+
if k in b_cols and k in c_cols:
|
|
286
|
+
n = col_dupes(k, "c_src")
|
|
287
|
+
if n and col_dupes(k, "b_src") == 0:
|
|
288
|
+
key_col_dups[k] = n
|
|
273
289
|
notes: list[str] = []
|
|
290
|
+
if key_col_dups and sample_pct:
|
|
291
|
+
notes.append("Key columns that stopped being unique were checked on the sample only.")
|
|
274
292
|
pair_copies = bool(dup_b or dup_c)
|
|
275
293
|
if pair_copies:
|
|
276
294
|
notes.append(
|
|
@@ -448,6 +466,7 @@ def _diff(
|
|
|
448
466
|
columns=col_changes,
|
|
449
467
|
duplicate_keys_base=dup_b,
|
|
450
468
|
duplicate_keys_candidate=dup_c,
|
|
469
|
+
key_column_duplicates=key_col_dups,
|
|
451
470
|
null_keys_base=int(pb.get("null_keys") or 0),
|
|
452
471
|
null_keys_candidate=int(pc.get("null_keys") or 0),
|
|
453
472
|
segments=segments,
|
|
@@ -88,6 +88,9 @@ def explain_diff(d: TableDiff, measures: list[str] | str | None = None, for_agen
|
|
|
88
88
|
|
|
89
89
|
if d.duplicate_keys_candidate > d.duplicate_keys_base:
|
|
90
90
|
s += f". WARNING: {_n(d.duplicate_keys_candidate)} duplicate key(s) on {', '.join(d.keys)}"
|
|
91
|
+
for col, n in sorted(d.key_column_duplicates.items()):
|
|
92
|
+
s += (f". WARNING: {col} was unique before the change and now repeats ({_n(n)} value(s)); "
|
|
93
|
+
f"check that ({', '.join(d.keys)}) is really the key")
|
|
91
94
|
if d.null_keys_candidate:
|
|
92
95
|
s += f". Note: {_n(d.null_keys_candidate)} row(s) have a NULL key ({', '.join(d.keys)})"
|
|
93
96
|
if d.sampled_pct:
|
|
@@ -16,6 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
import argparse
|
|
17
17
|
import json
|
|
18
18
|
import os
|
|
19
|
+
import re
|
|
19
20
|
import sys
|
|
20
21
|
import warnings
|
|
21
22
|
from datetime import datetime, timedelta, timezone
|
|
@@ -53,13 +54,26 @@ def parse_keys(values: list[str]) -> dict[str, list[str]]:
|
|
|
53
54
|
return out
|
|
54
55
|
|
|
55
56
|
|
|
57
|
+
_SECRET_REF = re.compile(r"[A-Za-z0-9_.\-]{1,128}/[A-Za-z0-9_.\-]{1,128}")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _check_secret_ref(ref: str, flag: str = "--*-secret") -> None:
|
|
61
|
+
"""A secret *reference* is two names, scope/key. Anything else (most likely the webhook URL
|
|
62
|
+
itself, pasted by mistake) is refused without echoing it, so it never lands in a job log."""
|
|
63
|
+
if not _SECRET_REF.fullmatch(ref):
|
|
64
|
+
raise SystemExit(
|
|
65
|
+
f"{flag} must name a Databricks secret as scope/key (for example bricksentry/slack_webhook). "
|
|
66
|
+
"The value given isn't in that form, so it isn't printed here. If you pasted the webhook URL "
|
|
67
|
+
"itself, store it in a secret scope and pass scope/key instead."
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
56
71
|
def read_secret(ref: str | None) -> str | None: # pragma: no cover - needs Databricks
|
|
57
72
|
"""``scope/key`` from a Databricks secret scope."""
|
|
58
73
|
if not ref:
|
|
59
74
|
return None
|
|
75
|
+
_check_secret_ref(ref)
|
|
60
76
|
scope, _, key = ref.partition("/")
|
|
61
|
-
if not (scope and key):
|
|
62
|
-
raise SystemExit(f"--*-secret must be scope/key, got {ref!r}")
|
|
63
77
|
try:
|
|
64
78
|
from databricks.sdk.runtime import dbutils
|
|
65
79
|
|
|
@@ -103,6 +117,7 @@ def _secret_or_problem(ref: str | None, flag: str, problems: list[str] | None):
|
|
|
103
117
|
if not ref:
|
|
104
118
|
return None
|
|
105
119
|
try:
|
|
120
|
+
_check_secret_ref(ref, flag) # before anything echoes ref
|
|
106
121
|
return read_secret(ref)
|
|
107
122
|
except SystemExit as e: # a malformed scope/key
|
|
108
123
|
msg = str(e)
|
|
@@ -102,6 +102,10 @@ class TableDiff:
|
|
|
102
102
|
moved_during_check: list[str] = field(default_factory=list) # "base" / "candidate"
|
|
103
103
|
not_compared: dict[str, str] = field(default_factory=dict) # column -> type the engine couldn't compare, or "masked"
|
|
104
104
|
row_filtered: list[str] = field(default_factory=list) # "base" / "candidate" tables with a row filter
|
|
105
|
+
# With a composite key: a key column that was unique in base and has duplicated values in
|
|
106
|
+
# candidate -> number of duplicated values. Catches a key chosen too wide, e.g. (order_id,
|
|
107
|
+
# region) when order_id alone identifies a row.
|
|
108
|
+
key_column_duplicates: dict[str, int] = field(default_factory=dict)
|
|
105
109
|
|
|
106
110
|
def _pct(self, n: int) -> float:
|
|
107
111
|
denom = max(self.base_rows, 1)
|
|
@@ -133,6 +137,7 @@ class TableDiff:
|
|
|
133
137
|
and self.changed_rows == 0
|
|
134
138
|
and self.base_rows == self.candidate_rows
|
|
135
139
|
and self.duplicate_keys_candidate <= self.duplicate_keys_base
|
|
140
|
+
and not self.key_column_duplicates
|
|
136
141
|
and not self.not_compared
|
|
137
142
|
and not self.row_filtered
|
|
138
143
|
)
|
|
@@ -9,6 +9,9 @@ never from an LLM, so agents and CI get the same answer for the same change.
|
|
|
9
9
|
- name: duplicate-keys
|
|
10
10
|
when: {duplicate_keys: true}
|
|
11
11
|
then: block
|
|
12
|
+
- name: key-column-duplicates # a column of a composite key was unique and now repeats
|
|
13
|
+
when: {key_column_duplicates: true}
|
|
14
|
+
then: needs_human
|
|
12
15
|
- name: new-null-keys
|
|
13
16
|
when: {null_keys: true}
|
|
14
17
|
then: warn
|
|
@@ -55,6 +58,7 @@ DEFAULT_POLICY: dict[str, Any] = {
|
|
|
55
58
|
{"name": "diff-failed", "when": {"diff_error": True}, "then": "needs_human"},
|
|
56
59
|
{"name": "lineage-unavailable", "when": {"lineage_error": True}, "then": "warn"},
|
|
57
60
|
{"name": "duplicate-keys", "when": {"duplicate_keys": True}, "then": "block"},
|
|
61
|
+
{"name": "key-column-duplicates", "when": {"key_column_duplicates": True}, "then": "needs_human"},
|
|
58
62
|
{"name": "null-keys", "when": {"null_keys": True}, "then": "warn"},
|
|
59
63
|
{"name": "dropped-column", "when": {"column_removed": True}, "then": "needs_human"},
|
|
60
64
|
{"name": "type-change", "when": {"column_type_changed": True}, "then": "warn"},
|
|
@@ -73,7 +77,7 @@ KNOWN_CONDITIONS = {
|
|
|
73
77
|
"table", "tag", "downstream_tag", "downstream_kind", "downstream_count_gt",
|
|
74
78
|
"removed_pct_gt", "added_pct_gt", "changed_pct_gt", "row_count_change_pct_gt",
|
|
75
79
|
"row_count_drop_pct_gt", "column_removed", "column_type_changed", "column_added",
|
|
76
|
-
"duplicate_keys", "null_keys", "column", "sum_change_pct_gt", "null_increase_gt",
|
|
80
|
+
"duplicate_keys", "key_column_duplicates", "null_keys", "column", "sum_change_pct_gt", "null_increase_gt",
|
|
77
81
|
"any_change", "diff_error", "lineage_error",
|
|
78
82
|
"changed_column", "changed_column_tag", "downstream_column_tag",
|
|
79
83
|
}
|
|
@@ -289,6 +293,15 @@ def _match(
|
|
|
289
293
|
return False, ""
|
|
290
294
|
reasons.append(f"{diff.duplicate_keys_candidate} duplicate key(s) in candidate (base had {diff.duplicate_keys_base})")
|
|
291
295
|
continue
|
|
296
|
+
if cond == "key_column_duplicates":
|
|
297
|
+
hit = bool(diff.key_column_duplicates)
|
|
298
|
+
if hit != bool(val):
|
|
299
|
+
return False, ""
|
|
300
|
+
if hit:
|
|
301
|
+
cols = ", ".join(f"{c} ({n} duplicated value(s))" for c, n in sorted(diff.key_column_duplicates.items()))
|
|
302
|
+
reasons.append(f"key column(s) unique before the change now repeat: {cols}; "
|
|
303
|
+
f"the key given was ({', '.join(diff.keys)})")
|
|
304
|
+
continue
|
|
292
305
|
if cond == "null_keys":
|
|
293
306
|
new_nulls = diff.null_keys_candidate > diff.null_keys_base
|
|
294
307
|
if new_nulls != bool(val):
|
|
@@ -21,6 +21,7 @@ from bricksentry.policy import DEFAULT_POLICY
|
|
|
21
21
|
_CORE = [
|
|
22
22
|
{"name": "diff-failed", "when": {"diff_error": True}, "then": "needs_human"},
|
|
23
23
|
{"name": "duplicate-keys", "when": {"duplicate_keys": True}, "then": "block"},
|
|
24
|
+
{"name": "key-column-duplicates", "when": {"key_column_duplicates": True}, "then": "needs_human"},
|
|
24
25
|
{"name": "null-keys", "when": {"null_keys": True}, "then": "warn"},
|
|
25
26
|
{"name": "dropped-column", "when": {"column_removed": True}, "then": "needs_human"},
|
|
26
27
|
{"name": "type-change", "when": {"column_type_changed": True}, "then": "warn"},
|
|
@@ -42,6 +43,7 @@ TEMPLATES: dict[str, dict[str, Any]] = {
|
|
|
42
43
|
{"name": "pii-column-changed", "when": {"changed_column_tag": "pii"}, "then": "needs_human"},
|
|
43
44
|
{"name": "certified-column-feed", "when": {"downstream_column_tag": "certified"}, "then": "needs_human"},
|
|
44
45
|
{"name": "duplicate-keys", "when": {"duplicate_keys": True}, "then": "block"},
|
|
46
|
+
{"name": "key-column-duplicates", "when": {"key_column_duplicates": True}, "then": "block"},
|
|
45
47
|
{"name": "null-keys", "when": {"null_keys": True}, "then": "needs_human"},
|
|
46
48
|
{"name": "dropped-column", "when": {"column_removed": True}, "then": "block"},
|
|
47
49
|
{"name": "type-change", "when": {"column_type_changed": True}, "then": "needs_human"},
|
|
@@ -65,6 +67,7 @@ TEMPLATES: dict[str, dict[str, Any]] = {
|
|
|
65
67
|
{"name": "pii-column-changed", "when": {"changed_column_tag": "pii"}, "then": "needs_human"},
|
|
66
68
|
{"name": "certified-column-feed", "when": {"downstream_column_tag": "certified"}, "then": "needs_human"},
|
|
67
69
|
{"name": "duplicate-keys", "when": {"duplicate_keys": True}, "then": "block"},
|
|
70
|
+
{"name": "key-column-duplicates", "when": {"key_column_duplicates": True}, "then": "block"},
|
|
68
71
|
{"name": "dropped-column", "when": {"column_removed": True}, "then": "block"},
|
|
69
72
|
{"name": "null-keys", "when": {"null_keys": True}, "then": "needs_human"},
|
|
70
73
|
{"name": "type-change", "when": {"column_type_changed": True}, "then": "needs_human"},
|
{bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/databricks_template_schema.json
RENAMED
|
@@ -86,10 +86,10 @@
|
|
|
86
86
|
},
|
|
87
87
|
"bricksentry_version": {
|
|
88
88
|
"type": "string",
|
|
89
|
-
"default": "0.1.
|
|
89
|
+
"default": "0.1.35",
|
|
90
90
|
"description": "bricksentry version to install in the job (pinned; change it and redeploy to upgrade)",
|
|
91
91
|
"pattern": "^\\d+\\.\\d+\\.\\d+$",
|
|
92
|
-
"pattern_match_failure_message": "Use a version like 0.1.
|
|
92
|
+
"pattern_match_failure_message": "Use a version like 0.1.35.",
|
|
93
93
|
"order": 10
|
|
94
94
|
}
|
|
95
95
|
},
|
|
@@ -117,7 +117,7 @@ def test_job_malformed_secret_ref(monkeypatch):
|
|
|
117
117
|
lines: list[str] = []
|
|
118
118
|
code = job.run(["--tables", "sales.orders", "--scratch-schema", "scratch", "--slack-secret", "noslash"],
|
|
119
119
|
backend=FakeDelta(), out=lines.append)
|
|
120
|
-
assert code == 2 and "must
|
|
120
|
+
assert code == 2 and "must name a Databricks secret as scope/key" in "\n".join(lines)
|
|
121
121
|
|
|
122
122
|
|
|
123
123
|
# --- cleanup -------------------------------------------------------------------------------
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""0.1.34: a webhook URL passed where a secret reference belongs is never printed."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from test_0114 import FakeDelta
|
|
5
|
+
|
|
6
|
+
from bricksentry import job
|
|
7
|
+
|
|
8
|
+
URL = "https://hooks.slack.com/services/T000/B000/SECRETTOKEN123"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.mark.parametrize("ref", [URL, "xoxb-SECRETTOKEN123", "scope/key/SECRETTOKEN123", "a b/SECRETTOKEN123"])
|
|
12
|
+
def test_malformed_secret_reference_is_not_echoed(ref):
|
|
13
|
+
problems: list[str] = []
|
|
14
|
+
assert job._secret_or_problem(ref, "--slack-secret", problems) is None
|
|
15
|
+
assert "SECRETTOKEN123" not in problems[0]
|
|
16
|
+
assert "must name a Databricks secret as scope/key" in problems[0]
|
|
17
|
+
with pytest.raises(SystemExit) as e:
|
|
18
|
+
job._secret_or_problem(ref, "--teams-secret", None)
|
|
19
|
+
assert "SECRETTOKEN123" not in str(e.value)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_valid_reference_still_named_in_errors(monkeypatch):
|
|
23
|
+
def boom(ref):
|
|
24
|
+
raise RuntimeError("Scope bricksentry does not exist!")
|
|
25
|
+
|
|
26
|
+
monkeypatch.setattr(job, "read_secret", boom)
|
|
27
|
+
problems: list[str] = []
|
|
28
|
+
job._secret_or_problem("bricksentry/slack_webhook", "--slack-secret", problems)
|
|
29
|
+
assert "--slack-secret bricksentry/slack_webhook: could not read the secret" in problems[0]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_job_with_pasted_url_never_prints_it():
|
|
33
|
+
lines: list[str] = []
|
|
34
|
+
code = job.run(["--tables", "sales.orders", "--scratch-schema", "scratch", "--slack-secret", URL],
|
|
35
|
+
backend=FakeDelta(), out=lines.append)
|
|
36
|
+
text = "\n".join(lines)
|
|
37
|
+
assert code == 2 and "SECRETTOKEN123" not in text and "hooks.slack.com" not in text
|
|
38
|
+
assert "isn't printed here" in text
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""0.1.35: a key column that was unique and stops being unique is caught, even when the key
|
|
2
|
+
given is wider (the Genie Code skill test: keys=(order_id, region) hid 25 duplicate order_ids)."""
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from bricksentry import Config, Sentry
|
|
7
|
+
from bricksentry.backends.duckdb_backend import DuckDBBackend
|
|
8
|
+
from bricksentry.diff import diff_tables
|
|
9
|
+
from bricksentry.explain import explain_diff
|
|
10
|
+
from bricksentry.policy_templates import get_template
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@pytest.fixture
|
|
14
|
+
def db():
|
|
15
|
+
b = DuckDBBackend()
|
|
16
|
+
b.execute("CREATE SCHEMA t")
|
|
17
|
+
b.execute("""CREATE TABLE t.orders AS SELECT i AS order_id,
|
|
18
|
+
['north','south','east','west'][(i % 4) + 1] AS region, CAST(10 AS DECIMAL(18,2)) AS amount, 'pending' AS status
|
|
19
|
+
FROM range(1, 1001) r(i)""")
|
|
20
|
+
# The bad MERGE: matching on (order_id, region) with uppercase regions inserts 25 copies.
|
|
21
|
+
b.execute("CREATE TABLE t.orders_merged AS SELECT * FROM t.orders")
|
|
22
|
+
b.execute("""INSERT INTO t.orders_merged SELECT order_id, upper(region), 99.99, 'updated'
|
|
23
|
+
FROM t.orders WHERE order_id <= 25""")
|
|
24
|
+
return b
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_wide_key_still_catches_duplicated_order_id(db):
|
|
28
|
+
d = diff_tables(db, "t.orders", "t.orders_merged", keys=["order_id", "region"])
|
|
29
|
+
assert d.duplicate_keys_candidate == 0 # by the pair, nothing repeats
|
|
30
|
+
assert d.added_rows == 25 and d.key_column_duplicates == {"order_id": 25}
|
|
31
|
+
assert not d.is_identical
|
|
32
|
+
text = explain_diff(d, [])
|
|
33
|
+
assert "order_id was unique before the change and now repeats (25 value(s))" in text
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_correct_key_unchanged(db):
|
|
37
|
+
d = diff_tables(db, "t.orders", "t.orders_merged", keys=["order_id"])
|
|
38
|
+
assert d.duplicate_keys_candidate == 25 and d.key_column_duplicates == {}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_column_that_already_repeated_is_not_flagged(db):
|
|
42
|
+
# (order_id, line_no): order_id legitimately repeats, so adding another line is fine.
|
|
43
|
+
db.execute("""CREATE TABLE t.lines AS SELECT i // 2 AS order_id, i % 2 AS line_no, 1 AS qty
|
|
44
|
+
FROM range(0, 200) r(i)""")
|
|
45
|
+
db.execute("CREATE TABLE t.lines2 AS SELECT * FROM t.lines UNION ALL SELECT 5, 2, 1")
|
|
46
|
+
d = diff_tables(db, "t.lines", "t.lines2", keys=["order_id", "line_no"])
|
|
47
|
+
assert d.added_rows == 1 and d.key_column_duplicates == {}
|
|
48
|
+
# line_no was not unique either; nothing to report.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _assess(db, policy):
|
|
52
|
+
cfg = Config.from_dict({"backend": {"type": "duckdb"}, "assessment_store": False, "sandbox_schema": "sb",
|
|
53
|
+
"lineage": {"type": "static"}, "policy": policy,
|
|
54
|
+
"tables": {"t.orders": {"keys": ["order_id", "region"]}}})
|
|
55
|
+
s = Sentry(cfg, backend=db)
|
|
56
|
+
return s.assess(["t.orders"], candidates={"t.orders": "t.orders_merged"})
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_policy_verdicts(db):
|
|
60
|
+
a = _assess(db, "builtin:default")
|
|
61
|
+
assert a.verdict.value == "needs_human"
|
|
62
|
+
hit = next(h for h in a.hits if h.rule == "key-column-duplicates")
|
|
63
|
+
assert "order_id (25 duplicated value(s))" in hit.reason and "(order_id, region)" in hit.reason
|
|
64
|
+
assert _assess(db, "builtin:agent-safe").verdict.value == "block"
|
|
65
|
+
assert _assess(db, "builtin:strict").verdict.value == "block"
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_every_template_has_the_rule():
|
|
69
|
+
for name in ("default", "strict", "agent-safe", "pii", "certified", "finance"):
|
|
70
|
+
rules = {r["name"]: r["then"] for r in get_template(name)["rules"]}
|
|
71
|
+
assert "key-column-duplicates" in rules, name
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_preview_with_wide_key(db):
|
|
75
|
+
cfg = Config.from_dict({"backend": {"type": "duckdb"}, "assessment_store": False, "sandbox_schema": "sb",
|
|
76
|
+
"lineage": {"type": "static"}, "policy": "builtin:agent-safe"})
|
|
77
|
+
s = Sentry(cfg, backend=db)
|
|
78
|
+
out = s.preview_write("INSERT INTO {{target}} SELECT order_id, upper(region), 99.99, 'updated' "
|
|
79
|
+
"FROM {{target}} WHERE order_id <= 25", "t.orders", keys=["order_id", "region"])
|
|
80
|
+
assert out["verdict"] == "block"
|
|
81
|
+
assert out["tables"][0]["diff"]["key_column_duplicates"] == {"order_id": 25}
|
|
82
|
+
assert db.scalar("SELECT COUNT(*) FROM t.orders") == 1000
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""The bricksentry-safe-write Agent Skill stays valid and in step with the tools it names."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from click.testing import CliRunner
|
|
7
|
+
|
|
8
|
+
from bricksentry import agent_tools
|
|
9
|
+
from bricksentry.cli import main
|
|
10
|
+
from bricksentry.mcp_server import tools
|
|
11
|
+
|
|
12
|
+
SKILL = Path(__file__).resolve().parents[1] / "skills" / "bricksentry-safe-write"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _frontmatter(text: str) -> dict[str, str]:
|
|
16
|
+
m = re.match(r"\A---\n(.*?)\n---\n", text, re.S)
|
|
17
|
+
assert m, "SKILL.md must start with YAML frontmatter"
|
|
18
|
+
return dict(line.split(": ", 1) for line in m.group(1).splitlines())
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_frontmatter_follows_the_agent_skills_spec():
|
|
22
|
+
fm = _frontmatter((SKILL / "SKILL.md").read_text())
|
|
23
|
+
assert fm["name"] == SKILL.name # the folder name and `name` must match
|
|
24
|
+
assert re.fullmatch(r"[a-z0-9]+(-[a-z0-9]+)*", fm["name"]) and len(fm["name"]) <= 64
|
|
25
|
+
assert 0 < len(fm["description"]) <= 1024 and "<" not in fm["description"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_every_tool_the_skill_names_exists():
|
|
29
|
+
text = (SKILL / "SKILL.md").read_text() + (SKILL / "references" / "setup.md").read_text()
|
|
30
|
+
named = set(re.findall(r"`(whats_downstream|rollback_plan|preview_write|assess_change|explain_diff|safe_to_ship)", text))
|
|
31
|
+
real = {t.__name__ for t in tools(False)}
|
|
32
|
+
assert named and named <= real
|
|
33
|
+
assert {"preview_write", "safe_to_ship", "rollback_plan", "whats_downstream"} <= named
|
|
34
|
+
for name in named:
|
|
35
|
+
assert callable(getattr(agent_tools, name))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_cli_commands_in_the_skill_exist():
|
|
39
|
+
text = (SKILL / "SKILL.md").read_text() + (SKILL / "references" / "setup.md").read_text()
|
|
40
|
+
cmds = set(re.findall(r"`bricksentry ([a-z][a-z-]+)", text)) | {c for block in re.findall(r"```[a-z]*\n(.*?)```", text, re.S)
|
|
41
|
+
for c in re.findall(r"(?m)^bricksentry ([a-z][a-z-]+)", block)}
|
|
42
|
+
assert {"preview", "rollback", "impact", "check-last-change", "mcp"} <= cmds
|
|
43
|
+
for cmd in cmds:
|
|
44
|
+
assert CliRunner().invoke(main, [cmd, "--help"]).exit_code == 0, cmd
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_the_skill_loop_runs(sentry):
|
|
48
|
+
agent_tools.set_sentry(sentry)
|
|
49
|
+
try:
|
|
50
|
+
assert "downstream" in agent_tools.whats_downstream("sales.orders")
|
|
51
|
+
assert agent_tools.rollback_plan("sales.orders")["rollback_sql"] # RESTORE on Delta; a note on DuckDB
|
|
52
|
+
r = agent_tools.preview_write("UPDATE {{target}} SET status = 'shipped' WHERE order_id = 42", "sales.orders")
|
|
53
|
+
d = agent_tools.safe_to_ship(r["id"])
|
|
54
|
+
assert d["verdict"] in ("pass", "warn", "needs_human", "block") and d["next_step"]
|
|
55
|
+
assert sentry.backend.scalar("SELECT COUNT(*) FROM sales.orders WHERE status = 'shipped' AND order_id = 42") == 0
|
|
56
|
+
finally:
|
|
57
|
+
agent_tools.set_sentry(None)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
bricksentry[databricks,mcp]==0.1.33
|
|
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.33 → bricksentry-0.1.35}/examples/databricks/bricksentry_check_my_table.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.33 → bricksentry-0.1.35}/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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bricksentry-0.1.33 → bricksentry-0.1.35}/templates/job-check/template/{{.project_name}}/.gitignore
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|