Skip to content

fix(drive): download the target of a shortcut - #1315

Closed
saariuslystoned wants to merge 2 commits into
openclaw:mainfrom
saariuslystoned:fix/drive-download-shortcut-target
Closed

saariuslystoned wants to merge 2 commits into
openclaw:mainfrom
saariuslystoned:fix/drive-download-shortcut-target

Conversation

@saariuslystoned

Copy link
Copy Markdown
Contributor

What problem this solves

A Drive shortcut (application/vnd.google-apps.shortcut) is a metadata-only file. The Drive shortcuts guide describes it as a link holding shortcutDetails.targetId, with its own title, and that title can differ from the target's. gog drive ls and drive search list shortcuts beside regular files, so gog drive download <id> on a listed item often gets a shortcut ID.

drive download treats every application/vnd.google-apps.* MIME type as a Workspace document. For a shortcut it therefore calls files.export on the shortcut itself with application/pdf. A shortcut has no content to export, so the download fails instead of fetching the file the shortcut points to.

Change

drive download now also requests shortcutDetails(targetId) in its metadata call. When the file is a shortcut, it reads the target's id, name, mimeType and continues with the target. A blob target is downloaded with alt=media, and a Docs Editors target is exported, including --format. A file name chosen by gog comes from the target (<targetId>_<name>), so it carries the real extension.

If the target can't be read (deleted, or no longer shared), the error names both IDs and wraps Drive's error. A deleted target still exits not_found (5).

Other files and --tab exports are unchanged. A shortcut to a folder still fails as before, now on the folder.

Evidence

  • internal/cmd/drive_download_shortcut_test.go drives DriveDownloadCmd with Drive metadata from an httptest server and recorded download/export calls. It covers:

    • a shortcut to a PDF, which must be one alt=media download of the target
    • a shortcut to a Google Doc, which must be one export of the target
    • a broken shortcut, which must exit 5 with no content request

    All three fail on main (e8428c3) because gog exports the shortcut ID, and pass with this change. The existing Drive download and get tests pass.

  • A built bin/gog from main and from this branch was run against a local Drive stand-in through GOG_GOOGLE_API_BASE_URL, with an empty GOG_HOME and the file keyring. The stand-in is not Google. It serves sc1 as a shortcut to t1 (report.pdf) and answers an export of anything that isn't a Docs file with a 403 in its own wording:

    main:   GET files/sc1 (fields id, name, mimeType)
            GET files/sc1/export?mimeType=application/pdf  -> 403, exit 6, no file written
    branch: GET files/sc1 (fields id, name, mimeType, shortcutDetails(targetId))
            GET files/t1  (fields id, name, mimeType)
            GET files/t1?alt=media                          -> t1_report.pdf, exit 0
    
  • make ci passed locally (macOS arm64, go1.27.3).

Boundary: no live Google Drive was used, and the exact error Drive returns for exporting a shortcut was not captured. targetResourceKey is not forwarded. drive download sends no resource keys for any file today, so a link-shared target that needs one behaves as it would if downloaded by its own ID.

🤖 Generated with Claude Code

drive download treated every application/vnd.google-apps.* type as a
Workspace document, so a shortcut ID went to files.export, which only
exports Docs Editors files. Read shortcutDetails.targetId and download
or export the target instead. An unreadable target keeps Drive's error,
so a deleted target still exits not_found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Resolve Drive shortcuts to their targets before downloading files or exporting Workspace documents.

Example: Run gog drive download sc1 when shortcut sc1 points to t1, named report.pdf.

  • Before: The CLI attempts to export sc1 as a PDF and fails.
  • After: The CLI downloads t1 and saves t1_report.pdf.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with shipped CLI proof against a local HTTP stand-in and distinct regression coverage.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The supplied terminal trace exercises built main and branch gog binaries through the real CLI and HTTP client against a local Drive stand-in, showing shortcut-to-blob resolution and successful target output; document export and missing-target behavior have supporting command tests, with no live Google Drive claim.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Downloading a shortcut listed by Drive fails instead of retrieving its target file.
Reason: The patch repairs a defined download operation using existing target metadata and transfer owners, with no new option or policy.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main download failure and remains worth merging; the earlier changelog finding is resolved, with no actionable code defects found.

Priority: P2
Reviewed head: 6d9d4aae41b374785469b267b9fcd4826f95b8a9

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Drive download command receives a file ID and output options, reads metadata through the account's Drive service, and sends the resolved file to the existing export or media downloader.

flowchart TD
  A[Drive download command] --> B[Read file metadata]
  B --> C[Resolve shortcut target]
  B --> D[Existing download pipeline]
  C --> D
  D --> E[Drive media or export request]
  E --> F[Output file or stdout]
Loading

Technical review

Best possible solution:

Merge the focused target-resolution fix while retaining the existing downloader and overwrite safeguards.

Do we have a high-confidence way to reproduce the issue?

Current-main source directly shows shortcut IDs reaching files.export, supported by the contributor's before-and-after CLI trace; no target code was run during this read-only review.

Is this the best way to solve the issue?

Resolving metadata once before the existing download pipeline is a small, complete fix for accessible file targets, without duplicating transfer or output logic.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e8428c36dd31.

Provenance checked

  • Drive metadata and export dispatch keeps the original intent (unknown: Commit 917e4b9 moved the command into its module rather than establishing a shortcut policy; scoped history searches encountered unavailable older blobs, leaving the initial MIME-dispatch introduction unknown.)
  • Shortcut semantics keeps the original intent (feat(drive): add shortcut support #763: Expose shortcut targets while preserving exact-ID mutations and treating folder shortcuts as non-traversed leaves.)
  • Local output overwrite protection keeps the original intent (fix(cli): add --overwrite to drive download and slides thumbnail #829: Require explicit --overwrite before replacing existing local output files.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • WadydX: Raw commit fa3fa16 adds internal/cmd/drive_download.go:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: fa3fa1638b5a; files: internal/cmd/drive_download.go)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Patch scope Production +26/-1; tests +112; changelog +2 The production change stays inside the existing command, and three command-level cases cover blob targets, document targets, and missing targets.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Shortcut downloads fail on current main, with a limited blast radius confined to this Drive operation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-08T14:55:17.524Z sha 6bd6cdf :: needs changes before merge. :: [P3] Add the required PR reference to the changelog entry

Reviewed November 8, 2026, 2:19 PM ET / 19:19 UTC (Revision 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@saariuslystoned

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 8, 2026
@steipete

Copy link
Copy Markdown
Collaborator

Thank you for the fix. I reproduced the claim and consolidated downloading or exporting the Drive shortcut target into #1336, with regression coverage and your coauthor credit retained. The full make ci gate, built-CLI checks for the new request-validation fixes, and exact-head GitHub CI passed. Closing this PR as superseded by the merged implementation in #1336.

@steipete steipete closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants