fix: harden long conversation continuity
Memind CI / Test, build, and release guards (push) Successful in 1m28s

This commit is contained in:
john
2026-07-27 21:39:34 +08:00
parent 5ae166fc44
commit 48c61a3279
16 changed files with 1635 additions and 94 deletions
+52 -1
View File
@@ -106,6 +106,12 @@ test('syncUserWorkspace imports new workspace files into asset library', async (
);
return [space ? [space] : []];
}
if (sql.includes('FROM h5_assets') && sql.includes('FOR UPDATE')) {
const asset = state.assets.find(
(item) => item.id === params[0] && item.user_id === params[1],
);
return [asset ? [asset] : []];
}
if (sql.includes('INSERT INTO h5_assets')) {
state.assets.push({
id: params[0],
@@ -123,18 +129,53 @@ test('syncUserWorkspace imports new workspace files into asset library', async (
return [[]];
}
if (sql.includes('INSERT INTO h5_asset_versions')) {
const storageKey = sql.includes('VALUES (?, ?, 1')
? params[2]
: params[3];
if (state.versions.some((item) => item.storage_key === storageKey)) {
const error = new Error(`Duplicate storage key ${storageKey}`);
error.code = 'ER_DUP_ENTRY';
throw error;
}
state.versions.push({
id: params[0],
asset_id: params[1],
storage_key: params[2],
storage_key: storageKey,
scan_status: params[7],
});
return [[]];
}
if (sql.includes('UPDATE h5_assets') && sql.includes('SET size_bytes =')) {
const asset = state.assets.find(
(item) => item.id === params[8] && item.user_id === params[9],
);
asset.size_bytes = params[0];
asset.checksum = params[1];
asset.mime_type = params[2];
asset.asset_type = params[3];
asset.risk_level = params[4];
asset.status = params[5];
asset.workspace_relative_path = params[6];
return [[]];
}
if (sql.includes('UPDATE h5_asset_versions')) {
const version = state.versions.find(
(item) => item.id === params[6] && item.asset_id === params[7],
);
version.size_bytes = params[0];
version.checksum = params[1];
version.mime_type = params[2];
version.scan_status = params[4];
return [[]];
}
if (sql.includes('used_bytes = used_bytes +')) {
state.spaces[0].used_bytes += params[0];
return [[]];
}
if (sql.includes('used_bytes = GREATEST')) {
state.spaces[0].used_bytes += params[0];
return [[]];
}
if (sql.includes('COALESCE(MAX(version_no)')) {
return [[{ max_version: 0 }]];
}
@@ -203,6 +244,16 @@ test('syncUserWorkspace imports new workspace files into asset library', async (
'writeManifestForSession',
{ userId: 'user-1', sessionId: 'session-1' },
]);
await fs.writeFile(path.join(workspace, 'oa', 'memo.txt'), 'updated workspace\n');
const updated = await sync.syncUserWorkspace('user-1', {
categoryCode: 'oa',
sourceSessionId: 'session-1',
sourceMessageId: 'message-2',
});
assert.equal(updated.updated, 1);
assert.equal(state.versions.length, 1);
assert.equal(state.assets[0].size_bytes, Buffer.byteLength('updated workspace\n'));
});
test('syncUserWorkspace imports sandboxable public html as warned ready asset', async () => {