Порівняти коміти

...
1 Коміти
Автор SHA1 Повідомлення Дата
l0ng-ai b03ee48ad5 fix(vcs): show feedback for explicit Git commands 2026-11-10 09:54:04 +08:00
3 змінених файлів з 200 додано та 22 видалено

No files matched your search

+73
Переглянути файл
@@ -0,0 +1,73 @@
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
test("shows Update failures from the branch menu even when VCS notifications are muted", async ({
workbench: page,
}) => {
await stubDesktop(page);
await page.evaluate(async () => {
const root = "/dev/acme-api";
const branch = { head: "main", upstream: "origin/main", behind: 68, ahead: 0, operation: null, headCommit: "c1" };
const branches = [
{
name: "main",
current: true,
remote: false,
upstream: "origin/main",
behind: 68,
ahead: 0,
commit: "c1",
lastCommitMs: 0,
},
];
const h = window.__ipc.handlers;
h.vcs_branch_info = () => branch;
h.vcs_branches = () => branches;
h.vcs_roots = () => [{ root, head: "main", headCommit: "c1", operation: null }];
h.vcs_status = () => [];
h.vcs_log = () => [];
h.vcs_tags = () => [];
h.vcs_config_get = () => null;
h.vcs_merge_base = () => "c1";
h.vcs_remote = () => {
throw {
kind: "invalid",
message:
"The following untracked working tree files would be overwritten by merge: e2e/settingsFormLayout.spec.ts",
};
};
const projectModule = "/src/platform/project.ts";
const { useProject } = await import(/* @vite-ignore */ projectModule);
useProject.setState({
settings: {
...useProject.getState().settings,
notifications: { groups: { vcs: { display: "none", log: true } } },
},
});
const storeModule = "/src/features/vcs/store.ts";
const { useVcs } = await import(/* @vite-ignore */ storeModule);
useVcs.setState({
available: true,
root,
repo: root,
roots: [root],
branch,
branches,
branchesLoaded: true,
});
const contextModule = "/src/platform/context.ts";
const { setContext } = await import(/* @vite-ignore */ contextModule);
setContext("vcsAvailable", true);
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
await executeAction("vcs.showLog");
});
const branches = page.getByRole("tree", { name: "Branches" });
await branches.getByRole("treeitem", { name: /main current/ }).click({ button: "right" });
await page.getByRole("menuitem", { name: "Update", exact: true }).click();
const dialog = page.getByRole("dialog", { name: "Update Project", exact: true });
await expect(dialog).toBeVisible();
await dialog.getByRole("button", { name: "OK", exact: true }).click();
await expect(page.getByText("Update failed", { exact: true })).toBeVisible();
await expect(page.getByText(/untracked working tree files would be overwritten by merge/)).toBeVisible();
expect(await ipcCalls(page, "vcs_remote")).toHaveLength(1);
});
+109 -2
Переглянути файл
@@ -1,9 +1,11 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { BranchInfo } from "@/bindings";
import type { BranchInfo, RemoteOp } from "@/bindings";
let branch: Partial<BranchInfo> = {};
/** What a pull brings in: the head moves to `c2`, with these changed files and commits. */
let pulled = { files: 0, commits: 0 };
let failure: { kind: string; message: string } | null = null;
let remoteGate: Promise<void> | null = null;
vi.mock("@tauri-apps/api/core", async (importOriginal) => ({
...(await importOriginal<typeof import("@tauri-apps/api/core")>()),
@@ -23,9 +25,12 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
data: { head: "main", headCommit: "c1", upstream: null, ahead: 0, behind: 0, operation: null, ...branch },
}),
vcsRemote: async () => {
await remoteGate;
if (failure) return { status: "error", error: failure };
if (pulled.commits) branch = { ...branch, headCommit: "c2" };
return { status: "ok", data: null };
},
vcsOperation: async () => (failure ? { status: "error", error: failure } : { status: "ok", data: null }),
vcsDiffRevisions: async () => ({ status: "ok", data: Array.from({ length: pulled.files }, (_, i) => ({ i })) }),
vcsLog: async () => ({ status: "ok", data: Array.from({ length: pulled.commits }, (_, i) => ({ i })) }),
cancelRequest: async () => ({ status: "ok", data: null }),
@@ -35,7 +40,10 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
import { _resetI18nForTests, setLocale, txTemplate } from "@/platform/i18n";
import { provideNotificationService } from "@/workbench/contributions";
import { runRemote } from "../ops";
import { useProject } from "@/platform/project";
import { expireNotification, notify, useNotifications } from "@/workbench/notificationStore";
import { runGitOperation, runOp, runRemote } from "../ops";
import { useVcs } from "../store";
type Note = { title: string; level: string };
let notes: Note[] = [];
@@ -48,6 +56,11 @@ beforeEach(() => {
afterEach(() => {
branch = {};
pulled = { files: 0, commits: 0 };
failure = null;
remoteGate = null;
useVcs.setState({ remoteBusy: null });
useNotifications.setState({ items: [] });
useProject.setState({ settings: null });
_resetI18nForTests();
});
@@ -105,3 +118,97 @@ describe("Update Project result notification", () => {
expect(txTemplate(await updateTitle())).toBe("已在 2 个提交中更新 3 个文件");
});
});
describe.each([
["VCS popups disabled", { groups: { vcs: { display: "none", log: true } } }],
["all balloons disabled", { balloons: false }],
["VCS popups and logging disabled", { groups: { vcs: { display: "none", log: false } } }],
])("Git command feedback with %s", (_name, prefs) => {
beforeEach(() => {
useProject.setState({ settings: { notifications: prefs } as never });
provideNotificationService({ notify, expire: expireNotification });
});
it("shows the untracked-file error that prevented Update", async () => {
failure = {
kind: "invalid",
message:
"The following untracked working tree files would be overwritten by merge: e2e/settingsFormLayout.spec.ts",
};
expect(await runRemote({ op: "pull", rebase: false }, undefined, ["/p"])).toBe(false);
expect(useNotifications.getState().items.find((n) => n.title === "Update failed")).toMatchObject({
balloon: true,
body: failure.message,
});
});
it.each<[RemoteOp, string]>([
[{ op: "fetch" }, "Fetch successful"],
[{ op: "push", force_with_lease: false, set_upstream: false, tags: null, no_verify: false }, "Push successful"],
[{ op: "pull", rebase: false }, "All files are up-to-date"],
])("shows progress and the result of $op", async (op, title) => {
let finish!: () => void;
remoteGate = new Promise((resolve) => (finish = resolve));
const running = runRemote(op, undefined, ["/p"]);
try {
expect(useNotifications.getState().items.find((n) => n.key === "vcs.remote")).toMatchObject({
balloon: true,
sticky: true,
});
} finally {
finish();
}
expect(await running).toBe(true);
expect(useNotifications.getState().items.find((n) => n.title === title)?.balloon).toBe(true);
});
it("shows the files and commits that Update brought in", async () => {
pulled = { files: 3, commits: 2 };
expect(await runRemote({ op: "pull", rebase: false }, undefined, ["/p"])).toBe(true);
expect(useNotifications.getState().items.find((n) => n.title === "3 files updated in 2 commits")?.balloon).toBe(
true,
);
});
it("explains why another remote operation cannot start", async () => {
useVcs.setState({ remoteBusy: "Fetching" });
expect(await runRemote({ op: "fetch" })).toBe(false);
expect(useNotifications.getState().items[0]).toMatchObject({
title: "Another remote operation is in progress",
balloon: true,
});
});
it("keeps cancelled and caller-handled failures quiet", async () => {
failure = { kind: "cancelled", message: "cancelled" };
expect(await runRemote({ op: "fetch" })).toBe(false);
expect(useNotifications.getState().items.some((n) => n.balloon)).toBe(false);
failure = { kind: "invalid", message: "rejected" };
expect(await runRemote({ op: "fetch" }, undefined, ["/p"], () => true)).toBe(false);
expect(useNotifications.getState().items.some((n) => n.balloon)).toBe(false);
});
it("shows local command failures but respects quiet callers", async () => {
const fail = () => Promise.reject(new Error("index locked"));
await runOp("Commit", fail);
expect(useNotifications.getState().items[0]).toMatchObject({ title: "Commit failed", balloon: true });
useNotifications.setState({ items: [] });
await runOp("Commit", fail, { quiet: true });
expect(useNotifications.getState().items).toEqual([]);
});
it("shows long local operation results", async () => {
const op = { op: "cherryPick", commits: ["c1"] } as const;
const options = { progress: "Cherry-picking", success: "Cherry-picked c1", failure: "Cherry-pick failed" };
expect(await runGitOperation({ ...op, commits: [...op.commits] }, options)).toBe(true);
expect(useNotifications.getState().items[0]).toMatchObject({ title: options.success, balloon: true });
failure = { kind: "invalid", message: "invalid revision" };
expect(await runGitOperation({ ...op, commits: [...op.commits] }, options)).toBe(false);
expect(useNotifications.getState().items[0]).toMatchObject({ title: options.failure, balloon: true });
});
it("still suppresses unsolicited VCS notifications", () => {
notify({ group: "vcs", level: "info", title: "Background refresh" });
expect(useNotifications.getState().items.some((n) => n.balloon)).toBe(false);
});
});
+18 -20
Переглянути файл
@@ -9,7 +9,7 @@ import { executeAction } from "@/platform/actions";
import { tx } from "@/platform/i18n";
import { call, commands, isCancelled, nextRequestId } from "@/platform/ipc";
import { attachDocument, editorsFor } from "@/editor/api";
import { maybeEditorService, notifications } from "@/workbench/contributions";
import { maybeEditorService, notifications, type NotificationService } from "@/workbench/contributions";
import { cancelTask, upsertTaskSoon, useTasks } from "@/workbench/tasks";
import { progressFraction } from "./model";
import { beginGitWork, conflictedFiles, currentRepo, refreshNow, repoName, useVcs } from "./store";
@@ -55,6 +55,11 @@ export function errorMessage(e: unknown): string {
return e instanceof Error ? e.message : String(e);
}
/** Feedback for an explicit Git command stays visible when background VCS notifications are muted. */
function notify(n: Omit<Parameters<NotificationService["notify"]>[0], "group" | "userInitiated">) {
notifications().notify({ ...n, group: "vcs", userInitiated: true });
}
// ---------------------------------------------------------------------------
// Local operations
@@ -80,7 +85,7 @@ export async function runOp<T>(title: string, fn: () => Promise<T>, opts: OpOpti
const msg = typeof opts.success === "function" ? opts.success(value) : opts.success;
if (msg) {
logConsole("info", msg);
notifications().notify({ group: "vcs", level: "info", title: msg });
notify({ level: "info", title: msg });
}
return value;
} catch (e) {
@@ -88,8 +93,7 @@ export async function runOp<T>(title: string, fn: () => Promise<T>, opts: OpOpti
logConsole("err", message);
const handled = opts.onError ? await opts.onError(message) : false;
if (!opts.quiet && !handled)
notifications().notify({
group: "vcs",
notify({
level: "error",
title: tx`${title} failed`,
body: message,
@@ -160,7 +164,7 @@ export async function runRemote(
handled?: (message: string) => boolean,
): Promise<boolean> {
if (useVcs.getState().remoteBusy) {
notifications().notify({ group: "vcs", level: "warning", title: "Another remote operation is in progress" });
notify({ level: "warning", title: "Another remote operation is in progress" });
return false;
}
const [progressText, doneTitle] = REMOTE_TITLE[op.op];
@@ -173,8 +177,7 @@ export async function runRemote(
const task = (message: string | null, fraction: number | null, done: boolean) =>
upsertTaskSoon({ id: taskId, title: progressTitle, message, fraction, done, cancel });
task(detail ?? null, null, false);
notifications().notify({
group: "vcs",
notify({
level: "info",
key: "vcs.remote",
title: `${progressTitle}…`,
@@ -231,8 +234,7 @@ export async function runRemote(
else {
// One repository's push names what went out; a partial multi-repo push stays generic.
const one = pushed.length === 1 ? pushed[0] : null;
notifications().notify({
group: "vcs",
notify({
level: "info",
key: "vcs.remote",
title:
@@ -256,8 +258,7 @@ export async function runRemote(
notifications().expire?.("vcs.remote");
void executeAction("vcs.resolveConflicts");
} else
notifications().notify({
group: "vcs",
notify({
level: "error",
key: "vcs.remote",
title: `${doneTitle} failed`,
@@ -319,7 +320,7 @@ const pushedTitle = (n: number, to: string) =>
/** IDEA's Update Project result: "N files updated in M commits" with View Commits. */
async function notifyUpdated(updated: readonly UpdatedRange[]) {
if (!updated.length) {
notifications().notify({ group: "vcs", level: "info", key: "vcs.remote", title: "All files are up-to-date" });
notify({ level: "info", key: "vcs.remote", title: "All files are up-to-date" });
return;
}
let files = 0;
@@ -344,8 +345,7 @@ async function notifyUpdated(updated: readonly UpdatedRange[]) {
commits += log.length;
}),
);
notifications().notify({
group: "vcs",
notify({
level: "info",
key: "vcs.remote",
title: `${filesText(files)} updated in ${commitsText(commits)}`,
@@ -389,7 +389,7 @@ export async function runGitOperation(
repo = currentRepo(),
): Promise<boolean> {
if (useVcs.getState().remoteBusy) {
notifications().notify({ group: "vcs", level: "warning", title: "Another Git operation is in progress" });
notify({ level: "warning", title: "Another Git operation is in progress" });
return false;
}
await saveAll();
@@ -402,8 +402,7 @@ export async function runGitOperation(
const task = (message: string | null, done: boolean) =>
upsertTaskSoon({ id: taskId, title: progress, message, fraction: done ? 1 : null, done, cancel });
task(null, false);
notifications().notify({
group: "vcs",
notify({
level: "info",
key: "vcs.operation",
title: `${progress}…`,
@@ -425,7 +424,7 @@ export async function runGitOperation(
}
logConsole("info", success);
const actions = opts.successActions ? await opts.successActions() : undefined;
notifications().notify({ group: "vcs", level: "info", key: "vcs.operation", title: success, actions });
notify({ level: "info", key: "vcs.operation", title: success, actions });
return true;
} catch (e) {
const cancelled = isCancelled(e);
@@ -435,8 +434,7 @@ export async function runGitOperation(
await refreshNow();
const handled = cancelled || (opts.onError ? await opts.onError(message) : false);
if (!handled)
notifications().notify({
group: "vcs",
notify({
level: "error",
key: "vcs.operation",
title: opts.failure,