@@ -65,21 +65,87 @@ describe('rewriteUnsupportedCommand', () => {
6565 } ) ;
6666 } ) ;
6767
68- describe ( 'Python script execution' , ( ) => {
69- it ( 'replaces python script with echo warning' , ( ) => {
68+ describe ( 'Python script execution — server detection' , ( ) => {
69+ it ( 'auto-serves serve.py with npx serve' , ( ) => {
70+ const result = rewriteUnsupportedCommand ( 'python3 serve.py' ) ;
71+ expect ( result . wasRewritten ) . toBe ( true ) ;
72+ expect ( result . command ) . toBe ( 'npx --yes serve -l 8000' ) ;
73+ expect ( result . reason ) . toContain ( 'serve.py' ) ;
74+ } ) ;
75+
76+ it ( 'auto-serves server.py with npx serve' , ( ) => {
77+ const result = rewriteUnsupportedCommand ( 'python server.py' ) ;
78+ expect ( result . wasRewritten ) . toBe ( true ) ;
79+ expect ( result . command ) . toBe ( 'npx --yes serve -l 8000' ) ;
80+ } ) ;
81+
82+ it ( 'auto-serves http_server.py with npx serve' , ( ) => {
83+ const result = rewriteUnsupportedCommand ( 'python3 http_server.py' ) ;
84+ expect ( result . wasRewritten ) . toBe ( true ) ;
85+ expect ( result . command ) . toBe ( 'npx --yes serve -l 8000' ) ;
86+ } ) ;
87+
88+ it ( 'auto-serves web.py with npx serve' , ( ) => {
89+ const result = rewriteUnsupportedCommand ( 'python3 web.py' ) ;
90+ expect ( result . wasRewritten ) . toBe ( true ) ;
91+ expect ( result . command ) . toBe ( 'npx --yes serve -l 8000' ) ;
92+ } ) ;
93+
94+ it ( 'extracts port from --port argument' , ( ) => {
95+ const result = rewriteUnsupportedCommand ( 'python3 serve.py --port 3000' ) ;
96+ expect ( result . wasRewritten ) . toBe ( true ) ;
97+ expect ( result . command ) . toBe ( 'npx --yes serve -l 3000' ) ;
98+ } ) ;
99+
100+ it ( 'extracts port from -p argument' , ( ) => {
101+ const result = rewriteUnsupportedCommand ( 'python3 server.py -p 9090' ) ;
102+ expect ( result . wasRewritten ) . toBe ( true ) ;
103+ expect ( result . command ) . toBe ( 'npx --yes serve -l 9090' ) ;
104+ } ) ;
105+
106+ it ( 'extracts bare port number as argument' , ( ) => {
107+ const result = rewriteUnsupportedCommand ( 'python3 serve.py 4000' ) ;
108+ expect ( result . wasRewritten ) . toBe ( true ) ;
109+ expect ( result . command ) . toBe ( 'npx --yes serve -l 4000' ) ;
110+ } ) ;
111+
112+ it ( 'shows error for non-server Python scripts' , ( ) => {
70113 const result = rewriteUnsupportedCommand ( 'python3 app.py' ) ;
71114 expect ( result . wasRewritten ) . toBe ( true ) ;
72115 expect ( result . command ) . toContain ( 'echo' ) ;
73116 expect ( result . command ) . toContain ( 'WebContainer only supports Node.js' ) ;
74117 } ) ;
75118
76- it ( 'handles python script with path' , ( ) => {
119+ it ( 'shows error for Python script with path' , ( ) => {
77120 const result = rewriteUnsupportedCommand ( 'python ./scripts/start.py' ) ;
78121 expect ( result . wasRewritten ) . toBe ( true ) ;
79122 expect ( result . command ) . toContain ( 'echo' ) ;
80123 } ) ;
81124 } ) ;
82125
126+ describe ( 'Generic unsupported runtimes' , ( ) => {
127+ it ( 'catches ruby commands' , ( ) => {
128+ const result = rewriteUnsupportedCommand ( 'ruby app.rb' ) ;
129+ expect ( result . wasRewritten ) . toBe ( true ) ;
130+ expect ( result . command ) . toContain ( 'echo' ) ;
131+ expect ( result . command ) . toContain ( 'ruby' ) ;
132+ } ) ;
133+
134+ it ( 'catches perl commands' , ( ) => {
135+ const result = rewriteUnsupportedCommand ( 'perl script.pl' ) ;
136+ expect ( result . wasRewritten ) . toBe ( true ) ;
137+ expect ( result . command ) . toContain ( 'echo' ) ;
138+ expect ( result . command ) . toContain ( 'perl' ) ;
139+ } ) ;
140+
141+ it ( 'catches php commands' , ( ) => {
142+ const result = rewriteUnsupportedCommand ( 'php index.php' ) ;
143+ expect ( result . wasRewritten ) . toBe ( true ) ;
144+ expect ( result . command ) . toContain ( 'echo' ) ;
145+ expect ( result . command ) . toContain ( 'php' ) ;
146+ } ) ;
147+ } ) ;
148+
83149 describe ( 'Passthrough (no rewrite needed)' , ( ) => {
84150 it ( 'does not rewrite npm commands' , ( ) => {
85151 const result = rewriteUnsupportedCommand ( 'npm run dev' ) ;
0 commit comments