UAT: agents resource remove does not check project links before deletion — spec requires failure when resource is linked to a project #2446

Open
opened 2026-04-03 18:23:28 +00:00 by freemo · 1 comment
Owner

Metadata

  • Commit Message: fix(resource): fail resource remove when resource is linked to a project
  • Branch: bugfix/resource-remove-project-link-check

Background and Context

The specification (line 10952–10953) states:

Cascading Deletion: Removes a registered resource and all its auto-discovered child resources. This operation fails if the resource is linked to any project — use agents project unlink-resource first.

The current resource remove implementation in src/cleveragents/cli/commands/resource.py (lines 1277–1343) does not check whether the resource is linked to any project before proceeding with deletion. It only checks for DAG edges (which is itself broken per issue #2407/#2383), but never queries the ProjectResourceLinkRepository to verify the resource is not linked to any project.

Current Behavior

Running agents resource remove local/api-repo on a resource that is linked to one or more projects via agents project link-resource will:

  1. Prompt for confirmation (unless --yes is passed)
  2. Check for DAG edges (and abort if any exist — wrong behavior per spec)
  3. Delete the resource directly without checking project links

A resource linked to a project can be deleted without first unlinking it, violating the spec's safety requirement.

Expected Behavior

Before deleting a resource, agents resource remove must:

  1. Query the ProjectResourceLinkRepository (or equivalent) to find all projects that have this resource linked
  2. If any project links exist, abort with an error message such as:
    Error: Resource 'local/api-repo' is linked to 1 project(s): local/api-service.
    Use 'agents project unlink-resource <project> local/api-repo' first.
    
  3. Only proceed with deletion if no project links exist

Steps to Reproduce (Code Analysis)

  1. Open src/cleveragents/cli/commands/resource.py, function resource_remove() (line ~1270)
  2. Observe that the function calls service.show_resource(resource) to verify existence
  3. Then checks for DAG edges via ResourceEdgeModel query
  4. Missing: No query against ProjectResourceLinkModel or project_resource_link_repo to check project links
  5. The _get_resource_link_repo() helper exists in project.py but is never called from resource_remove()

Code Location

  • File: src/cleveragents/cli/commands/resource.py
  • Function: resource_remove() (line ~1270)
  • Missing check: Query ProjectResourceLinkRepository.list_links_by_resource(resource_id) before deletion

Subtasks

  • Add project-link check to resource_remove() in src/cleveragents/cli/commands/resource.py
  • Query ProjectResourceLinkRepository (or equivalent) for all projects linking this resource
  • If any project links exist, print an error listing the linked projects and abort
  • Add unit tests for the new check
  • Add integration test verifying the error message format

Definition of Done

  • All subtasks completed
  • agents resource remove local/api-repo fails with a clear error when the resource is linked to a project
  • agents resource remove local/api-repo succeeds after unlinking from all projects
  • Tests pass
  • Commit pushed to bugfix/resource-remove-project-link-check with the specified commit message
  • PR merged

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Metadata - **Commit Message**: `fix(resource): fail resource remove when resource is linked to a project` - **Branch**: `bugfix/resource-remove-project-link-check` ## Background and Context The specification (line 10952–10953) states: > **Cascading Deletion**: Removes a registered resource and all its auto-discovered child resources. This operation **fails if the resource is linked to any project** — use `agents project unlink-resource` first. The current `resource remove` implementation in `src/cleveragents/cli/commands/resource.py` (lines 1277–1343) does **not** check whether the resource is linked to any project before proceeding with deletion. It only checks for DAG edges (which is itself broken per issue #2407/#2383), but never queries the `ProjectResourceLinkRepository` to verify the resource is not linked to any project. ## Current Behavior Running `agents resource remove local/api-repo` on a resource that is linked to one or more projects via `agents project link-resource` will: 1. Prompt for confirmation (unless `--yes` is passed) 2. Check for DAG edges (and abort if any exist — wrong behavior per spec) 3. Delete the resource directly **without checking project links** A resource linked to a project can be deleted without first unlinking it, violating the spec's safety requirement. ## Expected Behavior Before deleting a resource, `agents resource remove` must: 1. Query the `ProjectResourceLinkRepository` (or equivalent) to find all projects that have this resource linked 2. If any project links exist, **abort with an error** message such as: ``` Error: Resource 'local/api-repo' is linked to 1 project(s): local/api-service. Use 'agents project unlink-resource <project> local/api-repo' first. ``` 3. Only proceed with deletion if no project links exist ## Steps to Reproduce (Code Analysis) 1. Open `src/cleveragents/cli/commands/resource.py`, function `resource_remove()` (line ~1270) 2. Observe that the function calls `service.show_resource(resource)` to verify existence 3. Then checks for DAG edges via `ResourceEdgeModel` query 4. **Missing**: No query against `ProjectResourceLinkModel` or `project_resource_link_repo` to check project links 5. The `_get_resource_link_repo()` helper exists in `project.py` but is never called from `resource_remove()` ## Code Location - **File**: `src/cleveragents/cli/commands/resource.py` - **Function**: `resource_remove()` (line ~1270) - **Missing check**: Query `ProjectResourceLinkRepository.list_links_by_resource(resource_id)` before deletion ## Subtasks - [ ] Add project-link check to `resource_remove()` in `src/cleveragents/cli/commands/resource.py` - [ ] Query `ProjectResourceLinkRepository` (or equivalent) for all projects linking this resource - [ ] If any project links exist, print an error listing the linked projects and abort - [ ] Add unit tests for the new check - [ ] Add integration test verifying the error message format ## Definition of Done - [ ] All subtasks completed - [ ] `agents resource remove local/api-repo` fails with a clear error when the resource is linked to a project - [ ] `agents resource remove local/api-repo` succeeds after unlinking from all projects - [ ] Tests pass - [ ] Commit pushed to `bugfix/resource-remove-project-link-check` with the specified commit message - [ ] PR merged --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • MoSCoW: Should Have — Important spec requirement or quality improvement. Should be included in the milestone if possible.

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **MoSCoW**: Should Have — Important spec requirement or quality improvement. Should be included in the milestone if possible. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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#2446
No description provided.