@sovovs/bycli 1.8.0 → 2.1.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 (539) hide show
  1. package/cli-manifest.json +0 -61
  2. package/clis/twitter/search.js +3 -3
  3. package/dist/src/adapter-shadow.js +2 -2
  4. package/dist/src/browser/analyze.d.ts +10 -99
  5. package/dist/src/browser/analyze.js +10 -226
  6. package/dist/src/browser/cdp.js +67 -7
  7. package/dist/src/browser/daemon-client.d.ts +2 -0
  8. package/dist/src/browser/daemon-client.js +1 -1
  9. package/dist/src/browser/extension-capabilities.d.ts +13 -0
  10. package/dist/src/browser/extension-capabilities.js +22 -0
  11. package/dist/src/browser/extension-capabilities.test.d.ts +1 -0
  12. package/dist/src/browser/extension-version-metadata.test.d.ts +1 -0
  13. package/dist/src/browser/navigation-guard.d.ts +78 -0
  14. package/dist/src/browser/navigation-guard.js +142 -0
  15. package/dist/src/browser/navigation-guard.test.d.ts +1 -0
  16. package/dist/src/browser/page.d.ts +1 -0
  17. package/dist/src/browser/page.js +20 -1
  18. package/dist/src/browser/url-policy.d.ts +89 -0
  19. package/dist/src/browser/url-policy.js +311 -0
  20. package/dist/src/browser/url-policy.test.d.ts +1 -0
  21. package/dist/src/browser/verify-fixture.js +2 -2
  22. package/dist/src/build-manifest.js +4 -2
  23. package/dist/src/capabilityRouting.d.ts +3 -2
  24. package/dist/src/capabilityRouting.js +10 -2
  25. package/dist/src/cli.js +11 -14
  26. package/dist/src/commanderAdapter.js +5 -5
  27. package/dist/src/config-paths.d.ts +19 -0
  28. package/dist/src/config-paths.js +31 -0
  29. package/dist/src/daemon.js +256 -0
  30. package/dist/src/discovery.d.ts +10 -3
  31. package/dist/src/discovery.js +20 -10
  32. package/dist/src/discovery.test.d.ts +1 -0
  33. package/dist/src/execution.d.ts +5 -0
  34. package/dist/src/execution.js +272 -48
  35. package/dist/src/help.js +8 -8
  36. package/dist/src/main.js +18 -2
  37. package/dist/src/manifest-schema.d.ts +9 -0
  38. package/dist/src/manifest-schema.js +162 -0
  39. package/dist/src/manifest-schema.test.d.ts +1 -0
  40. package/dist/src/manifest-types.d.ts +1 -1
  41. package/dist/src/observation/redaction.js +10 -4
  42. package/dist/src/plugin.js +11 -8
  43. package/dist/src/recorder/highlevel/analyze.d.ts +29 -0
  44. package/dist/src/recorder/highlevel/analyze.js +91 -0
  45. package/dist/src/recorder/highlevel/init.d.ts +125 -0
  46. package/dist/src/recorder/highlevel/init.js +279 -0
  47. package/dist/src/recorder/highlevel/init.test.d.ts +1 -0
  48. package/dist/src/recorder/highlevel/verify.d.ts +73 -0
  49. package/dist/src/recorder/highlevel/verify.js +74 -0
  50. package/dist/src/recorder/http/analyze-runner.d.ts +28 -0
  51. package/dist/src/recorder/http/analyze-runner.js +78 -0
  52. package/dist/src/recorder/http/analyze-runner.test.d.ts +1 -0
  53. package/dist/src/recorder/http/handlers.d.ts +51 -0
  54. package/dist/src/recorder/http/handlers.js +219 -0
  55. package/dist/src/recorder/http/wrapper-config.d.ts +20 -0
  56. package/dist/src/recorder/http/wrapper-config.js +82 -0
  57. package/dist/src/recorder/http/wrapper-envelope.d.ts +31 -0
  58. package/dist/src/recorder/http/wrapper-envelope.js +51 -0
  59. package/dist/src/recorder/http/wrapper-gates.d.ts +16 -0
  60. package/dist/src/recorder/http/wrapper-gates.js +28 -0
  61. package/dist/src/recorder/http/wrapper-metrics.d.ts +1 -0
  62. package/dist/src/recorder/http/wrapper-metrics.js +5 -0
  63. package/dist/src/recorder/http/wrapper-registry.d.ts +50 -0
  64. package/dist/src/recorder/http/wrapper-registry.js +98 -0
  65. package/dist/src/recorder/http/wrapper-server.d.ts +59 -0
  66. package/dist/src/recorder/http/wrapper-server.js +240 -0
  67. package/dist/src/recorder/http/wrapper.test.d.ts +1 -0
  68. package/dist/src/recorder/observability/logger.d.ts +5 -0
  69. package/dist/src/recorder/observability/logger.js +13 -0
  70. package/dist/src/recorder/runner/config.d.ts +34 -0
  71. package/dist/src/recorder/runner/config.js +84 -0
  72. package/dist/src/recorder/runner/config.test.d.ts +1 -0
  73. package/dist/src/recorder/runner/reap.d.ts +79 -0
  74. package/dist/src/recorder/runner/reap.js +230 -0
  75. package/dist/src/recorder/runner/reap.test.d.ts +1 -0
  76. package/dist/src/recorder/runner/runner-port.d.ts +95 -0
  77. package/dist/src/recorder/runner/runner-port.js +518 -0
  78. package/dist/src/recorder/runner/runner-port.test.d.ts +1 -0
  79. package/dist/src/recorder/runner/session-keys.d.ts +28 -0
  80. package/dist/src/recorder/runner/session-keys.js +72 -0
  81. package/dist/src/recorder/runner/session-keys.test.d.ts +1 -0
  82. package/dist/src/recorder/runner/verify-runner-main.d.ts +96 -0
  83. package/dist/src/recorder/runner/verify-runner-main.js +292 -0
  84. package/dist/src/recorder/runner/verify-runner-main.test.d.ts +1 -0
  85. package/dist/src/registry-api.d.ts +1 -1
  86. package/dist/src/registry-api.types.test.d.ts +1 -0
  87. package/dist/src/registry-transaction.d.ts +42 -0
  88. package/dist/src/registry-transaction.js +194 -0
  89. package/dist/src/registry-transaction.test.d.ts +1 -0
  90. package/dist/src/registry.d.ts +58 -16
  91. package/dist/src/registry.js +131 -15
  92. package/dist/src/serialization.d.ts +1 -1
  93. package/dist/src/serialization.js +3 -3
  94. package/dist/src/types.d.ts +2 -0
  95. package/package.json +8 -5
  96. package/scripts/m1-daemon-navigate-drive.mjs +138 -0
  97. package/scripts/m1-extension-spike.mjs +237 -0
  98. package/scripts/m1-live-spike.mjs +156 -0
  99. package/scripts/m6b-connect-back-spike.sh +31 -0
  100. package/clis/12306/utils.test.js +0 -331
  101. package/clis/1688/assets.test.js +0 -39
  102. package/clis/1688/download.test.js +0 -31
  103. package/clis/1688/item.test.js +0 -67
  104. package/clis/1688/search.test.js +0 -75
  105. package/clis/1688/shared.test.js +0 -57
  106. package/clis/1688/store.test.js +0 -62
  107. package/clis/36kr/article.test.js +0 -46
  108. package/clis/36kr/hot.test.js +0 -15
  109. package/clis/36kr/news.test.js +0 -85
  110. package/clis/51job/utils.test.js +0 -69
  111. package/clis/_atlassian/shared.test.js +0 -170
  112. package/clis/aibase/news.test.js +0 -59
  113. package/clis/amazon/bestsellers.test.js +0 -29
  114. package/clis/amazon/discussion.test.js +0 -124
  115. package/clis/amazon/offer.test.js +0 -29
  116. package/clis/amazon/product.test.js +0 -24
  117. package/clis/amazon/rankings.test.js +0 -41
  118. package/clis/amazon/search.test.js +0 -22
  119. package/clis/amazon/shared.test.js +0 -44
  120. package/clis/apple-podcasts/commands.test.js +0 -119
  121. package/clis/apple-podcasts/utils.test.js +0 -57
  122. package/clis/arxiv/arxiv.test.js +0 -112
  123. package/clis/baidu-scholar/search.test.js +0 -23
  124. package/clis/barchart/greeks.test.js +0 -138
  125. package/clis/bilibili/comment.test.js +0 -153
  126. package/clis/bilibili/comments.test.js +0 -142
  127. package/clis/bilibili/dynamic.test.js +0 -68
  128. package/clis/bilibili/hot.test.js +0 -17
  129. package/clis/bilibili/subtitle.test.js +0 -196
  130. package/clis/bilibili/summary.test.js +0 -210
  131. package/clis/bilibili/utils.test.js +0 -61
  132. package/clis/bilibili/video.test.js +0 -132
  133. package/clis/binance/commands.test.js +0 -70
  134. package/clis/bloomberg/utils.test.js +0 -129
  135. package/clis/booking/booking.test.js +0 -356
  136. package/clis/boss/chatlist.test.js +0 -211
  137. package/clis/boss/chatmsg.test.js +0 -230
  138. package/clis/boss/search.test.js +0 -78
  139. package/clis/boss/utils.test.js +0 -34
  140. package/clis/brave/search.test.js +0 -76
  141. package/clis/chaoxing/utils.test.js +0 -45
  142. package/clis/chatgpt/commands.test.js +0 -45
  143. package/clis/chatgpt/envelope.test.js +0 -108
  144. package/clis/chatgpt/image.test.js +0 -188
  145. package/clis/chatgpt/utils.test.js +0 -330
  146. package/clis/chatgpt-app/ax.test.js +0 -35
  147. package/clis/chatwise/composer.test.js +0 -186
  148. package/clis/chess/analyze.test.js +0 -79
  149. package/clis/chess/game.test.js +0 -178
  150. package/clis/chess/games.test.js +0 -164
  151. package/clis/chess/stats.test.js +0 -79
  152. package/clis/chess/utils.test.js +0 -230
  153. package/clis/claude/ask.test.js +0 -338
  154. package/clis/claude/commands.test.js +0 -118
  155. package/clis/claude/utils.test.js +0 -148
  156. package/clis/cnki/search.test.js +0 -18
  157. package/clis/codex/sidebar.test.js +0 -329
  158. package/clis/coingecko/coingecko.test.js +0 -109
  159. package/clis/confluence/commands.test.js +0 -195
  160. package/clis/coupang/coupang.test.js +0 -159
  161. package/clis/coupang/utils.test.js +0 -62
  162. package/clis/ctrip/ctrip.test.js +0 -719
  163. package/clis/dblp/dblp.test.js +0 -397
  164. package/clis/deepseek/ask.test.js +0 -312
  165. package/clis/deepseek/detail.test.js +0 -81
  166. package/clis/deepseek/send.test.js +0 -107
  167. package/clis/deepseek/utils.test.js +0 -370
  168. package/clis/defillama/defillama.test.js +0 -99
  169. package/clis/devto/devto.test.js +0 -236
  170. package/clis/dianping/dianping.test.js +0 -578
  171. package/clis/douban/download.test.js +0 -170
  172. package/clis/douban/movie-hot.test.js +0 -14
  173. package/clis/douban/search.test.js +0 -11
  174. package/clis/douban/subject.test.js +0 -11
  175. package/clis/douban/utils.test.js +0 -438
  176. package/clis/doubao/detail.test.js +0 -42
  177. package/clis/doubao/history.test.js +0 -37
  178. package/clis/doubao/utils.test.js +0 -344
  179. package/clis/douyin/_shared/browser-fetch.test.js +0 -64
  180. package/clis/douyin/_shared/creation-id.test.js +0 -22
  181. package/clis/douyin/_shared/imagex-upload.test.js +0 -87
  182. package/clis/douyin/_shared/sts2.test.js +0 -27
  183. package/clis/douyin/_shared/text-extra.test.js +0 -37
  184. package/clis/douyin/_shared/timing.test.js +0 -28
  185. package/clis/douyin/_shared/tos-upload-short-read.test.js +0 -83
  186. package/clis/douyin/_shared/tos-upload.test.js +0 -229
  187. package/clis/douyin/_shared/transcode.test.js +0 -91
  188. package/clis/douyin/_shared/vod-upload.test.js +0 -38
  189. package/clis/douyin/activities.test.js +0 -55
  190. package/clis/douyin/collections.test.js +0 -45
  191. package/clis/douyin/delete.test.js +0 -100
  192. package/clis/douyin/draft.test.js +0 -335
  193. package/clis/douyin/drafts.test.js +0 -11
  194. package/clis/douyin/hashtag.test.js +0 -171
  195. package/clis/douyin/location.test.js +0 -23
  196. package/clis/douyin/profile.test.js +0 -46
  197. package/clis/douyin/publish-upload-id.test.js +0 -170
  198. package/clis/douyin/publish.test.js +0 -38
  199. package/clis/douyin/stats.test.js +0 -22
  200. package/clis/douyin/update.test.js +0 -11
  201. package/clis/douyin/user-videos.test.js +0 -151
  202. package/clis/douyin/videos.test.js +0 -54
  203. package/clis/duckduckgo/search.test.js +0 -128
  204. package/clis/duckduckgo/suggest.test.js +0 -66
  205. package/clis/eastmoney/hot-rank.test.js +0 -59
  206. package/clis/endoflife/endoflife.test.js +0 -51
  207. package/clis/facebook/feed.test.js +0 -169
  208. package/clis/facebook/marketplace.test.js +0 -91
  209. package/clis/facebook/notifications.test.js +0 -458
  210. package/clis/facebook/search.test.js +0 -55
  211. package/clis/flathub/flathub.test.js +0 -90
  212. package/clis/flomo/memos.test.js +0 -144
  213. package/clis/gemini/ask.test.js +0 -100
  214. package/clis/gemini/deep-research-result.test.js +0 -155
  215. package/clis/gemini/deep-research.test.js +0 -181
  216. package/clis/gemini/reply-state.test.js +0 -671
  217. package/clis/gemini/utils.test.js +0 -198
  218. package/clis/geogebra/geogebra.test.js +0 -175
  219. package/clis/gitee/search.test.js +0 -65
  220. package/clis/gitee/user.test.js +0 -63
  221. package/clis/google/utils.test.js +0 -75
  222. package/clis/google-scholar/cite.test.js +0 -47
  223. package/clis/google-scholar/profile.test.js +0 -49
  224. package/clis/google-scholar/search.test.js +0 -71
  225. package/clis/goproxy/goproxy.test.js +0 -103
  226. package/clis/gov-law/commands.test.js +0 -39
  227. package/clis/gov-policy/gov-policy.test.js +0 -224
  228. package/clis/grok/ask.test.js +0 -29
  229. package/clis/grok/utils.test.js +0 -103
  230. package/clis/hackernews/hackernews.test.js +0 -132
  231. package/clis/hf/hf.test.js +0 -16
  232. package/clis/hupu/hot.test.js +0 -224
  233. package/clis/imdb/utils.test.js +0 -88
  234. package/clis/indeed/indeed.test.js +0 -375
  235. package/clis/instagram/_shared/private-publish.test.js +0 -705
  236. package/clis/instagram/_shared/protocol-capture.test.js +0 -114
  237. package/clis/instagram/download.test.js +0 -118
  238. package/clis/instagram/note.test.js +0 -53
  239. package/clis/instagram/post.test.js +0 -1647
  240. package/clis/instagram/reel.test.js +0 -167
  241. package/clis/instagram/story.test.js +0 -134
  242. package/clis/jd/commands.test.js +0 -41
  243. package/clis/jd/item.test.js +0 -354
  244. package/clis/jianyu/search.test.js +0 -153
  245. package/clis/jianyu/shared/procurement-contract.test.js +0 -72
  246. package/clis/jianyu/shared/procurement-detail.test.js +0 -84
  247. package/clis/jike/read.test.js +0 -86
  248. package/clis/jira/commands.test.js +0 -287
  249. package/clis/juejin/search.js +0 -123
  250. package/clis/juejin/search.test.js +0 -98
  251. package/clis/lesswrong/frontpage.test.js +0 -37
  252. package/clis/lichess/lichess.test.js +0 -85
  253. package/clis/linkedin/connect.test.js +0 -213
  254. package/clis/linkedin/inbox.test.js +0 -152
  255. package/clis/linkedin/job-detail.test.js +0 -38
  256. package/clis/linkedin/jobs-preferences.test.js +0 -43
  257. package/clis/linkedin/people-search.test.js +0 -216
  258. package/clis/linkedin/post-analytics.test.js +0 -40
  259. package/clis/linkedin/posts.test.js +0 -40
  260. package/clis/linkedin/profile-analytics.test.js +0 -67
  261. package/clis/linkedin/profile-experience.test.js +0 -152
  262. package/clis/linkedin/profile-projects.test.js +0 -111
  263. package/clis/linkedin/profile-read.test.js +0 -77
  264. package/clis/linkedin/safe-send.test.js +0 -204
  265. package/clis/linkedin/salesnav-inbox.test.js +0 -113
  266. package/clis/linkedin/salesnav-message.test.js +0 -172
  267. package/clis/linkedin/salesnav-search.test.js +0 -76
  268. package/clis/linkedin/salesnav-thread.test.js +0 -79
  269. package/clis/linkedin/search.test.js +0 -222
  270. package/clis/linkedin/sent-invitations.test.js +0 -62
  271. package/clis/linkedin/services-read.test.js +0 -105
  272. package/clis/linkedin/thread-snapshot.test.js +0 -89
  273. package/clis/linkedin/timeline.test.js +0 -81
  274. package/clis/linkedin-learning/course.test.js +0 -114
  275. package/clis/linkedin-learning/search.test.js +0 -144
  276. package/clis/linkedin-learning/trending.test.js +0 -123
  277. package/clis/linux-do/feed.test.js +0 -153
  278. package/clis/linux-do/topic-content.test.js +0 -59
  279. package/clis/lobsters/lobsters.test.js +0 -169
  280. package/clis/notebooklm/add-source.test.js +0 -97
  281. package/clis/notebooklm/compat.test.js +0 -16
  282. package/clis/notebooklm/create.test.js +0 -58
  283. package/clis/notebooklm/generate-audio.test.js +0 -63
  284. package/clis/notebooklm/generate-slides.test.js +0 -75
  285. package/clis/notebooklm/history.test.js +0 -58
  286. package/clis/notebooklm/note-list.test.js +0 -56
  287. package/clis/notebooklm/notes-get.test.js +0 -72
  288. package/clis/notebooklm/open.test.js +0 -63
  289. package/clis/notebooklm/rpc.test.js +0 -131
  290. package/clis/notebooklm/source-fulltext.test.js +0 -106
  291. package/clis/notebooklm/source-get.test.js +0 -84
  292. package/clis/notebooklm/source-guide.test.js +0 -104
  293. package/clis/notebooklm/summary.test.js +0 -78
  294. package/clis/notebooklm/utils.test.js +0 -449
  295. package/clis/notebooklm/write-note.test.js +0 -70
  296. package/clis/nuget/nuget.test.js +0 -111
  297. package/clis/oeis/oeis.test.js +0 -88
  298. package/clis/ones/task-helpers.test.js +0 -12
  299. package/clis/ones/worklog.test.js +0 -20
  300. package/clis/openfda/openfda.test.js +0 -114
  301. package/clis/openreview/openreview.test.js +0 -427
  302. package/clis/osv/osv.test.js +0 -97
  303. package/clis/paperreview/commands.test.js +0 -243
  304. package/clis/paperreview/utils.test.js +0 -49
  305. package/clis/pixiv/download.test.js +0 -87
  306. package/clis/pixiv/illusts.test.js +0 -99
  307. package/clis/pixiv/search.test.js +0 -83
  308. package/clis/powerchina/search.test.js +0 -93
  309. package/clis/producthunt/utils.test.js +0 -64
  310. package/clis/pubmed/pubmed.test.js +0 -276
  311. package/clis/quark/utils.test.js +0 -58
  312. package/clis/qwen/utils.test.js +0 -45
  313. package/clis/reddit/extract-media.test.js +0 -149
  314. package/clis/reddit/frontpage.test.js +0 -34
  315. package/clis/reddit/home.test.js +0 -170
  316. package/clis/reddit/hot.test.js +0 -32
  317. package/clis/reddit/popular.test.js +0 -26
  318. package/clis/reddit/read.test.js +0 -335
  319. package/clis/reddit/reply.test.js +0 -89
  320. package/clis/reddit/search.test.js +0 -26
  321. package/clis/reddit/subreddit-info.test.js +0 -163
  322. package/clis/reddit/subreddit.test.js +0 -31
  323. package/clis/reddit/subscribed.test.js +0 -168
  324. package/clis/reddit/whoami.test.js +0 -105
  325. package/clis/rednote/navigation.test.js +0 -26
  326. package/clis/rednote/rednote.test.js +0 -222
  327. package/clis/rest-countries/rest-countries.test.js +0 -83
  328. package/clis/reuters/reuters.test.js +0 -299
  329. package/clis/rfc/rfc.test.js +0 -74
  330. package/clis/sinafinance/stock.test.js +0 -59
  331. package/clis/spotify/utils.test.js +0 -67
  332. package/clis/stackoverflow/stackoverflow.test.js +0 -404
  333. package/clis/steam/steam.test.js +0 -46
  334. package/clis/substack/utils.test.js +0 -44
  335. package/clis/suno/commands.test.js +0 -188
  336. package/clis/suno/download.test.js +0 -151
  337. package/clis/suno/generate.test.js +0 -252
  338. package/clis/suno/utils.test.js +0 -329
  339. package/clis/taobao/commands.test.js +0 -41
  340. package/clis/tdx/hot-rank.test.js +0 -59
  341. package/clis/ths/hot-rank.test.js +0 -64
  342. package/clis/tieba/commands.test.js +0 -79
  343. package/clis/tieba/utils.test.js +0 -290
  344. package/clis/tiktok/creator-videos.test.js +0 -113
  345. package/clis/tiktok/refactor.test.js +0 -389
  346. package/clis/tiktok/write-refactor.test.js +0 -370
  347. package/clis/toutiao/toutiao.test.js +0 -378
  348. package/clis/tvmaze/tvmaze.test.js +0 -93
  349. package/clis/twitter/bookmark-folder.test.js +0 -395
  350. package/clis/twitter/bookmark-folders.test.js +0 -152
  351. package/clis/twitter/bookmark.test.js +0 -74
  352. package/clis/twitter/bookmarks.test.js +0 -205
  353. package/clis/twitter/delete.test.js +0 -85
  354. package/clis/twitter/device-follow.test.js +0 -287
  355. package/clis/twitter/download.test.js +0 -457
  356. package/clis/twitter/followers.test.js +0 -62
  357. package/clis/twitter/following.test.js +0 -338
  358. package/clis/twitter/hide-reply.test.js +0 -76
  359. package/clis/twitter/like.test.js +0 -73
  360. package/clis/twitter/likes.test.js +0 -220
  361. package/clis/twitter/list-add.test.js +0 -133
  362. package/clis/twitter/list-create.test.js +0 -169
  363. package/clis/twitter/list-remove.test.js +0 -110
  364. package/clis/twitter/list-tweets.test.js +0 -196
  365. package/clis/twitter/lists.test.js +0 -253
  366. package/clis/twitter/post.test.js +0 -258
  367. package/clis/twitter/profile.test.js +0 -39
  368. package/clis/twitter/quote.test.js +0 -194
  369. package/clis/twitter/reply.test.js +0 -237
  370. package/clis/twitter/retweet.test.js +0 -73
  371. package/clis/twitter/search.test.js +0 -349
  372. package/clis/twitter/shared.test.js +0 -794
  373. package/clis/twitter/thread.test.js +0 -58
  374. package/clis/twitter/timeline.test.js +0 -104
  375. package/clis/twitter/trending.test.js +0 -15
  376. package/clis/twitter/tweets.test.js +0 -362
  377. package/clis/twitter/unbookmark.test.js +0 -73
  378. package/clis/twitter/unlike.test.js +0 -75
  379. package/clis/twitter/unretweet.test.js +0 -73
  380. package/clis/twitter/utils.test.js +0 -169
  381. package/clis/uisdc/news.test.js +0 -66
  382. package/clis/uiverse/_shared.test.js +0 -62
  383. package/clis/uiverse/navigation.test.js +0 -12
  384. package/clis/upwork/upwork.test.js +0 -566
  385. package/clis/wanfang/search.test.js +0 -23
  386. package/clis/web/read.test.js +0 -392
  387. package/clis/weibo/delete.test.js +0 -94
  388. package/clis/weibo/envelope.test.js +0 -85
  389. package/clis/weibo/favorites.test.js +0 -114
  390. package/clis/weibo/publish.test.js +0 -192
  391. package/clis/weibo/user-posts.test.js +0 -92
  392. package/clis/weibo/utils.test.js +0 -36
  393. package/clis/weixin/drafts.test.js +0 -69
  394. package/clis/weixin/search.test.js +0 -227
  395. package/clis/weread/ai-outline.test.js +0 -83
  396. package/clis/weread/book-search.test.js +0 -242
  397. package/clis/weread/commands.test.js +0 -398
  398. package/clis/weread/private-api-regression.test.js +0 -369
  399. package/clis/weread/search-regression.test.js +0 -494
  400. package/clis/weread/utils.test.js +0 -128
  401. package/clis/weread-official/commands.test.js +0 -385
  402. package/clis/weread-official/utils.test.js +0 -242
  403. package/clis/wikidata/wikidata.test.js +0 -83
  404. package/clis/wikipedia/trending.test.js +0 -57
  405. package/clis/wttr/wttr.test.js +0 -84
  406. package/clis/xianyu/chat.test.js +0 -84
  407. package/clis/xianyu/im.test.js +0 -253
  408. package/clis/xianyu/item.test.js +0 -56
  409. package/clis/xianyu/publish.test.js +0 -220
  410. package/clis/xianyu/search.test.js +0 -17
  411. package/clis/xiaoe/xiaoe.test.js +0 -486
  412. package/clis/xiaohongshu/comments.test.js +0 -258
  413. package/clis/xiaohongshu/creator-note-detail.test.js +0 -451
  414. package/clis/xiaohongshu/creator-notes-summary.test.js +0 -94
  415. package/clis/xiaohongshu/creator-notes.test.js +0 -281
  416. package/clis/xiaohongshu/creator-stats.test.js +0 -24
  417. package/clis/xiaohongshu/delete-note.test.js +0 -172
  418. package/clis/xiaohongshu/download.test.js +0 -316
  419. package/clis/xiaohongshu/navigation.test.js +0 -34
  420. package/clis/xiaohongshu/note.test.js +0 -249
  421. package/clis/xiaohongshu/publish.test.js +0 -608
  422. package/clis/xiaohongshu/search.test.js +0 -325
  423. package/clis/xiaohongshu/user-helpers.test.js +0 -160
  424. package/clis/xiaoyuzhou/auth.test.js +0 -124
  425. package/clis/xiaoyuzhou/download.test.js +0 -135
  426. package/clis/xiaoyuzhou/podcast-episodes.test.js +0 -78
  427. package/clis/xiaoyuzhou/transcript.test.js +0 -195
  428. package/clis/xiaoyuzhou/utils.test.js +0 -39
  429. package/clis/xueqiu/comments.test.js +0 -696
  430. package/clis/xueqiu/danjuan-utils.test.js +0 -41
  431. package/clis/xueqiu/utils.test.js +0 -26
  432. package/clis/yahoo/search.test.js +0 -94
  433. package/clis/youdao/note.test.js +0 -99
  434. package/clis/youtube/channel.test.js +0 -59
  435. package/clis/youtube/feed.test.js +0 -131
  436. package/clis/youtube/transcript-group.test.js +0 -99
  437. package/clis/youtube/transcript.test.js +0 -296
  438. package/clis/youtube/utils.test.js +0 -84
  439. package/clis/yuanbao/ask.test.js +0 -124
  440. package/clis/yuanbao/new.test.js +0 -30
  441. package/clis/yuanbao/shared.test.js +0 -80
  442. package/clis/zhihu/answer-comments.test.js +0 -287
  443. package/clis/zhihu/answer-detail.test.js +0 -338
  444. package/clis/zhihu/answer.test.js +0 -54
  445. package/clis/zhihu/collection.test.js +0 -337
  446. package/clis/zhihu/collections.test.js +0 -182
  447. package/clis/zhihu/comment.test.js +0 -50
  448. package/clis/zhihu/download.test.js +0 -12
  449. package/clis/zhihu/favorite.test.js +0 -59
  450. package/clis/zhihu/follow.test.js +0 -42
  451. package/clis/zhihu/like.test.js +0 -41
  452. package/clis/zhihu/question.test.js +0 -251
  453. package/clis/zhihu/recommend.test.js +0 -143
  454. package/clis/zhihu/search.test.js +0 -198
  455. package/clis/zhihu/target.test.js +0 -77
  456. package/clis/zhihu/text.test.js +0 -24
  457. package/clis/zhihu/write-shared.test.js +0 -176
  458. package/clis/zlibrary/commands.test.js +0 -65
  459. package/clis/zsxq/search.test.js +0 -24
  460. package/clis/zsxq/topic.test.js +0 -30
  461. package/clis/zsxq/topics.test.js +0 -24
  462. package/clis/zsxq/utils.test.js +0 -31
  463. package/dist/src/adapter-shadow.test.js +0 -49
  464. package/dist/src/adapter-source.test.js +0 -29
  465. package/dist/src/browser/analyze.test.js +0 -166
  466. package/dist/src/browser/article-extract.e2e.test.js +0 -105
  467. package/dist/src/browser/article-extract.test.js +0 -94
  468. package/dist/src/browser/ax-snapshot.test.js +0 -91
  469. package/dist/src/browser/base-page.test.js +0 -758
  470. package/dist/src/browser/cdp-click-fixture.test.js +0 -87
  471. package/dist/src/browser/cdp.test.js +0 -79
  472. package/dist/src/browser/compound.test.js +0 -175
  473. package/dist/src/browser/daemon-client.test.js +0 -199
  474. package/dist/src/browser/dom-helpers.test.js +0 -106
  475. package/dist/src/browser/dom-snapshot.test.js +0 -313
  476. package/dist/src/browser/errors.test.js +0 -60
  477. package/dist/src/browser/extract.test.js +0 -129
  478. package/dist/src/browser/find.test.js +0 -180
  479. package/dist/src/browser/html-tree.test.js +0 -181
  480. package/dist/src/browser/network-cache.test.js +0 -58
  481. package/dist/src/browser/network-key.test.js +0 -49
  482. package/dist/src/browser/page.test.js +0 -378
  483. package/dist/src/browser/shape-filter.test.js +0 -101
  484. package/dist/src/browser/shape.test.js +0 -82
  485. package/dist/src/browser/stealth.test.js +0 -134
  486. package/dist/src/browser/target-errors.test.js +0 -94
  487. package/dist/src/browser/target-resolver.test.js +0 -118
  488. package/dist/src/browser/utils.test.js +0 -29
  489. package/dist/src/browser/verify-fixture.test.js +0 -219
  490. package/dist/src/browser.test.js +0 -232
  491. package/dist/src/build-manifest.test.js +0 -341
  492. package/dist/src/capabilityRouting.test.js +0 -63
  493. package/dist/src/cli-argv-preprocess.test.js +0 -209
  494. package/dist/src/cli.test.js +0 -2803
  495. package/dist/src/commanderAdapter.test.js +0 -352
  496. package/dist/src/commands/daemon.test.js +0 -219
  497. package/dist/src/completion.test.js +0 -24
  498. package/dist/src/convention-audit.test.js +0 -247
  499. package/dist/src/daemon.test.js +0 -60
  500. package/dist/src/doctor.test.js +0 -263
  501. package/dist/src/download/article-download.test.js +0 -235
  502. package/dist/src/download/index.test.js +0 -140
  503. package/dist/src/download/media-download.test.js +0 -112
  504. package/dist/src/download/progress.test.js +0 -36
  505. package/dist/src/electron-apps.test.js +0 -49
  506. package/dist/src/engine.test.js +0 -312
  507. package/dist/src/errors.test.js +0 -109
  508. package/dist/src/execution.test.js +0 -623
  509. package/dist/src/extension-manifest-regression.test.js +0 -12
  510. package/dist/src/external.test.js +0 -146
  511. package/dist/src/help.test.js +0 -58
  512. package/dist/src/hooks.test.js +0 -92
  513. package/dist/src/interceptor.test.js +0 -81
  514. package/dist/src/launcher.test.js +0 -138
  515. package/dist/src/node-network.test.js +0 -55
  516. package/dist/src/observation/artifact.test.js +0 -121
  517. package/dist/src/observation/manager.test.js +0 -13
  518. package/dist/src/observation/redaction.test.js +0 -32
  519. package/dist/src/observation/retention.test.js +0 -118
  520. package/dist/src/observation/ring-buffer.test.js +0 -22
  521. package/dist/src/output.test.js +0 -53
  522. package/dist/src/package-exports.test.js +0 -112
  523. package/dist/src/pipeline/executor.test.js +0 -182
  524. package/dist/src/pipeline/steps/download.test.js +0 -102
  525. package/dist/src/pipeline/steps/fetch.test.js +0 -117
  526. package/dist/src/pipeline/template.test.js +0 -175
  527. package/dist/src/pipeline/transform.test.js +0 -133
  528. package/dist/src/plugin-manifest.test.js +0 -179
  529. package/dist/src/plugin-scaffold.test.js +0 -83
  530. package/dist/src/plugin.test.js +0 -1324
  531. package/dist/src/registry.test.js +0 -209
  532. package/dist/src/runtime-detect.test.js +0 -39
  533. package/dist/src/serialization.test.js +0 -78
  534. package/dist/src/snapshotFormatter.test.js +0 -521
  535. package/dist/src/tui.test.js +0 -19
  536. package/dist/src/update-check.test.js +0 -116
  537. package/dist/src/utils.test.js +0 -155
  538. package/dist/src/validate.test.js +0 -90
  539. 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
- });