@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@detiq/crawler",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public",
package/src/job-queue.ts CHANGED
@@ -3092,7 +3092,7 @@ async function processCreatePRJob(jobId: string, config: any) {
3092
3092
  const { decrypt } = await import('@detiq/core');
3093
3093
  const token = decrypt(conn.tokenEnc);
3094
3094
 
3095
- const { pushScriptsAsPR } = await import('@detiq/agents');
3095
+ const { pushScriptsAsPR, getFileContent, mergeSpecContent } = await import('@detiq/agents');
3096
3096
 
3097
3097
  const framework = conn.detectedFramework ?? 'playwright-ts';
3098
3098
 
@@ -3117,11 +3117,24 @@ async function processCreatePRJob(jobId: string, config: any) {
3117
3117
 
3118
3118
  if (scripts.length === 0) throw new Error('No generated scripts found to push.');
3119
3119
 
3120
- const files = scripts.map((s: any) => {
3120
+ // For each file, check if it already exists in the repo and merge if so
3121
+ const files = await Promise.all(scripts.map(async (s: any) => {
3121
3122
  const path = s.testCase?.repoTargetPath
3122
3123
  ?? deriveFallbackTargetPath(s.testCase?.ref ?? s.testCase?.title ?? s.id, framework);
3123
- return { path, content: s.code };
3124
- });
3124
+ let content = s.code;
3125
+
3126
+ // Spec files: attempt to merge with existing content
3127
+ const isSpecFile = /\.(spec|test|cy)\.(ts|js|py|java)$/.test(path) || /_test\.py$/.test(path);
3128
+ if (isSpecFile) {
3129
+ const existing = await getFileContent(token, conn.repoFullName, path, conn.defaultBranch).catch(() => null);
3130
+ if (existing && existing.trim().length > 0) {
3131
+ logger.info({ path }, '[create-pr] merging new tests into existing spec file');
3132
+ content = mergeSpecContent(existing, s.code);
3133
+ }
3134
+ }
3135
+
3136
+ return { path, content };
3137
+ }));
3125
3138
 
3126
3139
  if (files.length === 0) throw new Error('No scripts to push.');
3127
3140