fix(coding-agent): show resources before messages when resuming session

This commit is contained in:
haoqixu
2026-06-24 20:12:56 +08:00
parent a2e3e9d8b2
commit c5440162b8
3 changed files with 134 additions and 33 deletions
@@ -119,11 +119,13 @@ describe("InteractiveMode.showStatus", () => {
describe("InteractiveMode.setToolsExpanded", () => {
test("applies expansion state to the active header and chat entries", () => {
const header = { setExpanded: vi.fn() };
const loadedResourcesChild = { setExpanded: vi.fn() };
const chatChild = { setExpanded: vi.fn() };
const fakeThis: any = {
toolOutputExpanded: false,
customHeader: undefined,
builtInHeader: header,
loadedResourcesContainer: { children: [loadedResourcesChild] },
chatContainer: { children: [chatChild] },
ui: { requestRender: vi.fn() },
};
@@ -132,6 +134,7 @@ describe("InteractiveMode.setToolsExpanded", () => {
expect(fakeThis.toolOutputExpanded).toBe(true);
expect(header.setExpanded).toHaveBeenCalledWith(true);
expect(loadedResourcesChild.setExpanded).toHaveBeenCalledWith(true);
expect(chatChild.setExpanded).toHaveBeenCalledWith(true);
expect(fakeThis.ui.requestRender).toHaveBeenCalledTimes(1);
});
@@ -441,6 +444,7 @@ describe("InteractiveMode.showLoadedResources", () => {
const fakeThis: any = {
options: { verbose: options.verbose ?? false },
toolOutputExpanded: options.toolOutputExpanded ?? false,
loadedResourcesContainer: new Container(),
chatContainer: new Container(),
settingsManager: {
getQuietStartup: () => options.quietStartup,
@@ -619,7 +623,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
const output = renderAll(fakeThis.chatContainer);
const output = renderAll(fakeThis.loadedResourcesContainer);
expect(output).toContain("[Skills]");
expect(output).toContain("commit");
expect(output).not.toContain("resource-list");
@@ -636,7 +640,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
const output = renderAll(fakeThis.chatContainer);
const output = renderAll(fakeThis.loadedResourcesContainer);
expect(output).toContain("[Skills]");
expect(output).toContain("resource-list");
expect(output).not.toContain("commit");
@@ -654,7 +658,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
const output = renderAll(fakeThis.chatContainer);
const output = renderAll(fakeThis.loadedResourcesContainer);
expect(output).toContain("[Skills]");
expect(output).toContain("resource-list");
expect(output).not.toContain("commit");
@@ -670,7 +674,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
const output = renderAll(fakeThis.chatContainer);
const output = renderAll(fakeThis.loadedResourcesContainer);
expect(output).toContain("[Extensions]");
expect(output).toContain("answer.ts, btw.ts");
expect(output).not.toContain("extensions/answer.ts");
@@ -687,7 +691,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
@scope/pi-scoped, answer.ts, cli-extension.ts, HazAT/pi-interactive-subagents, HazAT/pi-interactive-subagents:subagents, local-index, pi-markdown-preview, user-index"`);
});
@@ -733,7 +737,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
alpha/one, beta/one, gamma/one"`);
});
@@ -761,7 +765,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
plan-mode"`);
});
@@ -789,7 +793,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
plan-mode"`);
});
@@ -826,7 +830,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
plan-mode, webfetch.ts"`);
});
@@ -863,7 +867,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
bar, foo"`);
});
@@ -900,7 +904,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
alpha/tools, beta/tools"`);
});
@@ -928,7 +932,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
main.ts"`);
});
@@ -956,7 +960,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
pi-markdown-preview"`);
});
@@ -972,7 +976,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
expect(normalizeRenderedOutput(fakeThis.chatContainer)).toMatchInlineSnapshot(`
expect(normalizeRenderedOutput(fakeThis.loadedResourcesContainer)).toMatchInlineSnapshot(`
"[Extensions]
project
/tmp/project/.pi/extensions/answer.ts
@@ -1003,7 +1007,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
const output = renderAll(fakeThis.chatContainer).replace(/\\/g, "/");
const output = renderAll(fakeThis.loadedResourcesContainer).replace(/\\/g, "/");
expect(output).toContain("[Context]");
expect(output).toContain("~/.pi/agent/AGENTS.md, AGENTS.md");
expect(output).not.toContain(`${cwd.replace(/\\/g, "/")}/AGENTS.md`);
@@ -1023,7 +1027,7 @@ describe("InteractiveMode.showLoadedResources", () => {
force: false,
});
const output = renderAll(fakeThis.chatContainer).replace(/\\/g, "/");
const output = renderAll(fakeThis.loadedResourcesContainer).replace(/\\/g, "/");
expect(output).toContain("[Context]");
expect(output).toContain("~/.pi/agent/AGENTS.md");
expect(output).toContain("~/Development/pi-mono/AGENTS.md");
@@ -1042,7 +1046,7 @@ describe("InteractiveMode.showLoadedResources", () => {
showDiagnosticsWhenQuiet: true,
});
expect(fakeThis.chatContainer.children).toHaveLength(0);
expect(fakeThis.loadedResourcesContainer.children).toHaveLength(0);
});
test("still shows diagnostics on quiet startup when requested", () => {
@@ -1057,7 +1061,7 @@ describe("InteractiveMode.showLoadedResources", () => {
showDiagnosticsWhenQuiet: true,
});
const output = renderAll(fakeThis.chatContainer);
const output = renderAll(fakeThis.loadedResourcesContainer);
expect(output).toContain("[Skill conflicts]");
expect(output).not.toContain("[Skills]");
});