Fix stale binary image fallback for empty modified diffs and relay reads

- mobileDiffImageDataUri now distinguishes a true deletion (modified
  side absent) from a modify whose binary bytes arrived empty
  (relay/size-cap cases), returning null instead of the stale
  pre-change image
- readWorkingDiffFile passes the file path to bufferToBlob so relay
  working-tree reads can detect previewable image extensions instead
  of always reporting empty binary content
- add mobile-file-tab-doc.test.ts covering diff/image/binary/text
  resolution paths
This commit is contained in:
Jinjing
2026-07-16 16:46:59 -07:00
parent 6fffc55102
commit 115b87efe4
5 changed files with 212 additions and 6 deletions
+12
View File
@@ -35,4 +35,16 @@ describe('readWorkingDiffFile', () => {
isBinary: true
})
})
it('base64-encodes a previewable image by its extension', async () => {
tmpDir = await mkdtemp(path.join(tmpdir(), 'relay-working-file-'))
const filePath = path.join(tmpDir, 'icon.png')
const pngBytes = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x01])
await writeFile(filePath, pngBytes)
await expect(readWorkingDiffFile(filePath)).resolves.toEqual({
content: pngBytes.toString('base64'),
isBinary: true
})
})
})
+3 -1
View File
@@ -16,7 +16,9 @@ export async function readWorkingDiffFile(
return { content: '', isBinary: true }
}
const buffer = await readFile(absPath)
return bufferToBlob(buffer)
// Why: bufferToBlob needs the path's extension to know an image is
// previewable; omitting it made every relay-side binary diff empty.
return bufferToBlob(buffer, absPath)
} catch {
return { content: '', isBinary: false }
}