Skip to content

refactor(agent-core): unify image extension sniff-failed detection - #974

Merged
7Sageer merged 1 commit into
MoonshotAI:mainfrom
7Sageer:refactor/agent-core-image-extension-guard
Jun 22, 2026
Merged

refactor(agent-core): unify image extension sniff-failed detection#974
7Sageer merged 1 commit into
MoonshotAI:mainfrom
7Sageer:refactor/agent-core-image-extension-guard

Conversation

@7Sageer

@7Sageer 7Sageer commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Follow-up to #970 (review feedback); no separate issue.

Problem

detectFileType expressed the rule "an image extension without confirming magic is not an image" twice — once in the media-mode branch and once in the text-mode fall-through — each with its own copy of the same comment. The rule is mode-independent, so the duplication forces any future change to this path to be edited in two places, or the two modes silently diverge.

Two test gaps from #970 are also closed here: the text-mode behavior change (an image-extension file whose bytes are not an image is reported as unknown rather than image) was not covered by the Read tool tests, and the matching file-type test only exercised text mode while its comment described media mode.

What changed

  • Merge the two duplicate image-extension guards into a single mode-independent check, keeping the video extension fallback before the NUL check so video containers with no magic still win. No behavior change.
  • Add a Read tool test: an image-extension file with non-image bytes is rejected as "not readable" instead of being redirected to ReadMediaFile.
  • Align the file-type test to assert the sniff-failed image case in both media and text modes, matching its comment.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Merge the two duplicate image-extension guards in detectFileType into a single mode-independent rule: an image extension without confirming magic is not an image in any mode. The video extension fallback stays before the NUL check so video containers with no magic still win. No behavior change.

Add and align tests: Read rejects an image-extension file with non-image bytes as not readable instead of redirecting to ReadMediaFile; file-type asserts the sniff-failed image case in both media and text modes.
@changeset-bot

changeset-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d866b78

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@d866b78
npx https://pkg.pr.new/@moonshot-ai/kimi-code@d866b78

commit: d866b78

@7Sageer
7Sageer merged commit d434d8f into MoonshotAI:main Jun 22, 2026
9 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant