fix: repair broken IPC wiring and cut the cost of repository polling
Three handlers referenced a dependency they were never given, which made them throw a ReferenceError as soon as they ran: - deployment:preflight for Gitea Actions profiles (`preflight` was passed to registerOperationsIpc but not to registerDeploymentIpc) - Unraid write-access repair (`safeRelativeRemoteFile` was missing from createUnraidAccessMethods) - a dead reference of the same name in unraid-state-methods no-undef and no-unused-vars were disabled for every file, which is why none of these were caught. Both are now enabled for src/main and src/shared, where the dependency graph is explicit. The renderer keeps them off because its functions are deliberately cross-script globals. Performance: - git.status() spawned three processes (rev-parse, status, remote get-url) per call. A directory holding its own .git is by definition the work tree root, so rev-parse is unnecessary, and the remote URL is cached against the mtime of .git/config, including the failure for a repository without that remote. - git status runs with --no-optional-locks so a read no longer rewrites the index. That stops it fighting a concurrent Git command for the index lock, and is what makes filesystem watching viable at all. - One commit issued four `git status` reads; callers that already hold the status now pass it on, leaving two. - The repository monitor is event driven. A watched repository is read on filesystem activity, with a 30s safety net for watchers that stop delivering and a 1s floor so a busy tree cannot drive a read per event. Repositories that cannot be watched keep using the interval. Idle cost for one repository over 35s: 24 git processes before, 3 after. - Resolving one repository by name no longer refreshes the whole workspace. - Concurrent configuration saves share a single write of the latest state. - Repository discovery follows directory junctions again. The filter that skipped them made the realpath cycle guard dead code, and hid any project folder reached through a junction. Renderer: - render() replaced the whole shell on every poll, discarding focus, caret and scroll position while the user was typing. Those are preserved now, and an unchanged render leaves the DOM alone entirely. - The four sections that enhanceRenderedUi() injected after render moved into the views, so the rendered markup is the single source of truth. - The monitor no longer keeps a repository paused forever when it is unlinked mid-mutation, scheduleAutoRefresh honours its delay argument, the demo bridges no longer block startup, and #app is no longer an aria-live region announcing the entire UI on every render. IPC channel plumbing moved to src/main/ipc/channel.cjs, replacing a module-level mutable diagnostics singleton with an argument. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
cf1da8a2fa
commit
9260d35957
@@ -215,3 +215,82 @@ test("inventory, deployment safety and failure evidence dialogs are reviewable",
|
||||
}
|
||||
await assertSurface(page);
|
||||
});
|
||||
|
||||
// A repository or deployment poll renders the whole shell again. Changing an
|
||||
// unrelated part of the state is what a poll effectively does, and it must not
|
||||
// take the caret or the scroll position away from the user.
|
||||
async function forceUnrelatedRerender(page) {
|
||||
await page.evaluate(() => {
|
||||
ui.diagnosticsStatus = { ...(ui.diagnosticsStatus || {}), enabled: !(ui.diagnosticsStatus?.enabled === false) };
|
||||
render();
|
||||
});
|
||||
}
|
||||
|
||||
test("a background refresh keeps typing and caret position intact", async ({ page }) => {
|
||||
const search = page.locator("#global-search");
|
||||
await search.click();
|
||||
await search.fill("Forge");
|
||||
// Typing schedules a debounced render. Wait for it, otherwise the caret below
|
||||
// can land on the element that render is about to replace.
|
||||
await expect.poll(() => page.evaluate(() => ui.inputRenderTimer === null)).toBe(true);
|
||||
await search.evaluate((element) => element.setSelectionRange(1, 3));
|
||||
|
||||
await forceUnrelatedRerender(page);
|
||||
|
||||
await expect(search).toBeFocused();
|
||||
expect(await search.inputValue()).toBe("Forge");
|
||||
expect(await search.evaluate((element) => [element.selectionStart, element.selectionEnd])).toEqual([1, 3]);
|
||||
});
|
||||
|
||||
test("a background refresh keeps scroll offsets intact", async ({ page }) => {
|
||||
await page.locator('.nav-button[data-action="navigate"][data-view="settings"]').click();
|
||||
const canvas = page.locator(".main-canvas");
|
||||
const scrolled = await canvas.evaluate((element) => {
|
||||
element.scrollTop = Math.min(120, Math.max(0, element.scrollHeight - element.clientHeight));
|
||||
return element.scrollTop;
|
||||
});
|
||||
expect(scrolled).toBeGreaterThan(0);
|
||||
|
||||
await forceUnrelatedRerender(page);
|
||||
|
||||
expect(await canvas.evaluate((element) => element.scrollTop)).toBe(scrolled);
|
||||
});
|
||||
|
||||
test("sections that used to be injected after render are part of the rendered markup", async ({ page }) => {
|
||||
await page.locator('.nav-button[data-action="navigate"][data-view="diagnostics"]').click();
|
||||
const auditPanel = page.locator(".diagnostics-page .section-block", { hasText: "Operational audit log" });
|
||||
await expect(auditPanel).toBeVisible();
|
||||
await expect(auditPanel).toContainText("Load the operational audit log");
|
||||
|
||||
// The audit rows are state the shell renders itself now, so a plain render has
|
||||
// to pick them up without any post-render injection step.
|
||||
await page.evaluate(() => {
|
||||
ui.auditEvents = [{ timestamp: new Date().toISOString(), event: "deployment.requested", details: { repository: "Jens/Probe", result: "queued" } }];
|
||||
render();
|
||||
});
|
||||
await expect(auditPanel.locator("table.data-table")).toContainText("Jens/Probe");
|
||||
await expect(auditPanel.locator("table.data-table")).toContainText("deployment.requested");
|
||||
});
|
||||
|
||||
test("an unchanged render leaves the existing DOM in place", async ({ page }) => {
|
||||
await page.locator('[data-action="select-repo"]').first().click();
|
||||
const marked = await page.evaluate(() => {
|
||||
// Relative timestamps ("just now" turning into "1m ago") and pending async
|
||||
// state legitimately change the markup between two renders that are seconds
|
||||
// apart. Rendering twice inside one synchronous block removes that window,
|
||||
// so the second render can only be skipped because nothing changed.
|
||||
render();
|
||||
document.querySelector(".repo-list").dataset.renderProbe = "kept";
|
||||
render();
|
||||
return document.querySelector(".repo-list")?.dataset.renderProbe || null;
|
||||
});
|
||||
expect(marked).toBe("kept");
|
||||
|
||||
const replaced = await page.evaluate(() => {
|
||||
document.querySelector(".repo-list").dataset.renderProbe = "kept";
|
||||
ui.repoSearch = `probe-${Date.now()}`;
|
||||
render();
|
||||
return document.querySelector(".repo-list")?.dataset.renderProbe || null;
|
||||
});
|
||||
expect(replaced).toBe(null);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user