Skip to content

fix(plan): show each item of a changed list property - #87

Open
GClunies wants to merge 3 commits into
datacoves:mainfrom
GClunies:fix/plan-show-list-items
Open

GClunies wants to merge 3 commits into
datacoves:mainfrom
GClunies:fix/plan-show-list-items

Conversation

@GClunies

@GClunies GClunies commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

snowcap plan shows a changed list property one item per row, with the before and after values side by side. Before this change, a list longer than 60 chars collapsed to <1 line, N chars>, so a reviewer could not see what changed (#86).

_plan_value_rows(key, before, after)
  if neither side is a list
    return one summarized row                    # as before
  match items of before and after with difflib   # an insert does not shift later rows
  for each matched run
    unchanged and longer than 3 items -> "<N unchanged items>"
    otherwise                          -> one row per item pair
  after 20 rows                        -> "<N more items>"
  wrap each item at 60 chars onto continuation rows

A dict item shows as key: value pairs. A multiline item still collapses, because the table cannot show a newline. A non-list side is one item, so a string before a list does not split into characters.

A resource monitor trigger change now reads:

│ triggers │ threshold: 50, action: NOTIFY  │ threshold: 50, action: NOTIFY   │
│          │ threshold: 75, action: NOTIFY  │ threshold: 75, action: NOTIFY   │
│          │ threshold: 90, action: NOTIFY  │ threshold: 90, action: NOTIFY   │
│          │ threshold: 100, action: NOTIFY │ threshold: 100, action: SUSPEND │

A 300-entry allowed_ip_list with one changed CIDR reads:

│ allowed_ip_list │ <150 unchanged items> │ <150 unchanged items> │
│                 │ 10.0.0.150/32         │ 192.168.0.1/32        │
│                 │ <149 unchanged items> │ <149 unchanged items> │

Evidence

The size of the plan for the cases in the review, rendered with dump_plan:

Case main First commit of this PR This PR now
300 IPs, 1 changed CIDR 11 lines, change hidden 311 lines 14 lines, change shown
View columns delta, table width about 90 chars, change hidden 307 chars 138 chars (60 per value cell)
_plan_value_rows("x", "abc", ["a"]) n/a 3 rows 1 row
  • Before: TestPlanValueRows and test_plan_text_shows_each_item_of_a_changed_list (in tests/test_blueprint.py): 7 of 9 fail on the first commit of this PR.
    After: 9 of 9 pass.
test_unchanged_items_of_a_long_list_collapse           300 IPs, 1 change -> 3 rows
test_a_short_run_of_unchanged_items_is_shown           3 unchanged items stay visible
test_an_inserted_item_does_not_shift_the_items_after   insert mid-list -> 1 changed row
test_a_long_item_wraps_within_the_value_width          every cell <= 60 chars
test_a_long_list_of_changes_ends_with_a_count          30 changes -> 20 rows + "<10 more items>"
test_a_non_list_side_is_one_item                       "abc" vs ["a"] -> 1 row
  • Unit suite pytest tests --ignore=tests/integration: 2236 passed, 1 skipped, 1 xfailed. On current main merged in: 2325 passed.
  • make lint and make typecheck: clean. CI build passes on Python 3.10, 3.11, and 3.12.

Merge Danger

Door: two-way

The change affects only the text that snowcap plan prints. The JSON plan and the SQL that apply runs do not change.

Blast Radius: cosmetic

A script that parses the text plan table sees more rows for a list property.

🤖 Generated with Claude Code

https://claude.ai/code/session_011dXsGKEWRyMmCh5dZHtQVU

A changed list (resource monitor triggers, network policy IPs, hybrid
table indexes) rendered as one table cell. Past 60 characters the cell
collapsed to '<1 line, N chars>', so the plan hid what changed. Show one
item per row, before and after side by side, with dict items as
key: value pairs.
@noel

noel commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Reviewed this PR. Checked out the branch, read the surrounding plan-rendering code and the diff / fetch_remote_state paths that feed change.before and change.delta, ran the unit suite (2229 passed, 1 skipped, 1 xfailed), and exercised _plan_value_rows / dump_plan directly with realistic inputs.

The computation is correct for the cases it targets and the new test is sound. My three findings are all about what the change removed rather than what it computes.

  1. blueprint.py:907, _plan_item caps nothing. A long list item is printed in full, which drops the 60-char bound that _summarize_plan_value exists to apply. A View columns delta produced a 307-char-wide plan table on this branch, against roughly 90 on main.

  2. blueprint.py:901, no row cap. A 300-entry allowed_ip_list with one changed CIDR renders 311 plan lines, against 11 on main, because unchanged items get a row too. Showing every item is the point of the PR, so the fix is probably a cap with an "and N more" line rather than reverting, but 311 lines for a one-CIDR change is worse than the summary it replaced.

  3. blueprint.py:901, low confidence. The isinstance(before, list) or isinstance(after, list) guard then iterates both sides, so a string before with a list after yields one row per character: _plan_value_rows('x', 'abc', ['a']) gives 3 rows. Spec coercion makes this unreachable from a live plan, but plan_from_dict reading a JSON plan file is untyped. Trivial fix: guard each side separately.

@noel

noel commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@GClunies checking in, quiet since my Oct 18 review.

The computation is correct and the test is sound, so this is close. All three findings are about the caps the change removed rather than anything it computes: no per-item width cap (a View columns delta renders a 307-char-wide table against roughly 90 on main) and no row cap (a 300-entry allowed_ip_list with one changed CIDR renders 311 lines against 11). Showing every item is the point of the PR, so a cap with an "and N more" line is probably the right shape rather than a revert.

Are you planning to make those updates?

Address review on datacoves#87:

- Wrap a list item longer than 60 chars onto continuation rows, so
  each cell stays within the value width.
- Match items with difflib, so an inserted item does not shift the
  rows after it.
- Collapse a run of more than 3 unchanged items to its count, and
  collapse the rows after the first 20 to their count.
- Read each side separately, so a string before a list is one item,
  not one row per character.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011dXsGKEWRyMmCh5dZHtQVU
@GClunies

Copy link
Copy Markdown
Contributor Author

@noel thanks for the review. All three findings are fixed in 15312c6.

Finding Fix Result
1. _plan_item caps nothing An item longer than 60 chars wraps onto continuation rows. View columns delta: 138 chars wide (60 per value cell), not 307. Each item still shows in full.
2. No row cap Items match with difflib. A run of more than 3 unchanged items collapses to <N unchanged items>. After 20 rows, the rest collapse to <N more items>. 300-entry allowed_ip_list, 1 changed CIDR: 14 plan lines, not 311. An insert mid-list no longer shifts the rows after it.
3. String before, list after Each side is read separately. A non-list side is one item. _plan_value_rows("x", "abc", ["a"]) gives 1 row.

I collapsed unchanged runs instead of a plain "first N rows" cap. A plain cap can hide the one changed item, for example a CIDR at position 250. The 20-row cap is only a backstop for a list where most items change.

Tests: TestPlanValueRows in tests/test_blueprint.py has one case per finding. Unit suite: 2236 passed. make lint: clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011dXsGKEWRyMmCh5dZHtQVU
@noel

noel commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

@GClunies thanks, re-reviewed at b8c7cfc. All three findings from Oct 18 are fixed: long items wrap at 60, a long list collapses its unchanged runs, and a string on one side no longer becomes one row per character. Suite, mypy and lint are clean, and a trial merge with current main has no conflicts.

One thing to fix before merge:

  1. Medium. blueprint.py _plan_item: a changed multi-line item can show as unchanged. Any item with a \n is turned into _summarize_plan_value's <N lines, M chars> before SequenceMatcher runs, so the diff compares summaries. A column comment edited from "foo\nbar" to "baz\nbar" keeps its line and character counts, both sides summarize the same, and the plan says nothing changed:

    _plan_value_rows("x", ["a\nb", "p", "q", "r", "s"], ["c\nd", "p", "q", "r", "s"]) renders <5 unchanged items> on both sides.

    On main that change shows a neutral summary and never claims "unchanged". Diff on the raw str(item) and summarize only at render time, plus a test for a same-shape multi-line edit.

Low, fine as follow-ups:

  • The same root cause makes [1, 2, 3, 4] against ["1", "2", "3", "4"] read as unchanged. Diffing raw values fixes both.
  • An inserted "" item is invisible, since "" is also the filler for "nothing on this side".
  • With exactly 21 rows, the last item becomes <1 more items>. Collapsing only when two or more rows would be hidden fixes the count and the grammar.

Simplification, optional: width, max_items and max_unchanged on _plan_value_rows are never passed by a caller or test, so they can be constants. _wrap_plan_item is a one-line helper used once and can be inlined.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants