@detiq/crawler 1.1.16 → 1.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/job-queue.js CHANGED
@@ -2643,7 +2643,7 @@ async function processCreatePRJob(jobId, config) {
2643
2643
  if (!conn) throw new Error(`RepoConnection ${repoConnectionId} not found`);
2644
2644
  const { decrypt: decrypt2 } = await import("@detiq/core");
2645
2645
  const token = decrypt2(conn.tokenEnc);
2646
- const { pushScriptsAsPR } = await import("@detiq/agents");
2646
+ const { pushScriptsAsPR, getFileContent, mergeSpecContent } = await import("@detiq/agents");
2647
2647
  const framework = conn.detectedFramework ?? "playwright-ts";
2648
2648
  let scripts;
2649
2649
  if (testScriptIds && testScriptIds.length > 0) {
@@ -2664,10 +2664,19 @@ async function processCreatePRJob(jobId, config) {
2664
2664
  );
2665
2665
  }
2666
2666
  if (scripts.length === 0) throw new Error("No generated scripts found to push.");
2667
- const files = scripts.map((s) => {
2667
+ const files = await Promise.all(scripts.map(async (s) => {
2668
2668
  const path2 = s.testCase?.repoTargetPath ?? deriveFallbackTargetPath(s.testCase?.ref ?? s.testCase?.title ?? s.id, framework);
2669
- return { path: path2, content: s.code };
2670
- });
2669
+ let content = s.code;
2670
+ const isSpecFile = /\.(spec|test|cy)\.(ts|js|py|java)$/.test(path2) || /_test\.py$/.test(path2);
2671
+ if (isSpecFile) {
2672
+ const existing = await getFileContent(token, conn.repoFullName, path2, conn.defaultBranch).catch(() => null);
2673
+ if (existing && existing.trim().length > 0) {
2674
+ logger.info({ path: path2 }, "[create-pr] merging new tests into existing spec file");
2675
+ content = mergeSpecContent(existing, s.code);
2676
+ }
2677
+ }
2678
+ return { path: path2, content };
2679
+ }));
2671
2680
  if (files.length === 0) throw new Error("No scripts to push.");
2672
2681
  await updateJobProgress(tenantId, jobId, 20, `Pushing ${files.length} scripts to GitHub`);
2673
2682
  const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);