@qulib/core 0.4.1 → 0.4.3

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.
Files changed (135) hide show
  1. package/README.md +56 -8
  2. package/dist/analyze.d.ts.map +1 -1
  3. package/dist/analyze.js +86 -7
  4. package/dist/cli/auth-login-resolve.d.ts +14 -0
  5. package/dist/cli/auth-login-resolve.d.ts.map +1 -0
  6. package/dist/cli/auth-login-resolve.js +68 -0
  7. package/dist/cli/auth-login-run.d.ts +13 -0
  8. package/dist/cli/auth-login-run.d.ts.map +1 -0
  9. package/dist/cli/auth-login-run.js +152 -0
  10. package/dist/cli/index.js +60 -7
  11. package/dist/harness/state-manager.d.ts +10 -0
  12. package/dist/harness/state-manager.d.ts.map +1 -1
  13. package/dist/harness/state-manager.js +15 -0
  14. package/dist/index.d.ts +8 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +7 -6
  17. package/dist/phases/act.js +3 -3
  18. package/dist/phases/observe.js +5 -5
  19. package/dist/phases/think.js +1 -1
  20. package/dist/schemas/automation-maturity.schema.d.ts +40 -0
  21. package/dist/schemas/automation-maturity.schema.d.ts.map +1 -1
  22. package/dist/schemas/automation-maturity.schema.js +27 -0
  23. package/dist/schemas/index.d.ts +1 -1
  24. package/dist/schemas/index.d.ts.map +1 -1
  25. package/dist/schemas/index.js +1 -1
  26. package/dist/schemas/repo-analysis.schema.d.ts +22 -0
  27. package/dist/schemas/repo-analysis.schema.d.ts.map +1 -1
  28. package/dist/schemas/repo-analysis.schema.js +1 -0
  29. package/dist/telemetry/emit.d.ts +22 -0
  30. package/dist/telemetry/emit.d.ts.map +1 -1
  31. package/dist/telemetry/emit.js +37 -0
  32. package/dist/telemetry/telemetry.interface.d.ts +1 -1
  33. package/dist/telemetry/telemetry.interface.d.ts.map +1 -1
  34. package/dist/tools/apply-auth.d.ts +4 -0
  35. package/dist/tools/apply-auth.d.ts.map +1 -0
  36. package/dist/tools/apply-auth.js +35 -0
  37. package/dist/tools/auth/apply.d.ts +4 -0
  38. package/dist/tools/auth/apply.d.ts.map +1 -0
  39. package/dist/tools/auth/apply.js +35 -0
  40. package/dist/tools/auth/block-gap.d.ts +9 -0
  41. package/dist/tools/auth/block-gap.d.ts.map +1 -0
  42. package/dist/tools/auth/block-gap.js +52 -0
  43. package/dist/tools/auth/custom-providers.d.ts +15 -0
  44. package/dist/tools/auth/custom-providers.d.ts.map +1 -0
  45. package/dist/tools/auth/custom-providers.js +62 -0
  46. package/dist/tools/auth/detect.d.ts +23 -0
  47. package/dist/tools/auth/detect.d.ts.map +1 -0
  48. package/dist/tools/auth/detect.js +526 -0
  49. package/dist/tools/auth/detector.d.ts +23 -0
  50. package/dist/tools/auth/detector.d.ts.map +1 -0
  51. package/dist/tools/auth/detector.js +526 -0
  52. package/dist/tools/auth/explore.d.ts +4 -0
  53. package/dist/tools/auth/explore.d.ts.map +1 -0
  54. package/dist/tools/auth/explore.js +346 -0
  55. package/dist/tools/auth/explorer.d.ts +4 -0
  56. package/dist/tools/auth/explorer.d.ts.map +1 -0
  57. package/dist/tools/auth/explorer.js +346 -0
  58. package/dist/tools/auth/gaps.d.ts +9 -0
  59. package/dist/tools/auth/gaps.d.ts.map +1 -0
  60. package/dist/tools/auth/gaps.js +52 -0
  61. package/dist/tools/auth/oauth-providers.d.ts +7 -0
  62. package/dist/tools/auth/oauth-providers.d.ts.map +1 -0
  63. package/dist/tools/auth/oauth-providers.js +21 -0
  64. package/dist/tools/auth/providers.d.ts +7 -0
  65. package/dist/tools/auth/providers.d.ts.map +1 -0
  66. package/dist/tools/auth/providers.js +21 -0
  67. package/dist/tools/auth/surface-analyzer.d.ts +4 -0
  68. package/dist/tools/auth/surface-analyzer.d.ts.map +1 -0
  69. package/dist/tools/auth/surface-analyzer.js +170 -0
  70. package/dist/tools/auth/surface.d.ts +4 -0
  71. package/dist/tools/auth/surface.d.ts.map +1 -0
  72. package/dist/tools/auth/surface.js +170 -0
  73. package/dist/tools/auth/user-providers.d.ts +15 -0
  74. package/dist/tools/auth/user-providers.d.ts.map +1 -0
  75. package/dist/tools/auth/user-providers.js +62 -0
  76. package/dist/tools/auth-block-gap.d.ts +6 -0
  77. package/dist/tools/auth-block-gap.d.ts.map +1 -1
  78. package/dist/tools/auth-block-gap.js +42 -9
  79. package/dist/tools/auth-detector.d.ts +19 -0
  80. package/dist/tools/auth-detector.d.ts.map +1 -1
  81. package/dist/tools/auth-detector.js +186 -8
  82. package/dist/tools/automation-maturity.d.ts.map +1 -1
  83. package/dist/tools/automation-maturity.js +76 -20
  84. package/dist/tools/explorers/browser.d.ts +3 -0
  85. package/dist/tools/explorers/browser.d.ts.map +1 -0
  86. package/dist/tools/explorers/browser.js +13 -0
  87. package/dist/tools/explorers/cypress-explorer.d.ts +8 -0
  88. package/dist/tools/explorers/cypress-explorer.d.ts.map +1 -0
  89. package/dist/tools/explorers/cypress-explorer.js +5 -0
  90. package/dist/tools/explorers/cypress.d.ts +8 -0
  91. package/dist/tools/explorers/cypress.d.ts.map +1 -0
  92. package/dist/tools/explorers/cypress.js +5 -0
  93. package/dist/tools/explorers/explorer.interface.d.ts +7 -0
  94. package/dist/tools/explorers/explorer.interface.d.ts.map +1 -0
  95. package/dist/tools/explorers/explorer.interface.js +1 -0
  96. package/dist/tools/explorers/factory.d.ts +4 -0
  97. package/dist/tools/explorers/factory.d.ts.map +1 -0
  98. package/dist/tools/explorers/factory.js +12 -0
  99. package/dist/tools/explorers/playwright-explorer.d.ts +8 -0
  100. package/dist/tools/explorers/playwright-explorer.d.ts.map +1 -0
  101. package/dist/tools/explorers/playwright-explorer.js +172 -0
  102. package/dist/tools/explorers/playwright.d.ts +8 -0
  103. package/dist/tools/explorers/playwright.d.ts.map +1 -0
  104. package/dist/tools/explorers/playwright.js +172 -0
  105. package/dist/tools/explorers/types.d.ts +7 -0
  106. package/dist/tools/explorers/types.d.ts.map +1 -0
  107. package/dist/tools/explorers/types.js +1 -0
  108. package/dist/tools/playwright-explorer.js +1 -1
  109. package/dist/tools/repo/detect-framework.d.ts +15 -0
  110. package/dist/tools/repo/detect-framework.d.ts.map +1 -0
  111. package/dist/tools/repo/detect-framework.js +153 -0
  112. package/dist/tools/repo/framework-detector.d.ts +15 -0
  113. package/dist/tools/repo/framework-detector.d.ts.map +1 -0
  114. package/dist/tools/repo/framework-detector.js +153 -0
  115. package/dist/tools/repo/scan.d.ts +19 -0
  116. package/dist/tools/repo/scan.d.ts.map +1 -0
  117. package/dist/tools/repo/scan.js +181 -0
  118. package/dist/tools/repo/scanner.d.ts +19 -0
  119. package/dist/tools/repo/scanner.d.ts.map +1 -0
  120. package/dist/tools/repo/scanner.js +181 -0
  121. package/dist/tools/repo-scanner.d.ts.map +1 -1
  122. package/dist/tools/repo-scanner.js +7 -2
  123. package/dist/tools/scoring/automation-maturity.d.ts +4 -0
  124. package/dist/tools/scoring/automation-maturity.d.ts.map +1 -0
  125. package/dist/tools/scoring/automation-maturity.js +219 -0
  126. package/dist/tools/scoring/gap-engine.d.ts +8 -0
  127. package/dist/tools/scoring/gap-engine.d.ts.map +1 -0
  128. package/dist/tools/scoring/gap-engine.js +138 -0
  129. package/dist/tools/scoring/gaps.d.ts +8 -0
  130. package/dist/tools/scoring/gaps.d.ts.map +1 -0
  131. package/dist/tools/scoring/gaps.js +138 -0
  132. package/dist/tools/scoring/public-surface.d.ts +5 -0
  133. package/dist/tools/scoring/public-surface.d.ts.map +1 -0
  134. package/dist/tools/scoring/public-surface.js +13 -0
  135. package/package.json +3 -3
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @module repo-scanner
3
+ * @packageBoundary @qulib/core (candidate: @qulib/analyzer)
4
+ *
5
+ * This module performs static analysis of a repository's file structure.
6
+ * It is currently embedded in @qulib/core because repo scanning is part of
7
+ * the observe phase and @qulib/core is the only consumer.
8
+ *
9
+ * Extraction to @qulib/analyzer is appropriate when:
10
+ * 1. A consumer needs repo analysis without URL crawling
11
+ * 2. The module grows to include PRD/Jira/Confluence ingestion
12
+ * 3. A standalone CLI command `qulib analyze-repo` is needed
13
+ *
14
+ * Before extraction: ensure RepoAnalysis schema is re-exported from @qulib/analyzer
15
+ * and @qulib/core depends on @qulib/analyzer (not the reverse).
16
+ */
17
+ import { readFile } from 'node:fs/promises';
18
+ import { relative, basename } from 'node:path';
19
+ import glob from 'fast-glob';
20
+ import { RepoAnalysisSchema } from '../../schemas/repo-analysis.schema.js';
21
+ import { detectFramework } from './framework-detector.js';
22
+ import { computeAutomationMaturity } from '../scoring/automation-maturity.js';
23
+ const IGNORE_PATTERNS = ['**/node_modules/**', '**/.next/**', '**/dist/**', '**/build/**'];
24
+ function toPosix(path) {
25
+ return path.split('\\').join('/');
26
+ }
27
+ function normalizeRoutePath(path) {
28
+ const normalized = `/${path}`.replace(/\/+/g, '/').replace(/\/$/, '');
29
+ return normalized === '' ? '/' : normalized;
30
+ }
31
+ function detectTestType(filePath, content) {
32
+ const normalizedPath = toPosix(filePath);
33
+ if (normalizedPath.includes('cypress/e2e'))
34
+ return 'cypress-e2e';
35
+ if (normalizedPath.includes('cypress/component'))
36
+ return 'cypress-component';
37
+ if ((normalizedPath.includes('playwright') || normalizedPath.includes('e2e')) &&
38
+ normalizedPath.endsWith('.spec.ts')) {
39
+ return 'playwright';
40
+ }
41
+ if (/\bfrom\s+['"]vitest['"]|\brequire\(['"]vitest['"]\)/.test(content))
42
+ return 'vitest';
43
+ if (/\bfrom\s+['"]jest['"]|\brequire\(['"]jest['"]\)/.test(content))
44
+ return 'jest';
45
+ return 'other';
46
+ }
47
+ function extractCoveredPaths(content) {
48
+ const matches = [...content.matchAll(/['"`](\/[a-zA-Z0-9\/_\-\[\]]+)['"`]/g)].map((m) => m[1]);
49
+ return [...new Set(matches)];
50
+ }
51
+ export async function scanRepo(repoPath) {
52
+ const routes = [];
53
+ const appRouterFiles = await glob(['app/**/page.tsx', 'app/**/page.ts'], {
54
+ cwd: repoPath,
55
+ onlyFiles: true,
56
+ absolute: true,
57
+ ignore: IGNORE_PATTERNS,
58
+ });
59
+ for (const file of appRouterFiles) {
60
+ const rel = toPosix(relative(repoPath, file));
61
+ const routeSegment = rel.replace(/^app\//, '').replace(/\/page\.tsx?$/, '');
62
+ const routePath = normalizeRoutePath(routeSegment);
63
+ routes.push({ path: routePath, file: rel, method: 'GET' });
64
+ }
65
+ const pagesRouterFiles = await glob(['pages/**/*.tsx', 'pages/**/*.ts'], {
66
+ cwd: repoPath,
67
+ onlyFiles: true,
68
+ absolute: true,
69
+ ignore: IGNORE_PATTERNS,
70
+ });
71
+ for (const file of pagesRouterFiles) {
72
+ const rel = toPosix(relative(repoPath, file));
73
+ const name = basename(rel);
74
+ if (name.startsWith('_'))
75
+ continue;
76
+ const routeSegment = rel.replace(/^pages\//, '').replace(/\.tsx?$/, '');
77
+ const routePath = routeSegment === 'index'
78
+ ? '/'
79
+ : normalizeRoutePath(routeSegment.replace(/\/index$/, ''));
80
+ routes.push({ path: routePath, file: rel, method: 'GET' });
81
+ }
82
+ const expressFiles = await glob(['src/**/*.ts', 'src/**/*.js'], {
83
+ cwd: repoPath,
84
+ onlyFiles: true,
85
+ absolute: true,
86
+ ignore: IGNORE_PATTERNS,
87
+ });
88
+ for (const file of expressFiles) {
89
+ const rel = toPosix(relative(repoPath, file));
90
+ const content = await readFile(file, 'utf8');
91
+ const routeRegex = /router\.(get|post|put|delete|patch)\s*\(\s*['"`]([^'"`]+)/gi;
92
+ for (const match of content.matchAll(routeRegex)) {
93
+ const method = match[1]?.toUpperCase();
94
+ const routePath = normalizeRoutePath(match[2] ?? '/');
95
+ routes.push({ path: routePath, file: rel, method });
96
+ }
97
+ }
98
+ const testFilePaths = await glob([
99
+ '**/*.spec.ts',
100
+ '**/*.test.ts',
101
+ '**/*.spec.tsx',
102
+ '**/*.test.tsx',
103
+ '**/cypress/e2e/**/*.ts',
104
+ '**/cypress/e2e/**/*.cy.ts',
105
+ ], {
106
+ cwd: repoPath,
107
+ onlyFiles: true,
108
+ absolute: true,
109
+ ignore: IGNORE_PATTERNS,
110
+ });
111
+ const testFiles = [];
112
+ for (const file of [...new Set(testFilePaths)]) {
113
+ const rel = toPosix(relative(repoPath, file));
114
+ const content = await readFile(file, 'utf8');
115
+ testFiles.push({
116
+ file: rel,
117
+ type: detectTestType(rel, content),
118
+ coveredPaths: extractCoveredPaths(content),
119
+ });
120
+ }
121
+ const cypressRoot = await glob(['cypress'], { cwd: repoPath, onlyDirectories: true, absolute: false, deep: 1 });
122
+ const e2eFolder = await glob(['cypress/e2e'], { cwd: repoPath, onlyDirectories: true, absolute: false, deep: 1 });
123
+ const componentFolder = await glob(['cypress/component'], { cwd: repoPath, onlyDirectories: true, absolute: false, deep: 1 });
124
+ const fixturesFolder = await glob(['cypress/fixtures'], { cwd: repoPath, onlyDirectories: true, absolute: false, deep: 1 });
125
+ const supportFolder = await glob(['cypress/support'], { cwd: repoPath, onlyDirectories: true, absolute: false, deep: 1 });
126
+ const commandsFile = await glob(['cypress/support/commands.ts'], { cwd: repoPath, onlyFiles: true, absolute: false });
127
+ const existingE2eFiles = await glob(['cypress/e2e/**/*.cy.ts'], { cwd: repoPath, onlyFiles: true, absolute: false });
128
+ const existingComponentFiles = await glob(['cypress/component/**/*.cy.tsx'], {
129
+ cwd: repoPath,
130
+ onlyFiles: true,
131
+ absolute: false,
132
+ });
133
+ const tsxFiles = await glob(['**/*.tsx'], {
134
+ cwd: repoPath,
135
+ onlyFiles: true,
136
+ absolute: true,
137
+ ignore: [...IGNORE_PATTERNS, '**/*.spec.tsx'],
138
+ });
139
+ const missingTestIds = [];
140
+ let interactiveTsxFilesScanned = 0;
141
+ for (const file of tsxFiles) {
142
+ const rel = toPosix(relative(repoPath, file));
143
+ const content = await readFile(file, 'utf8');
144
+ const hasInteractive = content.includes('<button') || content.includes('<input') || content.includes('<a ');
145
+ if (hasInteractive) {
146
+ interactiveTsxFilesScanned += 1;
147
+ if (!content.includes('data-testid')) {
148
+ missingTestIds.push(rel);
149
+ }
150
+ }
151
+ }
152
+ const base = {
153
+ scannedAt: new Date().toISOString(),
154
+ repoPath,
155
+ routes,
156
+ testFiles,
157
+ missingTestIds: [...new Set(missingTestIds)],
158
+ interactiveTsxFilesScanned,
159
+ cypressStructure: {
160
+ detected: cypressRoot.length > 0,
161
+ e2eFolder: e2eFolder[0],
162
+ componentFolder: componentFolder[0],
163
+ fixturesFolder: fixturesFolder[0],
164
+ supportFolder: supportFolder[0],
165
+ hasCommandsFile: commandsFile.length > 0,
166
+ existingE2eFiles,
167
+ existingComponentFiles,
168
+ },
169
+ };
170
+ let parsed = RepoAnalysisSchema.parse(base);
171
+ try {
172
+ const framework = await detectFramework(repoPath);
173
+ parsed = RepoAnalysisSchema.parse({ ...parsed, framework });
174
+ }
175
+ catch (error) {
176
+ const msg = error instanceof Error ? error.message : String(error);
177
+ console.warn(`[qulib] framework detection failed for ${repoPath}: ${msg}`);
178
+ }
179
+ const automationMaturity = computeAutomationMaturity(parsed);
180
+ return RepoAnalysisSchema.parse({ ...parsed, automationMaturity });
181
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"repo-scanner.d.ts","sourceRoot":"","sources":["../../src/tools/repo-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAmC3F,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAyItE"}
1
+ {"version":3,"file":"repo-scanner.d.ts","sourceRoot":"","sources":["../../src/tools/repo-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAmC3F,wBAAsB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CA8ItE"}
@@ -137,12 +137,16 @@ export async function scanRepo(repoPath) {
137
137
  ignore: [...IGNORE_PATTERNS, '**/*.spec.tsx'],
138
138
  });
139
139
  const missingTestIds = [];
140
+ let interactiveTsxFilesScanned = 0;
140
141
  for (const file of tsxFiles) {
141
142
  const rel = toPosix(relative(repoPath, file));
142
143
  const content = await readFile(file, 'utf8');
143
144
  const hasInteractive = content.includes('<button') || content.includes('<input') || content.includes('<a ');
144
- if (hasInteractive && !content.includes('data-testid')) {
145
- missingTestIds.push(rel);
145
+ if (hasInteractive) {
146
+ interactiveTsxFilesScanned += 1;
147
+ if (!content.includes('data-testid')) {
148
+ missingTestIds.push(rel);
149
+ }
146
150
  }
147
151
  }
148
152
  const base = {
@@ -151,6 +155,7 @@ export async function scanRepo(repoPath) {
151
155
  routes,
152
156
  testFiles,
153
157
  missingTestIds: [...new Set(missingTestIds)],
158
+ interactiveTsxFilesScanned,
154
159
  cypressStructure: {
155
160
  detected: cypressRoot.length > 0,
156
161
  e2eFolder: e2eFolder[0],
@@ -0,0 +1,4 @@
1
+ import type { RepoAnalysis } from '../../schemas/repo-analysis.schema.js';
2
+ import type { AutomationMaturity } from '../../schemas/automation-maturity.schema.js';
3
+ export declare function computeAutomationMaturity(repo: RepoAnalysis): AutomationMaturity;
4
+ //# sourceMappingURL=automation-maturity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automation-maturity.d.ts","sourceRoot":"","sources":["../../../src/tools/scoring/automation-maturity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EACV,kBAAkB,EAGnB,MAAM,6CAA6C,CAAC;AAiDrD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,YAAY,GAAG,kBAAkB,CAuLhF"}
@@ -0,0 +1,219 @@
1
+ import { existsSync, readdirSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { AutomationMaturitySchema } from '../../schemas/automation-maturity.schema.js';
4
+ /**
5
+ * Dimension weights (sum = 1). Breadth + harness adoption dominate: shipping risk is mostly
6
+ * untested routes and missing Playwright/Cypress-level coverage.
7
+ */
8
+ const W_TEST_BREADTH = 0.28;
9
+ const W_FRAMEWORK = 0.22;
10
+ const W_TEST_ID = 0.18;
11
+ const W_CI = 0.14;
12
+ const W_AUTH_TESTS = 0.1;
13
+ const W_COMPONENT_RATIO = 0.08;
14
+ function hasCiAtRoot(repoPath) {
15
+ const ev = [];
16
+ const gh = join(repoPath, '.github', 'workflows');
17
+ if (existsSync(gh) && statSync(gh).isDirectory()) {
18
+ try {
19
+ const files = readdirSync(gh).filter((f) => f.endsWith('.yml') || f.endsWith('.yaml'));
20
+ if (files.length > 0) {
21
+ ev.push(`.github/workflows (${files.length} workflow file(s))`);
22
+ return { ok: true, evidence: ev };
23
+ }
24
+ }
25
+ catch {
26
+ /* ignore */
27
+ }
28
+ }
29
+ if (existsSync(join(repoPath, '.circleci'))) {
30
+ ev.push('.circleci/ present');
31
+ return { ok: true, evidence: ev };
32
+ }
33
+ for (const f of ['.gitlab-ci.yml', 'Jenkinsfile']) {
34
+ if (existsSync(join(repoPath, f))) {
35
+ ev.push(`${f} present`);
36
+ return { ok: true, evidence: ev };
37
+ }
38
+ }
39
+ return { ok: false, evidence: ['No GitHub Actions, CircleCI, GitLab CI, or Jenkinsfile detected at repo root'] };
40
+ }
41
+ function scoreLevel(overall) {
42
+ if (overall < 20)
43
+ return { level: 1, label: 'L1 — nascent automation' };
44
+ if (overall < 40)
45
+ return { level: 2, label: 'L2 — emerging coverage' };
46
+ if (overall < 60)
47
+ return { level: 3, label: 'L3 — building maturity' };
48
+ if (overall < 80)
49
+ return { level: 4, label: 'L4 — strong automation' };
50
+ return { level: 5, label: 'L5 — advanced QA automation' };
51
+ }
52
+ export function computeAutomationMaturity(repo) {
53
+ const routePaths = [...new Set(repo.routes.map((r) => r.path))];
54
+ let coveredRoutes = 0;
55
+ for (const p of routePaths) {
56
+ const covered = repo.testFiles.some((tf) => tf.coveredPaths.some((c) => p === c || (c !== '/' && p.startsWith(c))));
57
+ if (covered)
58
+ coveredRoutes++;
59
+ }
60
+ const breadthScore = routePaths.length === 0 ? 100 : Math.round((100 * coveredRoutes) / routePaths.length);
61
+ const breadthDim = {
62
+ dimension: 'test-coverage-breadth',
63
+ score: breadthScore,
64
+ weight: W_TEST_BREADTH,
65
+ evidence: routePaths.length === 0
66
+ ? ['No static routes inferred from repo layout']
67
+ : [
68
+ `${coveredRoutes}/${routePaths.length} inferred routes appear in at least one test coveredPaths`,
69
+ ],
70
+ recommendations: breadthScore >= 80
71
+ ? []
72
+ : ['Add route-level smoke tests that assert critical paths referenced in production URLs.'],
73
+ };
74
+ const types = new Set(repo.testFiles.map((t) => t.type));
75
+ let frameworkScore = 0;
76
+ const fwEvidence = [`Test runners seen: ${[...types].join(', ') || 'none'}`];
77
+ if (types.has('playwright') || types.has('cypress-e2e') || types.has('cypress-component')) {
78
+ frameworkScore = 100;
79
+ fwEvidence.push('Playwright or Cypress present — good browser harness signal.');
80
+ }
81
+ else if (types.has('jest') || types.has('vitest')) {
82
+ frameworkScore = 55;
83
+ fwEvidence.push('Jest/Vitest only — add Playwright or Cypress for deployment-facing checks.');
84
+ }
85
+ else if (repo.testFiles.length > 0) {
86
+ frameworkScore = 30;
87
+ fwEvidence.push('Tests exist but no recognized browser harness in scanned files.');
88
+ }
89
+ else {
90
+ frameworkScore = 0;
91
+ fwEvidence.push('No test files matched qulib scan globs.');
92
+ }
93
+ const frameworkDim = {
94
+ dimension: 'framework-adoption',
95
+ score: frameworkScore,
96
+ weight: W_FRAMEWORK,
97
+ evidence: fwEvidence,
98
+ recommendations: frameworkScore >= 80 ? [] : ['Standardize on Playwright or Cypress for E2E against deployed URLs.'],
99
+ };
100
+ const missingIds = repo.missingTestIds.length;
101
+ const interactiveTsxScanned = repo.interactiveTsxFilesScanned ?? missingIds;
102
+ let hygieneScore = 0;
103
+ let hygieneApplicability = 'applicable';
104
+ let hygieneReason;
105
+ const hygieneEvidence = [];
106
+ if (interactiveTsxScanned === 0) {
107
+ hygieneApplicability = 'unknown';
108
+ hygieneReason = 'No interactive TSX files scanned — cannot compute a missing-id ratio honestly.';
109
+ hygieneEvidence.push(hygieneReason);
110
+ }
111
+ else {
112
+ const missingRatio = missingIds / interactiveTsxScanned;
113
+ hygieneScore = Math.round(Math.max(0, 100 * (1 - missingRatio)));
114
+ hygieneEvidence.push(`${missingIds}/${interactiveTsxScanned} interactive TSX file(s) lacked data-testid (heuristic scan).`);
115
+ }
116
+ const hygieneDim = {
117
+ dimension: 'test-id-hygiene',
118
+ score: hygieneScore,
119
+ weight: W_TEST_ID,
120
+ evidence: hygieneEvidence,
121
+ recommendations: hygieneApplicability === 'applicable' && hygieneScore < 85
122
+ ? ['Add stable data-testid (or role-based selectors) on interactive components used in tests.']
123
+ : [],
124
+ applicability: hygieneApplicability,
125
+ ...(hygieneReason && { reason: hygieneReason }),
126
+ };
127
+ const ci = hasCiAtRoot(repo.repoPath);
128
+ const ciDim = {
129
+ dimension: 'ci-integration',
130
+ score: ci.ok ? 100 : 0,
131
+ weight: W_CI,
132
+ evidence: ci.evidence,
133
+ recommendations: ci.ok ? [] : ['Add a CI workflow that runs unit/E2E tests on every PR.'],
134
+ };
135
+ const authRe = /\/(login|auth|signin)(\/|$)/i;
136
+ const authRouteFileRe = /(login|auth|signin)/i;
137
+ const authCovered = repo.testFiles.some((tf) => tf.coveredPaths.some((c) => authRe.test(c)));
138
+ const repoHasAuthRoute = repo.routes.some((r) => authRe.test(r.path));
139
+ const repoHasAuthTestFile = repo.testFiles.some((tf) => authRouteFileRe.test(tf.file));
140
+ const repoHasAnyAuthSignal = repoHasAuthRoute || repoHasAuthTestFile || authCovered;
141
+ let authScore = 0;
142
+ let authApplicability = 'applicable';
143
+ let authReason;
144
+ const authEvidence = [];
145
+ if (!repoHasAnyAuthSignal) {
146
+ authApplicability = 'not_applicable';
147
+ authReason = 'No auth routes, auth-named test files, or auth path coverage detected — repo appears auth-free.';
148
+ authEvidence.push(authReason);
149
+ }
150
+ else {
151
+ authScore = authCovered ? 90 : 25;
152
+ authEvidence.push(authCovered
153
+ ? 'At least one test references /login, /auth, or /signin in coveredPaths.'
154
+ : 'Repo has auth-shaped routes or test files but no auth-route coverage in extracted test path strings.');
155
+ }
156
+ const authDim = {
157
+ dimension: 'auth-test-coverage',
158
+ score: authScore,
159
+ weight: W_AUTH_TESTS,
160
+ evidence: authEvidence,
161
+ recommendations: authApplicability === 'applicable' && !authCovered
162
+ ? ['Add focused tests for sign-in and post-auth landing behavior.']
163
+ : [],
164
+ applicability: authApplicability,
165
+ ...(authReason && { reason: authReason }),
166
+ };
167
+ const cypressE2e = repo.testFiles.filter((t) => t.type === 'cypress-e2e').length;
168
+ const cypressComp = repo.testFiles.filter((t) => t.type === 'cypress-component').length;
169
+ const cypressTotal = cypressE2e + cypressComp;
170
+ let compRatioScore = 0;
171
+ let compApplicability = 'applicable';
172
+ let compReason;
173
+ const compEvidence = [];
174
+ if (cypressTotal === 0) {
175
+ compApplicability = 'not_applicable';
176
+ compReason = 'No Cypress (e2e or component) tests detected — component-test-ratio does not apply.';
177
+ compEvidence.push(compReason);
178
+ }
179
+ else {
180
+ compRatioScore = Math.round((100 * cypressComp) / cypressTotal);
181
+ compEvidence.push(`Cypress e2e files (matched): ${cypressE2e}, component: ${cypressComp}.`);
182
+ }
183
+ const compDim = {
184
+ dimension: 'component-test-ratio',
185
+ score: compRatioScore,
186
+ weight: W_COMPONENT_RATIO,
187
+ evidence: compEvidence,
188
+ recommendations: compApplicability === 'applicable' && cypressComp > 0
189
+ ? ['Balance component vs E2E Cypress tests so critical flows stay fast in CI.']
190
+ : [],
191
+ applicability: compApplicability,
192
+ ...(compReason && { reason: compReason }),
193
+ };
194
+ const dimensions = [breadthDim, frameworkDim, hygieneDim, ciDim, authDim, compDim];
195
+ // Overall score normalizes over applicable dimensions only.
196
+ // overallScore = round( Σ score_i * weight_i / Σ weight_i ) for i ∈ applicable.
197
+ // If no dimension is applicable (degenerate repo), overall = 0 and level = L1.
198
+ const applicableDims = dimensions.filter((d) => (d.applicability ?? 'applicable') === 'applicable');
199
+ const weightSum = applicableDims.reduce((s, d) => s + d.weight, 0);
200
+ const overallScore = weightSum > 0
201
+ ? Math.round(applicableDims.reduce((s, d) => s + d.score * d.weight, 0) / weightSum)
202
+ : 0;
203
+ const { level, label } = scoreLevel(overallScore);
204
+ const topRecommendations = [...applicableDims]
205
+ .sort((a, b) => a.score - b.score)
206
+ .flatMap((d) => d.recommendations)
207
+ .filter(Boolean)
208
+ .slice(0, 8);
209
+ return AutomationMaturitySchema.parse({
210
+ computedAt: new Date().toISOString(),
211
+ repoPath: repo.repoPath,
212
+ overallScore,
213
+ level,
214
+ label,
215
+ dimensions,
216
+ topRecommendations,
217
+ scoreFormula: 'overallScore = round( Σ (score * weight) / Σ weight ) for applicable dimensions only. not_applicable and unknown dimensions are excluded from the denominator.',
218
+ });
219
+ }
@@ -0,0 +1,8 @@
1
+ import { type GapAnalysis, type Gap } from '../../schemas/gap-analysis.schema.js';
2
+ import type { RouteInventory } from '../../schemas/route-inventory.schema.js';
3
+ import type { RepoAnalysis } from '../../schemas/repo-analysis.schema.js';
4
+ import type { HarnessConfig } from '../../schemas/config.schema.js';
5
+ export declare function computeQualityScoreFromGaps(gaps: Gap[], scoringWeights?: HarnessConfig['scoringWeights']): number;
6
+ export declare function computeCoverageScore(routes: RouteInventory): number | null;
7
+ export declare function analyzeGaps(routes: RouteInventory, repo: RepoAnalysis | null, mode: 'url-only' | 'url-repo', config: HarnessConfig): Omit<GapAnalysis, 'scenarios' | 'generatedTests'>;
8
+ //# sourceMappingURL=gap-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gap-engine.d.ts","sourceRoot":"","sources":["../../../src/tools/scoring/gap-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,sCAAsC,CAAC;AAC7F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAQpE,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,GAAG,EAAE,EACX,cAAc,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAC/C,MAAM,CAkBR;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAa1E;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,YAAY,GAAG,IAAI,EACzB,IAAI,EAAE,UAAU,GAAG,UAAU,EAC7B,MAAM,EAAE,aAAa,GACpB,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,gBAAgB,CAAC,CAqGnD"}
@@ -0,0 +1,138 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { GapSchema } from '../../schemas/gap-analysis.schema.js';
3
+ // TODO: Add category-specific weight overrides (e.g., auth-surface gaps should cost more than untested-route gaps by default).
4
+ // Requires a 2D weight matrix: { [severity]: { [category]: number } }.
5
+ // Deferred until there is empirical data from real scan runs to calibrate.
6
+ const DEFAULT_SCORING_WEIGHTS = { critical: 25, high: 20, medium: 8, low: 3 };
7
+ export function computeQualityScoreFromGaps(gaps, scoringWeights) {
8
+ let critical = 0;
9
+ let high = 0;
10
+ let medium = 0;
11
+ let low = 0;
12
+ for (const g of gaps) {
13
+ if (g.severity === 'critical')
14
+ critical++;
15
+ else if (g.severity === 'high')
16
+ high++;
17
+ else if (g.severity === 'medium')
18
+ medium++;
19
+ else
20
+ low++;
21
+ }
22
+ const w = {
23
+ critical: scoringWeights?.critical ?? DEFAULT_SCORING_WEIGHTS.critical,
24
+ high: scoringWeights?.high ?? DEFAULT_SCORING_WEIGHTS.high,
25
+ medium: scoringWeights?.medium ?? DEFAULT_SCORING_WEIGHTS.medium,
26
+ low: scoringWeights?.low ?? DEFAULT_SCORING_WEIGHTS.low,
27
+ };
28
+ return Math.max(0, 100 - critical * w.critical - high * w.high - medium * w.medium - low * w.low);
29
+ }
30
+ export function computeCoverageScore(routes) {
31
+ const scanned = routes.routes.length;
32
+ const skipped = routes.pagesSkipped;
33
+ const denom = scanned + skipped;
34
+ // TODO: return null here once the explorer exposes an explicit "discovered-but-unknown" signal
35
+ // (i.e. routes were found but the full set couldn't be confirmed — a low score is misleading)
36
+ if (denom === 0) {
37
+ if (routes.budgetExceeded) {
38
+ return 0;
39
+ }
40
+ return scanned === 0 ? 0 : 100;
41
+ }
42
+ return Math.round((100 * scanned) / denom);
43
+ }
44
+ export function analyzeGaps(routes, repo, mode, config) {
45
+ const coveredPaths = new Set();
46
+ if (repo) {
47
+ for (const testFile of repo.testFiles) {
48
+ for (const path of testFile.coveredPaths) {
49
+ coveredPaths.add(path);
50
+ }
51
+ }
52
+ }
53
+ const gaps = [];
54
+ const addGap = (gap) => {
55
+ const validated = GapSchema.parse(gap);
56
+ gaps.push(validated);
57
+ };
58
+ let hasNavigationFailures = false;
59
+ for (const route of routes.routes) {
60
+ if (repo && !coveredPaths.has(route.path)) {
61
+ const highRisk = /checkout|payment|auth|login|order/i.test(route.path);
62
+ addGap({
63
+ id: randomUUID(),
64
+ path: route.path,
65
+ severity: highRisk ? 'high' : 'medium',
66
+ reason: `Route is not covered by existing tests: ${route.path}`,
67
+ category: 'untested-route',
68
+ });
69
+ }
70
+ const navErrors = route.consoleErrors.filter((e) => e.startsWith('Navigation error:'));
71
+ if (navErrors.length > 0) {
72
+ hasNavigationFailures = true;
73
+ addGap({
74
+ id: randomUUID(),
75
+ path: route.path,
76
+ severity: 'high',
77
+ reason: `Navigation failed: ${navErrors.join('; ')}`,
78
+ category: 'console-error',
79
+ });
80
+ }
81
+ else if (route.consoleErrors.length > 0) {
82
+ addGap({
83
+ id: randomUUID(),
84
+ path: route.path,
85
+ severity: 'high',
86
+ reason: `Console errors detected (${route.consoleErrors.length})`,
87
+ category: 'console-error',
88
+ });
89
+ }
90
+ if (route.brokenLinks.length > 0) {
91
+ addGap({
92
+ id: randomUUID(),
93
+ path: route.path,
94
+ severity: 'medium',
95
+ reason: `Broken or invalid links detected (${route.brokenLinks.length})`,
96
+ category: 'broken-link',
97
+ });
98
+ }
99
+ for (const violation of route.a11yViolations) {
100
+ const impact = violation.impact.toLowerCase();
101
+ const severity = impact === 'critical'
102
+ ? 'critical'
103
+ : impact === 'serious'
104
+ ? 'high'
105
+ : impact === 'moderate'
106
+ ? 'medium'
107
+ : 'low';
108
+ addGap({
109
+ id: randomUUID(),
110
+ path: route.path,
111
+ severity,
112
+ reason: `A11y violation ${violation.id} (${violation.impact}): ${violation.helpUrl}`,
113
+ category: 'a11y',
114
+ });
115
+ }
116
+ }
117
+ const releaseConfidence = computeQualityScoreFromGaps(gaps, config.scoringWeights);
118
+ const pagesScanned = routes.routes.length;
119
+ let coverageWarning;
120
+ if (routes.budgetExceeded) {
121
+ coverageWarning = 'budget-exceeded';
122
+ }
123
+ else if (hasNavigationFailures) {
124
+ coverageWarning = 'navigation-failures';
125
+ }
126
+ else if (pagesScanned < config.minPagesForConfidence) {
127
+ coverageWarning = 'low-coverage';
128
+ }
129
+ return {
130
+ analyzedAt: new Date().toISOString(),
131
+ mode,
132
+ releaseConfidence,
133
+ coveragePagesScanned: pagesScanned,
134
+ coverageBudgetExceeded: routes.budgetExceeded,
135
+ coverageWarning,
136
+ gaps,
137
+ };
138
+ }
@@ -0,0 +1,8 @@
1
+ import { type GapAnalysis, type Gap } from '../../schemas/gap-analysis.schema.js';
2
+ import type { RouteInventory } from '../../schemas/route-inventory.schema.js';
3
+ import type { RepoAnalysis } from '../../schemas/repo-analysis.schema.js';
4
+ import type { HarnessConfig } from '../../schemas/config.schema.js';
5
+ export declare function computeQualityScoreFromGaps(gaps: Gap[], scoringWeights?: HarnessConfig['scoringWeights']): number;
6
+ export declare function computeCoverageScore(routes: RouteInventory): number | null;
7
+ export declare function analyzeGaps(routes: RouteInventory, repo: RepoAnalysis | null, mode: 'url-only' | 'url-repo', config: HarnessConfig): Omit<GapAnalysis, 'scenarios' | 'generatedTests'>;
8
+ //# sourceMappingURL=gaps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gaps.d.ts","sourceRoot":"","sources":["../../../src/tools/scoring/gaps.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,sCAAsC,CAAC;AAC7F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAQpE,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,GAAG,EAAE,EACX,cAAc,CAAC,EAAE,aAAa,CAAC,gBAAgB,CAAC,GAC/C,MAAM,CAkBR;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAa1E;AAED,wBAAgB,WAAW,CACzB,MAAM,EAAE,cAAc,EACtB,IAAI,EAAE,YAAY,GAAG,IAAI,EACzB,IAAI,EAAE,UAAU,GAAG,UAAU,EAC7B,MAAM,EAAE,aAAa,GACpB,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,gBAAgB,CAAC,CAqGnD"}