Skip to content

Check the field depth limit again inside the store's lock - #250

Merged
SirLouen merged 7 commits into
mainfrom
fix/244
Sep 24, 2026
Merged

SirLouen merged 7 commits into
mainfrom
fix/244

Conversation

@SirLouen

@SirLouen SirLouen commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Closes #244

What

The store now checks the field depth limit again inside its lock, on every field move and every new sub field, where it already checks that a field cannot move inside itself. The registry hands it the limit GOPHENBERG_FIELD_DEPTH sets. Two moves, or a move and a new sub field, that each pass on their own but together would nest a field too deep now leave the second one refused with field_too_deep.

Why

The limit was only checked before the store took its lock, so two writes arriving at the same moment were each judged on the tree as it stood before the other landed. Both could pass and leave a field deeper than the site allows.

Testing Instructions

  1. Start the test database with docker compose up -d and run make cover. TestTwoMovesAtTheSameMomentLeaveNoFieldPastTheLimit holds the store's lock, queues two moves that each pass alone, releases them together and expects the second one refused with no field past the limit.
  2. Run make lint.

Summary by CodeRabbit

  • Bug Fixes
    • Field creation and moves now consistently enforce configured nesting-depth limits, including when multiple operations happen concurrently.
    • Operations that would exceed the limit are refused, and the field structure remains within the configured depth.
    • Depth checks also apply when moving fields to a group without a parent, helping prevent invalid nesting in that case.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: gopherium/gophenberg/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: f5b1346e-7fe4-48ed-91e0-9167eb871ac3

📥 Commits

Reviewing files that changed from the base of the PR and between de832f4 and 46037f7.

📒 Files selected for processing (1)
  • internal/postgres/field_depth_race_test.go

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Field creation and movement now pass a nesting-depth limit to storage operations. The PostgreSQL store checks that limit when it creates or moves fields. New tests cover over-limit operations and concurrent requests.

Changes

Field depth enforcement

Layer / File(s) Summary
Depth checks and limit propagation
internal/content/field_tree.go, internal/content/registry_groups.go, internal/content/types.go, internal/content/registry_*_test.go, internal/seed/*_test.go, internal/server/*_test.go
The content package adds WithinDepth. The registry uses it and passes the configured depth limit to store operations. The TypeStore interface and its test doubles accept the new limit argument.
Depth validation in PostgreSQL writes
internal/postgres/groups.go, internal/postgres/field_depth_race_test.go, internal/postgres/*_test.go
PostgreSQL checks depth limits when creating subfields and moving fields. Tests cover rejected writes, concurrent moves, and existing field operations with the added limit argument.
Concurrent request coverage
test/features/features/containers.feature, test/features/memorytypes_test.go, test/features/steps_containers_test.go, test/features/world_test.go
Feature tests add concurrent move and move-plus-declaration scenarios. The in-memory test store enforces depth limits and supports frozen registry views for judging requests against the same starting state.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to 46037

No outstanding issue identified here blocks merging after the prescribed tests and lint checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.93% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 97 functions across 30 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: rechecking the field depth limit inside the store lock during field operations.
Linked Issues check ✅ Passed The changes satisfy the coding requirements in issue #244. Registry.CreateSubField and MoveFieldSettled pass r.FieldDepth() to the store. internal/postgres/groups.go validates the destination …
Out of Scope Changes check ✅ Passed The changes stay within issue #244. The interface changes, registry propagation, PostgreSQL locked checks, in-memory test-store behavior, test-double updates, and concurrency tests directly support de…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

No outstanding findings block merging.

Summary

The PR adds a lock-queued PostgreSQL test for a field move competing with sub-field creation, addressing the previously noted coverage gap. No new actionable issue was identified.

Reviews (2) · Last reviewed commit: "test(postgres): race a move against a ne..."

Comment thread test/features/steps_containers_test.go
@SirLouen
SirLouen merged commit e84e0f3 into main Sep 24, 2026
10 checks passed
@SirLouen
SirLouen deleted the fix/244 branch September 24, 2026 14:43
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.

Two field moves at the same moment can nest a field past the depth limit

1 participant