惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
Jina AI
Jina AI
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
I
InfoQ
L
LangChain Blog
The Cloudflare Blog
IT之家
IT之家
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
F
Fortinet All Blogs
博客园 - 聂微东
美团技术团队
博客园_首页

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
test(scripts): route ClawHub fixture server · openclaw/op...
vincentkoc · 2026-06-21 · via Recent Commits to openclaw:main
1+

// ClawHub Fixture Server tests cover the local package fixture HTTP contract.

2+

import { spawn, spawnSync, type ChildProcessWithoutNullStreams } from "node:child_process";

3+

import { existsSync, readFileSync } from "node:fs";

4+

import path from "node:path";

5+

import { setTimeout as delay } from "node:timers/promises";

6+

import { afterEach, describe, expect, it } from "vitest";

7+

import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";

8+9+

const SCRIPT_PATH = "scripts/e2e/lib/clawhub-fixture-server.cjs";

10+

const PACKAGE_NAME = "@openclaw/kitchen-sink";

11+

const PACKAGE_PATH = `/api/v1/packages/${encodeURIComponent(PACKAGE_NAME)}`;

12+

const KITCHEN_SINK_VERSION = "0.2.5";

13+

const tempDirs: string[] = [];

14+

const servers: ChildProcessWithoutNullStreams[] = [];

15+16+

afterEach(async () => {

17+

await Promise.all(servers.splice(0).map(stopServer));

18+

cleanupTempDirs(tempDirs);

19+

});

20+21+

function collectStream(stream: NodeJS.ReadableStream) {

22+

let text = "";

23+

stream.setEncoding("utf8");

24+

stream.on("data", (chunk: string) => {

25+

text += chunk;

26+

});

27+

return () => text;

28+

}

29+30+

async function stopServer(child: ChildProcessWithoutNullStreams) {

31+

if (child.exitCode !== null || child.signalCode !== null) {

32+

return;

33+

}

34+

const exited = new Promise<void>((resolve) => {

35+

child.once("exit", () => resolve());

36+

});

37+

child.kill("SIGTERM");

38+

await Promise.race([exited, delay(1_000)]);

39+

if (child.exitCode === null && child.signalCode === null) {

40+

child.kill("SIGKILL");

41+

await exited;

42+

}

43+

}

44+45+

async function startFixtureServer(profile: string) {

46+

const root = makeTempDir(tempDirs, "openclaw-clawhub-fixture-server-");

47+

const portFile = path.join(root, "port");

48+

const child = spawn(process.execPath, [SCRIPT_PATH, profile, portFile], {

49+

cwd: process.cwd(),

50+

env: { ...process.env },

51+

stdio: ["ignore", "pipe", "pipe"],

52+

});

53+

const readStdout = collectStream(child.stdout);

54+

const readStderr = collectStream(child.stderr);

55+

servers.push(child);

56+57+

for (let attempt = 0; attempt < 100; attempt += 1) {

58+

if (existsSync(portFile)) {

59+

const port = Number(readFileSync(portFile, "utf8"));

60+

if (Number.isInteger(port) && port > 0) {

61+

return { baseUrl: `http://127.0.0.1:${port}` };

62+

}

63+

}

64+

if (child.exitCode !== null) {

65+

throw new Error(`fixture server exited early: stdout=${readStdout()} stderr=${readStderr()}`);

66+

}

67+

await delay(25);

68+

}

69+70+

throw new Error(`fixture server did not write a port: stderr=${readStderr()}`);

71+

}

72+73+

async function fetchJson(baseUrl: string, requestPath: string) {

74+

const response = await fetch(`${baseUrl}${requestPath}`);

75+

expect(response.status).toBe(200);

76+

return response.json();

77+

}

78+79+

describe("ClawHub fixture server", () => {

80+

it("serves package metadata and npm-pack artifacts for kitchen-sink fixtures", async () => {

81+

const { baseUrl } = await startFixtureServer("kitchen-sink-plugin");

82+83+

const packageDetail = await fetchJson(baseUrl, PACKAGE_PATH);

84+

expect(packageDetail.package.name).toBe(PACKAGE_NAME);

85+

expect(packageDetail.package.latestVersion).toBe(KITCHEN_SINK_VERSION);

86+

expect(packageDetail.package.artifact.format).toBe("tgz");

87+88+

const versionDetail = await fetchJson(

89+

baseUrl,

90+

`${PACKAGE_PATH}/versions/${KITCHEN_SINK_VERSION}/artifact`,

91+

);

92+

expect(versionDetail.artifact).toMatchObject({

93+

artifactKind: "npm-pack",

94+

packageName: PACKAGE_NAME,

95+

source: "clawhub",

96+

version: KITCHEN_SINK_VERSION,

97+

});

98+99+

const artifactResponse = await fetch(

100+

`${baseUrl}${PACKAGE_PATH}/versions/${KITCHEN_SINK_VERSION}/artifact/download`,

101+

);

102+

expect(artifactResponse.status).toBe(200);

103+

expect(artifactResponse.headers.get("x-clawhub-artifact-type")).toBe("npm-pack-tarball");

104+

expect(artifactResponse.headers.get("x-clawhub-artifact-sha256")).toMatch(/^[a-f0-9]{64}$/u);

105+

expect(Buffer.from(await artifactResponse.arrayBuffer()).length).toBeGreaterThan(100);

106+107+

const missingResponse = await fetch(`${baseUrl}/missing`);

108+

expect(missingResponse.status).toBe(404);

109+

const methodResponse = await fetch(`${baseUrl}${PACKAGE_PATH}`, { method: "POST" });

110+

expect(methodResponse.status).toBe(405);

111+

});

112+113+

it("rejects missing startup arguments before binding a fixture server", () => {

114+

const result = spawnSync(process.execPath, [SCRIPT_PATH], {

115+

cwd: process.cwd(),

116+

encoding: "utf8",

117+

env: { ...process.env },

118+

});

119+120+

expect(result.status).toBe(1);

121+

expect(result.stderr).toContain(

122+

"usage: clawhub-fixture-server.cjs <kitchen-sink-plugin|plugins> <port-file>",

123+

);

124+

});

125+

});