feat: ship self-hosted KOC LOOP workflows

This commit is contained in:
巫凤萍
2026-08-11 23:07:26 +08:00
parent 1f1887c860
commit ddad4b7659
88 changed files with 6056 additions and 8938 deletions

View File

@@ -106,11 +106,55 @@ test("collects likes, comments and favorites from the verified MCP shape", async
});
assert.equal(calls.length, 3);
assert.equal(calls[2].body.params.name, "fetch_content_detail");
assert.equal(calls[2].body.params.arguments.include_comments, false);
assert.equal(calls[2].body.params.arguments.request.include_comments, false);
assert.equal(calls[2].headers.get("mcp-session-id"), "session-test");
assert.equal(new URL(calls[0].url).searchParams.get("key"), "test-key");
});
test("collects through a stateless MCP server without a session header", async () => {
const calls = [];
const fetchImpl = async (_url, init) => {
const body = JSON.parse(init.body);
calls.push({ body, headers: new Headers(init.headers) });
if (body.method === "initialize") {
return sse({
jsonrpc: "2.0",
id: body.id,
result: {
protocolVersion: "2025-03-26",
capabilities: { tools: { listChanged: false } },
serverInfo: { name: "ai-tool-center", version: "production" },
},
});
}
if (body.method === "tools/call") {
return sse(
toolEnvelope({
response: {
code: 200,
success: true,
data: { likes: 12, comments: 3, collects: 6 },
},
}),
);
}
throw new Error(`Unexpected MCP method: ${body.method}`);
};
const result = await collectXhsMetricsFromMcp(
"https://www.xiaohongshu.com/explore/test",
{ endpoint: "https://collector.example/mcp", key: "test-key" },
fetchImpl,
);
assert.deepEqual(result, { likes: 12, comments: 3, collects: 6 });
assert.deepEqual(
calls.map((call) => call.body.method),
["initialize", "tools/call"],
);
assert.equal(calls[1].headers.get("mcp-session-id"), null);
});
test("resolves the real XHS account profile from a submitted note link", async () => {
const { calls, fetchImpl } = createFakeMcp([
toolEnvelope({
@@ -180,12 +224,12 @@ test("resolves the real XHS account profile from a submitted note link", async (
"collect_xhs_wen_note_detail",
);
assert.equal(
calls[2].body.params.arguments.note_id,
calls[2].body.params.arguments.request.note_id,
"6a671108000000000f004bef",
);
assert.equal(calls[3].body.params.name, "parse_xhs_user_summary");
assert.equal(
calls[3].body.params.arguments.url,
calls[3].body.params.arguments.request.url,
"https://www.xiaohongshu.com/user/profile/6905cbca0000000037009f49",
);
assert.equal(
@@ -225,6 +269,7 @@ test("resolves followers directly from the supported XHS user summary tool", asy
);
assert.deepEqual(details, {
nickname: "555 五",
followers: 6,
redId: "1020668113",
ipLocation: "福建",
@@ -293,7 +338,7 @@ test("resolves an xhslink short URL before requesting the author profile", async
"https://www.xiaohongshu.com/user/profile/6905cbca0000000037009f49",
);
assert.equal(
fakeMcp.calls[2].body.params.arguments.note_id,
fakeMcp.calls[2].body.params.arguments.request.note_id,
"6a572da40000000021018bd2",
);
});
@@ -379,6 +424,7 @@ test("reads the user-visible Xiaohongshu number from a public profile", async ()
assert.equal(accountId, "1020668113");
assert.deepEqual(details, {
nickname: "",
redId: "1020668113",
followers: 10,
ipLocation: "",