feat(plugins): diffs of up to 8 MiB per side from open-diff (#3445)

views.open-diff and content tab reply diffs accept 8 MiB per side (was 1 MiB). A larger side fails with invalid("diff too large: the <side> side is over 8 MiB") from the host call and "Diff too large" for a web view's open-diff message, so plugins can tell the size limit from a malformed request. WIT docs updated and plugin components rebuilt.
This commit is contained in:
l0ng-ai
2026-11-15 03:32:29 +08:00
committed by GitHub
parent 519c8ad8fc
commit ea644dcdb0
93 changed files with 110 additions and 56 deletions
@@ -261,8 +261,14 @@ describe("plugin-backed content editor tabs", () => {
diffs.splice(2);
expect(() => openPluginDiffRequest({ left: "a", right: 1 }, 10)).toThrow();
expect(() => openPluginDiffRequest({ left: "a", right: "b", fileName: "x\ny" }, 10)).toThrow();
expect(() => openPluginDiffRequest({ left: "a", right: "b" }, 4 << 20)).toThrow();
expect(() => openPluginDiffRequest({ left: "a", right: "b" }, 40 << 20)).toThrow();
expect(diffs).toHaveLength(2);
// Lock files and generated code: several MiB per side open; past the limit the error says why.
const big = "x".repeat(5 << 20);
openPluginDiffRequest({ left: big, right: big + "y" }, 10 << 20);
expect(diffs).toHaveLength(3);
const huge = "x".repeat((8 << 20) + 1);
expect(() => openPluginDiffRequest({ left: "a", right: huge }, huge.length)).toThrow(/Diff too large/);
} finally {
unregisterDiff();
}
+12 -3
View File
@@ -153,13 +153,21 @@ export function registerContentTabSender(pluginId: string, view: string, send: (
};
}
/** Largest side of a plugin diff, as the host checks it (`MAX_DIFF_SIDE`). */
const MAX_DIFF_SIDE = 8 << 20;
function validDiff(v: unknown): ContentTabDiff | undefined {
if (v === undefined) return undefined;
if (!v || typeof v !== "object") throw new Error(tx("Invalid content editor configuration"));
const d = v as Record<string, unknown>;
for (const side of [d.left, d.right]) {
if (typeof side === "string" && side.length > MAX_DIFF_SIDE) {
throw new Error(tx`Diff too large: a side is over ${MAX_DIFF_SIDE >> 20} MiB`);
}
}
if (
!bodyText(d.left, 1 << 20) ||
!bodyText(d.right, 1 << 20) ||
!bodyText(d.left, MAX_DIFF_SIDE) ||
!bodyText(d.right, MAX_DIFF_SIDE) ||
(d.leftLabel !== undefined && !text(d.leftLabel, 128)) ||
(d.rightLabel !== undefined && !text(d.rightLabel, 128)) ||
(d.title !== undefined && !text(d.title, 256))
@@ -201,7 +209,8 @@ export function openPluginDiff(diff: ContentTabDiff, name: string, title: string
/** `open-diff` from a plugin web view, or the `views.open-diff` host call. */
export function openPluginDiffRequest(value: object, length: number) {
const m = value as Record<string, unknown>;
if (length > 3 << 20 || (m.fileName !== undefined && !text(m.fileName, 256))) {
// Both sides as JSON (escapes included), with room for the labels.
if (length > 4 * MAX_DIFF_SIDE + (1 << 20) || (m.fileName !== undefined && !text(m.fileName, 256))) {
throw new Error(tx("Invalid content editor configuration"));
}
const fileName = m.fileName as string | undefined;
+2 -1
View File
@@ -8163,5 +8163,6 @@
"Copy Library": "复制库",
"PID {pid}": "PID {pid}",
"PID {pid} · {count} processes": "PID {pid} · {count} 个进程",
"End Process {label}": "结束进程 {label}"
"End Process {label}": "结束进程 {label}",
"Diff too large: a side is over {max} MiB": "差异过大:有一侧超过 {max} MiB"
}