@detiq/crawler 1.1.15 → 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
@@ -2067,7 +2067,17 @@ jobDispatchTable = {
2067
2067
  IMPORT_TESTS: processImportTestsJob,
2068
2068
  BATCH_GENERATE_ALIGNED: processBatchGenerateAlignedJob,
2069
2069
  CREATE_PR: processCreatePRJob,
2070
- NEW_PAGES_PIPELINE: processNewPagesPipelineJob
2070
+ NEW_PAGES_PIPELINE: processNewPagesPipelineJob,
2071
+ // GENERATE_TESTS is processed in-process by the API (never QUEUED).
2072
+ // If the worker claims one, the API crashed after creating it — mark failed so it's visible.
2073
+ GENERATE_TESTS: async (jobId, _config) => {
2074
+ logger.error({ jobId }, "[job-worker] GENERATE_TESTS claimed by worker \u2014 API did not process it in-process");
2075
+ await prismaAdmin.platformJob.update({
2076
+ where: { id: jobId },
2077
+ data: { status: "FAILED", error: "Test generation was not completed by the API \u2014 please retry from the UI.", finishedAt: /* @__PURE__ */ new Date() }
2078
+ }).catch(() => {
2079
+ });
2080
+ }
2071
2081
  };
2072
2082
  async function processRepoScanJob(jobId, config) {
2073
2083
  const { repoConnectionId, tenantId, projectId } = config;
@@ -2633,7 +2643,7 @@ async function processCreatePRJob(jobId, config) {
2633
2643
  if (!conn) throw new Error(`RepoConnection ${repoConnectionId} not found`);
2634
2644
  const { decrypt: decrypt2 } = await import("@detiq/core");
2635
2645
  const token = decrypt2(conn.tokenEnc);
2636
- const { pushScriptsAsPR } = await import("@detiq/agents");
2646
+ const { pushScriptsAsPR, getFileContent, mergeSpecContent } = await import("@detiq/agents");
2637
2647
  const framework = conn.detectedFramework ?? "playwright-ts";
2638
2648
  let scripts;
2639
2649
  if (testScriptIds && testScriptIds.length > 0) {
@@ -2654,10 +2664,19 @@ async function processCreatePRJob(jobId, config) {
2654
2664
  );
2655
2665
  }
2656
2666
  if (scripts.length === 0) throw new Error("No generated scripts found to push.");
2657
- const files = scripts.map((s) => {
2667
+ const files = await Promise.all(scripts.map(async (s) => {
2658
2668
  const path2 = s.testCase?.repoTargetPath ?? deriveFallbackTargetPath(s.testCase?.ref ?? s.testCase?.title ?? s.id, framework);
2659
- return { path: path2, content: s.code };
2660
- });
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
+ }));
2661
2680
  if (files.length === 0) throw new Error("No scripts to push.");
2662
2681
  await updateJobProgress(tenantId, jobId, 20, `Pushing ${files.length} scripts to GitHub`);
2663
2682
  const now = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);