Skip to content

workspace: fix archive count and partial copy cleanup - #250

Merged
openshift-merge-bot[bot] merged 3 commits into
openshift-eng:mainfrom
fonta-rh:workspace-coderabbit-fixes
Jul 31, 2026
Merged

workspace: fix archive count and partial copy cleanup#250
openshift-merge-bot[bot] merged 3 commits into
openshift-eng:mainfrom
fonta-rh:workspace-coderabbit-fixes

Conversation

@fonta-rh

@fonta-rh fonta-rh commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Include strikethrough items in the JSON sections[*].archived count so it matches the pointer text written to CLAUDE.md
  • Clean up partial domain directories on shutil.copytree failure to prevent stale workspace domains on subsequent runs

Follow-up to #249 — addresses CodeRabbit findings that landed after merge.

Test plan

  • python3 -m pytest plugins/workspace/tests/ — 50 passed
  • bash plugins/workspace/tests/test_setup.sh — 84 passed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Archive summaries now accurately include strikethrough items in reported archive totals.
    • Section-level archive counts now reflect all items moved to the archive, including strikethrough items.
    • Improved copy-on-write error handling to safely clean up incomplete destinations.
    • Cleanup is skipped when no destination directory exists, preventing unnecessary recovery failures.
  • Chores

    • Updated the workspace plugin version to 0.1.2.

Include strikethrough items in the JSON archived count so it matches
the pointer text. Clean up partial domain directories on copytree
failure to prevent stale workspace domains.

Co-Authored-By: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-ci

openshift-ci Bot commented Jul 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fonta-rh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The workspace scripts now include strikethrough items in archive totals and clean up partial destinations after failed copy-on-write operations. Workspace plugin metadata is updated to version 0.1.2.

Changes

Workspace updates

Layer / File(s) Summary
Archive count calculation
plugins/workspace/scripts/consolidate-project.py
Archive headers and per-section to_archive totals now include checked and strikethrough items.
Copy-on-write failure cleanup
plugins/workspace/scripts/domain-info.py
Failed copies attempt to remove partial destinations. The error includes a manual-removal warning when cleanup fails.
Plugin version metadata
.claude-plugin/marketplace.json, plugins/workspace/.claude-plugin/plugin.json
The workspace plugin version is updated from 0.1.1 to 0.1.2.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: ready-for-human-review

🚥 Pre-merge checks | ✅ 10 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Ai-Attribution ⚠️ Warning The PR states Claude Code was used; all three PR commits lack Assisted-by/Generated-by and use Co-Authored-By for Claude Opus, with CodeRabbit also co-authored. Replace AI Co-Authored-By trailers with the required Assisted-by or Generated-by Red Hat attribution trailer(s).
✅ Passed checks (10 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 archive count fix and partial copy cleanup changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
No-Weak-Crypto ✅ Passed The full PR diff adds archive counting, directory cleanup, and version changes only; it contains no weak crypto, custom crypto, or secret comparisons.
Container-Privileges ✅ Passed The PR adds no privileged, hostPID, hostNetwork, hostIPC, SYS_ADMIN, or allowPrivilegeEscalation settings. The existing USER 0:0 line is unchanged.
No-Sensitive-Data-In-Logs ✅ Passed The PR adds only a copy-failure error with exception text and a destination path; no passwords, tokens, PII, customer data, or hostnames are logged.
No-Hardcoded-Secrets ✅ Passed The PR diff adds only archive counting, cleanup handling, and version literals; scans found no secret-like assignments, credentials in URLs, private keys, or long base64 strings.
No-Injection-Vectors ✅ Passed The complete PR diff adds no SQL, shell=True, eval/exec, pickle.loads, os.system, or dangerouslySetInnerHTML; all YAML parsing uses yaml.safe_load.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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 `@plugins/workspace/scripts/consolidate-project.py`:
- Line 221: Unify the archived-item count used by the consolidation flow so both
JSON/CLAUDE.md pointers and build_archive_block() report checked items plus
strikethrough items. Update build_archive_block() and the surrounding
archive-list construction to reuse one shared count or list, then add positive
coverage for sections with strikethroughs and negative coverage for sections
without them.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: e8c53820-82bf-4e53-ae09-08ddffcb2a04

📥 Commits

Reviewing files that changed from the base of the PR and between 32d3e22 and 465a567.

📒 Files selected for processing (2)
  • plugins/workspace/scripts/consolidate-project.py
  • plugins/workspace/scripts/domain-info.py

Comment thread plugins/workspace/scripts/consolidate-project.py
Accepted after review:
- consolidate-project.py:152: unify archive block header count to include strikethroughs

Co-Authored-By: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai coderabbitai Bot added the ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review label Jul 31, 2026

@lucaconsalvi lucaconsalvi 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.

Thanks for the quick follow-up, Pablo!

Both fixes look correct and minimal — the archive count now agrees across all three sites (archive block header, CLAUDE.md pointer, JSON output), and the partial-copy cleanup addresses a real downstream problem where find_domain_dir would pick up a broken directory on the next run.

One suggestion inline on the cleanup path — everything else looks good to merge.

shutil.copytree(domain_dir, dest)
except (OSError, shutil.Error) as exc:
if dest.exists():
shutil.rmtree(dest, ignore_errors=True)

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.

Nit: ignore_errors=True is the right instinct here (cleanup should not mask the original error), but if rmtree fails, the partial directory stays behind — and find_domain_dir will discover it on the next run and treat it as a valid domain.

Worth reporting the cleanup failure so the user knows to remove it manually:

except (OSError, shutil.Error) as exc:
    cleanup_ok = True
    if dest.exists():
        try:
            shutil.rmtree(dest)
        except OSError:
            cleanup_ok = False
    msg = f"Failed to copy domain to workspace: {exc}"
    if not cleanup_ok:
        msg += (f" (warning: partial directory at {dest} could not be"
                " removed — delete it manually before retrying)")
    print(json.dumps({"status": "error", "error": msg}))
    return

Not blocking — the current version works for the common case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — applied in 2deb127. Now catches rmtree failure and appends a manual-cleanup warning to the error message.

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.

Looks good, thanks!

When rmtree fails to clean up a partial domain directory after a
copytree failure, warn the user to delete it manually. Bump plugin
version to 0.1.2.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@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

🧹 Nitpick comments (1)
plugins/workspace/scripts/domain-info.py (1)

240-250: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add copy-on-write cleanup failure tests. Cover shutil.copytree failure with a partial destination, successful cleanup, and failed cleanup with the manual-delete warning. Assert the JSON error and destination state for each case.

🤖 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 `@plugins/workspace/scripts/domain-info.py` around lines 240 - 250, Extend the
tests covering the domain-copy error path around shutil.copytree to simulate
failures with a partial destination. Add cases for successful cleanup and
cleanup failure, asserting the emitted JSON error and whether the destination is
removed or remains with the manual-delete warning; also cover the copy failure
with a partial destination state.
🤖 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 `@plugins/workspace/scripts/domain-info.py`:
- Around line 240-245: Update the domain copy flow around find_domain_dir() and
copytree() to copy into a uniquely created staging directory, then remove only
that staging directory on failure instead of deleting dest. Add a negative-path
test covering a destination created before copy failure and verify that
destination remains intact.

---

Nitpick comments:
In `@plugins/workspace/scripts/domain-info.py`:
- Around line 240-250: Extend the tests covering the domain-copy error path
around shutil.copytree to simulate failures with a partial destination. Add
cases for successful cleanup and cleanup failure, asserting the emitted JSON
error and whether the destination is removed or remains with the manual-delete
warning; also cover the copy failure with a partial destination state.
🪄 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 YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: b406333f-41ea-47c0-9b7a-93b218faccdd

📥 Commits

Reviewing files that changed from the base of the PR and between b00a836 and 2deb127.

📒 Files selected for processing (3)
  • .claude-plugin/marketplace.json
  • plugins/workspace/.claude-plugin/plugin.json
  • plugins/workspace/scripts/domain-info.py

Comment thread plugins/workspace/scripts/domain-info.py
@fonta-rh

Copy link
Copy Markdown
Contributor Author

Re: CodeRabbit review-body nitpick — add copy-on-write cleanup tests

Won't fix — generic "add tests" suggestion. The error paths are straightforward and the existing test suite covers the domain-info happy paths. Not adding speculative coverage for a race condition that isn't reachable (see inline reply).

@lucaconsalvi

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 31, 2026
@openshift-merge-bot
openshift-merge-bot Bot merged commit a0f0c9b into openshift-eng:main Jul 31, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ready-for-human-review Indicates a PR has been reviewed by automated tools and is ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants