Add metadata validation script and module documentation
- Introduced a new Python script `check_agents_metadata.py` for validating agent metadata, including YAML parsing, rating ranges, and cross-references. - Added usage instructions and exit codes for the script. - Created a new markdown file `模块目录和功能说明.md` to outline the directory structure and functionality of the modules. - Added a text file `说明此文件不可AI修改.txt` to specify that certain files should not be modified by AI, including important information about the `dstalk` framework and its modules.
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
// ============================================================================
|
||||
// network_plugin_test.cpp — Network 插件单元测试
|
||||
// W22.2 (qa-xu): 覆盖 parse_headers_json / SSE 行解析 / 参数校验
|
||||
// 通过 #include plugin source 访问 file-scope static 函数
|
||||
// ============================================================================
|
||||
/*
|
||||
* @file network_plugin_test.cpp
|
||||
* @brief Network plugin unit tests (W22.2): parse_headers_json (normal, empty,
|
||||
* malformed, long values), SSE line splitting boundaries, and
|
||||
* http_post_json/http_post_stream parameter validation.
|
||||
* Network 插件单元测试 (W22.2):parse_headers_json(正常、空、畸形、长值)、SSE 行解析边界、
|
||||
* http_post_json/http_post_stream 参数校验。
|
||||
* Copyright (c) 2026 dstalk contributors. GPLv3.
|
||||
*/
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define BOOST_ASIO_DISABLE_STD_TO_ADDRESS
|
||||
#include "../plugins/network/src/network_plugin.cpp"
|
||||
@@ -15,6 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
static int g_failures = 0;
|
||||
// Lightweight assertion macro: increments g_failures counter on failure
|
||||
#define CHECK(cond, msg) do { \
|
||||
if (cond) { \
|
||||
std::cout << "[OK] " << (msg) << "\n"; \
|
||||
@@ -24,9 +29,9 @@ static int g_failures = 0;
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// ================================================================
|
||||
// SSE 行分割 helper (复刻 do_post_stream 的 emit_lines 逻辑)
|
||||
// ================================================================
|
||||
// SSE line-split helper: mirrors do_post_stream's emit_lines logic for unit-testing
|
||||
// SSE chunk parsing without a live network connection.
|
||||
// SSE 行分割辅助函数:镜像 do_post_stream 的 emit_lines 逻辑,无需实时网络连接即可单元测试 SSE 数据块解析。
|
||||
static std::vector<std::string> split_sse_lines(std::string fragment) {
|
||||
std::vector<std::string> lines;
|
||||
size_t pos = 0;
|
||||
@@ -55,11 +60,17 @@ static std::vector<std::string> split_sse_lines(std::string fragment) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Network 插件测试 (W22.2):parse_headers_json 正常/空/畸形/长值、
|
||||
// SSE 行分割(LF、CRLF、空、null 字节、尾部 CR)、
|
||||
// http_post_json/http_post_stream 参数校验(空指针)。
|
||||
// Network plugin tests (W22.2): parse_headers_json normal/empty/malformed/long,
|
||||
// SSE line splitting (LF, CRLF, empty, null-bytes, trailing CR),
|
||||
// and http_post_json/http_post_stream parameter validation (null pointers).
|
||||
int main()
|
||||
{
|
||||
// ================================================================
|
||||
// Test Block 1: parse_headers_json — 正常 JSON
|
||||
// Test Block 1: parse_headers_json — normal JSON
|
||||
// ================================================================
|
||||
std::cout << "\n--- Block 1: parse_headers_json normal JSON ---\n";
|
||||
|
||||
@@ -98,6 +109,7 @@ int main()
|
||||
|
||||
// ================================================================
|
||||
// Test Block 2: parse_headers_json — 空 / null 输入
|
||||
// Test Block 2: parse_headers_json — empty/null input
|
||||
// ================================================================
|
||||
std::cout << "\n--- Block 2: parse_headers_json empty/null input ---\n";
|
||||
|
||||
@@ -124,6 +136,7 @@ int main()
|
||||
|
||||
// ================================================================
|
||||
// Test Block 3: parse_headers_json — 畸形 JSON
|
||||
// Test Block 3: parse_headers_json — malformed JSON
|
||||
// ================================================================
|
||||
std::cout << "\n--- Block 3: parse_headers_json malformed JSON ---\n";
|
||||
|
||||
@@ -177,6 +190,7 @@ int main()
|
||||
|
||||
// ================================================================
|
||||
// Test Block 4: parse_headers_json — 超长 header 值
|
||||
// Test Block 4: parse_headers_json — long values
|
||||
// ================================================================
|
||||
std::cout << "\n--- Block 4: parse_headers_json long values ---\n";
|
||||
|
||||
@@ -209,6 +223,7 @@ int main()
|
||||
|
||||
// ================================================================
|
||||
// Test Block 5: SSE 行解析边界
|
||||
// Test Block 5: SSE line splitting boundaries
|
||||
// ================================================================
|
||||
std::cout << "\n--- Block 5: SSE line splitting boundaries ---\n";
|
||||
|
||||
@@ -274,6 +289,7 @@ int main()
|
||||
|
||||
// ================================================================
|
||||
// Test Block 6: http_post_json — 参数校验 (null ptr, early return)
|
||||
// Test Block 6: http_post_json — parameter validation (null ptr, early return)
|
||||
// ================================================================
|
||||
std::cout << "\n--- Block 6: http_post_json parameter validation ---\n";
|
||||
|
||||
@@ -319,6 +335,7 @@ int main()
|
||||
|
||||
// ================================================================
|
||||
// Test Block 7: http_post_stream — 参数校验
|
||||
// Test Block 7: http_post_stream — parameter validation
|
||||
// ================================================================
|
||||
std::cout << "\n--- Block 7: http_post_stream parameter validation ---\n";
|
||||
|
||||
@@ -338,7 +355,7 @@ int main()
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// Summary
|
||||
// Summary / 总结
|
||||
// ================================================================
|
||||
std::cout << "\n";
|
||||
if (g_failures == 0) {
|
||||
|
||||
Reference in New Issue
Block a user