Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([issue-3264]): show the track generator toggle before the track is saved
[._.]/ Adam Eivyd80ae7b00f46
diff --git a/client/src/components/music/TracksManager.jsx b/client/src/components/music/TracksManager.jsxindex 3b797e4120..c56b55a8c0 100644--- a/client/src/components/music/TracksManager.jsx+++ b/client/src/components/music/TracksManager.jsx@@ -140,6 +140,13 @@ export default function TracksManager() {// for every selection change (incl. idle / not-found) so a modal/remix left// open can't drive the previous track (see Authors.jsx for the base pattern).const hydratedRef = useRef(null);+ // Set by `handleSave` to the id it just created. The create flow navigates+ // /music/tracks/new → /music/tracks/<id>, which re-runs this effect; without+ // the marker the derivation below would snap a "Chiptune score" chosen BEFORE+ // saving back to "Audio model" the moment the track came into existence+ // (#3264). Consumed once — a later re-selection of the same track hydrates+ // from `chiptuneScore` normally.+ const justCreatedIdRef = useRef(null);const selectionKey = id ?? null;useEffect(() => {if (loading) return;@@ -147,9 +154,19 @@ export default function TracksManager() {hydratedRef.current = selectionKey;selectedIdRef.current = selectionKey;resetTrackViewState();- if (isCreate) setForm(emptyForm());- else if (selected) setForm(formFromTrack(selected));- setGenMode(selected?.chiptuneScore ? 'chiptune' : 'audio');+ if (isCreate) {+ setForm(emptyForm());+ // Deliberately no `setGenMode` here. A new track has no score to derive+ // from, so the derivation could only ever force 'audio' — and the create+ // editor renders while `listTracks` is still in flight, so it would also+ // clobber a mode the user picked during that window.+ } else if (selected) {+ setForm(formFromTrack(selected));+ // Skip the derivation exactly once for the track `handleSave` just made,+ // so the pre-save choice survives the create → navigate hydration.+ if (justCreatedIdRef.current === selectionKey) justCreatedIdRef.current = null;+ else setGenMode(selected.chiptuneScore ? 'chiptune' : 'audio');+ }}, [selectionKey, isCreate, selected, loading]);const upsertLocal = (track) => {@@ -171,6 +188,9 @@ export default function TracksManager() {// Point the async-handler ref at the new id immediately (the hydration// effect also sets it, but not until after navigation re-renders).selectedIdRef.current = created.id;+ // Carry the pre-save generator choice through the create → navigate+ // hydration instead of re-deriving it from the (score-less) new track.+ justCreatedIdRef.current = created.id;navigate(`/music/tracks/${encodeURIComponent(created.id)}`);toast.success(`Created "${created.title}"`);} else {@@ -425,55 +445,66 @@ export default function TracksManager() {/></Field>- {/* Generation — available once the track is saved (the server- attaches the audio + metadata to the persisted track). Two- modes: the on-device audio models (MusicGen/AudioLDM2/ACE-Step)- and the LLM-composed looping chiptune score (#2911). */}- {persisted ? (- <div className="space-y-2">- <div className="inline-flex rounded-lg border border-port-border overflow-hidden text-sm" role="group" aria-label="Generation mode">- {[['audio', 'Audio model'], ['chiptune', 'Chiptune score']].map(([mode, label]) => (- <button- key={mode}- type="button"- onClick={() => setGenMode(mode)}- className={`px-3 py-1.5 ${genMode === mode ? 'bg-port-accent/20 text-white' : 'bg-port-bg text-gray-400 hover:text-white'}`}- >- {label}- </button>- ))}- </div>- {genMode === 'chiptune' ? (- <ChiptunePanel- track={persisted}- remix={chiptuneRemix}- onTrackUpdate={(updated) => {- upsertLocal(updated); // list update is id-keyed → always safe- if (selectedIdRef.current === updated.id) {- setForm((f) => ({ ...f, audioFilename: updated.audioFilename || f.audioFilename }));- }- }}- />- ) : (- <MusicGenPanel- track={persisted}- prompt={form.prompt}- lyrics={form.lyrics}- remix={remix}- onGenerated={(updated) => {- upsertLocal(updated); // list update is id-keyed → always safe- // Merge ONLY the server-set generation fields into the open- // form (the active audio pointer mirrors onto the form) so any- // UNSAVED edits the user made to title/artist/album/prompt/- // lyrics before clicking Generate survive.- if (selectedIdRef.current === updated.id) {- setForm((f) => ({ ...f, audioFilename: updated.audioFilename || '' }));- }- }}- />- )}+ {/* Generation — two modes: the on-device audio models+ (MusicGen/AudioLDM2/ACE-Step) and the LLM-composed looping+ chiptune score (#2911).++ The mode TOGGLE renders even before the track is saved: mode+ is pure local state and needs no track id, and hiding it left+ a brand-new track showing no sign either generator existed+ (#3264). The PANELS stay gated on `persisted` — the server+ attaches audio + gen metadata to a saved id — but the gate now+ explains itself instead of rendering an empty region. */}+ <div className="space-y-2">+ <div className="inline-flex rounded-lg border border-port-border overflow-hidden text-sm" role="group" aria-label="Generation mode">+ {[['audio', 'Audio model'], ['chiptune', 'Chiptune score']].map(([mode, label]) => (+ <button+ key={mode}+ type="button"+ onClick={() => setGenMode(mode)}+ aria-pressed={genMode === mode}+ className={`px-3 py-1.5 ${genMode === mode ? 'bg-port-accent/20 text-white' : 'bg-port-bg text-gray-400 hover:text-white'}`}+ >+ {label}+ </button>+ ))}</div>- ) : null}+ {!persisted ? (+ <p className="text-xs text-gray-500">+ {genMode === 'chiptune'+ ? 'Save the track first, then generate a chiptune score.'+ : 'Save the track first, then generate with an audio model.'}+ </p>+ ) : genMode === 'chiptune' ? (+ <ChiptunePanel+ track={persisted}+ remix={chiptuneRemix}+ onTrackUpdate={(updated) => {+ upsertLocal(updated); // list update is id-keyed → always safe+ if (selectedIdRef.current === updated.id) {+ setForm((f) => ({ ...f, audioFilename: updated.audioFilename || f.audioFilename }));+ }+ }}+ />+ ) : (+ <MusicGenPanel+ track={persisted}+ prompt={form.prompt}+ lyrics={form.lyrics}+ remix={remix}+ onGenerated={(updated) => {+ upsertLocal(updated); // list update is id-keyed → always safe+ // Merge ONLY the server-set generation fields into the open+ // form (the active audio pointer mirrors onto the form) so any+ // UNSAVED edits the user made to title/artist/album/prompt/+ // lyrics before clicking Generate survive.+ if (selectedIdRef.current === updated.id) {+ setForm((f) => ({ ...f, audioFilename: updated.audioFilename || '' }));+ }+ }}+ />+ )}+ </div>{/* Render history — every generated/uploaded take as a card. Theactive take is highlighted; each card opens a detail/remix modal,diff --git a/client/src/components/music/TracksManager.test.jsx b/client/src/components/music/TracksManager.test.jsxindex 65b08ec968..78a6c0d14b 100644--- a/client/src/components/music/TracksManager.test.jsx+++ b/client/src/components/music/TracksManager.test.jsx@@ -1,4 +1,4 @@-import { render, screen, cleanup } from '@testing-library/react';+import { render, screen, cleanup, fireEvent } from '@testing-library/react';import { MemoryRouter, Routes, Route } from 'react-router-dom';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';@@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';// (#2477 follow-up), not the editor/generation internals.vi.mock('./ArtistPicker', () => ({ default: () => <div data-testid="artist-picker" /> }));vi.mock('./MusicGenPanel', () => ({ default: () => <div data-testid="gen-panel" /> }));+vi.mock('./ChiptunePanel', () => ({ default: () => <div data-testid="chiptune-panel" /> }));vi.mock('./TrackRenderCard', () => ({ default: () => <div data-testid="render-card" /> }));vi.mock('./TrackRenderModal', () => ({ default: () => null }));vi.mock('../songs/MidiVisualization.jsx', () => ({@@ -30,7 +31,7 @@ vi.mock('../../services/api', () => ({vi.mock('../../services/apiMusicVideo.js', () => ({ listMusicVideoProjects: vi.fn() }));import TracksManager from './TracksManager.jsx';-import { listTracks, listAlbums } from '../../services/api';+import { listTracks, listAlbums, createTrack } from '../../services/api';import { listMusicVideoProjects } from '../../services/apiMusicVideo.js';const TRACK = { id: 'track-1', title: 'Example Song', audioFilename: 'example.mp3', renders: [] };@@ -78,3 +79,85 @@ describe('<TracksManager> MIDI transcription read-through', () => {expect(screen.queryByText('MIDI transcription')).toBeNull();});});++// #3264: the generator toggle used to live INSIDE the `persisted ?` gate, so a+// brand-new track rendered nothing at all where the generators belong and there+// was no way to learn the two modes existed until after the first save.+describe('<TracksManager> generator mode toggle', () => {+ beforeEach(() => {+ listTracks.mockResolvedValue([TRACK]);+ listAlbums.mockResolvedValue([]);+ listMusicVideoProjects.mockResolvedValue([]);+ });+ afterEach(() => {+ cleanup();+ vi.clearAllMocks();+ });++ const modeButton = (name) => screen.getByRole('button', { name });++ it('shows the toggle on an unsaved track, with a hint instead of a panel', async () => {+ renderAt('new');+ await screen.findByRole('group', { name: /generation mode/i });++ expect(modeButton('Audio model')).toBeInTheDocument();+ expect(modeButton('Chiptune score')).toBeInTheDocument();+ // Gating generation on a saved track is correct and stays — but it must+ // explain itself rather than render an empty region.+ expect(screen.getByText(/Save the track first, then generate with an audio model/i)).toBeInTheDocument();+ expect(screen.queryByTestId('gen-panel')).toBeNull();+ expect(screen.queryByTestId('chiptune-panel')).toBeNull();+ });++ it('switches mode before save and names the selected mode in the hint', async () => {+ renderAt('new');+ await screen.findByRole('group', { name: /generation mode/i });++ fireEvent.click(modeButton('Chiptune score'));++ expect(modeButton('Chiptune score')).toHaveAttribute('aria-pressed', 'true');+ expect(modeButton('Audio model')).toHaveAttribute('aria-pressed', 'false');+ expect(screen.getByText(/Save the track first, then generate a chiptune score/i)).toBeInTheDocument();+ expect(screen.queryByTestId('chiptune-panel')).toBeNull();+ });++ it('keeps a pre-save chiptune choice after Create navigates to the new track', async () => {+ const created = { id: 'track-new', title: 'Fresh Cut', renders: [] };+ createTrack.mockResolvedValue(created);++ render(+ <MemoryRouter initialEntries={['/music/tracks/new']}>+ <Routes>+ <Route path="/music/tracks/:id" element={<TracksManager />} />+ </Routes>+ </MemoryRouter>,+ );+ await screen.findByRole('group', { name: /generation mode/i });++ fireEvent.click(modeButton('Chiptune score'));+ fireEvent.change(screen.getByLabelText('Title'), { target: { value: 'Fresh Cut' } });+ fireEvent.click(screen.getByRole('button', { name: 'Create' }));++ // The hydration effect re-runs on the create → navigate transition; the+ // created track carries no `chiptuneScore`, so a naive re-derivation would+ // snap the editor back to "Audio model" the instant the track existed.+ expect(await screen.findByTestId('chiptune-panel')).toBeInTheDocument();+ expect(screen.queryByTestId('gen-panel')).toBeNull();+ expect(modeButton('Chiptune score')).toHaveAttribute('aria-pressed', 'true');+ });++ it('still opens an existing scored track on the chiptune panel', async () => {+ listTracks.mockResolvedValue([{ ...TRACK, chiptuneScore: { tempo: 120 } }]);+ renderAt('track-1');++ expect(await screen.findByTestId('chiptune-panel')).toBeInTheDocument();+ expect(screen.queryByTestId('gen-panel')).toBeNull();+ });++ it('opens an existing unscored track on the audio panel', async () => {+ renderAt('track-1');++ expect(await screen.findByTestId('gen-panel')).toBeInTheDocument();+ expect(screen.queryByTestId('chiptune-panel')).toBeNull();+ });+});