mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
fix(ui): keep syncing MCP when an extras target fails
runSync threw at the first extras target with an error, after skills and agents had already synced. The Sync page then dropped their result and warnings, never wrote MCP, and showed one error without naming the extra or target. It now collects every failed extras target and carries on, matching `sync --all`; the page lists each as "<extra> → <target>: <error>".
This commit is contained in:
@@ -23,7 +23,7 @@ describe('MCP sync box', () => {
|
||||
|
||||
it('confirms every pending change, then writes only MCP with the reviewed plan', async () => {
|
||||
const user = userEvent.setup();
|
||||
vi.mocked(runSync).mockResolvedValue({ resources: undefined });
|
||||
vi.mocked(runSync).mockResolvedValue({ resources: undefined, failures: [] });
|
||||
box();
|
||||
await user.click(screen.getByRole('button', { name: 'Sync MCP' }));
|
||||
expect(screen.getByText('Also writes 1 change outside this project.')).toBeInTheDocument();
|
||||
|
||||
@@ -80,6 +80,17 @@ describe('runSync', () => {
|
||||
expect(mcpApi.configure).toHaveBeenCalledWith({}, 'after', true);
|
||||
});
|
||||
|
||||
it('reports a failed extras target and still applies MCP', async () => {
|
||||
vi.mocked(mcpApi.preview).mockResolvedValue(plan);
|
||||
vi.mocked(api.syncExtras).mockResolvedValueOnce({ extras: [{ name: 'rules', targets: [
|
||||
{ target: 'claude', mode: 'merge', synced: 0, skipped: 0, pruned: 0, error: 'permission denied' },
|
||||
{ target: 'codex', mode: 'merge', synced: 1, skipped: 0, pruned: 0 },
|
||||
] }] });
|
||||
const { failures } = await runSync(run);
|
||||
expect(failures).toEqual([{ target: 'claude', part: 'extra', extra: 'rules', error: 'permission denied' }]);
|
||||
expect(mcpApi.configure).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('stops before MCP when its changes differ after syncing resources', async () => {
|
||||
vi.mocked(mcpApi.preview).mockResolvedValueOnce(plan).mockResolvedValueOnce({ ...plan, revision: 'after', changes: [{ ...change, action: 'remove' }] });
|
||||
await expect(runSync(run)).rejects.toThrow(MCP_CHANGED);
|
||||
|
||||
@@ -166,7 +166,19 @@ export interface SyncRun {
|
||||
project?: { root: string; path: string };
|
||||
}
|
||||
|
||||
/** Writes each included part in order. MCP is checked before anything is written and again right before it applies. */
|
||||
/** A target that failed to sync; the rest of the run still went ahead. */
|
||||
export interface SyncFailure {
|
||||
target: string;
|
||||
part: 'extra';
|
||||
/** The extra's name */
|
||||
extra: string;
|
||||
error: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes each included part in order. MCP is checked before anything is written and again right before it applies.
|
||||
* A failed target does not stop the run: it is returned in `failures`, like `skillshare sync --all` reports it.
|
||||
*/
|
||||
export async function runSync(run: SyncRun) {
|
||||
const reviewed = run.mcp;
|
||||
const recheck = async () => {
|
||||
@@ -181,14 +193,19 @@ export async function runSync(run: SyncRun) {
|
||||
if (run.resources) {
|
||||
resources = await api.sync({ force: run.force, ...(run.resources !== 'both' && { kind: run.resources }), ...(run.project && { project: run.project.root }) });
|
||||
}
|
||||
const failures: SyncFailure[] = [];
|
||||
if (run.extras) {
|
||||
const extras = await api.syncExtras({ force: run.force });
|
||||
const failed = extras.extras.flatMap((e) => e.targets).find((e) => e.error || e.errors?.length);
|
||||
if (failed) throw new Error(failed.error || failed.errors?.join('; '));
|
||||
for (const e of extras.extras) {
|
||||
for (const t of e.targets) {
|
||||
const error = t.error || t.errors?.join('; ');
|
||||
if (error) failures.push({ target: t.target, part: 'extra', extra: e.name, error });
|
||||
}
|
||||
}
|
||||
}
|
||||
if (reviewed) {
|
||||
if (run.project) await mcpApi.syncProject(run.project.path, await recheck());
|
||||
else await mcpApi.configure({}, await recheck(), true);
|
||||
}
|
||||
return { resources };
|
||||
return { resources, failures };
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import PageHeader from '../components/PageHeader';
|
||||
import Spinner from '../components/Spinner';
|
||||
import { useToast } from '../components/Toast';
|
||||
import { describeMessage, mcpClient, targetLabel } from '../components/mcp/mcpView';
|
||||
import { countChanges, countEdited, extraGroups, groupByFolder, groupInSync, MCP_CHANGED, mcpGroups, resourceGroups, runSync, type ChangeGroup, type Part, type RowIcon } from '../components/sync/syncView';
|
||||
import { countChanges, countEdited, extraGroups, groupByFolder, groupInSync, MCP_CHANGED, mcpGroups, resourceGroups, runSync, type ChangeGroup, type Part, type RowIcon, type SyncFailure } from '../components/sync/syncView';
|
||||
import SkillsOffDialog from '../components/targets/SkillsOffDialog';
|
||||
import { joinList, refreshTargets } from '../components/targets/targetView';
|
||||
import { formatDateTime, formatRelativeTime, useI18n, useT } from '../i18n';
|
||||
@@ -73,6 +73,7 @@ export default function SyncPage() {
|
||||
const [running, setRunning] = useState(false);
|
||||
const [runError, setRunError] = useState('');
|
||||
const [outcome, setOutcome] = useState<SyncResponse | null>(null);
|
||||
const [failures, setFailures] = useState<SyncFailure[]>([]);
|
||||
const [stopping, setStopping] = useState('');
|
||||
|
||||
const plan = mcp.data?.plan;
|
||||
@@ -107,14 +108,16 @@ export default function SyncPage() {
|
||||
setRunning(true);
|
||||
setRunError('');
|
||||
setOutcome(null);
|
||||
setFailures([]);
|
||||
try {
|
||||
const { resources: result } = await runSync({
|
||||
const { resources: result, failures: failed } = await runSync({
|
||||
resources: parts.has('skill') && parts.has('agent') ? 'both' : parts.has('skill') ? 'skill' : parts.has('agent') ? 'agent' : null,
|
||||
extras: parts.has('extra') && !!extras.data?.extras.length,
|
||||
mcp: parts.has('mcp') && plan && !plan.blocked && plan.changes.some((c) => c.action !== 'unchanged') ? plan : null,
|
||||
force,
|
||||
});
|
||||
setOutcome(result ?? null);
|
||||
setFailures(failed);
|
||||
toast(t('sync.toast.done'), 'success');
|
||||
} catch (err) {
|
||||
const message = (err as Error).message;
|
||||
@@ -187,6 +190,7 @@ export default function SyncPage() {
|
||||
</div>
|
||||
)}
|
||||
{parts.has('mcp') && mcp.data?.previewError && <div className="ss-note bad"><AlertCircle size={16} /><span className="flex-1">{mcp.data.previewError}</span></div>}
|
||||
{failures.map((f) => <div key={`${f.extra}/${f.target}`} className="ss-note bad"><AlertCircle size={16} /><span className="flex-1">{f.extra} → {f.target}: {f.error}</span></div>)}
|
||||
{outcome?.warnings?.map((w) => <div key={w} className="ss-note warn"><TriangleAlert size={16} /><span className="flex-1">{w}</span></div>)}
|
||||
{!!outcome?.path_overlap && (
|
||||
<div className="ss-note warn !items-center">
|
||||
|
||||
Reference in New Issue
Block a user