refactor: remove debug logging and simplify event identifier extraction
This commit is contained in:
@@ -3,7 +3,7 @@ import type { Logger } from "pino";
|
||||
|
||||
import { createTestLogger } from "../../../test-utils/test-logger.js";
|
||||
import { AgentManager } from "../agent-manager.js";
|
||||
import { ClaudeAgentClient } from "./claude-agent.js";
|
||||
import { ClaudeAgentClient, readEventIdentifiers } from "./claude-agent.js";
|
||||
import type { AgentStreamEvent, AgentTimelineItem } from "../agent-sdk-types.js";
|
||||
|
||||
const sdkMocks = vi.hoisted(() => ({
|
||||
@@ -325,13 +325,7 @@ describe("ClaudeAgentSession redesign invariants", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("extracts identifiers from fixture-driven protocol shape variants", async () => {
|
||||
const spy = createSpyLogger();
|
||||
const session = await createSessionWithLogger(spy.logger);
|
||||
const internal = session as unknown as {
|
||||
routeSdkMessageFromPump: (message: Record<string, unknown>) => void;
|
||||
};
|
||||
|
||||
test("extracts identifiers from fixture-driven protocol shape variants", () => {
|
||||
const fixtures = [
|
||||
{
|
||||
name: "root identifiers take priority over nested variants",
|
||||
@@ -406,23 +400,12 @@ describe("ClaudeAgentSession redesign invariants", () => {
|
||||
},
|
||||
] as const;
|
||||
|
||||
try {
|
||||
for (const fixture of fixtures) {
|
||||
spy.debug.mockClear();
|
||||
internal.routeSdkMessageFromPump(
|
||||
fixture.message as unknown as Record<string, unknown>
|
||||
);
|
||||
const routingCall = spy.debug.mock.calls.find(
|
||||
(args) => args[1] === "Claude query pump routing decision"
|
||||
);
|
||||
expect(routingCall).toBeDefined();
|
||||
const payload = routingCall?.[0] as
|
||||
| { identifiers?: Record<string, string | null> }
|
||||
| undefined;
|
||||
expect(payload?.identifiers).toEqual(fixture.expected);
|
||||
}
|
||||
} finally {
|
||||
await session.close();
|
||||
for (const fixture of fixtures) {
|
||||
expect(
|
||||
readEventIdentifiers(
|
||||
fixture.message as unknown as Parameters<typeof readEventIdentifiers>[0]
|
||||
)
|
||||
).toEqual(fixture.expected);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1280,7 +1280,7 @@ function isMetadataOnlySdkMessage(message: SDKMessage): boolean {
|
||||
return isTaskNotificationUserContent(message.message?.content);
|
||||
}
|
||||
|
||||
function readEventIdentifiers(message: SDKMessage): EventIdentifiers {
|
||||
export function readEventIdentifiers(message: SDKMessage): EventIdentifiers {
|
||||
const root = message as unknown as Record<string, unknown>;
|
||||
const messageType = readTrimmedString(root.type);
|
||||
const streamEvent = root.event as Record<string, unknown> | undefined;
|
||||
@@ -2445,10 +2445,6 @@ class ClaudeAgentSession implements AgentSession {
|
||||
}
|
||||
|
||||
private emitRunEvent(run: RunRecord, event: AgentStreamEvent): void {
|
||||
this.logger.debug(
|
||||
{ runId: run.id, owner: run.owner, eventType: event.type },
|
||||
"Claude run event dispatch"
|
||||
);
|
||||
if (run.owner === "foreground" && run.queue) {
|
||||
run.queue.push(event);
|
||||
if (
|
||||
@@ -2480,12 +2476,6 @@ class ClaudeAgentSession implements AgentSession {
|
||||
this.preReplayMetadataSeen = false;
|
||||
}
|
||||
this.transitionTurnStateFromActiveRuns(`run ${run.id} terminal`);
|
||||
this.logDerivedSessionLifecycle("terminal_event");
|
||||
}
|
||||
|
||||
private logDerivedSessionLifecycle(context: string): void {
|
||||
const lifecycle = this.runTracker.deriveLifecycle(this.pendingPermissions.size);
|
||||
this.logger.debug({ lifecycle, context }, "Claude session lifecycle derived");
|
||||
}
|
||||
|
||||
private async transitionAutonomousToForeground(): Promise<void> {
|
||||
@@ -2829,17 +2819,6 @@ class ClaudeAgentSession implements AgentSession {
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug(
|
||||
{
|
||||
routeReason: route.reason,
|
||||
runId: route.run?.id ?? null,
|
||||
turnState: this.turnState,
|
||||
metadataOnly,
|
||||
identifiers,
|
||||
},
|
||||
"Claude query pump routing decision"
|
||||
);
|
||||
|
||||
const messageEvents = this.translateMessageToEvents(message, {
|
||||
suppressAssistantText: true,
|
||||
suppressReasoning: true,
|
||||
@@ -2934,17 +2913,13 @@ class ClaudeAgentSession implements AgentSession {
|
||||
message.type === "tool_progress"
|
||||
) {
|
||||
this.runTracker.transition(run, "streaming");
|
||||
this.logDerivedSessionLifecycle("streaming_event");
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "result") {
|
||||
this.runTracker.transition(run, "finalizing");
|
||||
this.logDerivedSessionLifecycle("result_event");
|
||||
return;
|
||||
}
|
||||
|
||||
this.logDerivedSessionLifecycle("non_terminal_event");
|
||||
}
|
||||
|
||||
private shouldSuppressLocalReplayActivity(message: SDKMessage): boolean {
|
||||
|
||||
Reference in New Issue
Block a user