1
0

feat: 版本管理,package.json 唯一版本源、/api/meta 返回版本、Dashboard Header 展示版本号

This commit is contained in:
2026-05-20 19:14:37 +08:00
parent f3df3a203b
commit 8eac814cc6
25 changed files with 490 additions and 20 deletions

View File

@@ -175,6 +175,7 @@ describe("API 路由", () => {
config: { host: "127.0.0.1", port: 0 },
mode: "test",
store,
version: "0.1.0",
});
baseUrl = `http://127.0.0.1:${server.port}`;
});
@@ -235,7 +236,7 @@ describe("API 路由", () => {
expect(invalidLimit.status).toBe(400);
});
test("/api/meta 返回 checker 类型列表", async () => {
test("/api/meta 返回 checker 类型列表和版本号", async () => {
const response = await fetch(`${baseUrl}/api/meta`);
const body = (await response.json()) as MetaResponse;
@@ -243,6 +244,7 @@ describe("API 路由", () => {
expect(body.checkerTypes).toEqual(checkerRegistry.supportedTypes);
expect(body.checkerTypes).toContain("http");
expect(body.checkerTypes).toContain("cmd");
expect(body.version).toBe("0.1.0");
});
test("不支持的 method 在有 API 通配符时返回 404", async () => {
@@ -410,6 +412,7 @@ describe("API 路由", () => {
config: { host: "127.0.0.1", port: 0 },
mode: "production",
store,
version: "0.1.0",
});
try {
const response = await fetch(`http://127.0.0.1:${prodServer.port}/api/dashboard`);

View File

@@ -77,6 +77,7 @@ function createHarness(overrides: BootstrapDependencies = {}) {
startServer(options) {
expect(options.config).toEqual({ host: config.host, port: config.port });
expect(options.store).toBe(store);
expect(options.version).toBe("0.1.0");
calls.push(`startServer:${options.mode}`);
},
...overrides,
@@ -89,7 +90,7 @@ describe("bootstrap", () => {
test("开发模式执行完整启动序列", async () => {
const { calls, dependencies } = createHarness();
await bootstrap({ configPath: "/tmp/probes.yaml", mode: "development" }, dependencies);
await bootstrap({ configPath: "/tmp/probes.yaml", mode: "development", version: "0.1.0" }, dependencies);
expect(calls).toEqual([
"loadConfig:/tmp/probes.yaml",
@@ -106,7 +107,7 @@ describe("bootstrap", () => {
test("收到退出信号时停止 engine 并关闭 store", async () => {
const { calls, dependencies, shutdownHandlers } = createHarness();
await bootstrap({ configPath: "/tmp/probes.yaml", mode: "development" }, dependencies);
await bootstrap({ configPath: "/tmp/probes.yaml", mode: "development", version: "0.1.0" }, dependencies);
expect(() => shutdownHandlers.get("SIGINT")!()).toThrow("exit:0");
@@ -122,7 +123,7 @@ describe("bootstrap", () => {
let error: unknown;
try {
await bootstrap({ configPath: "/tmp/probes.yaml", mode: "development" }, dependencies);
await bootstrap({ configPath: "/tmp/probes.yaml", mode: "development", version: "0.1.0" }, dependencies);
} catch (caught) {
error = caught;
}