Repository navigation
Conversation
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.
Motivation
stat()然后再读取文件会导致响应头(如Content-Length/ETag)与实际发送的主体不一致,从而让客户端挂起或误解析后续响应。Description
server.py中的静态文件处理逻辑(MedicationHandler._serve_static)以先以二进制模式打开文件,使用同一文件描述符读取主体(如果需要)并通过os.fstat()获取文件元数据,从而将元数据和主体绑定到同一版本。Content-Length,而不是直接使用单独的stat().st_size。candidate.read_bytes()的写入改为写入先前读取的body缓存。test_static_response_stays_consistent_when_asset_is_replaced(在tests/test_server.py)以模拟在打开资源后立即替换磁盘文件的场景,并验证返回内容与Content-Length的一致性。Testing
python -m unittest discover -s tests -v, 所有自动化单元测试通过(80 个测试通过)。tests.test_server.MedicationServerTest.test_static_files_support_head_and_conditional_requests和test_static_response_stays_consistent_when_asset_is_replaced已单独运行并通过。npm run test:e2e在当前环境中失败,因为运行环境缺少 Playwright 的浏览器可执行文件(需要运行npx playwright install来安装浏览器),因此这部分自动化在本次变更验证中未通过。Codex Task