test: protect manual Luker cache rebuild

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Sisyphus
2026-05-03 15:30:22 +00:00
parent d605720aaa
commit fe89c8b204

View File

@@ -159,6 +159,10 @@ const messageSnippet = extractSnippet(
'function onMessageReceived(messageId = null, type = "") {', 'function onMessageReceived(messageId = null, type = "") {',
"async function onViewGraph() {", "async function onViewGraph() {",
); );
const lukerCacheActionSnippet = extractSnippet(
"async function onRebuildLocalCacheFromLukerSidecar() {",
"async function onRepairLukerSidecar() {",
);
function createSessionStorage(seed = null) { function createSessionStorage(seed = null) {
const store = seed instanceof Map ? seed : new Map(); const store = seed instanceof Map ? seed : new Map();
@@ -1555,6 +1559,7 @@ async function createGraphPersistenceHarness({
persistencePrelude, persistencePrelude,
persistenceCore, persistenceCore,
messageSnippet, messageSnippet,
lukerCacheActionSnippet,
` `
result = { result = {
GRAPH_LOAD_STATES, GRAPH_LOAD_STATES,
@@ -1576,6 +1581,7 @@ result = {
maybeFlushQueuedGraphPersist, maybeFlushQueuedGraphPersist,
retryPendingGraphPersist, retryPendingGraphPersist,
persistExtractionBatchResult, persistExtractionBatchResult,
onRebuildLocalCacheFromLukerSidecar,
saveGraphToIndexedDb, saveGraphToIndexedDb,
cloneGraphForPersistence, cloneGraphForPersistence,
assertRecoveryChatStillActive, assertRecoveryChatStillActive,
@@ -4651,6 +4657,60 @@ result = {
); );
} }
{
const chatId = "chat-luker-manual-cache-rebuild";
const harness = await createGraphPersistenceHarness({
chatId,
globalChatId: chatId,
characterId: "char-luker-manual-cache-rebuild",
chatMetadata: {
integrity: "meta-luker-manual-cache-rebuild",
},
});
harness.runtimeContext.Luker = {
getContext() {
return harness.runtimeContext.__chatContext;
},
};
const graph = stampPersistedGraph(
createMeaningfulGraph(chatId, "luker-manual-cache"),
{
revision: 10,
integrity: "meta-luker-manual-cache-rebuild",
chatId,
reason: "luker-manual-cache-seed",
},
);
harness.api.setCurrentGraph(graph);
const persistResult = await harness.api.persistExtractionBatchResult({
reason: "luker-manual-cache-persist",
lastProcessedAssistantFloor: 6,
});
await new Promise((resolve) => setTimeout(resolve, 0));
assert.equal(persistResult.cacheTier, "none");
assert.equal(
Number(harness.api.getIndexedDbSnapshot()?.meta?.revision || 0),
0,
"Luker 默认路径不应自动重建浏览器缓存",
);
const rebuildResult = await harness.api.onRebuildLocalCacheFromLukerSidecar();
assert.equal(rebuildResult.handledToast, true);
assert.equal(rebuildResult.result?.loaded, true);
await new Promise((resolve) => setTimeout(resolve, 0));
await new Promise((resolve) => setTimeout(resolve, 0));
assert.equal(
Number(harness.api.getIndexedDbSnapshot()?.meta?.revision || 0),
persistResult.revision,
"只有手动重建本地缓存时才应写入浏览器缓存 revision",
);
assert.equal(
Number(harness.api.getIndexedDbSnapshot()?.nodes?.length || 0),
1,
"只有手动重建本地缓存时才应写入浏览器缓存 nodes",
);
}
{ {
const harness = await createGraphPersistenceHarness({ const harness = await createGraphPersistenceHarness({
chatId: "chat-luker-v2-load", chatId: "chat-luker-v2-load",