Skip to content

fix(wren): load cubes from folder-per-entity layout - #2350

Merged
goldmedal merged 3 commits into
Canner:mainfrom
ttw225:fix/enrich-context-cube-path
Jun 9, 2026
Merged

goldmedal merged 3 commits into
Canner:mainfrom
ttw225:fix/enrich-context-cube-path

Conversation

@ttw225

@ttw225 ttw225 commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • update the cube loader to follow the documented folder-per-entity layout: cubes/<name>/metadata.yml
  • keep legacy schema_version: 1 cube loading from cubes/*.yml
  • update cube context tests to cover v1 flat files, v2 nested metadata files, and v3 using the v2 layout

Testing

  • uv run pytest tests/unit/test_context.py -k cube
  • uv run pytest tests/unit/test_context.py

Summary by CodeRabbit

  • Refactor
    • Projects now support schema-versioned cube layouts: legacy flat cube files remain supported, while newer projects use per-cube directories with metadata files.
  • Chores
    • Automated upgrade planning and application migrates legacy flat cube files into per-cube directories, creating metadata files and removing old flat files; upgrade rejects duplicate target mappings.
  • Tests
    • Unit tests updated to cover v1/v2 layouts, migration path, and validation messages referencing snake_case field names.

@github-actions github-actions Bot added documentation Improvements or additions to documentation python Pull requests that update Python code core labels Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e77051ce-87eb-403d-bb62-1884d54b116c

📥 Commits

Reviewing files that changed from the base of the PR and between 15bfa46 and bfc484c.

📒 Files selected for processing (2)
  • core/wren/src/wren/context.py
  • core/wren/tests/unit/test_context.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/wren/tests/unit/test_context.py

Walkthrough

Cube loading now dispatches on project schema version: v1 reads flat cubes/*.yml; v2+ read per-cube cubes/<name>/metadata.yml. Upgrade planning and application migrate v1 flat files into v2 directories. Tests add v2 fixtures and cover loading, validation, and upgrade scenarios.

Changes

Schema-versioned cube layout support

Layer / File(s) Summary
Cube loading dispatch and v2 loader implementation
core/wren/src/wren/context.py
load_cubes() dispatches on schema_version: v1 -> _load_cubes_v1() for cubes/*.yml; v2+ -> _load_cubes_v2() for cubes/<name>/metadata.yml. New helper computes migration targets and _source_file is set relative to cubes/.
v1→v2 upgrade planning (cubes)
core/wren/src/wren/context.py
Planner loads v1 cubes, computes cubes/<name>/metadata.yml targets, schedules creation of those metadata files and deletion of legacy flat cubes/*.yml; detects conflicting mappings and raises UpgradeError.
v1→v2 upgrade application (cubes)
core/wren/src/wren/context.py
Applier creates cubes/<name>/ directories, writes migrated metadata.yml from cube dicts, deletes legacy flat YAML files when present, and enforces duplicate-target guard.
Test helpers and schema-versioned loading tests
core/wren/tests/unit/test_context.py
Adds _make_v2_cube_project() and _write_cube() helpers; tests cover v1 flat-YAML parsing, v2 metadata.yml parsing, ensure v2 ignores flat YAMLs, and assert manifest/JSON fields from v2 fixtures.
Cube validation tests with v2 fixtures
core/wren/tests/unit/test_context.py
Reworks validation tests to use v2 fixtures for unknown base_object, duplicate names, missing base_object error message (snake_case), non-string hierarchy level, bad hierarchy reference, and a passing case.
Upgrade tests: v1 fixture and assertions
core/wren/tests/unit/test_context.py
v1 project fixture now writes a legacy flat cube file; plan_upgrade and apply_upgrade tests assert migration file creation, legacy file deletion, duplicate-target rejection, and that migrated cubes load correctly.

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested labels

skills

Suggested reviewers

  • goldmedal
  • chilijung

🐰 Schema versions hop from flat to neat,
Metadata nests where cube directories meet,
Tests write paths, migrations tick and hum,
A rabbit cheers the tidy home they’ve come!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. 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 pull request title accurately and specifically describes the main change: fixing the cube loader to support the folder-per-entity layout (cubes//metadata.yml) for v2+ cubes while preserving v1 legacy behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@goldmedal

Copy link
Copy Markdown
Collaborator

It seems to be a bug in the cube loader 🤔 . The layout described by the skill or the document is what we actually expected.

@ttw225

ttw225 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

It seems to be a bug in the cube loader 🤔 . The layout described by the skill or the document is what we actually expected.

Got it, thanks for clarifying. I’ll update this PR to fix the cube loader instead, so it recursively discovers cube files in nested directories as expected.

@ttw225
ttw225 force-pushed the fix/enrich-context-cube-path branch from 6e1fdbd to 0e3cfb6 Compare June 9, 2026 04:58
@ttw225 ttw225 changed the title fix(skills): fix enrich-context cube paths to flat cubes/<name>.yml fix(wren): load cubes from folder-per-entity layout Jun 9, 2026
@ttw225

ttw225 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR accordingly. The cube loader now follows the schema-version layout split: schema_version: 1 loads legacy cubes/*.yml, while schema_version >= 2 loads cubes/<name>/metadata.yml.

I also updated the tests to cover v1 flat cubes, v2 nested cube metadata, and v3 reusing the v2 layout.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/wren/src/wren/context.py`:
- Around line 617-637: The upgrade currently changes schema layout so
load_cubes() will call _load_cubes_v2() and ignore legacy flat cube files,
causing silent loss; update the v1→v2 migration by adding cube conversion logic
in _plan_v1_to_v2() / _apply_v1_to_v2() that detects files matching the old
pattern (cubes/*.yml), reads each legacy cube, creates a directory per cube name
under cubes/, writes metadata.yml with the same content (preserving the
_source_file if needed), and removes or archives the original flat file;
alternatively, add a clear warning in the upgrade plan if you prefer manual
migration so users aren’t silently dropped.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 63e98273-0588-4376-907d-a6ce9b2ce477

📥 Commits

Reviewing files that changed from the base of the PR and between 6e1fdbd and 0e3cfb6.

📒 Files selected for processing (2)
  • core/wren/src/wren/context.py
  • core/wren/tests/unit/test_context.py

Comment thread core/wren/src/wren/context.py
Migrate legacy cubes/*.yml files into cubes/<name>/metadata.yml during v1 to v2 upgrades so cubes remain visible after the schema_version bump.

Update upgrade tests to cover cube migration in the planned and applied upgrade paths.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/wren/tests/unit/test_context.py (1)

944-976: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use the documented hierarchy YAML shape in these cube tests.

The public cube contract is hierarchies: - name: ... levels: [...], but these fixtures use a mapping (hierarchies: drill: [...]). validate_project() currently only inspects dicts, so these tests don't cover the documented metadata.yml form and won't catch the case users actually write. Please switch the fixtures to the list-of-objects shape and normalize that form in validation, or update the docs if the mapping syntax is the real API.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/wren/tests/unit/test_context.py` around lines 944 - 976, The tests
test_validate_cube_non_string_hierarchy_level and
test_validate_cube_bad_hierarchy use the non-documented mapping form for
hierarchies; update their _write_cube fixtures to use the public shape
"hierarchies: - name: <name> levels: [...]" (e.g. replace "hierarchies:\n 
drill: ..." or "hierarchies:\n  drill:\n    - ..." with a list containing an
object with name and levels) so validate_project() exercises the documented
list-of-objects form; additionally ensure validate_project (the validation
logic) normalizes/accepts that list form (or add normalization) so hierarchy
validation checks still run against the new shape.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/wren/src/wren/context.py`:
- Around line 1201-1211: Detect and fail on duplicate migration target paths
when planning or applying v1→v2 cube migrations: in the planning phase where
cubes = _load_cubes_v1(project_path) is iterated (the block that builds created
and deleted lists using source_file, name and dir_path) and in the actual
migration implementation _apply_v1_to_v2(), check for collisions on the computed
destination path ("cubes/{name}/metadata.yml") by maintaining a set of seen
target paths; if a duplicate is detected raise UpgradeError with a clear message
instead of adding to created/deleted or writing files. Ensure both planning and
apply use the same helper logic to compute the destination and perform the
collision check so apply_upgrade() cannot silently overwrite and drop a cube.

---

Outside diff comments:
In `@core/wren/tests/unit/test_context.py`:
- Around line 944-976: The tests test_validate_cube_non_string_hierarchy_level
and test_validate_cube_bad_hierarchy use the non-documented mapping form for
hierarchies; update their _write_cube fixtures to use the public shape
"hierarchies: - name: <name> levels: [...]" (e.g. replace "hierarchies:\n 
drill: ..." or "hierarchies:\n  drill:\n    - ..." with a list containing an
object with name and levels) so validate_project() exercises the documented
list-of-objects form; additionally ensure validate_project (the validation
logic) normalizes/accepts that list form (or add normalization) so hierarchy
validation checks still run against the new shape.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8b6c24ef-3a7a-4614-a8ab-ef2136e93da0

📥 Commits

Reviewing files that changed from the base of the PR and between 0e3cfb6 and 15bfa46.

📒 Files selected for processing (2)
  • core/wren/src/wren/context.py
  • core/wren/tests/unit/test_context.py

Comment thread core/wren/src/wren/context.py
Load v1 cubes from legacy cubes/*.yml and v2+ cubes from cubes/<name>/metadata.yml, matching the folder-per-entity project layout.

Migrate legacy cube files during v1->v2 upgrades and reject duplicate cube migration targets to avoid silent overwrites.

Update cube and upgrade tests for v1, v2, and v3 layout behavior.

@goldmedal goldmedal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ttw225 look great 👍

@goldmedal
goldmedal merged commit 6f2542e into Canner:main Jun 9, 2026
10 checks passed
@ttw225
ttw225 deleted the fix/enrich-context-cube-path branch June 9, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core documentation Improvements or additions to documentation python Pull requests that update Python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants