@@ -47,7 +47,7 @@ describe("transforms Build Output Specification into deploy input", () => {
4747 expect ( result . bundleType ) . toBe ( "esm" ) ;
4848 expect ( result . content ) . toBe ( "export default {}" ) ;
4949 expect ( result . modules ) . toHaveLength ( 1 ) ;
50- expect ( result . modules [ 0 ] ?. name ) . toBe ( "./ helper.wasm" ) ;
50+ expect ( result . modules [ 0 ] ?. name ) . toBe ( "helper.wasm" ) ;
5151 expect ( result . modules [ 0 ] ?. type ) . toBe ( "compiled-wasm" ) ;
5252 expect ( Object . keys ( result . dependencies ) ) . toHaveLength ( 2 ) ;
5353 } ) ;
@@ -83,9 +83,9 @@ describe("transforms Build Output Specification into deploy input", () => {
8383 expect ( builtConfig . manifest ?. type ) . toBe ( "complete" ) ;
8484 expect ( result . modules ) . toEqual (
8585 expect . arrayContaining ( [
86- expect . objectContaining ( { name : "./ chunk.mjs" , type : "esm" } ) ,
86+ expect . objectContaining ( { name : "chunk.mjs" , type : "esm" } ) ,
8787 expect . objectContaining ( {
88- name : "./ helper.wasm" ,
88+ name : "helper.wasm" ,
8989 type : "compiled-wasm" ,
9090 } ) ,
9191 ] )
@@ -266,11 +266,55 @@ describe("transforms Build Output Specification into deploy input", () => {
266266 const typeMap = Object . fromEntries (
267267 result . modules . map ( ( m ) => [ m . name , m . type ] )
268268 ) ;
269- expect ( typeMap [ "./lib.cjs" ] ) . toBe ( "commonjs" ) ;
270- expect ( typeMap [ "./app.py" ] ) . toBe ( "python" ) ;
271- expect ( typeMap [ "./dep.txt" ] ) . toBe ( "text" ) ;
272- expect ( typeMap [ "./blob.bin" ] ) . toBe ( "buffer" ) ;
273- expect ( typeMap [ "./config.json" ] ) . toBe ( "text" ) ;
269+ expect ( typeMap [ "lib.cjs" ] ) . toBe ( "commonjs" ) ;
270+ expect ( typeMap [ "app.py" ] ) . toBe ( "python" ) ;
271+ expect ( typeMap [ "dep.txt" ] ) . toBe ( "text" ) ;
272+ expect ( typeMap [ "blob.bin" ] ) . toBe ( "buffer" ) ;
273+ expect ( typeMap [ "config.json" ] ) . toBe ( "text" ) ;
274+ } ) ;
275+
276+ it ( "keeps Python vendored module paths exactly as in the manifest" , async ( ) => {
277+ // Python Workers import vendored packages from `python_modules/` and use
278+ // module names as file paths, so a `./` prefix makes `import workers` fail.
279+ await seed ( {
280+ ".cloudflare/output/v0/config.json" : buildOutputRootConfig ( ) ,
281+ ".cloudflare/output/v0/workers/default/worker.config.json" : workerConfig ( {
282+ name : "my-worker" ,
283+ compatibilityFlags : [ "python_workers" ] ,
284+ mainModule : "entry.py" ,
285+ modules : {
286+ "entry.py" : { type : "python" } ,
287+ "helpers.py" : { type : "python" } ,
288+ "python_modules/workers/__init__.py" : { type : "data" } ,
289+ "python_modules/_workers_sdk_patch_loader.pth" : { type : "data" } ,
290+ "python_modules/workers/workflows.js" : { type : "esm" } ,
291+ } ,
292+ } ) ,
293+ ".cloudflare/output/v0/workers/default/bundle/entry.py" :
294+ "from workers import WorkerEntrypoint" ,
295+ ".cloudflare/output/v0/workers/default/bundle/helpers.py" : "pass" ,
296+ ".cloudflare/output/v0/workers/default/bundle/python_modules/workers/__init__.py" :
297+ "" ,
298+ ".cloudflare/output/v0/workers/default/bundle/python_modules/_workers_sdk_patch_loader.pth" :
299+ "" ,
300+ ".cloudflare/output/v0/workers/default/bundle/python_modules/workers/workflows.js" :
301+ "export {}" ,
302+ } ) ;
303+
304+ const {
305+ rootConfig,
306+ workers : { default : worker } ,
307+ } = await readBuildOutput ( process . cwd ( ) ) ;
308+ const { builtConfig } = parseWorkerConfig ( worker , rootConfig ) ;
309+ const result = assembleBuildResult ( worker , builtConfig ) ;
310+
311+ expect ( result . bundleType ) . toBe ( "python" ) ;
312+ expect ( result . modules . map ( ( m ) => m . name ) . sort ( ) ) . toEqual ( [
313+ "helpers.py" ,
314+ "python_modules/_workers_sdk_patch_loader.pth" ,
315+ "python_modules/workers/__init__.py" ,
316+ "python_modules/workers/workflows.js" ,
317+ ] ) ;
274318 } ) ;
275319
276320 it ( "throws when run_worker_first is set without a user Worker" , async ( ) => {
0 commit comments