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: isolate music-video posting drafts when switching projects
[._.]/ Adam Eivy161fc7a42086
diff --git a/client/src/components/musicVideo/PublishPostingPanel.jsx b/client/src/components/musicVideo/PublishPostingPanel.jsxindex 650229b5ba..6aa984e8f4 100644--- a/client/src/components/musicVideo/PublishPostingPanel.jsx+++ b/client/src/components/musicVideo/PublishPostingPanel.jsx@@ -202,7 +202,7 @@ export default function PublishPostingPanel({ project, publishing }) {<p className="text-port-text-muted">Sign in to each platform in the PortOS Browser first. Fill draft opens a new tab there and fills the post from the kit and copy above; nothing is posted until you review it and press Post.</p>{!targets.length && <p className="text-port-text-muted">Turn on the platforms you use under Where you post to fill and post drafts here.</p>}<ul className="space-y-2">- {targets.map((entry) => <TargetRow key={entry.target} project={project} kit={kit} entry={entry} publishing={publishing} />)}+ {targets.map((entry) => <TargetRow key={`${project.id}-${entry.target}`} project={project} kit={kit} entry={entry} publishing={publishing} />)}</ul></section>);diff --git a/client/src/hooks/useMusicVideoPublishing.js b/client/src/hooks/useMusicVideoPublishing.jsindex 5f16fbccc0..81cde1496b 100644--- a/client/src/hooks/useMusicVideoPublishing.js+++ b/client/src/hooks/useMusicVideoPublishing.js@@ -1,4 +1,4 @@-import { useCallback, useEffect, useState } from 'react';+import { useCallback, useEffect, useRef, useState } from 'react';import toast from '../components/ui/Toast';import {prepareMusicVideoPublishDraft,@@ -9,6 +9,8 @@ import {recordMusicVideoPublishPost,} from '../services/apiMusicVideo.js';+const EMPTY_POSTING = { drafts: {}, busy: {}, errors: {} };+/*** Music Video posting (#9282). Each platform is two explicit steps: `prepare`* fills the post in the PortOS Browser and returns what it filled (a summary@@ -23,9 +25,13 @@ import {*/export default function useMusicVideoPublishing({ project, replaceProject } = {}) {const projectId = project?.id || null;- const [drafts, setDrafts] = useState({});- const [busy, setBusy] = useState({});- const [errors, setErrors] = useState({});+ // A selection lifetime, rather than just the id, also rejects an old reply+ // after switching A → B → A. Hide the previous state in the first render.+ const selection = useRef({ projectId });+ if (selection.current.projectId !== projectId) selection.current = { projectId };+ const scope = selection.current;+ const [posting, setPosting] = useState({ ...EMPTY_POSTING, scope });+ const { drafts, busy, errors } = posting.scope === scope ? posting : EMPTY_POSTING;const [platforms, setPlatforms] = useState(null);const [history, setHistory] = useState({});@@ -34,50 +40,52 @@ export default function useMusicVideoPublishing({ project, replaceProject } = {}.catch(() => setPlatforms((prev) => prev || {})), []);useEffect(() => { loadPlatforms(); }, [loadPlatforms]);- const setFor = (setter, target, value) => setter((prev) => {- const next = { ...prev };+ const setFor = (field, target, value) => setPosting((prev) => {+ if (selection.current !== scope) return prev;+ const state = prev.scope === scope ? prev : { ...EMPTY_POSTING, scope };+ const next = { ...state[field] };if (value == null) delete next[target];else next[target] = value;- return next;+ return { ...state, [field]: next };});const fail = (target, err) => {- setFor(setErrors, target, { message: err?.message || 'Failed', code: err?.code || null, url: err?.context?.url || null });+ setFor('errors', target, { message: err?.message || 'Failed', code: err?.code || null, url: err?.context?.url || null });};const prepare = (target, options = {}) => {- setFor(setBusy, target, 'prepare');- setFor(setErrors, target, null);+ setFor('busy', target, 'prepare');+ setFor('errors', target, null);return prepareMusicVideoPublishDraft(projectId, target, options, { silent: true })- .then((draft) => { setFor(setDrafts, target, draft); return draft; })- .catch((err) => { setFor(setDrafts, target, null); fail(target, err); return null; })- .finally(() => setFor(setBusy, target, null));+ .then((draft) => { setFor('drafts', target, draft); return draft; })+ .catch((err) => { setFor('drafts', target, null); fail(target, err); return null; })+ .finally(() => setFor('busy', target, null));};const submit = (target) => {const draft = drafts[target];if (!draft) return Promise.resolve(null);- setFor(setBusy, target, 'submit');- setFor(setErrors, target, null);+ setFor('busy', target, 'submit');+ setFor('errors', target, null);return submitMusicVideoPublishDraft(projectId, draft.draftId, { silent: true }).then((res) => {if (res?.project) replaceProject?.(res.project);loadPlatforms();- setFor(setDrafts, target, null);+ setFor('drafts', target, null);toast.success('Posted');return res?.post || null;}).catch((err) => {// A gone draft can't be posted again; the director fills it afresh.- if (err?.code === 'PUBLISH_DRAFT_MISSING') setFor(setDrafts, target, null);+ if (err?.code === 'PUBLISH_DRAFT_MISSING') setFor('drafts', target, null);fail(target, err);return null;})- .finally(() => setFor(setBusy, target, null));+ .finally(() => setFor('busy', target, null));};const discard = (target) => {const draft = drafts[target];- setFor(setDrafts, target, null);+ setFor('drafts', target, null);if (draft) discardMusicVideoPublishDraft(projectId, draft.draftId, { silent: true }).catch(() => {});};diff --git a/client/src/hooks/useMusicVideoPublishing.test.jsx b/client/src/hooks/useMusicVideoPublishing.test.jsxnew file mode 100644index 0000000000..c820b9f735--- /dev/null+++ b/client/src/hooks/useMusicVideoPublishing.test.jsx@@ -0,0 +1,86 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { act, fireEvent, render, screen, within } from '@testing-library/react';+import useMusicVideoPublishing from './useMusicVideoPublishing.js';+import PublishPostingPanel from '../components/musicVideo/PublishPostingPanel.jsx';++const api = vi.hoisted(() => ({+ prepareMusicVideoPublishDraft: vi.fn(),+ submitMusicVideoPublishDraft: vi.fn(),+ discardMusicVideoPublishDraft: vi.fn(async () => true),+ getMusicVideoPublishPlatforms: vi.fn(async () => ({ platforms: { youtube: { enabled: true }, reddit: { enabled: true } } })),+ updateMusicVideoPublishPlatforms: vi.fn(),+ recordMusicVideoPublishPost: vi.fn(),+}));+vi.mock('../services/apiMusicVideo.js', () => api);+vi.mock('../components/ui/Toast', () => ({ default: { success: vi.fn(), error: vi.fn() } }));++const project = (id) => ({ id, publishKit: { builtAt: '2026-01-01T00:00:00.000Z' } });+const row = (label) => screen.getByText(label, { selector: 'div' }).closest('li');+const deferred = () => {+ let resolve;+ let reject;+ const promise = new Promise((res, rej) => { resolve = res; reject = rej; });+ return { promise, resolve, reject };+};+function Posting({ id }) {+ const selected = project(id);+ const publishing = useMusicVideoPublishing({ project: selected, replaceProject: vi.fn() });+ return <PublishPostingPanel project={selected} publishing={publishing} />;+}++beforeEach(() => {+ vi.clearAllMocks();+ api.prepareMusicVideoPublishDraft.mockReset();+ api.submitMusicVideoPublishDraft.mockReset();+});++describe('music-video publishing project boundary', () => {+ it('drops the previous project preview and posting options immediately on selection', async () => {+ api.prepareMusicVideoPublishDraft.mockResolvedValue({ draftId: 'draft-a', summary: { title: 'Example A' } });+ const view = render(<Posting id="project-a" />);+ await screen.findByText('YouTube', { selector: 'div' });+ fireEvent.change(within(row('Reddit')).getByLabelText('Subreddit'), { target: { value: 'example-community' } });+ await act(async () => { fireEvent.click(within(row('YouTube')).getByRole('button', { name: 'Fill draft' })); });+ expect(screen.getByText('Example A')).toBeInTheDocument();++ view.rerender(<Posting id="project-b" />);+ expect(screen.queryByText('Example A')).not.toBeInTheDocument();+ expect(screen.queryByRole('button', { name: 'Post to YouTube' })).not.toBeInTheDocument();+ expect(within(row('Reddit')).getByLabelText('Subreddit')).toHaveValue('');+ view.rerender(<Posting id="project-a" />);+ expect(screen.queryByText('Example A')).not.toBeInTheDocument();+ expect(api.submitMusicVideoPublishDraft).not.toHaveBeenCalled();+ });++ it('ignores a late old-project preparation without clearing the current preparation', async () => {+ const first = deferred();+ const second = deferred();+ api.prepareMusicVideoPublishDraft.mockReturnValueOnce(first.promise).mockReturnValueOnce(second.promise);+ api.submitMusicVideoPublishDraft.mockResolvedValue({ post: { url: 'https://example.com/post' } });+ const view = render(<Posting id="project-a" />);+ await screen.findByText('YouTube', { selector: 'div' });+ fireEvent.click(within(row('YouTube')).getByRole('button', { name: 'Fill draft' }));+ view.rerender(<Posting id="project-b" />);+ fireEvent.click(within(row('YouTube')).getByRole('button', { name: 'Fill draft' }));+ await act(async () => { first.resolve({ draftId: 'draft-a', summary: { title: 'Example A' } }); });+ expect(screen.queryByText('Example A')).not.toBeInTheDocument();+ expect(within(row('YouTube')).getByRole('button', { name: 'Filling…' })).toBeDisabled();+ await act(async () => { second.resolve({ draftId: 'draft-b', summary: { title: 'Example B' } }); });+ expect(screen.getByText('Example B')).toBeInTheDocument();+ await act(async () => { fireEvent.click(screen.getByRole('button', { name: 'Post to YouTube' })); });+ expect(api.submitMusicVideoPublishDraft).toHaveBeenCalledWith('project-b', 'draft-b', { silent: true });+ });++ it('ignores an old-project sign-in error after switching away and back', async () => {+ const first = deferred();+ api.prepareMusicVideoPublishDraft.mockReturnValueOnce(first.promise);+ const view = render(<Posting id="project-a" />);+ await screen.findByText('YouTube', { selector: 'div' });+ fireEvent.click(within(row('YouTube')).getByRole('button', { name: 'Fill draft' }));+ view.rerender(<Posting id="project-b" />);+ view.rerender(<Posting id="project-a" />);+ await act(async () => { first.reject({ message: 'Example sign-in required', code: 'PUBLISH_LOGIN_REQUIRED' }); });+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();+ expect(within(row('YouTube')).getByRole('button', { name: 'Fill draft' })).toBeEnabled();+ });+});