playwright-intelligence-engine 2.0.1 → 2.0.2

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 (48) hide show
  1. package/README.md +229 -229
  2. package/dist/cli/index.d.ts.map +1 -1
  3. package/dist/core/version.d.ts +3 -3
  4. package/dist/index.js +81 -24
  5. package/package.json +76 -76
  6. package/src/authoring/author.ts +81 -81
  7. package/src/authoring/generation-contract.ts +283 -283
  8. package/src/authoring/hybrid-author.ts +115 -115
  9. package/src/authoring/index.ts +7 -7
  10. package/src/authoring/llm-author.ts +282 -282
  11. package/src/authoring/naming/name-plan.ts +28 -28
  12. package/src/authoring/naming/name-planner.ts +339 -339
  13. package/src/authoring/naming/naming-linter.ts +292 -292
  14. package/src/cli/index.ts +1238 -1172
  15. package/src/collectors/git-diff-collector.ts +190 -190
  16. package/src/core/version.ts +25 -25
  17. package/src/diagnostics/diagnostic-report.ts +204 -204
  18. package/src/diagnostics/failure-classifier.ts +701 -701
  19. package/src/evaluation/repository-runner.ts +197 -197
  20. package/src/gate/quality.ts +101 -101
  21. package/src/generator/architecture-generator.ts +582 -582
  22. package/src/generator/assertion-quality-gate.ts +88 -88
  23. package/src/generator/candidate-writer.ts +288 -288
  24. package/src/generator/test-generator.ts +52 -52
  25. package/src/index.ts +107 -107
  26. package/src/intelligence/evidence-bundle.ts +300 -300
  27. package/src/intelligence/generation-agent.ts +561 -561
  28. package/src/intelligence/generation-verifier.ts +1115 -1115
  29. package/src/intelligence/locator-disambiguation-engine.ts +331 -331
  30. package/src/intelligence/project-intelligence.ts +140 -140
  31. package/src/intelligence/repository-profile.ts +796 -796
  32. package/src/intelligence/trace-proposal-workflow.ts +318 -318
  33. package/src/intelligence/workflow-planner.ts +966 -966
  34. package/src/mcp/server.ts +970 -970
  35. package/src/perception/app-model.ts +32 -32
  36. package/src/perception/crawler.ts +263 -263
  37. package/src/perception/index.ts +3 -3
  38. package/src/repair/assertion-hasher.ts +386 -386
  39. package/src/repair/diff-allowlist.ts +612 -612
  40. package/src/repair/intent-validator.ts +761 -761
  41. package/src/repair/repair-planner.ts +467 -467
  42. package/src/repair/statement-patcher.ts +544 -544
  43. package/src/reproduce/interactive-workflow-runner.ts +828 -828
  44. package/src/sandbox/execution-runner.ts +408 -408
  45. package/src/selector/abstention-policy.ts +175 -175
  46. package/src/selector/candidate-extractor.ts +343 -343
  47. package/src/selector/repair-candidate-ranker.ts +92 -92
  48. package/src/selector/selector-scorer.ts +344 -344
@@ -1,88 +1,88 @@
1
- export interface AssertionQualityReport {
2
- passed: boolean;
3
- assertionCount: number;
4
- hasStateAssertion: boolean;
5
- isVacuousEcho: boolean;
6
- constantAssertionCount: number;
7
- arbitrarySleepCount: number;
8
- emptyOrSkippedCount: number;
9
- violations: string[];
10
- }
11
-
12
- export class AssertionQualityGate {
13
- /**
14
- * Evaluates the assertion quality of a generated Playwright spec file.
15
- * Enforces that generated tests are behavioral, non-vacuous, and contain real assertions.
16
- */
17
- public static evaluate(specContent: string, featureName: string): AssertionQualityReport {
18
- const violations: string[] = [];
19
-
20
- // 1. Count assertions
21
- const expectMatches = [...specContent.matchAll(/\bexpect(?:\.soft|\.poll)?\s*\(/g)];
22
- const assertionCount = expectMatches.length;
23
-
24
- if (assertionCount === 0) {
25
- violations.push('ZERO_ASSERTIONS: Generated spec contains zero expect() assertions.');
26
- }
27
-
28
- // 2. Check for constant assertions (e.g. expect(true).toBe(true), expect(1).toBe(1))
29
- const constantMatches = [
30
- ...specContent.matchAll(
31
- /\bexpect\s*\(\s*(?:true|false|\d+|['"][^'"]*['"])\s*\)\s*\.\s*(?:toBe|toEqual|toStrictEqual)\s*\(\s*(?:true|false|\d+|['"][^'"]*['"])\s*\)/g,
32
- ),
33
- ];
34
- const constantAssertionCount = constantMatches.length;
35
- if (constantAssertionCount > 0) {
36
- violations.push(`CONSTANT_ASSERTION: Spec contains ${constantAssertionCount} constant assertion(s) that do not inspect application state.`);
37
- }
38
-
39
- // 3. Check for arbitrary waitForTimeout sleeps
40
- const sleepMatches = [...specContent.matchAll(/\bwaitForTimeout\s*\(\s*\d+\s*\)/g)];
41
- const arbitrarySleepCount = sleepMatches.length;
42
- if (arbitrarySleepCount > 0) {
43
- violations.push(`ARBITRARY_SLEEP: Spec uses waitForTimeout() (${arbitrarySleepCount}x) instead of web-first assertions or state waits.`);
44
- }
45
-
46
- // 4. Check for empty or skipped tests
47
- const skippedMatches = [...specContent.matchAll(/\btest\s*\.\s*(?:skip|fixme)\s*\(/g)];
48
- const emptyBodyMatches = [...specContent.matchAll(/\btest\s*\([^,]+,\s*async\s*\([^)]*\)\s*=>\s*\{\s*\}\s*\)/g)];
49
- const emptyOrSkippedCount = skippedMatches.length + emptyBodyMatches.length;
50
- if (emptyOrSkippedCount > 0) {
51
- violations.push(`EMPTY_OR_SKIPPED_TEST: Spec contains ${emptyOrSkippedCount} skipped or empty test case(s).`);
52
- }
53
-
54
- // 5. Check for web-first / response assertions
55
- const stateAssertionRegex = /\b(toBeVisible|toBeHidden|toHaveText|toContainText|toHaveCount|toBeChecked|toHaveValue|toBeEmpty|toBeEnabled|toBeDisabled|toHaveAttribute|toHaveClass|toHaveURL|toHaveTitle|toBeOK)\b/;
56
- const hasStateAssertion = stateAssertionRegex.test(specContent);
57
-
58
- if (assertionCount > 0 && !hasStateAssertion) {
59
- violations.push('WEAK_ASSERTION: Generated spec contains no auto-retrying web-first state assertions.');
60
- }
61
-
62
- // 6. Check for vacuous echo assertion
63
- // An echo assertion is when the ONLY assertion in the spec is expecting a heading with the exact featureName string.
64
- let isVacuousEcho = false;
65
- if (assertionCount === 1) {
66
- const escapedFeature = featureName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
67
- const headingEchoRegex = new RegExp(
68
- `expect\\s*\\(\\s*page\\.getByRole\\s*\\(\\s*['"]heading['"]\\s*,\\s*\\{\\s*name:\\s*['"]${escapedFeature}['"]\\s*\\}\\s*\\)\\s*\\)\\.toBeVisible\\(\\)`,
69
- );
70
- if (headingEchoRegex.test(specContent)) {
71
- isVacuousEcho = true;
72
- violations.push(`VACUOUS_ECHO_ASSERTION: Spec only asserts visibility of input feature name '${featureName}' without verifying dynamic application behavior.`);
73
- }
74
- }
75
-
76
- return {
77
- passed: violations.length === 0,
78
- assertionCount,
79
- hasStateAssertion,
80
- isVacuousEcho,
81
- constantAssertionCount,
82
- arbitrarySleepCount,
83
- emptyOrSkippedCount,
84
- violations,
85
- };
86
- }
87
- }
88
-
1
+ export interface AssertionQualityReport {
2
+ passed: boolean;
3
+ assertionCount: number;
4
+ hasStateAssertion: boolean;
5
+ isVacuousEcho: boolean;
6
+ constantAssertionCount: number;
7
+ arbitrarySleepCount: number;
8
+ emptyOrSkippedCount: number;
9
+ violations: string[];
10
+ }
11
+
12
+ export class AssertionQualityGate {
13
+ /**
14
+ * Evaluates the assertion quality of a generated Playwright spec file.
15
+ * Enforces that generated tests are behavioral, non-vacuous, and contain real assertions.
16
+ */
17
+ public static evaluate(specContent: string, featureName: string): AssertionQualityReport {
18
+ const violations: string[] = [];
19
+
20
+ // 1. Count assertions
21
+ const expectMatches = [...specContent.matchAll(/\bexpect(?:\.soft|\.poll)?\s*\(/g)];
22
+ const assertionCount = expectMatches.length;
23
+
24
+ if (assertionCount === 0) {
25
+ violations.push('ZERO_ASSERTIONS: Generated spec contains zero expect() assertions.');
26
+ }
27
+
28
+ // 2. Check for constant assertions (e.g. expect(true).toBe(true), expect(1).toBe(1))
29
+ const constantMatches = [
30
+ ...specContent.matchAll(
31
+ /\bexpect\s*\(\s*(?:true|false|\d+|['"][^'"]*['"])\s*\)\s*\.\s*(?:toBe|toEqual|toStrictEqual)\s*\(\s*(?:true|false|\d+|['"][^'"]*['"])\s*\)/g,
32
+ ),
33
+ ];
34
+ const constantAssertionCount = constantMatches.length;
35
+ if (constantAssertionCount > 0) {
36
+ violations.push(`CONSTANT_ASSERTION: Spec contains ${constantAssertionCount} constant assertion(s) that do not inspect application state.`);
37
+ }
38
+
39
+ // 3. Check for arbitrary waitForTimeout sleeps
40
+ const sleepMatches = [...specContent.matchAll(/\bwaitForTimeout\s*\(\s*\d+\s*\)/g)];
41
+ const arbitrarySleepCount = sleepMatches.length;
42
+ if (arbitrarySleepCount > 0) {
43
+ violations.push(`ARBITRARY_SLEEP: Spec uses waitForTimeout() (${arbitrarySleepCount}x) instead of web-first assertions or state waits.`);
44
+ }
45
+
46
+ // 4. Check for empty or skipped tests
47
+ const skippedMatches = [...specContent.matchAll(/\btest\s*\.\s*(?:skip|fixme)\s*\(/g)];
48
+ const emptyBodyMatches = [...specContent.matchAll(/\btest\s*\([^,]+,\s*async\s*\([^)]*\)\s*=>\s*\{\s*\}\s*\)/g)];
49
+ const emptyOrSkippedCount = skippedMatches.length + emptyBodyMatches.length;
50
+ if (emptyOrSkippedCount > 0) {
51
+ violations.push(`EMPTY_OR_SKIPPED_TEST: Spec contains ${emptyOrSkippedCount} skipped or empty test case(s).`);
52
+ }
53
+
54
+ // 5. Check for web-first / response assertions
55
+ const stateAssertionRegex = /\b(toBeVisible|toBeHidden|toHaveText|toContainText|toHaveCount|toBeChecked|toHaveValue|toBeEmpty|toBeEnabled|toBeDisabled|toHaveAttribute|toHaveClass|toHaveURL|toHaveTitle|toBeOK)\b/;
56
+ const hasStateAssertion = stateAssertionRegex.test(specContent);
57
+
58
+ if (assertionCount > 0 && !hasStateAssertion) {
59
+ violations.push('WEAK_ASSERTION: Generated spec contains no auto-retrying web-first state assertions.');
60
+ }
61
+
62
+ // 6. Check for vacuous echo assertion
63
+ // An echo assertion is when the ONLY assertion in the spec is expecting a heading with the exact featureName string.
64
+ let isVacuousEcho = false;
65
+ if (assertionCount === 1) {
66
+ const escapedFeature = featureName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
67
+ const headingEchoRegex = new RegExp(
68
+ `expect\\s*\\(\\s*page\\.getByRole\\s*\\(\\s*['"]heading['"]\\s*,\\s*\\{\\s*name:\\s*['"]${escapedFeature}['"]\\s*\\}\\s*\\)\\s*\\)\\.toBeVisible\\(\\)`,
69
+ );
70
+ if (headingEchoRegex.test(specContent)) {
71
+ isVacuousEcho = true;
72
+ violations.push(`VACUOUS_ECHO_ASSERTION: Spec only asserts visibility of input feature name '${featureName}' without verifying dynamic application behavior.`);
73
+ }
74
+ }
75
+
76
+ return {
77
+ passed: violations.length === 0,
78
+ assertionCount,
79
+ hasStateAssertion,
80
+ isVacuousEcho,
81
+ constantAssertionCount,
82
+ arbitrarySleepCount,
83
+ emptyOrSkippedCount,
84
+ violations,
85
+ };
86
+ }
87
+ }
88
+