Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(debug): improve attachment source checking

Steven Enamakelf4e244333d07
diff --git a/scripts/debug/web-scripts/queued-image-attachment-roundtrip.mjs b/scripts/debug/web-scripts/queued-image-attachment-roundtrip.mjs
index 57cbf1beeb..236fb37547 100644
--- a/scripts/debug/web-scripts/queued-image-attachment-roundtrip.mjs
+++ b/scripts/debug/web-scripts/queued-image-attachment-roundtrip.mjs
@@ -38,6 +38,17 @@ function findStoredBytes(root, expected) {
return null;
}
+function hasSourceAuthority(value) {
+ if (Array.isArray(value)) return value.some(hasSourceAuthority);
+ if (!value || typeof value !== "object") return false;
+ return Object.entries(value).some(([key, child]) =>
+ (["path", "url", "localCachePath"].includes(key) &&
+ typeof child === "string" &&
+ child.length > 0) ||
+ hasSourceAuthority(child),
+ );
+}
+
async function waitUntil(predicate, label, timeoutMs = 10_000) {
const deadline = Date.now() + timeoutMs;
while (Date.now() < deadline) {
@@ -206,9 +217,8 @@ export default async function queuedImageAttachmentRoundtrip({
);
}
if (
- JSON.stringify(pending.attachments).match(
- /data:|base64|"(?:path|url|localCachePath)"\s*:/i,
- )
+ /data:[^\s\"]+|base64,/i.test(JSON.stringify(pending.attachments)) ||
+ hasSourceAuthority(pending.attachments)
) {
throw new Error("queued UI state retained upload bytes or a source path");
}
diff --git a/scripts/debug/web-scripts/typed-image-attachment-roundtrip.mjs b/scripts/debug/web-scripts/typed-image-attachment-roundtrip.mjs
index cae13d9697..773d2b818b 100644
--- a/scripts/debug/web-scripts/typed-image-attachment-roundtrip.mjs
+++ b/scripts/debug/web-scripts/typed-image-attachment-roundtrip.mjs
@@ -36,6 +36,17 @@ function findStoredBytes(root, expected) {
return null;
}
+function hasSourceAuthority(value) {
+ if (Array.isArray(value)) return value.some(hasSourceAuthority);
+ if (!value || typeof value !== "object") return false;
+ return Object.entries(value).some(([key, child]) =>
+ (["path", "url", "localCachePath"].includes(key) &&
+ typeof child === "string" &&
+ child.length > 0) ||
+ hasSourceAuthority(child),
+ );
+}
+
export default async function typedImageAttachmentRoundtrip({
page,
mock,
@@ -184,11 +195,12 @@ export default async function typedImageAttachmentRoundtrip({
)
throw new Error("chat turn did not carry the persisted opaque media ref");
if (
- JSON.stringify(chatRequest.params.attachments).match(
- /data:|base64|"(?:path|url)"\s*:/i,
- )
+ /data:[^\s\"]+|base64,/i.test(JSON.stringify(chatRequest.params.attachments)) ||
+ hasSourceAuthority(chatRequest.params.attachments)
)
- throw new Error("chat turn sent source bytes or a filesystem/network path");
+ throw new Error(
+ `chat turn sent source bytes or a filesystem/network path: ${JSON.stringify(chatRequest.params.attachments)}`,
+ );
const inferenceRequest = mock
.requests()