Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions scripts/hosted-review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ await Bun.write(process.argv[process.argv.indexOf('--output-last-message')+1],JS
await Bun.write(process.env.CODEX_HOME+'/auth.json',JSON.stringify({tokens:{refresh_token:'refreshed'}}));
console.log(JSON.stringify({type:'thread.started',thread_id:'test-thread'}));
console.log(JSON.stringify({type:'item.completed',item:{type:'agent_message',text:JSON.stringify(verdict)}}));
if(mode==='stderr-after-verdict') {
console.log(JSON.stringify({type:'turn.completed',usage:{input_tokens:17,output_tokens:3}}));
console.error('42');
process.exitCode=1;
}
`);
const event = join(temp, "event.json"), config = join(temp, "config.toml"), auth = join(temp, "auth.json");
writeFileSync(event, JSON.stringify({ action: "opened", sender: {login:"author",type:"User"}, pull_request: {number:7,head:{sha:head}} }));
Expand Down Expand Up @@ -313,6 +318,15 @@ test.each(["stale-verdict", "moved-on-retry", "moved-on-retry-error"])("hosted %
expect(existsSync(join(setup.temp, "reviews"))).toBe(false);
});

test("a non-object stderr line leaves the recovered verdict, thread and usage intact", () => {
const setup = fixture("stderr-after-verdict"), result = setup.run();
expect(result.exitCode).toBe(0);
expect(JSON.parse(readFileSync(join(setup.temp, "review.json"), "utf8")).conclusion).toBe("success");
expect(readFileSync(join(setup.state, "last-thread-id"), "utf8").trim()).toBe("test-thread");
expect(result.stdout.toString()).toContain("17 input, 0% cached · 3 output");
expect(existsSync(join(setup.temp, "retried"))).toBe(false);
});

test("an invalid verdict on the current head still retries and reports the failure", () => {
const setup = fixture("invalid-verdict"), result = setup.run();
expect(result.exitCode).not.toBe(0);
Expand Down
6 changes: 3 additions & 3 deletions scripts/run-review.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ if grep -Eq '^(Error: .*|.*"type":"(error|turn\.failed)".*)(unsupported_persiste
fresh < /dev/null 2>&1 | tee "$RUNNER_TEMP/codex.jsonl" | log && ran=1
fi
# A turn that fails after the review is complete, such as when the provider is at capacity for the next turn, still leaves the verdict it produced.
[ "$AGENT" = true ] || [ "$ran" = 1 ] || jq -Rrs '[split("\n")[] | fromjson? // empty | select(.type == "item.completed" and .item.type == "agent_message") | .item.text] | last // empty' \
[ "$AGENT" = true ] || [ "$ran" = 1 ] || jq -Rrs '[split("\n")[] | fromjson? | objects | select(.type == "item.completed" and .item.type == "agent_message") | .item.text] | last // empty' \
< "$RUNNER_TEMP/codex.jsonl" > "$RUNNER_TEMP/review.json"
# Recorded before the verdict check, so a fresh review can resume the thread it just started.
jq -Rrs '[split("\n")[] | fromjson? // empty | select(.type == "thread.started")] | first | .thread_id // empty' \
jq -Rrs '[split("\n")[] | fromjson? | objects | select(.type == "thread.started")] | first | .thread_id // empty' \
< "$RUNNER_TEMP/codex.jsonl" > "$CODEX_HOME/last-thread-id"
# A successfully resumed thread remembers the policy and pre-run compaction count in its next snapshot.
if [ "$ran" = 1 ] && [ -s "$CODEX_HOME/last-thread-id" ]; then
Expand Down Expand Up @@ -192,7 +192,7 @@ fi
# The line and the turns the price reads come from one pass, so the price judges the same turns the counts describe.
{ read -r usage; read -r turns; } < <(jq -Rrs '
def h: if . >= 1000000 then "\(. / 100000 | round / 10)M" elif . >= 1000 then "\(. / 100 | round / 10)k" else "\(.)" end;
[split("\n")[] | fromjson? // empty | select(.type == "turn.completed") | .usage] as $turns
[split("\n")[] | fromjson? | objects | select(.type == "turn.completed") | .usage] as $turns
| ($turns | map(.input_tokens) | add // 0) as $input
| ($turns | map(.cached_input_tokens) | add // 0) as $cached
| ($turns | map(.output_tokens) | add // 0) as $output
Expand Down
Loading