@@ -3,6 +3,7 @@ import { assert, describe, it } from "@effect/vitest";
33import { ConnectionCatalogDocument } from "@t3tools/client-runtime/platform" ;
44import { EnvironmentId , type PersistedSavedEnvironmentRecord } from "@t3tools/contracts" ;
55import * as Effect from "effect/Effect" ;
6+ import * as Encoding from "effect/Encoding" ;
67import * as FileSystem from "effect/FileSystem" ;
78import * as Path from "effect/Path" ;
89import * as Layer from "effect/Layer" ;
@@ -22,6 +23,11 @@ const textEncoder = new TextEncoder();
2223const decodeConnectionCatalog = Schema . decodeEffect (
2324 Schema . fromJsonString ( ConnectionCatalogDocument ) ,
2425) ;
26+ const encodeLegacySavedEnvironments = Schema . encodeEffect (
27+ Schema . fromJsonString (
28+ Schema . Struct ( { version : Schema . Literal ( 1 ) , records : Schema . Array ( Schema . Unknown ) } ) ,
29+ ) ,
30+ ) ;
2531function makeSafeStorageLayer ( available : boolean , failDecrypt : Ref . Ref < boolean > | null = null ) {
2632 return Layer . succeed ( ElectronSafeStorage . ElectronSafeStorage , {
2733 isEncryptionAvailable : Effect . succeed ( available ) ,
@@ -125,7 +131,8 @@ describe("DesktopConnectionCatalogStore", () => {
125131 withStore (
126132 Effect . gen ( function * ( ) {
127133 const store = yield * DesktopConnectionCatalogStore . DesktopConnectionCatalogStore ;
128- const savedEnvironments = yield * DesktopSavedEnvironments . DesktopSavedEnvironments ;
134+ const environment = yield * DesktopEnvironment . DesktopEnvironment ;
135+ const fileSystem = yield * FileSystem . FileSystem ;
129136 const records : readonly PersistedSavedEnvironmentRecord [ ] = [
130137 {
131138 environmentId : EnvironmentId . make ( "relay-environment" ) ,
@@ -159,11 +166,21 @@ describe("DesktopConnectionCatalogStore", () => {
159166 lastConnectedAt : null ,
160167 } ,
161168 ] ;
162- yield * savedEnvironments . setRegistry ( records ) ;
163- assert . isTrue (
164- yield * savedEnvironments . setSecret ( {
165- environmentId : EnvironmentId . make ( "bearer-environment" ) ,
166- secret : "legacy-token" ,
169+ yield * fileSystem . makeDirectory ( environment . stateDir , { recursive : true } ) ;
170+ yield * fileSystem . writeFileString (
171+ environment . savedEnvironmentRegistryPath ,
172+ yield * encodeLegacySavedEnvironments ( {
173+ version : 1 ,
174+ records : records . map ( ( record ) =>
175+ record . environmentId === "bearer-environment"
176+ ? {
177+ ...record ,
178+ encryptedBearerToken : Encoding . encodeBase64 (
179+ textEncoder . encode ( "encrypted:legacy-token" ) ,
180+ ) ,
181+ }
182+ : record ,
183+ ) ,
167184 } ) ,
168185 ) ;
169186
@@ -218,7 +235,10 @@ describe("DesktopConnectionCatalogStore", () => {
218235 assert . equal ( catalog . credentials [ 0 ] . credential . token , "legacy-token" ) ;
219236 }
220237
221- yield * savedEnvironments . setRegistry ( [ ] ) ;
238+ yield * fileSystem . writeFileString (
239+ environment . savedEnvironmentRegistryPath ,
240+ '{"version":1,"records":[]}' ,
241+ ) ;
222242 assert . deepEqual ( yield * store . get , migrated ) ;
223243 } ) ,
224244 ) ,
0 commit comments