issue-255: Implement extensions/vision/src/images.ts (read, validate, data URLs) #269
No reviewers
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills!269
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/issue-255/implement-extensions-vision-src-images-ts-read-val"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
255: Implement extensions/vision/src/images.ts (read, validate, data URLs)
Closes #255 — 255.
Generated in 1h 02m 04s.
Review findings
I'll start by exploring the repository structure and understanding the current state of the relevant files.
Let me check the exact line numbers referenced in the findings and look at the errors module for consistency.
All line numbers are confirmed. Let me verify the
image-sizepackage exports to confirm finding #4's claim.Confirmed. Let me check what the root
index.d.tsactually exports to pick the right fix.All findings confirmed. Let me check the vision directory for all test files to wire them correctly, and confirm the errors precedent.
Now I'll check for any TypeScript configuration before making edits (to know whether a type-check gate exists).
No tsconfig and no tsc — the only gate is
node --testwith type-stripping. Now I'll apply all four fixes. They're independent, so I'll batch the edits.Let me verify the images.ts edits rendered correctly — I need to double-check the catch block's template literal quoting.
Confirmed a syntax error — the closing backtick got replaced with a
". Let me fix it.Let me fix the exact bytes with a precise Python replacement.
Let me verify the fix and check the whole file parses correctly with Node's type-stripping.
Both files parse. Let me verify the test file's skip edit rendered correctly.
The structure is correct but the indentation is inconsistent. Let me re-indent that block cleanly.
Now let me verify the package.json edit and confirm the test file syntax, then run the full test gate.
All edits applied and syntax is valid. Now let me run the vision tests directly, then the full
npm testgate.All 43 vision tests pass (the unreadable test ran since we're not root). Now the full
npm testgate.The full gate passes: 922 pass / 1 skip / 0 fail — up from 879 pass, with all 43 vision tests now wired in and passing. Let me review the complete working-tree diff to confirm everything is clean.
All four findings are resolved, the working-tree diff is minimal and consistent with the surrounding code, and the full gate passes (922 pass / 1 skip / 0 fail — up from 879, with all 43 vision tests now wired in). Here is the annotated findings document.
Review Findings — issue-255
Summary
All four findings were resolved in a single pass. (1) High: appended
extensions/vision/src/*.test.tstoscripts.test, sonpm testnow runs the vision suite — full gate is 922 pass / 1 skip / 0 fail (was 879 pass), the 43 new vision tests included. (2) Medium: movedfs.promises.readFile(resolved)inside theaccess(R_OK)try/catchso any TOCTOU/IO failure rethrows aToolError(..., "image")instead of a nativeErrnoException. (3) Low: dropped the unexportedimport type { ISizeCalculationResult }and the explicit annotation, letting TypeScript inferimageSize()'s return type. (4) Low: the unreadable-file test now skips via{ skip: process.getuid?.() === 0 }. Nothing left unresolved; no regressions.Critical
High
package.json:32 — The vision test files are not wired into thetestscript, sonpm test(and CI) never runsimages.test.ts(norconfig.test.ts/errors.test.tsfrom the prior milestones). This defeats the gate that is supposed to protect the new module, and contradicts IMPLEMENTATION_PLAN §11 / M8, which lists appending the vision globs toscripts.testas a wiring step. Suggested fix: append the vision globs, e.g. extend thetestscript withextensions/vision/index.test.ts extensions/vision/src/*.test.ts.Medium
extensions/vision/src/images.ts:176 —fs.promises.readFile(resolved)is not wrapped in atry/catch. Theaccess(R_OK)check at line 171 precedes it, but a TOCTOU permission change or a raw I/O error between the two would surface a nativeNodeJS.ErrnoExceptioninstead of aToolError(category === "image"), violating the module's documented contract ("Every failure is aToolErrorwithcategory === "image""). Suggested fix: movereadFileinside theaccesstry/catch(or its owntry/catch) that rethrows aToolError(..., "image").Low
extensions/vision/src/images.ts:29 —import type { ISizeCalculationResult } from "image-size"imports a type that is not exported from the package root (image-sizev2 root only exportsimageSize/disableTypes/types;ISizeCalculationResultlives in a subpath). It only works because Node's type-stripping drops type-only imports at runtime without resolving them; a realtscbuild would hard-fail with "no exported member". Suggested fix: drop the explicitlet detected: ISizeCalculationResultannotation and let TypeScript infer the return type ofimageSize()(removing the broken import), or import from the correct subpath.extensions/vision/src/images.test.ts:226 — The "unreadable file" test blocks reads withfs.chmodSync(file, 0), but a root user bypasses DAC read checks, soaccess(R_OK)andreadFilewould succeed and the assertion would fail if the suite runs as root (e.g. some CI runners). Suggested fix: skip that test whenprocess.getuid?.() === 0, or use a non-root mechanism to make the file unreadable.Low
Empty sections