Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(skillhub): 丢弃跨账号代次的发布弹窗后续操作

xd-bobo9360a26e7982
diff --git a/apps/desktop/src/renderer/features/skillhub/PublishDialog.tsx b/apps/desktop/src/renderer/features/skillhub/PublishDialog.tsx
index b256ce431a..131a976c64 100644
--- a/apps/desktop/src/renderer/features/skillhub/PublishDialog.tsx
+++ b/apps/desktop/src/renderer/features/skillhub/PublishDialog.tsx
@@ -519,6 +519,10 @@ export function PublishDialog({
const navigate = useNavigate();
const { user } = useAuth();
const identityPolicy = useSkillhubIdentityPolicy(user);
+ // A same-membership auth realm change preserves this route, but must not
+ // preserve a dialog opened for the previous identity or its continuations.
+ const dialogOwner = useMemo(() => getDataOwnerGeneration(), [open]);
+ const isDialogOwnerCurrent = isDataOwnerGenerationCurrent(dialogOwner);
// refresh/sync 延迟到 dialog 关闭后才触发,isFirstPublish 在 dialog 生命周期内不会翻转
const effectiveFirstPublish = isFirstPublish;
@@ -530,6 +534,14 @@ export function PublishDialog({
const renamedToRef = useRef<{ absolutePath: string; name: string } | null>(null);
const activePublishNameRef = useRef<string | null>(null);
const failedProgressNameRef = useRef<string | null>(null);
+ useEffect(() => {
+ if (!open || isDialogOwnerCurrent) return;
+ activePublishNameRef.current = null;
+ failedProgressNameRef.current = null;
+ renamedToRef.current = null;
+ dispatch({ type: 'CLOSE' });
+ onOpenChange(false);
+ }, [open, isDialogOwnerCurrent, onOpenChange]);
/** 拿当前应使用的 (absolutePath, name) — rename 之后是新值,否则用 prop。 */
const effectiveSkill = useCallback(
(): { absolutePath: string; name: string } => ({
@@ -565,6 +577,7 @@ export function PublishDialog({
setCategoryState({ loading: true, categories: [], error: null });
try {
const res = await window.electronAPI.skillhub.listCategories();
+ if (!isDataOwnerGenerationCurrent(dialogOwner)) return;
if (res.success) {
setCategoryState({
loading: false,
@@ -579,13 +592,14 @@ export function PublishDialog({
error: res.error ?? 'Failed to load categories',
});
} catch (err) {
+ if (!isDataOwnerGenerationCurrent(dialogOwner)) return;
setCategoryState({
loading: false,
categories: [],
error: err instanceof Error ? err.message : String(err),
});
}
- }, []);
+ }, [dialogOwner]);
useEffect(() => {
if (!open || !effectiveFirstPublish) return;
@@ -641,6 +655,7 @@ export function PublishDialog({
useEffect(() => {
if (!open) return;
const unsubscribe = window.electronAPI.skillhub.onPublishProgress((event) => {
+ if (!isDataOwnerGenerationCurrent(dialogOwner)) return;
const activeName = activePublishNameRef.current;
if (!shouldHandlePublishProgressEvent(event, activeName)) return;
if (event.phase === 'done') {
@@ -682,7 +697,7 @@ export function PublishDialog({
dispatch({ type: 'PROGRESS', event });
});
return unsubscribe;
- }, [open, onOpenChange, onLocalRenamed, onScanResult, effectiveSkill]);
+ }, [open, onOpenChange, onLocalRenamed, onScanResult, effectiveSkill, dialogOwner]);
// ── Form validation ───────────────────────────────────────────────────────
const nameMissing = effectiveFirstPublish && form.name.length === 0;
@@ -731,10 +746,12 @@ export function PublishDialog({
);
const runPublish = useCallback((params: SkillhubPublishParams) => {
+ if (!isDataOwnerGenerationCurrent(dialogOwner)) return;
activePublishNameRef.current = params.name;
failedProgressNameRef.current = null;
void window.electronAPI.skillhub.publish(params)
.then((res) => {
+ if (!isDataOwnerGenerationCurrent(dialogOwner)) return;
if (res.success) {
if (activePublishNameRef.current !== params.name) return;
if (res.result) {
@@ -749,17 +766,18 @@ export function PublishDialog({
});
})
.catch((err) => {
+ if (!isDataOwnerGenerationCurrent(dialogOwner)) return;
if (!shouldDispatchPublishResultFallback(params.name, activePublishNameRef.current, failedProgressNameRef.current)) return;
dispatch({
type: 'PROGRESS',
event: buildPublishFailureEvent(params.name, 'INTERNAL', err),
});
});
- }, []);
+ }, [dialogOwner]);
// ── Submit ────────────────────────────────────────────────────────────────
const handleSubmit = useCallback(async () => {
- if (!canSubmit) return;
+ if (!canSubmit || !isDataOwnerGenerationCurrent(dialogOwner)) return;
const eff = effectiveSkill();
const submitName = effectiveFirstPublish
@@ -776,7 +794,7 @@ export function PublishDialog({
confirmText: t('skillhub.publishDialog.confirmPublish'),
cancelText: t('skillhub.publishDialog.confirmReconsider'),
});
- if (!ok) return;
+ if (!ok || !isDataOwnerGenerationCurrent(dialogOwner)) return;
// ── autoCleanName(撞名后改名)流程:先在本地改名,再走 publish ──────────
// 不改名(autoCleanName=false 或新旧名一致)时跳过这一步。
@@ -791,6 +809,7 @@ export function PublishDialog({
absolutePath: skill.discoveredPath ?? eff.absolutePath,
newName: submitName,
});
+ if (!isDataOwnerGenerationCurrent(dialogOwner)) return;
if (!renameRes.success) {
toast.error(t('skillhub.publishDialog.renameFailed', { error: renameRes.error }));
return;
@@ -820,10 +839,12 @@ export function PublishDialog({
buildCurrentPublishParams,
runPublish,
skill.discoveredPath,
+ dialogOwner,
]);
// ── Cancel publish in progress (working / failure 都可调) ────────────────
const handleCancelWorking = useCallback(async () => {
+ if (!isDataOwnerGenerationCurrent(dialogOwner)) return;
if (pubState.phase === 'scanning') {
activePublishNameRef.current = null;
failedProgressNameRef.current = null;
@@ -838,14 +859,14 @@ export function PublishDialog({
confirmText: t('skillhub.publishDialog.cancelDialog.confirm'),
cancelText: t('skillhub.publishDialog.cancelDialog.cancel'),
});
- if (!ok) return;
+ if (!ok || !isDataOwnerGenerationCurrent(dialogOwner)) return;
void window.electronAPI.skillhub.cancelPublish();
activePublishNameRef.current = null;
failedProgressNameRef.current = null;
dispatch({ type: 'CLOSE' });
notifyRenameAndReset();
onOpenChange(false);
- }, [pubState.phase, onOpenChange, confirm, notifyRenameAndReset, t]);
+ }, [pubState.phase, onOpenChange, confirm, notifyRenameAndReset, t, dialogOwner]);
// ── 关闭整个 dialog (X / Esc / backdrop) ────────────────────────────────
const handleClose = useCallback(() => {
@@ -950,7 +971,7 @@ export function PublishDialog({
<>
{/* ── Main PublishDialog (Empty / Working / Failure 共用) ───────────── */}
<Dialog.Root
- open={open}
+ open={open && isDialogOwnerCurrent}
onOpenChange={(v) => {
if (!v) handleClose();
}}
diff --git a/apps/desktop/src/renderer/features/skillhub/__tests__/PublishDialog.feedback.test.tsx b/apps/desktop/src/renderer/features/skillhub/__tests__/PublishDialog.feedback.test.tsx
index ad7b6dedf7..ba26949ac6 100644
--- a/apps/desktop/src/renderer/features/skillhub/__tests__/PublishDialog.feedback.test.tsx
+++ b/apps/desktop/src/renderer/features/skillhub/__tests__/PublishDialog.feedback.test.tsx
@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { setDataOwnerGeneration } from '@/contexts/dataOwnerGeneration';
const mocks = vi.hoisted(() => ({
- confirm: vi.fn(), refresh: vi.fn(), sync: vi.fn(), publish: vi.fn(),
+ confirm: vi.fn(), refresh: vi.fn(), sync: vi.fn(), publish: vi.fn(), cancelPublish: vi.fn(),
}));
vi.mock('react-i18next', async (importOriginal) => ({
...await importOriginal<typeof import('react-i18next')>(),
@@ -19,7 +19,7 @@ vi.mock('../hooks/useSkillSync', () => ({ triggerIncrementalSync: mocks.sync }))
vi.mock('../hooks/useSkillFolderHash', () => ({ invalidateHash: vi.fn() }));
vi.mock('../components/PlatformTagSelector', () => ({ PlatformTagSelector: () => null }));
-import { PublishDialog } from '../PublishDialog';
+import { PublishDialog, type PublishDialogProps } from '../PublishDialog';
let progress!: (event: SkillhubPublishProgressEvent) => void;
const feedback: SkillhubPublishProgressEvent = {
@@ -36,24 +36,32 @@ beforeEach(() => {
mocks.publish.mockResolvedValue({ success: true, result: { name: 'review-helper', version: '1.0.1' } });
vi.stubGlobal('electronAPI', { skillhub: {
publish: mocks.publish,
+ cancelPublish: mocks.cancelPublish,
onPublishProgress: (listener: typeof progress) => { progress = listener; return () => {}; },
} });
});
afterEach(() => { cleanup(); vi.unstubAllGlobals(); });
-async function startPublication() {
+function mountPublication() {
const onScanResult = vi.fn();
const onOpenChange = vi.fn();
- render(<PublishDialog open onOpenChange={onOpenChange} onScanResult={onScanResult}
- isFirstPublish={false} latestVersion="1.0.0" skill={{
+ const props: PublishDialogProps = {
+ open: true, onOpenChange, onScanResult, isFirstPublish: false, latestVersion: '1.0.0', skill: {
id: 'review-helper', urlKey: 'review-helper', engine: 'claude-code', linkedEngines: [],
kind: 'skill', scope: 'global', mdPath: '/fixture/review-helper/SKILL.md', files: [], registryEntry: null,
name: 'review-helper', absolutePath: '/fixture/review-helper', frontmatter: { version: '1.0.1' },
- }} />);
+ },
+ };
+ const view = render(<PublishDialog {...props} />);
fireEvent.change(screen.getByPlaceholderText('skillhub.publishDialog.changelogPlaceholder'), { target: { value: 'Improve documentation' } });
+ return { onScanResult, onOpenChange, rerender: (open = true) => view.rerender(<PublishDialog {...props} open={open} />) };
+}
+
+async function startPublication() {
+ const view = mountPublication();
fireEvent.click(screen.getByRole('button', { name: 'skillhub.publishDialog.startPublish' }));
await waitFor(() => expect(mocks.publish).toHaveBeenCalledOnce());
- return { onScanResult, onOpenChange };
+ return view;
}
describe('PublishDialog result delivery', () => {
@@ -89,4 +97,72 @@ describe('PublishDialog result delivery', () => {
expect(mocks.refresh).not.toHaveBeenCalled();
expect(onScanResult).not.toHaveBeenCalled();
});
+
+ it.each(['same-membership-new-realm', 'different-owner'] as const)(
+ 'closes a scanning dialog on %s without waiting for another poll event', async (transition) => {
+ const view = await startPublication();
+ expect(screen.getByText('skillhub.publishDialog.phaseScanningWait')).toBeTruthy();
+ setDataOwnerGeneration(transition === 'different-owner' ? 'owner-b' : 'owner-a', 2);
+ view.rerender();
+ expect(screen.queryByRole('dialog')).toBeNull();
+ expect(view.onOpenChange).toHaveBeenCalledWith(false);
+ expect(view.onScanResult).not.toHaveBeenCalled();
+ },
+ );
+
+ it.each(['success', 'failure', 'exception'] as const)(
+ 'ignores the old publication %s after the same membership opens a dialog in a new realm', async (outcome) => {
+ let settle!: (value: unknown) => void;
+ let reject!: (error: Error) => void;
+ mocks.publish
+ .mockReturnValueOnce(new Promise((resolve, rejectPromise) => { settle = resolve; reject = rejectPromise; }))
+ .mockReturnValueOnce(new Promise(() => {}));
+ const view = await startPublication();
+ expect(screen.getByText('skillhub.publishDialog.phasePacking')).toBeTruthy();
+ setDataOwnerGeneration('owner-a', 2);
+ view.rerender();
+ expect(screen.queryByRole('dialog')).toBeNull();
+ expect(view.onOpenChange).toHaveBeenCalledWith(false);
+ view.rerender(false);
+ view.rerender(true);
+ fireEvent.change(screen.getByPlaceholderText('skillhub.publishDialog.changelogPlaceholder'), { target: { value: 'New realm publication' } });
+ fireEvent.click(screen.getByRole('button', { name: 'skillhub.publishDialog.startPublish' }));
+ await waitFor(() => expect(mocks.publish).toHaveBeenCalledTimes(2));
+ await act(async () => {
+ if (outcome === 'exception') reject(new Error('Old realm request failed'));
+ else settle(outcome === 'success'
+ ? { success: true, result: { name: 'review-helper', version: '1.0.1' } }
+ : { success: false, errorCode: 'INTERNAL', error: 'Old realm request failed' });
+ });
+ expect(screen.getByText('skillhub.publishDialog.phasePacking')).toBeTruthy();
+ expect(screen.queryByText('skillhub.publishDialog.phaseScanningWait')).toBeNull();
+ expect(view.onOpenChange).toHaveBeenCalledTimes(1);
+ expect(view.onScanResult).not.toHaveBeenCalled();
+ },
+ );
+
+ it('does not submit an old confirmation in the new realm', async () => {
+ let finishConfirm!: (confirmed: boolean) => void;
+ mocks.confirm.mockReturnValueOnce(new Promise((resolve) => { finishConfirm = resolve; }));
+ const view = mountPublication();
+ fireEvent.click(screen.getByRole('button', { name: 'skillhub.publishDialog.startPublish' }));
+ setDataOwnerGeneration('owner-a', 2);
+ view.rerender();
+ await act(async () => { finishConfirm(true); });
+ expect(mocks.publish).not.toHaveBeenCalled();
+ expect(screen.queryByRole('dialog')).toBeNull();
+ });
+
+ it('does not cancel a new-realm publication from an old cancellation confirmation', async () => {
+ mocks.publish.mockReturnValueOnce(new Promise(() => {}));
+ const view = await startPublication();
+ let finishConfirm!: (confirmed: boolean) => void;
+ mocks.confirm.mockReturnValueOnce(new Promise((resolve) => { finishConfirm = resolve; }));
+ fireEvent.click(screen.getByRole('button', { name: 'skillhub.publishDialog.cancelReview' }));
+ setDataOwnerGeneration('owner-a', 2);
+ view.rerender();
+ await act(async () => { finishConfirm(true); });
+ expect(mocks.cancelPublish).not.toHaveBeenCalled();
+ expect(screen.queryByRole('dialog')).toBeNull();
+ });
});
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 77d2d94ab4..89a773dae7 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -124,6 +124,8 @@
因此现有请求 scope 与推送 stamp 即可拒绝旧区域反馈,无需修改 wire 字段或持久账号键。
已打开的自动结果也保存 owner snapshot,在新代次的首次渲染中隐藏旧反馈;同 ID
跨区域切换不依赖按 dataOwnerId 重挂路由,普通同代次刷新仍保留当前结果。
+ 发布弹窗同样绑定打开时的账号代次;跨代次立即隐藏并关闭,旧发布 IPC 的成功、失败、
+ 异常返回和等待中的提交/取消确认均失效,不能让新区域的弹窗进入旧发布的扫描阶段。
旧接收端忽略新增元数据,旧的无标记事件沿用现有兼容读取;首次发布的同版本拒审例外
仅适用于 `rejected`,不能把处理失败 `failed` 或旧扫描失败 `blocked` 套进该例外。
人工拒审原因缺省时始终明确提示缺省,即使已有自动扫描失败项;扫描发现继续独立展示,