@@ -6,8 +6,12 @@ import { tmpdir } from "node:os";
66import { join } from "node:path" ;
77import { test } from "node:test" ;
88import { END , START , categoryOf , renderOverview , renderReadme , systemsOf , truncate } from "./render-readme.mjs" ;
9- import { addVersion , platformsForAsset , versionFromRelease } from "./track-releases.mjs" ;
10- import { checkManifest , formatIndex , inspectArchive , validateEntry , validateIndex , verifyArchives } from "./validate-index.mjs" ;
9+ import {
10+ addVersion , discoverPlugins , platformsForAsset , unlistedPluginRepositories , versionFromRelease ,
11+ } from "./track-releases.mjs" ;
12+ import {
13+ checkManifest , formatIndex , inspectArchive , readPackageManifests , validateEntry , validateIndex , verifyArchives ,
14+ } from "./validate-index.mjs" ;
1115
1216// Fixtures are copied from the plugin contract (lithe-plugin-docs contract/v1/fixtures/marketplace)
1317// so this validator reports the same code as Lithe's Rust Core for each case.
@@ -207,6 +211,179 @@ test("release tracking preserves API 1/2 releases without adding requires", { ti
207211 }
208212} ) ;
209213
214+ // Organization discovery fixtures: GitHub responses are plain objects, and each
215+ // archive's bytes are its plugin.json text, so no test touches the network or unzip.
216+ const REPOSITORIES_PATH = "orgs/Lithe-IDEA/repos?type=public&per_page=100&page=1" ;
217+ const ZIG_ID = "io.github.lithe-idea.zig-support" ;
218+
219+ function organizationRepository ( name , overrides = { } ) {
220+ return {
221+ name,
222+ full_name : `Lithe-IDEA/${ name } ` ,
223+ html_url : `https://github.com/Lithe-IDEA/${ name } ` ,
224+ private : false ,
225+ archived : false ,
226+ fork : false ,
227+ description : "Zig language support for Lithe" ,
228+ license : { spdx_id : "Apache-2.0" } ,
229+ topics : [ "language" , "zig" ] ,
230+ ...overrides ,
231+ } ;
232+ }
233+
234+ function organizationRelease ( repository , version , overrides = { } ) {
235+ const name = `zig-support-${ version } -darwin.zip` ;
236+ return {
237+ tag_name : `v${ version } ` ,
238+ draft : false ,
239+ prerelease : false ,
240+ published_at : "2026-11-01T00:00:00Z" ,
241+ assets : [ { name, browser_download_url : `${ repository . html_url } /releases/download/v${ version } /${ name } ` } ] ,
242+ ...overrides ,
243+ } ;
244+ }
245+
246+ function zigManifest ( version ) {
247+ return {
248+ schemaVersion : 2 ,
249+ id : ZIG_ID ,
250+ displayName : "Zig Support" ,
251+ version,
252+ pluginAPIVersion : 2 ,
253+ vendor : { displayName : "Lithe Community" , signatureRequirement : "none" } ,
254+ } ;
255+ }
256+
257+ function organizationFixture ( responses , manifestsByURL ) {
258+ const downloads = [ ] ;
259+ return {
260+ downloads,
261+ request : async ( path ) => {
262+ assert . ok ( Object . hasOwn ( responses , path ) , `unexpected GitHub request: ${ path } ` ) ;
263+ return structuredClone ( responses [ path ] ) ;
264+ } ,
265+ downloadArchive : async ( url ) => {
266+ assert . ok ( Object . hasOwn ( manifestsByURL , url ) , `unexpected download: ${ url } ` ) ;
267+ downloads . push ( url ) ;
268+ return Buffer . from ( JSON . stringify ( manifestsByURL [ url ] ) ) ;
269+ } ,
270+ readManifests : ( bytes , pluginID ) => {
271+ const manifest = JSON . parse ( bytes . toString ( ) ) ;
272+ return { manifests : pluginID === undefined || manifest . id === pluginID ? [ manifest ] : [ ] , unsafe : [ ] } ;
273+ } ,
274+ } ;
275+ }
276+
277+ function zigOrganization ( ) {
278+ const repository = organizationRepository ( "lithe-plugin-zig" ) ;
279+ const releases = [
280+ organizationRelease ( repository , "1.2.0" , { prerelease : true } ) ,
281+ organizationRelease ( repository , "1.1.0" ) ,
282+ organizationRelease ( repository , "1.0.0" ) ,
283+ ] ;
284+ const manifestsByURL = Object . fromEntries ( releases . map ( ( release ) =>
285+ [ release . assets [ 0 ] . browser_download_url , zigManifest ( release . tag_name . slice ( 1 ) ) ] ) ) ;
286+ const fixture = organizationFixture ( {
287+ [ REPOSITORIES_PATH ] : [ repository , organizationRepository ( "lithe-plugin-docs" ) ] ,
288+ "repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=20" : releases ,
289+ } , manifestsByURL ) ;
290+ return { releases, fixture } ;
291+ }
292+
293+ test ( "organization discovery considers only active, unlisted lithe-plugin- repositories" , ( ) => {
294+ const index = { schemaVersion : 1 , plugins : [ { ...validEntry ( ) , repository : "https://github.com/Lithe-IDEA/Lithe-Plugin-Listed" } ] } ;
295+ const names = unlistedPluginRepositories ( [
296+ organizationRepository ( "lithe-plugin-zig" ) ,
297+ organizationRepository ( "lithe-plugin-docs" ) ,
298+ organizationRepository ( "lithe-plugin-listed" ) ,
299+ organizationRepository ( "lithe-plugin-old" , { archived : true } ) ,
300+ organizationRepository ( "lithe-plugin-copy" , { fork : true } ) ,
301+ organizationRepository ( "lithe-plugin-secret" , { private : true } ) ,
302+ organizationRepository ( "Lithe-store" ) ,
303+ ] , index ) . map ( ( repository ) => repository . name ) ;
304+ assert . deepEqual ( names , [ "lithe-plugin-zig" ] ) ;
305+ } ) ;
306+
307+ test ( "organization discovery lists a new plugin with its stable releases" , { timeout : 5_000 } , async ( ) => {
308+ const { releases, fixture } = zigOrganization ( ) ;
309+ const index = { schemaVersion : 1 , plugins : [ validEntry ( ) , { ...validEntry ( ) , id : "org.example.zig-tools" } ] } ;
310+ const result = await discoverPlugins ( index , fixture ) ;
311+
312+ assert . deepEqual ( result . skipped , [ ] ) ;
313+ assert . deepEqual ( result . newPlugins , [ ZIG_ID ] ) ;
314+ assert . deepEqual ( result . added , [ `${ ZIG_ID } @1.1.0 (v1.1.0) [new plugin]` , `${ ZIG_ID } @1.0.0 (v1.0.0) [new plugin]` ] ) ;
315+ assert . deepEqual ( index . plugins . map ( ( entry ) => entry . id ) , [ "io.example.zig-support" , ZIG_ID , "org.example.zig-tools" ] ) ;
316+ const { versions, ...metadata } = index . plugins [ 1 ] ;
317+ assert . deepEqual ( metadata , {
318+ id : ZIG_ID ,
319+ name : "Zig Support" ,
320+ author : "Lithe Community" ,
321+ repository : "https://github.com/Lithe-IDEA/lithe-plugin-zig" ,
322+ homepage : "https://github.com/Lithe-IDEA/lithe-plugin-zig#readme" ,
323+ description : "Zig language support for Lithe" ,
324+ tags : [ "language" , "zig" ] ,
325+ license : "Apache-2.0" ,
326+ } ) ;
327+ assert . deepEqual ( versions . map ( ( version ) => version . version ) , [ "1.1.0" , "1.0.0" ] ) ;
328+ assert . deepEqual ( validateIndex ( index ) , [ ] ) ;
329+ // The draft and its first version share one download; the pre-release is never fetched.
330+ assert . deepEqual ( fixture . downloads , [ releases [ 1 ] , releases [ 2 ] ] . map ( ( release ) => release . assets [ 0 ] . browser_download_url ) ) ;
331+ } ) ;
332+
333+ test ( "organization discovery keeps only the plugin named by --plugin" , { timeout : 5_000 } , async ( ) => {
334+ const other = zigOrganization ( ) ;
335+ const otherIndex = { schemaVersion : 1 , plugins : [ validEntry ( ) ] } ;
336+ const skippedRun = await discoverPlugins ( otherIndex , { ...other . fixture , onlyPlugin : "io.example.other" } ) ;
337+ assert . deepEqual ( skippedRun . added , [ ] ) ;
338+ assert . equal ( otherIndex . plugins . length , 1 ) ;
339+
340+ const named = zigOrganization ( ) ;
341+ const namedIndex = { schemaVersion : 1 , plugins : [ validEntry ( ) ] } ;
342+ const namedRun = await discoverPlugins ( namedIndex , { ...named . fixture , onlyPlugin : ZIG_ID } ) ;
343+ assert . deepEqual ( namedRun . newPlugins , [ ZIG_ID ] ) ;
344+ } ) ;
345+
346+ test ( "organization discovery skips repositories that cannot be listed yet" , { timeout : 5_000 } , async ( ) => {
347+ const preview = organizationRepository ( "lithe-plugin-preview" ) ;
348+ const unlicensed = organizationRepository ( "lithe-plugin-unlicensed" , { license : { spdx_id : "NOASSERTION" } } ) ;
349+ const undescribed = organizationRepository ( "lithe-plugin-undescribed" , { description : null } ) ;
350+ const copy = organizationRepository ( "lithe-plugin-copy" ) ;
351+ const copyRelease = organizationRelease ( copy , "1.0.0" ) ;
352+ const anonymous = organizationRepository ( "lithe-plugin-anonymous" ) ;
353+ const anonymousRelease = organizationRelease ( anonymous , "1.0.0" ) ;
354+ const official = organizationRepository ( "lithe-plugin-official" ) ;
355+ const officialRelease = organizationRelease ( official , "1.0.0" ) ;
356+ const fixture = organizationFixture ( {
357+ [ REPOSITORIES_PATH ] : [ preview , unlicensed , undescribed , copy , anonymous , official ] ,
358+ "repos/Lithe-IDEA/lithe-plugin-preview/releases?per_page=20" : [ organizationRelease ( preview , "0.1.0" , { prerelease : true } ) ] ,
359+ "repos/Lithe-IDEA/lithe-plugin-unlicensed/releases?per_page=20" : [ organizationRelease ( unlicensed , "1.0.0" ) ] ,
360+ "repos/Lithe-IDEA/lithe-plugin-undescribed/releases?per_page=20" : [ organizationRelease ( undescribed , "1.0.0" ) ] ,
361+ "repos/Lithe-IDEA/lithe-plugin-copy/releases?per_page=20" : [ copyRelease ] ,
362+ "repos/Lithe-IDEA/lithe-plugin-anonymous/releases?per_page=20" : [ anonymousRelease ] ,
363+ "repos/Lithe-IDEA/lithe-plugin-official/releases?per_page=20" : [ officialRelease ] ,
364+ } , {
365+ [ copyRelease . assets [ 0 ] . browser_download_url ] : { ...zigManifest ( "1.0.0" ) , id : "io.example.zig-support" } ,
366+ [ anonymousRelease . assets [ 0 ] . browser_download_url ] : { ...zigManifest ( "1.0.0" ) , id : "io.github.lithe-idea.anonymous" , vendor : { signatureRequirement : "none" } } ,
367+ [ officialRelease . assets [ 0 ] . browser_download_url ] : { ...zigManifest ( "1.0.0" ) , id : "dev.lithe.official" } ,
368+ } ) ;
369+ const index = { schemaVersion : 1 , plugins : [ validEntry ( ) ] } ;
370+ const result = await discoverPlugins ( index , fixture ) ;
371+
372+ assert . deepEqual ( result . added , [ ] ) ;
373+ assert . deepEqual ( result . newPlugins , [ ] ) ;
374+ assert . equal ( index . plugins . length , 1 ) ;
375+ const log = result . skipped . join ( "\n" ) ;
376+ assert . match ( log , / l i t h e - p l u g i n - p r e v i e w : n o s t a b l e r e l e a s e / ) ;
377+ assert . match ( log , / l i t h e - p l u g i n - u n l i c e n s e d : G i t H u b d e t e c t s n o l i c e n s e / ) ;
378+ assert . match ( log , / l i t h e - p l u g i n - u n d e s c r i b e d : t h e r e p o s i t o r y h a s n o d e s c r i p t i o n / ) ;
379+ assert . match ( log , / l i t h e - p l u g i n - c o p y : i o \. e x a m p l e \. z i g - s u p p o r t i s a l r e a d y l i s t e d f o r h t t p s : \/ \/ g i t h u b \. c o m \/ e x a m p l e \/ l i t h e - z i g / ) ;
380+ // A drafted entry that the index would reject never gains a version, so it is not listed.
381+ assert . match ( log , / i o \. g i t h u b \. l i t h e - i d e a \. a n o n y m o u s .* a u t h o r / ) ;
382+ assert . match ( log , / d e v \. l i t h e \. o f f i c i a l .* o f f i c i a l N a m e s p a c e / ) ;
383+ // Metadata problems are found before any archive is downloaded.
384+ assert . deepEqual ( fixture . downloads , [ copyRelease , anonymousRelease , officialRelease ] . map ( ( release ) => release . assets [ 0 ] . browser_download_url ) ) ;
385+ } ) ;
386+
210387test ( "archive verification rechecks changed manifest expectations for the same URL and hash" , { timeout : 5_000 } , async ( ) => {
211388 const entry = capabilityEntry ( ) ;
212389 const manifest = manifestFor ( entry ) ;
@@ -322,6 +499,9 @@ test("archives must hold one matching community plugin.json", () => {
322499 / s i g n a t u r e R e q u i r e m e n t / ,
323500 ) ;
324501 assert . match ( inspectArchive ( build ( { ...manifest , id : "io.other" } ) , entry , version ) . join ( ) , / e x a c t l y o n e p l u g i n \. j s o n / ) ;
502+ // Without an ID (an unlisted plugin) every manifest that declares one is returned.
503+ assert . deepEqual ( readPackageManifests ( build ( { ...manifest , id : "io.other" } ) ) . manifests . map ( ( found ) => found . id ) , [ "io.other" ] ) ;
504+ assert . deepEqual ( readPackageManifests ( build ( { version : "1.0.0" } ) ) . manifests , [ ] ) ;
325505 } finally {
326506 rmSync ( workDir , { recursive : true , force : true } ) ;
327507 }
0 commit comments