Skip to content

feat(fileupload): add path encoder and content transcoder options - #666

Open
florinMiro wants to merge 2 commits into
mainfrom
feat/fileupload-path-content-transform-options
Open

feat(fileupload): add path encoder and content transcoder options#666
florinMiro wants to merge 2 commits into
mainfrom
feat/fileupload-path-content-transform-options

Conversation

@florinMiro

@florinMiro florinMiro commented Jul 24, 2026

Copy link
Copy Markdown

Description

Add WithPathEncoder and WithContentTranscoder functional options to the high-level file upload client (pkg/apiclients/fileupload). They let callers URI-encode upload paths and transcode file content (e.g. to UTF-8) without exposing the internal upload revision client. Both default to no-op, so existing callers are unaffected.

Both hooks are applied before the client-side filters and the batch size accounting run, so those see exactly what will be transmitted:

  • WithPathEncoder is applied right after the relative path is computed, so the path length filter, the paths reported for skipped files, and the transmitted path all see the encoded value. The filesystem path the file is read from is unchanged.
  • WithContentTranscoder wraps each opened file before it is stat'ed, so the file size filter and the payload size accounting use the transcoded size. The transcoded file must report its own size and mode from Stat, which is what the low level client already relies on when validating a batch.

Checklist

  • Tests added and all succeed (make test)
  • Regenerated mocks, etc. (make generate)
  • Linted (make lint)
  • Test your changes work for the CLI

🤖 Generated with Claude Code


Note

Medium Risk
Changes the upload batching pipeline and file descriptor lifecycle; incorrect transcoder Stat or path encoding could cause wrong limits or skipped files, though defaults preserve existing behavior and tests cover the new paths.

Overview
Adds WithPathEncoder and WithContentTranscoder on the high-level file upload client so callers can transform upload paths (e.g. URI encoding) and file streams (e.g. UTF-8) without touching the internal revision client. Both default to no-op.

Encoding runs on the relative upload path before open; limits, skipped-file reporting, and transmitted paths use the encoded value while reads still use the real filesystem path. Transcoding wraps each opened file before Stat and filtering, so per-file size, batch payload accounting, and uploads reflect transcoded content. A transcodedFile wrapper always closes the underlying OS file when the transcoder does not delegate Close. Size-limit skip reasons now reference the upload path instead of the stat name.

Reviewed by Cursor Bugbot for commit 16db50c. Bugbot is set up for automated code reviews on this repo. Configure here.

@snyk-io

snyk-io Bot commented Jul 24, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues
Secrets 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-io

snyk-io Bot commented Jul 24, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@florinMiro
florinMiro force-pushed the feat/fileupload-path-content-transform-options branch 2 times, most recently from e9c34a4 to 49ab5ac Compare July 24, 2026 13:07
@florinMiro
florinMiro marked this pull request as ready for review July 24, 2026 13:59
@florinMiro
florinMiro requested review from a team as code owners July 24, 2026 13:59

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 49ab5ac. Configure here.

Comment thread pkg/apiclients/fileupload/batch.go Outdated
@snyk-pr-review-bot

This comment has been minimized.

Add WithPathEncoder and WithContentTranscoder to the high level file upload
client. They let callers URI-encode upload paths and transcode file content,
e.g. to UTF-8, without exposing the internal upload revision client. Both
default to no-op, so existing callers are unaffected.

Both are applied before the client side filters and the batch size
accounting run, so those see what is transmitted rather than what is on
disk: the path length filter measures the encoded path, and the file size
filter and payload size accounting use the size the transcoded file reports
from Stat. This is the same file the low level client stats when it
validates a batch.

The transcoded file is paired with the file it was opened from so that
closing it releases the file descriptor even when the transcoder's wrapper
does not delegate Close, and a file the transcoder fails on is skipped like
any other unreadable file instead of failing the whole revision while its
content is streamed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@florinMiro
florinMiro force-pushed the feat/fileupload-path-content-transform-options branch from f1964a6 to 359f665 Compare July 27, 2026 10:08
@florinMiro
florinMiro marked this pull request as ready for review July 27, 2026 10:08
@snyk-pr-review-bot

This comment has been minimized.

@snyk-pr-review-bot

Copy link
Copy Markdown

PR Reviewer Guide 🔍

🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected
📚 Repository Context Analyzed

This review considered 15 relevant code sections from 15 files (average relevance: 0.94)

🤖 Repository instructions applied (from AGENTS.md)

osFile, err := os.Open(path)
if err != nil {
logger.Debug().Msgf("failed to open file: %s", path)
f.Close()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why was this removed here? It is a bind mind bending to understand, maybe we can make this easier?

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.

2 participants