@sovovs/bycli 1.8.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (509) hide show
  1. package/cli-manifest.json +0 -61
  2. package/dist/src/adapter-shadow.js +2 -2
  3. package/dist/src/browser/analyze.d.ts +10 -99
  4. package/dist/src/browser/analyze.js +10 -226
  5. package/dist/src/browser/cdp.js +64 -7
  6. package/dist/src/browser/navigation-guard.d.ts +78 -0
  7. package/dist/src/browser/navigation-guard.js +142 -0
  8. package/dist/src/browser/navigation-guard.test.d.ts +1 -0
  9. package/dist/src/browser/url-policy.d.ts +89 -0
  10. package/dist/src/browser/url-policy.js +311 -0
  11. package/dist/src/browser/url-policy.test.d.ts +1 -0
  12. package/dist/src/browser/verify-fixture.js +2 -2
  13. package/dist/src/cli.js +10 -13
  14. package/dist/src/config-paths.d.ts +19 -0
  15. package/dist/src/config-paths.js +31 -0
  16. package/dist/src/daemon.js +240 -0
  17. package/dist/src/discovery.d.ts +5 -3
  18. package/dist/src/discovery.js +8 -6
  19. package/dist/src/execution.js +8 -3
  20. package/dist/src/main.js +18 -2
  21. package/dist/src/plugin.js +11 -8
  22. package/dist/src/recorder/highlevel/analyze.d.ts +29 -0
  23. package/dist/src/recorder/highlevel/analyze.js +91 -0
  24. package/dist/src/recorder/highlevel/init.d.ts +125 -0
  25. package/dist/src/recorder/highlevel/init.js +279 -0
  26. package/dist/src/recorder/highlevel/init.test.d.ts +1 -0
  27. package/dist/src/recorder/highlevel/verify.d.ts +73 -0
  28. package/dist/src/recorder/highlevel/verify.js +74 -0
  29. package/dist/src/recorder/http/analyze-runner.d.ts +28 -0
  30. package/dist/src/recorder/http/analyze-runner.js +78 -0
  31. package/dist/src/recorder/http/analyze-runner.test.d.ts +1 -0
  32. package/dist/src/recorder/http/handlers.d.ts +51 -0
  33. package/dist/src/recorder/http/handlers.js +219 -0
  34. package/dist/src/recorder/http/wrapper-config.d.ts +20 -0
  35. package/dist/src/recorder/http/wrapper-config.js +82 -0
  36. package/dist/src/recorder/http/wrapper-envelope.d.ts +31 -0
  37. package/dist/src/recorder/http/wrapper-envelope.js +51 -0
  38. package/dist/src/recorder/http/wrapper-gates.d.ts +16 -0
  39. package/dist/src/recorder/http/wrapper-gates.js +28 -0
  40. package/dist/src/recorder/http/wrapper-metrics.d.ts +1 -0
  41. package/dist/src/recorder/http/wrapper-metrics.js +5 -0
  42. package/dist/src/recorder/http/wrapper-registry.d.ts +50 -0
  43. package/dist/src/recorder/http/wrapper-registry.js +98 -0
  44. package/dist/src/recorder/http/wrapper-server.d.ts +59 -0
  45. package/dist/src/recorder/http/wrapper-server.js +240 -0
  46. package/dist/src/recorder/http/wrapper.test.d.ts +1 -0
  47. package/dist/src/recorder/observability/logger.d.ts +5 -0
  48. package/dist/src/recorder/observability/logger.js +13 -0
  49. package/dist/src/recorder/runner/config.d.ts +34 -0
  50. package/dist/src/recorder/runner/config.js +84 -0
  51. package/dist/src/recorder/runner/config.test.d.ts +1 -0
  52. package/dist/src/recorder/runner/reap.d.ts +79 -0
  53. package/dist/src/recorder/runner/reap.js +230 -0
  54. package/dist/src/recorder/runner/reap.test.d.ts +1 -0
  55. package/dist/src/recorder/runner/runner-port.d.ts +95 -0
  56. package/dist/src/recorder/runner/runner-port.js +518 -0
  57. package/dist/src/recorder/runner/runner-port.test.d.ts +1 -0
  58. package/dist/src/recorder/runner/session-keys.d.ts +28 -0
  59. package/dist/src/recorder/runner/session-keys.js +72 -0
  60. package/dist/src/recorder/runner/session-keys.test.d.ts +1 -0
  61. package/dist/src/recorder/runner/verify-runner-main.d.ts +95 -0
  62. package/dist/src/recorder/runner/verify-runner-main.js +275 -0
  63. package/dist/src/recorder/runner/verify-runner-main.test.d.ts +1 -0
  64. package/package.json +8 -5
  65. package/scripts/m1-daemon-navigate-drive.mjs +138 -0
  66. package/scripts/m1-extension-spike.mjs +237 -0
  67. package/scripts/m1-live-spike.mjs +156 -0
  68. package/scripts/m6b-connect-back-spike.sh +31 -0
  69. package/scripts/recorder.sh +186 -0
  70. package/clis/12306/utils.test.js +0 -331
  71. package/clis/1688/assets.test.js +0 -39
  72. package/clis/1688/download.test.js +0 -31
  73. package/clis/1688/item.test.js +0 -67
  74. package/clis/1688/search.test.js +0 -75
  75. package/clis/1688/shared.test.js +0 -57
  76. package/clis/1688/store.test.js +0 -62
  77. package/clis/36kr/article.test.js +0 -46
  78. package/clis/36kr/hot.test.js +0 -15
  79. package/clis/36kr/news.test.js +0 -85
  80. package/clis/51job/utils.test.js +0 -69
  81. package/clis/_atlassian/shared.test.js +0 -170
  82. package/clis/aibase/news.test.js +0 -59
  83. package/clis/amazon/bestsellers.test.js +0 -29
  84. package/clis/amazon/discussion.test.js +0 -124
  85. package/clis/amazon/offer.test.js +0 -29
  86. package/clis/amazon/product.test.js +0 -24
  87. package/clis/amazon/rankings.test.js +0 -41
  88. package/clis/amazon/search.test.js +0 -22
  89. package/clis/amazon/shared.test.js +0 -44
  90. package/clis/apple-podcasts/commands.test.js +0 -119
  91. package/clis/apple-podcasts/utils.test.js +0 -57
  92. package/clis/arxiv/arxiv.test.js +0 -112
  93. package/clis/baidu-scholar/search.test.js +0 -23
  94. package/clis/barchart/greeks.test.js +0 -138
  95. package/clis/bilibili/comment.test.js +0 -153
  96. package/clis/bilibili/comments.test.js +0 -142
  97. package/clis/bilibili/dynamic.test.js +0 -68
  98. package/clis/bilibili/hot.test.js +0 -17
  99. package/clis/bilibili/subtitle.test.js +0 -196
  100. package/clis/bilibili/summary.test.js +0 -210
  101. package/clis/bilibili/utils.test.js +0 -61
  102. package/clis/bilibili/video.test.js +0 -132
  103. package/clis/binance/commands.test.js +0 -70
  104. package/clis/bloomberg/utils.test.js +0 -129
  105. package/clis/booking/booking.test.js +0 -356
  106. package/clis/boss/chatlist.test.js +0 -211
  107. package/clis/boss/chatmsg.test.js +0 -230
  108. package/clis/boss/search.test.js +0 -78
  109. package/clis/boss/utils.test.js +0 -34
  110. package/clis/brave/search.test.js +0 -76
  111. package/clis/chaoxing/utils.test.js +0 -45
  112. package/clis/chatgpt/commands.test.js +0 -45
  113. package/clis/chatgpt/envelope.test.js +0 -108
  114. package/clis/chatgpt/image.test.js +0 -188
  115. package/clis/chatgpt/utils.test.js +0 -330
  116. package/clis/chatgpt-app/ax.test.js +0 -35
  117. package/clis/chatwise/composer.test.js +0 -186
  118. package/clis/chess/analyze.test.js +0 -79
  119. package/clis/chess/game.test.js +0 -178
  120. package/clis/chess/games.test.js +0 -164
  121. package/clis/chess/stats.test.js +0 -79
  122. package/clis/chess/utils.test.js +0 -230
  123. package/clis/claude/ask.test.js +0 -338
  124. package/clis/claude/commands.test.js +0 -118
  125. package/clis/claude/utils.test.js +0 -148
  126. package/clis/cnki/search.test.js +0 -18
  127. package/clis/codex/sidebar.test.js +0 -329
  128. package/clis/coingecko/coingecko.test.js +0 -109
  129. package/clis/confluence/commands.test.js +0 -195
  130. package/clis/coupang/coupang.test.js +0 -159
  131. package/clis/coupang/utils.test.js +0 -62
  132. package/clis/ctrip/ctrip.test.js +0 -719
  133. package/clis/dblp/dblp.test.js +0 -397
  134. package/clis/deepseek/ask.test.js +0 -312
  135. package/clis/deepseek/detail.test.js +0 -81
  136. package/clis/deepseek/send.test.js +0 -107
  137. package/clis/deepseek/utils.test.js +0 -370
  138. package/clis/defillama/defillama.test.js +0 -99
  139. package/clis/devto/devto.test.js +0 -236
  140. package/clis/dianping/dianping.test.js +0 -578
  141. package/clis/douban/download.test.js +0 -170
  142. package/clis/douban/movie-hot.test.js +0 -14
  143. package/clis/douban/search.test.js +0 -11
  144. package/clis/douban/subject.test.js +0 -11
  145. package/clis/douban/utils.test.js +0 -438
  146. package/clis/doubao/detail.test.js +0 -42
  147. package/clis/doubao/history.test.js +0 -37
  148. package/clis/doubao/utils.test.js +0 -344
  149. package/clis/douyin/_shared/browser-fetch.test.js +0 -64
  150. package/clis/douyin/_shared/creation-id.test.js +0 -22
  151. package/clis/douyin/_shared/imagex-upload.test.js +0 -87
  152. package/clis/douyin/_shared/sts2.test.js +0 -27
  153. package/clis/douyin/_shared/text-extra.test.js +0 -37
  154. package/clis/douyin/_shared/timing.test.js +0 -28
  155. package/clis/douyin/_shared/tos-upload-short-read.test.js +0 -83
  156. package/clis/douyin/_shared/tos-upload.test.js +0 -229
  157. package/clis/douyin/_shared/transcode.test.js +0 -91
  158. package/clis/douyin/_shared/vod-upload.test.js +0 -38
  159. package/clis/douyin/activities.test.js +0 -55
  160. package/clis/douyin/collections.test.js +0 -45
  161. package/clis/douyin/delete.test.js +0 -100
  162. package/clis/douyin/draft.test.js +0 -335
  163. package/clis/douyin/drafts.test.js +0 -11
  164. package/clis/douyin/hashtag.test.js +0 -171
  165. package/clis/douyin/location.test.js +0 -23
  166. package/clis/douyin/profile.test.js +0 -46
  167. package/clis/douyin/publish-upload-id.test.js +0 -170
  168. package/clis/douyin/publish.test.js +0 -38
  169. package/clis/douyin/stats.test.js +0 -22
  170. package/clis/douyin/update.test.js +0 -11
  171. package/clis/douyin/user-videos.test.js +0 -151
  172. package/clis/douyin/videos.test.js +0 -54
  173. package/clis/duckduckgo/search.test.js +0 -128
  174. package/clis/duckduckgo/suggest.test.js +0 -66
  175. package/clis/eastmoney/hot-rank.test.js +0 -59
  176. package/clis/endoflife/endoflife.test.js +0 -51
  177. package/clis/facebook/feed.test.js +0 -169
  178. package/clis/facebook/marketplace.test.js +0 -91
  179. package/clis/facebook/notifications.test.js +0 -458
  180. package/clis/facebook/search.test.js +0 -55
  181. package/clis/flathub/flathub.test.js +0 -90
  182. package/clis/flomo/memos.test.js +0 -144
  183. package/clis/gemini/ask.test.js +0 -100
  184. package/clis/gemini/deep-research-result.test.js +0 -155
  185. package/clis/gemini/deep-research.test.js +0 -181
  186. package/clis/gemini/reply-state.test.js +0 -671
  187. package/clis/gemini/utils.test.js +0 -198
  188. package/clis/geogebra/geogebra.test.js +0 -175
  189. package/clis/gitee/search.test.js +0 -65
  190. package/clis/gitee/user.test.js +0 -63
  191. package/clis/google/utils.test.js +0 -75
  192. package/clis/google-scholar/cite.test.js +0 -47
  193. package/clis/google-scholar/profile.test.js +0 -49
  194. package/clis/google-scholar/search.test.js +0 -71
  195. package/clis/goproxy/goproxy.test.js +0 -103
  196. package/clis/gov-law/commands.test.js +0 -39
  197. package/clis/gov-policy/gov-policy.test.js +0 -224
  198. package/clis/grok/ask.test.js +0 -29
  199. package/clis/grok/utils.test.js +0 -103
  200. package/clis/hackernews/hackernews.test.js +0 -132
  201. package/clis/hf/hf.test.js +0 -16
  202. package/clis/hupu/hot.test.js +0 -224
  203. package/clis/imdb/utils.test.js +0 -88
  204. package/clis/indeed/indeed.test.js +0 -375
  205. package/clis/instagram/_shared/private-publish.test.js +0 -705
  206. package/clis/instagram/_shared/protocol-capture.test.js +0 -114
  207. package/clis/instagram/download.test.js +0 -118
  208. package/clis/instagram/note.test.js +0 -53
  209. package/clis/instagram/post.test.js +0 -1647
  210. package/clis/instagram/reel.test.js +0 -167
  211. package/clis/instagram/story.test.js +0 -134
  212. package/clis/jd/commands.test.js +0 -41
  213. package/clis/jd/item.test.js +0 -354
  214. package/clis/jianyu/search.test.js +0 -153
  215. package/clis/jianyu/shared/procurement-contract.test.js +0 -72
  216. package/clis/jianyu/shared/procurement-detail.test.js +0 -84
  217. package/clis/jike/read.test.js +0 -86
  218. package/clis/jira/commands.test.js +0 -287
  219. package/clis/juejin/search.js +0 -123
  220. package/clis/juejin/search.test.js +0 -98
  221. package/clis/lesswrong/frontpage.test.js +0 -37
  222. package/clis/lichess/lichess.test.js +0 -85
  223. package/clis/linkedin/connect.test.js +0 -213
  224. package/clis/linkedin/inbox.test.js +0 -152
  225. package/clis/linkedin/job-detail.test.js +0 -38
  226. package/clis/linkedin/jobs-preferences.test.js +0 -43
  227. package/clis/linkedin/people-search.test.js +0 -216
  228. package/clis/linkedin/post-analytics.test.js +0 -40
  229. package/clis/linkedin/posts.test.js +0 -40
  230. package/clis/linkedin/profile-analytics.test.js +0 -67
  231. package/clis/linkedin/profile-experience.test.js +0 -152
  232. package/clis/linkedin/profile-projects.test.js +0 -111
  233. package/clis/linkedin/profile-read.test.js +0 -77
  234. package/clis/linkedin/safe-send.test.js +0 -204
  235. package/clis/linkedin/salesnav-inbox.test.js +0 -113
  236. package/clis/linkedin/salesnav-message.test.js +0 -172
  237. package/clis/linkedin/salesnav-search.test.js +0 -76
  238. package/clis/linkedin/salesnav-thread.test.js +0 -79
  239. package/clis/linkedin/search.test.js +0 -222
  240. package/clis/linkedin/sent-invitations.test.js +0 -62
  241. package/clis/linkedin/services-read.test.js +0 -105
  242. package/clis/linkedin/thread-snapshot.test.js +0 -89
  243. package/clis/linkedin/timeline.test.js +0 -81
  244. package/clis/linkedin-learning/course.test.js +0 -114
  245. package/clis/linkedin-learning/search.test.js +0 -144
  246. package/clis/linkedin-learning/trending.test.js +0 -123
  247. package/clis/linux-do/feed.test.js +0 -153
  248. package/clis/linux-do/topic-content.test.js +0 -59
  249. package/clis/lobsters/lobsters.test.js +0 -169
  250. package/clis/notebooklm/add-source.test.js +0 -97
  251. package/clis/notebooklm/compat.test.js +0 -16
  252. package/clis/notebooklm/create.test.js +0 -58
  253. package/clis/notebooklm/generate-audio.test.js +0 -63
  254. package/clis/notebooklm/generate-slides.test.js +0 -75
  255. package/clis/notebooklm/history.test.js +0 -58
  256. package/clis/notebooklm/note-list.test.js +0 -56
  257. package/clis/notebooklm/notes-get.test.js +0 -72
  258. package/clis/notebooklm/open.test.js +0 -63
  259. package/clis/notebooklm/rpc.test.js +0 -131
  260. package/clis/notebooklm/source-fulltext.test.js +0 -106
  261. package/clis/notebooklm/source-get.test.js +0 -84
  262. package/clis/notebooklm/source-guide.test.js +0 -104
  263. package/clis/notebooklm/summary.test.js +0 -78
  264. package/clis/notebooklm/utils.test.js +0 -449
  265. package/clis/notebooklm/write-note.test.js +0 -70
  266. package/clis/nuget/nuget.test.js +0 -111
  267. package/clis/oeis/oeis.test.js +0 -88
  268. package/clis/ones/task-helpers.test.js +0 -12
  269. package/clis/ones/worklog.test.js +0 -20
  270. package/clis/openfda/openfda.test.js +0 -114
  271. package/clis/openreview/openreview.test.js +0 -427
  272. package/clis/osv/osv.test.js +0 -97
  273. package/clis/paperreview/commands.test.js +0 -243
  274. package/clis/paperreview/utils.test.js +0 -49
  275. package/clis/pixiv/download.test.js +0 -87
  276. package/clis/pixiv/illusts.test.js +0 -99
  277. package/clis/pixiv/search.test.js +0 -83
  278. package/clis/powerchina/search.test.js +0 -93
  279. package/clis/producthunt/utils.test.js +0 -64
  280. package/clis/pubmed/pubmed.test.js +0 -276
  281. package/clis/quark/utils.test.js +0 -58
  282. package/clis/qwen/utils.test.js +0 -45
  283. package/clis/reddit/extract-media.test.js +0 -149
  284. package/clis/reddit/frontpage.test.js +0 -34
  285. package/clis/reddit/home.test.js +0 -170
  286. package/clis/reddit/hot.test.js +0 -32
  287. package/clis/reddit/popular.test.js +0 -26
  288. package/clis/reddit/read.test.js +0 -335
  289. package/clis/reddit/reply.test.js +0 -89
  290. package/clis/reddit/search.test.js +0 -26
  291. package/clis/reddit/subreddit-info.test.js +0 -163
  292. package/clis/reddit/subreddit.test.js +0 -31
  293. package/clis/reddit/subscribed.test.js +0 -168
  294. package/clis/reddit/whoami.test.js +0 -105
  295. package/clis/rednote/navigation.test.js +0 -26
  296. package/clis/rednote/rednote.test.js +0 -222
  297. package/clis/rest-countries/rest-countries.test.js +0 -83
  298. package/clis/reuters/reuters.test.js +0 -299
  299. package/clis/rfc/rfc.test.js +0 -74
  300. package/clis/sinafinance/stock.test.js +0 -59
  301. package/clis/spotify/utils.test.js +0 -67
  302. package/clis/stackoverflow/stackoverflow.test.js +0 -404
  303. package/clis/steam/steam.test.js +0 -46
  304. package/clis/substack/utils.test.js +0 -44
  305. package/clis/suno/commands.test.js +0 -188
  306. package/clis/suno/download.test.js +0 -151
  307. package/clis/suno/generate.test.js +0 -252
  308. package/clis/suno/utils.test.js +0 -329
  309. package/clis/taobao/commands.test.js +0 -41
  310. package/clis/tdx/hot-rank.test.js +0 -59
  311. package/clis/ths/hot-rank.test.js +0 -64
  312. package/clis/tieba/commands.test.js +0 -79
  313. package/clis/tieba/utils.test.js +0 -290
  314. package/clis/tiktok/creator-videos.test.js +0 -113
  315. package/clis/tiktok/refactor.test.js +0 -389
  316. package/clis/tiktok/write-refactor.test.js +0 -370
  317. package/clis/toutiao/toutiao.test.js +0 -378
  318. package/clis/tvmaze/tvmaze.test.js +0 -93
  319. package/clis/twitter/bookmark-folder.test.js +0 -395
  320. package/clis/twitter/bookmark-folders.test.js +0 -152
  321. package/clis/twitter/bookmark.test.js +0 -74
  322. package/clis/twitter/bookmarks.test.js +0 -205
  323. package/clis/twitter/delete.test.js +0 -85
  324. package/clis/twitter/device-follow.test.js +0 -287
  325. package/clis/twitter/download.test.js +0 -457
  326. package/clis/twitter/followers.test.js +0 -62
  327. package/clis/twitter/following.test.js +0 -338
  328. package/clis/twitter/hide-reply.test.js +0 -76
  329. package/clis/twitter/like.test.js +0 -73
  330. package/clis/twitter/likes.test.js +0 -220
  331. package/clis/twitter/list-add.test.js +0 -133
  332. package/clis/twitter/list-create.test.js +0 -169
  333. package/clis/twitter/list-remove.test.js +0 -110
  334. package/clis/twitter/list-tweets.test.js +0 -196
  335. package/clis/twitter/lists.test.js +0 -253
  336. package/clis/twitter/post.test.js +0 -258
  337. package/clis/twitter/profile.test.js +0 -39
  338. package/clis/twitter/quote.test.js +0 -194
  339. package/clis/twitter/reply.test.js +0 -237
  340. package/clis/twitter/retweet.test.js +0 -73
  341. package/clis/twitter/search.test.js +0 -349
  342. package/clis/twitter/shared.test.js +0 -794
  343. package/clis/twitter/thread.test.js +0 -58
  344. package/clis/twitter/timeline.test.js +0 -104
  345. package/clis/twitter/trending.test.js +0 -15
  346. package/clis/twitter/tweets.test.js +0 -362
  347. package/clis/twitter/unbookmark.test.js +0 -73
  348. package/clis/twitter/unlike.test.js +0 -75
  349. package/clis/twitter/unretweet.test.js +0 -73
  350. package/clis/twitter/utils.test.js +0 -169
  351. package/clis/uisdc/news.test.js +0 -66
  352. package/clis/uiverse/_shared.test.js +0 -62
  353. package/clis/uiverse/navigation.test.js +0 -12
  354. package/clis/upwork/upwork.test.js +0 -566
  355. package/clis/wanfang/search.test.js +0 -23
  356. package/clis/web/read.test.js +0 -392
  357. package/clis/weibo/delete.test.js +0 -94
  358. package/clis/weibo/envelope.test.js +0 -85
  359. package/clis/weibo/favorites.test.js +0 -114
  360. package/clis/weibo/publish.test.js +0 -192
  361. package/clis/weibo/user-posts.test.js +0 -92
  362. package/clis/weibo/utils.test.js +0 -36
  363. package/clis/weixin/drafts.test.js +0 -69
  364. package/clis/weixin/search.test.js +0 -227
  365. package/clis/weread/ai-outline.test.js +0 -83
  366. package/clis/weread/book-search.test.js +0 -242
  367. package/clis/weread/commands.test.js +0 -398
  368. package/clis/weread/private-api-regression.test.js +0 -369
  369. package/clis/weread/search-regression.test.js +0 -494
  370. package/clis/weread/utils.test.js +0 -128
  371. package/clis/weread-official/commands.test.js +0 -385
  372. package/clis/weread-official/utils.test.js +0 -242
  373. package/clis/wikidata/wikidata.test.js +0 -83
  374. package/clis/wikipedia/trending.test.js +0 -57
  375. package/clis/wttr/wttr.test.js +0 -84
  376. package/clis/xianyu/chat.test.js +0 -84
  377. package/clis/xianyu/im.test.js +0 -253
  378. package/clis/xianyu/item.test.js +0 -56
  379. package/clis/xianyu/publish.test.js +0 -220
  380. package/clis/xianyu/search.test.js +0 -17
  381. package/clis/xiaoe/xiaoe.test.js +0 -486
  382. package/clis/xiaohongshu/comments.test.js +0 -258
  383. package/clis/xiaohongshu/creator-note-detail.test.js +0 -451
  384. package/clis/xiaohongshu/creator-notes-summary.test.js +0 -94
  385. package/clis/xiaohongshu/creator-notes.test.js +0 -281
  386. package/clis/xiaohongshu/creator-stats.test.js +0 -24
  387. package/clis/xiaohongshu/delete-note.test.js +0 -172
  388. package/clis/xiaohongshu/download.test.js +0 -316
  389. package/clis/xiaohongshu/navigation.test.js +0 -34
  390. package/clis/xiaohongshu/note.test.js +0 -249
  391. package/clis/xiaohongshu/publish.test.js +0 -608
  392. package/clis/xiaohongshu/search.test.js +0 -325
  393. package/clis/xiaohongshu/user-helpers.test.js +0 -160
  394. package/clis/xiaoyuzhou/auth.test.js +0 -124
  395. package/clis/xiaoyuzhou/download.test.js +0 -135
  396. package/clis/xiaoyuzhou/podcast-episodes.test.js +0 -78
  397. package/clis/xiaoyuzhou/transcript.test.js +0 -195
  398. package/clis/xiaoyuzhou/utils.test.js +0 -39
  399. package/clis/xueqiu/comments.test.js +0 -696
  400. package/clis/xueqiu/danjuan-utils.test.js +0 -41
  401. package/clis/xueqiu/utils.test.js +0 -26
  402. package/clis/yahoo/search.test.js +0 -94
  403. package/clis/youdao/note.test.js +0 -99
  404. package/clis/youtube/channel.test.js +0 -59
  405. package/clis/youtube/feed.test.js +0 -131
  406. package/clis/youtube/transcript-group.test.js +0 -99
  407. package/clis/youtube/transcript.test.js +0 -296
  408. package/clis/youtube/utils.test.js +0 -84
  409. package/clis/yuanbao/ask.test.js +0 -124
  410. package/clis/yuanbao/new.test.js +0 -30
  411. package/clis/yuanbao/shared.test.js +0 -80
  412. package/clis/zhihu/answer-comments.test.js +0 -287
  413. package/clis/zhihu/answer-detail.test.js +0 -338
  414. package/clis/zhihu/answer.test.js +0 -54
  415. package/clis/zhihu/collection.test.js +0 -337
  416. package/clis/zhihu/collections.test.js +0 -182
  417. package/clis/zhihu/comment.test.js +0 -50
  418. package/clis/zhihu/download.test.js +0 -12
  419. package/clis/zhihu/favorite.test.js +0 -59
  420. package/clis/zhihu/follow.test.js +0 -42
  421. package/clis/zhihu/like.test.js +0 -41
  422. package/clis/zhihu/question.test.js +0 -251
  423. package/clis/zhihu/recommend.test.js +0 -143
  424. package/clis/zhihu/search.test.js +0 -198
  425. package/clis/zhihu/target.test.js +0 -77
  426. package/clis/zhihu/text.test.js +0 -24
  427. package/clis/zhihu/write-shared.test.js +0 -176
  428. package/clis/zlibrary/commands.test.js +0 -65
  429. package/clis/zsxq/search.test.js +0 -24
  430. package/clis/zsxq/topic.test.js +0 -30
  431. package/clis/zsxq/topics.test.js +0 -24
  432. package/clis/zsxq/utils.test.js +0 -31
  433. package/dist/src/adapter-shadow.test.js +0 -49
  434. package/dist/src/adapter-source.test.js +0 -29
  435. package/dist/src/browser/analyze.test.js +0 -166
  436. package/dist/src/browser/article-extract.e2e.test.js +0 -105
  437. package/dist/src/browser/article-extract.test.js +0 -94
  438. package/dist/src/browser/ax-snapshot.test.js +0 -91
  439. package/dist/src/browser/base-page.test.js +0 -758
  440. package/dist/src/browser/cdp-click-fixture.test.js +0 -87
  441. package/dist/src/browser/cdp.test.js +0 -79
  442. package/dist/src/browser/compound.test.js +0 -175
  443. package/dist/src/browser/daemon-client.test.js +0 -199
  444. package/dist/src/browser/dom-helpers.test.js +0 -106
  445. package/dist/src/browser/dom-snapshot.test.js +0 -313
  446. package/dist/src/browser/errors.test.js +0 -60
  447. package/dist/src/browser/extract.test.js +0 -129
  448. package/dist/src/browser/find.test.js +0 -180
  449. package/dist/src/browser/html-tree.test.js +0 -181
  450. package/dist/src/browser/network-cache.test.js +0 -58
  451. package/dist/src/browser/network-key.test.js +0 -49
  452. package/dist/src/browser/page.test.js +0 -378
  453. package/dist/src/browser/shape-filter.test.js +0 -101
  454. package/dist/src/browser/shape.test.js +0 -82
  455. package/dist/src/browser/stealth.test.js +0 -134
  456. package/dist/src/browser/target-errors.test.js +0 -94
  457. package/dist/src/browser/target-resolver.test.js +0 -118
  458. package/dist/src/browser/utils.test.js +0 -29
  459. package/dist/src/browser/verify-fixture.test.js +0 -219
  460. package/dist/src/browser.test.js +0 -232
  461. package/dist/src/build-manifest.test.js +0 -341
  462. package/dist/src/capabilityRouting.test.js +0 -63
  463. package/dist/src/cli-argv-preprocess.test.js +0 -209
  464. package/dist/src/cli.test.js +0 -2803
  465. package/dist/src/commanderAdapter.test.js +0 -352
  466. package/dist/src/commands/daemon.test.js +0 -219
  467. package/dist/src/completion.test.js +0 -24
  468. package/dist/src/convention-audit.test.js +0 -247
  469. package/dist/src/daemon.test.js +0 -60
  470. package/dist/src/doctor.test.js +0 -263
  471. package/dist/src/download/article-download.test.js +0 -235
  472. package/dist/src/download/index.test.js +0 -140
  473. package/dist/src/download/media-download.test.js +0 -112
  474. package/dist/src/download/progress.test.js +0 -36
  475. package/dist/src/electron-apps.test.js +0 -49
  476. package/dist/src/engine.test.js +0 -312
  477. package/dist/src/errors.test.js +0 -109
  478. package/dist/src/execution.test.js +0 -623
  479. package/dist/src/extension-manifest-regression.test.js +0 -12
  480. package/dist/src/external.test.js +0 -146
  481. package/dist/src/help.test.js +0 -58
  482. package/dist/src/hooks.test.js +0 -92
  483. package/dist/src/interceptor.test.js +0 -81
  484. package/dist/src/launcher.test.js +0 -138
  485. package/dist/src/node-network.test.js +0 -55
  486. package/dist/src/observation/artifact.test.js +0 -121
  487. package/dist/src/observation/manager.test.js +0 -13
  488. package/dist/src/observation/redaction.test.js +0 -32
  489. package/dist/src/observation/retention.test.js +0 -118
  490. package/dist/src/observation/ring-buffer.test.js +0 -22
  491. package/dist/src/output.test.js +0 -53
  492. package/dist/src/package-exports.test.js +0 -112
  493. package/dist/src/pipeline/executor.test.js +0 -182
  494. package/dist/src/pipeline/steps/download.test.js +0 -102
  495. package/dist/src/pipeline/steps/fetch.test.js +0 -117
  496. package/dist/src/pipeline/template.test.js +0 -175
  497. package/dist/src/pipeline/transform.test.js +0 -133
  498. package/dist/src/plugin-manifest.test.js +0 -179
  499. package/dist/src/plugin-scaffold.test.js +0 -83
  500. package/dist/src/plugin.test.js +0 -1324
  501. package/dist/src/registry.test.js +0 -209
  502. package/dist/src/runtime-detect.test.js +0 -39
  503. package/dist/src/serialization.test.js +0 -78
  504. package/dist/src/snapshotFormatter.test.js +0 -521
  505. package/dist/src/tui.test.js +0 -19
  506. package/dist/src/update-check.test.js +0 -116
  507. package/dist/src/utils.test.js +0 -155
  508. package/dist/src/validate.test.js +0 -90
  509. package/dist/src/weixin-download.test.js +0 -45
@@ -1,1324 +0,0 @@
1
- /**
2
- * Tests for plugin management: install, uninstall, list, and lock file support.
3
- */
4
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
5
- import * as fs from 'node:fs';
6
- import * as os from 'node:os';
7
- import * as path from 'node:path';
8
- import { pathToFileURL } from 'node:url';
9
- import { PLUGINS_DIR } from './discovery.js';
10
- import * as pluginModule from './plugin.js';
11
- const { mockExecFileSync, mockExecSync } = vi.hoisted(() => ({
12
- mockExecFileSync: vi.fn(),
13
- mockExecSync: vi.fn(),
14
- }));
15
- const { _getCommitHash, _installDependencies, _postInstallMonorepoLifecycle, installPlugin, listPlugins, _readLockFile, _readLockFileWithWriter, _resolveEsbuildBin, _resolveHostBycliRoot, uninstallPlugin, updatePlugin, _parseSource, _updateAllPlugins, _validatePluginStructure, _writeLockFile, _writeLockFileWithFs, _isSymlinkSync, _getMonoreposDir, getLockFilePath, _installLocalPlugin, _isLocalPluginSource, _moveDir, _resolvePluginSource, _resolveStoredPluginSource, _toStoredPluginSource, _toLocalPluginSource, } = pluginModule;
16
- describe('parseSource', () => {
17
- it('parses github:user/repo format', () => {
18
- const result = _parseSource('github:ByteYue/bycli-plugin-github-trending');
19
- expect(result).toEqual({
20
- type: 'git',
21
- cloneUrl: 'https://github.com/ByteYue/bycli-plugin-github-trending.git',
22
- name: 'github-trending',
23
- });
24
- });
25
- it('parses https URL format', () => {
26
- const result = _parseSource('https://github.com/ByteYue/bycli-plugin-hot-digest');
27
- expect(result).toEqual({
28
- type: 'git',
29
- cloneUrl: 'https://github.com/ByteYue/bycli-plugin-hot-digest.git',
30
- name: 'hot-digest',
31
- });
32
- });
33
- it('strips bycli-plugin- prefix from name', () => {
34
- const result = _parseSource('github:user/bycli-plugin-my-tool');
35
- expect(result.name).toBe('my-tool');
36
- });
37
- it('keeps name without prefix', () => {
38
- const result = _parseSource('github:user/awesome-cli');
39
- expect(result.name).toBe('awesome-cli');
40
- });
41
- it('returns null for invalid source', () => {
42
- expect(_parseSource('invalid')).toBeNull();
43
- expect(_parseSource('npm:some-package')).toBeNull();
44
- });
45
- it('parses file:// local plugin directories', () => {
46
- const localDir = path.join(os.tmpdir(), 'bycli-plugin-test');
47
- const fileUrl = pathToFileURL(localDir).href;
48
- const result = _parseSource(fileUrl);
49
- expect(result).toEqual({
50
- type: 'local',
51
- localPath: localDir,
52
- name: 'test',
53
- });
54
- });
55
- it('parses plain absolute local plugin directories', () => {
56
- const localDir = path.join(os.tmpdir(), 'my-plugin');
57
- const result = _parseSource(localDir);
58
- expect(result).toEqual({
59
- type: 'local',
60
- localPath: localDir,
61
- name: 'my-plugin',
62
- });
63
- });
64
- it('strips bycli-plugin- prefix for local paths', () => {
65
- const localDir = path.join(os.tmpdir(), 'bycli-plugin-foo');
66
- const result = _parseSource(localDir);
67
- expect(result.name).toBe('foo');
68
- });
69
- // ── Generic git URL support ──
70
- it('parses ssh:// URLs', () => {
71
- const result = _parseSource('ssh://git@gitlab.com/team/bycli-plugin-tools.git');
72
- expect(result).toEqual({
73
- type: 'git',
74
- cloneUrl: 'ssh://git@gitlab.com/team/bycli-plugin-tools.git',
75
- name: 'tools',
76
- });
77
- });
78
- it('parses ssh:// URLs without .git suffix', () => {
79
- const result = _parseSource('ssh://git@gitlab.com/team/my-plugin');
80
- expect(result).toEqual({
81
- type: 'git',
82
- cloneUrl: 'ssh://git@gitlab.com/team/my-plugin',
83
- name: 'my-plugin',
84
- });
85
- });
86
- it('parses git@ SCP-style URLs', () => {
87
- const result = _parseSource('git@gitlab.com:team/my-plugin.git');
88
- expect(result).toEqual({
89
- type: 'git',
90
- cloneUrl: 'git@gitlab.com:team/my-plugin.git',
91
- name: 'my-plugin',
92
- });
93
- });
94
- it('parses git@ SCP-style URLs and strips bycli-plugin- prefix', () => {
95
- const result = _parseSource('git@github.com:user/bycli-plugin-awesome.git');
96
- expect(result).toEqual({
97
- type: 'git',
98
- cloneUrl: 'git@github.com:user/bycli-plugin-awesome.git',
99
- name: 'awesome',
100
- });
101
- });
102
- it('parses generic HTTPS git URLs (non-GitHub)', () => {
103
- const result = _parseSource('https://codehub.example.com/Team/App/bycli-plugins-app.git');
104
- expect(result).toEqual({
105
- type: 'git',
106
- cloneUrl: 'https://codehub.example.com/Team/App/bycli-plugins-app.git',
107
- name: 'bycli-plugins-app',
108
- });
109
- });
110
- it('parses generic HTTPS git URLs without .git suffix', () => {
111
- const result = _parseSource('https://gitlab.example.com/org/my-plugin');
112
- expect(result).toEqual({
113
- type: 'git',
114
- cloneUrl: 'https://gitlab.example.com/org/my-plugin.git',
115
- name: 'my-plugin',
116
- });
117
- });
118
- it('still prefers GitHub shorthand over generic HTTPS for github.com', () => {
119
- const result = _parseSource('https://github.com/user/repo');
120
- // Should be handled by the GitHub-specific matcher (normalizes URL)
121
- expect(result).toEqual({
122
- type: 'git',
123
- cloneUrl: 'https://github.com/user/repo.git',
124
- name: 'repo',
125
- });
126
- });
127
- });
128
- describe('validatePluginStructure', () => {
129
- const testDir = path.join(PLUGINS_DIR, '__test-validate__');
130
- beforeEach(() => {
131
- fs.mkdirSync(testDir, { recursive: true });
132
- });
133
- afterEach(() => {
134
- try {
135
- fs.rmSync(testDir, { recursive: true });
136
- }
137
- catch { }
138
- });
139
- it('returns invalid for non-existent directory', () => {
140
- const res = _validatePluginStructure(path.join(PLUGINS_DIR, '__does_not_exist__'));
141
- expect(res.valid).toBe(false);
142
- expect(res.errors[0]).toContain('does not exist');
143
- });
144
- it('returns invalid for empty directory', () => {
145
- const res = _validatePluginStructure(testDir);
146
- expect(res.valid).toBe(false);
147
- expect(res.errors[0]).toContain('No command files found');
148
- });
149
- it('returns invalid for YAML-only plugin (YAML no longer supported)', () => {
150
- fs.writeFileSync(path.join(testDir, 'cmd.yaml'), 'site: test');
151
- const res = _validatePluginStructure(testDir);
152
- expect(res.valid).toBe(false);
153
- expect(res.errors[0]).toContain('No command files found');
154
- });
155
- it('returns valid for JS plugin', () => {
156
- fs.writeFileSync(path.join(testDir, 'cmd.js'), 'console.log("hi");');
157
- const res = _validatePluginStructure(testDir);
158
- expect(res.valid).toBe(true);
159
- expect(res.errors).toHaveLength(0);
160
- });
161
- it('returns invalid for TS plugin without package.json', () => {
162
- fs.writeFileSync(path.join(testDir, 'cmd.ts'), 'console.log("hi");');
163
- const res = _validatePluginStructure(testDir);
164
- expect(res.valid).toBe(false);
165
- expect(res.errors[0]).toContain('contains .ts files but no package.json');
166
- });
167
- it('returns invalid for TS plugin with missing type: module', () => {
168
- fs.writeFileSync(path.join(testDir, 'cmd.ts'), 'console.log("hi");');
169
- fs.writeFileSync(path.join(testDir, 'package.json'), JSON.stringify({ name: 'test' }));
170
- const res = _validatePluginStructure(testDir);
171
- expect(res.valid).toBe(false);
172
- expect(res.errors[0]).toContain('must have "type": "module"');
173
- });
174
- it('returns valid for TS plugin with correct package.json', () => {
175
- fs.writeFileSync(path.join(testDir, 'cmd.ts'), 'console.log("hi");');
176
- fs.writeFileSync(path.join(testDir, 'package.json'), JSON.stringify({ type: 'module' }));
177
- const res = _validatePluginStructure(testDir);
178
- expect(res.valid).toBe(true);
179
- expect(res.errors).toHaveLength(0);
180
- });
181
- });
182
- describe('lock file', () => {
183
- const backupPath = `${getLockFilePath()}.test-backup`;
184
- let hadOriginal = false;
185
- beforeEach(() => {
186
- hadOriginal = fs.existsSync(getLockFilePath());
187
- if (hadOriginal) {
188
- fs.mkdirSync(path.dirname(backupPath), { recursive: true });
189
- fs.copyFileSync(getLockFilePath(), backupPath);
190
- }
191
- });
192
- afterEach(() => {
193
- if (hadOriginal) {
194
- fs.copyFileSync(backupPath, getLockFilePath());
195
- fs.unlinkSync(backupPath);
196
- return;
197
- }
198
- try {
199
- fs.unlinkSync(getLockFilePath());
200
- }
201
- catch { }
202
- });
203
- it('reads empty lock when file does not exist', () => {
204
- try {
205
- fs.unlinkSync(getLockFilePath());
206
- }
207
- catch { }
208
- expect(_readLockFile()).toEqual({});
209
- });
210
- it('round-trips lock entries', () => {
211
- const entries = {
212
- 'test-plugin': {
213
- source: { kind: 'git', url: 'https://github.com/user/repo.git' },
214
- commitHash: 'abc1234567890def',
215
- installedAt: '2025-01-01T00:00:00.000Z',
216
- },
217
- 'another-plugin': {
218
- source: { kind: 'git', url: 'https://github.com/user/another.git' },
219
- commitHash: 'def4567890123abc',
220
- installedAt: '2025-02-01T00:00:00.000Z',
221
- updatedAt: '2025-03-01T00:00:00.000Z',
222
- },
223
- };
224
- _writeLockFile(entries);
225
- expect(_readLockFile()).toEqual(entries);
226
- });
227
- it('handles malformed lock file gracefully', () => {
228
- fs.mkdirSync(path.dirname(getLockFilePath()), { recursive: true });
229
- fs.writeFileSync(getLockFilePath(), 'not valid json');
230
- expect(_readLockFile()).toEqual({});
231
- });
232
- it('keeps the previous lockfile contents when atomic rewrite fails', () => {
233
- const existing = {
234
- stable: {
235
- source: { kind: 'git', url: 'https://github.com/user/stable.git' },
236
- commitHash: 'stable1234567890',
237
- installedAt: '2025-01-01T00:00:00.000Z',
238
- },
239
- };
240
- _writeLockFile(existing);
241
- const renameSync = vi.fn(() => {
242
- throw new Error('rename failed');
243
- });
244
- const rmSync = vi.fn(() => undefined);
245
- expect(() => _writeLockFileWithFs({
246
- broken: {
247
- source: { kind: 'git', url: 'https://github.com/user/broken.git' },
248
- commitHash: 'broken1234567890',
249
- installedAt: '2025-02-01T00:00:00.000Z',
250
- },
251
- }, {
252
- mkdirSync: fs.mkdirSync,
253
- writeFileSync: fs.writeFileSync,
254
- renameSync,
255
- rmSync,
256
- })).toThrow('rename failed');
257
- expect(_readLockFile()).toEqual(existing);
258
- expect(rmSync).toHaveBeenCalledTimes(1);
259
- });
260
- it('migrates legacy string sources to structured sources on read', () => {
261
- const legacyLocalPath = path.resolve(path.join(os.tmpdir(), 'bycli-legacy-local-plugin'));
262
- fs.mkdirSync(path.dirname(getLockFilePath()), { recursive: true });
263
- fs.writeFileSync(getLockFilePath(), JSON.stringify({
264
- alpha: {
265
- source: 'https://github.com/user/bycli-plugins.git',
266
- commitHash: 'abc1234567890def',
267
- installedAt: '2025-01-01T00:00:00.000Z',
268
- monorepo: { name: 'bycli-plugins', subPath: 'packages/alpha' },
269
- },
270
- beta: {
271
- source: `local:${legacyLocalPath}`,
272
- commitHash: 'local',
273
- installedAt: '2025-01-01T00:00:00.000Z',
274
- },
275
- }, null, 2));
276
- expect(_readLockFile()).toEqual({
277
- alpha: {
278
- source: {
279
- kind: 'monorepo',
280
- url: 'https://github.com/user/bycli-plugins.git',
281
- repoName: 'bycli-plugins',
282
- subPath: 'packages/alpha',
283
- },
284
- commitHash: 'abc1234567890def',
285
- installedAt: '2025-01-01T00:00:00.000Z',
286
- },
287
- beta: {
288
- source: { kind: 'local', path: legacyLocalPath },
289
- commitHash: 'local',
290
- installedAt: '2025-01-01T00:00:00.000Z',
291
- },
292
- });
293
- });
294
- it('returns normalized entries even when migration rewrite fails', () => {
295
- fs.mkdirSync(path.dirname(getLockFilePath()), { recursive: true });
296
- fs.writeFileSync(getLockFilePath(), JSON.stringify({
297
- alpha: {
298
- source: 'https://github.com/user/bycli-plugins.git',
299
- commitHash: 'abc1234567890def',
300
- installedAt: '2025-01-01T00:00:00.000Z',
301
- monorepo: { name: 'bycli-plugins', subPath: 'packages/alpha' },
302
- },
303
- }, null, 2));
304
- expect(_readLockFileWithWriter(() => {
305
- throw new Error('disk full');
306
- })).toEqual({
307
- alpha: {
308
- source: {
309
- kind: 'monorepo',
310
- url: 'https://github.com/user/bycli-plugins.git',
311
- repoName: 'bycli-plugins',
312
- subPath: 'packages/alpha',
313
- },
314
- commitHash: 'abc1234567890def',
315
- installedAt: '2025-01-01T00:00:00.000Z',
316
- },
317
- });
318
- });
319
- });
320
- describe('getCommitHash', () => {
321
- it('returns a hash for a git repo', () => {
322
- const hash = _getCommitHash(process.cwd());
323
- expect(hash).toBeDefined();
324
- expect(hash).toMatch(/^[0-9a-f]{40}$/);
325
- });
326
- it('returns undefined for non-git directory', () => {
327
- expect(_getCommitHash(os.tmpdir())).toBeUndefined();
328
- });
329
- });
330
- describe('resolveEsbuildBin', () => {
331
- it('resolves a usable esbuild executable path', () => {
332
- const binPath = _resolveEsbuildBin();
333
- expect(binPath).not.toBeNull();
334
- expect(typeof binPath).toBe('string');
335
- expect(fs.existsSync(binPath)).toBe(true);
336
- expect(binPath).toMatch(/esbuild(\.cmd)?$/);
337
- });
338
- });
339
- describe('resolveHostBycliRoot', () => {
340
- let tmpDir;
341
- beforeEach(() => {
342
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'bycli-host-root-test-'));
343
- });
344
- afterEach(() => {
345
- fs.rmSync(tmpDir, { recursive: true, force: true });
346
- });
347
- it('walks up from compiled dist/src files to the package root', () => {
348
- fs.writeFileSync(path.join(tmpDir, 'package.json'), JSON.stringify({ name: '@sovovs/bycli' }));
349
- const distSrcDir = path.join(tmpDir, 'dist', 'src');
350
- fs.mkdirSync(distSrcDir, { recursive: true });
351
- expect(_resolveHostBycliRoot(path.join(distSrcDir, 'plugin.js'))).toBe(tmpDir);
352
- });
353
- });
354
- describe('listPlugins', () => {
355
- const testDir = path.join(PLUGINS_DIR, '__test-list-plugin__');
356
- afterEach(() => {
357
- try {
358
- fs.rmSync(testDir, { recursive: true });
359
- }
360
- catch { }
361
- });
362
- it('lists installed plugins', () => {
363
- fs.mkdirSync(testDir, { recursive: true });
364
- fs.writeFileSync(path.join(testDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
365
- const plugins = listPlugins();
366
- const found = plugins.find(p => p.name === '__test-list-plugin__');
367
- expect(found).toBeDefined();
368
- expect(found.commands).toContain('hello');
369
- });
370
- it('includes version metadata from the lock file', () => {
371
- fs.mkdirSync(testDir, { recursive: true });
372
- fs.writeFileSync(path.join(testDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
373
- const lock = _readLockFile();
374
- lock['__test-list-plugin__'] = {
375
- source: { kind: 'git', url: 'https://github.com/user/repo.git' },
376
- commitHash: 'abcdef1234567890abcdef1234567890abcdef12',
377
- installedAt: '2025-01-01T00:00:00.000Z',
378
- };
379
- _writeLockFile(lock);
380
- const plugins = listPlugins();
381
- const found = plugins.find(p => p.name === '__test-list-plugin__');
382
- expect(found).toBeDefined();
383
- expect(found.version).toBe('abcdef1');
384
- expect(found.installedAt).toBe('2025-01-01T00:00:00.000Z');
385
- delete lock['__test-list-plugin__'];
386
- _writeLockFile(lock);
387
- });
388
- it('returns empty array when no plugins dir', () => {
389
- const plugins = listPlugins();
390
- expect(Array.isArray(plugins)).toBe(true);
391
- });
392
- it('prefers lockfile source for local symlink plugins', () => {
393
- const localTarget = fs.mkdtempSync(path.join(os.tmpdir(), 'bycli-local-list-'));
394
- const linkPath = path.join(PLUGINS_DIR, '__test-list-plugin__');
395
- fs.mkdirSync(PLUGINS_DIR, { recursive: true });
396
- fs.writeFileSync(path.join(localTarget, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
397
- try {
398
- fs.unlinkSync(linkPath);
399
- }
400
- catch { }
401
- try {
402
- fs.rmSync(linkPath, { recursive: true, force: true });
403
- }
404
- catch { }
405
- fs.symlinkSync(localTarget, linkPath, 'dir');
406
- const lock = _readLockFile();
407
- lock['__test-list-plugin__'] = {
408
- source: { kind: 'local', path: localTarget },
409
- commitHash: 'local',
410
- installedAt: '2025-01-01T00:00:00.000Z',
411
- };
412
- _writeLockFile(lock);
413
- const plugins = listPlugins();
414
- const found = plugins.find(p => p.name === '__test-list-plugin__');
415
- expect(found?.source).toBe(`local:${localTarget}`);
416
- try {
417
- fs.unlinkSync(linkPath);
418
- }
419
- catch { }
420
- try {
421
- fs.rmSync(localTarget, { recursive: true, force: true });
422
- }
423
- catch { }
424
- delete lock['__test-list-plugin__'];
425
- _writeLockFile(lock);
426
- });
427
- });
428
- describe('uninstallPlugin', () => {
429
- const testDir = path.join(PLUGINS_DIR, '__test-uninstall__');
430
- afterEach(() => {
431
- try {
432
- fs.rmSync(testDir, { recursive: true });
433
- }
434
- catch { }
435
- });
436
- it('removes plugin directory', () => {
437
- fs.mkdirSync(testDir, { recursive: true });
438
- fs.writeFileSync(path.join(testDir, 'test.js'), 'cli({ site: "test", name: "test", access: "read" })');
439
- uninstallPlugin('__test-uninstall__');
440
- expect(fs.existsSync(testDir)).toBe(false);
441
- });
442
- it('removes lock entry on uninstall', () => {
443
- fs.mkdirSync(testDir, { recursive: true });
444
- fs.writeFileSync(path.join(testDir, 'test.js'), 'cli({ site: "test", name: "test", access: "read" })');
445
- const lock = _readLockFile();
446
- lock['__test-uninstall__'] = {
447
- source: { kind: 'git', url: 'https://github.com/user/repo.git' },
448
- commitHash: 'abc123',
449
- installedAt: '2025-01-01T00:00:00.000Z',
450
- };
451
- _writeLockFile(lock);
452
- uninstallPlugin('__test-uninstall__');
453
- expect(_readLockFile()['__test-uninstall__']).toBeUndefined();
454
- });
455
- it('throws for non-existent plugin', () => {
456
- expect(() => uninstallPlugin('__nonexistent__')).toThrow('not installed');
457
- });
458
- });
459
- describe('updatePlugin', () => {
460
- it('throws for non-existent plugin', () => {
461
- expect(() => updatePlugin('__nonexistent__')).toThrow('not installed');
462
- });
463
- it('refreshes local plugins without running git pull', () => {
464
- const localTarget = fs.mkdtempSync(path.join(os.tmpdir(), 'bycli-local-update-'));
465
- const linkPath = path.join(PLUGINS_DIR, '__test-local-update__');
466
- fs.mkdirSync(PLUGINS_DIR, { recursive: true });
467
- fs.writeFileSync(path.join(localTarget, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
468
- fs.symlinkSync(localTarget, linkPath, 'dir');
469
- const lock = _readLockFile();
470
- lock['__test-local-update__'] = {
471
- source: { kind: 'local', path: localTarget },
472
- commitHash: 'local',
473
- installedAt: '2025-01-01T00:00:00.000Z',
474
- };
475
- _writeLockFile(lock);
476
- mockExecFileSync.mockClear();
477
- updatePlugin('__test-local-update__');
478
- expect(mockExecFileSync.mock.calls.some(([cmd, args, opts]) => cmd === 'git'
479
- && Array.isArray(args)
480
- && args[0] === 'pull'
481
- && opts?.cwd === linkPath)).toBe(false);
482
- const updated = _readLockFile()['__test-local-update__'];
483
- expect(updated?.source).toEqual({ kind: 'local', path: path.resolve(localTarget) });
484
- expect(updated?.updatedAt).toBeDefined();
485
- try {
486
- fs.unlinkSync(linkPath);
487
- }
488
- catch { }
489
- try {
490
- fs.rmSync(localTarget, { recursive: true, force: true });
491
- }
492
- catch { }
493
- const finalLock = _readLockFile();
494
- delete finalLock['__test-local-update__'];
495
- _writeLockFile(finalLock);
496
- });
497
- });
498
- vi.mock('node:child_process', () => {
499
- return {
500
- execFileSync: mockExecFileSync.mockImplementation((_cmd, args, opts) => {
501
- if (Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
502
- if (opts?.cwd === os.tmpdir()) {
503
- throw new Error('not a git repository');
504
- }
505
- return '1234567890abcdef1234567890abcdef12345678\n';
506
- }
507
- if (opts && opts.cwd && String(opts.cwd).endsWith('plugin-b')) {
508
- throw new Error('Network error');
509
- }
510
- return '';
511
- }),
512
- execSync: mockExecSync.mockImplementation(() => ''),
513
- };
514
- });
515
- describe('installDependencies', () => {
516
- beforeEach(() => {
517
- mockExecFileSync.mockClear();
518
- mockExecSync.mockClear();
519
- });
520
- it('throws when npm install fails', () => {
521
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'bycli-plugin-b-'));
522
- const failingDir = path.join(tmpDir, 'plugin-b');
523
- fs.mkdirSync(failingDir, { recursive: true });
524
- fs.writeFileSync(path.join(failingDir, 'package.json'), JSON.stringify({ name: 'plugin-b' }));
525
- expect(() => _installDependencies(failingDir)).toThrow('npm install failed');
526
- fs.rmSync(tmpDir, { recursive: true, force: true });
527
- });
528
- });
529
- describe('postInstallMonorepoLifecycle', () => {
530
- let repoDir;
531
- let subDir;
532
- beforeEach(() => {
533
- mockExecFileSync.mockClear();
534
- mockExecSync.mockClear();
535
- repoDir = fs.mkdtempSync(path.join(os.tmpdir(), 'bycli-monorepo-'));
536
- subDir = path.join(repoDir, 'packages', 'alpha');
537
- fs.mkdirSync(subDir, { recursive: true });
538
- fs.writeFileSync(path.join(repoDir, 'package.json'), JSON.stringify({
539
- name: 'bycli-plugins',
540
- private: true,
541
- workspaces: ['packages/*'],
542
- }));
543
- fs.writeFileSync(path.join(subDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
544
- });
545
- afterEach(() => {
546
- fs.rmSync(repoDir, { recursive: true, force: true });
547
- });
548
- it('installs dependencies at the monorepo root and skips sub-plugins without own dependencies', () => {
549
- _postInstallMonorepoLifecycle(repoDir, [subDir]);
550
- const npmCalls = mockExecFileSync.mock.calls.filter(([cmd, args]) => cmd === 'npm' && Array.isArray(args) && args[0] === 'install');
551
- expect(npmCalls).toHaveLength(1);
552
- expect(npmCalls[0][2]).toMatchObject({ cwd: repoDir });
553
- expect(npmCalls.some(([, , opts]) => opts?.cwd === subDir)).toBe(false);
554
- });
555
- it('also installs dependencies in sub-plugins that declare their own production dependencies', () => {
556
- // Give the sub-plugin its own production dependencies
557
- fs.writeFileSync(path.join(subDir, 'package.json'), JSON.stringify({
558
- name: 'bycli-plugin-alpha',
559
- version: '1.0.0',
560
- type: 'module',
561
- dependencies: { undici: '^8.0.0' },
562
- }));
563
- _postInstallMonorepoLifecycle(repoDir, [subDir]);
564
- const npmCalls = mockExecFileSync.mock.calls.filter(([cmd, args]) => cmd === 'npm' && Array.isArray(args) && args[0] === 'install');
565
- expect(npmCalls).toHaveLength(2);
566
- expect(npmCalls[0][2]).toMatchObject({ cwd: repoDir });
567
- expect(npmCalls[1][2]).toMatchObject({ cwd: subDir });
568
- });
569
- });
570
- describe('updateAllPlugins', () => {
571
- const testDirA = path.join(PLUGINS_DIR, 'plugin-a');
572
- const testDirB = path.join(PLUGINS_DIR, 'plugin-b');
573
- const testDirC = path.join(PLUGINS_DIR, 'plugin-c');
574
- beforeEach(() => {
575
- fs.mkdirSync(testDirA, { recursive: true });
576
- fs.mkdirSync(testDirB, { recursive: true });
577
- fs.mkdirSync(testDirC, { recursive: true });
578
- fs.writeFileSync(path.join(testDirA, 'cmd.js'), 'cli({ site: "a", name: "cmd", access: "read" })');
579
- fs.writeFileSync(path.join(testDirB, 'cmd.js'), 'cli({ site: "b", name: "cmd", access: "read" })');
580
- fs.writeFileSync(path.join(testDirC, 'cmd.js'), 'cli({ site: "c", name: "cmd", access: "read" })');
581
- const lock = _readLockFile();
582
- lock['plugin-a'] = {
583
- source: { kind: 'git', url: 'https://github.com/user/plugin-a.git' },
584
- commitHash: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
585
- installedAt: '2025-01-01T00:00:00.000Z',
586
- };
587
- lock['plugin-b'] = {
588
- source: { kind: 'git', url: 'https://github.com/user/plugin-b.git' },
589
- commitHash: 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
590
- installedAt: '2025-01-01T00:00:00.000Z',
591
- };
592
- lock['plugin-c'] = {
593
- source: { kind: 'git', url: 'https://github.com/user/plugin-c.git' },
594
- commitHash: 'cccccccccccccccccccccccccccccccccccccccc',
595
- installedAt: '2025-01-01T00:00:00.000Z',
596
- };
597
- _writeLockFile(lock);
598
- });
599
- afterEach(() => {
600
- try {
601
- fs.rmSync(testDirA, { recursive: true });
602
- }
603
- catch { }
604
- try {
605
- fs.rmSync(testDirB, { recursive: true });
606
- }
607
- catch { }
608
- try {
609
- fs.rmSync(testDirC, { recursive: true });
610
- }
611
- catch { }
612
- const lock = _readLockFile();
613
- delete lock['plugin-a'];
614
- delete lock['plugin-b'];
615
- delete lock['plugin-c'];
616
- _writeLockFile(lock);
617
- vi.clearAllMocks();
618
- });
619
- it('collects successes and failures without throwing', () => {
620
- mockExecFileSync.mockImplementation((cmd, args) => {
621
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
622
- const cloneUrl = String(args[3]);
623
- const cloneDir = String(args[4]);
624
- fs.mkdirSync(cloneDir, { recursive: true });
625
- fs.writeFileSync(path.join(cloneDir, 'cmd.js'), 'cli({ site: "test", name: "hello", access: "read" })');
626
- if (cloneUrl.includes('plugin-b')) {
627
- fs.writeFileSync(path.join(cloneDir, 'package.json'), JSON.stringify({ name: 'plugin-b' }));
628
- }
629
- return '';
630
- }
631
- if (cmd === 'npm' && Array.isArray(args) && args[0] === 'install') {
632
- throw new Error('Network error');
633
- }
634
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
635
- return '1234567890abcdef1234567890abcdef12345678\n';
636
- }
637
- return '';
638
- });
639
- const results = _updateAllPlugins();
640
- const resA = results.find(r => r.name === 'plugin-a');
641
- const resB = results.find(r => r.name === 'plugin-b');
642
- const resC = results.find(r => r.name === 'plugin-c');
643
- expect(resA).toBeDefined();
644
- expect(resA.success).toBe(true);
645
- expect(resB).toBeDefined();
646
- expect(resB.success).toBe(false);
647
- expect(resB.error).toContain('Network error');
648
- expect(resC).toBeDefined();
649
- expect(resC.success).toBe(true);
650
- });
651
- });
652
- // ── Monorepo-specific tests ─────────────────────────────────────────────────
653
- describe('parseSource with monorepo subplugin', () => {
654
- it('parses github:user/repo/subplugin format', () => {
655
- const result = _parseSource('github:ByteYue/bycli-plugins/polymarket');
656
- expect(result).toEqual({
657
- type: 'git',
658
- cloneUrl: 'https://github.com/ByteYue/bycli-plugins.git',
659
- name: 'bycli-plugins',
660
- subPlugin: 'polymarket',
661
- });
662
- });
663
- it('strips bycli-plugin- prefix from repo name in subplugin format', () => {
664
- const result = _parseSource('github:user/bycli-plugin-collection/defi');
665
- expect(result.name).toBe('collection');
666
- expect(result.subPlugin).toBe('defi');
667
- });
668
- it('still parses github:user/repo without subplugin', () => {
669
- const result = _parseSource('github:user/my-repo');
670
- expect(result).toEqual({
671
- type: 'git',
672
- cloneUrl: 'https://github.com/user/my-repo.git',
673
- name: 'my-repo',
674
- });
675
- expect(result.subPlugin).toBeUndefined();
676
- });
677
- });
678
- describe('isSymlinkSync', () => {
679
- let tmpDir;
680
- beforeEach(() => {
681
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'bycli-symlink-test-'));
682
- });
683
- afterEach(() => {
684
- fs.rmSync(tmpDir, { recursive: true, force: true });
685
- });
686
- it('returns false for a regular directory', () => {
687
- const dir = path.join(tmpDir, 'regular');
688
- fs.mkdirSync(dir);
689
- expect(_isSymlinkSync(dir)).toBe(false);
690
- });
691
- it('returns true for a symlink', () => {
692
- const target = path.join(tmpDir, 'target');
693
- const link = path.join(tmpDir, 'link');
694
- fs.mkdirSync(target);
695
- fs.symlinkSync(target, link, 'dir');
696
- expect(_isSymlinkSync(link)).toBe(true);
697
- });
698
- it('returns false for non-existent path', () => {
699
- expect(_isSymlinkSync(path.join(tmpDir, 'nope'))).toBe(false);
700
- });
701
- });
702
- describe('monorepo uninstall with symlink', () => {
703
- let tmpDir;
704
- let pluginDir;
705
- let monoDir;
706
- beforeEach(() => {
707
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'bycli-mono-uninstall-'));
708
- pluginDir = path.join(PLUGINS_DIR, '__test-mono-sub__');
709
- monoDir = path.join(_getMonoreposDir(), '__test-mono__');
710
- const subDir = path.join(monoDir, 'packages', 'sub');
711
- fs.mkdirSync(subDir, { recursive: true });
712
- fs.writeFileSync(path.join(subDir, 'cmd.js'), 'cli({ site: "test", name: "cmd", access: "read" })');
713
- fs.mkdirSync(PLUGINS_DIR, { recursive: true });
714
- fs.symlinkSync(subDir, pluginDir, 'dir');
715
- const lock = _readLockFile();
716
- lock['__test-mono-sub__'] = {
717
- source: {
718
- kind: 'monorepo',
719
- url: 'https://github.com/user/test.git',
720
- repoName: '__test-mono__',
721
- subPath: 'packages/sub',
722
- },
723
- commitHash: 'abc123',
724
- installedAt: '2025-01-01T00:00:00.000Z',
725
- };
726
- _writeLockFile(lock);
727
- });
728
- afterEach(() => {
729
- try {
730
- fs.unlinkSync(pluginDir);
731
- }
732
- catch { }
733
- try {
734
- fs.rmSync(pluginDir, { recursive: true, force: true });
735
- }
736
- catch { }
737
- try {
738
- fs.rmSync(monoDir, { recursive: true, force: true });
739
- }
740
- catch { }
741
- const lock = _readLockFile();
742
- delete lock['__test-mono-sub__'];
743
- _writeLockFile(lock);
744
- });
745
- it('removes symlink but keeps monorepo if other sub-plugins reference it', () => {
746
- const lock = _readLockFile();
747
- lock['__test-mono-other__'] = {
748
- source: {
749
- kind: 'monorepo',
750
- url: 'https://github.com/user/test.git',
751
- repoName: '__test-mono__',
752
- subPath: 'packages/other',
753
- },
754
- commitHash: 'abc123',
755
- installedAt: '2025-01-01T00:00:00.000Z',
756
- };
757
- _writeLockFile(lock);
758
- uninstallPlugin('__test-mono-sub__');
759
- expect(fs.existsSync(pluginDir)).toBe(false);
760
- expect(fs.existsSync(monoDir)).toBe(true);
761
- expect(_readLockFile()['__test-mono-sub__']).toBeUndefined();
762
- expect(_readLockFile()['__test-mono-other__']).toBeDefined();
763
- const finalLock = _readLockFile();
764
- delete finalLock['__test-mono-other__'];
765
- _writeLockFile(finalLock);
766
- });
767
- it('removes symlink AND monorepo dir when last sub-plugin is uninstalled', () => {
768
- uninstallPlugin('__test-mono-sub__');
769
- expect(fs.existsSync(pluginDir)).toBe(false);
770
- expect(fs.existsSync(monoDir)).toBe(false);
771
- expect(_readLockFile()['__test-mono-sub__']).toBeUndefined();
772
- });
773
- });
774
- describe('listPlugins with monorepo metadata', () => {
775
- const testSymlinkTarget = path.join(os.tmpdir(), 'bycli-list-mono-target');
776
- const testLink = path.join(PLUGINS_DIR, '__test-mono-list__');
777
- beforeEach(() => {
778
- fs.mkdirSync(testSymlinkTarget, { recursive: true });
779
- fs.writeFileSync(path.join(testSymlinkTarget, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
780
- fs.mkdirSync(PLUGINS_DIR, { recursive: true });
781
- try {
782
- fs.unlinkSync(testLink);
783
- }
784
- catch { }
785
- fs.symlinkSync(testSymlinkTarget, testLink, 'dir');
786
- const lock = _readLockFile();
787
- lock['__test-mono-list__'] = {
788
- source: {
789
- kind: 'monorepo',
790
- url: 'https://github.com/user/test-mono.git',
791
- repoName: 'test-mono',
792
- subPath: 'packages/list',
793
- },
794
- commitHash: 'def456def456def456def456def456def456def4',
795
- installedAt: '2025-01-01T00:00:00.000Z',
796
- };
797
- _writeLockFile(lock);
798
- });
799
- afterEach(() => {
800
- try {
801
- fs.unlinkSync(testLink);
802
- }
803
- catch { }
804
- try {
805
- fs.rmSync(testSymlinkTarget, { recursive: true, force: true });
806
- }
807
- catch { }
808
- const lock = _readLockFile();
809
- delete lock['__test-mono-list__'];
810
- _writeLockFile(lock);
811
- });
812
- it('lists symlinked plugins with monorepoName', () => {
813
- const plugins = listPlugins();
814
- const found = plugins.find(p => p.name === '__test-mono-list__');
815
- expect(found).toBeDefined();
816
- expect(found.monorepoName).toBe('test-mono');
817
- expect(found.commands).toContain('hello');
818
- expect(found.source).toBe('https://github.com/user/test-mono.git');
819
- });
820
- });
821
- describe('installLocalPlugin', () => {
822
- let tmpDir;
823
- const pluginName = '__test-local-plugin__';
824
- beforeEach(() => {
825
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'bycli-local-install-'));
826
- fs.writeFileSync(path.join(tmpDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
827
- });
828
- afterEach(() => {
829
- const linkPath = path.join(PLUGINS_DIR, pluginName);
830
- try {
831
- fs.unlinkSync(linkPath);
832
- }
833
- catch { }
834
- try {
835
- fs.rmSync(tmpDir, { recursive: true, force: true });
836
- }
837
- catch { }
838
- const lock = _readLockFile();
839
- delete lock[pluginName];
840
- _writeLockFile(lock);
841
- });
842
- it('creates a symlink to the local directory', () => {
843
- const result = _installLocalPlugin(tmpDir, pluginName);
844
- expect(result).toBe(pluginName);
845
- const linkPath = path.join(PLUGINS_DIR, pluginName);
846
- expect(fs.existsSync(linkPath)).toBe(true);
847
- expect(_isSymlinkSync(linkPath)).toBe(true);
848
- });
849
- it('records local: source in lockfile', () => {
850
- _installLocalPlugin(tmpDir, pluginName);
851
- const lock = _readLockFile();
852
- expect(lock[pluginName]).toBeDefined();
853
- expect(lock[pluginName].source).toEqual({ kind: 'local', path: path.resolve(tmpDir) });
854
- });
855
- it('lists the recorded local source', () => {
856
- _installLocalPlugin(tmpDir, pluginName);
857
- const plugins = listPlugins();
858
- const found = plugins.find(p => p.name === pluginName);
859
- expect(found).toBeDefined();
860
- expect(found.source).toBe(`local:${path.resolve(tmpDir)}`);
861
- });
862
- it('throws for non-existent path', () => {
863
- expect(() => _installLocalPlugin('/does/not/exist', 'x')).toThrow('does not exist');
864
- });
865
- });
866
- describe('isLocalPluginSource', () => {
867
- it('detects lockfile local sources', () => {
868
- expect(_isLocalPluginSource('local:/tmp/plugin')).toBe(true);
869
- expect(_isLocalPluginSource('https://github.com/user/repo.git')).toBe(false);
870
- expect(_isLocalPluginSource(undefined)).toBe(false);
871
- });
872
- });
873
- describe('plugin source helpers', () => {
874
- it('formats local plugin sources consistently', () => {
875
- const dir = path.join(os.tmpdir(), 'bycli-plugin-source');
876
- expect(_toLocalPluginSource(dir)).toBe(`local:${path.resolve(dir)}`);
877
- });
878
- it('serializes structured local sources consistently', () => {
879
- const dir = path.join(os.tmpdir(), 'bycli-plugin-source');
880
- expect(_toStoredPluginSource({ kind: 'local', path: dir })).toBe(`local:${path.resolve(dir)}`);
881
- });
882
- it('prefers lockfile source over git remote lookup', () => {
883
- const dir = path.join(os.tmpdir(), 'bycli-plugin-source');
884
- const localPath = path.resolve(path.join(os.tmpdir(), 'bycli-plugin-source-local'));
885
- const source = _resolveStoredPluginSource({
886
- source: { kind: 'local', path: localPath },
887
- commitHash: 'local',
888
- installedAt: '2025-01-01T00:00:00.000Z',
889
- }, dir);
890
- expect(source).toBe(`local:${localPath}`);
891
- });
892
- it('returns structured monorepo sources unchanged', () => {
893
- const dir = path.join(os.tmpdir(), 'bycli-plugin-source');
894
- const source = _resolvePluginSource({
895
- source: {
896
- kind: 'monorepo',
897
- url: 'https://github.com/user/bycli-plugins.git',
898
- repoName: 'bycli-plugins',
899
- subPath: 'packages/alpha',
900
- },
901
- commitHash: 'abcdef1234567890abcdef1234567890abcdef12',
902
- installedAt: '2025-01-01T00:00:00.000Z',
903
- }, dir);
904
- expect(source).toEqual({
905
- kind: 'monorepo',
906
- url: 'https://github.com/user/bycli-plugins.git',
907
- repoName: 'bycli-plugins',
908
- subPath: 'packages/alpha',
909
- });
910
- });
911
- });
912
- describe('moveDir', () => {
913
- it('cleans up destination when EXDEV fallback copy fails', () => {
914
- const src = path.join(os.tmpdir(), 'bycli-move-src');
915
- const dest = path.join(os.tmpdir(), 'bycli-move-dest');
916
- const renameErr = Object.assign(new Error('cross-device link not permitted'), { code: 'EXDEV' });
917
- const copyErr = new Error('copy failed');
918
- const renameSync = vi.fn(() => { throw renameErr; });
919
- const cpSync = vi.fn(() => { throw copyErr; });
920
- const rmSync = vi.fn(() => undefined);
921
- expect(() => _moveDir(src, dest, { renameSync, cpSync, rmSync })).toThrow(copyErr);
922
- expect(renameSync).toHaveBeenCalledWith(src, dest);
923
- expect(cpSync).toHaveBeenCalledWith(src, dest, { recursive: true });
924
- expect(rmSync).toHaveBeenCalledWith(dest, { recursive: true, force: true });
925
- });
926
- });
927
- describe('installPlugin transactional staging', () => {
928
- const standaloneSource = 'github:user/bycli-plugin-__test-transactional-standalone__';
929
- const standaloneName = '__test-transactional-standalone__';
930
- const standaloneDir = path.join(PLUGINS_DIR, standaloneName);
931
- const monorepoSource = 'github:user/bycli-plugins-__test-transactional__';
932
- const monorepoRepoDir = path.join(_getMonoreposDir(), 'bycli-plugins-__test-transactional__');
933
- const monorepoLink = path.join(PLUGINS_DIR, 'alpha');
934
- beforeEach(() => {
935
- mockExecFileSync.mockClear();
936
- mockExecSync.mockClear();
937
- });
938
- afterEach(() => {
939
- try {
940
- fs.unlinkSync(monorepoLink);
941
- }
942
- catch { }
943
- try {
944
- fs.rmSync(monorepoLink, { recursive: true, force: true });
945
- }
946
- catch { }
947
- try {
948
- fs.rmSync(monorepoRepoDir, { recursive: true, force: true });
949
- }
950
- catch { }
951
- try {
952
- fs.rmSync(standaloneDir, { recursive: true, force: true });
953
- }
954
- catch { }
955
- const lock = _readLockFile();
956
- delete lock[standaloneName];
957
- delete lock.alpha;
958
- _writeLockFile(lock);
959
- vi.clearAllMocks();
960
- });
961
- it('does not expose the final standalone plugin dir when lifecycle fails in staging', () => {
962
- mockExecFileSync.mockImplementation((cmd, args) => {
963
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
964
- const cloneDir = String(args[args.length - 1]);
965
- fs.mkdirSync(cloneDir, { recursive: true });
966
- fs.writeFileSync(path.join(cloneDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
967
- fs.writeFileSync(path.join(cloneDir, 'package.json'), JSON.stringify({ name: standaloneName }));
968
- return '';
969
- }
970
- if (cmd === 'npm' && Array.isArray(args) && args[0] === 'install') {
971
- throw new Error('boom');
972
- }
973
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
974
- return '1234567890abcdef1234567890abcdef12345678\n';
975
- }
976
- return '';
977
- });
978
- expect(() => installPlugin(standaloneSource)).toThrow(`npm install failed`);
979
- expect(fs.existsSync(standaloneDir)).toBe(false);
980
- expect(_readLockFile()[standaloneName]).toBeUndefined();
981
- });
982
- it('does not expose monorepo links or repo dir when lifecycle fails in staging', () => {
983
- mockExecFileSync.mockImplementation((cmd, args) => {
984
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
985
- const cloneDir = String(args[args.length - 1]);
986
- const alphaDir = path.join(cloneDir, 'packages', 'alpha');
987
- fs.mkdirSync(alphaDir, { recursive: true });
988
- fs.writeFileSync(path.join(cloneDir, 'package.json'), JSON.stringify({
989
- name: 'bycli-plugins-__test-transactional__',
990
- private: true,
991
- }));
992
- fs.writeFileSync(path.join(cloneDir, 'bycli-plugin.json'), JSON.stringify({
993
- plugins: {
994
- alpha: { path: 'packages/alpha' },
995
- },
996
- }));
997
- fs.writeFileSync(path.join(alphaDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
998
- return '';
999
- }
1000
- if (cmd === 'npm' && Array.isArray(args) && args[0] === 'install') {
1001
- throw new Error('boom');
1002
- }
1003
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
1004
- return '1234567890abcdef1234567890abcdef12345678\n';
1005
- }
1006
- return '';
1007
- });
1008
- expect(() => installPlugin(monorepoSource)).toThrow(`npm install failed`);
1009
- expect(fs.existsSync(monorepoRepoDir)).toBe(false);
1010
- expect(fs.existsSync(monorepoLink)).toBe(false);
1011
- expect(_readLockFile().alpha).toBeUndefined();
1012
- });
1013
- });
1014
- describe('installPlugin with existing monorepo', () => {
1015
- const repoName = '__test-existing-monorepo__';
1016
- const repoDir = path.join(_getMonoreposDir(), repoName);
1017
- const pluginName = 'beta';
1018
- const pluginLink = path.join(PLUGINS_DIR, pluginName);
1019
- beforeEach(() => {
1020
- mockExecFileSync.mockClear();
1021
- mockExecSync.mockClear();
1022
- });
1023
- afterEach(() => {
1024
- try {
1025
- fs.unlinkSync(pluginLink);
1026
- }
1027
- catch { }
1028
- try {
1029
- fs.rmSync(pluginLink, { recursive: true, force: true });
1030
- }
1031
- catch { }
1032
- try {
1033
- fs.rmSync(repoDir, { recursive: true, force: true });
1034
- }
1035
- catch { }
1036
- const lock = _readLockFile();
1037
- delete lock[pluginName];
1038
- _writeLockFile(lock);
1039
- vi.clearAllMocks();
1040
- });
1041
- it('reinstalls root dependencies when adding a sub-plugin from an existing monorepo', () => {
1042
- const subDir = path.join(repoDir, 'packages', pluginName);
1043
- fs.mkdirSync(subDir, { recursive: true });
1044
- fs.writeFileSync(path.join(repoDir, 'package.json'), JSON.stringify({
1045
- name: repoName,
1046
- private: true,
1047
- workspaces: ['packages/*'],
1048
- }));
1049
- fs.writeFileSync(path.join(repoDir, 'bycli-plugin.json'), JSON.stringify({
1050
- plugins: {
1051
- [pluginName]: { path: `packages/${pluginName}` },
1052
- },
1053
- }));
1054
- fs.writeFileSync(path.join(subDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
1055
- mockExecFileSync.mockImplementation((cmd, args) => {
1056
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
1057
- const cloneDir = String(args[4]);
1058
- fs.mkdirSync(cloneDir, { recursive: true });
1059
- fs.writeFileSync(path.join(cloneDir, 'bycli-plugin.json'), JSON.stringify({
1060
- plugins: {
1061
- [pluginName]: { path: `packages/${pluginName}` },
1062
- },
1063
- }));
1064
- return '';
1065
- }
1066
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
1067
- return '1234567890abcdef1234567890abcdef12345678\n';
1068
- }
1069
- return '';
1070
- });
1071
- installPlugin(`github:user/${repoName}/${pluginName}`);
1072
- const npmCalls = mockExecFileSync.mock.calls.filter(([cmd, args]) => cmd === 'npm' && Array.isArray(args) && args[0] === 'install');
1073
- expect(npmCalls.some(([, , opts]) => opts?.cwd === repoDir)).toBe(true);
1074
- expect(fs.realpathSync(pluginLink)).toBe(fs.realpathSync(subDir));
1075
- });
1076
- });
1077
- describe('updatePlugin transactional staging', () => {
1078
- const standaloneName = '__test-transactional-update__';
1079
- const standaloneDir = path.join(PLUGINS_DIR, standaloneName);
1080
- const monorepoName = '__test-transactional-mono-update__';
1081
- const monorepoRepoDir = path.join(_getMonoreposDir(), monorepoName);
1082
- const monorepoPluginName = 'alpha-update';
1083
- const monorepoLink = path.join(PLUGINS_DIR, monorepoPluginName);
1084
- beforeEach(() => {
1085
- mockExecFileSync.mockClear();
1086
- mockExecSync.mockClear();
1087
- });
1088
- afterEach(() => {
1089
- try {
1090
- fs.unlinkSync(monorepoLink);
1091
- }
1092
- catch { }
1093
- try {
1094
- fs.rmSync(monorepoLink, { recursive: true, force: true });
1095
- }
1096
- catch { }
1097
- try {
1098
- fs.rmSync(monorepoRepoDir, { recursive: true, force: true });
1099
- }
1100
- catch { }
1101
- try {
1102
- fs.rmSync(standaloneDir, { recursive: true, force: true });
1103
- }
1104
- catch { }
1105
- const lock = _readLockFile();
1106
- delete lock[standaloneName];
1107
- delete lock[monorepoPluginName];
1108
- _writeLockFile(lock);
1109
- vi.clearAllMocks();
1110
- });
1111
- it('keeps the existing standalone plugin when staged update preparation fails', () => {
1112
- fs.mkdirSync(standaloneDir, { recursive: true });
1113
- fs.writeFileSync(path.join(standaloneDir, 'old.js'), 'cli({ site: "old", name: "old", access: "read" })');
1114
- const lock = _readLockFile();
1115
- lock[standaloneName] = {
1116
- source: {
1117
- kind: 'git',
1118
- url: 'https://github.com/user/bycli-plugin-__test-transactional-update__.git',
1119
- },
1120
- commitHash: 'oldhasholdhasholdhasholdhasholdhasholdh',
1121
- installedAt: '2025-01-01T00:00:00.000Z',
1122
- };
1123
- _writeLockFile(lock);
1124
- mockExecFileSync.mockImplementation((cmd, args) => {
1125
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
1126
- const cloneDir = String(args[4]);
1127
- fs.mkdirSync(cloneDir, { recursive: true });
1128
- fs.writeFileSync(path.join(cloneDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
1129
- fs.writeFileSync(path.join(cloneDir, 'package.json'), JSON.stringify({ name: standaloneName }));
1130
- return '';
1131
- }
1132
- if (cmd === 'npm' && Array.isArray(args) && args[0] === 'install') {
1133
- throw new Error('boom');
1134
- }
1135
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
1136
- return '1234567890abcdef1234567890abcdef12345678\n';
1137
- }
1138
- return '';
1139
- });
1140
- expect(() => updatePlugin(standaloneName)).toThrow('npm install failed');
1141
- expect(fs.existsSync(standaloneDir)).toBe(true);
1142
- expect(fs.readFileSync(path.join(standaloneDir, 'old.js'), 'utf-8')).toContain('site: "old"');
1143
- expect(_readLockFile()[standaloneName]?.commitHash).toBe('oldhasholdhasholdhasholdhasholdhasholdh');
1144
- });
1145
- it('keeps the existing monorepo repo and link when staged update preparation fails', () => {
1146
- const subDir = path.join(monorepoRepoDir, 'packages', monorepoPluginName);
1147
- fs.mkdirSync(subDir, { recursive: true });
1148
- fs.writeFileSync(path.join(subDir, 'old.js'), 'cli({ site: "old", name: "old", access: "read" })');
1149
- fs.mkdirSync(PLUGINS_DIR, { recursive: true });
1150
- fs.symlinkSync(subDir, monorepoLink, 'dir');
1151
- const lock = _readLockFile();
1152
- lock[monorepoPluginName] = {
1153
- source: {
1154
- kind: 'monorepo',
1155
- url: 'https://github.com/user/bycli-plugins-__test-transactional-mono-update__.git',
1156
- repoName: monorepoName,
1157
- subPath: `packages/${monorepoPluginName}`,
1158
- },
1159
- commitHash: 'oldmonooldmonooldmonooldmonooldmonoold',
1160
- installedAt: '2025-01-01T00:00:00.000Z',
1161
- };
1162
- _writeLockFile(lock);
1163
- mockExecFileSync.mockImplementation((cmd, args) => {
1164
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
1165
- const cloneDir = String(args[4]);
1166
- const alphaDir = path.join(cloneDir, 'packages', monorepoPluginName);
1167
- fs.mkdirSync(alphaDir, { recursive: true });
1168
- fs.writeFileSync(path.join(cloneDir, 'package.json'), JSON.stringify({
1169
- name: 'bycli-plugins-__test-transactional-mono-update__',
1170
- private: true,
1171
- }));
1172
- fs.writeFileSync(path.join(cloneDir, 'bycli-plugin.json'), JSON.stringify({
1173
- plugins: {
1174
- [monorepoPluginName]: { path: `packages/${monorepoPluginName}` },
1175
- },
1176
- }));
1177
- fs.writeFileSync(path.join(alphaDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
1178
- return '';
1179
- }
1180
- if (cmd === 'npm' && Array.isArray(args) && args[0] === 'install') {
1181
- throw new Error('boom');
1182
- }
1183
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
1184
- return '1234567890abcdef1234567890abcdef12345678\n';
1185
- }
1186
- return '';
1187
- });
1188
- expect(() => updatePlugin(monorepoPluginName)).toThrow('npm install failed');
1189
- expect(fs.existsSync(monorepoRepoDir)).toBe(true);
1190
- expect(fs.existsSync(monorepoLink)).toBe(true);
1191
- expect(fs.readFileSync(path.join(subDir, 'old.js'), 'utf-8')).toContain('site: "old"');
1192
- expect(_readLockFile()[monorepoPluginName]?.commitHash).toBe('oldmonooldmonooldmonooldmonooldmonoold');
1193
- });
1194
- it('relinks monorepo plugins when the updated manifest moves their subPath', () => {
1195
- const oldSubDir = path.join(monorepoRepoDir, 'packages', 'old-alpha');
1196
- fs.mkdirSync(oldSubDir, { recursive: true });
1197
- fs.writeFileSync(path.join(oldSubDir, 'old.js'), 'cli({ site: "old", name: "old", access: "read" })');
1198
- fs.mkdirSync(PLUGINS_DIR, { recursive: true });
1199
- fs.symlinkSync(oldSubDir, monorepoLink, 'dir');
1200
- const lock = _readLockFile();
1201
- lock[monorepoPluginName] = {
1202
- source: {
1203
- kind: 'monorepo',
1204
- url: 'https://github.com/user/bycli-plugins-__test-transactional-mono-update__.git',
1205
- repoName: monorepoName,
1206
- subPath: 'packages/old-alpha',
1207
- },
1208
- commitHash: 'oldmonooldmonooldmonooldmonooldmonoold',
1209
- installedAt: '2025-01-01T00:00:00.000Z',
1210
- };
1211
- _writeLockFile(lock);
1212
- mockExecFileSync.mockImplementation((cmd, args) => {
1213
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
1214
- const cloneDir = String(args[4]);
1215
- const movedDir = path.join(cloneDir, 'packages', 'moved-alpha');
1216
- fs.mkdirSync(movedDir, { recursive: true });
1217
- fs.writeFileSync(path.join(cloneDir, 'bycli-plugin.json'), JSON.stringify({
1218
- plugins: {
1219
- [monorepoPluginName]: { path: 'packages/moved-alpha' },
1220
- },
1221
- }));
1222
- fs.writeFileSync(path.join(movedDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
1223
- return '';
1224
- }
1225
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
1226
- return '1234567890abcdef1234567890abcdef12345678\n';
1227
- }
1228
- return '';
1229
- });
1230
- updatePlugin(monorepoPluginName);
1231
- const expectedTarget = path.join(monorepoRepoDir, 'packages', 'moved-alpha');
1232
- expect(fs.realpathSync(monorepoLink)).toBe(fs.realpathSync(expectedTarget));
1233
- expect(_readLockFile()[monorepoPluginName]?.source).toMatchObject({
1234
- kind: 'monorepo',
1235
- subPath: 'packages/moved-alpha',
1236
- });
1237
- });
1238
- it('rejects monorepo updates whose manifest path escapes the repo root', () => {
1239
- const oldSubDir = path.join(monorepoRepoDir, 'packages', 'old-alpha');
1240
- fs.mkdirSync(oldSubDir, { recursive: true });
1241
- fs.writeFileSync(path.join(oldSubDir, 'old.js'), 'cli({ site: "old", name: "old", access: "read" })');
1242
- fs.mkdirSync(PLUGINS_DIR, { recursive: true });
1243
- fs.symlinkSync(oldSubDir, monorepoLink, 'dir');
1244
- const lock = _readLockFile();
1245
- lock[monorepoPluginName] = {
1246
- source: {
1247
- kind: 'monorepo',
1248
- url: 'https://github.com/user/bycli-plugins-__test-transactional-mono-update__.git',
1249
- repoName: monorepoName,
1250
- subPath: 'packages/old-alpha',
1251
- },
1252
- commitHash: 'oldmonooldmonooldmonooldmonooldmonoold',
1253
- installedAt: '2025-01-01T00:00:00.000Z',
1254
- };
1255
- _writeLockFile(lock);
1256
- mockExecFileSync.mockImplementation((cmd, args) => {
1257
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
1258
- const cloneDir = String(args[4]);
1259
- fs.mkdirSync(cloneDir, { recursive: true });
1260
- fs.writeFileSync(path.join(cloneDir, 'bycli-plugin.json'), JSON.stringify({
1261
- plugins: {
1262
- [monorepoPluginName]: { path: '../outside-alpha' },
1263
- },
1264
- }));
1265
- return '';
1266
- }
1267
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
1268
- return '1234567890abcdef1234567890abcdef12345678\n';
1269
- }
1270
- return '';
1271
- });
1272
- expect(() => updatePlugin(monorepoPluginName)).toThrow('escapes repo root');
1273
- expect(fs.realpathSync(monorepoLink)).toBe(fs.realpathSync(oldSubDir));
1274
- expect(_readLockFile()[monorepoPluginName]?.source).toMatchObject({
1275
- kind: 'monorepo',
1276
- subPath: 'packages/old-alpha',
1277
- });
1278
- });
1279
- it('rolls back the monorepo repo swap when relinking fails', () => {
1280
- const oldSubDir = path.join(monorepoRepoDir, 'packages', 'old-alpha');
1281
- fs.mkdirSync(oldSubDir, { recursive: true });
1282
- fs.writeFileSync(path.join(oldSubDir, 'old.js'), 'cli({ site: "old", name: "old", access: "read" })');
1283
- fs.mkdirSync(monorepoLink, { recursive: true });
1284
- fs.writeFileSync(path.join(monorepoLink, 'blocker.txt'), 'not a symlink');
1285
- const lock = _readLockFile();
1286
- lock[monorepoPluginName] = {
1287
- source: {
1288
- kind: 'monorepo',
1289
- url: 'https://github.com/user/bycli-plugins-__test-transactional-mono-update__.git',
1290
- repoName: monorepoName,
1291
- subPath: 'packages/old-alpha',
1292
- },
1293
- commitHash: 'oldmonooldmonooldmonooldmonooldmonoold',
1294
- installedAt: '2025-01-01T00:00:00.000Z',
1295
- };
1296
- _writeLockFile(lock);
1297
- mockExecFileSync.mockImplementation((cmd, args) => {
1298
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'clone') {
1299
- const cloneDir = String(args[4]);
1300
- const movedDir = path.join(cloneDir, 'packages', 'moved-alpha');
1301
- fs.mkdirSync(movedDir, { recursive: true });
1302
- fs.writeFileSync(path.join(cloneDir, 'bycli-plugin.json'), JSON.stringify({
1303
- plugins: {
1304
- [monorepoPluginName]: { path: 'packages/moved-alpha' },
1305
- },
1306
- }));
1307
- fs.writeFileSync(path.join(movedDir, 'hello.js'), 'cli({ site: "test", name: "hello", access: "read" })');
1308
- return '';
1309
- }
1310
- if (cmd === 'git' && Array.isArray(args) && args[0] === 'rev-parse' && args[1] === 'HEAD') {
1311
- return '1234567890abcdef1234567890abcdef12345678\n';
1312
- }
1313
- return '';
1314
- });
1315
- expect(() => updatePlugin(monorepoPluginName)).toThrow('to be a symlink');
1316
- expect(fs.existsSync(path.join(monorepoRepoDir, 'packages', 'old-alpha', 'old.js'))).toBe(true);
1317
- expect(fs.existsSync(path.join(monorepoRepoDir, 'packages', 'moved-alpha'))).toBe(false);
1318
- expect(fs.readFileSync(path.join(monorepoLink, 'blocker.txt'), 'utf-8')).toBe('not a symlink');
1319
- expect(_readLockFile()[monorepoPluginName]?.source).toMatchObject({
1320
- kind: 'monorepo',
1321
- subPath: 'packages/old-alpha',
1322
- });
1323
- });
1324
- });