@@ -73,8 +73,8 @@ fn status(pipe: &Pipe, target: &str) -> Option<Status> {
7373}
7474
7575// Expected (TS `Npm.cacheKey`, run with Bun on this checkout): each spec form is keyed in the cache as TS keys it, so
76- // the same spec finds the same directory: a bare name, a version, ranges, tags, a scope, git and hosted specs, an alias ,
77- // a path, a URL , and specs `npm-package-arg` refuses.
76+ // the same spec finds the same directory: a bare name, a version, ranges, tags, a scope, git and hosted specs (URLs ,
77+ // SSH, SCP, shortcuts, committishes), an alias, paths, URLs, tarballs , and specs `npm-package-arg` refuses.
7878#[ test]
7979fn a_spec_is_keyed_as_ts_keys_it ( ) {
8080 let Some ( root) = support:: ts_root ( ) else { return } ;
@@ -113,6 +113,69 @@ fn a_spec_is_keyed_as_ts_keys_it() {
113113 "_foo" ,
114114 "@s" ,
115115 "opencode-sidebar-tokens@0.1.3" ,
116+ // carbon jsnpm-4: hosted git URLs, SSH and SCP, a name with a hosted URL, `~`, and tarballs.
117+ "https://github.com/u/r" ,
118+ "https://github.com/u/r.git" ,
119+ "https://gitlab.com/u/r" ,
120+ "https://bitbucket.org/u/r" ,
121+ "ssh://git@github.com/u/r.git" ,
122+ "git@github.com:u/r.git" ,
123+ "foo@https://github.com/u/r" ,
124+ "u/r~1" ,
125+ "plugin.tgz" ,
126+ "plugin.tar.gz" ,
127+ "plugin.tar" ,
128+ // Around them: committishes, other hosts, shortcuts, non-hosted git, paths, and refused specs.
129+ "u/r#semver:^1" ,
130+ "u/r#a::b" ,
131+ "u/r#semver:^1::v2" ,
132+ "github:u/r#abc" ,
133+ "https://x.org/y.git" ,
134+ "https://x.org/y" ,
135+ "git@x.org:y/z.git" ,
136+ "git+ssh://git@x.org/y.git" ,
137+ "git+ssh://git@x.org:22/y.git" ,
138+ "foo@git@github.com:u/r.git" ,
139+ "foo@u/r" ,
140+ "./x.tgz" ,
141+ "/abs/x.tgz" ,
142+ "x.tgz.bak" ,
143+ "@s/x@./y.tgz" ,
144+ "http://github.com/u/r" ,
145+ "https://github.com/u/r/tree/main" ,
146+ "https://github.com/u" ,
147+ "https://www.github.com/u/r" ,
148+ "github:u" ,
149+ "gitlab:g/s/p" ,
150+ "gist:abc123" ,
151+ "bitbucket:u/r" ,
152+ "https://gist.github.com/u/abc" ,
153+ "foo@github:u/r" ,
154+ "sourcehut:u/r" ,
155+ "https://git.sr.ht/~u/r" ,
156+ "~/x" ,
157+ "~u/r" ,
158+ "a/b/c" ,
159+ "u/r.git" ,
160+ "U/r#x" ,
161+ "-u/r" ,
162+ ".." ,
163+ "../x" ,
164+ "x/.." ,
165+ "x/../y" ,
166+ "@s/../x" ,
167+ "@s/x/y" ,
168+ "existing@1.0.0/../../../outside" ,
169+ "-foo" ,
170+ "foo bar@" ,
171+ "node_modules" ,
172+ "@s/.x" ,
173+ "@../x" ,
174+ "ftp://x.org/y" ,
175+ "git+file:///tmp/r" ,
176+ "github:u/r%zz" ,
177+ "https://github.com/u/r%zz" ,
178+ "foo@npm:bar@1" ,
116179 ] ;
117180 let script = format ! (
118181 "const {{ Npm }} = await import({:?}); const specs = JSON.parse(process.argv[1]); \
@@ -127,9 +190,15 @@ fn a_spec_is_keyed_as_ts_keys_it() {
127190 assert ! ( output. status. success( ) , "{output:?}" ) ;
128191 let ts: Vec < String > = serde_json:: from_slice ( & output. stdout ) . unwrap ( ) ;
129192 let rust: Vec < String > = specs. iter ( ) . map ( |spec| opencode_plugin:: loader:: npm:: cache_key ( spec) ) . collect ( ) ;
130- for ( ( spec, ts) , rust) in specs. iter ( ) . zip ( & ts) . zip ( & rust) {
131- assert_eq ! ( rust, ts, "{spec}" ) ;
132- }
193+ let differ: Vec < String > = specs
194+ . iter ( )
195+ . zip ( & ts)
196+ . zip ( & rust)
197+ . filter ( |( ( _, ts) , rust) | ts != rust)
198+ . map ( |( ( spec, ts) , rust) | format ! ( "{spec}: TS {ts}, Rust {rust}" ) )
199+ . collect ( ) ;
200+ assert_eq ! ( ts. len( ) , specs. len( ) ) ;
201+ assert ! ( differ. is_empty( ) , "{} of {} keys differ:\n {}" , differ. len( ) , specs. len( ) , differ. join( "\n " ) ) ;
133202}
134203
135204// Expected (TS `Npm.resolve`, `prepare`): a `cli.json` entry that names an installed package loads its TUI entry from
0 commit comments