Upload Bundle can send a bundle built before the latest playground edits

Aperta
#1,755 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend, testing

Direzione di ricerca

Start with UploadBundleDialog.tsx to trace how the current bundle is selected, then read Viewer.tsx to understand when files are rebuilt. Add the files-hash comparison and test it in apps/playground/src/utils/__tests__/file.test.ts; the issue also specifies an E2E test in testing/src/specs/playground.spec.ts. Done means an immediate upload after editing posts a bundle containing the latest title, with the helper test passing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Area: Playground Bug Difficulty: Low Priority: Medium

Upload Bundle can send an ODC instance a bundle built before the user's latest edits, and report success. UploadBundleDialog uploads transpilerState.bundle whenever the state is built. The Viewer rebuilds only on its polling tick, every settings.refreshInterval milliseconds (2000 by default, and user-configurable in User Settings). The built state does not record which files it was built from. So between an edit and the next tick, the state is still built from the previous files, and an upload in that window posts the old code. The dialog says nothing about this. With a longer refresh interval, the window is that long.

Where

apps/playground/src/components/Header/ActionsDropdown/UploadBundleDialog.tsx:57-92:

const handleSubmit = async () => {
  const state = transpilerStateRef.current;
  if (editorErrors.length > 0) {
    // ...
  } else if (state.status === 'building' || state.status === 'initial') {
    // ...
  }
  // ...
  const bundle = state.bundle;

apps/playground/src/components/Viewer/Viewer.tsx:64-73:

useInterval(() => {
  const currentFiles = editorFilesRef.current;
  hashFiles(currentFiles)
    .then((currentHash) => {
      if (currentHash !== filesHash) {
        void transpile(currentFiles);
      }
    })
    .catch(console.error);
}, refreshInterval);

Reproduce

  1. Log in to an instance through the actions menu, then set Refresh Interval to 30000 in User Settings.
  2. Change details.title in index.ts.
  3. Within 30 seconds, open the actions menu, choose Upload Bundle and click Upload.

Actual: the instance stores the instrument with the old title, and the playground shows a success notification.
Expected: the upload uses a bundle built from the files currently in the editor, either by building them first or by refusing with a "build in progress" message.

Tests

Store the files hash on the built state and add a pure helper that compares it with the current files. Test the helper in apps/playground/src/utils/__tests__/file.test.ts: it('should treat a bundle built from other files as stale, so an upload never sends code older than the editor').

E2E in testing/src/specs/playground.spec.ts: intercept POST **/v1/instruments with page.route, edit the title, upload straight away, and assert that the posted bundle contains the new title.

Suggested fix

Record the files hash in the built state ({ status: 'built', bundle, filesHash }). In handleSubmit, hash useAppStore.getState().files, and if it differs from filesHash, build those files and upload the result (or refuse with a message).

Lingua principale
TypeScript
Stelle
119
Fork
19
Merge medio
5g 10h
PR unite (30g)
36

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DouglasNeuroInformatics/OpenDataCapture

Tutte le issue di DouglasNeuroInformatics/OpenDataCapture

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.