Skip to content

Commit c86d328

Browse files
committed
fix(miner): surface costUsd on the changed-files-enumeration-failure path too
Reconciling this branch with #5356 (costUsd wiring) surfaced a gap: the new changed-file-enumeration-failure return statement ran after the SDK result message (and its billed total_cost_usd) was already available, but omitted costUsd -- silently undercounting real spend for that one failure path in budgetSpent. Added it, plus regression coverage in both the node:test source and its vitest/Codecov mirror.
1 parent 4f5ccf8 commit c86d328

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

packages/gittensory-engine/test/agent-sdk-driver.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ test("success derives changed files from the worktree after untracked mutating t
9797
assert.deepEqual(result.changedFiles, ["packages/gittensory-engine/src/vulnerable.ts"]);
9898
});
9999

100-
test("success fails closed when changed-file enumeration is unavailable", async () => {
100+
test("success fails closed when changed-file enumeration is unavailable, but still reports the real dollar cost", async () => {
101101
const driver = driverWith({
102102
query: queryYielding([
103-
{ type: "result", subtype: "success", is_error: false, num_turns: 2, result: "done" },
103+
{ type: "result", subtype: "success", is_error: false, num_turns: 2, result: "done", total_cost_usd: 0.0042 },
104104
]),
105105
listChangedFiles: async () => {
106106
throw new Error("not a git worktree");
@@ -112,6 +112,9 @@ test("success fails closed when changed-file enumeration is unavailable", async
112112
assert.equal(result.ok, false);
113113
assert.deepEqual(result.changedFiles, []);
114114
assert.match(result.error!, /agent_sdk_changed_files_unavailable: not a git worktree/);
115+
// The SDK session ran and was billed before enumeration ever failed -- budgetSpent must not silently
116+
// undercount this path just because the changed-files step failed afterward.
117+
assert.equal(result.costUsd, 0.0042);
115118
});
116119

117120
test("success stringifies a non-Error changed-file enumeration failure", async () => {

test/unit/agent-sdk-driver.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ describe("createAgentSdkCodingAgentDriver", () => {
134134
expect(result.changedFiles).toEqual(["packages/gittensory-engine/src/vulnerable.ts"]);
135135
});
136136

137-
it("fails closed when changed-file enumeration is unavailable", async () => {
137+
it("fails closed when changed-file enumeration is unavailable, but still reports the real dollar cost", async () => {
138138
const driver = driverWith({
139139
query: queryYielding([
140-
{ type: "result", subtype: "success", is_error: false, num_turns: 2, result: "done" },
140+
{ type: "result", subtype: "success", is_error: false, num_turns: 2, result: "done", total_cost_usd: 0.0042 },
141141
]),
142142
listChangedFiles: async () => {
143143
throw new Error("not a git worktree");
@@ -149,6 +149,9 @@ describe("createAgentSdkCodingAgentDriver", () => {
149149
expect(result.ok).toBe(false);
150150
expect(result.changedFiles).toEqual([]);
151151
expect(result.error).toContain("agent_sdk_changed_files_unavailable: not a git worktree");
152+
// The SDK session ran and was billed before enumeration ever failed -- budgetSpent must not silently
153+
// undercount this path just because the changed-files step failed afterward.
154+
expect(result.costUsd).toBe(0.0042);
152155
});
153156

154157
it("stringifies a non-Error changed-file enumeration failure", async () => {

0 commit comments

Comments
 (0)