Skip to content

Commit 9da3fce

Browse files
committed
fix(mcp): preserve parameter guidance while merging main
2 parents d0b2d10 + 6d46336 commit 9da3fce

196 files changed

Lines changed: 4967 additions & 893 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/permissions/MacSettingsWindow.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as NodeEvents from "node:events";
2+
import * as NodeVM from "node:vm";
23
import { beforeEach, expect, it, vi } from "vite-plus/test";
34
import { watchMacSettingsWindow } from "./MacSettingsWindow.ts";
45

@@ -42,3 +43,29 @@ it("distinguishes unavailable tracking from a valid absent window", () => {
4243
expect(unavailable).toHaveBeenCalledTimes(2);
4344
stop();
4445
});
46+
it("polls while its parent lives and stops after reparenting to launchd", () => {
47+
watchMacSettingsWindow(vi.fn(), vi.fn())();
48+
const script = mocks.spawn.mock.lastCall?.[1][3];
49+
const imports = new Set<string>();
50+
const writeData = vi.fn();
51+
const poll = vi.fn(() => ({ count: 0 }));
52+
const sleep = vi.fn(() => {
53+
if (sleep.mock.calls.length > 2) throw new Error("tracker kept polling after parent exit");
54+
});
55+
const bridge = Object.assign((line: string) => ({ dataUsingEncoding: () => line }), {
56+
getppid: () => {
57+
if (!imports.has("unistd")) throw new Error("unistd bridge unavailable");
58+
return sleep.mock.calls.length < 2 ? 42 : 1;
59+
},
60+
NSRunningApplication: { runningApplicationsWithBundleIdentifier: poll },
61+
NSFileHandle: { fileHandleWithStandardOutput: { writeData } },
62+
NSThread: { sleepForTimeInterval: sleep },
63+
NSUTF8StringEncoding: 4,
64+
});
65+
NodeVM.runInNewContext(script + "\nrun();", {
66+
ObjC: { import: (name: string) => imports.add(name) },
67+
$: bridge,
68+
});
69+
expect(poll).toHaveBeenCalledTimes(2);
70+
expect(writeData.mock.calls).toEqual([["null\n"]]);
71+
});

‎apps/desktop/src/permissions/MacSettingsWindow.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ const decodeSettingsWindow = Schema.decodeUnknownSync(Schema.fromJsonString(Sett
2020
const SETTINGS_WINDOW_SCRIPT = `
2121
ObjC.import("CoreGraphics");
2222
ObjC.import("AppKit");
23+
ObjC.import("unistd");
2324
function run() {
2425
let previous = "";
25-
while (true) {
26+
while ($.getppid() !== 1) {
2627
const apps = $.NSRunningApplication.runningApplicationsWithBundleIdentifier("com.apple.systempreferences");
2728
let result = null;
2829
if (apps.count > 0) {

‎apps/desktop/src/preview/BrowserSession.test.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe("BrowserSession", () => {
145145
}).pipe(Effect.provide(layer)),
146146
);
147147

148-
it.effect("grants clipboard-sanitized-write through both the request and check handlers", () =>
148+
it.effect("grants preview permissions through both the request and check handlers", () =>
149149
Effect.gen(function* () {
150150
const browserSessions = yield* BrowserSession.BrowserSession;
151151
const partition = yield* browserSessions.getPartition("scope-a");
@@ -168,7 +168,12 @@ describe("BrowserSession", () => {
168168
return granted;
169169
};
170170

171-
for (const permission of ["clipboard-sanitized-write", "geolocation", "fullscreen"]) {
171+
for (const permission of [
172+
"clipboard-sanitized-write",
173+
"geolocation",
174+
"fullscreen",
175+
"loopback-network",
176+
]) {
172177
assert.isTrue(requestAllows(permission), `request handler should allow ${permission}`);
173178
assert.isTrue(
174179
checkHandler(null, permission) as boolean,
@@ -179,7 +184,13 @@ describe("BrowserSession", () => {
179184
// `clipboard-write` is not a real Electron permission — the async write API
180185
// uses `clipboard-sanitized-write` — so the stale name must not be granted,
181186
// and unrelated permissions stay denied.
182-
for (const permission of ["clipboard-write", "notifications", "midi"]) {
187+
for (const permission of [
188+
"clipboard-write",
189+
"notifications",
190+
"midi",
191+
"local-network",
192+
"local-network-access",
193+
]) {
183194
assert.isFalse(requestAllows(permission), `request handler should deny ${permission}`);
184195
assert.isFalse(
185196
checkHandler(null, permission) as boolean,

‎apps/desktop/src/preview/BrowserSession.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet<string> = new Set([
2424
"geolocation",
2525
// DesktopWindow confines HTML fullscreen to the guest's webview.
2626
"fullscreen",
27+
// Loopback requests already succeed in Electron 44; permission-aware sign-in widgets query first.
28+
"loopback-network",
2729
// Deny local-fonts to untrusted previews: it exposes installed-font fingerprints and file bytes.
2830
// Deny notifications: pages could impersonate T3 Code; app notifications use the default session.
2931
]);

‎apps/desktop/src/window/DesktopWindow.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,45 @@ describe("DesktopWindow", () => {
472472
);
473473
});
474474

475+
it("rejects renderer navigations whose origin only serializes as null", () => {
476+
for (const applicationUrl of ["t3code://app/", "t3code-dev://app/"]) {
477+
assert.isTrue(
478+
DesktopWindow.isSameOriginRendererNavigation({
479+
applicationUrl,
480+
navigationUrl: `${applicationUrl}threads?id=1#latest`,
481+
}),
482+
applicationUrl,
483+
);
484+
}
485+
for (const navigationUrl of [
486+
"t3code://other/",
487+
"t3code://app.example/",
488+
"t3code://app:8080/",
489+
"t3code://user@other/",
490+
"t3code:app",
491+
"t3code-dev://app/",
492+
"file:///etc/passwd",
493+
"data:text/html,<p>hi</p>",
494+
"javascript:alert(1)",
495+
"about:blank",
496+
"blob:t3code://app/0b5e2c4a",
497+
]) {
498+
assert.isFalse(
499+
DesktopWindow.isSameOriginRendererNavigation({
500+
applicationUrl: "t3code://app/",
501+
navigationUrl,
502+
}),
503+
navigationUrl,
504+
);
505+
}
506+
assert.isFalse(
507+
DesktopWindow.isSameOriginRendererNavigation({
508+
applicationUrl: "data:text/html,app",
509+
navigationUrl: "data:text/html,other",
510+
}),
511+
);
512+
});
513+
475514
it.effect(
476515
"opens and reopens the window without backend readiness when local execution is disabled",
477516
() =>
@@ -973,6 +1012,17 @@ describe("DesktopWindow", () => {
9731012
if (!willNavigate) {
9741013
return yield* Effect.die("will-navigate listener was not registered");
9751014
}
1015+
for (const [url, expectedPrevented] of [
1016+
["t3code-dev://app/threads?id=1#latest", false],
1017+
["t3code-dev://other/", true],
1018+
["t3code://app/", true],
1019+
] as const) {
1020+
const preventDefault = vi.fn();
1021+
willNavigate({ preventDefault }, url);
1022+
assert.equal(preventDefault.mock.calls.length, expectedPrevented ? 1 : 0, url);
1023+
}
1024+
assert.deepEqual(openedExternalUrls, []);
1025+
9761026
let prevented = false;
9771027
willNavigate(
9781028
{

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,19 @@ function buildConnectingSplashDataUrl(shouldUseDarkColors: boolean): string {
183183
return `data:text/html;charset=utf-8,${encodeURIComponent(html)}`;
184184
}
185185

186-
function isSameOriginRendererNavigation(input: {
186+
export function isSameOriginRendererNavigation(input: {
187187
readonly applicationUrl: string;
188188
readonly navigationUrl: string;
189189
}): boolean {
190190
try {
191-
return new URL(input.applicationUrl).origin === new URL(input.navigationUrl).origin;
191+
const applicationUrl = new URL(input.applicationUrl);
192+
const navigationUrl = new URL(input.navigationUrl);
193+
// Node serializes custom-scheme origins as "null", even for different hosts and schemes.
194+
return (
195+
applicationUrl.host !== "" &&
196+
navigationUrl.protocol === applicationUrl.protocol &&
197+
navigationUrl.host === applicationUrl.host
198+
);
192199
} catch {
193200
return false;
194201
}
9.19 KB
Loading
-2.19 KB
Binary file not shown.
-10.9 KB
Binary file not shown.
7.35 KB
Loading

0 commit comments

Comments
 (0)