Skip to content

修复 env 写回模式回退 & 收紧 CONTENT_FILTER 裁剪#175

Closed
CJackHwang wants to merge 1 commit intodevfrom
codex/fix-fallback-to-file-config-on-json-parse-failure
Closed

修复 env 写回模式回退 & 收紧 CONTENT_FILTER 裁剪#175
CJackHwang wants to merge 1 commit intodevfrom
codex/fix-fallback-to-file-config-on-json-parse-failure

Conversation

@CJackHwang
Copy link
Copy Markdown
Owner

Motivation

  • 修复 loadConfig 在写回(env writeback)模式下的早退问题:当环境变量 DS2API_CONFIG_JSON/CONFIG_JSON 存在但解析失败时,应回退到磁盘上的持久化配置以维持 file-backed 行为,避免重启后丢失 keys/accounts。
  • 避免对任意包含 CONTENT_FILTER 的文本无差别截断,只有确认为上游泄漏签名时才裁剪,以免破坏正常可见内容(例如对审查机制的说明)。

Description

  • loadConfig 中,当 DS2API_CONFIG_JSON/CONFIG_JSON 无法解析时增加逻辑:若非 Vercel 且允许写回,则尝试读取 ConfigPath() 指向的持久化文件并在可解析时返回该文件配置(并将 fromEnv=false)。
  • internal/sse/content_filter_leak.go 中收紧裁剪逻辑:搜索到 CONTENT_FILTER 后仅在其后缀匹配已知泄漏签名(例如中文“你好,这个问题我暂时无法回答”之类前缀)时才从文本中去除该后缀,否则保留原文。
  • 新增/更新回归测试:TestEnvBackedStoreWritebackFallsBackToPersistedFileWhenEnvMalformed 覆盖 env JSON 畸形但磁盘配置可用的回退场景,以及 TestParseDeepSeekContentLineKeepsLegitContentFilterMentions 验证合法提及 CONTENT_FILTER 不被误截断。
  • 修改的文件:internal/config/store.gointernal/config/config_test.gointernal/sse/content_filter_leak.gointernal/sse/line_test.go

Testing

  • 运行了 go test ./internal/config ./internal/sse,两组测试均通过。
  • 新增的单元测试 TestEnvBackedStoreWritebackFallsBackToPersistedFileWhenEnvMalformedTestParseDeepSeekContentLineKeepsLegitContentFilterMentions 已在本地测试套件中通过。

Codex Task

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ds2api Ready Ready Preview, Comment Mar 30, 2026 5:21pm

@CJackHwang CJackHwang closed this Mar 30, 2026
@CJackHwang CJackHwang deleted the codex/fix-fallback-to-file-config-on-json-parse-failure branch March 30, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant