feat(twitter): add --images flag to post command#666
feat(twitter): add --images flag to post command#666jackwener merged 5 commits intojackwener:mainfrom
Conversation
Support attaching up to 4 images when posting tweets via `opencli twitter post "text" --images /path/a.png,/path/b.jpg`. Uses the existing CDP DOM.setFileInputFiles mechanism (page.setFileInput) to inject files into Twitter's file input. Includes proper file validation, graceful error handling for older extensions, and polling-based upload readiness detection instead of fixed delays. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
One concrete issue here: the new "wait for image upload" check is using the tweet button enabled state as the upload-complete signal, but That means So for a text+image tweet this can silently post the text without the images, or with only a partially finished upload, while still reporting success. I think the wait condition needs to watch an actual media-upload completion signal in the DOM, not the generic button enabled state. There also does not seem to be any test coverage for the new image path. The diff only changes |
Replace unreliable tweet-button-only polling with dual-condition check: wait for [data-testid="attachments"] with correct [role="group"] count AND button enabled. Increase timeout to 30s. Add 8 unit tests covering image upload flow, file validation, and error paths. Addresses PR jackwener#666 review feedback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@Astro-Han Thanks for the review! Addressed both points:
|
- Use top-level fs/path imports instead of dynamic imports inside func - Fix test statSync mock to return undefined (not null) for missing files - Fix test path mock to preserve other exports via importOriginal - Fix null type error in no-browser-session test - Reduce upload poll interval from 1s to 500ms for faster detection - Use JSON.stringify for imageCount interpolation for consistency
- Extract validateImagePaths() with extension validation (jpg/png/gif/webp) matching xiaohongshu publish pattern - Validate images before browser navigation (fail-fast on bad input) - Remove try/catch wrapper around setFileInput — let errors propagate naturally instead of masking the original error - Deduplicate tweetButton/tweetButtonInline lookups using fallback OR - Use constants for MAX_IMAGES, UPLOAD_POLL_MS, UPLOAD_TIMEOUT_MS - Add tests: unsupported format, validates-before-navigating
* feat(twitter): add --images flag to post command Support attaching up to 4 images when posting tweets via `opencli twitter post "text" --images /path/a.png,/path/b.jpg`. Uses the existing CDP DOM.setFileInputFiles mechanism (page.setFileInput) to inject files into Twitter's file input. Includes proper file validation, graceful error handling for older extensions, and polling-based upload readiness detection instead of fixed delays. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(twitter): use attachments DOM signal for upload detection, add tests Replace unreliable tweet-button-only polling with dual-condition check: wait for [data-testid="attachments"] with correct [role="group"] count AND button enabled. Increase timeout to 30s. Add 8 unit tests covering image upload flow, file validation, and error paths. Addresses PR jackwener#666 review feedback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix(twitter): use top-level imports, fix test mocks, faster upload poll - Use top-level fs/path imports instead of dynamic imports inside func - Fix test statSync mock to return undefined (not null) for missing files - Fix test path mock to preserve other exports via importOriginal - Fix null type error in no-browser-session test - Reduce upload poll interval from 1s to 500ms for faster detection - Use JSON.stringify for imageCount interpolation for consistency * refactor(twitter): extract validation, fail-fast, reduce duplication - Extract validateImagePaths() with extension validation (jpg/png/gif/webp) matching xiaohongshu publish pattern - Validate images before browser navigation (fail-fast on bad input) - Remove try/catch wrapper around setFileInput — let errors propagate naturally instead of masking the original error - Deduplicate tweetButton/tweetButtonInline lookups using fallback OR - Use constants for MAX_IMAGES, UPLOAD_POLL_MS, UPLOAD_TIMEOUT_MS - Add tests: unsupported format, validates-before-navigating --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: jackwener <jakevingoo@gmail.com>
Summary
--imagesoption totwitter postcommand, supporting up to 4 images (comma-separated paths)page.setFileInput()(CDPDOM.setFileInputFiles) to attach files to Twitter's file inputstatSyncchecks), graceful error handling for older extensions, and polling-based upload readiness detectionUsage
Test plan
npx tsc --noEmitpassesnpm testpasses (456 passed)🤖 Generated with Claude Code