🐛 fix(database): 修复元数据缓存与查询安全回归 - #215
Merged
Merged
Conversation
修复元数据缓存缺失、代码生成路径重复斜杠,以及只读 SQL 对 PostgreSQL dollar-quoted literal 和 FETCH 限制的误判。\n\n通过连接级有界缓存、路径规范化和 tokenizer/limit 回归测试恢复既有契约。\n\n验证:PYTHONPATH=src pytest -q tests/unit/test_connection_manager.py tests/unit/test_database_introspection.py tests/unit/test_introspection_benchmark.py tests/unit/test_atomic_codegen_tools.py tests/unit/test_mcp_query_safety.py(88 passed);ruff check 通过。\n\nCloses #214
ZhaoXingPeng
force-pushed
the
fix/214-ci-regressions
branch
from
September 12, 2026 11:31
f6065b9 to
4dbcc7a
Compare
补充缓存键按连接和 schema 隔离的维护说明,帮助后续审查保持 DDL 失效语义。\n\n验证:pytest tests/unit 已通过。\n\nRefs #214
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue
Closes #214
背景(Situation)
main CI 暴露 17 个单元测试回归:生成器在空
packageSuffix时产生重复斜杠,ConnectionManager 没有连接级元数据缓存,公共只读 SQL 工具无法正确处理 PostgreSQL dollar-quoted literal 和 FETCH 限制。上述问题会导致生成路径错误、重复数据库 introspection,以及潜在的查询安全误判。任务(Task)
恢复 Issue #214 的验收契约:实现有界、连接隔离、可失效且返回深拷贝的元数据缓存;规范化 Java 输出路径;扩展只读 SQL tokenizer 与结果上限逻辑,并在执行前拒绝
FETCH WITH TIES。不修改 MCP 工具名称、数据库 schema 或非相关生成行为。行动(Action)
connection_manager.py:增加 256 项 LRU 元数据缓存、深拷贝读写、按连接失效,并在 DDL/关闭连接时清理。atomic_codegen_tools.py:消除包路径中的重复/。mcp_tools.py:支持$$...$$与$tag$...$tag$,拒绝未闭合 dollar quote;识别并收紧顶层FETCH FIRST/NEXT,拒绝FETCH WITH TIES。验证(Verification)
完整
pytest -q仍需真实 MySQL 环境,当前按仓库测试约定在未设置DBJAVAGENIX_TEST_DB_HOST时无法收集集成测试。实验与证据(Evidence)
回归输入覆盖 256+1 项缓存淘汰、连接级失效、DDL 后刷新、空包后缀、
$$...$$/$tag$...$tag$、未闭合 dollar quote、顶层与嵌套 FETCH 以及FETCH WITH TIES。上述针对性单元测试结果为 88 passed;失败 introspection 不写入缓存由专门测试确认。未宣称真实数据库性能提升。兼容性、风险与回滚
4dbcc7a。