fix(ui): serialize agent file tab selection (#105366)

This commit is contained in:
Peter Steinberger
2026-07-12 13:46:35 +01:00
committed by GitHub
parent 9d042e252c
commit aa840f0f5c
2 changed files with 47 additions and 0 deletions
@@ -505,11 +505,14 @@ export function renderAgentFiles(params: {
${files.map((file) => {
const isActive = active === file.name;
const label = file.name.replace(/\.md$/i, "");
// File reads are serialized; changing the active tab mid-read would
// expose an editor whose content request was never accepted.
return html`
<button
class="agent-tab ${isActive ? "active" : ""} ${file.missing
? "agent-tab--missing"
: ""}"
?disabled=${params.agentFilesLoading}
@click=${() => params.onSelectFile(file.name)}
>
${label}${file.missing
+44
View File
@@ -437,6 +437,50 @@ describe("renderAgents", () => {
});
describe("renderAgentFiles", () => {
it("does not accept another file selection while a file request is loading", () => {
const container = document.createElement("div");
const onSelectFile = vi.fn();
render(
renderAgentFiles({
agentId: "alpha",
agentFilesList: {
agentId: "alpha",
workspace: "/tmp/workspace",
files: [
{
name: "AGENTS.md",
path: "/tmp/workspace/AGENTS.md",
missing: false,
},
{
name: "HEARTBEAT.md",
path: "/tmp/workspace/HEARTBEAT.md",
missing: false,
},
],
},
agentFilesLoading: true,
agentFilesError: null,
agentFileActive: "AGENTS.md",
agentFileContents: { "AGENTS.md": "# Instructions" },
agentFileDrafts: { "AGENTS.md": "# Instructions" },
agentFileSaving: false,
onLoadFiles: () => undefined,
onSelectFile,
onFileDraftChange: () => undefined,
onFileReset: () => undefined,
onFileSave: () => undefined,
}),
container,
);
const heartbeatTab = expectAgentTab(container, "HEARTBEAT");
expect(heartbeatTab.disabled).toBe(true);
heartbeatTab.click();
expect(onSelectFile).not.toHaveBeenCalled();
});
it("renders the upgraded markdown preview structure with file metadata", () => {
const container = document.createElement("div");