Fix tweak recovery for effective encryption settings

This commit is contained in:
vorotamoroz committed 2026-10-17 08:23:08 +00:00
1 parent 72dc88c7ef
commit d31ad56211
6 files changed
+199 -10

No files matched your search

+1 -1
View File
@@ -187,7 +187,7 @@ LIVESYNC_CLI_COMMAND="docker run --rm --network host --user $(id -u):$(id -g) --
npm run test:e2e:obsidian:cli-to-obsidian-sync
```
`test:e2e:obsidian:tweak-compatibility` exercises the mismatch dialogue against temporary CouchDB databases. Build the plug-in first. The scenario removes the legacy filename-case value from the remote preferred settings, applies compatible differences through the ordinary settings action, and verifies note synchronisation and a subsequent restart. Separate true/false and true/missing filename-case mismatches check that Fetch remains required. The true/missing case also fetches the files and verifies a subsequent synchronisation attempt. A final case changes the remote while the dialogue is open, selects the stale Fetch action, and checks that the current settings, existing local file, and documents in both remotes remain unchanged.
`test:e2e:obsidian:tweak-compatibility` exercises the mismatch dialogue against temporary CouchDB databases. Build the plug-in first. The scenario removes the legacy filename-case value from the remote preferred settings, applies compatible differences through the ordinary settings action, and verifies note synchronisation and a subsequent restart. An enabled but inactive internal Metadata encryption preference must neither suppress the `Sync now` dialogue nor be lost when applying the remote chunk settings and restarting. Separate true/false and true/missing filename-case mismatches check that Fetch remains required. The true/missing case also fetches the files and verifies a subsequent synchronisation attempt. A final case changes the remote while the dialogue is open, selects the stale Fetch action, and checks that the current settings, existing local file, and documents in both remotes remain unchanged.
`test:e2e:obsidian:minio-upload` reuses the Object Storage variables from `.test.env` or the process environment. It expects a reachable S3-compatible service and starts with isolated Object Storage settings and the device-local compatibility acknowledgement already in place, keeping the scenario focused on upload rather than unconfigured start-up or setup. It confirms those settings through `obsidian-cli eval`, creates a note in real Obsidian, runs one-shot Journal Sync, and verifies through the AWS SDK that objects were written under a unique bucket prefix. Adapter tests separately observe an in-progress SDK command, while this real-runtime workflow verifies the resulting request counters advance and rebalance.
@@ -6,6 +6,8 @@
* in the chunk size and V2 customisation setting. Applying the ordinary
* remote settings action must permit a fresh synchronisation without a Fetch. A
* Separate true/false and true/missing case controls keep Fetch required.
* An enabled but inactive internal Metadata encryption preference must survive
* ordinary setting adoption and restart, and must not suppress the Sync now dialogue.
*/
import { readFile } from "node:fs/promises";
import { join } from "node:path";
@@ -129,6 +131,21 @@ async function replicateOnce(cliBinary: string, env: NodeJS.ProcessEnv): Promise
);
}
async function runSyncNow(cliBinary: string, env: NodeJS.ProcessEnv): Promise<void> {
await evalObsidianJson<boolean>(
cliBinary,
[
"(async()=>{",
"const command=app.commands.commands['obsidian-livesync:livesync-replicate'];",
"if(typeof command?.callback!=='function') throw new Error('Sync now command is unavailable');",
"await command.callback();",
"return JSON.stringify(true);",
"})()",
].join(""),
env
);
}
async function selectCompatibilityAction(
port: number,
action: string,
@@ -220,17 +237,23 @@ async function prepareConfiguredSession(
async function readTweakState(
cliBinary: string,
env: NodeJS.ProcessEnv
): Promise<{ customChunkSize: unknown; usePluginSyncV2: unknown; handleFilenameCaseSensitive: unknown }> {
): Promise<{
customChunkSize: unknown;
usePluginSyncV2: unknown;
handleFilenameCaseSensitive: unknown;
encryptInternalMetadata: unknown;
}> {
return await evalObsidianJson<{
customChunkSize: unknown;
usePluginSyncV2: unknown;
handleFilenameCaseSensitive: unknown;
encryptInternalMetadata: unknown;
}>(
cliBinary,
[
"(()=>{",
"const settings=app.plugins.plugins['obsidian-livesync'].core.services.setting.currentSettings();",
"return JSON.stringify({customChunkSize:settings.customChunkSize,usePluginSyncV2:settings.usePluginSyncV2,handleFilenameCaseSensitive:settings.handleFilenameCaseSensitive});",
"return JSON.stringify({customChunkSize:settings.customChunkSize,usePluginSyncV2:settings.usePluginSyncV2,handleFilenameCaseSensitive:settings.handleFilenameCaseSensitive,encryptInternalMetadata:settings.encryptInternalMetadata});",
"})()",
].join(""),
env
@@ -360,12 +383,20 @@ async function main(): Promise<void> {
await removeLegacyCasePreference(couchDb, dbName);
targetSession = await prepareConfiguredSession(binary, cli.binary, targetVault, settings, {
encrypt: false,
encryptInternalMetadata: true,
customChunkSize: 60,
usePluginSyncV2: true,
handleFilenameCaseSensitive: false,
autoAcceptCompatibleTweak: false,
});
await prepareRemote(cli.binary, targetSession.cliEnv);
const commandPromise = runSyncNow(cli.binary, targetSession.cliEnv);
await selectCompatibilityAction(targetSession.remoteDebuggingPort, dismissAction);
await commandPromise;
const dismissedState = await readTweakState(cli.binary, targetSession.cliEnv);
assertEqual(dismissedState.customChunkSize, 60, "Dismissing Sync now changed the chunk size.");
assertEqual(dismissedState.encryptInternalMetadata, true, "Dismissing Sync now changed the saved preference.");
const targetReplicationPromise = replicateOnce(cli.binary, targetSession.cliEnv);
await selectCompatibilityAction(targetSession.remoteDebuggingPort, applySettingsAction);
const targetReplication = await targetReplicationPromise;
@@ -383,6 +414,11 @@ async function main(): Promise<void> {
await waitForLiveSyncCoreReady(cli.binary, targetSession.cliEnv);
await assertE2eCompatibilityMarker(cli.binary, targetSession.cliEnv);
const restartedState = await readTweakState(cli.binary, targetSession.cliEnv);
assertEqual(
restartedState.encryptInternalMetadata,
true,
"The inactive internal Metadata encryption preference was not retained after adoption and restart."
);
assertEqual(
restartedState.customChunkSize,
0,