Harden real-runtime workflow validation

This commit is contained in:
vorotamoroz
2026-08-31 00:35:29 +00:00
parent 3a23b7a6b0
commit 9a28d46287
8 changed files with 72 additions and 42 deletions
@@ -28,14 +28,16 @@ export async function startHeldOneShotReplication(cliBinary: string, env: NodeJS
"const core=app.plugins.plugins['obsidian-livesync'].core;",
"const replicator=core.services.replicator.getActiveReplicator();",
"if(!replicator) throw new Error('No active replicator is available.');",
"const original=replicator.openReplication;",
"const methodName=typeof replicator.openOneShotReplicationWithOutcome==='function'?'openOneShotReplicationWithOutcome':'openReplication';",
"const original=replicator[methodName];",
"if(typeof original!=='function') throw new Error('The active replicator has no one-shot entry point.');",
"let releaseGate;",
"const gate=new Promise((resolve)=>{releaseGate=resolve;});",
`const state={kind:${JSON.stringify(REMOTE_ACTIVITY_GATE_KIND.oneShot)},entered:false,done:false,released:false,error:undefined,result:undefined,promise:undefined,release:undefined,restore:undefined};`,
"state.release=()=>{if(!state.released){state.released=true;releaseGate();}};",
"state.restore=()=>{replicator.openReplication=original;};",
"state.restore=()=>{replicator[methodName]=original;};",
"host[stateKey]=state;",
"replicator.openReplication=async function(...args){",
"replicator[methodName]=async function(...args){",
"state.entered=true;",
"await gate;",
"return await original.apply(this,args);",