fix(cli): stopped $-pattern expansion when injecting cache prefix

This commit is contained in:
can1357
2026-07-24 02:25:25 +02:00
parent 3f2ef2cea1
commit 5ded27b0b1
2 changed files with 5 additions and 3 deletions
+3 -1
View File
@@ -352,7 +352,9 @@ function renderCacheBenchmarkPrefix(prefix: string, namespace: string): string {
}
// Render the static wrapper first, then inject caller bytes so prompt
// normalization cannot trim spaces or collapse blank lines in prefix files.
return rendered.replace(CACHE_PREFIX_PLACEHOLDER, prefix);
// Function replacer: a prefix containing `$&`/`$'`/`` $` `` must not be
// expanded as a string-replacement pattern.
return rendered.replace(CACHE_PREFIX_PLACEHOLDER, () => prefix);
}
async function resolveCachePrefix(
@@ -494,10 +494,10 @@ describe("bench cache mode", () => {
expect(stablePrefixes[0]).not.toContain("\uFFFD");
});
it("preserves significant whitespace from the default prefix-file reader", async () => {
it("preserves significant whitespace and replacement patterns from the default prefix-file reader", async () => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "omp-bench-cache-prefix-whitespace-"));
const prefixPath = path.join(tempDir, "prefix.txt");
const exactPrefix = "line one \n\n\nline two\t\n";
const exactPrefix = "line one \n\n\n$& $' $` $$ line two\t\n";
const stablePrefixes: string[] = [];
await Bun.write(prefixPath, exactPrefix);
try {