Skip to content

Add comprehensive Zenodo sandbox testing - #82

Merged
neuromechanist merged 5 commits into
devfrom
feature/issue-76-zenodo-testing
Jan 28, 2026
Merged

neuromechanist merged 5 commits into
devfrom
feature/issue-76-zenodo-testing

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Implements comprehensive Zenodo sandbox testing strategy.

Changes

Test Coverage Expansion

  • Expanded test suite from 2 to 22 tests across 7 suites
  • Added metadata updates, error handling, rate limiting tests
  • Added deposition lifecycle and file upload tests
  • Automatic cleanup of unpublished depositions
  • Production token detection and blocking

CI/CD Integration

  • Added zenodo-sandbox-test job to workflow
  • Runs on backend/test file changes
  • Uses ZENODO_SANDBOX_API_KEY secret

CLI Improvements

  • Enhanced sandbox mode warnings with visual formatting
  • Updated confirmation messages (TEST vs PERMANENT)
  • Added sandbox detection in doi info command

Documentation

  • Created comprehensive testing guide (10KB)
  • Updated README with testing section
  • Added environment variables documentation
  • Added to mkdocs navigation

Safety Measures

  • Backend blocks production DOI in dev environment
  • Test file detects production token misuse
  • Multiple safeguards against accidental production use

Test Coverage

7 test suites with 22 tests:

  1. Concept DOI Creation (3 tests)
  2. Version DOI Publishing (2 tests)
  3. Metadata Updates (3 tests)
  4. Error Handling (4 tests)
  5. Rate Limiting (2 tests)
  6. Deposition Lifecycle (4 tests)
  7. File Upload (4 tests)

Files Modified

  • test/zenodo-sandbox.test.ts (145→1131 lines)
  • .github/workflows/test.yml (+31 lines)
  • src/commands/admin.ts (+28 lines)
  • backend/src/routes/admin.ts (+15 lines)
  • docs/development/zenodo-testing.md (new, 359 lines)
  • README.md (+59 lines)
  • mkdocs.yml (+2 lines)

Verification

  • TypeScript compilation passes
  • Linting passes
  • Test syntax verified
  • Tests skip by default (opt-in only)
  • Documentation complete

Next Steps

  1. Admin configures ZENODO_SANDBOX_API_KEY GitHub secret
  2. Tests run automatically on next PR
  3. Team reviews testing guide

Closes #76

Critical fixes:
- Add DELETE /admin/zenodo/deposition/:id endpoint for test cleanup
- Fix environment detection to fail closed (no default fallback)
- Improve cleanup error handling with failure tracking
- Fix rate limit documentation inconsistency
- Fix IAM revocation security hole (partial revocation on failure)
- Fix incomplete webhook test with proper assertions
- Fix DELETE status code expectation (204 only)

Security improvements:
- IAM revocation now continues on failure (prevents security hole)
- Mark users as revoked_iam_pending when S3 cleanup fails
- Track IAM revocation failures for follow-up
- Provide actionable guidance in error responses
- Environment validation prevents production DOI in dev

Test improvements:
- Cleanup failures now tracked and reported
- Webhook test validates token rejection properly
- DELETE expects correct 204 status code

Documentation:
- Clarify rate limit math (60 req/min with 400ms safety margin)
@github-actions

github-actions Bot commented Jan 27, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR82

Version: 0.3.7-PR82.dd2c2b3
Commit: dd2c2b3


🤖 Updated on each push.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Critical Issues Fixed ✅

All blocking and critical issues from the PR review have been addressed:

1. ✅ DELETE Endpoint Added (BLOCKING)

File: backend/src/routes/admin.ts:1130-1165

  • Added DELETE /admin/zenodo/deposition/:id endpoint
  • Supports sandbox query parameter
  • Proper error handling and logging
  • Test cleanup now functional

2. ✅ Environment Detection Fixed (CRITICAL)

File: backend/src/routes/admin.ts:771-809

  • Removed unsafe default fallback to "development"
  • Fail closed: Returns 500 if ENVIRONMENT not set
  • Validates environment value against whitelist
  • Normalizes case and trims whitespace
  • Prevents production DOI creation in dev/staging

3. ✅ Cleanup Error Handling Improved (CRITICAL)

File: test/zenodo-sandbox.test.ts:53-99

  • Tracks cleanup failures in array
  • Reports failures at end with specific error messages
  • Provides manual cleanup instructions
  • Uses stderr for error output (CI capture)

4. ✅ Rate Limit Documentation Fixed (CRITICAL)

Files: test/zenodo-sandbox.test.ts:639-641, docs/development/zenodo-testing.md:220-240

  • Clarified rate limit math: 60 req/min minimum, 400ms safety margin
  • Explained why 400ms instead of 1000ms
  • Documented actual behavior vs documented limits

5. ✅ IAM Revocation Security Hole Fixed (CRITICAL)

File: backend/src/routes/admin.ts:321-507
This was the security hole you mentioned!

  • IAM revocation failures no longer block entire revocation
  • User marked as revoked_iam_pending instead of staying approved
  • API tokens revoked even if IAM fails
  • IAM failures tracked in database for follow-up
  • Response includes actionable cleanup steps
  • Returns 207 Multi-Status for partial success

6. ✅ Webhook Test Fixed (IMPORTANT)

File: test/zenodo-sandbox.test.ts:249-274

  • Added proper assertions (expects 401 + error message)
  • Verifies token validation works correctly
  • Clear test intent and logging

7. ✅ DELETE Status Code Fixed (IMPORTANT)

File: test/zenodo-sandbox.test.ts:923

  • Changed from [204, 201] to 204 only
  • 201 Created is semantically incorrect for DELETE
  • Now expects proper HTTP status

Security Impact

The IAM revocation fix is critical for security:

Before: If IAM revocation failed (network issue, AWS error), the entire revocation was blocked. User stayed "approved" with active S3 credentials.

After: If IAM revocation fails:

  1. User status → revoked_iam_pending
  2. API tokens revoked (prevents API access)
  3. IAM failure tracked in database
  4. Admin gets actionable cleanup steps
  5. Returns 207 with clear warning

This prevents the security hole where revoked users could still access S3 data.

Testing

All changes compile and lint successfully:

✅ bun run tsc --noEmit (no errors)
✅ bun run lint (14 files checked)

Next Steps

Remaining improvements (can be follow-up PR):

  • Add missing safety tests (sandbox blocking, environment checks)
  • Add rate limit retry logic
  • Enhance CLI error messages
  • Add E2E webhook test

- Use owner AWS credentials for forced IAM cleanup
- List ALL access keys (not just stored one)
- Continue on error with detailed step tracking
- Return success if ANY access key deleted
- Add comprehensive error reporting
- Track partial success/failure per step

Addresses security hole where S3 credentials remained active
when IAM user deletion failed.
- Split 'doi' into 'doi create' and 'doi info' subcommands
- Now shows --sandbox flag in admin doi create documentation
- Regenerated all command docs from CLI help (single source of truth)
- Move 'already has DOI' check before environment validation
- Only check ENVIRONMENT for production DOIs (skip for sandbox)
- Webhook returns 401 for missing secret (not 500)

Fixes:
- Test expecting 'Production DOI blocked' now gets correct error
- Sandbox DOI creation skips environment checks
- Webhook tests get 401 (unauthorized) instead of 500 (server error)
@neuromechanist
neuromechanist merged commit 730c998 into dev Jan 28, 2026
@neuromechanist
neuromechanist deleted the feature/issue-76-zenodo-testing branch February 7, 2026 18:49
neuromechanist added a commit that referenced this pull request Sep 9, 2026
The ADR is authoritative over other docs, and review found several of its
claims contradicted by the code it describes. Corrected rather than
softened, so the verdict matches what ships:

- "leaves the issue exactly as it was" was false once apply was on. The
  invariant is split: a DECIDING failure leaves the issue byte-for-byte
  unchanged, an ACTING failure cannot promise that, so the write order is
  now part of the decision.
- "a 28-issue backlog drains over two runs" was false; there was no cursor
  and no rotation. Replaced with what the code does and why there is no
  stored cursor.
- "the admin route stays callable on staging as a dry run" read as a safety
  property the route did not have. Both fences are now stated.
- "the rollup is a pressure valve, not the normal mode" could not hold
  while nothing closed a rollup: `rollupOpen` is the hysteresis, so with no
  writer the cap silently became RESUME. The sweep releasing it is now the
  stated rule, with the alternative ("leave it to a human") declined.
- The band is 6-9, not 5-10: the rule latches at CAP and releases at
  RESUME, both inclusive.
- Counts, dates and the burst size: 29 open as of 2026-09-09 stated once
  with its date rather than restated in eleven comments, and the
  2026-07-22 burst was 15 issues (#68-#82), not 14 -- #83 in that range is
  a pull request.

Adds the two refusals that were missing: an empty comparison
(`expectedCount === 0`) is not a passing one, and the cause label is
classified from the stored `last_error` rather than the incoming callback.

This branch was previously deployed

1 inactive deployment
npm — dd2c2b3d Deployed Jan 28, 2026 by neuromechanist
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