Skip to content

[Bug] OpenAI 兼容性测试失败 - JSON 解析错误 #54

@best

Description

@best

问题描述

在 中, 测试失败:

错误详情

  • 文件:
  • 错误:
  • 原因: 返回的内容包含 markdown 格式的代码块(json ... ),而不是纯 JSON

复现步骤

  1. 运行测试:

@openlinkos/monorepo@0.1.0 test /data/code/github.com/openlinkos/agent
vitest run

RUN v1.6.1 /data/code/github.com/openlinkos/agent

✓ packages/ai/tests/server.test.ts (19 tests) 61ms
✓ packages/ai/tests/errors.test.ts (58 tests) 19ms
✓ packages/agent/tests/tool-compose.test.ts (34 tests) 19ms
✓ packages/ai/tests/stream-utils.test.ts (28 tests) 20ms
✓ packages/ai/tests/rate-limiter.test.ts (28 tests) 22ms
✓ packages/ai/tests/provider-errors.test.ts (37 tests) 19ms
✓ packages/team/tests/supervisor.test.ts (11 tests) 14ms
✓ packages/ai/tests/abort.test.ts (15 tests) 86ms
✓ packages/agent/tests/builtin-middleware.test.ts (19 tests) 19ms
✓ packages/agent/tests/middleware.test.ts (21 tests) 21ms
✓ packages/agent/tests/tracer.test.ts (14 tests) 23ms
✓ packages/agent/tests/agent.test.ts (20 tests) 26ms
✓ packages/agent/tests/plugin.test.ts (15 tests) 30ms
✓ packages/subagent/tests/subagent.test.ts (15 tests) 229ms
✓ packages/agent/tests/errors.test.ts (10 tests) 12ms
✓ packages/ai/tests/strip-think-tags.test.ts (20 tests) 31ms
✓ packages/team/tests/team.test.ts (19 tests) 48ms
✓ packages/eval/tests/eval.test.ts (55 tests) 375ms
✓ packages/agent/tests/workflow.test.ts (16 tests) 40ms
✓ packages/ai/tests/deepseek-qwen.test.ts (20 tests) 61ms
✓ packages/team/tests/parallel.test.ts (15 tests) 148ms
✓ channels/channel-slack/tests/slack.test.ts (13 tests) 258ms
✓ packages/ai/tests/structured.test.ts (17 tests) 15ms
✓ packages/agent/tests/context-window.test.ts (17 tests) 13ms
✓ packages/mcp/tests/client.test.ts (14 tests) 13ms
✓ packages/agent/tests/presets.test.ts (23 tests) 16ms
✓ packages/agent/tests/integration/tools-guardrails.test.ts (5 tests) 11ms
✓ packages/agent/tests/conversation.test.ts (11 tests) 25ms
✓ packages/agent/tests/tools.test.ts (21 tests) 66ms
✓ packages/ai/tests/retry.test.ts (17 tests) 46ms
✓ packages/team/tests/communication.test.ts (20 tests) 14ms
✓ packages/team/tests/sequential.test.ts (8 tests) 20ms
✓ channels/channel-discord/tests/discord.test.ts (12 tests) 135ms
✓ packages/team/tests/debate.test.ts (9 tests) 14ms
✓ packages/ai/tests/integration/model-generate.test.ts (5 tests) 130ms
✓ packages/agent/tests/exporter.test.ts (10 tests) 34ms
✓ plugins/plugin-memory/tests/persistent.test.ts (17 tests) 40ms
✓ packages/channel/tests/channel-manager.test.ts (15 tests) 19ms
✓ plugins/plugin-memory/tests/vector.test.ts (19 tests) 15ms
✓ packages/agent/tests/guardrails.test.ts (18 tests) 36ms
✓ packages/agent/tests/persistence.test.ts (17 tests) 34ms
✓ packages/agent/tests/session.test.ts (12 tests) 15ms
✓ packages/ai/tests/integration/provider-fallback.test.ts (4 tests) 86ms
✓ packages/agent/tests/agent-tool.test.ts (8 tests) 11ms
✓ packages/ai/tests/ollama.test.ts (10 tests) 23ms
✓ packages/mcp/tests/bridge.test.ts (8 tests) 15ms
✓ channels/channel-telegram/tests/telegram.test.ts (11 tests) 281ms
✓ packages/ai/tests/types.test.ts (11 tests) 23ms
✓ packages/agent/tests/integration/subagent-delegation.test.ts (5 tests) 118ms
✓ packages/ai/tests/stream.test.ts (12 tests) 12ms
✓ packages/subagent/tests/progress.test.ts (9 tests) 12ms
✓ packages/channel/tests/base-channel.test.ts (13 tests) 30ms
✓ packages/ai/tests/provider-registry.test.ts (12 tests) 39ms
✓ packages/cli/tests/output.test.ts (11 tests) 12ms
✓ plugins/plugin-memory/tests/plugin.test.ts (8 tests) 42ms
✓ packages/cli/tests/display.test.ts (15 tests) 15ms
✓ packages/agent/tests/integration/team-coordination.test.ts (5 tests) 25ms
✓ packages/agent/tests/integration/agent-ai.test.ts (2 tests) 82ms
✓ packages/agent/tests/abort.test.ts (5 tests) 12ms
✓ packages/cli/tests/config.test.ts (10 tests) 34ms
✓ packages/ai/tests/integration/streaming.test.ts (3 tests) 206ms
✓ packages/channel-web/tests/web.test.ts (9 tests) 135ms
✓ packages/cli/tests/team.test.ts (5 tests) 12ms
✓ packages/cli/tests/run.test.ts (6 tests) 22ms
✓ plugins/plugin-memory/tests/conversation.test.ts (9 tests) 9ms
✓ packages/cli/tests/loader.test.ts (15 tests) 7ms
stdout | packages/cli/tests/init.test.ts > initCommand > should create all scaffold files in an empty directory
ℹ create agent.config.ts
ℹ create .env
ℹ create .gitignore
ℹ create package.json

✔ Project scaffolded! 4 files created, 0 skipped.

ℹ Next steps:

  1. cd /tmp/cli-init-test-rphqPm/my-project
  2. Edit .env with your API keys
  3. Edit agent.config.ts to customize your agent
  4. Run openlinkos run agent.config.ts to start

stdout | packages/cli/tests/init.test.ts > initCommand > should not overwrite existing files
ℹ create agent.config.ts
ℹ create .env
ℹ create .gitignore
ℹ create package.json

✔ Project scaffolded! 4 files created, 0 skipped.

ℹ Next steps:

  1. cd /tmp/cli-init-test-oAyyC5/existing
  2. Edit .env with your API keys
  3. Edit agent.config.ts to customize your agent
  4. Run openlinkos run agent.config.ts to start

ℹ skip agent.config.ts (already exists)
ℹ skip .env (already exists)
ℹ skip .gitignore (already exists)
ℹ skip package.json (already exists)

✔ Project scaffolded! 0 files created, 4 skipped.

ℹ Next steps:

  1. cd /tmp/cli-init-test-oAyyC5/existing
  2. Edit .env with your API keys
  3. Edit agent.config.ts to customize your agent
  4. Run openlinkos run agent.config.ts to start

stdout | packages/cli/tests/init.test.ts > initCommand > should create agent.config.ts with correct content
ℹ create agent.config.ts
ℹ create .env
ℹ create .gitignore
ℹ create package.json

✔ Project scaffolded! 4 files created, 0 skipped.

ℹ Next steps:

  1. cd /tmp/cli-init-test-1ovpPA/check-content
  2. Edit .env with your API keys
  3. Edit agent.config.ts to customize your agent
  4. Run openlinkos run agent.config.ts to start

stdout | packages/cli/tests/init.test.ts > initCommand > should create .env with API key placeholders
ℹ create agent.config.ts
ℹ create .env
ℹ create .gitignore
ℹ create package.json

✔ Project scaffolded! 4 files created, 0 skipped.

ℹ Next steps:

  1. cd /tmp/cli-init-test-R7GX9K/env-test
  2. Edit .env with your API keys
  3. Edit agent.config.ts to customize your agent
  4. Run openlinkos run agent.config.ts to start

stdout | packages/cli/tests/init.test.ts > initCommand > should work with explicit directory set to '.'
ℹ create agent.config.ts
ℹ create .env
ℹ create .gitignore
ℹ create package.json

✔ Project scaffolded! 4 files created, 0 skipped.

ℹ Next steps:

  1. cd /tmp/cli-init-test-5Wg4QQ/dot-test
  2. Edit .env with your API keys
  3. Edit agent.config.ts to customize your agent
  4. Run openlinkos run agent.config.ts to start

✓ packages/cli/tests/init.test.ts (5 tests) 23ms
↓ packages/ai/tests/e2e/anthropic-compat.e2e.test.ts (3 tests | 3 skipped)
✓ packages/cli/tests/cli.test.ts (9 tests) 11ms
✓ packages/cli/tests/chat.test.ts (2 tests) 30ms
✓ packages/channel-terminal/tests/terminal.test.ts (7 tests) 233ms
✓ packages/agent/tests/e2e/react-loop.e2e.test.ts (1 test) 1919ms
❯ packages/ai/tests/e2e/openai-compat.e2e.test.ts (4 tests | 1 failed) 3186ms
❯ packages/ai/tests/e2e/openai-compat.e2e.test.ts > OpenAI-compatible adapter E2E > structured output via responseFormat
→ Unexpected token '`', "```json
{
"... is not valid JSON
✓ packages/agent/tests/e2e/tool-calling.e2e.test.ts (2 tests) 4996ms

Test Files 1 failed | 72 passed | 1 skipped (74)
Tests 1 failed | 1024 passed | 3 skipped (1028)
Start at 09:25:51
Duration 8.19s (transform 6.36s, setup 19ms, collect 13.81s, tests 13.95s, environment 22ms, prepare 12.15s)

 ELIFECYCLE  Test failed. See above for more details.
2. 查看 的 structured output 测试

优先级

  • high: 影响核心 AI 功能测试
  • 标签: bug, priority:high, package:ai, package:agent

期望结果

修复 OpenAI 兼容性适配器,确保 responseFormat 返回纯 JSON,而不是 markdown 格式代码块

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions