发布企业公共世界更新端点

This commit is contained in:
冰朔 2026-09-19 22:38:20 +08:00
commit 68aca714cb
2 changed files with 50 additions and 0 deletions

View file

@ -328,3 +328,27 @@ test("public endpoints are read-only and expose CORS", async () => {
assert.equal((await fetch(`${base}/v1/search`, { method: "POST" })).status, 405);
} finally { await new Promise(resolve => server.close(resolve)); }
});
test("public world release descriptor and bundle are read-only", async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "guanghu-public-release-"));
const descriptorPath = path.join(root, "release.json");
const bundlePath = path.join(root, "bundle.zip");
fs.writeFileSync(descriptorPath, JSON.stringify({ schema: "guanghu.public-world-release/v1", world_id: "GLW-2.0-0001", version: "test", bundle_url: "https://example.invalid/bundle", bundle_sha256: "0".repeat(64) }));
fs.writeFileSync(bundlePath, Buffer.from("PK-test"));
const server = createServer({ runtimeStatusProvider: async () => warmRuntimeStatus(), publicWorldReleaseFile: descriptorPath, publicWorldBundleFile: bundlePath });
await new Promise(resolve => server.listen(0, "127.0.0.1", resolve));
const base = `http://127.0.0.1:${server.address().port}`;
try {
const descriptor = await fetch(`${base}/v1/public-world-release`);
assert.equal(descriptor.status, 200);
assert.equal((await descriptor.json()).schema, "guanghu.public-world-release/v1");
const bundle = await fetch(`${base}/v1/public-world-bundle`);
assert.equal(bundle.status, 200);
assert.equal(bundle.headers.get("content-type"), "application/zip");
assert.equal(Buffer.from(await bundle.arrayBuffer()).toString(), "PK-test");
assert.equal((await fetch(`${base}/v1/public-world-bundle`, { method: "POST" })).status, 405);
} finally {
await new Promise(resolve => server.close(resolve));
fs.rmSync(root, { recursive: true, force: true });
}
});