惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
J
Java Code Geeks
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
IT之家
IT之家
博客园_首页
B
Blog RSS Feed
Google DeepMind News
Google DeepMind News
B
Blog
U
Unit 42
Apple Machine Learning Research
Apple Machine Learning Research
L
LangChain Blog
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog
博客园 - 聂微东
腾讯CDC
A
About on SuperTechFans

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(codex): emit app-server final chat events (#71293) · ...
steipete · 2026-04-25 · via Recent Commits to openclaw:main

@@ -9,6 +9,11 @@ import {

99

} from "openclaw/plugin-sdk/agent-harness";

1010

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";

1111

import { __testing as nativeHookRelayTesting } from "../../../../src/agents/harness/native-hook-relay.js";

12+

import {

13+

onAgentEvent,

14+

resetAgentEventsForTest,

15+

type AgentEventPayload,

16+

} from "../../../../src/infra/agent-events.js";

1217

import {

1318

initializeGlobalHookRunner,

1419

resetGlobalHookRunner,

@@ -276,12 +281,14 @@ function extractRelayIdFromThreadRequest(params: unknown): string {

276281277282

describe("runCodexAppServerAttempt", () => {

278283

beforeEach(async () => {

284+

resetAgentEventsForTest();

279285

tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-codex-run-"));

280286

});

281287282288

afterEach(async () => {

283289

__testing.resetCodexAppServerClientFactoryForTests();

284290

nativeHookRelayTesting.clearNativeHookRelaysForTests();

291+

resetAgentEventsForTest();

285292

resetGlobalHookRunner();

286293

vi.restoreAllMocks();

287294

await fs.rm(tempDir, { recursive: true, force: true });

@@ -341,6 +348,9 @@ describe("runCodexAppServerAttempt", () => {

341348

const llmInput = vi.fn();

342349

const llmOutput = vi.fn();

343350

const agentEnd = vi.fn();

351+

const onRunAgentEvent = vi.fn();

352+

const globalAgentEvents: AgentEventPayload[] = [];

353+

onAgentEvent((event) => globalAgentEvents.push(event));

344354

initializeGlobalHookRunner(

345355

createMockPluginRegistry([

346356

{ hookName: "llm_input", handler: llmInput },

@@ -354,7 +364,9 @@ describe("runCodexAppServerAttempt", () => {

354364

sessionManager.appendMessage(assistantMessage("existing context", Date.now()));

355365

const harness = createStartedThreadHarness();

356366357-

const run = runCodexAppServerAttempt(createParams(sessionFile, workspaceDir));

367+

const params = createParams(sessionFile, workspaceDir);

368+

params.onAgentEvent = onRunAgentEvent;

369+

const run = runCodexAppServerAttempt(params);

358370

await harness.waitForMethod("turn/start");

359371

await vi.waitFor(() => expect(llmInput).toHaveBeenCalledTimes(1), { interval: 1 });

360372

@@ -391,6 +403,56 @@ describe("runCodexAppServerAttempt", () => {

391403

expect(result.assistantTexts).toEqual(["hello back"]);

392404

await vi.waitFor(() => expect(llmOutput).toHaveBeenCalledTimes(1), { interval: 1 });

393405

await vi.waitFor(() => expect(agentEnd).toHaveBeenCalledTimes(1), { interval: 1 });

406+

const agentEvents = onRunAgentEvent.mock.calls.map(([event]) => event);

407+

expect(agentEvents).toEqual(

408+

expect.arrayContaining([

409+

{

410+

stream: "lifecycle",

411+

data: expect.objectContaining({

412+

phase: "start",

413+

startedAt: expect.any(Number),

414+

}),

415+

},

416+

{

417+

stream: "assistant",

418+

data: { text: "hello back" },

419+

},

420+

{

421+

stream: "lifecycle",

422+

data: expect.objectContaining({

423+

phase: "end",

424+

startedAt: expect.any(Number),

425+

endedAt: expect.any(Number),

426+

}),

427+

},

428+

]),

429+

);

430+

const startIndex = agentEvents.findIndex(

431+

(event) => event.stream === "lifecycle" && event.data.phase === "start",

432+

);

433+

const assistantIndex = agentEvents.findIndex((event) => event.stream === "assistant");

434+

const endIndex = agentEvents.findIndex(

435+

(event) => event.stream === "lifecycle" && event.data.phase === "end",

436+

);

437+

expect(startIndex).toBeGreaterThanOrEqual(0);

438+

expect(assistantIndex).toBeGreaterThan(startIndex);

439+

expect(endIndex).toBeGreaterThan(assistantIndex);

440+

expect(globalAgentEvents).toEqual(

441+

expect.arrayContaining([

442+

expect.objectContaining({

443+

runId: "run-1",

444+

sessionKey: "agent:main:session-1",

445+

stream: "assistant",

446+

data: { text: "hello back" },

447+

}),

448+

expect.objectContaining({

449+

runId: "run-1",

450+

sessionKey: "agent:main:session-1",

451+

stream: "lifecycle",

452+

data: expect.objectContaining({ phase: "end" }),

453+

}),

454+

]),

455+

);

394456395457

expect(llmOutput).toHaveBeenCalledWith(

396458

expect.objectContaining({

@@ -530,14 +592,17 @@ describe("runCodexAppServerAttempt", () => {

530592531593

it("fires agent_end with failure metadata when the codex turn fails", async () => {

532594

const agentEnd = vi.fn();

595+

const onRunAgentEvent = vi.fn();

533596

initializeGlobalHookRunner(

534597

createMockPluginRegistry([{ hookName: "agent_end", handler: agentEnd }]),

535598

);

536599

const sessionFile = path.join(tempDir, "session.jsonl");

537600

const workspaceDir = path.join(tempDir, "workspace");

538601

const harness = createStartedThreadHarness();

539602540-

const run = runCodexAppServerAttempt(createParams(sessionFile, workspaceDir));

603+

const params = createParams(sessionFile, workspaceDir);

604+

params.onAgentEvent = onRunAgentEvent;

605+

const run = runCodexAppServerAttempt(params);

541606

await harness.waitForMethod("turn/start");

542607

await harness.notify({

543608

method: "turn/completed",

@@ -556,6 +621,25 @@ describe("runCodexAppServerAttempt", () => {

556621557622

expect(result.promptError).toBe("codex exploded");

558623

await vi.waitFor(() => expect(agentEnd).toHaveBeenCalledTimes(1), { interval: 1 });

624+

const agentEvents = onRunAgentEvent.mock.calls.map(([event]) => event);

625+

expect(agentEvents).toEqual(

626+

expect.arrayContaining([

627+

{

628+

stream: "lifecycle",

629+

data: expect.objectContaining({ phase: "start", startedAt: expect.any(Number) }),

630+

},

631+

{

632+

stream: "lifecycle",

633+

data: expect.objectContaining({

634+

phase: "error",

635+

startedAt: expect.any(Number),

636+

endedAt: expect.any(Number),

637+

error: "codex exploded",

638+

}),

639+

},

640+

]),

641+

);

642+

expect(agentEvents.some((event) => event.stream === "assistant")).toBe(false);

559643

expect(agentEnd).toHaveBeenCalledWith(

560644

expect.objectContaining({

561645

success: false,