mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-09 03:22:40 +00:00
fix: canonicalize codex protocol JSON assets (#91507)
This commit is contained in:
@@ -4,6 +4,8 @@ import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildCodexProtocolExportArgs,
|
||||
canonicalizeCodexAppServerProtocolJson,
|
||||
formatCodexAppServerProtocolJsonText,
|
||||
resolveCodexAppServerProtocolSource,
|
||||
resolveCodexProtocolCargoTargetDir,
|
||||
resolveCodexProtocolMinFreeBytes,
|
||||
@@ -162,6 +164,81 @@ describe("codex app-server protocol source resolver", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Codex app-server protocol JSON canonicalizer", () => {
|
||||
it("sorts object keys recursively before formatting", () => {
|
||||
const source = JSON.stringify({
|
||||
z: {
|
||||
d: 1,
|
||||
b: {
|
||||
y: 2,
|
||||
x: 3,
|
||||
},
|
||||
},
|
||||
a: [
|
||||
{
|
||||
z: 4,
|
||||
a: {
|
||||
c: 5,
|
||||
b: 6,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(formatCodexAppServerProtocolJsonText(source)).toBe(`{
|
||||
"a": [
|
||||
{
|
||||
"a": {
|
||||
"b": 6,
|
||||
"c": 5
|
||||
},
|
||||
"z": 4
|
||||
}
|
||||
],
|
||||
"z": {
|
||||
"b": {
|
||||
"x": 3,
|
||||
"y": 2
|
||||
},
|
||||
"d": 1
|
||||
}
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it("sorts arrays only when plain object items expose top-level type values", () => {
|
||||
expect(
|
||||
canonicalizeCodexAppServerProtocolJson({
|
||||
enum: ["z", "a"],
|
||||
mixed: [{ type: "b" }, "item", { type: "a" }],
|
||||
oneOf: [
|
||||
{ title: "Second", z: true },
|
||||
{ a: true, title: "First" },
|
||||
],
|
||||
required: ["z", "a"],
|
||||
typed: [
|
||||
{ type: "beta", z: 1 },
|
||||
{ type: "alpha", z: 2 },
|
||||
{ type: "beta", z: 3 },
|
||||
],
|
||||
}),
|
||||
).toEqual({
|
||||
enum: ["z", "a"],
|
||||
mixed: [{ type: "b" }, "item", { type: "a" }],
|
||||
oneOf: [
|
||||
{ title: "Second", z: true },
|
||||
{ a: true, title: "First" },
|
||||
],
|
||||
required: ["z", "a"],
|
||||
typed: [
|
||||
{ type: "alpha", z: 2 },
|
||||
{ type: "beta", z: 1 },
|
||||
{ type: "beta", z: 3 },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function createProtocolSchema(codexRepo: string): void {
|
||||
fs.mkdirSync(path.join(codexRepo, "codex-rs/app-server-protocol/schema/typescript"), {
|
||||
recursive: true,
|
||||
|
||||
Reference in New Issue
Block a user