дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Git Log and File History changed files get Create Patch and Copy as Patch to Clipboard, in the toolbar and the context menu. Only the selected repository-relative paths are exported, as path-filtered revision diffs with Git's empty tree on the missing side of additions and deletions and both names for renames. The existing patch dialog, base directory defaults, reverse option and clipboard flow are reused; empty, malformed, no-op, mixed-repository and external-repository selections are disabled. Co-authored-by: muutot <[email protected]>
215 рядки
8.6 KiB
TypeScript
215 рядки
8.6 KiB
TypeScript
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
|
|
|
|
const ROOT = "/dev/acme-api";
|
|
const FILE = `${ROOT}/src/new-name.ts`;
|
|
const REVISION = "a".repeat(40);
|
|
|
|
test("File History opens its revision and compares only that file with the working copy", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await stubDesktop(page);
|
|
await page.evaluate(
|
|
async ({ root, path, revision }) => {
|
|
const h = window.__ipc.handlers;
|
|
h.vcs_roots = () => [{ root, head: "main", headCommit: revision, operation: null }];
|
|
h.vcs_branch_info = () => ({
|
|
head: "main",
|
|
headCommit: revision,
|
|
upstream: null,
|
|
ahead: 0,
|
|
behind: 0,
|
|
operation: null,
|
|
});
|
|
h.vcs_branches = () => [];
|
|
h.vcs_status = () => [];
|
|
h.vcs_log = ({ query }) =>
|
|
(query as { path?: string }).path
|
|
? [
|
|
{
|
|
id: revision,
|
|
shortId: revision.slice(0, 8),
|
|
parents: ["b".repeat(40)],
|
|
refs: [],
|
|
author: "Author",
|
|
email: "[email protected]",
|
|
timeMs: 1,
|
|
summary: "Rename historical file",
|
|
message: "Rename historical file",
|
|
historyPath: "src/old-name.ts",
|
|
},
|
|
]
|
|
: [];
|
|
h.vcs_log_refs = () => ({});
|
|
h.vcs_log_users = () => ["Author <[email protected]>"];
|
|
h.vcs_log_details_batch = () => [];
|
|
h.vcs_commit_files = () => [];
|
|
h.vcs_file_at = ({ path: filePath }) => `historical contents of ${String(filePath)}\n`;
|
|
h.vcs_diff_entries = ({ entries }) => (entries as unknown[]).map(() => ({ mode: "100644", gitlink: null }));
|
|
h.fs_probe = () => ({ size: 32, binary: false, tooLarge: false });
|
|
|
|
const storeModule = "/src/features/vcs/store.ts";
|
|
const { useVcs } = await import(/* @vite-ignore */ storeModule);
|
|
useVcs.setState({
|
|
available: true,
|
|
root,
|
|
repo: root,
|
|
roots: [root],
|
|
branchesLoaded: true,
|
|
statusLoaded: 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.showHistory", { path });
|
|
},
|
|
{ root: ROOT, path: FILE, revision: REVISION },
|
|
);
|
|
|
|
const commits = page.getByRole("listbox", { name: "Commits" });
|
|
const row = commits.getByRole("option", { name: /Rename historical file/ });
|
|
await expect(row).toBeVisible();
|
|
|
|
await row.click({ button: "right" });
|
|
const menu = page.getByRole("menu", { name: "Context menu" });
|
|
await expect(menu.getByRole("menuitem", { name: "Show File at Revision" })).toBeVisible();
|
|
await menu.getByRole("menuitem", { name: "Compare with Local" }).click();
|
|
|
|
await expect
|
|
.poll(async () => ipcCalls(page, "vcs_file_at"))
|
|
.toContainEqual({ path: `${ROOT}/src/old-name.ts`, rev: REVISION });
|
|
// The working copy side is the file itself (an editable document), not the historical path.
|
|
await expect
|
|
.poll(async () => ipcCalls(page, "vcs_diff_entries"))
|
|
.toContainEqual({
|
|
entries: [
|
|
{ path: `${ROOT}/src/old-name.ts`, rev: REVISION },
|
|
{ path: FILE, rev: "WT" },
|
|
],
|
|
});
|
|
await expect(page.getByText(`historical contents of ${ROOT}/src/old-name.ts`).first()).toBeVisible();
|
|
|
|
await row.click({ button: "right" });
|
|
await page
|
|
.getByRole("menu", { name: "Context menu" })
|
|
.getByRole("menuitem", { name: "Show File at Revision" })
|
|
.click();
|
|
await expect
|
|
.poll(async () => ipcCalls(page, "vcs_file_at"))
|
|
.toContainEqual({ path: `${ROOT}/src/old-name.ts`, rev: REVISION });
|
|
});
|
|
|
|
test("File History creates and copies a patch for only the selected changed file", async ({ workbench: page }) => {
|
|
const parent = "b".repeat(40);
|
|
const selectedPath = "src/selected.ts";
|
|
const otherPath = "src/other.ts";
|
|
const patch = `diff --git a/${selectedPath} b/${selectedPath}\n`;
|
|
await stubDesktop(page);
|
|
await page.evaluate(
|
|
async ({ root, path, revision, parent, selectedPath, otherPath }) => {
|
|
const h = window.__ipc.handlers;
|
|
h.vcs_roots = () => [{ root, head: "main", headCommit: revision, operation: null }];
|
|
h.vcs_branch_info = () => ({
|
|
head: "main",
|
|
headCommit: revision,
|
|
upstream: null,
|
|
ahead: 0,
|
|
behind: 0,
|
|
operation: null,
|
|
});
|
|
h.vcs_branches = () => [];
|
|
h.vcs_status = () => [];
|
|
h.vcs_log = ({ query }) =>
|
|
(query as { path?: string }).path
|
|
? [
|
|
{
|
|
id: revision,
|
|
shortId: revision.slice(0, 8),
|
|
parents: [parent],
|
|
refs: [],
|
|
author: "Author",
|
|
email: "[email protected]",
|
|
timeMs: 1,
|
|
summary: "Export selected history file",
|
|
message: "Export selected history file",
|
|
historyPath: selectedPath,
|
|
},
|
|
]
|
|
: [];
|
|
h.vcs_log_refs = () => ({});
|
|
h.vcs_log_users = () => ["Author <[email protected]>"];
|
|
h.vcs_log_details_batch = () => [];
|
|
h.vcs_commit_files = () => [
|
|
{ path: selectedPath, kind: "modified", oldPath: null },
|
|
{ path: otherPath, kind: "modified", oldPath: null },
|
|
];
|
|
h.vcs_create_patch = ({ source }) => {
|
|
const paths = (source as { paths?: string[] }).paths ?? [];
|
|
return paths.map((entry) => `diff --git a/${entry} b/${entry}\n`).join("");
|
|
};
|
|
h.vcs_write_patch = () => null;
|
|
h.clipboard_write_text = () => null;
|
|
|
|
const projectModule = "/src/platform/project.ts";
|
|
const { useProject } = await import(/* @vite-ignore */ projectModule);
|
|
useProject.setState((state: { settings: Record<string, unknown> }) => ({
|
|
settings: {
|
|
...state.settings,
|
|
vcs: { confirmation: { onPatchCreated: "no" } },
|
|
},
|
|
}));
|
|
const storeModule = "/src/features/vcs/store.ts";
|
|
const { useVcs } = await import(/* @vite-ignore */ storeModule);
|
|
useVcs.setState({ available: true, root, repo: root, roots: [root], branchesLoaded: true, statusLoaded: 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.showHistory", { path });
|
|
},
|
|
{ root: ROOT, path: `${ROOT}/${selectedPath}`, revision: REVISION, parent, selectedPath, otherPath },
|
|
);
|
|
|
|
const row = page.getByRole("listbox", { name: "Commits" }).getByRole("option", {
|
|
name: /Export selected history file/,
|
|
});
|
|
await expect(row).toBeVisible();
|
|
await row.click();
|
|
const tree = page.getByRole("tree", { name: "Changed files" });
|
|
const selected = tree.getByText("selected.ts", { exact: true });
|
|
await expect(selected).toBeVisible();
|
|
await expect(tree.getByText("other.ts", { exact: true })).toBeVisible();
|
|
const toolbar = page.getByRole("toolbar", { name: "Changed files" });
|
|
const create = toolbar.getByRole("button", { name: "Create Patch…", exact: true });
|
|
await expect(create).toBeDisabled();
|
|
await selected.click();
|
|
await expect(create).toBeEnabled();
|
|
await create.click();
|
|
|
|
const dialog = page.getByRole("dialog", { name: "Create Patch", exact: true });
|
|
await expect(dialog.getByRole("textbox", { name: "Base directory" })).toHaveValue(ROOT);
|
|
const destination = await dialog.getByRole("textbox", { name: "Patch file" }).inputValue();
|
|
expect(destination).toBe(`${ROOT}/Export_selected_history_file.patch`);
|
|
await dialog.getByRole("button", { name: "Create", exact: true }).click();
|
|
const source = { from: "revisions", before: parent, after: REVISION, paths: [selectedPath] };
|
|
await expect.poll(() => ipcCalls(page, "vcs_create_patch")).toEqual([{ repo: ROOT, base: ROOT, source }]);
|
|
await expect
|
|
.poll(() => ipcCalls(page, "vcs_write_patch"))
|
|
.toEqual([expect.objectContaining({ path: destination, patch })]);
|
|
|
|
await selected.click({ button: "right" });
|
|
await page
|
|
.getByRole("menu", { name: "Context menu" })
|
|
.getByRole("menuitem", { name: "Copy as Patch to Clipboard", exact: true })
|
|
.click();
|
|
await expect.poll(() => ipcCalls(page, "clipboard_write_text")).toEqual([{ text: patch }]);
|
|
await expect
|
|
.poll(() => ipcCalls(page, "vcs_create_patch"))
|
|
.toEqual([
|
|
{ repo: ROOT, base: ROOT, source },
|
|
{ repo: ROOT, base: null, source },
|
|
]);
|
|
});
|