refactor(sync): extract saveGraphToChat + luker cache action (Phase 5e)

This commit is contained in:
youzini
2026-05-31 13:22:49 +00:00
parent 0160a0da83
commit 23318ea0dc
3 changed files with 357 additions and 237 deletions

View File

@@ -192,7 +192,9 @@ import {
buildBmeSyncRuntimeOptionsImpl,
loadGraphFromChatImpl,
maybeCaptureGraphShadowSnapshotImpl,
onRebuildLocalCacheFromLukerSidecarImpl,
persistExtractionBatchResultImpl,
saveGraphToChatImpl,
shouldUseAuthorityGraphStoreImpl,
shouldUseAuthorityJobsImpl,
syncGraphLoadFromLiveContextImpl,
@@ -860,7 +862,9 @@ async function createGraphPersistenceHarness({
buildBmeSyncRuntimeOptionsImpl,
loadGraphFromChatImpl,
maybeCaptureGraphShadowSnapshotImpl,
onRebuildLocalCacheFromLukerSidecarImpl,
persistExtractionBatchResultImpl,
saveGraphToChatImpl,
shouldUseAuthorityGraphStoreImpl,
shouldUseAuthorityJobsImpl,
syncGraphLoadFromLiveContextImpl,
@@ -1368,6 +1372,39 @@ async function createGraphPersistenceHarness({
recordLocalPersistEarlyFailure(reason = "") {
runtimeContext.__lastLocalPersistEarlyFailure = String(reason || "");
},
isGraphLoadStateDbReady(loadState = runtimeContext.graphPersistenceState?.loadState) {
return loadState === GRAPH_LOAD_STATES.LOADED || loadState === GRAPH_LOAD_STATES.EMPTY_CONFIRMED;
},
isGraphMetadataWriteAllowed() {
return true;
},
isLukerPrimaryPersistenceHost(context = runtimeContext.getContext?.()) {
return resolveBmeHostProfile(context) === "luker";
},
async loadGraphFromLukerSidecarV2(chatId, options = {}) {
runtimeContext.__lastLukerSidecarLoad = { chatId, options };
return { loaded: Boolean(runtimeContext.currentGraph), reason: "test-luker-sidecar" };
},
normalizeIndexedDbRevision(value, fallbackValue = 0) {
const numeric = Number(value);
if (Number.isFinite(numeric) && numeric > 0) return Math.floor(numeric);
const fallback = Number(fallbackValue);
return Number.isFinite(fallback) && fallback > 0 ? Math.floor(fallback) : 0;
},
resolvePersistRevisionFloor(baseRevision = 0, graph = runtimeContext.currentGraph) {
return Math.max(
0,
Math.floor(Number(baseRevision || 0)),
Math.floor(Number(graph?.meta?.revision || 0)),
Math.floor(Number(getGraphPersistedRevision(graph) || 0)),
);
},
resolveCurrentChatStateTarget(context = runtimeContext.getContext?.()) {
return resolveCurrentBmeChatStateTarget(context);
},
scheduleBmeIndexedDbTask(task) {
return Promise.resolve().then(() => task());
},
__syncNowCalls: [],
async syncNow(chatId, options = {}) {
runtimeContext.__syncNowCalls.push({