Skip to content

Commit e210f01

Browse files
committed
fix(provider-core): verify placeholder title preservation
1 parent f1ee8e4 commit e210f01

2 files changed

Lines changed: 46 additions & 8 deletions

File tree

‎packages/provider-core/src/server/textGenerationOperations.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,11 @@ export function fromRunner(name: string, run: Runner): ProviderTextGeneration {
150150
}),
151151
});
152152
const title = sanitizeThreadTitle(generated.title);
153-
// Some models return the schema placeholder instead of generating a title.
154-
// Preserve an existing useful title rather than replacing it with "title".
155-
const sanitizedTitle =
156-
title.toLocaleLowerCase() === "title" && input.previousTitle
157-
? sanitizeThreadTitle(input.previousTitle)
158-
: title;
159153
return {
160-
title: sanitizedTitle,
154+
title:
155+
title.toLowerCase() === "title" && input.previousTitle
156+
? sanitizeThreadTitle(input.previousTitle)
157+
: title,
161158
...(generated.needsRefinement ? { needsRefinement: true } : {}),
162159
};
163160
});

‎packages/provider-core/src/server/textGenerationUtils.test.ts‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { describe, expect, it } from "vite-plus/test";
1+
import { ProviderInstanceId } from "@t3tools/contracts";
2+
import * as Effect from "effect/Effect";
3+
import { it } from "@effect/vitest";
4+
import { describe, expect } from "vite-plus/test";
25

6+
import { decodeJsonReply, fromRunner } from "./textGenerationOperations.ts";
37
import { sanitizeCommitSubject, sanitizeThreadTitle } from "./textGenerationUtils.ts";
48

59
describe("sanitizeCommitSubject", () => {
@@ -20,3 +24,40 @@ describe("sanitizeThreadTitle", () => {
2024
expect(sanitizeThreadTitle(" Implement issue #140 ")).toBe("Implement issue #140");
2125
});
2226
});
27+
28+
describe("generateThreadTitle", () => {
29+
it.effect.each([
30+
{ generated: "title", previousTitle: "Implement issue #140", expected: "Implement issue #140" },
31+
{
32+
generated: ' "TITLE" ',
33+
previousTitle: " Implement issue #140 ",
34+
expected: "Implement issue #140",
35+
},
36+
{ generated: "title", previousTitle: undefined, expected: "title" },
37+
{ generated: "title", previousTitle: "", expected: "title" },
38+
{
39+
generated: "Improve title generation",
40+
previousTitle: "Old title",
41+
expected: "Improve title generation",
42+
},
43+
])(
44+
"returns $expected for $generated with previous title $previousTitle",
45+
({ generated, previousTitle, expected }) =>
46+
Effect.gen(function* () {
47+
const provider = fromRunner("test", (request) =>
48+
decodeJsonReply(
49+
request,
50+
"test",
51+
JSON.stringify({ title: generated, needsRefinement: true }),
52+
),
53+
);
54+
const result = yield* provider.generateThreadTitle({
55+
cwd: "/repo",
56+
message: "Implement issue #140",
57+
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5" },
58+
previousTitle,
59+
});
60+
expect(result).toEqual({ title: expected, needsRefinement: true });
61+
}),
62+
);
63+
});

0 commit comments

Comments
 (0)