test(ai): collecter toutes les requetes pour eviter la course avec l'hydratation d'historique
This commit is contained in:
+16
-10
@@ -1371,10 +1371,15 @@ async function main() {
|
||||
stateMod.state.allVaults = [];
|
||||
stateMod.state.selectedContextVault = null;
|
||||
stateMod.state.currentVault = null;
|
||||
let lastUrl = "";
|
||||
// Collect every request: `new BooksLM()` also hydrates the AI history
|
||||
// asynchronously, so the *last* URL is not necessarily the tree-search one.
|
||||
const urls = [];
|
||||
const sawTreeSearchAll = () => urls.some(
|
||||
(u) => u.includes("/api/tree-search") && u.includes("vault=all"),
|
||||
);
|
||||
globalThis.fetch = async (url) => {
|
||||
lastUrl = String(url);
|
||||
if (lastUrl.includes("/api/tree-search")) {
|
||||
urls.push(String(url));
|
||||
if (String(url).includes("/api/tree-search")) {
|
||||
return {
|
||||
ok: true, status: 200,
|
||||
json: async () => ({ results: [{ path: "Café/note.md", type: "file" }] }),
|
||||
@@ -1392,13 +1397,13 @@ async function main() {
|
||||
b._onComposerInput();
|
||||
const menu = b._panel.querySelector(".bookslm-mention-menu");
|
||||
let waited = 0;
|
||||
while (!lastUrl.includes("tree-search") && waited < 500) {
|
||||
while (!sawTreeSearchAll() && waited < 500) {
|
||||
await sleep(20);
|
||||
waited += 20;
|
||||
}
|
||||
assert.ok(!menu.classList.contains("hidden"), "accented mention keeps the menu open");
|
||||
assert.ok(lastUrl.includes("vault=all"),
|
||||
`no vault -> searches all vaults (got last fetch "${lastUrl}")`);
|
||||
assert.ok(sawTreeSearchAll(),
|
||||
`no vault -> searches all vaults (got ${JSON.stringify(urls)})`);
|
||||
assert.equal(menu.querySelectorAll(".bookslm-menu-item").length, 1);
|
||||
b._panel.remove();
|
||||
localStorage.clear();
|
||||
@@ -1687,10 +1692,10 @@ async function main() {
|
||||
const stateMod = await import(pathToFileURL(path.join(JS_DIR, "state.js")).href);
|
||||
const prev = stateMod.state.allVaults;
|
||||
stateMod.state.allVaults = [{ name: "FallbackVault" }];
|
||||
let lastUrl = "";
|
||||
const urls = [];
|
||||
globalThis.fetch = async (url) => {
|
||||
lastUrl = String(url);
|
||||
if (lastUrl.includes("/files")) {
|
||||
urls.push(String(url));
|
||||
if (String(url).includes("/files")) {
|
||||
return { ok: true, status: 200, json: async () => ({ files: [{ path: "a.md" }] }) };
|
||||
}
|
||||
return { ok: true, status: 200, json: async () => ({}) };
|
||||
@@ -1703,7 +1708,8 @@ async function main() {
|
||||
await b._showMentionMenu("");
|
||||
const menu = b._panel.querySelector(".bookslm-mention-menu");
|
||||
assert.ok(!menu.classList.contains("hidden"), "empty-query menu is shown");
|
||||
assert.ok(lastUrl.includes("FallbackVault"), "uses the fallback vault");
|
||||
assert.ok(urls.some((u) => u.includes("/files") && u.includes("FallbackVault")),
|
||||
`uses the fallback vault (got ${JSON.stringify(urls)})`);
|
||||
stateMod.state.allVaults = prev;
|
||||
b._panel.remove();
|
||||
localStorage.clear();
|
||||
|
||||
Reference in New Issue
Block a user