Skip to content

Commit 63b8696

Browse files
committed
test(mdviewer): add LRU cache test for files removed from working set
- Verify files closed from working set move to LRU cache (not evicted) - Expose __getWorkingSetPaths test helper for verifying working set state - 24/24 md editor integration tests passing
1 parent 28e6006 commit 63b8696

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

src-mdviewer/src/bridge.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ export function initBridge() {
116116
window.__getCacheKeys = function () {
117117
return docCache._getCacheKeysForTest();
118118
};
119+
window.__getWorkingSetPaths = function () {
120+
return docCache._getWorkingSetPathsForTest();
121+
};
119122
window.__triggerContentSync = function () {
120123
const content = document.getElementById("viewer-content");
121124
if (content) {

src-mdviewer/src/core/doc-cache.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export function _getCacheKeysForTest() {
4848
return Array.from(cache.keys());
4949
}
5050

51+
/** For test access only — returns the working set paths. */
52+
export function _getWorkingSetPathsForTest() {
53+
return Array.from(workingSetPaths);
54+
}
55+
5156
/**
5257
* Get the currently active file path.
5358
*/

test/spec/md-editor-integ-test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,47 @@ define(function (require, exports, module) {
907907
expect(keys.some(k => k.endsWith("doc2.md"))).toBeTrue();
908908
expect(keys.some(k => k.endsWith("doc3.md"))).toBeTrue();
909909
}, 15000);
910+
911+
it("should files removed from working set move to LRU cache (not evicted)", async function () {
912+
const win = _getMdIFrameWin();
913+
914+
// Open doc1 and doc2 to put them in cache and working set
915+
await _openMdFileAndWaitForPreview("doc1.md");
916+
await awaitsFor(() => _getViewerH1Text().includes("Document One"),
917+
"doc1 to load");
918+
919+
await _openMdFileAndWaitForPreview("doc2.md");
920+
await awaitsFor(() => _getViewerH1Text().includes("Document Two"),
921+
"doc2 to load");
922+
923+
// Both should be in cache and working set
924+
await awaitsFor(() => {
925+
const cacheKeys = win.__getCacheKeys();
926+
const wsPaths = win.__getWorkingSetPaths();
927+
return cacheKeys.some(k => k.endsWith("doc1.md")) &&
928+
cacheKeys.some(k => k.endsWith("doc2.md")) &&
929+
wsPaths.some(p => p.endsWith("doc1.md")) &&
930+
wsPaths.some(p => p.endsWith("doc2.md"));
931+
}, "doc1 and doc2 in cache and working set");
932+
933+
// Close doc2 from working set
934+
await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE),
935+
"close doc2");
936+
937+
// doc2 should still be in cache (moved to LRU) but not in working set
938+
await awaitsFor(() => {
939+
const cacheKeys = win.__getCacheKeys();
940+
const wsPaths = win.__getWorkingSetPaths();
941+
return cacheKeys.some(k => k.endsWith("doc2.md")) &&
942+
!wsPaths.some(p => p.endsWith("doc2.md"));
943+
}, "doc2 in cache (LRU) but not in working set");
944+
945+
// doc1 should still be in both cache and working set
946+
const cacheKeys = win.__getCacheKeys();
947+
const wsPaths = win.__getWorkingSetPaths();
948+
expect(cacheKeys.some(k => k.endsWith("doc1.md"))).toBeTrue();
949+
expect(wsPaths.some(p => p.endsWith("doc1.md"))).toBeTrue();
950+
}, 15000);
910951
});
911952

912953
});

0 commit comments

Comments
 (0)