Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion packages/client-runtime/src/state/fileMetadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,54 @@ describe("file metadata", () => {
}),
);

it.effect("uses search and tree kinds without another request", () =>
it.effect("uses search and tree kinds for directories but still stats found files", () =>
Effect.gen(function* () {
const h = yield* makeHarness();
yield* h.seed("folder.ts", "directory");
expect(yield* h.read("/workspace/folder.ts")).toEqual({ kind: "directory" });
expect(h.batches).toHaveLength(0);
h.values.set("/workspace/notes.md", { kind: "file", byteLength: 2048 });
yield* h.seed("notes.md", "file");
expect(yield* h.read("/workspace/notes.md")).toEqual({ kind: "file", byteLength: 2048 });
}),
);

it.effect(
"stats listed files that replace directories or misses and reuses known file sizes",
() =>
Effect.gen(function* () {
const h = yield* makeHarness();
const threadId = ThreadId.make("listed-file-thread");
h.registry.mount(h.atoms.retainThread({ environmentId: ENVIRONMENT_ID, threadId }));
const directory = "/workspace/was-directory";
const missing = "/workspace/was-missing";
const file = "/workspace/known-file";
yield* h.seed("was-directory", "directory");
expect(yield* h.read(missing, ENVIRONMENT_ID, threadId)).toBeNull();
h.values.set(file, { kind: "file", byteLength: 100 });
yield* h.read(file, ENVIRONMENT_ID, threadId);

h.values.set(directory, { kind: "file", byteLength: 2048 });
h.values.set(missing, { kind: "file", byteLength: 4096 });
yield* h.seed("was-directory", "file");
yield* h.seed("was-missing", "file");
yield* h.seed("known-file", "file");

expect(yield* h.read(directory)).toEqual({ kind: "file", byteLength: 2048 });
h.registry.refresh(h.atom(missing, ENVIRONMENT_ID, threadId));
expect(yield* h.read(missing, ENVIRONMENT_ID, threadId)).toEqual({
kind: "file",
byteLength: 4096,
});
h.registry.refresh(h.atom(file, ENVIRONMENT_ID, threadId));
expect(yield* h.read(file, ENVIRONMENT_ID, threadId)).toEqual({
kind: "file",
byteLength: 100,
});
expect(h.batches.flat()).toEqual([missing, file, directory, missing]);
}),
);

it.effect("splits large mounts into bounded batches and caches misses", () =>
Effect.gen(function* () {
const h = yield* makeHarness();
Expand Down
19 changes: 16 additions & 3 deletions packages/client-runtime/src/state/fileMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,22 @@ export function createFileMetadataAtoms<R, E>(
if (isCurrent && !isCurrent(session.value)) return;
for (const entry of entries) {
const path = resolveWorkspaceFilePath(entry.path, cwd);
const previous = knownEntry(session.value, path, now);
if (previous?.value?.kind === entry.kind) continue;
remember(session.value, path, { kind: entry.kind }, now, true);
if (entry.kind === "directory") {
if (knownEntry(session.value, path, now)?.value?.kind !== "directory")
remember(session.value, path, { kind: "directory" }, now, true);
continue;
}

// A file listing can invalidate the cached kind but only a stat supplies full metadata.
const key = normalizeProjectPathForComparison(path);
const cached = cache.get(session.value);
if (cached?.get(key)?.value?.kind === "file") continue;
cached?.delete(key);
for (const thread of retainedThreads.values()) {
const retained = thread.sessions.get(session.value);
const previous = retained?.get(key);
if (previous && previous.value?.kind !== "file") retained?.delete(key);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect } from "e2e";

import { test, WEB } from "./t3.ts";

const FILE = "quarterly-figures.md";

test(
"The file citation tooltip shows the size even after workspace search finds the file",
WEB,
async ({ t3, app, browser, screen }) => {
const project = await t3.project("demo", { [FILE]: "x".repeat(2048) });
const thread = await t3.thread({
project,
title: "Review figures",
messages: [`See :codex-file-citation{path="${FILE}" line_range_start="1"}`],
});
await t3.open(thread);

await screen.getByRole("textbox").pressSequentially(`@${FILE}`);
await screen.getByRole("option", FILE, { exact: false }).hover();
await browser.keyboard.press("Escape");
await screen.getByRole("button", /^Agent See/).tap();
await screen.getByRole("link", /^quarterly-figures\.md/).hover();

try {
await expect(
browser.locator('[data-slot="tooltip-viewport"]:has-text("quarterly-figures.md")'),
).toContainText("2 KB");
} finally {
await app.screenshot("cited-file-tooltip");
}
},
);
Loading