29 lines
1.6 KiB
JavaScript
29 lines
1.6 KiB
JavaScript
|
|
"use strict";
|
||
|
|
|
||
|
|
const test = require("node:test");
|
||
|
|
const assert = require("node:assert/strict");
|
||
|
|
const crypto = require("node:crypto");
|
||
|
|
const fs = require("node:fs");
|
||
|
|
const os = require("node:os");
|
||
|
|
const path = require("node:path");
|
||
|
|
|
||
|
|
test("health surface stays read-only and identifies Chenglu Agent", async () => {
|
||
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "chenglu-server-"));
|
||
|
|
const { privateKey, publicKey } = crypto.generateKeyPairSync("ed25519");
|
||
|
|
process.env.CHENGLU_STATE_PATH = path.join(dir, "state.json");
|
||
|
|
process.env.CHENGLU_IDENTITY_KEY = path.join(dir, "identity.key");
|
||
|
|
process.env.CHENGLU_IDENTITY_PUBLIC = path.join(dir, "identity.pub");
|
||
|
|
fs.writeFileSync(process.env.CHENGLU_IDENTITY_KEY, privateKey.export({ type: "pkcs8", format: "pem" }));
|
||
|
|
fs.writeFileSync(process.env.CHENGLU_IDENTITY_PUBLIC, publicKey.export({ type: "spki", format: "pem" }));
|
||
|
|
fs.writeFileSync(process.env.CHENGLU_STATE_PATH, JSON.stringify({ version: 2, mode: "ONLINE_IDLE" }));
|
||
|
|
const { createServer } = require("../src/server");
|
||
|
|
const server = createServer().listen(0, "127.0.0.1");
|
||
|
|
try {
|
||
|
|
await new Promise(resolve => server.once("listening", resolve));
|
||
|
|
const address = server.address();
|
||
|
|
const health = await fetch(`http://127.0.0.1:${address.port}/health`).then(response => response.json());
|
||
|
|
assert.deepEqual(health, { ok: true, agent_id: "CHENGLU-AGENT-001", mode: "ONLINE_IDLE" });
|
||
|
|
const rejected = await fetch(`http://127.0.0.1:${address.port}/v1/identity`, { method: "DELETE" });
|
||
|
|
assert.equal(rejected.status, 404);
|
||
|
|
} finally { await new Promise(resolve => server.close(resolve)); fs.rmSync(dir, { recursive: true, force: true }); }
|
||
|
|
});
|