(
pathProvider: PathProvider,
runtime: RuntimeIdentity,
options: AssertDataDirCompatibilityOptions = {}
)
| 82 | } |
| 83 | |
| 84 | export function assertDataDirCompatible( |
| 85 | pathProvider: PathProvider, |
| 86 | runtime: RuntimeIdentity, |
| 87 | options: AssertDataDirCompatibilityOptions = {} |
| 88 | ): void { |
| 89 | const userDataDir = pathProvider.getUserDataDir() |
| 90 | const meta = readDataDirCompatibilityMeta(userDataDir) |
| 91 | if (!meta) return |
| 92 | |
| 93 | const runtimeStableVersion = normalizeRuntimeStableVersion(runtime.version) |
| 94 | if (!runtimeStableVersion) { |
| 95 | throw new DataDirCompatibilityError( |
| 96 | 'DATA_DIR_REQUIRES_NEWER_RUNTIME', |
| 97 | `ChatLab data directory compatibility check requires a valid runtime semver; current version is ${runtime.version}.`, |
| 98 | { |
| 99 | userDataDir, |
| 100 | metaPath: getMetaPath(userDataDir), |
| 101 | currentVersion: runtime.version, |
| 102 | minRuntimeVersion: meta.minRuntimeVersion, |
| 103 | } |
| 104 | ) |
| 105 | } |
| 106 | |
| 107 | if (compareStableSemver(runtimeStableVersion, meta.minRuntimeVersion) < 0) { |
| 108 | const env = options.env ?? process.env |
| 109 | if (env.CHATLAB_ALLOW_INCOMPATIBLE_DATA_DIR === '1') { |
| 110 | const warn = options.warn ?? console.warn |
| 111 | warn( |
| 112 | [ |
| 113 | 'CHATLAB_ALLOW_INCOMPATIBLE_DATA_DIR=1 is set. ChatLab will bypass the data directory runtime version gate.', |
| 114 | `Current runtime ${runtime.kind}@${runtime.version} is below required version ${meta.minRuntimeVersion}.`, |
| 115 | `Data directory: ${userDataDir}. Continuing may risk data corruption.`, |
| 116 | ].join(' ') |
| 117 | ) |
| 118 | return |
| 119 | } |
| 120 | |
| 121 | throw new DataDirCompatibilityError( |
| 122 | 'DATA_DIR_REQUIRES_NEWER_RUNTIME', |
| 123 | `ChatLab data directory requires runtime version ${meta.minRuntimeVersion} or newer; current version is ${runtime.version}.`, |
| 124 | { |
| 125 | userDataDir, |
| 126 | metaPath: getMetaPath(userDataDir), |
| 127 | currentVersion: runtime.version, |
| 128 | minRuntimeVersion: meta.minRuntimeVersion, |
| 129 | } |
| 130 | ) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | export function raiseDataDirMinRuntimeVersion( |
| 135 | pathProvider: PathProvider, |
no test coverage detected