Skip to content

Commit c933b20

Browse files
Merge origin/main into factory/issue-36012
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents 29a5469 + 0af8be3 commit c933b20

28 files changed

Lines changed: 620 additions & 133 deletions

‎.github/VOUCHED.td‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ github:btsouth
2222
github:cestercian
2323
github:chrisdeeming
2424
github:chuks-qua
25+
-github:coygeek Filed over 270 automated issues, about 50 a day at peak, far past what maintainers can triage
2526
github:cursoragent
2627
github:D3OXY
2728
github:dbalders

‎.github/workflows/issue-vouch.yml‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Issue Vouch
2+
3+
on:
4+
issues:
5+
types: [opened, reopened]
6+
push:
7+
branches:
8+
- main
9+
paths:
10+
- .github/VOUCHED.td
11+
- .github/workflows/issue-vouch.yml
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
issues: write
17+
18+
concurrency:
19+
group: issue-vouch-${{ github.event.issue.number || 'all' }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
label:
24+
name: Label issues by author trust
25+
runs-on: ubuntu-24.04
26+
steps:
27+
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
28+
with:
29+
script: |
30+
const { owner, repo } = context.repo;
31+
// Only listed authors get a label; open issues number in the thousands,
32+
// so unvouched is the default and stays unlabelled.
33+
const labelByStatus = { vouched: "vouch:trusted", denounced: "vouch:denounced" };
34+
const managedLabelNames = new Set(["vouch:trusted", "vouch:unvouched", "vouch:denounced"]);
35+
36+
const { data: file } = await github.rest.repos.getContent({
37+
owner,
38+
repo,
39+
path: ".github/VOUCHED.td",
40+
ref: context.payload.repository.default_branch,
41+
});
42+
const statusByUser = new Map();
43+
for (const raw of Buffer.from(file.content, "base64").toString("utf8").split("\n")) {
44+
const match = /^(-?)github:(\S+)/.exec(raw.trim());
45+
if (match) statusByUser.set(match[2].toLowerCase(), match[1] ? "denounced" : "vouched");
46+
}
47+
48+
const issues =
49+
context.eventName === "issues"
50+
? [context.payload.issue]
51+
: (
52+
await github.paginate(github.rest.issues.listForRepo, {
53+
owner,
54+
repo,
55+
state: "open",
56+
per_page: 100,
57+
})
58+
).filter((issue) => !issue.pull_request);
59+
60+
for (const issue of issues) {
61+
const status = statusByUser.get(issue.user.login.toLowerCase());
62+
const next = labelByStatus[status];
63+
const current = issue.labels.map((label) => label.name).filter((name) => managedLabelNames.has(name));
64+
65+
for (const name of current) {
66+
if (name === next) continue;
67+
try {
68+
await github.rest.issues.removeLabel({ owner, repo, issue_number: issue.number, name });
69+
} catch (error) {
70+
if (error.status !== 404) throw error;
71+
}
72+
}
73+
if (next && !current.includes(next)) {
74+
await github.rest.issues.addLabels({ owner, repo, issue_number: issue.number, labels: [next] });
75+
core.info(`Issue #${issue.number} (${issue.user.login}): ${status} -> ${next}`);
76+
}
77+
}

‎.github/workflows/pr-vouch.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ jobs:
101101
{
102102
name: "vouch:trusted",
103103
color: "1f883d",
104-
description: "PR author is trusted by repo permissions or the VOUCHED list.",
104+
description: "Author is trusted by repo permissions or the VOUCHED list.",
105105
},
106106
{
107107
name: "vouch:unvouched",
108108
color: "fbca04",
109-
description: "PR author is not yet trusted in the VOUCHED list.",
109+
description: "Author is not yet trusted in the VOUCHED list.",
110110
},
111111
{
112112
name: "vouch:denounced",
113113
color: "d1242f",
114-
description: "PR author is explicitly blocked by the VOUCHED list.",
114+
description: "Author is explicitly blocked by the VOUCHED list.",
115115
},
116116
];
117117

‎apps/mobile/src/features/review/ReviewCommentComposerSheet.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TextInputWrapper } from "expo-paste-input";
33
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
44
import { useMemo, useState } from "react";
55
import { ScrollView, View, useWindowDimensions } from "react-native";
6+
import * as Dialog from "../../components/ui/Dialog";
67
import { FilePreviewModal, type FilePreviewSource } from "../../components/ui/FilePreviewModal";
78

89
import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
@@ -86,13 +87,14 @@ export function ReviewCommentComposerSheet(props: ReviewCommentComposerSheetProp
8687
const handleNativePaste = useNativePaste((uris) => {
8788
void (async () => {
8889
try {
89-
const images = await convertPastedImagesToAttachments({
90+
const result = await convertPastedImagesToAttachments({
9091
uris,
9192
existingCount: attachments.length,
9293
});
93-
if (images.length > 0) {
94-
setAttachments((current) => [...current, ...images]);
94+
if (result.attachments.length > 0) {
95+
setAttachments((current) => [...current, ...result.attachments]);
9596
}
97+
if (result.error) Dialog.alert("Could not paste image", result.error);
9698
} catch (error) {
9799
console.error("[review comment] error converting pasted images", error);
98100
}

‎apps/mobile/src/features/threads/QuestionAttachments.tsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,17 @@ export function QuestionAttachments(props: {
109109
uris,
110110
existingCount: appAtomRegistry.get(composerDraftsAtom)[key]?.attachments.length ?? 0,
111111
})
112-
.then(async (images) => {
112+
.then(async (result) => {
113113
if (
114114
scope.active &&
115115
(appAtomRegistry.get(questionAttachmentPreparationAtom)[key] ?? 0) > 0
116116
) {
117-
if (append(key, images) > 0)
118-
Dialog.alert("Could not paste image", "Too many attachments.");
119-
} else await releaseUnusedComposerAttachmentFiles(images);
117+
const problems = [
118+
...(result.error ? [result.error] : []),
119+
...(append(key, result.attachments) > 0 ? ["Too many attachments."] : []),
120+
];
121+
if (problems.length) Dialog.alert("Could not paste image", problems.join("\n\n"));
122+
} else await releaseUnusedComposerAttachmentFiles(result.attachments);
120123
})
121124
.catch((error) =>
122125
Dialog.alert(

‎apps/mobile/src/lib/composerImagePreview.test.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ vi.mock("expo-file-system", () => ({
3232
return mocks.write(content, options);
3333
}
3434
async move(destination: { uri: string }) {
35-
mocks.files.delete(this.uri);
35+
if (!mocks.files.delete(this.uri)) throw new Error("source missing");
3636
mocks.files.add(destination.uri);
3737
this.uri = destination.uri;
3838
}
@@ -103,4 +103,32 @@ describe("materializedPreviewAtom", () => {
103103
expect(await materialize()).toBe("file:///cache/t3-composer-previews/image-failed.png");
104104
expect(mocks.write).toHaveBeenCalledTimes(2);
105105
});
106+
107+
it("shares one write when the atom is rebuilt while its preview is still being written", async () => {
108+
const attachment: DraftComposerImageAttachment = {
109+
id: "image-rebuilt",
110+
type: "image",
111+
name: "pasted.jpeg",
112+
mimeType: "image/jpeg",
113+
sizeBytes: 3,
114+
previewUri: "data:image/jpeg;base64,AAAA",
115+
};
116+
const read = () => {
117+
const registry = AtomRegistry.make();
118+
const atom = materializedPreviewAtom(new MaterializedPreviewKey(attachment));
119+
const unmount = registry.mount(atom);
120+
return vi
121+
.waitFor(() => {
122+
const result = registry.get(atom);
123+
expect(AsyncResult.isSuccess(result)).toBe(true);
124+
return AsyncResult.isSuccess(result) ? result.value : undefined;
125+
})
126+
.finally(unmount);
127+
};
128+
129+
expect(await Promise.all([read(), read()])).toEqual([
130+
"file:///cache/t3-composer-previews/image-rebuilt.jpg",
131+
"file:///cache/t3-composer-previews/image-rebuilt.jpg",
132+
]);
133+
});
106134
});

‎apps/mobile/src/lib/composerImagePreview.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ async function materializeDataUrlPreview(id: string, dataUrl: string): Promise<s
3232
return file.uri;
3333
}
3434

35+
const inFlightPreviews = new Map<string, Promise<string | null>>();
36+
37+
// A render reads the atom before its effect subscribes, so the registry can drop and rebuild it
38+
// mid-write; a second writer would delete the first one's partial file and fail its own move.
39+
function materializePreviewOnce(id: string, dataUrl: string): Promise<string | null> {
40+
const pending = inFlightPreviews.get(id);
41+
if (pending) return pending;
42+
const next = materializeDataUrlPreview(id, dataUrl).finally(() => inFlightPreviews.delete(id));
43+
inFlightPreviews.set(id, next);
44+
return next;
45+
}
46+
3547
class ImagePreviewCacheError extends Schema.TaggedError<ImagePreviewCacheError>()(
3648
"ImagePreviewCacheError",
3749
{ cause: Schema.Defect() },
@@ -59,7 +71,7 @@ export class MaterializedPreviewKey implements Equal.Equal {
5971
export const materializedPreviewAtom = Atom.family(({ attachment }: MaterializedPreviewKey) =>
6072
Atom.make(
6173
Effect.tryPromise({
62-
try: () => materializeDataUrlPreview(attachment.id, attachment.previewUri),
74+
try: () => materializePreviewOnce(attachment.id, attachment.previewUri),
6375
catch: (cause) => new ImagePreviewCacheError({ cause }),
6476
}).pipe(
6577
Effect.catch((error) =>

‎apps/mobile/src/lib/composerImages.test.ts‎

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ vi.mock("./uuid", () => ({
121121

122122
import { convertPastedImagesToAttachments, persistComposerAttachmentFile } from "./composerImages";
123123

124+
function oversizedPng(): string {
125+
const png = Buffer.alloc(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1);
126+
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]).copy(png);
127+
png.write("IHDR", 12);
128+
png.writeUInt32BE(2000, 16);
129+
png.writeUInt32BE(2000, 20);
130+
return png.toString("base64");
131+
}
132+
124133
describe("native pasted image cleanup", () => {
125134
beforeEach(() => {
126135
files.clear();
@@ -131,7 +140,10 @@ describe("native pasted image cleanup", () => {
131140
const uri = "content://media/external/images/media/42";
132141
files.set(uri, { base64: "aGVsbG8=", deleted: false, mimeType: "image/jpeg" });
133142

134-
const attachments = await convertPastedImagesToAttachments({ uris: [uri], existingCount: 0 });
143+
const { attachments } = await convertPastedImagesToAttachments({
144+
uris: [uri],
145+
existingCount: 0,
146+
});
135147

136148
expect(attachments).toEqual([
137149
expect.objectContaining({
@@ -149,7 +161,10 @@ describe("native pasted image cleanup", () => {
149161
files.set(uri, { base64: "b3JpZ2luYWw=", deleted: false, mimeType: "image/heic" });
150162
manipulator.state.sourceSize = { width: 100, height: 100 };
151163

152-
const attachments = await convertPastedImagesToAttachments({ uris: [uri], existingCount: 0 });
164+
const { attachments } = await convertPastedImagesToAttachments({
165+
uris: [uri],
166+
existingCount: 0,
167+
});
153168

154169
expect(attachments).toEqual([
155170
expect.objectContaining({
@@ -171,7 +186,10 @@ describe("native pasted image cleanup", () => {
171186
Math.ceil((PROVIDER_SEND_TURN_MAX_IMAGE_BYTES + 1) / 3) * 4,
172187
);
173188

174-
const attachments = await convertPastedImagesToAttachments({ uris: [uri], existingCount: 0 });
189+
const { attachments } = await convertPastedImagesToAttachments({
190+
uris: [uri],
191+
existingCount: 0,
192+
});
175193

176194
expect(attachments).toEqual([]);
177195
expect(files.get("file:///cache/rendered.jpeg")?.deleted).toBe(true);
@@ -183,7 +201,7 @@ describe("native pasted image cleanup", () => {
183201
"file:///private/var/mobile/Containers/Data/Application/app/tmp/t3-composer-paste/id.png";
184202
files.set(uri, { base64: "aGVsbG8=", deleted: false });
185203

186-
const attachments = await convertPastedImagesToAttachments({
204+
const { attachments } = await convertPastedImagesToAttachments({
187205
uris: [uri],
188206
existingCount: 0,
189207
});
@@ -216,6 +234,53 @@ describe("native pasted image cleanup", () => {
216234
expect(files.get(overflow)?.deleted).toBe(true);
217235
expect(files.get(userOwned)?.deleted).toBe(false);
218236
});
237+
238+
it("re-renders an over-limit paste whose dimensions already fit, like the photo picker", async () => {
239+
const uri =
240+
"file:///private/var/mobile/Containers/Data/Application/app/tmp/t3-composer-paste/photo.png";
241+
files.set(uri, { base64: oversizedPng(), deleted: false });
242+
manipulator.state.sourceSize = { width: 2000, height: 2000 };
243+
244+
const { attachments } = await convertPastedImagesToAttachments({
245+
uris: [uri],
246+
existingCount: 0,
247+
});
248+
249+
expect(attachments).toHaveLength(1);
250+
expect(attachments[0]?.sizeBytes).toBeLessThanOrEqual(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES);
251+
expect(files.get("file:///cache/rendered.jpeg")?.deleted).toBe(true);
252+
});
253+
254+
it("keeps the readable images of a paste and still reports the one it dropped", async () => {
255+
const gone =
256+
"file:///private/var/mobile/Containers/Data/Application/app/tmp/t3-composer-paste/gone.png";
257+
const kept =
258+
"file:///private/var/mobile/Containers/Data/Application/app/tmp/t3-composer-paste/kept.png";
259+
files.set(kept, { base64: "aGVsbG8=", deleted: false });
260+
261+
const result = await convertPastedImagesToAttachments({ uris: [gone, kept], existingCount: 0 });
262+
263+
expect(result.attachments).toEqual([
264+
expect.objectContaining({ dataUrl: "data:image/png;base64,aGVsbG8=" }),
265+
]);
266+
expect(result.error).toBe("Could not read a pasted image.");
267+
});
268+
269+
it("reports the size limit when even the JPEG re-render is too large", async () => {
270+
const uri =
271+
"file:///private/var/mobile/Containers/Data/Application/app/tmp/t3-composer-paste/huge.png";
272+
files.set(uri, { base64: oversizedPng(), deleted: false });
273+
manipulator.state.sourceSize = { width: 2000, height: 2000 };
274+
manipulator.state.renderedBase64 = oversizedPng();
275+
276+
const result = await convertPastedImagesToAttachments({ uris: [uri], existingCount: 0 });
277+
278+
expect(result).toEqual({
279+
attachments: [],
280+
error: "A pasted image exceeds the 10 MB attachment limit.",
281+
});
282+
expect(files.get(uri)?.deleted).toBe(true);
283+
});
219284
});
220285

221286
describe("persistComposerAttachmentFile", () => {

0 commit comments

Comments
 (0)