Skip to content

Improved file ordering in session#41

Open
chris-adam wants to merge 1 commit into
mainfrom
PARAF-413/file_ordering
Open

Improved file ordering in session#41
chris-adam wants to merge 1 commit into
mainfrom
PARAF-413/file_ordering

Conversation

@chris-adam

@chris-adam chris-adam commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Improved file ordering when managing items in a session.
  • Tests

    • Added test coverage for item ordering functionality.

Review Change Stack

@chris-adam chris-adam marked this pull request as ready for review May 27, 2026 11:16
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR introduces IItemOrderProvider, a new Zope adapter interface for computing item ordering within a context. A default implementation enumerates context items and maps their UIDs to positions. The adapter is registered in ZCML, integrated into file session insertion logic to replace inline enumeration, and tested comprehensively.

Changes

Item Ordering Adapter Pattern

Layer / File(s) Summary
Interface and adapter implementation
src/imio/esign/interfaces.py, src/imio/esign/adapters.py, src/imio/esign/configure.zcml
IItemOrderProvider interface defines the contract for mapping item UIDs to sort positions. DefaultItemOrderProvider implements this by enumerating context items into a UID-to-index dict. Adapter is registered in ZCML for all contexts.
File session integration
src/imio/esign/utils.py
Imports IItemOrderProvider and refactors add_files_to_session to use getAdapter(context, IItemOrderProvider).get_item_order() instead of inline context.values() enumeration.
Adapter tests
src/imio/esign/tests/test_adapters.py
Validates DefaultItemOrderProvider returns correct UID-to-index mappings for both non-empty and empty folders, and confirms adapter integration.
Release notes
CHANGES.rst
Documents improved file ordering in session for version 1.0b9.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • IMIO/imio.esign#23: Both PRs modify src/imio/esign/utils.py to order session file insertion based on context item order; this PR abstracts the ordering into an adapter pattern.

Suggested reviewers

  • gbastien

Poem

🐰 A tidy refactor hops into view,
Where ordering logic gets its own avenue,
Adapters now handle the UID-to-slot dance,
While session files file in perfect stance! 📄✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% 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 title 'Improved file ordering in session' directly aligns with the core change: refactoring file ordering from inline logic to a dedicated adapter-based approach.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch PARAF-413/file_ordering

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/imio/esign/tests/test_adapters.py (1)

31-33: ⚡ Quick win

Assert complete UID→index mapping equality.

This loop validates expected keys but not unexpected extra entries in order. Build the expected mapping and assert full dict equality.

Proposed test tightening
-        children = list(folder.values())
-        for idx, child in enumerate(children):
-            self.assertEqual(order[child.UID()], idx)
+        children = list(folder.values())
+        expected_order = {child.UID(): idx for idx, child in enumerate(children)}
+        self.assertEqual(order, expected_order)
🤖 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 `@src/imio/esign/tests/test_adapters.py` around lines 31 - 33, The test
currently loops over children and asserts each child's UID maps to the expected
index but doesn't catch extra keys in order; instead, construct an expected
mapping from the actual children (e.g., expected = {child.UID(): idx for idx,
child in enumerate(list(folder.values()))}) and then assert equality between
expected and order (use assertEqual(expected, order)) so the test fails on both
missing and unexpected entries; update the code around the loop that references
children, folder.values(), order, and child.UID() accordingly.
🤖 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.

Nitpick comments:
In `@src/imio/esign/tests/test_adapters.py`:
- Around line 31-33: The test currently loops over children and asserts each
child's UID maps to the expected index but doesn't catch extra keys in order;
instead, construct an expected mapping from the actual children (e.g., expected
= {child.UID(): idx for idx, child in enumerate(list(folder.values()))}) and
then assert equality between expected and order (use assertEqual(expected,
order)) so the test fails on both missing and unexpected entries; update the
code around the loop that references children, folder.values(), order, and
child.UID() accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40137db8-1a6a-45cf-9565-5de5da02c4d1

📥 Commits

Reviewing files that changed from the base of the PR and between 3e06631 and 05e6fab.

📒 Files selected for processing (6)
  • CHANGES.rst
  • src/imio/esign/adapters.py
  • src/imio/esign/configure.zcml
  • src/imio/esign/interfaces.py
  • src/imio/esign/tests/test_adapters.py
  • src/imio/esign/utils.py

@coveralls

coveralls commented May 27, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 26507845761

Coverage increased (+0.2%) to 85.031%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 9 of 9 lines across 3 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1296
Covered Lines: 1102
Line Coverage: 85.03%
Coverage Strength: 0.85 hits per line

💛 - Coveralls

@chris-adam chris-adam requested review from gbastien and sgeulette May 27, 2026 11:22
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