@yasserkhanorg/e2e-agents 1.5.0 → 1.7.0
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/cli/commands/train.d.ts.map +1 -1
- package/dist/cli/commands/train.js +125 -50
- package/dist/cli/parse_args.d.ts.map +1 -1
- package/dist/cli/parse_args.js +3 -0
- package/dist/cli/types.d.ts +3 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/esm/cli/commands/train.js +125 -50
- package/dist/esm/cli/parse_args.js +3 -0
- package/dist/esm/logger.js +29 -2
- package/dist/esm/pipeline/orchestrator.js +17 -3
- package/dist/esm/training/enricher.js +82 -11
- package/dist/esm/training/merger.js +77 -10
- package/dist/esm/training/scanner.js +523 -2
- package/dist/esm/training/validator.js +58 -2
- package/dist/logger.d.ts +9 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +29 -2
- package/dist/pipeline/orchestrator.d.ts.map +1 -1
- package/dist/pipeline/orchestrator.js +17 -3
- package/dist/training/enricher.d.ts +3 -1
- package/dist/training/enricher.d.ts.map +1 -1
- package/dist/training/enricher.js +82 -11
- package/dist/training/merger.d.ts +11 -1
- package/dist/training/merger.d.ts.map +1 -1
- package/dist/training/merger.js +77 -10
- package/dist/training/scanner.d.ts +28 -2
- package/dist/training/scanner.d.ts.map +1 -1
- package/dist/training/scanner.js +527 -2
- package/dist/training/types.d.ts +8 -0
- package/dist/training/types.d.ts.map +1 -1
- package/dist/training/validator.d.ts +5 -0
- package/dist/training/validator.d.ts.map +1 -1
- package/dist/training/validator.js +59 -2
- package/package.json +1 -1
|
@@ -15,6 +15,50 @@ const SKIP_DIRS = new Set([
|
|
|
15
15
|
]);
|
|
16
16
|
const TEST_EXTENSIONS = ['.spec.ts', '.test.ts', '.spec.js', '.test.js', '.spec.tsx', '.test.tsx'];
|
|
17
17
|
const GO_TEST_SUFFIX = '_test.go';
|
|
18
|
+
/**
|
|
19
|
+
* Test category directories that organize tests but aren't feature families.
|
|
20
|
+
* Test-only families matching these names are excluded.
|
|
21
|
+
*/
|
|
22
|
+
const TEST_CATEGORY_DIRS = new Set([
|
|
23
|
+
'specs', 'spec', 'accessibility', 'visual', 'smoke', 'regression',
|
|
24
|
+
'integration', 'functional', 'unit', 'e2e', 'performance', 'load',
|
|
25
|
+
]);
|
|
26
|
+
/**
|
|
27
|
+
* Structural directories that are code-organization concerns, not feature families.
|
|
28
|
+
* Discovered source dirs matching these names are excluded from family creation.
|
|
29
|
+
*/
|
|
30
|
+
const STRUCTURAL_DIRS = new Set([
|
|
31
|
+
'actions', 'client', 'components', 'hooks', 'i18n', 'packages',
|
|
32
|
+
'reducers', 'selectors', 'store', 'stores', 'tests', 'types',
|
|
33
|
+
'utils', 'helpers', 'lib', 'common', 'shared', 'constants',
|
|
34
|
+
'config', 'styles', 'sass', 'css', 'assets', 'images', 'fonts',
|
|
35
|
+
'middleware', 'contexts', 'providers', 'layouts', 'templates',
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* Server Go files that are infrastructure / cross-cutting concerns,
|
|
39
|
+
* not feature-specific domains. Matched after stripping _local/_store suffixes.
|
|
40
|
+
*/
|
|
41
|
+
const SERVER_INFRA_FILES = new Set([
|
|
42
|
+
'api', 'apitestlib', 'context', 'helpers', 'params', 'swagger',
|
|
43
|
+
'app', 'server', 'enterprise', 'product_service', 'security_update_check',
|
|
44
|
+
'store', 'adapters', 'errors', 'integrity', 'migrate', 'doc',
|
|
45
|
+
'main', 'init', 'cluster_discovery', 'web_conn', 'web_broadcast_hooks',
|
|
46
|
+
'manualtesting', 'testlib', 'router', 'handler', 'opentracing',
|
|
47
|
+
'platform', 'focalboard', 'playbooks', 'client4', 'model',
|
|
48
|
+
'manifest', 'permission', 'log', 'utils',
|
|
49
|
+
]);
|
|
50
|
+
/**
|
|
51
|
+
* Server tier directories to scan for Go domain files.
|
|
52
|
+
* Each tier represents a layer of the backend architecture.
|
|
53
|
+
*/
|
|
54
|
+
const SERVER_TIERS = [
|
|
55
|
+
'channels/api4',
|
|
56
|
+
'channels/app',
|
|
57
|
+
'channels/store/sqlstore',
|
|
58
|
+
'channels/web',
|
|
59
|
+
'channels/wsapi',
|
|
60
|
+
'public/model',
|
|
61
|
+
];
|
|
18
62
|
/** Type-safe includes check for readonly arrays */
|
|
19
63
|
const includes = (arr, v) => arr.includes(v);
|
|
20
64
|
function isSkipped(name) {
|
|
@@ -314,10 +358,385 @@ function detectFeatures(familyId, group, projectRoot) {
|
|
|
314
358
|
}
|
|
315
359
|
return features;
|
|
316
360
|
}
|
|
317
|
-
|
|
361
|
+
/**
|
|
362
|
+
* Discover families by walking the test directory tree at depth ≥ 2.
|
|
363
|
+
*
|
|
364
|
+
* This is the primary family discovery mechanism for projects where source
|
|
365
|
+
* code is organized by code type (components/, actions/) but tests are
|
|
366
|
+
* organized by feature (channels/drafts/, channels/search/).
|
|
367
|
+
*
|
|
368
|
+
* Each leaf test directory (containing spec files) at meaningful depth ≥ 2
|
|
369
|
+
* becomes a candidate family. Top-level feature dirs (depth 1) are already
|
|
370
|
+
* discovered by the standard `discoverTestDirs` + `groupByFamily` pipeline.
|
|
371
|
+
*/
|
|
372
|
+
/**
|
|
373
|
+
* Normalize a Go filename into a family domain identifier.
|
|
374
|
+
* Strips _local, _store, trailing 's' (plurals), and normalizes casing.
|
|
375
|
+
*/
|
|
376
|
+
function normalizeServerDomain(baseName) {
|
|
377
|
+
let name = baseName;
|
|
378
|
+
// Strip common suffixes
|
|
379
|
+
name = name.replace(/_local$/, '');
|
|
380
|
+
name = name.replace(/_store$/, '');
|
|
381
|
+
// Skip very short names (e.g., single-letter files)
|
|
382
|
+
if (name.length < 3)
|
|
383
|
+
return null;
|
|
384
|
+
return normalizeId(name);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Given a domain name like "channel_bookmark", find its parent domain
|
|
388
|
+
* if a shorter prefix exists in the set (e.g., "channel").
|
|
389
|
+
* This groups related server files under a single family.
|
|
390
|
+
*/
|
|
391
|
+
function findParentDomain(name, allDomains) {
|
|
392
|
+
const parts = name.split('_');
|
|
393
|
+
// Try progressively shorter prefixes
|
|
394
|
+
for (let i = parts.length - 1; i >= 1; i--) {
|
|
395
|
+
const candidate = parts.slice(0, i).join('_');
|
|
396
|
+
if (allDomains.has(candidate) && candidate !== name) {
|
|
397
|
+
return candidate;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return name;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Discover families by scanning server Go source files.
|
|
404
|
+
*
|
|
405
|
+
* The backend follows a three-tier pattern:
|
|
406
|
+
* api4/draft.go + app/draft.go + store/sqlstore/draft_store.go
|
|
407
|
+
*
|
|
408
|
+
* Related files are grouped under parent domains:
|
|
409
|
+
* channel.go, channel_bookmark.go, channel_category.go → "channel" family
|
|
410
|
+
*
|
|
411
|
+
* Each domain becomes a candidate family with precise serverPaths.
|
|
412
|
+
*/
|
|
413
|
+
export function discoverServerDerivedFamilies(serverRoot) {
|
|
414
|
+
const resolved = resolve(serverRoot);
|
|
415
|
+
// First pass: collect all raw domain names across tiers
|
|
416
|
+
const allRawDomains = new Set();
|
|
417
|
+
// domain → tier → Set<file basenames>
|
|
418
|
+
const domainTierFiles = new Map();
|
|
419
|
+
function collectGoFile(entry, tierRelPath) {
|
|
420
|
+
if (!entry.endsWith('.go') || entry.endsWith('_test.go') || entry.startsWith('.'))
|
|
421
|
+
return;
|
|
422
|
+
const baseName = entry.replace('.go', '');
|
|
423
|
+
const domain = normalizeServerDomain(baseName);
|
|
424
|
+
if (!domain || SERVER_INFRA_FILES.has(domain))
|
|
425
|
+
return;
|
|
426
|
+
allRawDomains.add(domain);
|
|
427
|
+
if (!domainTierFiles.has(domain))
|
|
428
|
+
domainTierFiles.set(domain, new Map());
|
|
429
|
+
const tierMap = domainTierFiles.get(domain);
|
|
430
|
+
if (!tierMap.has(tierRelPath))
|
|
431
|
+
tierMap.set(tierRelPath, new Set());
|
|
432
|
+
tierMap.get(tierRelPath).add(baseName);
|
|
433
|
+
}
|
|
434
|
+
for (const tier of SERVER_TIERS) {
|
|
435
|
+
const tierPath = join(resolved, tier);
|
|
436
|
+
if (!existsSync(tierPath))
|
|
437
|
+
continue;
|
|
438
|
+
let entries;
|
|
439
|
+
try {
|
|
440
|
+
entries = readdirSync(tierPath);
|
|
441
|
+
}
|
|
442
|
+
catch {
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
for (const entry of entries) {
|
|
446
|
+
collectGoFile(entry, tier);
|
|
447
|
+
// Also check subdirectories (e.g., app/slashcommands/, app/users/)
|
|
448
|
+
const subPath = join(tierPath, entry);
|
|
449
|
+
try {
|
|
450
|
+
const stat = lstatSync(subPath);
|
|
451
|
+
if (stat.isDirectory() && !isSkipped(entry)) {
|
|
452
|
+
const subEntries = readdirSync(subPath);
|
|
453
|
+
for (const subEntry of subEntries) {
|
|
454
|
+
collectGoFile(subEntry, `${tier}/${entry}`);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
catch { /* skip */ }
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
// Scan job directories — each subdirectory is a job type
|
|
462
|
+
const jobsPath = join(resolved, 'channels/jobs');
|
|
463
|
+
if (existsSync(jobsPath)) {
|
|
464
|
+
try {
|
|
465
|
+
for (const entry of readdirSync(jobsPath)) {
|
|
466
|
+
const jobPath = join(jobsPath, entry);
|
|
467
|
+
try {
|
|
468
|
+
if (!lstatSync(jobPath).isDirectory() || isSkipped(entry))
|
|
469
|
+
continue;
|
|
470
|
+
const domain = normalizeId(entry);
|
|
471
|
+
if (SERVER_INFRA_FILES.has(domain))
|
|
472
|
+
continue;
|
|
473
|
+
allRawDomains.add(domain);
|
|
474
|
+
const jobFiles = readdirSync(jobPath);
|
|
475
|
+
for (const jf of jobFiles) {
|
|
476
|
+
if (jf.endsWith('.go') && !jf.endsWith('_test.go')) {
|
|
477
|
+
if (!domainTierFiles.has(domain))
|
|
478
|
+
domainTierFiles.set(domain, new Map());
|
|
479
|
+
const tierMap = domainTierFiles.get(domain);
|
|
480
|
+
const tierKey = `channels/jobs/${entry}`;
|
|
481
|
+
if (!tierMap.has(tierKey))
|
|
482
|
+
tierMap.set(tierKey, new Set());
|
|
483
|
+
tierMap.get(tierKey).add(jf.replace('.go', ''));
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
catch { /* skip */ }
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
catch { /* skip */ }
|
|
491
|
+
}
|
|
492
|
+
// Second pass: group child domains under parents
|
|
493
|
+
// e.g., channel_bookmark → channel, post_priority → post
|
|
494
|
+
// Track which top-level tiers each family touches for significance filtering.
|
|
495
|
+
const familyPaths = new Map();
|
|
496
|
+
const familyTiers = new Map();
|
|
497
|
+
for (const [domain, tierMap] of domainTierFiles) {
|
|
498
|
+
const parentDomain = findParentDomain(domain, allRawDomains);
|
|
499
|
+
if (!familyPaths.has(parentDomain))
|
|
500
|
+
familyPaths.set(parentDomain, new Set());
|
|
501
|
+
if (!familyTiers.has(parentDomain))
|
|
502
|
+
familyTiers.set(parentDomain, new Set());
|
|
503
|
+
const paths = familyPaths.get(parentDomain);
|
|
504
|
+
const tiers = familyTiers.get(parentDomain);
|
|
505
|
+
for (const [tierRelPath, fileNames] of tierMap) {
|
|
506
|
+
// Track the top-level tier (e.g., "channels/api4" from "channels/api4/slashcommands")
|
|
507
|
+
const topTier = tierRelPath.split('/').slice(0, 2).join('/');
|
|
508
|
+
tiers.add(topTier);
|
|
509
|
+
for (const baseName of fileNames) {
|
|
510
|
+
// Use directory-level glob to capture the file and related variants
|
|
511
|
+
paths.add(`server/${tierRelPath}/${baseName}*.go`);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
// Build families from grouped domains.
|
|
516
|
+
// Multi-tier families (≥2 tiers) can be new families.
|
|
517
|
+
// Single-tier families can only merge into existing families.
|
|
518
|
+
const multiTierFamilies = [];
|
|
519
|
+
const singleTierFamilies = [];
|
|
520
|
+
for (const [domain, paths] of familyPaths) {
|
|
521
|
+
if (paths.size === 0)
|
|
522
|
+
continue;
|
|
523
|
+
const tierCount = familyTiers.get(domain)?.size ?? 0;
|
|
524
|
+
const family = {
|
|
525
|
+
id: domain,
|
|
526
|
+
routes: [`/${domain.replace(/_/g, '-')}`],
|
|
527
|
+
webappPaths: [],
|
|
528
|
+
serverPaths: Array.from(paths),
|
|
529
|
+
specDirs: [],
|
|
530
|
+
cypressSpecDirs: [],
|
|
531
|
+
tags: [],
|
|
532
|
+
features: [],
|
|
533
|
+
routesGuessed: true,
|
|
534
|
+
};
|
|
535
|
+
if (tierCount >= 2) {
|
|
536
|
+
multiTierFamilies.push(family);
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
singleTierFamilies.push(family);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return { multiTierFamilies, singleTierFamilies };
|
|
543
|
+
}
|
|
544
|
+
export function discoverTestDerivedFamilies(testsRoot) {
|
|
545
|
+
const resolved = resolve(testsRoot);
|
|
546
|
+
const candidates = [];
|
|
547
|
+
function walk(dir, depth) {
|
|
548
|
+
if (depth > 8)
|
|
549
|
+
return;
|
|
550
|
+
let entries;
|
|
551
|
+
try {
|
|
552
|
+
entries = readdirSync(dir);
|
|
553
|
+
}
|
|
554
|
+
catch {
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
const hasSpecs = entries.some((e) => TEST_EXTENSIONS.some((ext) => e.endsWith(ext)) || e.endsWith(GO_TEST_SUFFIX));
|
|
558
|
+
const subdirs = entries.filter((e) => {
|
|
559
|
+
if (isSkipped(e))
|
|
560
|
+
return false;
|
|
561
|
+
try {
|
|
562
|
+
const stat = lstatSync(join(dir, e));
|
|
563
|
+
return !stat.isSymbolicLink() && stat.isDirectory();
|
|
564
|
+
}
|
|
565
|
+
catch {
|
|
566
|
+
return false;
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
const relPath = relative(resolved, dir).replace(/\\/g, '/');
|
|
570
|
+
const parts = relPath.split('/').filter(Boolean);
|
|
571
|
+
const meaningful = parts.filter((p) => !TEST_CATEGORY_DIRS.has(normalizeId(p)) && !isSkipped(p));
|
|
572
|
+
// Depth-2+ meaningful dirs with spec files → candidate families
|
|
573
|
+
if (meaningful.length >= 2 && hasSpecs) {
|
|
574
|
+
const leafId = normalizeId(meaningful[meaningful.length - 1]);
|
|
575
|
+
const parentId = normalizeId(meaningful[meaningful.length - 2]);
|
|
576
|
+
if (!STRUCTURAL_DIRS.has(leafId) && !TEST_CATEGORY_DIRS.has(leafId)) {
|
|
577
|
+
candidates.push({ dir, relPath, leafId, parentId });
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
for (const sub of subdirs) {
|
|
581
|
+
walk(join(dir, sub), depth + 1);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
// Walk from standard test roots
|
|
585
|
+
const testRoots = ['tests', 'test', 'e2e-tests', 'e2e', 'specs', 'spec'];
|
|
586
|
+
for (const root of testRoots) {
|
|
587
|
+
const rootPath = join(resolved, root);
|
|
588
|
+
if (existsSync(rootPath)) {
|
|
589
|
+
walk(rootPath, 0);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
// Detect leaf-name collisions across parents
|
|
593
|
+
const idCount = new Map();
|
|
594
|
+
for (const c of candidates) {
|
|
595
|
+
idCount.set(c.leafId, (idCount.get(c.leafId) || 0) + 1);
|
|
596
|
+
}
|
|
597
|
+
// Build families — prefix with parent when names collide
|
|
598
|
+
const familyMap = new Map();
|
|
599
|
+
for (const c of candidates) {
|
|
600
|
+
let familyId = c.leafId;
|
|
601
|
+
if ((idCount.get(c.leafId) || 0) > 1 && c.parentId) {
|
|
602
|
+
familyId = `${c.parentId}_${c.leafId}`;
|
|
603
|
+
}
|
|
604
|
+
if (!familyMap.has(familyId)) {
|
|
605
|
+
const specFiles = getSpecFiles(c.dir);
|
|
606
|
+
familyMap.set(familyId, {
|
|
607
|
+
id: familyId,
|
|
608
|
+
routes: [`/${familyId.replace(/_/g, '-')}`],
|
|
609
|
+
webappPaths: [],
|
|
610
|
+
serverPaths: [],
|
|
611
|
+
specDirs: [c.relPath + '/'],
|
|
612
|
+
cypressSpecDirs: [],
|
|
613
|
+
tags: extractTags(specFiles),
|
|
614
|
+
features: [],
|
|
615
|
+
routesGuessed: true,
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
const existing = familyMap.get(familyId);
|
|
620
|
+
const specDir = c.relPath + '/';
|
|
621
|
+
if (!existing.specDirs.includes(specDir)) {
|
|
622
|
+
existing.specDirs.push(specDir);
|
|
623
|
+
existing.tags = [...new Set([...existing.tags, ...extractTags(getSpecFiles(c.dir))])];
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
return Array.from(familyMap.values());
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Discover test library paths (page objects, helpers) organized by feature.
|
|
631
|
+
* Walks well-known test lib directories and maps subdirectories to family IDs.
|
|
632
|
+
*/
|
|
633
|
+
export function discoverTestLibPaths(testsRoot) {
|
|
634
|
+
const resolved = resolve(testsRoot);
|
|
635
|
+
const result = new Map();
|
|
636
|
+
const libDirs = [
|
|
637
|
+
'lib/src/ui/components',
|
|
638
|
+
'lib/src/ui/pages',
|
|
639
|
+
'lib/src/server',
|
|
640
|
+
];
|
|
641
|
+
for (const libDir of libDirs) {
|
|
642
|
+
const fullDir = join(resolved, libDir);
|
|
643
|
+
if (!existsSync(fullDir))
|
|
644
|
+
continue;
|
|
645
|
+
let entries;
|
|
646
|
+
try {
|
|
647
|
+
entries = readdirSync(fullDir);
|
|
648
|
+
}
|
|
649
|
+
catch {
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
for (const entry of entries) {
|
|
653
|
+
if (isSkipped(entry))
|
|
654
|
+
continue;
|
|
655
|
+
const fullPath = join(fullDir, entry);
|
|
656
|
+
try {
|
|
657
|
+
const stat = lstatSync(fullPath);
|
|
658
|
+
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
catch {
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
const familyId = normalizeId(entry);
|
|
665
|
+
const relPath = relative(resolved, fullPath).replace(/\\/g, '/');
|
|
666
|
+
const pattern = `${relPath}/*`;
|
|
667
|
+
if (!result.has(familyId))
|
|
668
|
+
result.set(familyId, []);
|
|
669
|
+
result.get(familyId).push(pattern);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return result;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Discover files in well-known directories (types, utils) whose basename
|
|
676
|
+
* maps directly to a family ID.
|
|
677
|
+
*/
|
|
678
|
+
export function discoverNameMatchedPaths(appPath, gitRepoRoot) {
|
|
679
|
+
const result = new Map();
|
|
680
|
+
const resolvedApp = resolve(appPath);
|
|
681
|
+
const scanRoots = [
|
|
682
|
+
{ root: join(resolvedApp, 'src/utils'), base: resolvedApp },
|
|
683
|
+
{ root: join(resolvedApp, 'src/types'), base: resolvedApp },
|
|
684
|
+
];
|
|
685
|
+
// Monorepo-aware: scan platform types directory
|
|
686
|
+
if (gitRepoRoot) {
|
|
687
|
+
const resolvedGitRoot = resolve(gitRepoRoot);
|
|
688
|
+
const platformTypes = join(resolvedGitRoot, 'webapp/platform/types/src');
|
|
689
|
+
if (existsSync(platformTypes)) {
|
|
690
|
+
scanRoots.push({ root: platformTypes, base: resolvedGitRoot });
|
|
691
|
+
}
|
|
692
|
+
const platformClient = join(resolvedGitRoot, 'webapp/platform/client/src');
|
|
693
|
+
if (existsSync(platformClient)) {
|
|
694
|
+
scanRoots.push({ root: platformClient, base: resolvedGitRoot });
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
for (const { root, base } of scanRoots) {
|
|
698
|
+
if (!existsSync(root))
|
|
699
|
+
continue;
|
|
700
|
+
let entries;
|
|
701
|
+
try {
|
|
702
|
+
entries = readdirSync(root);
|
|
703
|
+
}
|
|
704
|
+
catch {
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
for (const entry of entries) {
|
|
708
|
+
if (entry.startsWith('.'))
|
|
709
|
+
continue;
|
|
710
|
+
const ext = entry.slice(entry.lastIndexOf('.'));
|
|
711
|
+
if (!['.ts', '.tsx', '.js', '.jsx'].includes(ext))
|
|
712
|
+
continue;
|
|
713
|
+
const fullPath = join(root, entry);
|
|
714
|
+
try {
|
|
715
|
+
const stat = lstatSync(fullPath);
|
|
716
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
catch {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
// Strip extension and normalize
|
|
723
|
+
const baseName = entry.slice(0, entry.lastIndexOf('.'));
|
|
724
|
+
const familyId = normalizeId(baseName);
|
|
725
|
+
if (familyId.length < 3)
|
|
726
|
+
continue;
|
|
727
|
+
const relPath = relative(base, fullPath).replace(/\\/g, '/');
|
|
728
|
+
if (!result.has(familyId))
|
|
729
|
+
result.set(familyId, []);
|
|
730
|
+
result.get(familyId).push(relPath);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return result;
|
|
734
|
+
}
|
|
735
|
+
export function scanProject(projectRoot, testsRoot, serverRoot, gitRepoRoot) {
|
|
318
736
|
const resolved = resolve(projectRoot);
|
|
737
|
+
const resolvedTestsRoot = testsRoot ? resolve(testsRoot) : resolved;
|
|
319
738
|
const sourceDirs = discoverSourceDirs(resolved);
|
|
320
|
-
const testDirs = discoverTestDirs(
|
|
739
|
+
const testDirs = discoverTestDirs(resolvedTestsRoot);
|
|
321
740
|
const allDirs = [...sourceDirs, ...testDirs];
|
|
322
741
|
const groups = groupByFamily(allDirs);
|
|
323
742
|
const families = [];
|
|
@@ -326,6 +745,13 @@ export function scanProject(projectRoot) {
|
|
|
326
745
|
const hasTests = group.test.length > 0 || group.cypress.length > 0;
|
|
327
746
|
if (!hasSrc && !hasTests)
|
|
328
747
|
continue;
|
|
748
|
+
// Skip structural directories that are code-organization, not features.
|
|
749
|
+
// Only skip if they have source dirs but no corresponding test dirs.
|
|
750
|
+
if (STRUCTURAL_DIRS.has(familyId) && !hasTests)
|
|
751
|
+
continue;
|
|
752
|
+
// Skip test-only families that match broad test categories (not feature families).
|
|
753
|
+
if (!hasSrc && hasTests && TEST_CATEGORY_DIRS.has(familyId))
|
|
754
|
+
continue;
|
|
329
755
|
const allSpecFiles = [];
|
|
330
756
|
for (const td of [...group.test, ...group.cypress]) {
|
|
331
757
|
allSpecFiles.push(...getSpecFiles(td.path));
|
|
@@ -343,6 +769,101 @@ export function scanProject(projectRoot) {
|
|
|
343
769
|
routesGuessed: true,
|
|
344
770
|
});
|
|
345
771
|
}
|
|
772
|
+
// When a separate testsRoot is provided, discover families from test
|
|
773
|
+
// directory structure. Projects with feature-organized tests but
|
|
774
|
+
// code-type-organized source benefit from this.
|
|
775
|
+
if (testsRoot) {
|
|
776
|
+
const testFamilies = discoverTestDerivedFamilies(resolvedTestsRoot);
|
|
777
|
+
const existingIds = new Set(families.map((f) => f.id));
|
|
778
|
+
for (const tf of testFamilies) {
|
|
779
|
+
if (existingIds.has(tf.id)) {
|
|
780
|
+
// Merge specDirs into existing family
|
|
781
|
+
const existing = families.find((f) => f.id === tf.id);
|
|
782
|
+
for (const sd of tf.specDirs) {
|
|
783
|
+
if (!existing.specDirs.includes(sd)) {
|
|
784
|
+
existing.specDirs.push(sd);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
existing.tags = [...new Set([...existing.tags, ...tf.tags])];
|
|
788
|
+
}
|
|
789
|
+
else {
|
|
790
|
+
families.push(tf);
|
|
791
|
+
existingIds.add(tf.id);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
// When a separate serverRoot is provided, discover families from Go source
|
|
796
|
+
// filenames across the three-tier backend (api4, app, store).
|
|
797
|
+
if (serverRoot) {
|
|
798
|
+
const { multiTierFamilies: serverMulti, singleTierFamilies: serverSingle } = discoverServerDerivedFamilies(resolve(serverRoot));
|
|
799
|
+
const existingIds = new Set(families.map((f) => f.id));
|
|
800
|
+
// Merge ALL server families (multi + single tier) into existing families,
|
|
801
|
+
// but only add NEW families if they span ≥2 tiers.
|
|
802
|
+
const allServerFamilies = [...serverMulti, ...serverSingle];
|
|
803
|
+
for (const sf of allServerFamilies) {
|
|
804
|
+
// Try exact match, then singular/plural variants
|
|
805
|
+
let target = families.find((f) => f.id === sf.id);
|
|
806
|
+
if (!target && !sf.id.endsWith('s')) {
|
|
807
|
+
target = families.find((f) => f.id === sf.id + 's');
|
|
808
|
+
}
|
|
809
|
+
if (!target && sf.id.endsWith('s')) {
|
|
810
|
+
target = families.find((f) => f.id === sf.id.slice(0, -1));
|
|
811
|
+
}
|
|
812
|
+
if (target) {
|
|
813
|
+
// Merge serverPaths into existing family
|
|
814
|
+
for (const sp of sf.serverPaths) {
|
|
815
|
+
if (!target.serverPaths.includes(sp)) {
|
|
816
|
+
target.serverPaths.push(sp);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
else if (serverMulti.includes(sf)) {
|
|
821
|
+
// Only add new families if they span ≥2 tiers
|
|
822
|
+
families.push(sf);
|
|
823
|
+
existingIds.add(sf.id);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
// Merge test library paths (page objects, helpers) into existing families
|
|
828
|
+
if (testsRoot) {
|
|
829
|
+
const testLibPaths = discoverTestLibPaths(resolvedTestsRoot);
|
|
830
|
+
for (const [libFamilyId, patterns] of testLibPaths) {
|
|
831
|
+
let target = families.find((f) => f.id === libFamilyId);
|
|
832
|
+
if (!target && !libFamilyId.endsWith('s')) {
|
|
833
|
+
target = families.find((f) => f.id === libFamilyId + 's');
|
|
834
|
+
}
|
|
835
|
+
if (!target && libFamilyId.endsWith('s')) {
|
|
836
|
+
target = families.find((f) => f.id === libFamilyId.slice(0, -1));
|
|
837
|
+
}
|
|
838
|
+
if (target) {
|
|
839
|
+
for (const p of patterns) {
|
|
840
|
+
if (!target.webappPaths.includes(p)) {
|
|
841
|
+
target.webappPaths.push(p);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
// Merge name-matched type/util files into existing families
|
|
848
|
+
{
|
|
849
|
+
const nameMatchedPaths = discoverNameMatchedPaths(resolved, gitRepoRoot);
|
|
850
|
+
for (const [nmFamilyId, paths] of nameMatchedPaths) {
|
|
851
|
+
let target = families.find((f) => f.id === nmFamilyId);
|
|
852
|
+
if (!target && !nmFamilyId.endsWith('s')) {
|
|
853
|
+
target = families.find((f) => f.id === nmFamilyId + 's');
|
|
854
|
+
}
|
|
855
|
+
if (!target && nmFamilyId.endsWith('s')) {
|
|
856
|
+
target = families.find((f) => f.id === nmFamilyId.slice(0, -1));
|
|
857
|
+
}
|
|
858
|
+
if (target) {
|
|
859
|
+
for (const p of paths) {
|
|
860
|
+
if (!target.webappPaths.includes(p)) {
|
|
861
|
+
target.webappPaths.push(p);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
346
867
|
const familyIds = new Set(families.map((f) => f.id));
|
|
347
868
|
const unmatchedSourceDirs = sourceDirs.filter((d) => !familyIds.has(normalizeId(d.familyHint)));
|
|
348
869
|
const unmatchedTestDirs = testDirs.filter((d) => !familyIds.has(normalizeId(d.familyHint)));
|
|
@@ -3,6 +3,62 @@
|
|
|
3
3
|
import { execFileSync } from 'child_process';
|
|
4
4
|
import { resolve } from 'path';
|
|
5
5
|
import { bindFilesToFamilies } from '../knowledge/route_families.js';
|
|
6
|
+
/**
|
|
7
|
+
* Glob-style patterns for infrastructure / cross-cutting files that will never
|
|
8
|
+
* belong to a single route family. Excluded from coverage calculations.
|
|
9
|
+
*/
|
|
10
|
+
const INFRA_GLOBS = [
|
|
11
|
+
'Makefile', 'go.mod', 'go.sum',
|
|
12
|
+
'*.lock',
|
|
13
|
+
'**/mocks/*', '**/storetest/*', '**/testlib/*',
|
|
14
|
+
'**/i18n/*',
|
|
15
|
+
'**/.github/*', '**/scripts/*',
|
|
16
|
+
'**/docker-compose*',
|
|
17
|
+
'**/__fixtures__/*', '**/test_templates/*',
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Check if a file path matches any infrastructure glob pattern.
|
|
21
|
+
* Uses simple string matching — no external glob library needed.
|
|
22
|
+
*/
|
|
23
|
+
export function isInfraFile(filePath) {
|
|
24
|
+
const normalized = filePath.replace(/\\/g, '/');
|
|
25
|
+
for (const pattern of INFRA_GLOBS) {
|
|
26
|
+
if (pattern.startsWith('**/')) {
|
|
27
|
+
// Match anywhere in the path
|
|
28
|
+
const suffix = pattern.slice(3);
|
|
29
|
+
if (suffix.endsWith('/*')) {
|
|
30
|
+
// Directory match: **/mocks/* → any segment named "mocks" with a child
|
|
31
|
+
const dirName = suffix.slice(0, -2);
|
|
32
|
+
if (normalized.includes(`/${dirName}/`) || normalized.startsWith(`${dirName}/`))
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
else if (suffix.endsWith('*')) {
|
|
36
|
+
// Prefix match: **/docker-compose* → file starting with docker-compose
|
|
37
|
+
const prefix = suffix.slice(0, -1);
|
|
38
|
+
const base = normalized.split('/').pop() || '';
|
|
39
|
+
if (base.startsWith(prefix))
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
if (normalized.endsWith(`/${suffix}`) || normalized === suffix)
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (pattern.startsWith('*.')) {
|
|
48
|
+
// Extension match: *.lock
|
|
49
|
+
const ext = pattern.slice(1);
|
|
50
|
+
if (normalized.endsWith(ext))
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// Exact basename match: Makefile, go.mod, go.sum
|
|
55
|
+
const base = normalized.split('/').pop() || '';
|
|
56
|
+
if (base === pattern)
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
6
62
|
export function parseGitLog(log) {
|
|
7
63
|
const commits = [];
|
|
8
64
|
let current = null;
|
|
@@ -49,10 +105,10 @@ export function getCommitFiles(projectRoot, since) {
|
|
|
49
105
|
return parseGitLog(log);
|
|
50
106
|
}
|
|
51
107
|
export function validateCommit(manifest, files, hash, message) {
|
|
52
|
-
// Filter out non-source files
|
|
108
|
+
// Filter out non-source files and infrastructure files
|
|
53
109
|
const sourceFiles = files.filter((f) => {
|
|
54
110
|
return !f.endsWith('.md') && !f.endsWith('.json') && !f.endsWith('.yml') && !f.endsWith('.yaml') &&
|
|
55
|
-
!f.startsWith('.') && !f.includes('node_modules/');
|
|
111
|
+
!f.startsWith('.') && !f.includes('node_modules/') && !isInfraFile(f);
|
|
56
112
|
});
|
|
57
113
|
if (sourceFiles.length === 0) {
|
|
58
114
|
return { hash, message, changedFiles: [], boundFiles: 0, unboundFiles: [], familiesHit: [] };
|
package/dist/logger.d.ts
CHANGED
|
@@ -11,12 +11,21 @@ export declare enum LogLevel {
|
|
|
11
11
|
}
|
|
12
12
|
export declare class Logger {
|
|
13
13
|
private level;
|
|
14
|
+
private jsonMode;
|
|
14
15
|
constructor(minLevel?: LogLevel);
|
|
15
16
|
error(message: string, context?: Record<string, unknown>): void;
|
|
16
17
|
warn(message: string, context?: Record<string, unknown>): void;
|
|
17
18
|
info(message: string, context?: Record<string, unknown>): void;
|
|
18
19
|
debug(message: string, context?: Record<string, unknown>): void;
|
|
19
20
|
setLevel(level: LogLevel): void;
|
|
21
|
+
setJsonMode(enabled: boolean): void;
|
|
22
|
+
/**
|
|
23
|
+
* Start a timer for measuring duration of an operation.
|
|
24
|
+
* Returns an object with `end()` that logs at DEBUG level and returns elapsed ms.
|
|
25
|
+
*/
|
|
26
|
+
timer(label: string): {
|
|
27
|
+
end: () => number;
|
|
28
|
+
};
|
|
20
29
|
private log;
|
|
21
30
|
}
|
|
22
31
|
export declare const logger: Logger;
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,oBAAY,QAAQ;IAChB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACZ;AAqCD,qBAAa,MAAM;IACf,OAAO,CAAC,KAAK,CAAW;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH,oBAAY,QAAQ;IAChB,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACZ;AAqCD,qBAAa,MAAM;IACf,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,QAAQ,CAAU;gBAEd,QAAQ,CAAC,EAAE,QAAQ;IAK/B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAM/D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAM9D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAM9D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAM/D,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAInC;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG;QAAC,GAAG,EAAE,MAAM,MAAM,CAAA;KAAC;IAWzC,OAAO,CAAC,GAAG;CAoBd;AAGD,eAAO,MAAM,MAAM,QAAe,CAAC"}
|