( conversations: NormalizedConversation[], workDir: string, )
| 775 | } |
| 776 | |
| 777 | function normalizeFilenames( |
| 778 | conversations: NormalizedConversation[], |
| 779 | workDir: string, |
| 780 | ): void { |
| 781 | // Replace occurrences of the workDir path with workingDirPlaceholder to avoid diffs due to different test run locations |
| 782 | // We do so case-insensitively and with both / and \ to cover different OSes |
| 783 | // We also normalize any slashes in the rest of the path (e.g., C:\my\workdir\path\to\file.txt -> ${workdir}/path/to/file.txt) |
| 784 | workDir = workDir.replace(/\\/g, "/").replace(/\/+$/, ""); |
| 785 | const escaped = workDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); |
| 786 | const workDirPattern = new RegExp( |
| 787 | escaped.replace(/\//g, "[\\\\/]+") + "([\\\\/]+[^\\s\"'`,]*)?", |
| 788 | "gi", |
| 789 | ); |
| 790 | const workDirReplacer = (_: string, rest?: string) => |
| 791 | workingDirPlaceholder + (rest?.replace(/[\\/]+/g, "/") ?? ""); |
| 792 | |
| 793 | // Match non-rooted Windows paths like abc\def\something.ext and flip slashes to / |
| 794 | // We don't need to match absolute paths because the only legit ones should be inside workdir which |
| 795 | // is handled above. Plus there's nothing we could do to normalize them since we don't know their base. |
| 796 | const windowsFnPattern = |
| 797 | /(?<![a-zA-Z0-9_\\])([a-zA-Z0-9_.-]+(?:\\[a-zA-Z0-9_.-]+)+)/g; |
| 798 | const windowsFnReplacer = (_: string, path: string) => |
| 799 | path.replace(/\\/g, "/"); |
| 800 | |
| 801 | for (const conv of conversations) { |
| 802 | for (const msg of conv.messages) { |
| 803 | if (msg.content) { |
| 804 | msg.content = msg.content.replace(workDirPattern, workDirReplacer); |
| 805 | msg.content = msg.content.replace(windowsFnPattern, windowsFnReplacer); |
| 806 | } |
| 807 | for (const tc of msg.tool_calls ?? []) { |
| 808 | if (tc.function?.arguments) { |
| 809 | tc.function.arguments = tc.function.arguments.replace( |
| 810 | workDirPattern, |
| 811 | workDirReplacer, |
| 812 | ); |
| 813 | tc.function.arguments = tc.function.arguments.replace( |
| 814 | windowsFnPattern, |
| 815 | windowsFnReplacer, |
| 816 | ); |
| 817 | } |
| 818 | } |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | function normalizeToolCalls( |
| 824 | conversations: NormalizedConversation[], |
no outgoing calls
no test coverage detected
searching dependent graphs…