Skip to content

Commit de96bfd

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-4812
2 parents 18361cd + 2e2d86c commit de96bfd

100 files changed

Lines changed: 3463 additions & 636 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.

‎.coderabbit.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default defineConfig((ctx) => ({
2727
instructions: "Hold changed code to the rules in docs/internals/web-ui.md.",
2828
},
2929
{
30-
path: "**/*.test.{ts,tsx}",
30+
path: "**/*.test.*",
3131
instructions:
3232
"Hold changed tests to the rules in docs/internals/testing.md. Request tests only as those rules allow.",
3333
},

‎.github/triage/PLAYBOOK.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ provided alongside this playbook. Everything machine-specific lives there, not h
1111

1212
## 1. Ask what went wrong
1313

14-
Your first message to the user: ask them to describe what went wrong, in their own
15-
words. Ask them to paste screenshots directly into this session if they have any.
14+
Unless the user already described it, your first message asks what went wrong, in
15+
their own words. Ask them to paste screenshots directly into this session if they have any.
1616
Ask follow-up questions when the description is vague. Good repro steps are the most
1717
valuable thing you can extract from this conversation.
1818

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Test Signal
3+
model: gpt-6-1-terra
4+
reasoning: low
5+
input: incremental
6+
tools:
7+
- browse_code
8+
- modify_pr
9+
# An explicit include overrides ignore.md, which skips test files for every other check.
10+
include:
11+
- "**/*.test.*"
12+
exclude:
13+
- ".repos/**"
14+
requires:
15+
- Check
16+
maxBudgetPerRun: 1
17+
maxBudgetPerPR: 5
18+
conclusion: neutral
19+
---
20+
21+
# Test signal review
22+
23+
Review only the tests this pull request adds or grows. Tests it moves, renames, or deletes are not findings. The rules are in `docs/internals/testing.md` under `## What to test`; read that section first and hold new tests to it.
24+
25+
Post each finding as a brief inline comment on the new test with one fix. Ask only for fewer or smaller tests, never for more coverage.
26+
27+
When there are no findings, make the entire final response exactly `All clear` on one line with nothing else.

‎AGENTS.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
102102
- While you iterate, run `vp test run <files>`. For big files, add `-t "<name>"`.
103103
- Use `vp run typecheck`, not `npx tsc`; it caches per package. Both run tsc-rs (`typescript` is the `@tsc-rs/typescript` drop-in).
104104
- Run `node -e` snippets from `apps/server` or the owning package. `effect` does not resolve from the repo root.
105-
- Test meaningful logic or observable behavior. Do not render components to static markup to assert props or attributes, or add tests that merely assert callback wiring or mirror the implementation.
105+
- Test behavior that can break, such as orchestration and event-sourcing, provider protocol translation, auth and permission guards, persistence and migrations, external-format parsing, race fixes, and the logic a bug fix changed. Leave out tests for what types already guarantee, trivial logic, copy text, smoke runs, mock-call mirrors, callback wiring, and props rendered to static markup.
106+
- Extend before you add. When an existing test or table covers the behavior, add a row or an assertion there. Write a new `it` only when no case fits.
107+
- Test at one layer: the lowest one that fails on `main`. Do not repeat the case in a wrapper test, at each call site, or in web and mobile copies of the same logic.
106108
- [Testing](docs/internals/testing.md) carries these same test rules, plus review guidance, for review bots. Change both together.
107109
- **Do not run repo-wide checks.** No `vp check`, no `vp run -r test`, no `vp run -r typecheck` unless I ask. CI owns the full suite.
108110
- Backend behavior changes ship with focused tests for that behavior.
109-
- Proof for a bug fix depends on the bug. Logic, data, state, and protocol bugs get a failing test first (the fewest that fail on `main` for that reason, in the module's existing test file), then the fix. Purely visual bugs (spacing, colour, alignment, a layout shift) get before/after captures as their proof and no test: do not add UI tests for nitpicks, and do not ask for one in review when a capture already shows it. A server-only fix with no visible surface ships the test plus a short runtime transcript.
111+
- Proof for a bug fix depends on the bug. Logic, data, state, and protocol bugs get a failing test first (the fewest that fail on `main` for that reason, in an existing case of the module's test file where one fits), then the fix. Purely visual bugs (spacing, colour, alignment, a layout shift) get before/after captures as their proof and no test: do not add UI tests for nitpicks, and do not ask for one in review when a capture already shows it. A server-only fix with no visible surface ships the test plus a short runtime transcript.
110112
- The server is event-sourced, and side effects run after the command commits. In tests, drain the effect worker (`OrchestrationEffectWorkerV2.drain`) or await the specific persisted event or `Deferred` that marks the milestone. Never wait on sleeps or polling. A test that needs a timeout to pass is wrong. Concretely:
111113
- `it.effect` runs on a `TestClock`; `Effect.sleep` only advances through `TestClock.adjust`. `it.live` is wall-clock and only for subprocess or network fixtures.
112114
- No `yieldNow` or `sleep` polling loops. Await the `Deferred`, take from the `Queue`, or drain the worker.

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

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,7 @@ describe("BrowserSession", () => {
168168
return granted;
169169
};
170170

171-
for (const permission of [
172-
"clipboard-read",
173-
"clipboard-sanitized-write",
174-
"geolocation",
175-
"fullscreen",
176-
]) {
171+
for (const permission of ["clipboard-sanitized-write", "geolocation", "fullscreen"]) {
177172
assert.isTrue(requestAllows(permission), `request handler should allow ${permission}`);
178173
assert.isTrue(
179174
checkHandler(null, permission) as boolean,
@@ -226,6 +221,55 @@ describe("BrowserSession", () => {
226221
}).pipe(Effect.provide(layer)),
227222
);
228223

224+
it.effect("asks once per origin before a page reads the clipboard", () =>
225+
Effect.gen(function* () {
226+
const browserSessions = yield* BrowserSession.BrowserSession;
227+
const partition = yield* browserSessions.getPartition("scope-a");
228+
yield* browserSessions.getSession("scope-a");
229+
const browserSession = sessions.get(partition);
230+
assert.isDefined(browserSession);
231+
const requestHandler = browserSession.setPermissionRequestHandler.mock.calls[0]?.[0];
232+
const checkHandler = browserSession.setPermissionCheckHandler.mock.calls[0]?.[0];
233+
assert.isFunction(requestHandler);
234+
assert.isFunction(checkHandler);
235+
236+
const readClipboard = (requestingUrl: string) =>
237+
Effect.callback<boolean>((resume) => {
238+
requestHandler(
239+
null,
240+
"clipboard-read",
241+
(granted: boolean) => resume(Effect.succeed(granted)),
242+
{ requestingUrl, isMainFrame: true },
243+
);
244+
});
245+
const checkClipboard = (origin: string): boolean =>
246+
checkHandler(null, "clipboard-read", origin, {}) as boolean;
247+
248+
showMessageBox.mockReset();
249+
showMessageBox.mockReturnValueOnce(0).mockReturnValueOnce(1);
250+
251+
assert.isFalse(checkClipboard("https://allowed.test"));
252+
assert.isTrue(yield* readClipboard("https://allowed.test/page"));
253+
assert.strictEqual(showMessageBox.mock.calls.length, 1);
254+
assert.strictEqual(
255+
showMessageBox.mock.calls[0]?.[0].message,
256+
"https://allowed.test wants to see text and images copied to the clipboard",
257+
);
258+
assert.deepStrictEqual(showMessageBox.mock.calls[0]?.[0].buttons, ["Allow", "Block"]);
259+
// Enter must not accept a prompt the page raised while the user was typing.
260+
assert.strictEqual(showMessageBox.mock.calls[0]?.[0].defaultId, 1);
261+
262+
assert.isTrue(yield* readClipboard("https://allowed.test/other"));
263+
assert.isTrue(checkClipboard("https://allowed.test"));
264+
265+
assert.isFalse(yield* readClipboard("https://blocked.test/"));
266+
assert.isFalse(yield* readClipboard("https://blocked.test/again"));
267+
assert.isFalse(checkClipboard("https://blocked.test"));
268+
assert.isTrue(checkClipboard("https://allowed.test"));
269+
assert.strictEqual(showMessageBox.mock.calls.length, 2);
270+
}).pipe(Effect.provide(layer)),
271+
);
272+
229273
it.effect("clears a partition whose session has not been opened yet", () =>
230274
Effect.gen(function* () {
231275
const browserSessions = yield* BrowserSession.BrowserSession;

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

Lines changed: 98 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export type BrowserSessionPartitionNamespace = "profile";
2020

2121
// Electron's clipboard API uses clipboard-sanitized-write and checks both permission handlers.
2222
const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet<string> = new Set([
23-
"clipboard-read",
2423
"clipboard-sanitized-write",
2524
"geolocation",
2625
// DesktopWindow confines HTML fullscreen to the guest's webview.
@@ -55,6 +54,19 @@ const externalProtocolPromptUrl = (rawUrl: string | undefined): string | null =>
5554

5655
const MAX_PROMPT_URL_LENGTH = 300;
5756

57+
const truncateForPrompt = (text: string): string =>
58+
text.length > MAX_PROMPT_URL_LENGTH ? `${text.slice(0, MAX_PROMPT_URL_LENGTH)}…` : text;
59+
60+
const permissionOrigin = (rawUrl: string | undefined): string | null => {
61+
if (!rawUrl) return null;
62+
try {
63+
const { origin } = new URL(rawUrl);
64+
return origin === "null" ? null : origin;
65+
} catch {
66+
return null;
67+
}
68+
};
69+
5870
export class BrowserSessionPartitionDerivationError extends Schema.TaggedError<BrowserSessionPartitionDerivationError>()(
5971
"BrowserSessionPartitionDerivationError",
6072
{
@@ -175,47 +187,70 @@ export const make = Effect.gen(function* BrowserSessionMake() {
175187
const electronDialog = yield* ElectronDialog.ElectronDialog;
176188
const runFork = Effect.runForkWith(yield* Effect.context<never>());
177189
// One prompt at a time, so a page cannot stack dialogs by looping a deep link.
178-
let externalPromptOpen = false;
179-
/** Electron launches external protocols after granting openExternal; untrusted pages require confirmation. */
180-
const confirmOpenExternal = (
190+
let permissionPromptOpen = false;
191+
/** Settles with `undefined` when the user gave no answer: another prompt was open or the dialog failed. */
192+
const promptPermission = (
181193
requester: WebContents | null,
182-
rawUrl: string | undefined,
183-
callback: (granted: boolean) => void,
194+
prompt: {
195+
readonly buttons: readonly [allow: string, deny: string];
196+
readonly message: string;
197+
readonly detail?: string;
198+
},
199+
callback: (answer: boolean | undefined) => void,
184200
): void => {
185-
const url = externalProtocolPromptUrl(rawUrl);
186-
if (url === null || externalPromptOpen) {
187-
callback(false);
201+
if (permissionPromptOpen) {
202+
callback(undefined);
188203
return;
189204
}
190-
externalPromptOpen = true;
191-
const settle = (granted: boolean) =>
205+
permissionPromptOpen = true;
206+
const settle = (answer: boolean | undefined) =>
192207
Effect.sync(() => {
193-
externalPromptOpen = false;
194-
callback(granted);
208+
permissionPromptOpen = false;
209+
callback(answer);
195210
});
196-
const shownUrl =
197-
url.length > MAX_PROMPT_URL_LENGTH ? `${url.slice(0, MAX_PROMPT_URL_LENGTH)}…` : url;
198211
runFork(
199212
electronDialog
200213
.showMessageBox(
201214
{
202215
type: "question",
203-
buttons: ["Open", "Cancel"],
204-
defaultId: 0,
216+
buttons: [...prompt.buttons],
217+
// Default to deny so an Enter typed into the page cannot accept a prompt it raised.
218+
defaultId: 1,
205219
cancelId: 1,
206-
message: `Open this ${new URL(url).protocol.slice(0, -1)} link?`,
207-
detail: `A page in the browser wants to open another application:\n\n${shownUrl}`,
220+
message: prompt.message,
221+
...(prompt.detail === undefined ? {} : { detail: prompt.detail }),
208222
},
209223
previewHostWindow(requester),
210224
)
211225
.pipe(
212-
Effect.map(({ response }) => response === 0),
213-
Effect.orElseSucceed(() => false),
226+
Effect.map(({ response }): boolean | undefined => response === 0),
227+
Effect.orElseSucceed(() => undefined),
214228
Effect.flatMap(settle),
215-
Effect.onInterrupt(() => settle(false)),
229+
Effect.onInterrupt(() => settle(undefined)),
216230
),
217231
);
218232
};
233+
/** Electron launches external protocols after granting openExternal; untrusted pages require confirmation. */
234+
const confirmOpenExternal = (
235+
requester: WebContents | null,
236+
rawUrl: string | undefined,
237+
callback: (granted: boolean) => void,
238+
): void => {
239+
const url = externalProtocolPromptUrl(rawUrl);
240+
if (url === null) {
241+
callback(false);
242+
return;
243+
}
244+
promptPermission(
245+
requester,
246+
{
247+
buttons: ["Open", "Cancel"],
248+
message: `Open this ${new URL(url).protocol.slice(0, -1)} link?`,
249+
detail: `A page in the browser wants to open another application:\n\n${truncateForPrompt(url)}`,
250+
},
251+
(answer) => callback(answer === true),
252+
);
253+
};
219254
const sessionsRef = yield* SynchronizedRef.make<ReadonlyMap<string, Session>>(new Map());
220255

221256
const getPartition = Effect.fn("BrowserSession.getPartition")(function* (
@@ -248,6 +283,35 @@ export const make = Effect.gen(function* BrowserSessionMake() {
248283
return Effect.try({
249284
try: () => {
250285
const browserSession = session.fromPartition(partition);
286+
// Like Chrome, clipboard reads ask once per origin; both answers last for the session.
287+
const clipboardReadDecisions = new Map<string, boolean>();
288+
const confirmClipboardRead = (
289+
requester: WebContents,
290+
rawUrl: string | undefined,
291+
callback: (granted: boolean) => void,
292+
): void => {
293+
const origin = permissionOrigin(rawUrl);
294+
if (origin === null) {
295+
callback(false);
296+
return;
297+
}
298+
const remembered = clipboardReadDecisions.get(origin);
299+
if (remembered !== undefined) {
300+
callback(remembered);
301+
return;
302+
}
303+
promptPermission(
304+
requester,
305+
{
306+
buttons: ["Allow", "Block"],
307+
message: `${truncateForPrompt(origin)} wants to see text and images copied to the clipboard`,
308+
},
309+
(answer) => {
310+
if (answer !== undefined) clipboardReadDecisions.set(origin, answer);
311+
callback(answer === true);
312+
},
313+
);
314+
};
251315
// Rewriting Electron's native User-Agent makes Turnstile fail integrity checks with error 600010.
252316
browserSession.setPermissionRequestHandler(
253317
(webContents, permission, callback, details) => {
@@ -259,11 +323,21 @@ export const make = Effect.gen(function* BrowserSessionMake() {
259323
);
260324
return;
261325
}
326+
if (permission === "clipboard-read") {
327+
confirmClipboardRead(
328+
webContents,
329+
"requestingUrl" in details ? details.requestingUrl : undefined,
330+
callback,
331+
);
332+
return;
333+
}
262334
callback(ALLOWED_PREVIEW_PERMISSIONS.has(permission));
263335
},
264336
);
265-
browserSession.setPermissionCheckHandler((_webContents, permission) =>
266-
ALLOWED_PREVIEW_PERMISSIONS.has(permission),
337+
browserSession.setPermissionCheckHandler((_webContents, permission, requestingOrigin) =>
338+
permission === "clipboard-read"
339+
? clipboardReadDecisions.get(permissionOrigin(requestingOrigin) ?? "") === true
340+
: ALLOWED_PREVIEW_PERMISSIONS.has(permission),
267341
);
268342
const next = new Map(sessions);
269343
next.set(partition, browserSession);

‎apps/mobile/deps/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
The Enriched Markdown tarball comes from Julius's [`fork/t3-mobile` branch](https://github.com/pingdotgg/enriched-markdown/tree/fork/t3-mobile). Its `t3-fork.json` records the exact source commit and upstream base. React block renderers and signed image sources (`renderers`, `resolveImageSource`) are upstream. The fork carries native streaming memory bounds (an 8 MiB measurement-key budget and coalesced pending renders), plus changes with an open upstream PR: the `onLinksChange` link list that link pills and iOS link menus read ([#1088](https://github.com/software-mansion/enriched-markdown/pull/1088)), Android inline image alignment ([#1089](https://github.com/software-mansion/enriched-markdown/pull/1089)), clipboard link metadata ([#962](https://github.com/software-mansion/enriched-markdown/pull/962)), and development-host autolinks ([#961](https://github.com/software-mansion/enriched-markdown/pull/961)).
1+
The Enriched Markdown tarball comes from Julius's [`fork/t3-mobile` branch](https://github.com/pingdotgg/enriched-markdown/tree/fork/t3-mobile). Its `t3-fork.json` records the exact source commit and upstream base. React block renderers and signed image sources (`renderers`, `resolveImageSource`) are upstream. The fork carries native streaming memory bounds (an 8 MiB measurement-key budget and coalesced pending renders), plus changes with an open upstream PR: the `onLinksChange` link list that link pills and iOS link menus read ([#1088](https://github.com/software-mansion/enriched-markdown/pull/1088)), Android inline image alignment ([#1089](https://github.com/software-mansion/enriched-markdown/pull/1089)), clipboard link metadata ([#962](https://github.com/software-mansion/enriched-markdown/pull/962)), development-host autolinks ([#961](https://github.com/software-mansion/enriched-markdown/pull/961)), and `md4cFlags.preserveWindowsPaths`, which keeps backslashes in Windows drive paths in prose ([#1105](https://github.com/software-mansion/enriched-markdown/pull/1105), after [md4c#5](https://github.com/software-mansion-labs/md4c/pull/5)).
22

33
To replace it, commit the fork changes, run `yarn install --immutable` and `yarn workspace react-native-enriched-markdown prepare` in the fork checkout, then `node scripts/pack-t3.mjs /path/to/t3code/apps/mobile/deps`. Keep the package version aligned with Julius's `fork/t3-mobile` branch. Rename the archive to include the first eight characters of the source commit, such as `react-native-enriched-markdown-1.2.0-t3.16-8d2f84a8.tgz`, so each build has a distinct dependency path without version bumps. Update the tarball path in `apps/mobile/package.json` and `pnpm-workspace.yaml`'s `allowBuilds`, and run `vp i` to update the lockfile. Native clients need rebuilding when this dependency changes.
Binary file not shown.
Binary file not shown.

‎apps/mobile/modules/t3-review-diff/android/src/main/java/expo/modules/t3reviewdiff/T3ReviewDiffView.kt‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,13 +1423,24 @@ private fun centeredBaseline(top: Int, bottom: Int, paint: Paint): Float {
14231423
return (top + bottom) / 2f - (metrics.ascent + metrics.descent) / 2f
14241424
}
14251425

1426+
// A single-line preview never shows this many characters, so longer text is cut before measuring.
1427+
private const val ELLIPSIZE_MAX_CHARS = 500
1428+
14261429
private fun ellipsize(value: String, paint: Paint, width: Float): String {
1427-
if (paint.measureText(value) <= width) return value
1430+
val truncated = value.length > ELLIPSIZE_MAX_CHARS
1431+
val capEnd = surrogateSafeEnd(value, ELLIPSIZE_MAX_CHARS)
1432+
val text = if (truncated) value.substring(0, capEnd) else value
1433+
if (!truncated && paint.measureText(text) <= width) return value
14281434
val suffix = "..."
14291435
val available = max(0f, width - paint.measureText(suffix))
1430-
var end = value.length
1431-
while (end > 0 && paint.measureText(value, 0, end) > available) end -= 1
1432-
return value.substring(0, end) + suffix
1436+
val end = surrogateSafeEnd(text, paint.breakText(text, true, available, null))
1437+
return text.substring(0, end) + suffix
1438+
}
1439+
1440+
private fun surrogateSafeEnd(value: String, end: Int): Int {
1441+
val splitsPair = end in 1 until value.length &&
1442+
Character.isSurrogatePair(value[end - 1], value[end])
1443+
return if (splitsPair) end - 1 else end
14331444
}
14341445

14351446
private fun indexFileHeaders(rows: List<DiffRow>): IntArray {

0 commit comments

Comments
 (0)