Skip to content

Commit 97f4ff5

Browse files
committed
fix(repair): keep output schema strict
1 parent aaf3304 commit 97f4ff5

7 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎schema/repair/codex-result.schema.json‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@
285285
"source_prs",
286286
"repair_strategy",
287287
"allow_no_pr",
288-
"branch_update_blockers"
288+
"branch_update_blockers",
289+
"repair_contract"
289290
],
290291
"additionalProperties": false,
291292
"properties": {
@@ -358,22 +359,29 @@
358359
}
359360
},
360361
"repair_contract": {
361-
"type": "object",
362-
"required": ["must_touch", "match"],
363-
"additionalProperties": false,
364-
"properties": {
365-
"must_touch": {
366-
"type": "array",
367-
"minItems": 1,
368-
"items": {
369-
"type": "string"
370-
}
362+
"anyOf": [
363+
{
364+
"type": "null"
371365
},
372-
"match": {
373-
"type": "string",
374-
"enum": ["any", "all"]
366+
{
367+
"type": "object",
368+
"required": ["must_touch", "match"],
369+
"additionalProperties": false,
370+
"properties": {
371+
"must_touch": {
372+
"type": "array",
373+
"minItems": 1,
374+
"items": {
375+
"type": "string"
376+
}
377+
},
378+
"match": {
379+
"type": "string",
380+
"enum": ["any", "all"]
381+
}
382+
}
375383
}
376-
}
384+
]
377385
}
378386
}
379387
}

‎src/repair/commit-finding-intake.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ function writeSyntheticRun(context: LooseRecord) {
342342
repair_strategy: "new_fix_pr",
343343
allow_no_pr: true,
344344
branch_update_blockers: [],
345+
repair_contract: null,
345346
},
346347
};
347348
fs.writeFileSync(

‎src/repair/deterministic-automerge-result.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export function deterministicAutomergeResult({
7878
repair_strategy: "repair_contributor_branch",
7979
allow_no_pr: false,
8080
branch_update_blockers: [],
81+
repair_contract: null,
8182
};
8283

8384
return {

‎src/repair/lib.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export function renderPrompt(
290290
parts.push(
291291
"## Required final output",
292292
"Return JSON matching `schema/repair/codex-result.schema.json` and nothing else.",
293-
"If the fix has explicit files that must differ from the latest base in the final repaired tree, set `fix_artifact.repair_contract` with `must_touch` and `match` (`any` or `all`). The executor checks this once against the final branch delta after review fixes and base sync. Omit `repair_contract` when the expected edit surface is uncertain, only represented by incomplete `likely_files`, or the work is a pure deterministic rebase.",
293+
"If the fix has explicit files that must differ from the latest base in the final repaired tree, set `fix_artifact.repair_contract` to an object with `must_touch` and `match` (`any` or `all`). The executor checks this once against the final branch delta after review fixes and base sync. Set `repair_contract` to null when the expected edit surface is uncertain, only represented by incomplete `likely_files`, or the work is a pure deterministic rebase.",
294294
);
295295

296296
return parts.join("\n\n");

‎test/repair/deterministic-automerge-result.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ test("deterministic automerge result emits generic direct-Codex repair artifact"
8888
]);
8989
assert.deepEqual(result?.fix_artifact.affected_surfaces, ["extensions/memory-core"]);
9090
assert.equal(result?.fix_artifact.changelog_required, false);
91+
assert.equal(result?.fix_artifact.repair_contract, null);
9192
assert.deepEqual(result?.fix_artifact.source_prs, [
9293
"https://github.com/openclaw/openclaw/pull/71898",
9394
]);

‎test/repair/repair-contract.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414

1515
test("repair contract is explicit and ignores incomplete likely_files", () => {
1616
assert.equal(repairContract({ likely_files: ["src/a.ts"] }), null);
17+
assert.equal(repairContract({ repair_contract: null }), null);
1718
assert.deepEqual(
1819
repairContract({
1920
likely_files: ["src/a.ts"],
@@ -25,6 +26,7 @@ test("repair contract is explicit and ignores incomplete likely_files", () => {
2526

2627
test("repair contract validates schema-level shape", () => {
2728
assert.deepEqual(validateRepairContractShape({}), []);
29+
assert.deepEqual(validateRepairContractShape({ repair_contract: null }), []);
2830
assert.deepEqual(
2931
validateRepairContractShape({
3032
repair_contract: { must_touch: ["src/a.ts"], match: "any" },

‎test/repair/run-worker.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ import test from "node:test";
77

88
const repoRoot = process.cwd();
99

10+
test("repair output schema keeps every strict object property required", () => {
11+
const schema = JSON.parse(
12+
fs.readFileSync(path.join(repoRoot, "schema/repair/codex-result.schema.json"), "utf8"),
13+
);
14+
15+
const visit = (value: unknown, location: string): void => {
16+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
17+
const node = value as Record<string, unknown>;
18+
if (node.type === "object" && node.additionalProperties === false) {
19+
const properties = Object.keys((node.properties ?? {}) as Record<string, unknown>).sort();
20+
const required = Array.isArray(node.required) ? node.required.map(String).sort() : [];
21+
assert.deepEqual(required, properties, `${location} must require every declared property`);
22+
}
23+
for (const [key, child] of Object.entries(node)) {
24+
if (Array.isArray(child)) {
25+
child.forEach((entry, index) => visit(entry, `${location}.${key}[${index}]`));
26+
} else {
27+
visit(child, `${location}.${key}`);
28+
}
29+
}
30+
};
31+
32+
visit(schema, "schema");
33+
});
34+
1035
test("run-worker starts Codex in the target checkout when one is available", () => {
1136
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "clawsweeper-run-worker-"));
1237
const fakeBin = path.join(tmp, "bin");

0 commit comments

Comments
 (0)