@@ -29,83 +29,109 @@ suite('Pip and UV commands', () => {
2929 sinon . restore ( ) ;
3030 } ) ;
3131
32- test ( 'PipAvailableVersionsCommand executes without error' , async ( ) => {
33- runPythonStub . resolves ( JSON . stringify ( { versions : [ '1.0.0' ] } ) ) ;
34- const command = new PipAvailableVersionsCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
35-
36- await assert . doesNotReject ( ( ) => command . execute ( { packageName : 'package' , pythonVersion : '3.13.1' } ) ) ;
32+ // Mutation commands have no output to parse; unit coverage is a smoke test that
33+ // execute() resolves. Their concrete command strings are exercised by integration tests.
34+ suite ( 'mutation commands execute without error' , ( ) => {
35+ test ( 'PipInstallCommand' , async ( ) => {
36+ const command = new PipInstallCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
37+ await assert . doesNotReject ( ( ) => command . execute ( { packages : [ { packageName : 'package' } ] } ) ) ;
38+ } ) ;
39+
40+ test ( 'UvInstallCommand' , async ( ) => {
41+ const command = new UvInstallCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
42+ await assert . doesNotReject ( ( ) => command . execute ( { packages : [ { packageName : 'package' } ] } ) ) ;
43+ } ) ;
44+
45+ test ( 'PipUninstallCommand' , async ( ) => {
46+ const command = new PipUninstallCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
47+ await assert . doesNotReject ( ( ) => command . execute ( { packages : [ { packageName : 'package' } ] } ) ) ;
48+ } ) ;
49+
50+ test ( 'UvUninstallCommand' , async ( ) => {
51+ const command = new UvUninstallCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
52+ await assert . doesNotReject ( ( ) => command . execute ( { packages : [ { packageName : 'package' } ] } ) ) ;
53+ } ) ;
3754 } ) ;
3855
39- test ( 'UvAvailableVersionsCommand executes without error' , async ( ) => {
40- runUvStub . resolves ( JSON . stringify ( { versions : [ '1.0.0' ] } ) ) ;
41- const command = new UvAvailableVersionsCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
42-
43- await assert . doesNotReject ( ( ) => command . execute ( { packageName : 'package' , pythonVersion : '3.13.1' } ) ) ;
44- } ) ;
45-
46- test ( 'PipInstallCommand executes without error' , async ( ) => {
47- const command = new PipInstallCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
48-
49- await assert . doesNotReject ( ( ) => command . execute ( { packages : [ { packageName : 'package' } ] } ) ) ;
50- } ) ;
56+ test ( 'PipAvailableVersionsCommand parses versions and filters prereleases' , async ( ) => {
57+ runPythonStub . resolves ( JSON . stringify ( { versions : [ '2.0.0rc1' , '1.0.0' ] } ) ) ;
58+ const command = new PipAvailableVersionsCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
5159
52- test ( 'UvInstallCommand executes without error' , async ( ) => {
53- const command = new UvInstallCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
60+ const result = await command . execute ( {
61+ packageName : 'package' ,
62+ pythonVersion : '3.13.1' ,
63+ includePrerelease : false ,
64+ } ) ;
5465
55- await assert . doesNotReject ( ( ) => command . execute ( { packages : [ { packageName : 'package' } ] } ) ) ;
66+ assert . deepStrictEqual ( result . map ( ( v ) => v . public ) , [ '1.0.0' ] ) ;
5667 } ) ;
5768
58- test ( 'PipUninstallCommand executes without error' , async ( ) => {
59- const command = new PipUninstallCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
60-
61- await assert . doesNotReject ( ( ) => command . execute ( { packages : [ { packageName : 'package' } ] } ) ) ;
62- } ) ;
69+ test ( 'UvAvailableVersionsCommand parses versions from embedded JSON' , async ( ) => {
70+ runUvStub . resolves ( `Some preamble\n${ JSON . stringify ( { versions : [ '1.0.0' ] } ) } ` ) ;
71+ const command = new UvAvailableVersionsCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
6372
64- test ( 'UvUninstallCommand executes without error' , async ( ) => {
65- const command = new UvUninstallCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
73+ const result = await command . execute ( { packageName : 'package' , pythonVersion : '3.13.1' } ) ;
6674
67- await assert . doesNotReject ( ( ) => command . execute ( { packages : [ { packageName : 'package' } ] } ) ) ;
75+ assert . deepStrictEqual ( result . map ( ( v ) => v . public ) , [ '1.0.0' ] ) ;
6876 } ) ;
6977
70- test ( 'PipListCommand executes without error ' , async ( ) => {
71- runPythonStub . resolves ( JSON . stringify ( [ { name : 'package' , version : '1.0.0' } ] ) ) ;
78+ test ( 'PipListCommand parses packages and drops entries missing a version ' , async ( ) => {
79+ runPythonStub . resolves ( JSON . stringify ( [ { name : 'package' , version : '1.0.0' } , { name : 'broken' } ] ) ) ;
7280 const command = new PipListCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
7381
74- await assert . doesNotReject ( ( ) => command . execute ( ) ) ;
82+ const result = await command . execute ( ) ;
83+
84+ assert . deepStrictEqual (
85+ result . map ( ( p ) => ( { name : p . name , version : p . version } ) ) ,
86+ [ { name : 'package' , version : '1.0.0' } ] ,
87+ ) ;
7588 } ) ;
7689
77- test ( 'UvListCommand executes without error ' , async ( ) => {
90+ test ( 'UvListCommand parses packages from JSON ' , async ( ) => {
7891 runUvStub . resolves ( JSON . stringify ( [ { name : 'package' , version : '1.0.0' } ] ) ) ;
7992 const command = new UvListCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
8093
81- await assert . doesNotReject ( ( ) => command . execute ( ) ) ;
94+ const result = await command . execute ( ) ;
95+
96+ assert . deepStrictEqual (
97+ result . map ( ( p ) => ( { name : p . name , version : p . version } ) ) ,
98+ [ { name : 'package' , version : '1.0.0' } ] ,
99+ ) ;
82100 } ) ;
83101
84- test ( 'PipListDirectNamesCommand executes without error ' , async ( ) => {
85- runPythonStub . resolves ( JSON . stringify ( [ { name : 'package ' , version : '1.0.0' } ] ) ) ;
102+ test ( 'PipListDirectNamesCommand returns normalized names ' , async ( ) => {
103+ runPythonStub . resolves ( JSON . stringify ( [ { name : 'Flask_Thing ' , version : '1.0.0' } ] ) ) ;
86104 const command = new PipListDirectNamesCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
87105
88- await assert . doesNotReject ( ( ) => command . execute ( ) ) ;
106+ const result = await command . execute ( ) ;
107+
108+ assert . deepStrictEqual ( [ ...result ] , [ 'flask-thing' ] ) ;
89109 } ) ;
90110
91- test ( 'UvListDirectNamesCommand executes without error ' , async ( ) => {
92- runUvStub . resolves ( 'package 1.0.0') ;
111+ test ( 'UvListDirectNamesCommand keeps top-level packages and skips indented dependencies ' , async ( ) => {
112+ runUvStub . resolves ( [ 'Flask_Thing 1.0.0', '├── dependency 2.0.0' , '└── another-dep 3.0.0' ] . join ( '\n' ) ) ;
93113 const command = new UvListDirectNamesCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
94114
95- await assert . doesNotReject ( ( ) => command . execute ( ) ) ;
115+ const result = await command . execute ( ) ;
116+
117+ assert . deepStrictEqual ( [ ...result ] , [ 'flask-thing' ] ) ;
96118 } ) ;
97119
98- test ( 'PipVersionCommand executes without error ' , async ( ) => {
99- runPythonStub . resolves ( 'pip 24.0 from site-packages' ) ;
120+ test ( 'PipVersionCommand parses the version from pip --version output ' , async ( ) => {
121+ runPythonStub . resolves ( 'pip 24.0 from / site-packages/pip (python 3.13) ' ) ;
100122 const command = new PipVersionCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
101123
102- await assert . doesNotReject ( ( ) => command . execute ( ) ) ;
124+ const result = await command . execute ( ) ;
125+
126+ assert . strictEqual ( result ?. public , '24.0' ) ;
103127 } ) ;
104128
105- test ( 'UvVersionCommand executes without error ' , async ( ) => {
106- runUvStub . resolves ( 'uv 0.4.20' ) ;
129+ test ( 'UvVersionCommand parses the version from uv --version output ' , async ( ) => {
130+ runUvStub . resolves ( 'uv 0.4.20 (abcdef 2024-01-01) ' ) ;
107131 const command = new UvVersionCommand ( { pythonExecutable : 'python' , log : mockLog } ) ;
108132
109- await assert . doesNotReject ( ( ) => command . execute ( ) ) ;
133+ const result = await command . execute ( ) ;
134+
135+ assert . strictEqual ( result ?. public , '0.4.20' ) ;
110136 } ) ;
111- } ) ;
137+ } ) ;
0 commit comments