Skip to content

Add dataset deletion system (Epic #128) - #132

Merged
neuromechanist merged 7 commits into
devfrom
feature/issue-128-epic-deletion
Feb 12, 2026
Merged

neuromechanist merged 7 commits into
devfrom
feature/issue-128-epic-deletion

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Complete dataset deletion system: role-based access control, S3 object deletion, GitHub repo deletion, cascade deletion with admin route, CLI command, and scheduled cron cleanup.

Phases (all squash-merged):

Key changes:

  • Role-based access: owner > admin > member hierarchy with middleware
  • DELETE /admin/datasets/:id with DOI/owner permission checks, active pub-request blocking
  • nemar admin delete-dataset <id> CLI command with confirmation prompt
  • Daily cron: sandbox datasets (14d), stale unpublished nm datasets (90d)
  • deleteDatasetCascade shared service: GitHub repo + S3 objects + D1 batch delete
  • 3 new migrations: user roles, drop is_admin, last_activity_at with backfill
  • Tests: S3 deletion (unit), GitHub deletion (integration), cascade deletion (integration)

Test plan

  • bunx biome check clean in both backend/ and root
  • bunx tsc --noEmit clean in backend/
  • bun test passes (existing + new tests)
  • Manual: create sandbox dataset, delete via CLI, verify cleanup
  • Manual: verify cron trigger config in wrangler.toml
  • Verify migration backfill protects live datasets from cron

Phase 1 of deletion epic (#128). Adds deleteObjects, deleteDatasetObjects,
and deleteStagingObjects to backend/src/services/s3.ts.

- S3 Multi-Object Delete API with 1000-key batching
- bypassGovernance flag for Object Lock GOVERNANCE mode
- Dataset ID and PR number validation
- Robust XML response parsing with batch count validation
- Try-catch around fetch for partial progress preservation
- Refactored applyObjectLock to reuse computeMd5Base64 helper
- Integration tests in test/s3-deletion.test.ts (skip when no AWS creds)

Closes #123
Phase 2 of deletion epic (#128). Adds deleteRepository to
backend/src/services/github.ts.

- Idempotent: returns true for 204 (deleted) and 404 (already gone)
- Repo name validation (rejects /, .., empty strings)
- Tight status check (204/404 only, not all 2xx)
- Integration tests in test/github-deletion.test.ts

Closes #124
Phase 3 of epic #128: wires S3 and GitHub deletion into a full cascade.

- Add shared deleteDatasetCascade service (GitHub, S3, D1 batch delete)
- Add DELETE /admin/datasets/:id with DOI/owner permission checks
- Add admin delete-dataset CLI command with confirmation prompt
- Add scheduled cron cleanup (sandbox 14d, stale nm 90d)
- Add last_activity_at migration with backfill
- Harden error handling: all steps reflected in deleted field,
  independent try-catch for cron queries and audit log writes
@github-actions

github-actions Bot commented Feb 12, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR132

Version: 0.4.0-PR132.1a8794c
Commit: 1a8794c


🤖 Updated on each push.

- Fix CLAUDE.md: document deletion system (was still saying "not implemented")
- Fix 'completed' -> 'published' status in pub-request blocking query
- Return HTTP 207 on partial deletion failure (was always 200)
- Handle no-body DELETE requests (don't require JSON body)
- Add pub-request guard to cron stale dataset query
- Include warnings in cron audit log results
- Add explicit dataset_collaborators delete for FK defense-in-depth
- CLI: check result.deleted, show spinner.fail on incomplete deletion
- Merge duplicate DOI check blocks, simplify S3 summary output
@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review Summary (6 agents, all parallel)

Critical Issues Fixed

  1. CLAUDE.md documented the problem, not the solution - Updated to document the new deletion system
  2. 'completed' vs 'published' status mismatch - The pub-request blocking query used 'completed' but the actual terminal status is 'published'. Fixed.
  3. DELETE endpoint always returned 200 - Now returns 207 on partial failure
  4. DELETE endpoint required JSON body - Clients sending no body would fail. Now handles no-body gracefully.

Important Issues Fixed

  1. Cron didn't exclude datasets with active pub requests - Added NOT IN subquery
  2. Cron discarded step details - Now includes warnings in audit log
  3. CLI didn't check result.deleted - Now shows spinner.fail when deletion incomplete
  4. FK cascade not guaranteed - Added explicit dataset_collaborators DELETE for defense-in-depth
  5. Duplicate DOI check in CLI - Merged into single block
  6. Dense S3 summary line - Simplified with intermediate variable

Known Gaps (deferred)

  • last_activity_at not updated in mutation endpoints - requires changes to upload/version/publish routes (separate PR)
  • hasRole/parseRole unit tests - pure functions, low risk
  • Cron handler not directly testable without D1 mock infrastructure

Not Fixed (false positives or acceptable)

- deleteRepository: reject slash, .., empty repo names (path traversal guard)
- hasRole, isDemotion, isValidRole, parseRole: full unit test coverage
@neuromechanist
neuromechanist merged commit fe1d4a9 into dev Feb 12, 2026
8 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-128-epic-deletion branch February 12, 2026 08:56

This branch was previously deployed

1 inactive deployment
npm — 1a8794ce Deployed Feb 12, 2026 by neuromechanist via publish #220
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.

1 participant