дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 17:21:13 +02:00
The repository scan skips symlinks, so a file opened through a file symlink or a symlinked directory whose target lies outside the registered Git roots had no Git Blame or change markers, even when Git tracked the target. Read-only editor commands (blame, line hunks) now use the target's repository, discovered with the restricted read policy and never registered for status or Commit; excluded mappings and a disabled Git integration are honoured. The editor probes once per open file whether the link has committed history: only then do Annotate and the markers apply, and ordinary files in projects without Git make no further backend calls on edits. Co-authored-by: igallart <[email protected]>
176 рядки
8.1 KiB
TypeScript
176 рядки
8.1 KiB
TypeScript
import { expect, ipcCalls, openFromTree, stubDesktop, test } from "./fixtures";
|
||
|
||
test("the gutter only offers blame without Git roots once a linked target has confirmed history", async ({
|
||
workbench: page,
|
||
}) => {
|
||
const root = "/dev/acme-api";
|
||
const plain = `${root}/plain.txt`;
|
||
const linked = `${root}/linked.txt`;
|
||
await stubDesktop(page);
|
||
await page.evaluate(
|
||
async ({ plain, linked }) => {
|
||
const handlers = window.__ipc.handlers;
|
||
handlers.fs_probe = () => ({ size: 15, binary: false, tooLarge: false });
|
||
handlers.fs_read_text = () => "Committed line\n";
|
||
handlers.vcs_linked_file_has_history = ({ path }) => path === linked;
|
||
handlers.vcs_line_hunks = () => [];
|
||
handlers.vcs_blame = () => [
|
||
{ commit: "a".repeat(40), author: "Demo Author", timeMs: Date.UTC(2026, 4, 3), summary: "Add note" },
|
||
];
|
||
const storeModule = "/src/features/vcs/store.ts";
|
||
const { useVcs } = await import(/* @vite-ignore */ storeModule);
|
||
useVcs.setState({ available: false, roots: [] });
|
||
const contextModule = "/src/platform/context.ts";
|
||
const { setContext } = await import(/* @vite-ignore */ contextModule);
|
||
setContext("vcsAvailable", false);
|
||
const serviceModule = "/src/workbench/contributions.ts";
|
||
const { editorService } = await import(/* @vite-ignore */ serviceModule);
|
||
await editorService().openFile(plain);
|
||
},
|
||
{ plain, linked },
|
||
);
|
||
const gutter = page.locator(".cm-lineNumbers .cm-gutterElement").filter({ hasText: /^1$/ });
|
||
const annotate = page.getByRole("menuitem", { name: "Annotate with Git Blame", exact: true });
|
||
await expect.poll(() => ipcCalls(page, "vcs_linked_file_has_history")).toContainEqual({ path: plain });
|
||
await gutter.click({ button: "right" });
|
||
await expect(page.getByRole("menu")).toBeVisible();
|
||
await expect(annotate).toHaveCount(0);
|
||
await page.keyboard.press("Escape");
|
||
await page.locator(".cm-content").click();
|
||
await page.keyboard.press("Meta+Shift+A");
|
||
const search = page.getByRole("combobox");
|
||
const action = page.getByRole("option", { name: /Annotate with Git Blame/ });
|
||
await search.fill("Annotate with Git Blame");
|
||
await expect(action).toHaveCount(0);
|
||
await page.keyboard.press("Escape");
|
||
expect(await ipcCalls(page, "vcs_line_hunks")).toEqual([]);
|
||
|
||
await page.evaluate(async (path) => {
|
||
const serviceModule = "/src/workbench/contributions.ts";
|
||
const { editorService } = await import(/* @vite-ignore */ serviceModule);
|
||
await editorService().openFile(path);
|
||
}, linked);
|
||
await expect.poll(() => ipcCalls(page, "vcs_line_hunks")).toContainEqual({ path: linked });
|
||
await page.locator(".cm-content").click();
|
||
await page.keyboard.press("Meta+Shift+A");
|
||
await search.fill("Annotate with Git Blame");
|
||
await expect(action).toBeVisible();
|
||
await page.keyboard.press("Escape");
|
||
await gutter.click({ button: "right" });
|
||
await annotate.click();
|
||
await expect(page.locator(`.cm-vcs-blame [data-commit="${"a".repeat(40)}"] .cm-vcs-blame-author`)).toHaveText(
|
||
"Author",
|
||
);
|
||
});
|
||
|
||
test("Git annotations align dates and full author names at UI text size", async ({ workbench: page }) => {
|
||
const editor = await openFromTree(page, "build.gradle.kts");
|
||
await stubDesktop(page);
|
||
const longEmail = `reconciliation+${"regional-settlement-".repeat(5)}[email protected]`;
|
||
await page.evaluate(async (email) => {
|
||
const root = "/dev/acme-api";
|
||
const file = `${root}/build.gradle.kts`;
|
||
const handlers = window.__ipc.handlers;
|
||
const lines = [
|
||
{
|
||
commit: "a1234567".padEnd(40, "a"),
|
||
author: "Lena Park",
|
||
timeMs: Date.UTC(2026, 4, 3, 12),
|
||
summary: "Update totals",
|
||
},
|
||
{
|
||
commit: "b1234567".padEnd(40, "b"),
|
||
author: "Lena Ortiz",
|
||
timeMs: Date.UTC(2026, 8, 23, 12),
|
||
summary: "Review totals",
|
||
},
|
||
];
|
||
handlers.vcs_blame = () => lines;
|
||
handlers.vcs_log = ({ query }) => {
|
||
const { branch, path } = query as { branch?: string | null; path?: string | null };
|
||
// The file's last commit, which Annotate draws bold, is the newer one.
|
||
const line = path && branch === "HEAD" ? lines[1] : lines.find(({ commit }) => commit === branch);
|
||
if (!line) return [];
|
||
return [
|
||
{
|
||
...line,
|
||
id: line.commit,
|
||
shortId: line.commit.slice(0, 8),
|
||
refs: [],
|
||
parents: [],
|
||
email: line === lines[0] ? "[email protected]" : email,
|
||
message: line.summary,
|
||
},
|
||
];
|
||
};
|
||
const projectModule = "/src/platform/project.ts";
|
||
const { useProject } = await import(/* @vite-ignore */ projectModule);
|
||
const { settings } = useProject.getState();
|
||
useProject.setState({
|
||
settings: {
|
||
...settings,
|
||
general: { ...settings?.general, dateFormat: { overrideSystem: true, pattern: "d MMMM yyyy" } },
|
||
},
|
||
});
|
||
const storeModule = "/src/features/vcs/store.ts";
|
||
const { useVcs } = await import(/* @vite-ignore */ storeModule);
|
||
useVcs.setState({ available: true, root, repo: root, roots: [root] });
|
||
const contextModule = "/src/platform/context.ts";
|
||
const { setContext } = await import(/* @vite-ignore */ contextModule);
|
||
setContext("vcsAvailable", true);
|
||
// Options › Names › Full Name: the default (Last Name) would hide what is measured here.
|
||
const blameModule = "/src/features/vcs/blame.ts";
|
||
const { useAnnotateNames } = await import(/* @vite-ignore */ blameModule);
|
||
useAnnotateNames.setState({ names: "fullName" });
|
||
const actionsModule = "/src/platform/actions.ts";
|
||
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
|
||
await executeAction("vcs.annotate", file);
|
||
}, longEmail);
|
||
|
||
const gutter = editor.locator(".cm-vcs-blame");
|
||
const first = gutter.locator("[data-commit]").filter({ hasText: "3 May 2026" });
|
||
const second = gutter.locator("[data-commit]").filter({ hasText: "23 September 2026" });
|
||
const firstAuthor = first.locator(".cm-vcs-blame-author");
|
||
const secondAuthor = second.locator(".cm-vcs-blame-author");
|
||
await expect(firstAuthor).toHaveText("Lena Park");
|
||
await expect(secondAuthor).toHaveText("Lena Ortiz");
|
||
await expect
|
||
.poll(async () => Math.abs((await firstAuthor.boundingBox())!.x - (await secondAuthor.boundingBox())!.x))
|
||
.toBeLessThan(1);
|
||
// The bold labels of the file's last commit still fit their columns.
|
||
await expect(secondAuthor).toHaveCSS("font-weight", "700");
|
||
await expect(firstAuthor).toHaveCSS("font-weight", "400");
|
||
for (const cell of [second.locator(".cm-vcs-blame-date"), secondAuthor])
|
||
await expect.poll(() => cell.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(0);
|
||
|
||
await first.hover();
|
||
const details = page.getByRole("dialog").filter({ has: page.getByTitle("Show Commit in Git Log") });
|
||
await expect(details).toContainText("[email protected]");
|
||
await expect.poll(async () => (await details.boundingBox())!.width).toBeLessThan(400);
|
||
await expect(details.getByTitle("Show Commit in Git Log")).toHaveCSS(
|
||
"font-family",
|
||
await details.evaluate((el) => getComputedStyle(el).fontFamily),
|
||
);
|
||
|
||
await page.setViewportSize({ width: 430, height: 640 });
|
||
await second.hover();
|
||
await expect(details).toContainText(longEmail);
|
||
await expect(details).toBeInViewport({ ratio: 1 });
|
||
await expect.poll(() => details.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
||
const uiSize = await editor.evaluate((el) => getComputedStyle(el).getPropertyValue("--fs-ui").trim());
|
||
await expect(firstAuthor).toHaveCSS("font-size", uiSize);
|
||
|
||
const firstRevision = first.locator(".cm-vcs-blame-revision");
|
||
await expect(firstRevision).toBeHidden();
|
||
await second.click({ button: "right" });
|
||
await page.getByRole("menuitem", { name: "Options", exact: true }).hover();
|
||
await page.getByRole("menuitemcheckbox", { name: "Revision", exact: true }).click();
|
||
await expect(firstRevision).toBeVisible();
|
||
expect((await firstRevision.boundingBox())!.x).toBeLessThan(
|
||
(await first.locator(".cm-vcs-blame-date").boundingBox())!.x,
|
||
);
|
||
await expect
|
||
.poll(async () => Math.abs((await firstAuthor.boundingBox())!.x - (await secondAuthor.boundingBox())!.x))
|
||
.toBeLessThan(1);
|
||
});
|