* perf(app): optimize wrapped measurements and checkpoint native layout experiment Compute full grapheme geometry only for final wrap fragments. Preserve shaped-text search behavior while bounding additive wrap probes. Keep the Android background layout experiment isolated from the normal diff renderer; native renderer integration and iOS bindings remain unfinished. * perf(server): reduce cold diff generation work Keep active diff reads owned across invalidation and wait for the initial watcher inventory before cold generation. Batch patch and blob reads while preserving per-file size isolation, bounded output, and daemon responsiveness. Avoid constructing fallback tokens when full-file highlighting already covers both sides. * test(server): exercise oversized highlighted diff rejection The single-line fixture now bypasses highlighting under the long-line guard, so it no longer reaches the structured payload limit. Use short dense lines to keep testing oversized rejection and continued socket usability. * fix(server): queue fresh diffs for forced reads A forced request following a repository mutation must not reuse an older active build. Invalidate that result and coalesce waiting callers onto one subsequent build. Give the cache a named object input and completed-value type. * test(server): share deferred diff loader setup * test(server): name completed diff cache setup * refactor(server): use aliases for new diff imports * fix(server): keep shipped diff imports resolvable by Node The TypeScript build preserves path aliases without a runtime resolver. Restore relative imports for shipped code and declarations, and correct the server import guideline that prompted the regression.
174 lines
5.3 KiB
TypeScript
174 lines
5.3 KiB
TypeScript
import { test, expect, beforeEach, afterEach } from "vitest";
|
|
import { execSync } from "child_process";
|
|
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
|
import { tmpdir } from "os";
|
|
import path from "path";
|
|
import { createDaemonTestContext, type DaemonTestContext } from "../test-utils/index.js";
|
|
import type { SessionOutboundMessage } from "../messages.js";
|
|
|
|
type CheckoutDiffUpdatePayload = Extract<
|
|
SessionOutboundMessage,
|
|
{ type: "checkout_diff_update" }
|
|
>["payload"];
|
|
|
|
function tmpCwd(): string {
|
|
return mkdtempSync(path.join(tmpdir(), "daemon-e2e-checkout-diff-"));
|
|
}
|
|
|
|
function initGitRepo(cwd: string): void {
|
|
execSync("git init -b main", { cwd, stdio: "pipe" });
|
|
execSync("git config user.email 'test@test.com'", { cwd, stdio: "pipe" });
|
|
execSync("git config user.name 'Test'", { cwd, stdio: "pipe" });
|
|
}
|
|
|
|
function commitFile(cwd: string, fileName: string, content: string): void {
|
|
const filePath = path.join(cwd, fileName);
|
|
writeFileSync(filePath, content);
|
|
execSync(`git add "${fileName}"`, { cwd, stdio: "pipe" });
|
|
execSync("git -c commit.gpgsign=false commit -m 'Initial commit'", {
|
|
cwd,
|
|
stdio: "pipe",
|
|
});
|
|
}
|
|
|
|
async function waitForCheckoutDiffUpdate(
|
|
ctx: DaemonTestContext,
|
|
subscriptionId: string,
|
|
predicate: (payload: CheckoutDiffUpdatePayload) => boolean,
|
|
timeoutMs = 15000,
|
|
): Promise<CheckoutDiffUpdatePayload> {
|
|
return new Promise((resolve, reject) => {
|
|
const timeout = setTimeout(() => {
|
|
unsubscribe();
|
|
reject(new Error(`Timed out waiting for checkout_diff_update (${subscriptionId})`));
|
|
}, timeoutMs);
|
|
|
|
const unsubscribe = ctx.client.on("checkout_diff_update", (message) => {
|
|
if (message.type !== "checkout_diff_update") {
|
|
return;
|
|
}
|
|
if (message.payload.subscriptionId !== subscriptionId) {
|
|
return;
|
|
}
|
|
if (!predicate(message.payload)) {
|
|
return;
|
|
}
|
|
clearTimeout(timeout);
|
|
unsubscribe();
|
|
resolve(message.payload);
|
|
});
|
|
});
|
|
}
|
|
|
|
let ctx: DaemonTestContext;
|
|
|
|
beforeEach(async () => {
|
|
ctx = await createDaemonTestContext();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await ctx.cleanup();
|
|
}, 60000);
|
|
|
|
test("pushes file-level checkout diff updates with deterministic path order", async () => {
|
|
const cwd = tmpCwd();
|
|
|
|
try {
|
|
initGitRepo(cwd);
|
|
commitFile(cwd, "base.txt", "base\n");
|
|
|
|
const subscriptionId = "checkout-diff-e2e-subscription";
|
|
const initial = await ctx.client.subscribeCheckoutDiff(
|
|
cwd,
|
|
{ mode: "uncommitted" },
|
|
{ subscriptionId },
|
|
);
|
|
|
|
expect(initial.error).toBeNull();
|
|
expect(initial.files).toEqual([]);
|
|
|
|
writeFileSync(path.join(cwd, "zeta.txt"), "zeta\n");
|
|
writeFileSync(path.join(cwd, "alpha.txt"), "alpha\n");
|
|
|
|
const update = await waitForCheckoutDiffUpdate(ctx, subscriptionId, (payload) => {
|
|
const paths = new Set(payload.files.map((file) => file.path));
|
|
return paths.has("alpha.txt") && paths.has("zeta.txt");
|
|
});
|
|
|
|
expect(update.error).toBeNull();
|
|
expect(update.files.map((file) => file.path)).toEqual(["alpha.txt", "zeta.txt"]);
|
|
|
|
ctx.client.unsubscribeCheckoutDiff(subscriptionId);
|
|
} finally {
|
|
rmSync(cwd, { recursive: true, force: true });
|
|
}
|
|
}, 60000);
|
|
|
|
test("pushes updates when subscribed from a subdirectory and files change outside it", async () => {
|
|
const cwd = tmpCwd();
|
|
|
|
try {
|
|
initGitRepo(cwd);
|
|
commitFile(cwd, "base.txt", "base\n");
|
|
|
|
const nestedDir = path.join(cwd, "nested", "dir");
|
|
mkdirSync(nestedDir, { recursive: true });
|
|
|
|
const subscriptionId = "checkout-diff-subdir-e2e-subscription";
|
|
const initial = await ctx.client.subscribeCheckoutDiff(
|
|
nestedDir,
|
|
{ mode: "uncommitted" },
|
|
{ subscriptionId },
|
|
);
|
|
|
|
expect(initial.error).toBeNull();
|
|
expect(initial.files).toEqual([]);
|
|
|
|
writeFileSync(path.join(cwd, "outside-subdir.txt"), "changed outside\n");
|
|
|
|
const update = await waitForCheckoutDiffUpdate(ctx, subscriptionId, (payload) =>
|
|
payload.files.some((file) => file.path === "outside-subdir.txt"),
|
|
);
|
|
|
|
expect(update.error).toBeNull();
|
|
expect(update.files.some((file) => file.path === "outside-subdir.txt")).toBe(true);
|
|
|
|
ctx.client.unsubscribeCheckoutDiff(subscriptionId);
|
|
} finally {
|
|
rmSync(cwd, { recursive: true, force: true });
|
|
}
|
|
}, 60000);
|
|
|
|
test("keeps the socket usable after rejecting an oversized structured diff", async () => {
|
|
const cwd = tmpCwd();
|
|
|
|
try {
|
|
initGitRepo(cwd);
|
|
commitFile(cwd, "large-a.js", "const value = 0;\n");
|
|
commitFile(cwd, "large-b.js", "const value = 0;\n");
|
|
// Short lines stay eligible for highlighting; a giant single line is skipped
|
|
// before token expansion and cannot exercise the structured-payload limit.
|
|
const denseExpression = `const value = ${"a+".repeat(100)}a;\n`.repeat(4_000);
|
|
writeFileSync(path.join(cwd, "large-a.js"), denseExpression);
|
|
writeFileSync(path.join(cwd, "large-b.js"), denseExpression);
|
|
|
|
const initial = await ctx.client.subscribeCheckoutDiff(
|
|
cwd,
|
|
{ mode: "uncommitted" },
|
|
{ subscriptionId: "oversized-checkout-diff" },
|
|
);
|
|
|
|
expect(initial).toMatchObject({
|
|
cwd,
|
|
files: [],
|
|
diffTooLarge: true,
|
|
error: { code: "UNKNOWN" },
|
|
});
|
|
|
|
const status = await ctx.client.getCheckoutStatus(cwd);
|
|
expect(status).toMatchObject({ cwd, isGit: true });
|
|
} finally {
|
|
rmSync(cwd, { recursive: true, force: true });
|
|
}
|
|
}, 120000);
|