From 78ef085f8006a4e5020404c32b1d6d476e0d3908 Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Thu, 29 Oct 2026 13:17:56 +0530 Subject: [PATCH 1/9] IDP-52: allow adding name to a new dandiset --- .../src/components/DataUploadDialog.tsx | 18 ++++++++++++++-- .../frontend/src/components/uploadSession.ts | 9 +++++--- .../src/core/use-cases/emberObjectStore.ts | 2 +- .../src/core/use-cases/runProtocol.ts | 4 +++- .../frontend/tests/unit/runProtocol.test.ts | 21 ++++++++++++++++++- 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx b/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx index 0593cee..1a3ffb7 100644 --- a/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx +++ b/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx @@ -10,6 +10,7 @@ import { MenuItem, Select, Stack, + TextField, Typography, } from '@mui/material' import CloudUploadOutlinedIcon from '@mui/icons-material/CloudUploadOutlined' @@ -69,7 +70,7 @@ const MIN_ATTEMPT_MS = 300 export default function DataUploadDialog({ open, initialProtocol, onClose, onAuthRequired }: DataUploadDialogProps) { const { tokenParsed } = useAppContext() const [form] = useSessionStore(session) - const { step, protocol, file, isDragging, uploadMessage, spawnedWorkspaceId, outputsDir, runSteps, dandisetId, shareWithMaabcd, doi, publishing, publishError, checkpoint } = form + const { step, protocol, file, isDragging, uploadMessage, spawnedWorkspaceId, outputsDir, runSteps, dandisetId, dandisetName, shareWithMaabcd, doi, publishing, publishError, checkpoint } = form // EMBER-DANDI: the upload goes to the researcher's own account. Choosing a protocol lists their // dandisets for it, each with the workspace it runs in, so choosing one chooses both. const usesEmber = UPLOAD_BACKEND === 'ember' @@ -218,6 +219,7 @@ export default function DataUploadDialog({ open, initialProtocol, onClose, onAut workspaceId: spawnedWorkspaceId, workspaceName: selectedProtocol.name, dandisetId: dandisetId || undefined, + dandisetName: dandisetId ? undefined : dandisetName, shareWithMaabcd, resume: checkpoint, }) @@ -465,6 +467,18 @@ export default function DataUploadDialog({ open, initialProtocol, onClose, onAut )} )} + {emberSignedIn && protocolDandisets !== null && !dandisetId && ( + setForm((prev) => ({ ...prev, dandisetName: e.target.value }))} + slotProps={{ htmlInput: { style: { fontFamily: 'Inter, sans-serif', fontSize: '14px' } } }} + sx={{ mt: 1.5 }} + /> + )} )} {usesEmber && selectedProtocol?.maabcdAggregateDandisetId && ( @@ -511,7 +525,7 @@ export default function DataUploadDialog({ open, initialProtocol, onClose, onAut )} {usesEmber && ( - {dandisetId ? `Uploading into your dandiset ${dandisetId}` : 'Uploading into a new dandiset in your EMBER-DANDI account'} + {dandisetId ? `Uploading into your dandiset ${dandisetId}` : `Uploading into a new dandiset${dandisetName.trim() ? ` "${dandisetName.trim()}"` : ''} in your EMBER-DANDI account`} {spawnedWorkspaceId !== undefined ? `, analyzed in workspace ${spawnedWorkspaceId}.` : ', analyzed in a new workspace.'} )} diff --git a/applications/idp-arc/frontend/src/components/uploadSession.ts b/applications/idp-arc/frontend/src/components/uploadSession.ts index 271b68a..f1f766b 100644 --- a/applications/idp-arc/frontend/src/components/uploadSession.ts +++ b/applications/idp-arc/frontend/src/components/uploadSession.ts @@ -30,6 +30,8 @@ export interface FormState { runSteps: RunStep[] /** EMBER-DANDI only: the researcher's dandiset to upload into; empty creates a new one. */ dandisetId: string + /** The name of the new dandiset, when none is chosen; empty uses the protocol's name. */ + dandisetName: string /** Also upload into the protocol's MAABCD dandiset; on by default. */ shareWithMaabcd: boolean /** What the last attempt got done: a retry carries on from there (the run checks it still applies). */ @@ -50,13 +52,14 @@ export const INITIAL_FORM: FormState = { outputsDir: '', runSteps: [], dandisetId: '', + dandisetName: '', shareWithMaabcd: true, } export const session = createSessionStore(INITIAL_FORM) /** What is saved across a reload: the run, not the form around it. */ -type SavedRun = Pick const RUN_INTERRUPTED = 'The run stopped unexpectedly. Retry to carry on from where it stopped.' @@ -73,9 +76,9 @@ if (typeof window !== 'undefined') { session.subscribe(() => { if (!savingFor || leaving) return - const { step, protocol, dandisetId, spawnedWorkspaceId, shareWithMaabcd, checkpoint, runSteps, outputsDir, uploadMessage, resultSeen } = session.get() + const { step, protocol, dandisetId, dandisetName, spawnedWorkspaceId, shareWithMaabcd, checkpoint, runSteps, outputsDir, uploadMessage, resultSeen } = session.get() if (!checkpoint || resultSeen) return clearRun(savingFor) - const run: SavedRun = { step, protocol, dandisetId, spawnedWorkspaceId, shareWithMaabcd, checkpoint, runSteps, outputsDir, uploadMessage } + const run: SavedRun = { step, protocol, dandisetId, dandisetName, spawnedWorkspaceId, shareWithMaabcd, checkpoint, runSteps, outputsDir, uploadMessage } saveRun(savingFor, run) }) diff --git a/applications/idp-arc/frontend/src/core/use-cases/emberObjectStore.ts b/applications/idp-arc/frontend/src/core/use-cases/emberObjectStore.ts index 03bfef9..c96ec1d 100644 --- a/applications/idp-arc/frontend/src/core/use-cases/emberObjectStore.ts +++ b/applications/idp-arc/frontend/src/core/use-cases/emberObjectStore.ts @@ -60,7 +60,7 @@ export function createEmberObjectStore( // The researcher's own copy. const protocol = input.dandisets?.protocol ?? { id: input.protocolId, name: input.protocolId } const userDandisetId = saved.userDandisetId || input.dandisets?.user - || await dandisets.createForProtocol(input.dandisets?.newName || `IDP upload: ${protocol.name}`, protocol) + || await dandisets.createForProtocol(input.dandisets?.newName || protocol.name, protocol) if (saved.userDandisetId !== userDandisetId) save({ userDandisetId }) let asset = saved.own if (!asset) { diff --git a/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts b/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts index 55eec41..fc4f988 100644 --- a/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts +++ b/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts @@ -45,6 +45,8 @@ export interface RunProtocolInput { /** The researcher's EMBER-DANDI dandiset to upload into; undefined creates one. The bucket * ignores it. */ dandisetId?: string + /** Name for the dandiset created when `dandisetId` is undefined; the protocol's name when empty. */ + dandisetName?: string /** Also upload into the protocol's MAABCD dandiset, when it has one (the default). */ shareWithMaabcd?: boolean /** From an earlier attempt that stopped: the run carries on from there when canResume allows. */ @@ -286,7 +288,7 @@ export function createRunProtocolUseCase( onCheckpoint: (upload) => save({ upload }), dandisets: { user: input.dandisetId, - newName: `${protocol.name} (IDP)`, + newName: input.dandisetName?.trim() || protocol.name, protocol: protocolRef(), maabcd: input.shareWithMaabcd === false ? undefined : protocol.maabcdAggregateDandisetId, }, diff --git a/applications/idp-arc/frontend/tests/unit/runProtocol.test.ts b/applications/idp-arc/frontend/tests/unit/runProtocol.test.ts index 2402017..4f57e3c 100644 --- a/applications/idp-arc/frontend/tests/unit/runProtocol.test.ts +++ b/applications/idp-arc/frontend/tests/unit/runProtocol.test.ts @@ -334,11 +334,30 @@ test('an EMBER-DANDI upload gets the run\'s workspace recorded in its dandiset, const create = f.calls.findIndex((c) => c.startsWith('create:')) assert.equal(f.calls[create + 1], 'record:42') assert.deepEqual(seen.dandisets, { - user: '000123', newName: 'Four-choice reversal digging task (IDP)', maabcd: '000533', + user: '000123', newName: 'Four-choice reversal digging task', maabcd: '000533', protocol: { id: 'four-choice-reversal', name: 'Four-choice reversal digging task', url: 'https://github.com/maracbaylis/four-choice-example' }, }) }) +for (const [typed, expected] of [ + [' Cohort A, week 3 ', 'Cohort A, week 3'], + [' ', 'Four-choice reversal digging task'], + [undefined, 'Four-choice reversal digging task'], +] as const) { + test(`a new dandiset is named ${JSON.stringify(typed)} -> "${expected}"`, async () => { + const seen: { dandisets?: { newName?: string } } = {} + const store: IObjectStore = { + async put(input) { + seen.dandisets = input.dandisets + return { url: 'https://api-dandi.example.org/api/assets/a/download/', key: 'k', name: 'animal_01.xlsx', dandisetId: '000777' } + }, + } + await createRunProtocolUseCase(auth, fakes().api, store)( + { protocol: FOUR_CHOICE, file: file(), workspaceName: 'Four-choice', dandisetName: typed }, () => {}) + assert.equal(seen.dandisets?.newName, expected) + }) +} + test('with "Share with MAABCD" unticked, nothing goes to the protocol\'s MAABCD dandiset', async () => { const f = fakes() const seen: { dandisets?: { maabcd?: string } } = {} From ee027b32bf23c5af25ea2665466747daaf2c4d8b Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Mon, 2 Nov 2026 13:20:26 +0530 Subject: [PATCH 2/9] IDP-52: choose the DANDI instance with one setting --- README.md | 17 +++++++ applications/idp-arc/Dockerfile | 7 +++ .../idp-arc/deploy/resources/default.conf | 24 +++++++--- .../idp-arc/frontend/src/app/container.ts | 10 ++-- .../src/components/DataUploadDialog.tsx | 15 ++++-- .../frontend/src/core/dandiInstances.ts | 38 +++++++++++++++ .../frontend/src/core/ports/IObjectStore.ts | 2 +- .../src/core/use-cases/runProtocol.ts | 5 +- .../idp-arc/frontend/src/data/README.md | 4 +- .../idp-arc/frontend/src/data/protocols.json | 5 +- .../idp-arc/frontend/src/infra/emberUrls.ts | 3 -- .../tests/unit/dandiInstances.test.ts | 48 +++++++++++++++++++ applications/idp-arc/frontend/vite.config.ts | 6 ++- 13 files changed, 161 insertions(+), 23 deletions(-) create mode 100644 applications/idp-arc/frontend/src/core/dandiInstances.ts delete mode 100644 applications/idp-arc/frontend/src/infra/emberUrls.ts create mode 100644 applications/idp-arc/frontend/tests/unit/dandiInstances.test.ts diff --git a/README.md b/README.md index c780488..d5d450b 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,23 @@ researcher's workspace from there. - **`bucket`**: a public bucket open for anonymous writes, named by `VITE_UPLOAD_BUCKET_URL`. Its CORS must allow PUT from this app's origin. Needs only the OSB login. +### Choosing the DANDI instance + +EMBER-DANDI is the default. To use another instance, such as DANDI's sandbox for testing, name it in +`applications/idp-arc/frontend/.env.local`: + +```bash +# dandi, dandi-sandbox, ember-dandi (default) or ember-dandi-sandbox +VITE_DANDI_INSTANCE=dandi-sandbox +``` + +That one name sets the API and web origins (`src/core/dandiInstances.ts`), the instance OSB copies +into for MAABCD, and which dandiset of a protocol's `maabcdAggregateDandisets` in +`src/data/protocols.json` the copy goes to (none for that instance: nothing is shared). Any other +name stops the dev server and the build. In deployment, pass it as the `VITE_DANDI_INSTANCE` build +argument (the image's nginx proxy follows it; the container's `DANDI_INSTANCE` overrides the proxy). +The OSB user's `DANDI_API_KEY` must be a key for that instance. + --- ## Docker (Local Build + Run) diff --git a/applications/idp-arc/Dockerfile b/applications/idp-arc/Dockerfile index 09bde31..7eb8193 100644 --- a/applications/idp-arc/Dockerfile +++ b/applications/idp-arc/Dockerfile @@ -15,6 +15,9 @@ ENV VITE_UPLOAD_BUCKET_URL=${VITE_UPLOAD_BUCKET_URL} # EMBER-DANDI OAuth application (public client, PKCE) registered for this IDP origin. ARG VITE_EMBER_CLIENT_ID ENV VITE_EMBER_CLIENT_ID=${VITE_EMBER_CLIENT_ID} +# The DANDI instance: dandi, dandi-sandbox, ember-dandi (the default) or ember-dandi-sandbox. +ARG VITE_DANDI_INSTANCE +ENV VITE_DANDI_INSTANCE=${VITE_DANDI_INSTANCE} RUN yarn build FROM nginxinc/nginx-unprivileged:stable-alpine @@ -26,6 +29,10 @@ COPY --from=build --chown=101:101 /app/dist/ /usr/share/nginx/html/ # template the pod's DNS servers so the EMBER proxy can resolve at request time (see default.conf). COPY --chown=101:101 deploy/resources/default.conf /etc/nginx/templates/default.conf.template ENV NGINX_ENTRYPOINT_LOCAL_RESOLVERS=1 +# The DANDI instance the /ember-proxy forwards to: the one the bundle was built for, EMBER-DANDI +# when unset; the container's DANDI_INSTANCE overrides it at start. +ARG VITE_DANDI_INSTANCE +ENV DANDI_INSTANCE=${VITE_DANDI_INSTANCE:-ember-dandi} USER 101 EXPOSE 8080 \ No newline at end of file diff --git a/applications/idp-arc/deploy/resources/default.conf b/applications/idp-arc/deploy/resources/default.conf index 504613f..43c0d36 100644 --- a/applications/idp-arc/deploy/resources/default.conf +++ b/applications/idp-arc/deploy/resources/default.conf @@ -1,5 +1,16 @@ # Installed as an envsubst template (Dockerfile): ${NGINX_LOCAL_RESOLVERS} becomes the pod's -# nameservers from /etc/resolv.conf at container start. Other $names are nginx variables. +# nameservers from /etc/resolv.conf at container start, and ${DANDI_INSTANCE} the DANDI instance +# in use, from the container's environment. Other $names are nginx variables. + +# The instance's API (src/core/dandiInstances.ts; a test checks they agree). +map "${DANDI_INSTANCE}" $dandi_api_origin { + default ""; + "dandi" https://api.dandiarchive.org; + "dandi-sandbox" https://api.sandbox.dandiarchive.org; + "ember-dandi" https://api-dandi.emberarchive.org; + "ember-dandi-sandbox" https://api-dandi.sandbox.emberarchive.org; +} + server { listen 8080; @@ -18,19 +29,20 @@ server { # can change under us. A variable proxy_pass doesn't strip the location prefix, hence the rewrite. resolver ${NGINX_LOCAL_RESOLVERS} ipv6=off; resolver_timeout 5s; - set $ember https://api-dandi.emberarchive.org; + # proxy_pass sends the instance's host as Host. An unknown DANDI_INSTANCE leaves it empty: refused. + set $dandi_api $dandi_api_origin; location /ember-proxy/oauth/token/ { + if ($dandi_api = "") { return 500 "DANDI_INSTANCE is not a known DANDI instance"; } rewrite ^/ember-proxy(/.*)$ $1 break; - proxy_pass $ember; + proxy_pass $dandi_api; proxy_ssl_server_name on; - proxy_set_header Host api-dandi.emberarchive.org; } location /ember-proxy/api/ { + if ($dandi_api = "") { return 500 "DANDI_INSTANCE is not a known DANDI instance"; } rewrite ^/ember-proxy(/.*)$ $1 break; - proxy_pass $ember; + proxy_pass $dandi_api; proxy_ssl_server_name on; - proxy_set_header Host api-dandi.emberarchive.org; } location /ember-proxy/ { return 404; diff --git a/applications/idp-arc/frontend/src/app/container.ts b/applications/idp-arc/frontend/src/app/container.ts index f7edb18..16b09b4 100644 --- a/applications/idp-arc/frontend/src/app/container.ts +++ b/applications/idp-arc/frontend/src/app/container.ts @@ -22,7 +22,7 @@ import { PublicBucketObjectStore } from '../infra/publicBucketObjectStore' import { EmberOAuthClient, EMBER_CALLBACK_PATH } from '../infra/emberOAuthClient' import { EmberDandiDirectClient } from '../infra/emberDandiDirectClient' import { EmberUploadApiClient } from '../infra/emberUploadApiClient' -import { EMBER_API_ORIGIN, EMBER_WEB_ORIGIN } from '../infra/emberUrls' +import { dandiInstance } from '../core/dandiInstances' import type { IObjectStore } from '../core/ports/IObjectStore' import { createEmberObjectStore } from '../core/use-cases/emberObjectStore' import { createProtocolDandisetsUseCases, type ProtocolDandiset } from '../core/use-cases/protocolDandisets' @@ -45,10 +45,14 @@ const OSB_WEB_ORIGIN = `${OSB_SCHEME}://www.${OSB_DOMAIN}` export type UploadBackend = 'ember' | 'bucket' /** VITE_UPLOAD_BACKEND: `bucket`, or EMBER-DANDI for anything else, unset included. */ export const UPLOAD_BACKEND: UploadBackend = import.meta.env.VITE_UPLOAD_BACKEND === 'bucket' ? 'bucket' : 'ember' +/** The DANDI instance in use, from VITE_DANDI_INSTANCE (EMBER-DANDI when unset): where the + * researcher's uploads go, and which of a protocol's MAABCD dandisets the copy goes to. */ +export const DANDI_INSTANCE = dandiInstance(import.meta.env.VITE_DANDI_INSTANCE) +const { api: EMBER_API_ORIGIN, web: EMBER_WEB_ORIGIN } = DANDI_INSTANCE /** The OSB (Keycloak) user whose key (user attribute `DANDI_API_KEY`) signs the copy into the - * protocol's MAABCD dandiset, and the DANDI deployment it goes to (dandi-cli's name). */ + * protocol's MAABCD dandiset, on the same instance (dandi-cli's name for it). */ const MAABCD_EMBER_USERNAME = 'maabcd-consortium' -const MAABCD_DANDI_INSTANCE = 'ember-dandi' +const MAABCD_DANDI_INSTANCE = DANDI_INSTANCE.name /** Same-origin path for the browser's own EMBER calls (Vite proxy in dev, nginx deployed): EMBER's * token response carries no CORS headers. */ const EMBER_FETCH_BASE = '/ember-proxy' diff --git a/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx b/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx index 1a3ffb7..d80d33e 100644 --- a/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx +++ b/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx @@ -22,7 +22,8 @@ import OpenInNewIcon from '@mui/icons-material/OpenInNewOutlined' import ErrorOutlineIcon from '@mui/icons-material/ErrorOutlineOutlined' import HourglassEmptyIcon from '@mui/icons-material/HourglassEmpty' -import { emberAuth, getWorkspaceUrl, listProtocolDandisets, publishDandiset, recordedWorkspace, runProtocol, UPLOAD_BACKEND, type ProtocolDandiset } from '../app/container' +import { DANDI_INSTANCE, emberAuth, getWorkspaceUrl, listProtocolDandisets, publishDandiset, recordedWorkspace, runProtocol, UPLOAD_BACKEND, type ProtocolDandiset } from '../app/container' +import { maabcdDandisetFor } from '../core/dandiInstances' import { EMBER_SIGN_IN, UserFacingError, userMessage } from '../core/userMessages' import { withRunLock } from './runStorage' import { INITIAL_FORM, restoreSession, session } from './uploadSession' @@ -38,8 +39,11 @@ import { templatesZipFileName, templatesZipHref } from '../core/protocolTemplate import { SIGN_IN_AGAIN } from '../core/userMessages' import protocols from '../data/protocols.json' -/** Only protocols with an analysis repository can be run, so only those are offered. */ -const runnableProtocols = protocols.filter((p) => 'repoZipUrl' in p && p.repoZipUrl) +/** Only protocols with an analysis repository can be run, so only those are offered. Each carries + * its MAABCD dandiset on the DANDI instance in use (none: nothing is shared). */ +const runnableProtocols = protocols + .filter((p) => 'repoZipUrl' in p && p.repoZipUrl) + .map((p) => ({ ...p, maabcdAggregateDandisetId: maabcdDandisetFor(p, DANDI_INSTANCE.name) })) type RunnableProtocol = (typeof runnableProtocols)[number] export interface DataUploadDialogProps { @@ -481,6 +485,11 @@ export default function DataUploadDialog({ open, initialProtocol, onClose, onAut )} )} + {usesEmber && selectedProtocol && 'maabcdAggregateDandisets' in selectedProtocol && !selectedProtocol.maabcdAggregateDandisetId && ( + + No MAABCD dandiset on {DANDI_INSTANCE.name} for this protocol, so nothing is shared with the consortium. + + )} {usesEmber && selectedProtocol?.maabcdAggregateDandisetId && ( Object.hasOwn(DANDI_INSTANCES, name) + +/** The instance VITE_DANDI_INSTANCE names; EMBER-DANDI when it is empty. Throws for any other name. */ +export function dandiInstance(configured?: string): DandiInstance { + const name = (configured ?? '').trim() || DEFAULT_DANDI_INSTANCE + if (!isDandiInstanceName(name)) { + throw new Error(`VITE_DANDI_INSTANCE "${name}" is not a DANDI instance; use one of: ${Object.keys(DANDI_INSTANCES).join(', ')}.`) + } + return { name, ...DANDI_INSTANCES[name] } +} + +/** The protocol's MAABCD dandiset on `instance` (protocols.json `maabcdAggregateDandisets`); + * undefined when it has none there. */ +export function maabcdDandisetFor( + protocol: { maabcdAggregateDandisets?: Readonly> }, + instance: DandiInstanceName, +): string | undefined { + return protocol.maabcdAggregateDandisets?.[instance] || undefined +} diff --git a/applications/idp-arc/frontend/src/core/ports/IObjectStore.ts b/applications/idp-arc/frontend/src/core/ports/IObjectStore.ts index 0f9a119..00ee9aa 100644 --- a/applications/idp-arc/frontend/src/core/ports/IObjectStore.ts +++ b/applications/idp-arc/frontend/src/core/ports/IObjectStore.ts @@ -20,7 +20,7 @@ export interface ObjectUploadInput { newName?: string /** Recorded in the dandiset's metadata, with the workspace the run uses. */ protocol?: { id: string; name: string; url?: string } - /** The protocol's MAABCD dandiset (protocols.json `maabcdAggregateDandisetId`), uploaded to through OSB. */ + /** The protocol's MAABCD dandiset (protocols.json `maabcdAggregateDandisets`, for the instance in use), uploaded to through OSB. */ maabcd?: string } /** From an earlier, interrupted put of the same file: what it already did is not done again. */ diff --git a/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts b/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts index fc4f988..bc759fd 100644 --- a/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts +++ b/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts @@ -29,8 +29,9 @@ export interface RunProtocolDefinition { /** The image the notebooks run in (their environment): an OSB application's name (e.g. `netpyne`) * or an image reference from a registry OSB allows. Without it, OSB's default (JupyterLab). */ image?: string - /** The protocol's MAABCD dandiset on EMBER-DANDI, which each upload is also copied into - * (through OSB). Empty or absent: no MAABCD copy. */ + /** The protocol's MAABCD dandiset on the DANDI instance in use (protocols.json + * `maabcdAggregateDandisets`), which each upload is also copied into (through OSB). Empty or + * absent: no MAABCD copy. */ maabcdAggregateDandisetId?: string } diff --git a/applications/idp-arc/frontend/src/data/README.md b/applications/idp-arc/frontend/src/data/README.md index d62a129..1e6957f 100644 --- a/applications/idp-arc/frontend/src/data/README.md +++ b/applications/idp-arc/frontend/src/data/README.md @@ -13,7 +13,7 @@ Field names follow the MAABCD–OSB Integration design (`id`, `repoZipUrl`, `not | `description`, `imageUrl`, `videoUrl` | Protocols page | Text and media shown for the protocol. | | `repoZipUrl` | run | GitHub archive of the analysis repository, `https://codeload.github.com///zip/refs/heads/` (or `refs/tags/`, or `/zip/`). A **branch** follows the latest fixes; a **commit** freezes the code. An empty `repoZipUrl` = no analysis yet: the upload dialog doesn't offer the protocol. | | `notebooksDir` | run | Repository-relative folder of the notebooks (`notebooks`). | -| `maabcdAggregateDandisetId` | upload | The protocol's MAABCD consortium dandiset on EMBER-DANDI (`000607`): six digits, owned by the consortium account. When the researcher shares their upload, a copy goes there through OSB's `/dandi` endpoints, signed with that account's key. Leave it out and uploads for the protocol aren't shared. | +| `maabcdAggregateDandisets` | upload | The protocol's MAABCD consortium dandiset on each DANDI instance, by instance name (`{ "ember-dandi": "000607", "dandi-sandbox": "219158" }`; names in `src/core/dandiInstances.ts`, six digits each, owned by the consortium account there). The one for the instance in use (`VITE_DANDI_INSTANCE`) is where a shared copy goes, through OSB's `/dandi` endpoints, signed with that account's key. No entry for the instance, or no field: uploads for the protocol aren't shared there. | | `requirements`, `pythonPath`, `install` | run | Override the repository setup below (defaults in `REPOSITORY_SETUP`, runProtocol.ts: `requirements.txt`; `["scripts"]`; `["scripts/install.py", "scripts/setup.py", "scripts/pyproject.toml"]`). OSB applies only the ones the repository has. Leave them out for a repository that follows the contract. | | `templatesZipUrl` | Protocols page, dialog | Archive of the protocol's templates (data sheets, instructions), downloaded by the **Download** buttons on the Protocols page and in the dialog's upload step. A path relative to `public/` (`protocols_archives/4c.zip`) or an absolute URL. Missing or empty = both buttons disabled. | | `inputFormats` | dialog, run | Extensions the analysis code can actually read. The dialog refuses other files before anything starts. **Without it, any file is accepted** (except an empty one, always refused). | @@ -24,7 +24,7 @@ Each upload goes to EMBER-DANDI, in up to two copies: | | Researcher's dandiset | MAABCD aggregate dandiset | |---|---|---| -| Dandiset | picked in the dialog, or a new one | `maabcdAggregateDandisetId`, if the researcher shares | +| Dandiset | picked in the dialog, or a new one | `maabcdAggregateDandisets` (the instance's), if the researcher shares | | Path | `//` | `//` | | Built and signed by | IDP, with the researcher's EMBER login | OSB, with the consortium's `DANDI_API_KEY` | diff --git a/applications/idp-arc/frontend/src/data/protocols.json b/applications/idp-arc/frontend/src/data/protocols.json index 5f3d3f3..5947b7b 100644 --- a/applications/idp-arc/frontend/src/data/protocols.json +++ b/applications/idp-arc/frontend/src/data/protocols.json @@ -4,7 +4,10 @@ "name": "Four-choice reversal digging task", "repoZipUrl": "https://codeload.github.com/maracbaylis/four-choice-example/zip/refs/heads/main", "notebooksDir": "notebooks", - "maabcdAggregateDandisetId": "000607", + "maabcdAggregateDandisets": { + "ember-dandi": "000607", + "dandi-sandbox": "219158" + }, "inputFormats": [".xlsx", ".zip"], "templatesZipUrl": "protocols_archives/4c.zip", "description": "In the four choice reversal digging task mice must identify the single rewarded option and update their choice when a previously unrewarded option becomes rewarded. The reversal phase in this task is sensitive to orbitofrontal and dorsomedial prefrontal cortex function and the 2-day version used here provides a metric of recall on the 2nd day of testing before reversal.", diff --git a/applications/idp-arc/frontend/src/infra/emberUrls.ts b/applications/idp-arc/frontend/src/infra/emberUrls.ts deleted file mode 100644 index a5ce025..0000000 --- a/applications/idp-arc/frontend/src/infra/emberUrls.ts +++ /dev/null @@ -1,3 +0,0 @@ -/** EMBER-DANDI's API and web UI. Production only: the proxies and OSB's MAABCD copy use it too. */ -export const EMBER_API_ORIGIN = 'https://api-dandi.emberarchive.org' -export const EMBER_WEB_ORIGIN = 'https://dandi.emberarchive.org' diff --git a/applications/idp-arc/frontend/tests/unit/dandiInstances.test.ts b/applications/idp-arc/frontend/tests/unit/dandiInstances.test.ts new file mode 100644 index 0000000..6593918 --- /dev/null +++ b/applications/idp-arc/frontend/tests/unit/dandiInstances.test.ts @@ -0,0 +1,48 @@ +// The DANDI instance in use (core/dandiInstances.ts). Run: yarn test:unit +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import { DANDI_INSTANCES, dandiInstance, isDandiInstanceName, maabcdDandisetFor } from '../../src/core/dandiInstances' + +test('EMBER-DANDI when no instance is configured', () => { + for (const unset of [undefined, '', ' ']) { + assert.deepEqual(dandiInstance(unset), { name: 'ember-dandi', api: 'https://api-dandi.emberarchive.org', web: 'https://dandi.emberarchive.org' }) + } +}) + +test('each of the four instances gives its own API and web origins', () => { + assert.deepEqual(dandiInstance('dandi-sandbox'), { name: 'dandi-sandbox', api: 'https://api.sandbox.dandiarchive.org', web: 'https://sandbox.dandiarchive.org' }) + assert.equal(dandiInstance(' ember-dandi-sandbox ').web, 'https://dandi.sandbox.emberarchive.org') + assert.equal(dandiInstance('dandi').api, 'https://api.dandiarchive.org') + assert.equal(Object.keys(DANDI_INSTANCES).length, 4) +}) + +test('an unknown instance name throws, naming the ones there are', () => { + assert.throws(() => dandiInstance('dandi-sandbx'), /"dandi-sandbx".*dandi, dandi-sandbox, ember-dandi, ember-dandi-sandbox/) + assert.throws(() => dandiInstance('toString'), /not a DANDI instance/) +}) + +test('a protocol\'s MAABCD dandiset is the one for the instance in use, or none', () => { + const protocol = { maabcdAggregateDandisets: { 'ember-dandi': '000607', 'dandi-sandbox': '219158' } } + assert.equal(maabcdDandisetFor(protocol, 'ember-dandi'), '000607') + assert.equal(maabcdDandisetFor(protocol, 'dandi-sandbox'), '219158') + assert.equal(maabcdDandisetFor(protocol, 'dandi'), undefined) + assert.equal(maabcdDandisetFor({}, 'ember-dandi'), undefined) +}) + +test('every maabcdAggregateDandisets key in protocols.json is an instance, and its value six digits', () => { + const protocols = JSON.parse(readFileSync(new URL('../../src/data/protocols.json', import.meta.url), 'utf8')) + for (const p of protocols) { + assert.equal('maabcdAggregateDandisetId' in p, false, `${p.id}: the field is now maabcdAggregateDandisets, by instance`) + for (const [instance, id] of Object.entries(p.maabcdAggregateDandisets ?? {})) { + assert.ok(isDandiInstanceName(instance), `${p.id}: "${instance}" is not a DANDI instance`) + assert.match(id as string, /^\d{6}$/, `${p.id}: ${instance}`) + } + } +}) + +test('nginx proxies to the same API origin for each instance as the app uses', () => { + const conf = readFileSync(new URL('../../../deploy/resources/default.conf', import.meta.url), 'utf8') + const mapped = Object.fromEntries([...conf.matchAll(/^\s*"([a-z-]+)"\s+(https:\/\/\S+);/gm)].map((m) => [m[1], m[2]])) + assert.deepEqual(mapped, Object.fromEntries(Object.entries(DANDI_INSTANCES).map(([name, { api }]) => [name, api]))) +}) diff --git a/applications/idp-arc/frontend/vite.config.ts b/applications/idp-arc/frontend/vite.config.ts index 29c3518..ab5b696 100644 --- a/applications/idp-arc/frontend/vite.config.ts +++ b/applications/idp-arc/frontend/vite.config.ts @@ -4,7 +4,7 @@ import path from 'path' import fs from 'node:fs' import http from 'node:http' import https from 'node:https' -import { EMBER_API_ORIGIN } from './src/infra/emberUrls' +import { dandiInstance } from './src/core/dandiInstances' // Must use loadEnv(), not process.env — Vite doesn't load .env into process.env for this // file, so process.env here silently falls back to the production domain. @@ -13,6 +13,8 @@ const OSB_DOMAIN = env.VITE_OSB_BASE_DOMAIN || 'v2dev.opensourcebrain.org' const OSB_SCHEME = env.VITE_OSB_PROTOCOL || 'https' const OSB_WEB_ORIGIN = `${OSB_SCHEME}://www.${OSB_DOMAIN}` +// Throws at start for a VITE_DANDI_INSTANCE that isn't one of the four. +const DANDI_API_ORIGIN = dandiInstance(env.VITE_DANDI_INSTANCE).api /** * Optional HTTPS for the dev server: EMBER-DANDI's OAuth application only accepts https:// * redirect URIs, so its sign-in needs https://localhost:5173 (registered as @@ -65,7 +67,7 @@ export default defineConfig({ }, // EMBER's token reply has no CORS headers. Only what the app calls, as nginx (default.conf). '^/ember-proxy/(oauth/token/|api/)': { - target: EMBER_API_ORIGIN, + target: DANDI_API_ORIGIN, changeOrigin: true, rewrite: (path) => path.replace(/^\/ember-proxy/, ''), }, From 0f3e2900d0e09920026ae3abeb7883769a2ad94f Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Thu, 5 Nov 2026 18:28:06 +0530 Subject: [PATCH 3/9] IDP-52: sign in to DANDI's sandbox with an API key, locally --- README.md | 9 +++ .../idp-arc/frontend/src/app/container.ts | 17 ++++-- .../idp-arc/frontend/src/globals.d.ts | 2 + .../src/infra/sandboxApiKeyEmberAuth.ts | 55 +++++++++++++++++++ applications/idp-arc/frontend/vite.config.ts | 19 +++++-- 5 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 applications/idp-arc/frontend/src/globals.d.ts create mode 100644 applications/idp-arc/frontend/src/infra/sandboxApiKeyEmberAuth.ts diff --git a/README.md b/README.md index d5d450b..76dbf74 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,15 @@ name stops the dev server and the build. In deployment, pass it as the `VITE_DAN argument (the image's nginx proxy follows it; the container's `DANDI_INSTANCE` overrides the proxy). The OSB user's `DANDI_API_KEY` must be a key for that instance. +### Signing in to DANDI's sandbox with an API key (local only) + +The sandbox has no OAuth app for us, so also add your sandbox API key to `.env.local`. The dev server +signs DANDI calls with it, so it never reaches the browser, and `yarn build` ignores it: + +```bash +DANDI_SANDBOX_API_KEY= +``` + --- ## Docker (Local Build + Run) diff --git a/applications/idp-arc/frontend/src/app/container.ts b/applications/idp-arc/frontend/src/app/container.ts index 16b09b4..7ab08b3 100644 --- a/applications/idp-arc/frontend/src/app/container.ts +++ b/applications/idp-arc/frontend/src/app/container.ts @@ -23,6 +23,8 @@ import { EmberOAuthClient, EMBER_CALLBACK_PATH } from '../infra/emberOAuthClient import { EmberDandiDirectClient } from '../infra/emberDandiDirectClient' import { EmberUploadApiClient } from '../infra/emberUploadApiClient' import { dandiInstance } from '../core/dandiInstances' +import { SandboxApiKeyEmberAuth } from '../infra/sandboxApiKeyEmberAuth' +import type { IEmberAuth } from '../core/ports/IEmberAuth' import type { IObjectStore } from '../core/ports/IObjectStore' import { createEmberObjectStore } from '../core/use-cases/emberObjectStore' import { createProtocolDandisetsUseCases, type ProtocolDandiset } from '../core/use-cases/protocolDandisets' @@ -71,12 +73,15 @@ const workspaceApi = new WorkspaceApiClient(WORKSPACES_API, WORKSPACES_LIST_URL) /** Signs the researcher in to EMBER-DANDI (OAuth in a popup, a full-page redirect if it is blocked); * their token stays in the browser. */ -export const emberAuth = new EmberOAuthClient({ - authOrigin: EMBER_API_ORIGIN, - apiBase: EMBER_FETCH_BASE, - clientId: import.meta.env.VITE_EMBER_CLIENT_ID ?? '', - redirectUri: `${window.location.origin}${EMBER_CALLBACK_PATH}`, -}) +export const emberAuth: IEmberAuth = __DANDI_SANDBOX_API_KEY__ + // Dev server only: the proxy signs every call with its DANDI_SANDBOX_API_KEY (vite.config.ts). + ? new SandboxApiKeyEmberAuth(EMBER_FETCH_BASE) + : new EmberOAuthClient({ + authOrigin: EMBER_API_ORIGIN, + apiBase: EMBER_FETCH_BASE, + clientId: import.meta.env.VITE_EMBER_CLIENT_ID ?? '', + redirectUri: `${window.location.origin}${EMBER_CALLBACK_PATH}`, + }) export { EMBER_CALLBACK_PATH } export { EmberPopupBlocked, EmberSignInCancelled } from '../infra/emberOAuthClient' const emberDirect = new EmberDandiDirectClient(EMBER_FETCH_BASE) diff --git a/applications/idp-arc/frontend/src/globals.d.ts b/applications/idp-arc/frontend/src/globals.d.ts new file mode 100644 index 0000000..3f1d6cc --- /dev/null +++ b/applications/idp-arc/frontend/src/globals.d.ts @@ -0,0 +1,2 @@ +/** True only in the Vite dev server on DANDI's sandbox with DANDI_SANDBOX_API_KEY set (vite.config.ts `define`). */ +declare const __DANDI_SANDBOX_API_KEY__: boolean diff --git a/applications/idp-arc/frontend/src/infra/sandboxApiKeyEmberAuth.ts b/applications/idp-arc/frontend/src/infra/sandboxApiKeyEmberAuth.ts new file mode 100644 index 0000000..6582db7 --- /dev/null +++ b/applications/idp-arc/frontend/src/infra/sandboxApiKeyEmberAuth.ts @@ -0,0 +1,55 @@ +import type { IEmberAuth } from '../core/ports/IEmberAuth' + +/** Sent instead of a token; the dev proxy replaces it with the DANDI_SANDBOX_API_KEY it holds. */ +const PLACEHOLDER_TOKEN = 'sandbox-proxy-api-key' + +/** + * Local development only: always "signed in", as the owner of DANDI_SANDBOX_API_KEY. The key stays in + * the Vite dev server, which sets `Authorization: token ` on every proxied DANDI call + * (vite.config.ts); the browser never sees it. For DANDI's sandbox, which has no OAuth app for us. + */ +export class SandboxApiKeyEmberAuth implements IEmberAuth { + readonly expiresAt = Number.MAX_SAFE_INTEGER + private readonly apiBase: string + + constructor(apiBase: string) { + this.apiBase = apiBase + } + + isConnected(): boolean { + return true + } + + getToken(): string { + return PLACEHOLDER_TOKEN + } + + async getAccount(): Promise<{ username: string; name: string | null }> { + const res = await fetch(`${this.apiBase}/api/users/me/`, { headers: { Authorization: `Bearer ${PLACEHOLDER_TOKEN}` } }) + if (!res.ok) throw new Error(`Could not read the DANDI account of DANDI_SANDBOX_API_KEY (HTTP ${res.status}).`) + const body = await res.json() + return { username: body.username, name: body.name ?? null } + } + + connect(): Promise { + return Promise.reject(new Error('Signed in through DANDI_SANDBOX_API_KEY; there is no sign-in flow.')) + } + + connectInPopup(): { done: Promise; cancel: () => void } { + return { done: Promise.resolve(), cancel: () => {} } + } + + relayPopupCallback(): boolean { + return false + } + + takeReturnTo(): string | null { + return null + } + + async handleCallback(): Promise { + return null + } + + disconnect(): void {} +} diff --git a/applications/idp-arc/frontend/vite.config.ts b/applications/idp-arc/frontend/vite.config.ts index ab5b696..caa1f29 100644 --- a/applications/idp-arc/frontend/vite.config.ts +++ b/applications/idp-arc/frontend/vite.config.ts @@ -13,8 +13,12 @@ const OSB_DOMAIN = env.VITE_OSB_BASE_DOMAIN || 'v2dev.opensourcebrain.org' const OSB_SCHEME = env.VITE_OSB_PROTOCOL || 'https' const OSB_WEB_ORIGIN = `${OSB_SCHEME}://www.${OSB_DOMAIN}` -// Throws at start for a VITE_DANDI_INSTANCE that isn't one of the four. -const DANDI_API_ORIGIN = dandiInstance(env.VITE_DANDI_INSTANCE).api +// Throws at start for a VITE_DANDI_INSTANCE that isn't one of the two. +const DANDI_INSTANCE = dandiInstance(env.VITE_DANDI_INSTANCE) +const DANDI_API_ORIGIN = DANDI_INSTANCE.api +/** Dev server on DANDI's sandbox only (no OAuth app for us there): signs every proxied DANDI call with + * this key instead of the user's token. Not VITE_-prefixed, so it never reaches the bundle. */ +const DANDI_SANDBOX_API_KEY = DANDI_INSTANCE.name === 'dandi-sandbox' ? env.DANDI_SANDBOX_API_KEY?.trim() ?? '' : '' /** * Optional HTTPS for the dev server: EMBER-DANDI's OAuth application only accepts https:// * redirect URIs, so its sign-in needs https://localhost:5173 (registered as @@ -35,6 +39,7 @@ const devHttps = loadDevHttpsCerts() // eslint-disable-next-line no-console console.log(`[vite] proxying OSB -> ${OSB_WEB_ORIGIN}`) +console.log(`[vite] proxying DANDI -> ${DANDI_API_ORIGIN}${DANDI_SANDBOX_API_KEY ? ' (signed with DANDI_SANDBOX_API_KEY, no OAuth)' : ''}`) // IPv4 lookups and reused connections for every proxied call. macOS resolves `*.local` names // (local minikube: `osb.local`) through multicast DNS first, and the IPv6 query only falls back @@ -43,8 +48,11 @@ console.log(`[vite] proxying OSB -> ${OSB_WEB_ORIGIN}`) const agentOptions = { keepAlive: true, family: 4 } const upstreamAgent = OSB_SCHEME === 'https' ? new https.Agent(agentOptions) : new http.Agent(agentOptions) -export default defineConfig({ +export default defineConfig(({ command }) => ({ plugins: [react()], + define: { + __DANDI_SANDBOX_API_KEY__: JSON.stringify(command === 'serve' && !!DANDI_SANDBOX_API_KEY), + }, build: { sourcemap: true, outDir: 'dist', @@ -70,6 +78,9 @@ export default defineConfig({ target: DANDI_API_ORIGIN, changeOrigin: true, rewrite: (path) => path.replace(/^\/ember-proxy/, ''), + ...(DANDI_SANDBOX_API_KEY ? { + configure: (proxy) => proxy.on('proxyReq', (req) => req.setHeader('Authorization', `token ${DANDI_SANDBOX_API_KEY}`)), + } : {}), }, }, }, @@ -78,4 +89,4 @@ export default defineConfig({ '@': path.resolve(__dirname, './src'), }, } -}) +})) From 7876fd7629719549e986cb16942389b5f8de4fd6 Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Thu, 5 Nov 2026 18:37:53 +0530 Subject: [PATCH 4/9] IDP-52: use the sandboxes in local development only --- README.md | 22 +++++++---------- applications/idp-arc/Dockerfile | 7 ------ .../idp-arc/deploy/resources/default.conf | 24 +++++-------------- .../idp-arc/frontend/src/app/container.ts | 6 ++--- .../frontend/src/core/dandiInstances.ts | 6 ++--- .../idp-arc/frontend/src/globals.d.ts | 2 +- .../src/infra/sandboxApiKeyEmberAuth.ts | 2 +- .../tests/unit/dandiInstances.test.ts | 18 +++++--------- applications/idp-arc/frontend/vite.config.ts | 8 +++---- 9 files changed, 32 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 76dbf74..1aae4b8 100644 --- a/README.md +++ b/README.md @@ -86,27 +86,21 @@ researcher's workspace from there. - **`bucket`**: a public bucket open for anonymous writes, named by `VITE_UPLOAD_BUCKET_URL`. Its CORS must allow PUT from this app's origin. Needs only the OSB login. -### Choosing the DANDI instance +### Testing on a sandbox (local only) -EMBER-DANDI is the default. To use another instance, such as DANDI's sandbox for testing, name it in -`applications/idp-arc/frontend/.env.local`: +Deployments always use EMBER-DANDI. To test on a sandbox instead, add this to +`applications/idp-arc/frontend/.env.local` and restart `yarn start:dev`: ```bash -# dandi, dandi-sandbox, ember-dandi (default) or ember-dandi-sandbox +# dandi-sandbox or ember-dandi-sandbox VITE_DANDI_INSTANCE=dandi-sandbox ``` -That one name sets the API and web origins (`src/core/dandiInstances.ts`), the instance OSB copies -into for MAABCD, and which dandiset of a protocol's `maabcdAggregateDandisets` in -`src/data/protocols.json` the copy goes to (none for that instance: nothing is shared). Any other -name stops the dev server and the build. In deployment, pass it as the `VITE_DANDI_INSTANCE` build -argument (the image's nginx proxy follows it; the container's `DANDI_INSTANCE` overrides the proxy). -The OSB user's `DANDI_API_KEY` must be a key for that instance. +MAABCD copies then go to the protocol's dandiset for that sandbox in `src/data/protocols.json` +(none listed: nothing is shared). -### Signing in to DANDI's sandbox with an API key (local only) - -The sandbox has no OAuth app for us, so also add your sandbox API key to `.env.local`. The dev server -signs DANDI calls with it, so it never reaches the browser, and `yarn build` ignores it: +The sandboxes have no OAuth app for us, so also add your API key on that sandbox there. The dev +server signs DANDI calls with it, so it never reaches the browser, and `yarn build` ignores it: ```bash DANDI_SANDBOX_API_KEY= diff --git a/applications/idp-arc/Dockerfile b/applications/idp-arc/Dockerfile index 7eb8193..09bde31 100644 --- a/applications/idp-arc/Dockerfile +++ b/applications/idp-arc/Dockerfile @@ -15,9 +15,6 @@ ENV VITE_UPLOAD_BUCKET_URL=${VITE_UPLOAD_BUCKET_URL} # EMBER-DANDI OAuth application (public client, PKCE) registered for this IDP origin. ARG VITE_EMBER_CLIENT_ID ENV VITE_EMBER_CLIENT_ID=${VITE_EMBER_CLIENT_ID} -# The DANDI instance: dandi, dandi-sandbox, ember-dandi (the default) or ember-dandi-sandbox. -ARG VITE_DANDI_INSTANCE -ENV VITE_DANDI_INSTANCE=${VITE_DANDI_INSTANCE} RUN yarn build FROM nginxinc/nginx-unprivileged:stable-alpine @@ -29,10 +26,6 @@ COPY --from=build --chown=101:101 /app/dist/ /usr/share/nginx/html/ # template the pod's DNS servers so the EMBER proxy can resolve at request time (see default.conf). COPY --chown=101:101 deploy/resources/default.conf /etc/nginx/templates/default.conf.template ENV NGINX_ENTRYPOINT_LOCAL_RESOLVERS=1 -# The DANDI instance the /ember-proxy forwards to: the one the bundle was built for, EMBER-DANDI -# when unset; the container's DANDI_INSTANCE overrides it at start. -ARG VITE_DANDI_INSTANCE -ENV DANDI_INSTANCE=${VITE_DANDI_INSTANCE:-ember-dandi} USER 101 EXPOSE 8080 \ No newline at end of file diff --git a/applications/idp-arc/deploy/resources/default.conf b/applications/idp-arc/deploy/resources/default.conf index 43c0d36..504613f 100644 --- a/applications/idp-arc/deploy/resources/default.conf +++ b/applications/idp-arc/deploy/resources/default.conf @@ -1,16 +1,5 @@ # Installed as an envsubst template (Dockerfile): ${NGINX_LOCAL_RESOLVERS} becomes the pod's -# nameservers from /etc/resolv.conf at container start, and ${DANDI_INSTANCE} the DANDI instance -# in use, from the container's environment. Other $names are nginx variables. - -# The instance's API (src/core/dandiInstances.ts; a test checks they agree). -map "${DANDI_INSTANCE}" $dandi_api_origin { - default ""; - "dandi" https://api.dandiarchive.org; - "dandi-sandbox" https://api.sandbox.dandiarchive.org; - "ember-dandi" https://api-dandi.emberarchive.org; - "ember-dandi-sandbox" https://api-dandi.sandbox.emberarchive.org; -} - +# nameservers from /etc/resolv.conf at container start. Other $names are nginx variables. server { listen 8080; @@ -29,20 +18,19 @@ server { # can change under us. A variable proxy_pass doesn't strip the location prefix, hence the rewrite. resolver ${NGINX_LOCAL_RESOLVERS} ipv6=off; resolver_timeout 5s; - # proxy_pass sends the instance's host as Host. An unknown DANDI_INSTANCE leaves it empty: refused. - set $dandi_api $dandi_api_origin; + set $ember https://api-dandi.emberarchive.org; location /ember-proxy/oauth/token/ { - if ($dandi_api = "") { return 500 "DANDI_INSTANCE is not a known DANDI instance"; } rewrite ^/ember-proxy(/.*)$ $1 break; - proxy_pass $dandi_api; + proxy_pass $ember; proxy_ssl_server_name on; + proxy_set_header Host api-dandi.emberarchive.org; } location /ember-proxy/api/ { - if ($dandi_api = "") { return 500 "DANDI_INSTANCE is not a known DANDI instance"; } rewrite ^/ember-proxy(/.*)$ $1 break; - proxy_pass $dandi_api; + proxy_pass $ember; proxy_ssl_server_name on; + proxy_set_header Host api-dandi.emberarchive.org; } location /ember-proxy/ { return 404; diff --git a/applications/idp-arc/frontend/src/app/container.ts b/applications/idp-arc/frontend/src/app/container.ts index 7ab08b3..a8f67dc 100644 --- a/applications/idp-arc/frontend/src/app/container.ts +++ b/applications/idp-arc/frontend/src/app/container.ts @@ -47,9 +47,9 @@ const OSB_WEB_ORIGIN = `${OSB_SCHEME}://www.${OSB_DOMAIN}` export type UploadBackend = 'ember' | 'bucket' /** VITE_UPLOAD_BACKEND: `bucket`, or EMBER-DANDI for anything else, unset included. */ export const UPLOAD_BACKEND: UploadBackend = import.meta.env.VITE_UPLOAD_BACKEND === 'bucket' ? 'bucket' : 'ember' -/** The DANDI instance in use, from VITE_DANDI_INSTANCE (EMBER-DANDI when unset): where the - * researcher's uploads go, and which of a protocol's MAABCD dandisets the copy goes to. */ -export const DANDI_INSTANCE = dandiInstance(import.meta.env.VITE_DANDI_INSTANCE) +/** The DANDI instance in use: VITE_DANDI_INSTANCE in the dev server, EMBER-DANDI otherwise. Sets where + * the researcher's uploads go, and which of a protocol's MAABCD dandisets the copy goes to. */ +export const DANDI_INSTANCE = dandiInstance(import.meta.env.DEV ? import.meta.env.VITE_DANDI_INSTANCE : undefined) const { api: EMBER_API_ORIGIN, web: EMBER_WEB_ORIGIN } = DANDI_INSTANCE /** The OSB (Keycloak) user whose key (user attribute `DANDI_API_KEY`) signs the copy into the * protocol's MAABCD dandiset, on the same instance (dandi-cli's name for it). */ diff --git a/applications/idp-arc/frontend/src/core/dandiInstances.ts b/applications/idp-arc/frontend/src/core/dandiInstances.ts index 7d6dc27..7b4012b 100644 --- a/applications/idp-arc/frontend/src/core/dandiInstances.ts +++ b/applications/idp-arc/frontend/src/core/dandiInstances.ts @@ -1,9 +1,9 @@ -/** The DANDI deployments the app can use, by the name OSB and dandi-cli know them by. */ +/** The DANDI deployments the app can use, by the name OSB and dandi-cli know them by: EMBER-DANDI, + * and the two sandboxes for local testing. */ export const DANDI_INSTANCES = { - 'dandi': { api: 'https://api.dandiarchive.org', web: 'https://dandiarchive.org' }, - 'dandi-sandbox': { api: 'https://api.sandbox.dandiarchive.org', web: 'https://sandbox.dandiarchive.org' }, 'ember-dandi': { api: 'https://api-dandi.emberarchive.org', web: 'https://dandi.emberarchive.org' }, 'ember-dandi-sandbox': { api: 'https://api-dandi.sandbox.emberarchive.org', web: 'https://dandi.sandbox.emberarchive.org' }, + 'dandi-sandbox': { api: 'https://api.sandbox.dandiarchive.org', web: 'https://sandbox.dandiarchive.org' }, } as const export type DandiInstanceName = keyof typeof DANDI_INSTANCES diff --git a/applications/idp-arc/frontend/src/globals.d.ts b/applications/idp-arc/frontend/src/globals.d.ts index 3f1d6cc..421d75b 100644 --- a/applications/idp-arc/frontend/src/globals.d.ts +++ b/applications/idp-arc/frontend/src/globals.d.ts @@ -1,2 +1,2 @@ -/** True only in the Vite dev server on DANDI's sandbox with DANDI_SANDBOX_API_KEY set (vite.config.ts `define`). */ +/** True only in the Vite dev server on a sandbox with DANDI_SANDBOX_API_KEY set (vite.config.ts `define`). */ declare const __DANDI_SANDBOX_API_KEY__: boolean diff --git a/applications/idp-arc/frontend/src/infra/sandboxApiKeyEmberAuth.ts b/applications/idp-arc/frontend/src/infra/sandboxApiKeyEmberAuth.ts index 6582db7..732fe93 100644 --- a/applications/idp-arc/frontend/src/infra/sandboxApiKeyEmberAuth.ts +++ b/applications/idp-arc/frontend/src/infra/sandboxApiKeyEmberAuth.ts @@ -6,7 +6,7 @@ const PLACEHOLDER_TOKEN = 'sandbox-proxy-api-key' /** * Local development only: always "signed in", as the owner of DANDI_SANDBOX_API_KEY. The key stays in * the Vite dev server, which sets `Authorization: token ` on every proxied DANDI call - * (vite.config.ts); the browser never sees it. For DANDI's sandbox, which has no OAuth app for us. + * (vite.config.ts); the browser never sees it. For the sandboxes, which have no OAuth app for us. */ export class SandboxApiKeyEmberAuth implements IEmberAuth { readonly expiresAt = Number.MAX_SAFE_INTEGER diff --git a/applications/idp-arc/frontend/tests/unit/dandiInstances.test.ts b/applications/idp-arc/frontend/tests/unit/dandiInstances.test.ts index 6593918..96ad950 100644 --- a/applications/idp-arc/frontend/tests/unit/dandiInstances.test.ts +++ b/applications/idp-arc/frontend/tests/unit/dandiInstances.test.ts @@ -10,15 +10,15 @@ test('EMBER-DANDI when no instance is configured', () => { } }) -test('each of the four instances gives its own API and web origins', () => { - assert.deepEqual(dandiInstance('dandi-sandbox'), { name: 'dandi-sandbox', api: 'https://api.sandbox.dandiarchive.org', web: 'https://sandbox.dandiarchive.org' }) - assert.equal(dandiInstance(' ember-dandi-sandbox ').web, 'https://dandi.sandbox.emberarchive.org') - assert.equal(dandiInstance('dandi').api, 'https://api.dandiarchive.org') - assert.equal(Object.keys(DANDI_INSTANCES).length, 4) +test('each sandbox gives its own API and web origins', () => { + assert.deepEqual(dandiInstance(' dandi-sandbox '), { name: 'dandi-sandbox', api: 'https://api.sandbox.dandiarchive.org', web: 'https://sandbox.dandiarchive.org' }) + assert.equal(dandiInstance('ember-dandi-sandbox').api, 'https://api-dandi.sandbox.emberarchive.org') + assert.deepEqual(Object.keys(DANDI_INSTANCES), ['ember-dandi', 'ember-dandi-sandbox', 'dandi-sandbox']) }) test('an unknown instance name throws, naming the ones there are', () => { - assert.throws(() => dandiInstance('dandi-sandbx'), /"dandi-sandbx".*dandi, dandi-sandbox, ember-dandi, ember-dandi-sandbox/) + assert.throws(() => dandiInstance('dandi-sandbx'), /"dandi-sandbx".*ember-dandi, ember-dandi-sandbox, dandi-sandbox/) + assert.throws(() => dandiInstance('dandi'), /not a DANDI instance/) assert.throws(() => dandiInstance('toString'), /not a DANDI instance/) }) @@ -26,7 +26,6 @@ test('a protocol\'s MAABCD dandiset is the one for the instance in use, or none' const protocol = { maabcdAggregateDandisets: { 'ember-dandi': '000607', 'dandi-sandbox': '219158' } } assert.equal(maabcdDandisetFor(protocol, 'ember-dandi'), '000607') assert.equal(maabcdDandisetFor(protocol, 'dandi-sandbox'), '219158') - assert.equal(maabcdDandisetFor(protocol, 'dandi'), undefined) assert.equal(maabcdDandisetFor({}, 'ember-dandi'), undefined) }) @@ -41,8 +40,3 @@ test('every maabcdAggregateDandisets key in protocols.json is an instance, and i } }) -test('nginx proxies to the same API origin for each instance as the app uses', () => { - const conf = readFileSync(new URL('../../../deploy/resources/default.conf', import.meta.url), 'utf8') - const mapped = Object.fromEntries([...conf.matchAll(/^\s*"([a-z-]+)"\s+(https:\/\/\S+);/gm)].map((m) => [m[1], m[2]])) - assert.deepEqual(mapped, Object.fromEntries(Object.entries(DANDI_INSTANCES).map(([name, { api }]) => [name, api]))) -}) diff --git a/applications/idp-arc/frontend/vite.config.ts b/applications/idp-arc/frontend/vite.config.ts index caa1f29..eb4d3f0 100644 --- a/applications/idp-arc/frontend/vite.config.ts +++ b/applications/idp-arc/frontend/vite.config.ts @@ -13,12 +13,12 @@ const OSB_DOMAIN = env.VITE_OSB_BASE_DOMAIN || 'v2dev.opensourcebrain.org' const OSB_SCHEME = env.VITE_OSB_PROTOCOL || 'https' const OSB_WEB_ORIGIN = `${OSB_SCHEME}://www.${OSB_DOMAIN}` -// Throws at start for a VITE_DANDI_INSTANCE that isn't one of the two. +// Throws at start for a VITE_DANDI_INSTANCE that isn't one of the three. const DANDI_INSTANCE = dandiInstance(env.VITE_DANDI_INSTANCE) const DANDI_API_ORIGIN = DANDI_INSTANCE.api -/** Dev server on DANDI's sandbox only (no OAuth app for us there): signs every proxied DANDI call with - * this key instead of the user's token. Not VITE_-prefixed, so it never reaches the bundle. */ -const DANDI_SANDBOX_API_KEY = DANDI_INSTANCE.name === 'dandi-sandbox' ? env.DANDI_SANDBOX_API_KEY?.trim() ?? '' : '' +/** Dev server on a sandbox only (no OAuth app for us there): signs every proxied DANDI call with this + * key instead of the user's token. Not VITE_-prefixed, so it never reaches the bundle. */ +const DANDI_SANDBOX_API_KEY = DANDI_INSTANCE.name.endsWith('-sandbox') ? env.DANDI_SANDBOX_API_KEY?.trim() ?? '' : '' /** * Optional HTTPS for the dev server: EMBER-DANDI's OAuth application only accepts https:// * redirect URIs, so its sign-in needs https://localhost:5173 (registered as From d0635b437ce15c265227e8214feaf1ada6fb59f2 Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Thu, 5 Nov 2026 19:02:05 +0530 Subject: [PATCH 5/9] IDP-52: pack a README into each upload; show "Open workspace" only once it exists --- applications/idp-arc/frontend/package.json | 3 +- .../idp-arc/frontend/src/app/container.ts | 2 +- .../src/components/DataUploadDialog.tsx | 4 +- .../frontend/src/core/dandisetReadme.ts | 68 ++++++++++++++++ .../idp-arc/frontend/src/core/pathSafe.ts | 9 +++ .../frontend/src/core/ports/IObjectStore.ts | 4 +- .../src/core/use-cases/emberObjectStore.ts | 32 ++++++-- .../src/core/use-cases/runProtocol.ts | 4 +- .../src/infra/emberDandiDirectClient.ts | 2 + .../tests/unit/dandisetReadme.test.ts | 80 +++++++++++++++++++ .../tests/unit/emberObjectStore.test.ts | 36 +++++++-- .../frontend/tests/unit/pathSafe.test.ts | 17 ++++ .../frontend/tests/unit/runProtocol.test.ts | 5 +- applications/idp-arc/frontend/yarn.lock | 5 ++ 14 files changed, 252 insertions(+), 19 deletions(-) create mode 100644 applications/idp-arc/frontend/src/core/dandisetReadme.ts create mode 100644 applications/idp-arc/frontend/src/core/pathSafe.ts create mode 100644 applications/idp-arc/frontend/tests/unit/dandisetReadme.test.ts create mode 100644 applications/idp-arc/frontend/tests/unit/pathSafe.test.ts diff --git a/applications/idp-arc/frontend/package.json b/applications/idp-arc/frontend/package.json index d853039..fec8f60 100644 --- a/applications/idp-arc/frontend/package.json +++ b/applications/idp-arc/frontend/package.json @@ -18,6 +18,7 @@ "@emotion/styled": "^11.14.1", "@mui/icons-material": "^9.0.0", "@mui/material": "^9.0.0", + "fflate": "^0.8.2", "i18next": "^26.0.3", "keycloak-js": "^26.2.3", "react": "^19.2.0", @@ -42,4 +43,4 @@ "typescript-eslint": "^8.48.0", "vite": "^7.3.1" } -} \ No newline at end of file +} diff --git a/applications/idp-arc/frontend/src/app/container.ts b/applications/idp-arc/frontend/src/app/container.ts index a8f67dc..37a6c38 100644 --- a/applications/idp-arc/frontend/src/app/container.ts +++ b/applications/idp-arc/frontend/src/app/container.ts @@ -92,7 +92,7 @@ const protocolDandisets = createProtocolDandisetsUseCases({ /** Where uploads go before OSB imports them (UPLOAD_BACKEND): EMBER-DANDI, or the public bucket. */ export const objectStore: IObjectStore = UPLOAD_BACKEND === 'ember' - ? createEmberObjectStore(authClient, emberAuth, emberDirect, new EmberUploadApiClient(WORKSPACES_API, MAABCD_DANDI_INSTANCE, MAABCD_EMBER_USERNAME), protocolDandisets, EMBER_API_ORIGIN) + ? createEmberObjectStore(authClient, emberAuth, emberDirect, new EmberUploadApiClient(WORKSPACES_API, MAABCD_DANDI_INSTANCE, MAABCD_EMBER_USERNAME), protocolDandisets, EMBER_API_ORIGIN, EMBER_WEB_ORIGIN) : new PublicBucketObjectStore(import.meta.env.VITE_UPLOAD_BUCKET_URL) // ─── Use-cases (injected with their concrete dependencies) ──────────────────── diff --git a/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx b/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx index d80d33e..3fe3178 100644 --- a/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx +++ b/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx @@ -631,7 +631,9 @@ export default function DataUploadDialog({ open, initialProtocol, onClose, onAut {step === 'stillRunning' ? 'Results will be in' : 'Results are in'} {outputsDir}/ in your workspace. )} - {step !== 'uploading' && spawnedWorkspaceId !== undefined && ( + {/* Only once this run has its workspace: one merely recorded in the dandiset may not be touched yet. */} + {step !== 'uploading' && spawnedWorkspaceId !== undefined + && runSteps.some((s) => s.id === RUN_STEP.workspace && s.state === 'succeeded') && ( diff --git a/applications/idp-arc/frontend/src/core/dandisetReadme.ts b/applications/idp-arc/frontend/src/core/dandisetReadme.ts new file mode 100644 index 0000000..d14b963 --- /dev/null +++ b/applications/idp-arc/frontend/src/core/dandisetReadme.ts @@ -0,0 +1,68 @@ +/** + * The README that travels with an upload: it says which dandiset the data is in, so whoever opens + * the OSB workspace can find it. It goes inside the uploaded zip, which OSB's import unpacks next to + * the data; a plain file is zipped with it. + * + * The zip is the same bytes every time for the same file and README (fixed dates, no clock in the + * text): a retry recomputes the DANDI etag, and the upload checkpoint relies on it not changing. + */ +import { strToU8, unzipSync, zipSync, type Zippable } from 'fflate' + +/** Files bigger than this go up as they are, without a README: repacking reads them into memory. */ +export const MAX_REPACK_BYTES = 200 * 1024 * 1024 + +/** A fixed entry date, so the zip's bytes don't depend on when it was built. */ +const ENTRY_DATE = new Date(2000, 0, 1) + +export interface DandisetReadmeInput { + /** The dandiset's own name. */ + name: string + dandisetId: string + /** The dandiset's page on the archive's website. */ + dandisetUrl: string + protocol: { name: string; url?: string; description?: string } + /** The name of the file the researcher uploaded. */ + originalName: string +} + +export function dandisetReadme({ name, dandisetId, dandisetUrl, protocol, originalName }: DandisetReadmeInput): string { + return [ + `# ${name}`, + '', + `Behavioral data from the ${protocol.name}.`, + '', + ...(protocol.description ? [protocol.description, ''] : []), + '## Files', + '', + `- \`${originalName}\`: the researcher's upload. Every file here except this README comes from it, unchanged.`, + '', + '## Links', + '', + `- Dandiset ${dandisetId}: ${dandisetUrl} (every published version, with its DOI)`, + ...(protocol.url ? [`- Analysis code: ${protocol.url}`] : []), + '', + ].join('\n') +} + +/** The file to upload: `file` with `readme` added (into it if it is a zip, else zipped together). */ +export async function withReadme(file: File, readme: string): Promise { + const bytes = new Uint8Array(await file.arrayBuffer()) + let entries: Record | null = null + if (file.name.toLowerCase().endsWith('.zip')) { + try { + entries = unzipSync(bytes) + } catch { + entries = null // not a readable zip: carried inside the new one, as it is + } + } + const files = entries + ? Object.entries(entries).filter(([path]) => !path.endsWith('/')) + : [[file.name, bytes] as const] + const readmeName = files.some(([path]) => path === 'README.md') ? 'README-dandiset.md' : 'README.md' + + const zippable: Zippable = { [readmeName]: [strToU8(readme), { mtime: ENTRY_DATE }] } + for (const [path, data] of files) zippable[path] = [data, { mtime: ENTRY_DATE }] + const name = entries ? file.name : `${file.name.replace(/\.[^.]*$/, '') || file.name}.zip` + const zipped = zipSync(zippable, { level: 6 }) as Uint8Array + return new File([zipped], name, { type: 'application/zip', lastModified: ENTRY_DATE.getTime() }) +} diff --git a/applications/idp-arc/frontend/src/core/pathSafe.ts b/applications/idp-arc/frontend/src/core/pathSafe.ts new file mode 100644 index 0000000..33f847f --- /dev/null +++ b/applications/idp-arc/frontend/src/core/pathSafe.ts @@ -0,0 +1,9 @@ +/** One DANDI asset path segment: DANDI rejects `@` and the like, and `/` would add segments. + * Runs of other characters become one `-`; none is left dangling before the extension. */ +export function pathSafe(value: string): string { + return value + .replace(/[^A-Za-z0-9._-]+/g, '-') + .replace(/-{2,}/g, '-') + .replace(/-+(\.[A-Za-z0-9]+)?$/, '$1') + .replace(/^[-._]+|[-._]+$/g, '') || 'unknown' +} diff --git a/applications/idp-arc/frontend/src/core/ports/IObjectStore.ts b/applications/idp-arc/frontend/src/core/ports/IObjectStore.ts index 00ee9aa..08eb331 100644 --- a/applications/idp-arc/frontend/src/core/ports/IObjectStore.ts +++ b/applications/idp-arc/frontend/src/core/ports/IObjectStore.ts @@ -19,7 +19,7 @@ export interface ObjectUploadInput { user?: string newName?: string /** Recorded in the dandiset's metadata, with the workspace the run uses. */ - protocol?: { id: string; name: string; url?: string } + protocol?: { id: string; name: string; url?: string; description?: string } /** The protocol's MAABCD dandiset (protocols.json `maabcdAggregateDandisets`, for the instance in use), uploaded to through OSB. */ maabcd?: string } @@ -42,6 +42,8 @@ export interface StoredObject { dandisetId?: string /** EMBER-DANDI: the file's DANDI etag, so the MAABCD copy needs no file. */ etag?: string + /** EMBER-DANDI: the README packed into the upload (dandisetReadme.ts), to rebuild the same bytes from the file. */ + readme?: string } export interface IObjectStore { diff --git a/applications/idp-arc/frontend/src/core/use-cases/emberObjectStore.ts b/applications/idp-arc/frontend/src/core/use-cases/emberObjectStore.ts index c96ec1d..20b4618 100644 --- a/applications/idp-arc/frontend/src/core/use-cases/emberObjectStore.ts +++ b/applications/idp-arc/frontend/src/core/use-cases/emberObjectStore.ts @@ -4,6 +4,8 @@ import type { IEmberAuth } from '../ports/IEmberAuth' import type { IEmberUploadApi } from '../ports/IEmberUploadApi' import type { IObjectStore, ObjectUploadInput, StoredObject } from '../ports/IObjectStore' import { computeDandiEtag, type PartPlan } from '../dandiEtag' +import { dandisetReadme, MAX_REPACK_BYTES, withReadme } from '../dandisetReadme' +import { pathSafe } from '../pathSafe' import { EMBER_SIGN_IN, UserFacingError } from '../userMessages' import type { ProtocolDandisets } from './protocolDandisets' @@ -42,10 +44,11 @@ export function createEmberObjectStore( /** EMBER's public API origin (`https://api-dandi.emberarchive.org`): the download link has to * work from OSB's cluster, so never the browser's same-origin proxy. */ emberApiOrigin: string, + /** EMBER-DANDI's web origin (`https://dandi.emberarchive.org`): the dandiset page in the README. */ + emberWebOrigin: string, ): IObjectStore { return { async put(input: ObjectUploadInput, onProgress?: (sentBytes: number, totalBytes: number) => void): Promise { - const { file } = input const token = emberAuth.getToken() if (!token) throw new UserFacingError(EMBER_SIGN_IN, 'No EMBER-DANDI token (not signed in, or it expired)') const saved: EmberUploadCheckpoint = { ...(input.resume as EmberUploadCheckpoint | undefined) } @@ -54,6 +57,8 @@ export function createEmberObjectStore( input.onCheckpoint?.({ ...saved }) } + // What goes up is the file with the README packed in, once the dandiset (its link) is known. + let file = input.file const progress = (sent: number) => onProgress?.(Math.min(sent, file.size), file.size) progress(saved.own ? file.size : 0) @@ -62,6 +67,16 @@ export function createEmberObjectStore( const userDandisetId = saved.userDandisetId || input.dandisets?.user || await dandisets.createForProtocol(input.dandisets?.newName || protocol.name, protocol) if (saved.userDandisetId !== userDandisetId) save({ userDandisetId }) + // The dandiset's own name: a re-upload into an existing one keeps the name it has. + const name = await dandisetName(token, userDandisetId) || input.dandisets?.newName || protocol.name + const readme = input.file.size <= MAX_REPACK_BYTES ? dandisetReadme({ + name, + dandisetId: userDandisetId, + dandisetUrl: `${emberWebOrigin.replace(/\/+$/, '')}/dandiset/${userDandisetId}`, + protocol, + originalName: input.file.name, + }) : undefined + if (readme) file = await withReadme(input.file, readme) let asset = saved.own if (!asset) { const { etag, parts: plan } = await computeDandiEtag(file) @@ -83,6 +98,7 @@ export function createEmberObjectStore( size: file.size, dandisetId: userDandisetId, etag: saved.etag, + ...(readme ? { readme } : {}), } }, @@ -90,7 +106,9 @@ export function createEmberObjectStore( if (stored.dandisetId) await dandisets.recordWorkspace(stored.dandisetId, workspaceId, protocol) }, - async shareWithMaabcd(stored, dandisetId, file) { + async shareWithMaabcd(stored, dandisetId, original) { + // The bytes of the researcher's copy: the same README packed in the same way. + const file = original && stored.readme ? await withReadme(original, stored.readme) : original const hashed = !stored.etag && file ? await computeDandiEtag(file) : undefined const etag = stored.etag ?? hashed?.etag if (!etag) throw new Error('The MAABCD copy needs the file\'s checksum, but no file is selected (the page was reloaded)') @@ -112,6 +130,11 @@ export function createEmberObjectStore( }, } + async function dandisetName(token: string, dandisetId: string): Promise { + const { name } = await direct.getDraftMetadata(token, dandisetId) + return typeof name === 'string' && name.trim() ? name.trim() : undefined + } + async function putParts(parts: { partNumber: number; url: string }[], plan: PartPlan[], file: File, report: (sentInTransfer: number) => void) { // Every part or none (deduplicated): a shorter list would silently upload a truncated file. @@ -131,8 +154,3 @@ export function createEmberObjectStore( return result } } - -/** One asset path segment: DANDI rejects `@` and the like; also stops `/` adding segments. */ -function pathSafe(value: string): string { - return value.replace(/[^A-Za-z0-9._-]+/g, '-').replace(/^[-._]+|[-._]+$/g, '') || 'unknown' -} diff --git a/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts b/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts index bc759fd..54dfb7f 100644 --- a/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts +++ b/applications/idp-arc/frontend/src/core/use-cases/runProtocol.ts @@ -33,6 +33,8 @@ export interface RunProtocolDefinition { * `maabcdAggregateDandisets`), which each upload is also copied into (through OSB). Empty or * absent: no MAABCD copy. */ maabcdAggregateDandisetId?: string + /** What the task is: written into the upload's README. */ + description?: string } export interface RunProtocolInput { @@ -290,7 +292,7 @@ export function createRunProtocolUseCase( dandisets: { user: input.dandisetId, newName: input.dandisetName?.trim() || protocol.name, - protocol: protocolRef(), + protocol: { ...protocolRef(), description: protocol.description }, maabcd: input.shareWithMaabcd === false ? undefined : protocol.maabcdAggregateDandisetId, }, }, (sent, total) => { diff --git a/applications/idp-arc/frontend/src/infra/emberDandiDirectClient.ts b/applications/idp-arc/frontend/src/infra/emberDandiDirectClient.ts index d2dc359..6653117 100644 --- a/applications/idp-arc/frontend/src/infra/emberDandiDirectClient.ts +++ b/applications/idp-arc/frontend/src/infra/emberDandiDirectClient.ts @@ -312,6 +312,8 @@ function guessContentType(path: string): string { csv: 'text/csv', tsv: 'text/tab-separated-values', json: 'application/json', + md: 'text/markdown', + zip: 'application/zip', nwb: 'application/x-nwb', txt: 'text/plain', xls: 'application/vnd.ms-excel', diff --git a/applications/idp-arc/frontend/tests/unit/dandisetReadme.test.ts b/applications/idp-arc/frontend/tests/unit/dandisetReadme.test.ts new file mode 100644 index 0000000..905a0fe --- /dev/null +++ b/applications/idp-arc/frontend/tests/unit/dandisetReadme.test.ts @@ -0,0 +1,80 @@ +// The README packed into an upload (core/dandisetReadme.ts). Run: yarn test:unit +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { strFromU8, strToU8, unzipSync, zipSync } from 'fflate' +import { dandisetReadme, withReadme } from '../../src/core/dandisetReadme' + +const README = dandisetReadme({ + name: 'Cohort A, spring 2026', + dandisetId: '000777', + dandisetUrl: 'https://dandi.example.org/dandiset/000777', + protocol: { + name: 'Four-choice reversal digging task', + url: 'https://github.com/maracbaylis/four-choice-example', + description: 'Mice must identify the single rewarded option.', + }, + originalName: 'cohort.zip', +}) + +const unpack = async (file: File) => unzipSync(new Uint8Array(await file.arrayBuffer())) + +test('the README says what the dataset is, then its files and links, and nothing time-dependent', () => { + assert.equal(README, [ + '# Cohort A, spring 2026', + '', + 'Behavioral data from the Four-choice reversal digging task.', + '', + 'Mice must identify the single rewarded option.', + '', + '## Files', + '', + '- `cohort.zip`: the researcher\'s upload. Every file here except this README comes from it, unchanged.', + '', + '## Links', + '', + '- Dandiset 000777: https://dandi.example.org/dandiset/000777 (every published version, with its DOI)', + '- Analysis code: https://github.com/maracbaylis/four-choice-example', + '', + ].join('\n')) +}) + +test('without a description or analysis code, those lines are left out', () => { + const readme = dandisetReadme({ name: 'X', dandisetId: '1', dandisetUrl: 'u', protocol: { name: 'P' }, originalName: 'a.xlsx' }) + assert.doesNotMatch(readme, /Analysis code|\n\n\n/) +}) + +test('a single file is zipped together with the README, under its own name', async () => { + const packed = await withReadme(new File(['sheet bytes'], 'animal 01.xlsx'), README) + assert.equal(packed.name, 'animal 01.zip') + const entries = await unpack(packed) + assert.deepEqual(Object.keys(entries), ['README.md', 'animal 01.xlsx']) + assert.equal(strFromU8(entries['README.md']), README) + assert.equal(strFromU8(entries['animal 01.xlsx']), 'sheet bytes') +}) + +test('a zip keeps its name and every file and folder path; the README goes at its top', async () => { + const upload = zipSync({ 'cohort/': new Uint8Array(), 'cohort/a.xlsx': strToU8('a'), 'cohort/protocol.pdf': strToU8('p') }) + const packed = await withReadme(new File([upload], 'cohort.zip'), README) + assert.equal(packed.name, 'cohort.zip') + const entries = await unpack(packed) + assert.deepEqual(Object.keys(entries), ['README.md', 'cohort/a.xlsx', 'cohort/protocol.pdf']) + assert.equal(strFromU8(entries['cohort/a.xlsx']), 'a') +}) + +test('a README.md already in the zip is kept; ours takes another name', async () => { + const upload = zipSync({ 'README.md': strToU8('the lab\'s own notes') }) + const entries = await unpack(await withReadme(new File([upload], 'x.zip'), README)) + assert.deepEqual(Object.keys(entries), ['README-dandiset.md', 'README.md']) + assert.equal(strFromU8(entries['README.md']), 'the lab\'s own notes') +}) + +test('the same file and README always give the same bytes, so a retry gets the same checksum', async () => { + const bytes = async () => new Uint8Array(await (await withReadme(new File(['sheet'], 'a.xlsx'), README)).arrayBuffer()) + assert.deepEqual(await bytes(), await bytes()) +}) + +test('a .zip that is not a readable zip is carried inside the new one as it is', async () => { + const entries = await unpack(await withReadme(new File(['not a zip'], 'broken.zip'), README)) + assert.deepEqual(Object.keys(entries), ['README.md', 'broken.zip']) + assert.equal(strFromU8(entries['broken.zip']), 'not a zip') +}) diff --git a/applications/idp-arc/frontend/tests/unit/emberObjectStore.test.ts b/applications/idp-arc/frontend/tests/unit/emberObjectStore.test.ts index b27cdf1..a16d85a 100644 --- a/applications/idp-arc/frontend/tests/unit/emberObjectStore.test.ts +++ b/applications/idp-arc/frontend/tests/unit/emberObjectStore.test.ts @@ -5,13 +5,16 @@ import { createEmberObjectStore, EMBER_SIGN_IN } from '../../src/core/use-cases/ import type { IDandiDirectApi } from '../../src/core/ports/IDandiDirectApi' import type { IEmberUploadApi } from '../../src/core/ports/IEmberUploadApi' import { UserFacingError } from '../../src/core/userMessages' +import { strFromU8, unzipSync } from 'fflate' const ORIGIN = 'https://api-dandi.example.org' +const WEB = 'https://dandi.example.org' const file = () => new File(['animal data'], 'animal 01.xlsx') const finalizedPaths: string[] = [] function fakes(opts: { dedupDirect?: boolean; dedupOsb?: boolean; shortParts?: boolean; failOsbOnce?: boolean; failDirectOnce?: boolean } = {}) { const calls: string[] = [] + const sent: Blob[] = [] let osbFails = opts.failOsbOnce ? 1 : 0 let directFails = opts.failDirectOnce ? 1 : 0 const direct: IDandiDirectApi = { @@ -27,7 +30,7 @@ function fakes(opts: { dedupDirect?: boolean; dedupOsb?: boolean; shortParts?: b if (directFails > 0) { directFails -= 1; throw new Error('EMBER initialize failed') } return opts.dedupDirect ? { parts: [], blobId: 'blob-1' } : { uploadId: 'up-1', parts: [{ partNumber: 1, size: 11, url: 'https://s3/direct' }] } }, - async putPart(url) { calls.push(`put:${url}`); return `etag-${url.split('/').pop()}` }, + async putPart(url, body) { calls.push(`put:${url}`); sent.push(body); return `etag-${url.split('/').pop()}` }, async finalizeUpload(token, input) { finalizedPaths.push(input.path) calls.push(`direct-finalize:${input.dandisetId}:${input.uploadId ?? 'dedup'}:${input.parts.map((p) => p.etag).join(',')}`) @@ -52,9 +55,11 @@ function fakes(opts: { dedupDirect?: boolean; dedupOsb?: boolean; shortParts?: b async recordWorkspace(dandisetId: string, workspaceId: number, protocol: { id: string }) { calls.push(`record:${dandisetId}:${workspaceId}:${protocol.id}`) }, } const store = (emberToken: string | null = 'ember-token') => createEmberObjectStore( - { getToken: async () => 'osb-token' }, { getToken: () => emberToken }, direct, osb, dandisets, `${ORIGIN}/`, + { getToken: async () => 'osb-token' }, + { getToken: () => emberToken }, + direct, osb, dandisets, `${ORIGIN}/`, WEB, ) - return { calls, store } + return { calls, store, sent } } test('uploads to the picked dandiset directly; the MAABCD copy is a separate call, through OSB', async () => { @@ -69,10 +74,10 @@ test('uploads to the picked dandiset directly; the MAABCD copy is a separate cal // Plain data, so it can be saved across a reload: the copy needs the etag, not the file. assert.deepEqual(JSON.parse(JSON.stringify(stored)), stored) await store().shareWithMaabcd!(stored, '000533', file()) - assert.deepEqual(calls.slice(3), ['osb-urls:osb-token:000533:animal 01.xlsx:true', 'put:https://s3/osb', 'osb-validate:000533:etag-osb']) + assert.deepEqual(calls.slice(3), ['osb-urls:osb-token:000533:animal 01.zip:true', 'put:https://s3/osb', 'osb-validate:000533:etag-osb']) // The run imports the researcher's own copy, from EMBER's public origin (not the browser's proxy). assert.equal(stored.url, `${ORIGIN}/api/assets/asset-1/download/`) - assert.match(stored.key, /^four-choice-reversal\/[0-9a-f-]{36}\/animal-01\.xlsx$/) + assert.match(stored.key, /^four-choice-reversal\/[0-9a-f-]{36}\/animal-01\.zip$/) assert.equal(stored.dandisetId, '000123') assert.equal(progress.at(-1), 1) assert.ok(progress.every((p, i) => i === 0 || p >= progress[i - 1]), 'progress never goes backwards') @@ -129,7 +134,7 @@ test('a failed MAABCD copy rejects on its own; calling it again makes only that calls.length = 0 await store().shareWithMaabcd!(stored, '000533', file()) - assert.deepEqual(calls, ['osb-urls:osb-token:000533:animal 01.xlsx:true', 'put:https://s3/osb', 'osb-validate:000533:etag-osb']) + assert.deepEqual(calls, ['osb-urls:osb-token:000533:animal 01.zip:true', 'put:https://s3/osb', 'osb-validate:000533:etag-osb']) }) test('without the file, the MAABCD copy works when EMBER already holds the bytes, and fails when it would need the bytes', async () => { @@ -177,3 +182,22 @@ test('a retry with everything done makes no copy at all', async () => { assert.equal(stored.url, `${ORIGIN}/api/assets/asset-1/download/`) }) + +test('what goes up is the file zipped with a README linking the dandiset; the MAABCD copy rebuilds the same bytes', async () => { + const { store, sent } = fakes() + const stored = await store().put({ + file: file(), protocolId: 'four-choice-reversal', userSub: 'user-1', + dandisets: { user: '000123', protocol: { id: 'four-choice-reversal', name: 'Four-choice reversal digging task' } }, + }) + const uploaded = unzipSync(new Uint8Array(await sent[0].arrayBuffer())) + assert.deepEqual(Object.keys(uploaded), ['README.md', 'animal 01.xlsx']) + assert.equal(strFromU8(uploaded['animal 01.xlsx']), 'animal data') + assert.match(strFromU8(uploaded['README.md']), /^- Dandiset 000123: https:\/\/dandi\.example\.org\/dandiset\/000123 /m) + assert.equal(stored.readme, strFromU8(uploaded['README.md'])) + assert.equal(stored.name, 'animal 01.zip') + assert.equal(stored.size, sent[0].size) + + // Without the etag (an older checkpoint), the copy hashes the file it is given: rebuilt, it matches. + await store().shareWithMaabcd!({ ...stored, etag: undefined }, '000533', file()) + assert.deepEqual(new Uint8Array(await sent[1].arrayBuffer()), new Uint8Array(await sent[0].arrayBuffer())) +}) diff --git a/applications/idp-arc/frontend/tests/unit/pathSafe.test.ts b/applications/idp-arc/frontend/tests/unit/pathSafe.test.ts new file mode 100644 index 0000000..b253ab3 --- /dev/null +++ b/applications/idp-arc/frontend/tests/unit/pathSafe.test.ts @@ -0,0 +1,17 @@ +// One DANDI asset path segment (core/pathSafe.ts). Run: yarn test:unit +import { test } from 'node:test' +import assert from 'node:assert/strict' +import { pathSafe } from '../../src/core/pathSafe' + +test('runs of other characters become one dash, and none is left before the extension', () => { + assert.equal(pathSafe('four-choice-filled-3-animals-ABC001-003 -2-.zip'), 'four-choice-filled-3-animals-ABC001-003-2.zip') + assert.equal(pathSafe('Weight and Feeding log.xlsx'), 'Weight-and-Feeding-log.xlsx') + assert.equal(pathSafe('animal_01.xlsx'), 'animal_01.xlsx') + assert.equal(pathSafe('a@b/c.xlsx'), 'a-b-c.xlsx') +}) + +test('nothing usable gives "unknown"; dots and dashes at the ends are dropped', () => { + assert.equal(pathSafe('@@@'), 'unknown') + assert.equal(pathSafe('--.hidden--'), 'hidden') + assert.equal(pathSafe('four-choice-reversal'), 'four-choice-reversal') +}) diff --git a/applications/idp-arc/frontend/tests/unit/runProtocol.test.ts b/applications/idp-arc/frontend/tests/unit/runProtocol.test.ts index 4f57e3c..9723c8e 100644 --- a/applications/idp-arc/frontend/tests/unit/runProtocol.test.ts +++ b/applications/idp-arc/frontend/tests/unit/runProtocol.test.ts @@ -335,7 +335,10 @@ test('an EMBER-DANDI upload gets the run\'s workspace recorded in its dandiset, assert.equal(f.calls[create + 1], 'record:42') assert.deepEqual(seen.dandisets, { user: '000123', newName: 'Four-choice reversal digging task', maabcd: '000533', - protocol: { id: 'four-choice-reversal', name: 'Four-choice reversal digging task', url: 'https://github.com/maracbaylis/four-choice-example' }, + protocol: { + id: 'four-choice-reversal', name: 'Four-choice reversal digging task', url: 'https://github.com/maracbaylis/four-choice-example', + description: FOUR_CHOICE.description, + }, }) }) diff --git a/applications/idp-arc/frontend/yarn.lock b/applications/idp-arc/frontend/yarn.lock index ecd6b8e..2dc69b8 100644 --- a/applications/idp-arc/frontend/yarn.lock +++ b/applications/idp-arc/frontend/yarn.lock @@ -1311,6 +1311,11 @@ fdir@^6.5.0: resolved "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz" integrity sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg== +fflate@0.8.2: + version "0.8.2" + resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.8.2.tgz#fc8631f5347812ad6028bbe4a2308b2792aa1dea" + integrity sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A== + file-entry-cache@^8.0.0: version "8.0.0" resolved "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz" From 928254d4ec06eb29d4c5ce31c9554dbe34ae1b50 Mon Sep 17 00:00:00 2001 From: "D. Gopal Krishna" Date: Fri, 6 Nov 2026 02:05:23 +0530 Subject: [PATCH 6/9] IDP-52: convert Reporting Sheets to BIDS and check them on pick --- .../src/components/BidsStructureButton.tsx | 66 +++ .../src/components/DataUploadDialog.tsx | 41 +- .../frontend/src/components/useBidsCheck.ts | 35 ++ .../idp-arc/frontend/src/core/bids/config.ts | 119 +++++ .../idp-arc/frontend/src/core/bids/convert.ts | 65 +++ .../frontend/src/core/bids/datasetFiles.ts | 107 +++++ .../frontend/src/core/bids/fileTree.ts | 33 ++ .../idp-arc/frontend/src/core/bids/sheet.ts | 108 +++++ .../idp-arc/frontend/src/core/bids/upload.ts | 49 ++ .../idp-arc/frontend/src/core/bids/values.ts | 54 +++ .../frontend/src/core/bids/workbook.ts | 111 +++++ .../frontend/src/core/bids/xlsxReader.ts | 89 ++++ .../idp-arc/frontend/src/core/zipStream.ts | 308 ++++++++++++ .../idp-arc/frontend/src/data/README.md | 1 + .../idp-arc/frontend/src/data/protocols.json | 234 ++++++++++ .../frontend/tests/unit/bidsConvert.test.ts | 442 ++++++++++++++++++ .../frontend/tests/unit/xlsxFixture.ts | 66 +++ .../frontend/tests/unit/zipStream.test.ts | 84 ++++ 18 files changed, 2010 insertions(+), 2 deletions(-) create mode 100644 applications/idp-arc/frontend/src/components/BidsStructureButton.tsx create mode 100644 applications/idp-arc/frontend/src/components/useBidsCheck.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/config.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/convert.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/datasetFiles.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/fileTree.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/sheet.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/upload.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/values.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/workbook.ts create mode 100644 applications/idp-arc/frontend/src/core/bids/xlsxReader.ts create mode 100644 applications/idp-arc/frontend/src/core/zipStream.ts create mode 100644 applications/idp-arc/frontend/tests/unit/bidsConvert.test.ts create mode 100644 applications/idp-arc/frontend/tests/unit/xlsxFixture.ts create mode 100644 applications/idp-arc/frontend/tests/unit/zipStream.test.ts diff --git a/applications/idp-arc/frontend/src/components/BidsStructureButton.tsx b/applications/idp-arc/frontend/src/components/BidsStructureButton.tsx new file mode 100644 index 0000000..c48c64f --- /dev/null +++ b/applications/idp-arc/frontend/src/components/BidsStructureButton.tsx @@ -0,0 +1,66 @@ +import { useState } from 'react' +import { Box, IconButton, Popover, Tooltip, Typography } from '@mui/material' +import AccountTreeOutlinedIcon from '@mui/icons-material/AccountTreeOutlined' +import { contentSize, type OutputFile } from '../core/bids/convert' +import { fileTree } from '../core/bids/fileTree' +import { formatBytes } from '../core/formatBytes' + +/** Shows, in a popover, the folders and files the BIDS conversion of the picked file would produce. */ +export default function BidsStructureButton({ files }: { files: OutputFile[] }) { + const [anchor, setAnchor] = useState(null) + const sizes = new Map(files.map((f) => [f.path, contentSize(f.content)])) + const lines = fileTree(files.map((f) => f.path)) + // A line's full path, to look its size up: the folders above it, then its name. + const parents: string[] = [] + + return ( + <> + + { e.stopPropagation(); setAnchor(e.currentTarget) }}> + + + + setAnchor(null)} + onClick={(e) => e.stopPropagation()} + anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} + transformOrigin={{ vertical: 'top', horizontal: 'center' }} + slotProps={{ + paper: { + sx: { + // Opaque, so the dialog underneath doesn't show through. + bgcolor: '#2A2A2A', + backgroundImage: 'none', + border: '1px solid', + borderColor: 'divider', + boxShadow: 12, + mt: 1, + }, + }, + }} + > + + + What would go to DANDI, worked out in your browser. Nothing has been uploaded. + + + {lines.map((line, i) => { + parents.length = line.depth + const path = [...parents, line.name].join('') + if (line.folder) parents.push(line.name) + const size = sizes.get(path) + return ( + + {' '.repeat(line.depth)}{line.name} + {size !== undefined && {` ${formatBytes(size)}`}} + + ) + })} + + + + + ) +} diff --git a/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx b/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx index 3fe3178..fb89219 100644 --- a/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx +++ b/applications/idp-arc/frontend/src/components/DataUploadDialog.tsx @@ -37,6 +37,9 @@ import { isNonBlocking, PUBLISH_STEP, PUBLISHING_LABEL, type RunProtocolInput } import { formatBytes } from '../core/formatBytes' import { templatesZipFileName, templatesZipHref } from '../core/protocolTemplates' import { SIGN_IN_AGAIN } from '../core/userMessages' +import type { BidsConfig } from '../core/bids/convert' +import { useBidsCheck } from './useBidsCheck' +import BidsStructureButton from './BidsStructureButton' import protocols from '../data/protocols.json' /** Only protocols with an analysis repository can be run, so only those are offered. Each carries @@ -197,9 +200,14 @@ export default function DataUploadDialog({ open, initialProtocol, onClose, onAut const inputFormats = inputFormatsFor(selectedProtocol?.inputFormats) const templatesHref = templatesZipHref(selectedProtocol) const fileProblem = file ? inputFileProblem(file, selectedProtocol?.name ?? 'This protocol', selectedProtocol?.inputFormats) : null + // The file is converted to BIDS on pick, and its errors stop the upload. + const bidsConfig = selectedProtocol?.bids as BidsConfig | undefined + const bidsCheck = useBidsCheck(fileProblem ? null : file, bidsConfig, selectedProtocol?.name ?? '') + const bidsProblems = bidsCheck.result?.problems ?? [] + const bidsBlocks = bidsCheck.checking || bidsProblems.some((p) => p.level === 'error') const handleUpload = async () => { - if (fileProblem || !selectedProtocol) return + if (fileProblem || bidsBlocks || !selectedProtocol) return // Picked up after a reload: the file is needed again unless it was already uploaded. if (!file) { if (checkpoint?.stored) return runLocked(selectedProtocol, null) @@ -314,7 +322,7 @@ export default function DataUploadDialog({ open, initialProtocol, onClose, onAut const stepIndex = step === 'select' ? 0 : 1 const canGoNext = !!protocol && (!usesEmber || (emberSignedIn && protocolDandisets !== null && !findingWorkspace)) - const canUpload = !!file && !fileProblem && emberSignedIn + const canUpload = !!file && !fileProblem && !bidsBlocks && emberSignedIn return ( )} + {bidsCheck.checking && ( + Checking the file… + )} + {bidsCheck.result && ( + e.stopPropagation()}> + {!bidsProblems.some((p) => p.level === 'error') && ( + + + Ready for DANDI: {bidsCheck.result.subjects.length === 1 ? '1 animal' : `${bidsCheck.result.subjects.length} animals`} ({bidsCheck.result.subjects.map((s) => s.id).join(', ')}),{' '} + {bidsCheck.result.files.filter((f) => f.path.startsWith('sub-') && f.path.endsWith('.tsv')).length} tables + + + + )} + {bidsProblems.slice(0, 8).map((p, i) => ( + + {p.message} + + ))} + {bidsProblems.length > 8 && ( + …and {bidsProblems.length - 8} more + )} + + )} ) : ( <> @@ -594,6 +626,11 @@ export default function DataUploadDialog({ open, initialProtocol, onClose, onAut Download an example input file for this protocol and fill in your data the same way. + {bidsConfig && ( + + Upload one filled reporting sheet per animal, or a zip of them. Other files in the zip, such as the weight log or the protocol PDFs, are kept with your data. + + )}