mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
fix(project-trust): show the selected trust scope in the open prompt (#4789)
The open-project trust prompt shows the selected trust scope: checking Trust projects in names the folder and the primary button becomes Trust Folder.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { expect, ipcCalls, stubDesktop, test } from "./fixtures";
|
||||
|
||||
const parent = "/dev/imports/From-vendor/QuarterlySettlementReconciliationAndReportingProjects";
|
||||
const project = `${parent}/settlement-api`;
|
||||
|
||||
test("the trust prompt keeps the folder scope and restricted preview visible in a narrow window", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: 420, height: 455 });
|
||||
await stubDesktop(page);
|
||||
await page.evaluate(() => {
|
||||
const h = window.__ipc.handlers;
|
||||
h.project_trust_status = ({ path }) => ({ root: path, trusted: false, decided: false });
|
||||
h.project_trust_set = () => null;
|
||||
h.open_project = ({ path }) => ({ root: path, name: "settlement-api", trusted: false, isGit: false, settings: {} });
|
||||
h.fs_read_dir = () => [];
|
||||
});
|
||||
const open = () =>
|
||||
page.evaluate(async (path) => {
|
||||
const projectModule = "/src/platform/project.ts";
|
||||
const { openProject } = await import(/* @vite-ignore */ projectModule);
|
||||
void openProject(path).catch(() => undefined);
|
||||
}, project);
|
||||
await open();
|
||||
|
||||
const dialog = page.getByRole("dialog", { name: "Trust and Open Project?" });
|
||||
const restricted = dialog.getByRole("button", { name: "Preview in Restricted Mode" });
|
||||
const folder = dialog.getByRole("checkbox", { name: /Trust projects in/ });
|
||||
const projectAction = dialog.getByRole("button", { name: "Trust Project", exact: true });
|
||||
const folderAction = dialog.getByRole("button", { name: "Trust Folder", exact: true });
|
||||
await expect(restricted).toBeFocused();
|
||||
await expect(projectAction).toBeVisible();
|
||||
await expect(folder).not.toBeChecked();
|
||||
await expect(dialog.getByTitle(project, { exact: true })).toBeVisible();
|
||||
await expect(dialog.getByTitle(parent, { exact: true })).toBeVisible();
|
||||
await folder.check();
|
||||
await expect(folderAction).toHaveCount(1);
|
||||
await expect(projectAction).toHaveCount(0);
|
||||
for (const selector of ["[data-dialog-body]", "[data-dialog-footer]"]) {
|
||||
expect(await dialog.locator(selector).evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
||||
}
|
||||
await expect(restricted).toBeInViewport({ ratio: 1 });
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(dialog).toBeHidden();
|
||||
expect(await ipcCalls(page, "project_trust_set")).toEqual([]);
|
||||
expect(await ipcCalls(page, "open_project")).toEqual([]);
|
||||
|
||||
await open();
|
||||
await expect(projectAction).toBeVisible();
|
||||
await expect(folder).not.toBeChecked();
|
||||
await folder.check();
|
||||
await restricted.click();
|
||||
await expect(dialog).toBeHidden();
|
||||
expect(await ipcCalls(page, "project_trust_set")).toEqual([{ path: project, trusted: false, folder: false }]);
|
||||
await expect.poll(() => ipcCalls(page, "open_project")).toEqual([{ path: project }]);
|
||||
});
|
||||
@@ -39,8 +39,10 @@ function TrustDialog() {
|
||||
return (
|
||||
<Dialog
|
||||
open={!!path}
|
||||
icon="app"
|
||||
width={560}
|
||||
icon="warning"
|
||||
width={600}
|
||||
className={styles.trustDialog}
|
||||
blockWorkbenchShortcuts
|
||||
title="Trust and Open Project?"
|
||||
onClose={() => void executeAction("project.dontOpen")}
|
||||
buttons={[
|
||||
@@ -49,8 +51,12 @@ function TrustDialog() {
|
||||
autoFocus: true,
|
||||
onClick: () => void executeAction("project.previewRestricted"),
|
||||
},
|
||||
{ label: "Don't Open", onClick: () => void executeAction("project.dontOpen") },
|
||||
{ label: "Trust Project", role: "default", onClick: () => void executeAction("project.trust") },
|
||||
{ label: "Don't Open", role: "cancel" },
|
||||
{
|
||||
label: folder ? "Trust Folder" : "Trust Project",
|
||||
role: "default",
|
||||
onClick: () => void executeAction("project.trust"),
|
||||
},
|
||||
]}
|
||||
footerStart={
|
||||
<Checkbox
|
||||
@@ -68,17 +74,17 @@ function TrustDialog() {
|
||||
/>
|
||||
}
|
||||
>
|
||||
<div className={styles.content}>
|
||||
<div className={styles.promptContent}>
|
||||
<PathLine path={path ?? ""} />
|
||||
<p>
|
||||
<T>Loading, running or building a project may execute potentially malicious code from its build scripts.</T>
|
||||
</p>
|
||||
<p className={styles.restrictedPreview}>
|
||||
<T>
|
||||
If you don't trust the source, preview the project in Restricted Mode, where project commands and tools
|
||||
can't run.
|
||||
</T>
|
||||
</p>
|
||||
<p>
|
||||
<T>Loading, running or building a project may execute potentially malicious code from its build scripts.</T>
|
||||
</p>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -6,14 +6,27 @@
|
||||
.content p {
|
||||
margin: 0;
|
||||
}
|
||||
.promptContent {
|
||||
composes: content;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
.promptContent > .pathLine {
|
||||
padding: var(--space-1) var(--space-2);
|
||||
background: var(--bg-elev);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius-small);
|
||||
color: var(--fg-secondary);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.restrictedPreview {
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
.pathLine {
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.content > .pathLine {
|
||||
color: var(--fg-secondary);
|
||||
}
|
||||
.pathHead {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
@@ -26,15 +39,31 @@
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.folderOption {
|
||||
max-width: 100%;
|
||||
align-items: flex-start;
|
||||
width: 100%;
|
||||
}
|
||||
.folderLabel {
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
flex-direction: column;
|
||||
gap: var(--space-0-5);
|
||||
min-width: 0;
|
||||
}
|
||||
.folderPrefix {
|
||||
flex: none;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.folderLabel > .pathLine {
|
||||
color: var(--fg-secondary);
|
||||
font-family: var(--font-mono);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.trustDialog [data-dialog-footer] button {
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
min-height: var(--h-button);
|
||||
height: auto;
|
||||
padding-block: var(--space-1);
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.banner {
|
||||
display: flex;
|
||||
|
||||
@@ -115,7 +115,7 @@ it("saves the parent-folder choice and reuses a persisted decision", async () =>
|
||||
const opening = confirmProjectTrust("/projects/new");
|
||||
await screen.findByRole("dialog");
|
||||
fireEvent.click(screen.getByRole("checkbox", { name: /Trust projects in/ }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Trust Project" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Trust Folder" }));
|
||||
await act(async () => opening);
|
||||
expect(decide).toHaveBeenCalledWith("/projects/new", true, true);
|
||||
status.mockResolvedValue({ status: "ok", data: { trusted: true, decided: true } });
|
||||
@@ -140,7 +140,7 @@ it("shows and trusts the canonical folder when opening through a symlink", async
|
||||
const opening = confirmProjectTrust("/aliases/new");
|
||||
await screen.findByRole("dialog");
|
||||
fireEvent.click(screen.getByRole("checkbox", { name: /Trust projects in \/real\/projects/ }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Trust Project" }));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Trust Folder" }));
|
||||
await act(async () => opening);
|
||||
expect(decide).toHaveBeenCalledWith("/real/projects/new", true, true);
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"Trust Folder": "Trust Folder",
|
||||
"No files selected": "No files selected",
|
||||
"{added} added": "{added} added",
|
||||
"{modified} modified": "{modified} modified",
|
||||
|
||||
@@ -642,6 +642,7 @@
|
||||
"If you don't trust the source, preview the project in Restricted Mode, where project commands and tools can't run.": "如果不信任来源,请以受限模式预览项目,此模式下不会运行项目命令和工具。",
|
||||
"Loading, running or building a project may execute potentially malicious code from its build scripts.": "加载、运行或构建项目可能会执行其构建脚本中的恶意代码。",
|
||||
"Trust projects in": "信任此文件夹中的项目:",
|
||||
"Trust Folder": "信任文件夹",
|
||||
"Restricted Mode: project commands and tools are disabled.": "受限模式:项目命令和工具已禁用。",
|
||||
"Trust Project": "信任项目",
|
||||
"Trust decisions are saved in your user data and take effect immediately.": "信任决定保存在您的用户数据中,并立即生效。",
|
||||
|
||||
Reference in New Issue
Block a user