feat(resource): implement ResourceHandler CRUD and discovery methods #1054

Merged
hamza.khyari merged 1 commit from feature/resource-handler-crud into master 2026-03-24 14:40:34 +00:00
Member

Summary

  • Extend the ResourceHandler protocol with six new content operations: read, write, delete, list_children, diff, and discover_children
  • Add frozen dataclass result types (Content, WriteResult, DeleteResult, DiffResult) to the handler protocol
  • Implement all six methods for GitCheckoutHandler (via git plumbing + filesystem), FsDirectoryHandler (via pathlib/os/difflib), and partial support for DevcontainerHandler (read/write/discover via devcontainer exec)
  • DatabaseResourceHandler inherits NotImplementedError stubs pending connection management
  • 19 Behave scenarios + 2 Robot integration tests (read → write → diff cycle) covering all handlers

Details

Protocol Extension (protocol.py)

  • Content — frozen dataclass with data: bytes, encoding, content_hash, metadata, and a .text convenience property
  • WriteResultsuccess, bytes_written, content_hash, message
  • DeleteResultsuccess, message
  • DiffResulthas_changes, unified_diff, files_changed, insertions, deletions
  • All six methods added to ResourceHandler Protocol with full Google-style docstrings

Base Handler (_base.py)

  • NotImplementedError defaults for all six methods so existing handlers remain valid
  • _require_location() helper extracted for DRY location validation
  • _derive_child_id() helper for generating ULID-valid child resource IDs

Handler Implementations

  • GitCheckoutHandler: read (git show + fs fallback), write (file write), delete (unlink + git rm --cached), list_children (git ls-tree), diff (git diff --no-index), discover_children (git ls-tree -d)
  • FsDirectoryHandler: read (pathlib), write (pathlib), delete (unlink/rmtree), list_children (os.listdir), diff (difflib unified), discover_children (os.scandir)
  • DevcontainerHandler: read (devcontainer exec cat), write (devcontainer exec tee), discover_children (devcontainer exec ls)

Tests

  • 19 Behave scenarios: read, write, delete, list_children, diff, discover_children for FsDirectory and GitCheckout handlers, plus NotImplementedError defaults for Database handler
  • 2 Robot integration tests: full read → write → diff cycle on real temp directories and git repos

ISSUES CLOSED: #827

## Summary - Extend the `ResourceHandler` protocol with six new content operations: `read`, `write`, `delete`, `list_children`, `diff`, and `discover_children` - Add frozen dataclass result types (`Content`, `WriteResult`, `DeleteResult`, `DiffResult`) to the handler protocol - Implement all six methods for `GitCheckoutHandler` (via git plumbing + filesystem), `FsDirectoryHandler` (via pathlib/os/difflib), and partial support for `DevcontainerHandler` (read/write/discover via `devcontainer exec`) - `DatabaseResourceHandler` inherits `NotImplementedError` stubs pending connection management - 19 Behave scenarios + 2 Robot integration tests (read → write → diff cycle) covering all handlers ## Details ### Protocol Extension (`protocol.py`) - `Content` — frozen dataclass with `data: bytes`, `encoding`, `content_hash`, `metadata`, and a `.text` convenience property - `WriteResult` — `success`, `bytes_written`, `content_hash`, `message` - `DeleteResult` — `success`, `message` - `DiffResult` — `has_changes`, `unified_diff`, `files_changed`, `insertions`, `deletions` - All six methods added to `ResourceHandler` Protocol with full Google-style docstrings ### Base Handler (`_base.py`) - `NotImplementedError` defaults for all six methods so existing handlers remain valid - `_require_location()` helper extracted for DRY location validation - `_derive_child_id()` helper for generating ULID-valid child resource IDs ### Handler Implementations - **GitCheckoutHandler**: `read` (git show + fs fallback), `write` (file write), `delete` (unlink + git rm --cached), `list_children` (git ls-tree), `diff` (git diff --no-index), `discover_children` (git ls-tree -d) - **FsDirectoryHandler**: `read` (pathlib), `write` (pathlib), `delete` (unlink/rmtree), `list_children` (os.listdir), `diff` (difflib unified), `discover_children` (os.scandir) - **DevcontainerHandler**: `read` (devcontainer exec cat), `write` (devcontainer exec tee), `discover_children` (devcontainer exec ls) ### Tests - 19 Behave scenarios: read, write, delete, list_children, diff, discover_children for FsDirectory and GitCheckout handlers, plus NotImplementedError defaults for Database handler - 2 Robot integration tests: full read → write → diff cycle on real temp directories and git repos ISSUES CLOSED: #827
hamza.khyari added this to the v3.6.0 milestone 2026-03-18 11:30:19 +00:00
freemo approved these changes 2026-03-19 04:55:33 +00:00
Dismissed
freemo left a comment

Code Review — PR #1054 feat(resource): implement ResourceHandler CRUD and discovery methods

Comprehensive implementation across the full handler hierarchy. The architecture is clean: protocol layer defines 4 frozen dataclasses + 6 method signatures, base layer provides DRY helpers and NotImplementedError defaults, and each handler implements what it can. Good design decisions:

  • Content.text property with encoding-aware decode
  • _derive_child_id() using SHA-256 → Crockford Base32 for ULID-compatible IDs
  • GitCheckoutHandler with filesystem fallback for untracked files
  • DevcontainerHandler implementing read/write/discover via devcontainer exec

19 Behave scenarios + 2 Robot integration tests provide solid coverage. The DatabaseResourceHandler correctly inherits NotImplementedError stubs pending connection management — good boundary decision.

Approved. No issues found.

## Code Review — PR #1054 `feat(resource): implement ResourceHandler CRUD and discovery methods` Comprehensive implementation across the full handler hierarchy. The architecture is clean: protocol layer defines 4 frozen dataclasses + 6 method signatures, base layer provides DRY helpers and `NotImplementedError` defaults, and each handler implements what it can. Good design decisions: - `Content.text` property with encoding-aware decode - `_derive_child_id()` using SHA-256 → Crockford Base32 for ULID-compatible IDs - `GitCheckoutHandler` with filesystem fallback for untracked files - `DevcontainerHandler` implementing read/write/discover via `devcontainer exec` 19 Behave scenarios + 2 Robot integration tests provide solid coverage. The `DatabaseResourceHandler` correctly inherits `NotImplementedError` stubs pending connection management — good boundary decision. **Approved.** No issues found.
Owner

Day 43 Review — Rebase Required

This PR has merge conflicts with master and cannot be merged in its current state. This is one of 9 Hamza PRs in the resource/LSP domain (v3.5.0-v3.6.0) that all have conflicts. These PRs likely share a common dependency chain and should be rebased sequentially.

@hamza.khyari: Please rebase onto current master. If multiple PRs depend on each other, start with the base PR in the chain and work upward.

Rebase priority: HIGH — these PRs represent significant feature work that is blocked by merge conflicts. Every day they remain conflicted is a day they cannot be reviewed or merged.

**Day 43 Review — Rebase Required** This PR has merge conflicts with `master` and cannot be merged in its current state. This is one of 9 Hamza PRs in the resource/LSP domain (v3.5.0-v3.6.0) that all have conflicts. These PRs likely share a common dependency chain and should be rebased sequentially. @hamza.khyari: Please rebase onto current `master`. If multiple PRs depend on each other, start with the base PR in the chain and work upward. **Rebase priority**: HIGH — these PRs represent significant feature work that is blocked by merge conflicts. Every day they remain conflicted is a day they cannot be reviewed or merged.
hamza.khyari force-pushed feature/resource-handler-crud from 7a73033970
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 16s
CI / build (pull_request) Successful in 29s
CI / quality (pull_request) Successful in 35s
CI / typecheck (pull_request) Successful in 40s
CI / security (pull_request) Successful in 43s
CI / unit_tests (pull_request) Failing after 2m55s
CI / docker (pull_request) Has been skipped
CI / integration_tests (pull_request) Failing after 3m38s
CI / e2e_tests (pull_request) Successful in 3m52s
CI / coverage (pull_request) Successful in 6m8s
CI / benchmark-regression (pull_request) Successful in 37m46s
to 295b0aa19f
Some checks failed
CI / build (pull_request) Successful in 35s
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 3m23s
CI / integration_tests (pull_request) Failing after 3m37s
CI / unit_tests (pull_request) Failing after 3m44s
CI / quality (pull_request) Successful in 3m47s
CI / security (pull_request) Successful in 4m1s
CI / typecheck (pull_request) Successful in 4m9s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 7m44s
CI / coverage (pull_request) Successful in 11m20s
CI / status-check (pull_request) Failing after 2s
CI / benchmark-regression (pull_request) Has been cancelled
2026-03-24 12:36:34 +00:00
Compare
hamza.khyari dismissed freemo's review 2026-03-24 12:36:34 +00:00
Reason:

New commits pushed, approval review dismissed automatically according to repository settings

hamza.khyari force-pushed feature/resource-handler-crud from e7b5330a6b
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 18s
CI / lint (pull_request) Successful in 3m18s
CI / integration_tests (pull_request) Successful in 3m37s
CI / typecheck (pull_request) Successful in 3m48s
CI / quality (pull_request) Successful in 3m50s
CI / security (pull_request) Successful in 3m57s
CI / e2e_tests (pull_request) Successful in 5m15s
CI / unit_tests (pull_request) Successful in 5m49s
CI / docker (pull_request) Successful in 1m8s
CI / coverage (pull_request) Successful in 11m21s
CI / status-check (pull_request) Successful in 1s
CI / benchmark-regression (pull_request) Has been cancelled
to 90e5bbb99c
All checks were successful
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 17s
CI / lint (pull_request) Successful in 3m17s
CI / unit_tests (pull_request) Successful in 3m38s
CI / quality (pull_request) Successful in 3m42s
CI / typecheck (pull_request) Successful in 3m54s
CI / security (pull_request) Successful in 4m2s
CI / docker (pull_request) Successful in 50s
CI / e2e_tests (pull_request) Successful in 8m32s
CI / integration_tests (pull_request) Successful in 6m54s
CI / coverage (pull_request) Successful in 14m10s
CI / status-check (pull_request) Successful in 1s
CI / benchmark-regression (pull_request) Successful in 59m15s
2026-03-24 13:53:58 +00:00
Compare
hamza.khyari scheduled this pull request to auto merge when all checks succeed 2026-03-24 14:00:47 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core!1054
No description provided.