Skip to content

Add --sandbox flag to admin publish approve command - #85

Merged
neuromechanist merged 9 commits into
devfrom
feature/issue-83-publish-approve-sandbox
Jan 28, 2026
Merged

neuromechanist merged 9 commits into
devfrom
feature/issue-83-publish-approve-sandbox

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Jan 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds --sandbox flag to nemar admin publish approve command to allow testing the full publication workflow on Zenodo sandbox.

Changes

CLI (src/commands/admin.ts)

  • Added --sandbox option to publish approve command
  • Added sandbox warning banner (similar to doi create)
  • Updated confirmation message to indicate sandbox mode
  • Pass sandbox parameter to API client

API Client (src/lib/api.ts)

  • Added sandbox parameter to approvePublication() function
  • Passes sandbox in request body
  • Support TEST_API_URL environment variable for testing

Backend (backend/src/routes/admin.ts)

  • Added sandbox field to approveSchema
  • Extract sandbox from request
  • Added environment safety checks (block production DOI in non-production)
  • Added sandbox dataset protection (block publishing xx-prefix datasets)
  • Select correct Zenodo API key based on sandbox flag
  • Pass sandbox to createDeposition()

Backend (backend/src/routes/datasets.ts)

  • Fixed dataset INSERT to include visibility column (defaults to 'private')

Tests (test/zenodo-sandbox.test.ts)

  • Fixed production DOI blocking test to accept either error message
  • Fixed invalid token test to accept 401 or 403 response

Tests (test/.env.test)

  • Updated TEST_API_URL to use dev backend for testing

Testing

# View help
nemar admin publish approve --help

# Test with sandbox flag (on test dataset)
nemar admin publish approve nm099999 --sandbox

Before & After

Before:

  • DOI always created on production Zenodo
  • No way to test full workflow
  • Dataset INSERT missing visibility column
  • Tests using production API

After:

  • Can test full workflow with --sandbox flag
  • DOI created on sandbox.zenodo.org
  • Warning banner shows sandbox mode is active
  • Environment safety checks prevent accidental production DOI
  • Sandbox datasets (xx-prefix) blocked from publication
  • All tests passing with dev API

CI Results

All tests passing:

  • ✅ lint
  • ✅ api-test
  • ✅ unit-test
  • ✅ zenodo-sandbox-test
  • ✅ e2e-sandbox

Fixes #83

- Add --sandbox option to CLI command
- Update API client to pass sandbox parameter
- Update backend schema to accept sandbox
- Use sandbox parameter when selecting Zenodo API key
- Pass sandbox to createDeposition() call
- Add sandbox warning banner in CLI output

Fixes #83
- Add environment safety checks to doi_create step
- Block production DOI in non-production environments
- Block publishing sandbox datasets (xx-prefix)
- Fix error message consistency
- Add missing warning line about DOI resolution

Addresses code review findings from PR #85
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Code Review Complete ✅

Ran comprehensive code review using pr-review-toolkit:code-reviewer agent.

Issues Found & Fixed

Critical Issues (Fixed in 3ff7796)

  1. Missing Environment Safety Checks - Added the same environment validation from doi create to prevent accidental production DOI creation in non-production environments
  2. Missing Sandbox Dataset Protection - Added check to block publishing sandbox datasets (xx-prefix)

Important Issues (Fixed in 3ff7796)

  1. Error Message Consistency - Fixed error message format to match doi create pattern
  2. Incomplete Warning - Added missing "DOI will NOT resolve in production" line to sandbox warning

What Works Correctly ✅

  • Parameter threading (CLI → API → Backend → Service)
  • API key selection based on sandbox flag
  • Zenodo service receives correct parameters
  • User experience (warnings, confirmations)
  • Schema validation

Changes Made

  • backend/src/routes/admin.ts:
    • Added environment safety checks to doi_create step (lines 1998-2024)
    • Added sandbox dataset protection (lines 1793-1802)
    • Fixed error message format for consistency
  • src/commands/admin.ts:
    • Added missing warning line about DOI resolution

All TypeScript checks pass. Ready for merge.

@github-actions

github-actions Bot commented Jan 28, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR85

Version: 0.3.7-PR85.276e665
Commit: 276e665


🤖 Updated on each push.

- backend: Add visibility column to dataset INSERT (defaults to 'private')
- api: Support TEST_API_URL environment variable for testing
- api: Require visibility field in dataset validation

Fixes unit test failures where datasets were returned without visibility field.
Root cause: test/.env.test was pointing to production API which has older version.
Note: test/.env.test (gitignored) updated to use dev API for local testing.
Test was failing because nm099999 already has DOI, so backend
returns 'already has a concept DOI' instead of 'Production DOI blocked'.
Zenodo API returns 403 (Forbidden) for invalid tokens, not 401.
Bug: When creating a DOI with --sandbox flag, the dataset's is_sandbox
flag was not being updated to match. This caused inconsistent state where
database said is_sandbox=0 but DOI was actually on sandbox.zenodo.org.

Fix: Update both concept_doi UPDATE statements to also set is_sandbox
based on the sandbox parameter.

This prevents future inconsistencies between database flag and actual
Zenodo environment.
After fixing is_sandbox flag, nm099999 is correctly marked as sandbox
dataset. Backend now blocks production DOI creation with 'Cannot create
DOI for sandbox datasets' error. Test updated to accept all three valid
blocking errors.

This branch was previously deployed

1 inactive deployment
npm — 276e665c 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