@@ -24,17 +24,34 @@ describe("unmangleLocal", () => {
2424 it ( "returns null for non-mangled strings" , ( ) => {
2525 expect ( unmangleLocal ( "just_a_variable" ) ) . toBeNull ( ) ;
2626 expect ( unmangleLocal ( "_private" ) ) . toBeNull ( ) ;
27- expect ( unmangleLocal ( "_cell_Hbol_" ) ) . toBeNull ( ) ;
27+ } ) ;
28+
29+ it ( "handles the single-underscore local" , ( ) => {
30+ // `_` is a valid local name (variables.py:62-63), mangling to
31+ // `_cell_<id>_` with no trailing suffix.
32+ expect ( unmangleLocal ( "_cell_Hbol_" ) ) . toEqual ( {
33+ cellId : "Hbol" ,
34+ name : "_" ,
35+ } ) ;
36+ } ) ;
37+
38+ it ( "handles UUID-style cell ids" , ( ) => {
39+ // External / VSCode notebooks use `external_prefix()` which is a
40+ // `uuid4()` (hyphenated).
41+ expect (
42+ unmangleLocal ( "_cell_c9bf9e57-1685-4c89-bafb-ff5af830be8a_a" ) ,
43+ ) . toEqual ( {
44+ cellId : "c9bf9e57-1685-4c89-bafb-ff5af830be8a" ,
45+ name : "_a" ,
46+ } ) ;
2847 } ) ;
2948
3049 it ( "does not match marimo cell file paths" , ( ) => {
3150 // The compiled cell file is `__marimo__cell_<id>_.py` (two leading
3251 // underscores, trailing `_` with no name); it must not be confused with a
3352 // mangled local.
3453 expect ( unmangleLocal ( "__marimo__cell_Hbol_.py" ) ) . toBeNull ( ) ;
35- expect (
36- unmangleLocal ( "/tmp/marimo_42/__marimo__cell_Hbol_.py" ) ,
37- ) . toBeNull ( ) ;
54+ expect ( unmangleLocal ( "/tmp/marimo_42/__marimo__cell_Hbol_.py" ) ) . toBeNull ( ) ;
3855 } ) ;
3956} ) ;
4057
@@ -44,19 +61,15 @@ describe("splitMangledLocals", () => {
4461 } ) ;
4562
4663 it ( "splits a NameError message" , ( ) => {
47- expect (
48- splitMangledLocals ( "name '_cell_Hbol_a' is not defined" ) ,
49- ) . toEqual ( [
64+ expect ( splitMangledLocals ( "name '_cell_Hbol_a' is not defined" ) ) . toEqual ( [
5065 "name '" ,
5166 { cellId : "Hbol" , name : "_a" } ,
5267 "' is not defined" ,
5368 ] ) ;
5469 } ) ;
5570
5671 it ( "handles multiple mangled names in one string" , ( ) => {
57- expect (
58- splitMangledLocals ( "_cell_AAAA_x and _cell_BBBB_y" ) ,
59- ) . toEqual ( [
72+ expect ( splitMangledLocals ( "_cell_AAAA_x and _cell_BBBB_y" ) ) . toEqual ( [
6073 { cellId : "AAAA" , name : "_x" } ,
6174 " and " ,
6275 { cellId : "BBBB" , name : "_y" } ,
@@ -67,6 +80,37 @@ describe("splitMangledLocals", () => {
6780 const path = "/tmp/marimo_42/__marimo__cell_Hbol_.py" ;
6881 expect ( splitMangledLocals ( path ) ) . toEqual ( [ path ] ) ;
6982 } ) ;
83+
84+ it ( "ignores `_cell_...` substrings preceded by `_`" , ( ) => {
85+ // Mirrors `(?<!_)` in `variables.py`: a leading `_` (e.g. inside
86+ // `__marimo__cell_<id>_<...>`) means this is not a mangle the compiler
87+ // produced, so we must not demangle it.
88+ const text = "see __marimo__cell_Hbol_a for details" ;
89+ expect ( splitMangledLocals ( text ) ) . toEqual ( [ text ] ) ;
90+ } ) ;
91+
92+ it ( "splits a UUID-style cell id" , ( ) => {
93+ expect (
94+ splitMangledLocals (
95+ "name '_cell_c9bf9e57-1685-4c89-bafb-ff5af830be8a_a' is not defined" ,
96+ ) ,
97+ ) . toEqual ( [
98+ "name '" ,
99+ {
100+ cellId : "c9bf9e57-1685-4c89-bafb-ff5af830be8a" ,
101+ name : "_a" ,
102+ } ,
103+ "' is not defined" ,
104+ ] ) ;
105+ } ) ;
106+
107+ it ( "splits the single-underscore local" , ( ) => {
108+ expect ( splitMangledLocals ( "name '_cell_Hbol_' is not defined" ) ) . toEqual ( [
109+ "name '" ,
110+ { cellId : "Hbol" , name : "_" } ,
111+ "' is not defined" ,
112+ ] ) ;
113+ } ) ;
70114} ) ;
71115
72116describe ( "containsMangledLocal" , ( ) => {
@@ -77,8 +121,12 @@ describe("containsMangledLocal", () => {
77121 } ) ;
78122
79123 it ( "ignores the cell file path" , ( ) => {
80- expect (
81- containsMangledLocal ( "/tmp/marimo_42/__marimo__cell_Hbol_.py" ) ,
82- ) . toBe ( false ) ;
124+ expect ( containsMangledLocal ( "/tmp/marimo_42/__marimo__cell_Hbol_.py" ) ) . toBe (
125+ false ,
126+ ) ;
127+ } ) ;
128+
129+ it ( "ignores `_cell_...` substrings preceded by `_`" , ( ) => {
130+ expect ( containsMangledLocal ( "see __marimo__cell_Hbol_a" ) ) . toBe ( false ) ;
83131 } ) ;
84132} ) ;
0 commit comments