@@ -326,6 +326,206 @@ describe("cookieDatabaseCandidatePaths", () => {
326326
327327const firefox = BROWSER_IMPORT_SOURCES . find ( ( source ) => source . id === "firefox" ) ! ;
328328
329+ const zen = BROWSER_IMPORT_SOURCES . find ( ( source ) => source . id === "zen" ) ! ;
330+
331+ describe ( "Zen" , ( ) => {
332+ it . effect ( "resolves Zen's native user-data roots on every supported platform" , ( ) =>
333+ run (
334+ Effect . gen ( function * ( ) {
335+ const darwinContext = yield * sourcePathContext . pipe (
336+ Effect . provideService ( HostProcess . Environment , { HOME : "/Users/zen-user" } ) ,
337+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
338+ ) ;
339+ const windowsContext = yield * sourcePathContext . pipe (
340+ Effect . provideService ( HostProcess . Environment , {
341+ HOME : "C:\\Users\\zen-user" ,
342+ APPDATA : "C:\\Users\\zen-user\\AppData\\Roaming" ,
343+ } ) ,
344+ Effect . provideService ( HostProcess . Platform , "win32" ) ,
345+ ) ;
346+ const linuxContext = yield * sourcePathContext . pipe (
347+ Effect . provideService ( HostProcess . Environment , { HOME : "/home/zen-user" } ) ,
348+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
349+ ) ;
350+
351+ assert . equal ( zen . name , "Zen" ) ;
352+ assert . equal ( zen . engine , "firefox" ) ;
353+ assert . deepEqual ( [ ...zen . platforms ] , [ "darwin" , "win32" , "linux" ] ) ;
354+ assert . equal (
355+ zen . userDataDirectory ( darwinContext ) ,
356+ darwinContext . path . join ( "/Users/zen-user" , "Library" , "Application Support" , "zen" ) ,
357+ ) ;
358+ assert . equal (
359+ zen . userDataDirectory ( windowsContext ) ,
360+ windowsContext . path . join ( "C:\\Users\\zen-user\\AppData\\Roaming" , "zen" ) ,
361+ ) ;
362+ assert . equal (
363+ zen . userDataDirectory ( linuxContext ) ,
364+ linuxContext . path . join ( "/home/zen-user" , ".config" , "zen" ) ,
365+ ) ;
366+ assert . deepEqual ( zen . alternateLinuxRoots ?.( linuxContext ) , [
367+ linuxContext . path . join ( "/home/zen-user" , ".zen" ) ,
368+ ] ) ;
369+ } ) ,
370+ ) ,
371+ ) ;
372+
373+ it . effect ( "discovers Zen profiles through its Firefox-compatible metadata" , ( ) =>
374+ run (
375+ Effect . gen ( function * ( ) {
376+ const fileSystem = yield * FileSystem . FileSystem ;
377+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-zen-" } ) ;
378+ const context = yield * sourcePathContext . pipe (
379+ Effect . provideService ( HostProcess . Environment , { HOME : home } ) ,
380+ Effect . provideService ( HostProcess . Platform , "darwin" ) ,
381+ ) ;
382+ const root = zen . userDataDirectory ( context ) ! ;
383+ yield * fileSystem . makeDirectory ( root , { recursive : true } ) ;
384+ const profile = context . path . join ( root , "Profiles" , "zen.default" ) ;
385+ yield * fileSystem . makeDirectory ( profile , { recursive : true } ) ;
386+ yield * writeFirefoxCookieDatabase ( context . path . join ( profile , "cookies.sqlite" ) , 2 , 1 ) ;
387+ yield * fileSystem . makeDirectory ( context . path . join ( root , "Profiles" , "empty.default" ) , {
388+ recursive : true ,
389+ } ) ;
390+ yield * fileSystem . writeFileString (
391+ context . path . join ( root , "profiles.ini" ) ,
392+ [
393+ "[Profile0]" ,
394+ "Name=Zen" ,
395+ "IsRelative=1" ,
396+ "Path=Profiles/zen.default" ,
397+ "ZenAvatarPath=chrome://browser/content/zen-avatars/avatar-55.svg" ,
398+ "Default=1" ,
399+ "" ,
400+ "[Profile1]" ,
401+ "Name=Empty" ,
402+ "IsRelative=1" ,
403+ "Path=Profiles/empty.default" ,
404+ "" ,
405+ ] . join ( "\n" ) ,
406+ ) ;
407+
408+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
409+ {
410+ directory : context . path . join ( "Profiles" , "zen.default" ) ,
411+ name : "Zen" ,
412+ cookieCount : 2 ,
413+ } ,
414+ ] ) ;
415+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
416+ assert . isFalse ( yield * isSourceRunning ( zen , context ) ) ;
417+ assert . equal (
418+ yield * resolveCookieDatabase ( zen , context , context . path . join ( "Profiles" , "zen.default" ) ) ,
419+ context . path . join ( profile , "cookies.sqlite" ) ,
420+ ) ;
421+ } ) ,
422+ ) ,
423+ ) ;
424+
425+ it . effect ( "discovers Zen profiles in both current and legacy Linux roots" , ( ) =>
426+ run (
427+ Effect . gen ( function * ( ) {
428+ const fileSystem = yield * FileSystem . FileSystem ;
429+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-zen-linux-" } ) ;
430+ const context = yield * sourcePathContext . pipe (
431+ Effect . provideService ( HostProcess . Environment , { HOME : home } ) ,
432+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
433+ ) ;
434+ const currentRoot = context . path . join ( home , ".config" , "zen" ) ;
435+ const legacyRoot = context . path . join ( home , ".zen" ) ;
436+ const currentProfile = context . path . join ( currentRoot , "current.default" ) ;
437+ const legacyProfile = context . path . join ( legacyRoot , "legacy.default" ) ;
438+
439+ for ( const [ root , profile , name ] of [
440+ [ currentRoot , currentProfile , "Current" ] ,
441+ [ legacyRoot , legacyProfile , "Legacy" ] ,
442+ ] as const ) {
443+ yield * fileSystem . makeDirectory ( profile , { recursive : true } ) ;
444+ yield * writeFirefoxCookieDatabase ( context . path . join ( profile , "cookies.sqlite" ) , 1 , 0 ) ;
445+ yield * fileSystem . writeFileString (
446+ context . path . join ( root , "profiles.ini" ) ,
447+ [
448+ "[Profile0]" ,
449+ `Name=${ name } ` ,
450+ "IsRelative=1" ,
451+ `Path=${ context . path . basename ( profile ) } ` ,
452+ ] . join ( "\n" ) ,
453+ ) ;
454+ }
455+
456+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
457+ { directory : "current.default" , name : "Current" , cookieCount : 1 } ,
458+ { directory : legacyProfile , name : "Legacy" , cookieCount : 1 } ,
459+ ] ) ;
460+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
461+ assert . equal (
462+ yield * resolveCookieDatabase ( zen , context , legacyProfile ) ,
463+ context . path . join ( legacyProfile , "cookies.sqlite" ) ,
464+ ) ;
465+
466+ yield * fileSystem . writeFileString (
467+ context . path . join ( currentRoot , "profiles.ini" ) ,
468+ `[Profile0]\nName=Shared\nIsRelative=0\nPath=${ legacyProfile } \n` ,
469+ ) ;
470+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
471+ { directory : legacyProfile , name : "Shared" , cookieCount : 1 } ,
472+ ] ) ;
473+
474+ yield * fileSystem . remove ( currentRoot , { recursive : true } ) ;
475+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
476+ assert . deepEqual ( yield * listSourceProfiles ( zen , context ) , [
477+ { directory : legacyProfile , name : "Legacy" , cookieCount : 1 } ,
478+ ] ) ;
479+ } ) ,
480+ ) ,
481+ ) ;
482+
483+ it . effect ( "does not mistake Firefox Snap installs for Zen profiles" , ( ) =>
484+ run (
485+ Effect . gen ( function * ( ) {
486+ const fileSystem = yield * FileSystem . FileSystem ;
487+ const home = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "t3code-zen-snap-" } ) ;
488+ const context = yield * sourcePathContext . pipe (
489+ Effect . provideService ( HostProcess . Environment , { HOME : home } ) ,
490+ Effect . provideService ( HostProcess . Platform , "linux" ) ,
491+ ) ;
492+ const zenRoot = context . path . join ( home , ".config" , "zen" ) ;
493+ const snapRoot = context . path . join (
494+ home ,
495+ "snap" ,
496+ "firefox" ,
497+ "common" ,
498+ ".mozilla" ,
499+ "firefox" ,
500+ ) ;
501+ const zenProfile = context . path . join ( zenRoot , "zen.default" ) ;
502+ const snapProfile = context . path . join ( snapRoot , "snap.default" ) ;
503+ for ( const root of [ zenRoot , snapRoot ] ) {
504+ const profile = root === zenRoot ? zenProfile : snapProfile ;
505+ yield * fileSystem . makeDirectory ( profile , { recursive : true } ) ;
506+ yield * writeFirefoxCookieDatabase ( context . path . join ( profile , "cookies.sqlite" ) , 1 , 0 ) ;
507+ yield * fileSystem . writeFileString (
508+ context . path . join ( root , "profiles.ini" ) ,
509+ [
510+ "[Profile0]" ,
511+ "Name=Personal" ,
512+ "IsRelative=1" ,
513+ `Path=${ profile === zenProfile ? "zen.default" : "snap.default" } ` ,
514+ ] . join ( "\n" ) ,
515+ ) ;
516+ }
517+
518+ const profiles = yield * listSourceProfiles ( zen , context ) ;
519+ assert . deepEqual (
520+ profiles . map ( ( profile ) => profile . directory ) ,
521+ [ "zen.default" ] ,
522+ ) ;
523+ assert . isTrue ( yield * isSourceInstalled ( zen , context ) ) ;
524+ } ) ,
525+ ) ,
526+ ) ;
527+ } ) ;
528+
329529describe ( "Firefox Snap profiles" , ( ) => {
330530 it . effect . skipIf ( ! symlinksSupported ) (
331531 "finds Snap profiles with or without profiles.ini and checks their locks" ,
0 commit comments