bricksentry 0.1.19__tar.gz → 0.1.20__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.
Files changed (82) hide show
  1. {bricksentry-0.1.19 → bricksentry-0.1.20}/CHANGELOG.md +7 -0
  2. {bricksentry-0.1.19 → bricksentry-0.1.20}/PKG-INFO +2 -2
  3. {bricksentry-0.1.19 → bricksentry-0.1.20}/README.md +1 -1
  4. bricksentry-0.1.20/deploy/databricks-app/requirements.txt +1 -0
  5. {bricksentry-0.1.19 → bricksentry-0.1.20}/pyproject.toml +1 -1
  6. {bricksentry-0.1.19 → bricksentry-0.1.20}/server.json +2 -2
  7. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/__init__.py +1 -1
  8. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/cli.py +2 -0
  9. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/history.py +42 -2
  10. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/job.py +2 -0
  11. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/models.py +3 -0
  12. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/notify.py +6 -0
  13. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/report.py +2 -0
  14. {bricksentry-0.1.19 → bricksentry-0.1.20}/templates/job-check/databricks_template_schema.json +2 -2
  15. bricksentry-0.1.20/tests/test_0120.py +81 -0
  16. bricksentry-0.1.19/deploy/databricks-app/requirements.txt +0 -1
  17. {bricksentry-0.1.19 → bricksentry-0.1.20}/.gitignore +0 -0
  18. {bricksentry-0.1.19 → bricksentry-0.1.20}/CONTRIBUTING.md +0 -0
  19. {bricksentry-0.1.19 → bricksentry-0.1.20}/LICENSE +0 -0
  20. {bricksentry-0.1.19 → bricksentry-0.1.20}/SECURITY.md +0 -0
  21. {bricksentry-0.1.19 → bricksentry-0.1.20}/action.yml +0 -0
  22. {bricksentry-0.1.19 → bricksentry-0.1.20}/deploy/databricks-app/README.md +0 -0
  23. {bricksentry-0.1.19 → bricksentry-0.1.20}/deploy/databricks-app/app.yaml +0 -0
  24. {bricksentry-0.1.19 → bricksentry-0.1.20}/deploy/databricks-app/bricksentry.yml +0 -0
  25. {bricksentry-0.1.19 → bricksentry-0.1.20}/deploy/databricks-app/databricks.yml +0 -0
  26. {bricksentry-0.1.19 → bricksentry-0.1.20}/deploy/databricks-app/grants.sql +0 -0
  27. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/bricksentry.yml +0 -0
  28. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/bricksentry_check_my_table.ipynb +0 -0
  29. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/bricksentry_check_my_table.py +0 -0
  30. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/bricksentry_hr_walkthrough.ipynb +0 -0
  31. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/bricksentry_hr_walkthrough.py +0 -0
  32. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/bricksentry_quickstart.ipynb +0 -0
  33. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/bricksentry_quickstart.py +0 -0
  34. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/github-workflow.yml +0 -0
  35. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/databricks/policy.yml +0 -0
  36. {bricksentry-0.1.19 → bricksentry-0.1.20}/examples/demo/agent_loop_demo.py +0 -0
  37. {bricksentry-0.1.19 → bricksentry-0.1.20}/scripts/build_notebook.py +0 -0
  38. {bricksentry-0.1.19 → bricksentry-0.1.20}/scripts/render_demo_image.py +0 -0
  39. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/__main__.py +0 -0
  40. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/agent_tools.py +0 -0
  41. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/assess.py +0 -0
  42. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/backends/__init__.py +0 -0
  43. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/backends/base.py +0 -0
  44. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/backends/databricks_backend.py +0 -0
  45. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/backends/duckdb_backend.py +0 -0
  46. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/changes.py +0 -0
  47. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/config.py +0 -0
  48. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/demo.py +0 -0
  49. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/diff.py +0 -0
  50. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/explain.py +0 -0
  51. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/github.py +0 -0
  52. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/job_demo.py +0 -0
  53. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/lineage.py +0 -0
  54. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/mcp_server.py +0 -0
  55. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/measures.py +0 -0
  56. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/policy.py +0 -0
  57. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/policy_templates.py +0 -0
  58. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/preview.py +0 -0
  59. {bricksentry-0.1.19 → bricksentry-0.1.20}/src/bricksentry/py.typed +0 -0
  60. {bricksentry-0.1.19 → bricksentry-0.1.20}/templates/job-check/README.md +0 -0
  61. {bricksentry-0.1.19 → bricksentry-0.1.20}/templates/job-check/template/{{.project_name}}/.gitignore +0 -0
  62. {bricksentry-0.1.19 → bricksentry-0.1.20}/templates/job-check/template/{{.project_name}}/README.md.tmpl +0 -0
  63. {bricksentry-0.1.19 → bricksentry-0.1.20}/templates/job-check/template/{{.project_name}}/databricks.yml.tmpl +0 -0
  64. {bricksentry-0.1.19 → bricksentry-0.1.20}/templates/job-check/template/{{.project_name}}/resources/bricksentry_check.job.yml.tmpl +0 -0
  65. {bricksentry-0.1.19 → bricksentry-0.1.20}/templates/job-check/template/{{.project_name}}/src/bricksentry_check.py +0 -0
  66. {bricksentry-0.1.19 → bricksentry-0.1.20}/templates/job-check/template/{{.project_name}}/src/bricksentry_demo.py +0 -0
  67. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/conftest.py +0 -0
  68. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_0110.py +0 -0
  69. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_0112.py +0 -0
  70. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_0114.py +0 -0
  71. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_018.py +0 -0
  72. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_019.py +0 -0
  73. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_assess_policy.py +0 -0
  74. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_check_notebook.py +0 -0
  75. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_databricks_and_uc.py +0 -0
  76. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_demo.py +0 -0
  77. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_diff.py +0 -0
  78. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_hr_notebook.py +0 -0
  79. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_notebook.py +0 -0
  80. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_notify_templates.py +0 -0
  81. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_preview_agents.py +0 -0
  82. {bricksentry-0.1.19 → bricksentry-0.1.20}/tests/test_sample_guard_and_store.py +0 -0
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.20 (2026-11-13)
4
+
5
+ From a question on X: what happens to a valid write that lands after the bad change you want to undo?
6
+
7
+ - **"Newer data changes exist" warning.** `check-last-change` reads the table history again after the check. If data changes were committed after the checked version (because you passed `--version`, or a write landed while the check ran), it warns right above the `RESTORE` that restoring also undoes them, and lists them. The warning appears in the CLI, the job task log, the pull-request report, Slack and Teams alerts, and the JSON (`rollback_warning` on each table, `newer_changes` on the change). OPTIMIZE and VACUUM don't count.
8
+ - README: before acting on an older alert, run `check-last-change --version N` again to see what was written since.
9
+
3
10
  ## 0.1.19 (2026-11-12)
4
11
 
5
12
  - `bricksentry demo` showed black boxes instead of colored verdict labels in macOS Terminal, which doesn't support 24-bit color. Terminals that don't set `COLORTERM=truecolor` now get the standard named colors; the others keep the website's colors.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bricksentry
3
- Version: 0.1.19
3
+ Version: 0.1.20
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
@@ -115,7 +115,7 @@ bricksentry check-last-change main.sales.orders --version 42 # a specific ver
115
115
  bricksentry check-last-change main.sales.orders --since 2026-11-11T09:00:00Z --fail-on needs_human
116
116
  ```
117
117
 
118
- Keys come from `bricksentry.yml`, `--key`, or the table's `PRIMARY KEY` constraint. OPTIMIZE and VACUUM commits are skipped because they don't change data.
118
+ Keys come from `bricksentry.yml`, `--key`, or the table's `PRIMARY KEY` constraint. OPTIMIZE and VACUUM commits are skipped because they don't change data. If data changes landed after the version you check, the output warns you right above the `RESTORE`, because restoring would undo them too. Acting on an alert later? Run `check-last-change --version N` again first: it lists anything written since.
119
119
 
120
120
  ### Every feature on an HR pipeline
121
121
 
@@ -68,7 +68,7 @@ bricksentry check-last-change main.sales.orders --version 42 # a specific ver
68
68
  bricksentry check-last-change main.sales.orders --since 2026-11-11T09:00:00Z --fail-on needs_human
69
69
  ```
70
70
 
71
- Keys come from `bricksentry.yml`, `--key`, or the table's `PRIMARY KEY` constraint. OPTIMIZE and VACUUM commits are skipped because they don't change data.
71
+ Keys come from `bricksentry.yml`, `--key`, or the table's `PRIMARY KEY` constraint. OPTIMIZE and VACUUM commits are skipped because they don't change data. If data changes landed after the version you check, the output warns you right above the `RESTORE`, because restoring would undo them too. Acting on an alert later? Run `check-last-change --version N` again first: it lists anything written since.
72
72
 
73
73
  ### Every feature on an HR pipeline
74
74
 
@@ -0,0 +1 @@
1
+ bricksentry[databricks,mcp]==0.1.20
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "bricksentry"
7
- version = "0.1.19"
7
+ version = "0.1.20"
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"
@@ -8,12 +8,12 @@
8
8
  "source": "github"
9
9
  },
10
10
  "websiteUrl": "https://bricksentry.org",
11
- "version": "0.1.19",
11
+ "version": "0.1.20",
12
12
  "packages": [
13
13
  {
14
14
  "registryType": "pypi",
15
15
  "identifier": "bricksentry-mcp",
16
- "version": "0.1.19",
16
+ "version": "0.1.20",
17
17
  "runtimeHint": "uvx",
18
18
  "transport": {
19
19
  "type": "stdio"
@@ -23,4 +23,4 @@ __all__ = [
23
23
  "TableDiff",
24
24
  "Verdict",
25
25
  ]
26
- __version__ = "0.1.19"
26
+ __version__ = "0.1.20"
@@ -248,6 +248,8 @@ def check_last_change(table, keys, version, since, sample_pct, allow_no_change,
248
248
  click.echo(f"- {t.summary}")
249
249
  for h in t.hits:
250
250
  click.echo(f" [{h.verdict.value}] {h.rule}: {h.reason}")
251
+ if t.rollback_warning:
252
+ click.echo(click.style("Warning before you undo: ", fg="yellow", bold=True) + t.rollback_warning)
251
253
  click.echo(f"Undo: {t.rollback}")
252
254
  if a.notify:
253
255
  click.echo(f"Notify: {', '.join(a.notify)}")
@@ -10,7 +10,7 @@ from __future__ import annotations
10
10
 
11
11
  import re
12
12
  import uuid
13
- from dataclasses import dataclass
13
+ from dataclasses import dataclass, field
14
14
  from datetime import datetime, timezone
15
15
  from typing import TYPE_CHECKING, Any
16
16
 
@@ -42,6 +42,8 @@ class Change:
42
42
  operation: str
43
43
  timestamp: str
44
44
  versions: list[int] # every data-changing version folded into this check
45
+ # Data changes committed after ``version``: restoring to ``base_version`` undoes them too.
46
+ newer: list[dict[str, Any]] = field(default_factory=list)
45
47
 
46
48
  def to_dict(self) -> dict[str, Any]:
47
49
  return {
@@ -51,6 +53,7 @@ class Change:
51
53
  "operation": self.operation,
52
54
  "timestamp": self.timestamp,
53
55
  "versions": self.versions,
56
+ "newer_changes": self.newer,
54
57
  }
55
58
 
56
59
 
@@ -58,6 +61,33 @@ def is_data_op(operation: Any) -> bool:
58
61
  return str(operation or "").strip().upper() in DATA_OPS
59
62
 
60
63
 
64
+ def newer_data_changes(history: list[dict[str, Any]], version: int) -> list[dict[str, Any]]:
65
+ """Data changes committed after ``version``, oldest first (OPTIMIZE, VACUUM ... left out)."""
66
+ out = []
67
+ for h in history:
68
+ v = h.get("version")
69
+ if v is None or int(v) <= version or not is_data_op(h.get("operation")):
70
+ continue
71
+ out.append({"version": int(v), "operation": str(h.get("operation")), "timestamp": str(h.get("timestamp") or "")})
72
+ return sorted(out, key=lambda h: h["version"])
73
+
74
+
75
+ def rollback_warning(change: Change, max_listed: int = 3) -> str | None:
76
+ """The warning to show next to the RESTORE when newer data changes exist, else None."""
77
+ if not change.newer:
78
+ return None
79
+ listed = ", ".join(
80
+ f"v{h['version']} ({h['operation']}{', ' + h['timestamp'] if h['timestamp'] else ''})"
81
+ for h in change.newer[-max_listed:][::-1])
82
+ more = len(change.newer) - max_listed
83
+ if more > 0:
84
+ listed += f" and {more} more"
85
+ n = len(change.newer)
86
+ return (f"Newer data changes exist: {listed}. Restoring to v{change.base_version} also undoes "
87
+ f"{'it' if n == 1 else 'them'}. Re-run {'that write' if n == 1 else 'those writes'} after "
88
+ "restoring, or fix forward instead.")
89
+
90
+
61
91
  def _ts(value: Any) -> datetime | None:
62
92
  if value is None or value == "":
63
93
  return None
@@ -165,7 +195,8 @@ def check_change(
165
195
  if not _NAME.fullmatch(table):
166
196
  raise ValueError(f"table must be schema.table or catalog.schema.table; got {table!r}")
167
197
 
168
- change = pick_change(table, db.history(table, history_limit), version=version, since=since)
198
+ history = db.history(table, history_limit)
199
+ change = pick_change(table, history, version=version, since=since)
169
200
  keys = keys or sentry.config.spec(table).keys or db.primary_key(table)
170
201
  if not keys:
171
202
  raise ValueError(
@@ -197,9 +228,18 @@ def check_change(
197
228
  pass
198
229
 
199
230
  # The change already happened, so undoing it means going back to the version before it.
231
+ # That also undoes anything written after it, so read the history again (writes may have
232
+ # landed while the check ran) and warn about newer data changes next to the RESTORE.
233
+ try:
234
+ latest = db.history(table, history_limit)
235
+ except Exception: # pragma: no cover - keep the first read if a second one fails
236
+ latest = history
237
+ change.newer = newer_data_changes(latest, change.version)
238
+ warning = rollback_warning(change)
200
239
  undo = f"RESTORE TABLE {db.qualified(table)} TO VERSION AS OF {change.base_version}"
201
240
  for t in a.tables:
202
241
  t.rollback = undo
242
+ t.rollback_warning = warning
203
243
  t.summary = f"v{change.base_version} -> v{change.version} ({change.operation}): {t.summary}"
204
244
  sentry._save(a)
205
245
  return a, change
@@ -166,6 +166,8 @@ def run(argv: list[str] | None = None, backend: Any = None, out=print) -> int:
166
166
  out(f" {t.summary}")
167
167
  for h in t.hits:
168
168
  out(f" [{h.verdict.value}] {h.rule}: {h.reason}")
169
+ if t.rollback_warning:
170
+ out(f" WARNING before you undo: {t.rollback_warning}")
169
171
  out(f" Undo: {t.rollback}")
170
172
  for line in s.notify(a):
171
173
  out(f" notify {line}")
@@ -215,6 +215,7 @@ class TableAssessment:
215
215
  changed_columns: list[str] = field(default_factory=list)
216
216
  column_tags: dict[str, dict[str, str]] = field(default_factory=dict) # tags on this table's changed columns
217
217
  column_downstream: list[ColumnImpact] = field(default_factory=list)
218
+ rollback_warning: str | None = None # e.g. newer data changes that the RESTORE would also undo
218
219
 
219
220
  def to_dict(self) -> dict[str, Any]:
220
221
  return {
@@ -231,6 +232,7 @@ class TableAssessment:
231
232
  "column_tags": self.column_tags,
232
233
  "column_downstream": [c.to_dict() for c in self.column_downstream],
233
234
  "rollback": self.rollback,
235
+ "rollback_warning": self.rollback_warning,
234
236
  }
235
237
 
236
238
  @classmethod
@@ -248,6 +250,7 @@ class TableAssessment:
248
250
  changed_columns=list(d.get("changed_columns") or []),
249
251
  column_tags={k: dict(v) for k, v in (d.get("column_tags") or {}).items()},
250
252
  column_downstream=[ColumnImpact(**c) for c in d.get("column_downstream") or []],
253
+ rollback_warning=d.get("rollback_warning"),
251
254
  )
252
255
 
253
256
 
@@ -192,6 +192,9 @@ def slack_payload(
192
192
  lines.append(f"`{h.verdict.value}` *{_slack_escape(h.rule)}* on {_slack_escape(h.table)}: {_slack_escape(_clip(h.reason))}")
193
193
  if len(a.hits) > max_reasons:
194
194
  lines.append(f"_…and {len(a.hits) - max_reasons} more_")
195
+ for t in a.tables:
196
+ if t.rollback_warning:
197
+ lines.append(f":warning: *Before you restore {_slack_escape(t.table)}:* {_slack_escape(t.rollback_warning)}")
195
198
  if a.notify:
196
199
  lines.append("*Review requested from:* " + ", ".join(_slack_mention(o, mentions) for o in a.notify))
197
200
  link = run_link(pr, run_url)
@@ -235,6 +238,9 @@ def teams_payload(
235
238
  body.append(_plain(f"[{h.verdict.value}] {h.rule} on {h.table}: {_clip(h.reason)}"))
236
239
  if len(a.hits) > max_reasons:
237
240
  body.append(_plain(f"…and {len(a.hits) - max_reasons} more"))
241
+ for t in a.tables:
242
+ if t.rollback_warning:
243
+ body.append(_plain(f"Before you restore {t.table}: {t.rollback_warning}"))
238
244
  if a.notify:
239
245
  body.append(_plain(f"Review requested from: {', '.join(a.notify)}"))
240
246
  body.append({"type": "RichTextBlock", "spacing": "Medium", "inlines": [
@@ -93,6 +93,8 @@ def _table_section(t: TableAssessment, max_downstream: int) -> list[str]:
93
93
  out.append(f"| … | {len(t.column_downstream) - max_downstream} more | | |")
94
94
  out += ["", "</details>", ""]
95
95
  if t.rollback and t.rollback.startswith("RESTORE"):
96
+ if t.rollback_warning:
97
+ out += [f"> :warning: **Before you restore:** {t.rollback_warning}", ""]
96
98
  out += ["**Rollback:**", "```sql", t.rollback, "```", ""]
97
99
  elif t.rollback:
98
100
  out += [f"**Rollback:** {t.rollback}", ""]
@@ -86,10 +86,10 @@
86
86
  },
87
87
  "bricksentry_version": {
88
88
  "type": "string",
89
- "default": "0.1.19",
89
+ "default": "0.1.20",
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.19.",
92
+ "pattern_match_failure_message": "Use a version like 0.1.20.",
93
93
  "order": 10
94
94
  }
95
95
  },
@@ -0,0 +1,81 @@
1
+ """0.1.20: warn when newer data changes exist, since the RESTORE would undo them too."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+
7
+ from click.testing import CliRunner
8
+ from test_0114 import HISTORY, FakeDelta, sentry
9
+
10
+ from bricksentry.cli import main
11
+ from bricksentry.history import Change, newer_data_changes, rollback_warning
12
+ from bricksentry.models import TableAssessment
13
+ from bricksentry.notify import slack_payload, teams_payload
14
+ from bricksentry.report import to_markdown
15
+
16
+
17
+ def test_newer_data_changes_skips_maintenance_and_sorts():
18
+ hist = [{"version": 7, "operation": "WRITE", "timestamp": "t7"}, {"version": 6, "operation": "OPTIMIZE"},
19
+ {"version": 5, "operation": "MERGE", "timestamp": "t5"}, {"version": 4, "operation": "WRITE"}]
20
+ assert [h["version"] for h in newer_data_changes(hist, 4)] == [5, 7]
21
+ assert newer_data_changes(hist, 7) == []
22
+
23
+
24
+ def test_warning_text_lists_newest_first_and_caps():
25
+ c = Change("t", 2, 1, "DELETE", "", [2], newer=[{"version": v, "operation": "WRITE", "timestamp": ""}
26
+ for v in range(3, 8)])
27
+ w = rollback_warning(c)
28
+ assert w.startswith("Newer data changes exist: v7 (WRITE), v6 (WRITE), v5 (WRITE) and 2 more.")
29
+ assert "Restoring to v1 also undoes them" in w
30
+ assert rollback_warning(Change("t", 2, 1, "DELETE", "", [2])) is None
31
+
32
+
33
+ def test_latest_change_has_no_warning():
34
+ a, change = sentry().check_change("sales.orders")
35
+ assert change.newer == [] and a.tables[0].rollback_warning is None
36
+ assert "Before you restore" not in to_markdown(a)
37
+
38
+
39
+ def test_older_version_warns_about_newer_change():
40
+ a, change = sentry().check_change("sales.orders", version=2)
41
+ t = a.tables[0]
42
+ assert [h["version"] for h in change.newer] == [3] # the OPTIMIZE at v4 is not a data change
43
+ assert t.rollback == 'RESTORE TABLE "sales"."orders" TO VERSION AS OF 1'
44
+ assert t.rollback_warning.startswith("Newer data changes exist: v3 (MERGE, 2026-11-11 10:00:00).")
45
+ assert "Restoring to v1 also undoes it. Re-run that write" in t.rollback_warning
46
+ md = to_markdown(a)
47
+ assert md.index("Before you restore") < md.index("RESTORE TABLE")
48
+ assert "Before you restore sales.orders" in json.dumps(slack_payload(a))
49
+ assert "Before you restore sales.orders" in json.dumps(teams_payload(a))
50
+ assert TableAssessment.from_dict(t.to_dict()).rollback_warning == t.rollback_warning
51
+
52
+
53
+ def test_write_landing_during_the_check_is_caught():
54
+ class Busy(FakeDelta):
55
+ reads = 0
56
+
57
+ def history(self, table, limit=50):
58
+ self.reads += 1
59
+ if self.reads == 1:
60
+ return HISTORY
61
+ return [{"version": 5, "timestamp": "2026-11-11 10:10:00", "operation": "WRITE"}, *HISTORY]
62
+
63
+ a, change = sentry(Busy()).check_change("sales.orders")
64
+ assert change.version == 3 and [h["version"] for h in change.newer] == [5]
65
+ assert "v5 (WRITE" in a.tables[0].rollback_warning
66
+
67
+
68
+ def test_cli_text_and_json(monkeypatch, tmp_path):
69
+ db = FakeDelta()
70
+ monkeypatch.setattr("bricksentry.assess.make_backend", lambda spec: db)
71
+ cfg = tmp_path / "bricksentry.yml"
72
+ cfg.write_text("sandbox_schema: scratch\nassessment_store: false\nlineage: {type: static}\n")
73
+ r = CliRunner().invoke(main, ["check-last-change", "sales.orders", "-c", str(cfg), "--no-notify",
74
+ "--version", "2"])
75
+ assert r.exit_code in (0, 1), r.output
76
+ assert r.output.index("Warning before you undo: Newer data changes exist: v3") < r.output.index("Undo: RESTORE")
77
+ r = CliRunner().invoke(main, ["check-last-change", "sales.orders", "-c", str(cfg), "--no-notify",
78
+ "--version", "2", "--format", "json"])
79
+ d = json.loads(r.output)
80
+ assert d["change"]["newer_changes"][0]["version"] == 3
81
+ assert d["tables"][0]["rollback_warning"].startswith("Newer data changes exist")
@@ -1 +0,0 @@
1
- bricksentry[databricks,mcp]==0.1.19
File without changes
File without changes
File without changes
File without changes