(
options: {
rawPatch: string;
cwd?: string;
fileExts?: string[];
timeoutMs?: number;
},
runtime: SemanticDiffRuntime = createDefaultSemanticDiffRuntime(),
)
| 469 | } |
| 470 | |
| 471 | export async function runSemanticDiff( |
| 472 | options: { |
| 473 | rawPatch: string; |
| 474 | cwd?: string; |
| 475 | fileExts?: string[]; |
| 476 | timeoutMs?: number; |
| 477 | }, |
| 478 | runtime: SemanticDiffRuntime = createDefaultSemanticDiffRuntime(), |
| 479 | ): Promise<SemanticDiffResponse> { |
| 480 | if (!options.rawPatch.trim()) { |
| 481 | return { |
| 482 | status: "ok", |
| 483 | summary: { |
| 484 | fileCount: 0, |
| 485 | added: 0, |
| 486 | modified: 0, |
| 487 | deleted: 0, |
| 488 | moved: 0, |
| 489 | renamed: 0, |
| 490 | reordered: 0, |
| 491 | binary: 0, |
| 492 | orphan: 0, |
| 493 | total: 0, |
| 494 | }, |
| 495 | changes: [], |
| 496 | binaryChanges: [], |
| 497 | semVersion: "not-run", |
| 498 | semSource: "empty-patch", |
| 499 | }; |
| 500 | } |
| 501 | |
| 502 | const cwd = options.cwd || runtime.cwd || getSemanticDiffScratchCwd(runtime.dataDir); |
| 503 | const effectiveRuntime = cwd === runtime.cwd ? runtime : { ...runtime, cwd }; |
| 504 | const resolved = await resolveSem(effectiveRuntime); |
| 505 | if (!("command" in resolved)) return resolved; |
| 506 | |
| 507 | const fileExts = normalizeSemanticDiffFileExts(options.fileExts); |
| 508 | const args = ["diff", "--patch", "--format", "json"]; |
| 509 | if (fileExts.length > 0) { |
| 510 | args.push("--file-exts", ...fileExts); |
| 511 | } |
| 512 | |
| 513 | const result = await effectiveRuntime.runCommand(resolved.command, args, { |
| 514 | cwd, |
| 515 | input: options.rawPatch, |
| 516 | timeoutMs: options.timeoutMs ?? SEM_TIMEOUT_MS, |
| 517 | }); |
| 518 | |
| 519 | if (result.timedOut) { |
| 520 | return { |
| 521 | status: "error", |
| 522 | reason: "sem-timeout", |
| 523 | message: result.error ?? "sem timed out while analyzing the diff.", |
| 524 | semVersion: resolved.version, |
| 525 | semSource: resolved.source, |
| 526 | }; |
| 527 | } |
| 528 |
no test coverage detected