playwright-intelligence-engine 0.0.0-stage → 2.0.1
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/LICENSE +191 -0
- package/README.md +229 -3
- package/bin/pw-intel.js +37 -0
- package/dist/authoring/author.d.ts +83 -0
- package/dist/authoring/author.d.ts.map +1 -0
- package/dist/authoring/generation-contract.d.ts +90 -0
- package/dist/authoring/generation-contract.d.ts.map +1 -0
- package/dist/authoring/hybrid-author.d.ts +6 -0
- package/dist/authoring/hybrid-author.d.ts.map +1 -0
- package/dist/authoring/index.d.ts +7 -0
- package/dist/authoring/index.d.ts.map +1 -0
- package/dist/authoring/llm-author.d.ts +28 -0
- package/dist/authoring/llm-author.d.ts.map +1 -0
- package/dist/authoring/naming/index.d.ts +4 -0
- package/dist/authoring/naming/index.d.ts.map +1 -0
- package/dist/authoring/naming/name-plan.d.ts +45 -0
- package/dist/authoring/naming/name-plan.d.ts.map +1 -0
- package/dist/authoring/naming/name-planner.d.ts +25 -0
- package/dist/authoring/naming/name-planner.d.ts.map +1 -0
- package/dist/authoring/naming/naming-linter.d.ts +20 -0
- package/dist/authoring/naming/naming-linter.d.ts.map +1 -0
- package/dist/authoring/template-author.d.ts +6 -0
- package/dist/authoring/template-author.d.ts.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/collectors/collector-interface.d.ts +7 -0
- package/dist/collectors/collector-interface.d.ts.map +1 -0
- package/dist/collectors/environment-collector.d.ts +12 -0
- package/dist/collectors/environment-collector.d.ts.map +1 -0
- package/dist/collectors/error-collector.d.ts +18 -0
- package/dist/collectors/error-collector.d.ts.map +1 -0
- package/dist/collectors/git-diff-collector.d.ts +20 -0
- package/dist/collectors/git-diff-collector.d.ts.map +1 -0
- package/dist/collectors/live-browser-collector.d.ts +45 -0
- package/dist/collectors/live-browser-collector.d.ts.map +1 -0
- package/dist/collectors/network-collector.d.ts +28 -0
- package/dist/collectors/network-collector.d.ts.map +1 -0
- package/dist/collectors/static-ast-collector.d.ts +32 -0
- package/dist/collectors/static-ast-collector.d.ts.map +1 -0
- package/dist/collectors/trace-collector.d.ts +12 -0
- package/dist/collectors/trace-collector.d.ts.map +1 -0
- package/dist/config/project-config.d.ts +33 -0
- package/dist/config/project-config.d.ts.map +1 -0
- package/dist/core/errors/engine-errors.d.ts +34 -0
- package/dist/core/errors/engine-errors.d.ts.map +1 -0
- package/dist/core/types/diagnostic-context.d.ts +151 -0
- package/dist/core/types/diagnostic-context.d.ts.map +1 -0
- package/dist/core/types/repair-evidence.d.ts +56 -0
- package/dist/core/types/repair-evidence.d.ts.map +1 -0
- package/dist/core/version.d.ts +13 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/diagnostics/diagnostic-contract.d.ts +52 -0
- package/dist/diagnostics/diagnostic-contract.d.ts.map +1 -0
- package/dist/diagnostics/diagnostic-report.d.ts +11 -0
- package/dist/diagnostics/diagnostic-report.d.ts.map +1 -0
- package/dist/diagnostics/evidence-correlator.d.ts +22 -0
- package/dist/diagnostics/evidence-correlator.d.ts.map +1 -0
- package/dist/diagnostics/external-failure-evidence.d.ts +18 -0
- package/dist/diagnostics/external-failure-evidence.d.ts.map +1 -0
- package/dist/diagnostics/failure-category.d.ts +4 -0
- package/dist/diagnostics/failure-category.d.ts.map +1 -0
- package/dist/diagnostics/failure-classifier.d.ts +58 -0
- package/dist/diagnostics/failure-classifier.d.ts.map +1 -0
- package/dist/evaluation/evaluation-scorecard.d.ts +72 -0
- package/dist/evaluation/evaluation-scorecard.d.ts.map +1 -0
- package/dist/evaluation/repository-inspector.d.ts +21 -0
- package/dist/evaluation/repository-inspector.d.ts.map +1 -0
- package/dist/evaluation/repository-runner.d.ts +24 -0
- package/dist/evaluation/repository-runner.d.ts.map +1 -0
- package/dist/evidence/evidence-model.d.ts +88 -0
- package/dist/evidence/evidence-model.d.ts.map +1 -0
- package/dist/evidence/evidence-normalizer.d.ts +19 -0
- package/dist/evidence/evidence-normalizer.d.ts.map +1 -0
- package/dist/evidence/evidence-redactor.d.ts +37 -0
- package/dist/evidence/evidence-redactor.d.ts.map +1 -0
- package/dist/framework/config-adapter.d.ts +28 -0
- package/dist/framework/config-adapter.d.ts.map +1 -0
- package/dist/gate/index.d.ts +21 -0
- package/dist/gate/index.d.ts.map +1 -0
- package/dist/gate/oracle.d.ts +26 -0
- package/dist/gate/oracle.d.ts.map +1 -0
- package/dist/gate/quality.d.ts +27 -0
- package/dist/gate/quality.d.ts.map +1 -0
- package/dist/gate/safety.d.ts +28 -0
- package/dist/gate/safety.d.ts.map +1 -0
- package/dist/generator/architecture-generator.d.ts +55 -0
- package/dist/generator/architecture-generator.d.ts.map +1 -0
- package/dist/generator/assertion-quality-gate.d.ts +18 -0
- package/dist/generator/assertion-quality-gate.d.ts.map +1 -0
- package/dist/generator/candidate-writer.d.ts +34 -0
- package/dist/generator/candidate-writer.d.ts.map +1 -0
- package/dist/generator/test-generator.d.ts +26 -0
- package/dist/generator/test-generator.d.ts.map +1 -0
- package/dist/governance/audit-log.d.ts +23 -0
- package/dist/governance/audit-log.d.ts.map +1 -0
- package/dist/governance/governance-policy.d.ts +24 -0
- package/dist/governance/governance-policy.d.ts.map +1 -0
- package/dist/governance/team-dashboard.d.ts +51 -0
- package/dist/governance/team-dashboard.d.ts.map +1 -0
- package/dist/governance/workflow-audit.d.ts +13 -0
- package/dist/governance/workflow-audit.d.ts.map +1 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20318 -0
- package/dist/integrations/ci-summary.d.ts +14 -0
- package/dist/integrations/ci-summary.d.ts.map +1 -0
- package/dist/integrations/playwright-report-adapter.d.ts +22 -0
- package/dist/integrations/playwright-report-adapter.d.ts.map +1 -0
- package/dist/integrations/quality-gate.d.ts +35 -0
- package/dist/integrations/quality-gate.d.ts.map +1 -0
- package/dist/integrations/sarif-report.d.ts +48 -0
- package/dist/integrations/sarif-report.d.ts.map +1 -0
- package/dist/intelligence/autonomous-repair-workflow.d.ts +31 -0
- package/dist/intelligence/autonomous-repair-workflow.d.ts.map +1 -0
- package/dist/intelligence/business-intent.d.ts +58 -0
- package/dist/intelligence/business-intent.d.ts.map +1 -0
- package/dist/intelligence/evidence-bundle.d.ts +364 -0
- package/dist/intelligence/evidence-bundle.d.ts.map +1 -0
- package/dist/intelligence/failure-clustering.d.ts +38 -0
- package/dist/intelligence/failure-clustering.d.ts.map +1 -0
- package/dist/intelligence/generation-agent.d.ts +120 -0
- package/dist/intelligence/generation-agent.d.ts.map +1 -0
- package/dist/intelligence/generation-verifier.d.ts +151 -0
- package/dist/intelligence/generation-verifier.d.ts.map +1 -0
- package/dist/intelligence/llm-proposal.d.ts +377 -0
- package/dist/intelligence/llm-proposal.d.ts.map +1 -0
- package/dist/intelligence/locator-disambiguation-engine.d.ts +38 -0
- package/dist/intelligence/locator-disambiguation-engine.d.ts.map +1 -0
- package/dist/intelligence/model-contract.d.ts +86 -0
- package/dist/intelligence/model-contract.d.ts.map +1 -0
- package/dist/intelligence/model-provider.d.ts +75 -0
- package/dist/intelligence/model-provider.d.ts.map +1 -0
- package/dist/intelligence/project-intelligence.d.ts +22 -0
- package/dist/intelligence/project-intelligence.d.ts.map +1 -0
- package/dist/intelligence/repair-agent.d.ts +46 -0
- package/dist/intelligence/repair-agent.d.ts.map +1 -0
- package/dist/intelligence/repository-profile.d.ts +131 -0
- package/dist/intelligence/repository-profile.d.ts.map +1 -0
- package/dist/intelligence/suite-intelligence.d.ts +59 -0
- package/dist/intelligence/suite-intelligence.d.ts.map +1 -0
- package/dist/intelligence/test-intelligence.d.ts +44 -0
- package/dist/intelligence/test-intelligence.d.ts.map +1 -0
- package/dist/intelligence/trace-proposal-workflow.d.ts +30 -0
- package/dist/intelligence/trace-proposal-workflow.d.ts.map +1 -0
- package/dist/intelligence/verified-llm-repair-workflow.d.ts +21 -0
- package/dist/intelligence/verified-llm-repair-workflow.d.ts.map +1 -0
- package/dist/intelligence/workflow-planner.d.ts +278 -0
- package/dist/intelligence/workflow-planner.d.ts.map +1 -0
- package/dist/mcp/server.d.ts +32 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/memory/stability-ledger.d.ts +46 -0
- package/dist/memory/stability-ledger.d.ts.map +1 -0
- package/dist/perception/app-model.d.ts +55 -0
- package/dist/perception/app-model.d.ts.map +1 -0
- package/dist/perception/crawler.d.ts +18 -0
- package/dist/perception/crawler.d.ts.map +1 -0
- package/dist/perception/index.d.ts +3 -0
- package/dist/perception/index.d.ts.map +1 -0
- package/dist/repair/approval-service.d.ts +139 -0
- package/dist/repair/approval-service.d.ts.map +1 -0
- package/dist/repair/assertion-hasher.d.ts +62 -0
- package/dist/repair/assertion-hasher.d.ts.map +1 -0
- package/dist/repair/ast-patcher.d.ts +36 -0
- package/dist/repair/ast-patcher.d.ts.map +1 -0
- package/dist/repair/browser-operation-executor.d.ts +27 -0
- package/dist/repair/browser-operation-executor.d.ts.map +1 -0
- package/dist/repair/diff-allowlist.d.ts +74 -0
- package/dist/repair/diff-allowlist.d.ts.map +1 -0
- package/dist/repair/intent-validator.d.ts +157 -0
- package/dist/repair/intent-validator.d.ts.map +1 -0
- package/dist/repair/repair-operations.d.ts +40 -0
- package/dist/repair/repair-operations.d.ts.map +1 -0
- package/dist/repair/repair-planner.d.ts +98 -0
- package/dist/repair/repair-planner.d.ts.map +1 -0
- package/dist/repair/repair-workflow.d.ts +42 -0
- package/dist/repair/repair-workflow.d.ts.map +1 -0
- package/dist/repair/safe-operation-compiler.d.ts +15 -0
- package/dist/repair/safe-operation-compiler.d.ts.map +1 -0
- package/dist/repair/source-mapper.d.ts +19 -0
- package/dist/repair/source-mapper.d.ts.map +1 -0
- package/dist/repair/statement-patcher.d.ts +75 -0
- package/dist/repair/statement-patcher.d.ts.map +1 -0
- package/dist/repair/verification-gates.d.ts +25 -0
- package/dist/repair/verification-gates.d.ts.map +1 -0
- package/dist/repair/workflow-plan.d.ts +35 -0
- package/dist/repair/workflow-plan.d.ts.map +1 -0
- package/dist/repair/workspace-promoter.d.ts +43 -0
- package/dist/repair/workspace-promoter.d.ts.map +1 -0
- package/dist/reproduce/diagnostic-rerunner.d.ts +40 -0
- package/dist/reproduce/diagnostic-rerunner.d.ts.map +1 -0
- package/dist/reproduce/direct-browser-investigator.d.ts +41 -0
- package/dist/reproduce/direct-browser-investigator.d.ts.map +1 -0
- package/dist/reproduce/interactive-workflow-runner.d.ts +43 -0
- package/dist/reproduce/interactive-workflow-runner.d.ts.map +1 -0
- package/dist/sandbox/dependency-strategy.d.ts +45 -0
- package/dist/sandbox/dependency-strategy.d.ts.map +1 -0
- package/dist/sandbox/execution-runner.d.ts +81 -0
- package/dist/sandbox/execution-runner.d.ts.map +1 -0
- package/dist/sandbox/worktree-manager.d.ts +51 -0
- package/dist/sandbox/worktree-manager.d.ts.map +1 -0
- package/dist/selector/abstention-policy.d.ts +34 -0
- package/dist/selector/abstention-policy.d.ts.map +1 -0
- package/dist/selector/candidate-extractor.d.ts +71 -0
- package/dist/selector/candidate-extractor.d.ts.map +1 -0
- package/dist/selector/live-locator-verifier.d.ts +28 -0
- package/dist/selector/live-locator-verifier.d.ts.map +1 -0
- package/dist/selector/repair-candidate-ranker.d.ts +10 -0
- package/dist/selector/repair-candidate-ranker.d.ts.map +1 -0
- package/dist/selector/selector-scorer.d.ts +43 -0
- package/dist/selector/selector-scorer.d.ts.map +1 -0
- package/dist/trace/adapters/adapter-registry.d.ts +18 -0
- package/dist/trace/adapters/adapter-registry.d.ts.map +1 -0
- package/dist/trace/adapters/trace-adapter.d.ts +21 -0
- package/dist/trace/adapters/trace-adapter.d.ts.map +1 -0
- package/dist/trace/adapters/unknown-adapter.d.ts +10 -0
- package/dist/trace/adapters/unknown-adapter.d.ts.map +1 -0
- package/dist/trace/adapters/v10-adapter.d.ts +10 -0
- package/dist/trace/adapters/v10-adapter.d.ts.map +1 -0
- package/dist/trace/adapters/v4-adapter.d.ts +11 -0
- package/dist/trace/adapters/v4-adapter.d.ts.map +1 -0
- package/dist/trace/adapters/v8-adapter.d.ts +10 -0
- package/dist/trace/adapters/v8-adapter.d.ts.map +1 -0
- package/dist/trace/adapters/v9-adapter.d.ts +10 -0
- package/dist/trace/adapters/v9-adapter.d.ts.map +1 -0
- package/dist/trace/archive-reader.d.ts +44 -0
- package/dist/trace/archive-reader.d.ts.map +1 -0
- package/dist/trace/snapshot-resolver.d.ts +55 -0
- package/dist/trace/snapshot-resolver.d.ts.map +1 -0
- package/dist/trace/trace-parser.d.ts +50 -0
- package/dist/trace/trace-parser.d.ts.map +1 -0
- package/dist/trace/version-detector.d.ts +20 -0
- package/dist/trace/version-detector.d.ts.map +1 -0
- package/package.json +76 -6
- package/skills/README.md +20 -0
- package/skills/pie-failure-investigation/SKILL.md +16 -0
- package/skills/pie-quality-engineer/SKILL.md +66 -0
- package/skills/pie-release-readiness/SKILL.md +22 -0
- package/skills/pie-repair-review/SKILL.md +21 -0
- package/skills/pie-trace-to-repair/SKILL.md +35 -0
- package/src/authoring/author.ts +81 -0
- package/src/authoring/generation-contract.ts +283 -0
- package/src/authoring/hybrid-author.ts +115 -0
- package/src/authoring/index.ts +7 -0
- package/src/authoring/llm-author.ts +282 -0
- package/src/authoring/naming/index.ts +4 -0
- package/src/authoring/naming/name-plan.ts +28 -0
- package/src/authoring/naming/name-planner.ts +339 -0
- package/src/authoring/naming/naming-linter.ts +292 -0
- package/src/authoring/template-author.ts +39 -0
- package/src/cli/index.ts +1172 -0
- package/src/collectors/collector-interface.ts +8 -0
- package/src/collectors/environment-collector.ts +103 -0
- package/src/collectors/error-collector.ts +177 -0
- package/src/collectors/git-diff-collector.ts +190 -0
- package/src/collectors/live-browser-collector.ts +412 -0
- package/src/collectors/network-collector.ts +90 -0
- package/src/collectors/static-ast-collector.ts +226 -0
- package/src/collectors/trace-collector.ts +66 -0
- package/src/config/project-config.ts +114 -0
- package/src/core/errors/engine-errors.ts +90 -0
- package/src/core/types/diagnostic-context.ts +94 -0
- package/src/core/types/repair-evidence.ts +45 -0
- package/src/core/version.ts +25 -0
- package/src/diagnostics/diagnostic-contract.ts +79 -0
- package/src/diagnostics/diagnostic-report.ts +204 -0
- package/src/diagnostics/evidence-correlator.ts +117 -0
- package/src/diagnostics/external-failure-evidence.ts +72 -0
- package/src/diagnostics/failure-category.ts +40 -0
- package/src/diagnostics/failure-classifier.ts +701 -0
- package/src/evaluation/evaluation-scorecard.ts +198 -0
- package/src/evaluation/repository-inspector.ts +143 -0
- package/src/evaluation/repository-runner.ts +197 -0
- package/src/evidence/evidence-model.ts +76 -0
- package/src/evidence/evidence-normalizer.ts +322 -0
- package/src/evidence/evidence-redactor.ts +218 -0
- package/src/framework/config-adapter.ts +131 -0
- package/src/gate/index.ts +43 -0
- package/src/gate/oracle.ts +69 -0
- package/src/gate/quality.ts +101 -0
- package/src/gate/safety.ts +94 -0
- package/src/generator/architecture-generator.ts +582 -0
- package/src/generator/assertion-quality-gate.ts +88 -0
- package/src/generator/candidate-writer.ts +288 -0
- package/src/generator/test-generator.ts +52 -0
- package/src/governance/audit-log.ts +115 -0
- package/src/governance/governance-policy.ts +72 -0
- package/src/governance/team-dashboard.ts +189 -0
- package/src/governance/workflow-audit.ts +72 -0
- package/src/index.ts +107 -0
- package/src/integrations/ci-summary.ts +37 -0
- package/src/integrations/playwright-report-adapter.ts +173 -0
- package/src/integrations/quality-gate.ts +95 -0
- package/src/integrations/sarif-report.ts +110 -0
- package/src/intelligence/autonomous-repair-workflow.ts +139 -0
- package/src/intelligence/business-intent.ts +163 -0
- package/src/intelligence/evidence-bundle.ts +300 -0
- package/src/intelligence/failure-clustering.ts +134 -0
- package/src/intelligence/generation-agent.ts +561 -0
- package/src/intelligence/generation-verifier.ts +1115 -0
- package/src/intelligence/llm-proposal.ts +519 -0
- package/src/intelligence/locator-disambiguation-engine.ts +331 -0
- package/src/intelligence/model-contract.ts +205 -0
- package/src/intelligence/model-provider.ts +348 -0
- package/src/intelligence/project-intelligence.ts +140 -0
- package/src/intelligence/repair-agent.ts +297 -0
- package/src/intelligence/repository-profile.ts +796 -0
- package/src/intelligence/suite-intelligence.ts +305 -0
- package/src/intelligence/test-intelligence.ts +136 -0
- package/src/intelligence/trace-proposal-workflow.ts +318 -0
- package/src/intelligence/verified-llm-repair-workflow.ts +48 -0
- package/src/intelligence/workflow-planner.ts +966 -0
- package/src/mcp/server.ts +970 -0
- package/src/memory/stability-ledger.ts +243 -0
- package/src/perception/app-model.ts +32 -0
- package/src/perception/crawler.ts +263 -0
- package/src/perception/index.ts +3 -0
- package/src/repair/approval-service.ts +541 -0
- package/src/repair/assertion-hasher.ts +386 -0
- package/src/repair/ast-patcher.ts +223 -0
- package/src/repair/browser-operation-executor.ts +263 -0
- package/src/repair/diff-allowlist.ts +612 -0
- package/src/repair/intent-validator.ts +761 -0
- package/src/repair/repair-operations.ts +65 -0
- package/src/repair/repair-planner.ts +467 -0
- package/src/repair/repair-workflow.ts +241 -0
- package/src/repair/safe-operation-compiler.ts +68 -0
- package/src/repair/source-mapper.ts +156 -0
- package/src/repair/statement-patcher.ts +544 -0
- package/src/repair/verification-gates.ts +46 -0
- package/src/repair/workflow-plan.ts +59 -0
- package/src/repair/workspace-promoter.ts +313 -0
- package/src/reproduce/diagnostic-rerunner.ts +287 -0
- package/src/reproduce/direct-browser-investigator.ts +208 -0
- package/src/reproduce/interactive-workflow-runner.ts +828 -0
- package/src/sandbox/dependency-strategy.ts +215 -0
- package/src/sandbox/execution-runner.ts +408 -0
- package/src/sandbox/worktree-manager.ts +287 -0
- package/src/selector/abstention-policy.ts +175 -0
- package/src/selector/candidate-extractor.ts +343 -0
- package/src/selector/live-locator-verifier.ts +139 -0
- package/src/selector/repair-candidate-ranker.ts +92 -0
- package/src/selector/selector-scorer.ts +344 -0
- package/src/trace/adapters/adapter-registry.ts +49 -0
- package/src/trace/adapters/trace-adapter.ts +28 -0
- package/src/trace/adapters/unknown-adapter.ts +50 -0
- package/src/trace/adapters/v10-adapter.ts +39 -0
- package/src/trace/adapters/v4-adapter.ts +31 -0
- package/src/trace/adapters/v8-adapter.ts +42 -0
- package/src/trace/adapters/v9-adapter.ts +39 -0
- package/src/trace/archive-reader.ts +246 -0
- package/src/trace/snapshot-resolver.ts +308 -0
- package/src/trace/trace-parser.ts +467 -0
- package/src/trace/version-detector.ts +81 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export type IsolationLevel =
|
|
5
|
+
| 'FULLY_ISOLATED'
|
|
6
|
+
| 'IMMUTABLE_SHARED'
|
|
7
|
+
| 'SHARED_MUTABLE'
|
|
8
|
+
| 'UNSUPPORTED';
|
|
9
|
+
|
|
10
|
+
export interface DependencyPreparationResult {
|
|
11
|
+
isolationLevel: IsolationLevel;
|
|
12
|
+
strategy: 'npm' | 'pnpm' | 'yarn-classic' | 'yarn-pnp' | 'none';
|
|
13
|
+
linkedPaths: string[];
|
|
14
|
+
warning?: string | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface DependencyValidationResult {
|
|
18
|
+
isValid: boolean;
|
|
19
|
+
isolationLevel: IsolationLevel;
|
|
20
|
+
error?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface DependencyStrategy {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
detect(root: string): Promise<boolean>;
|
|
26
|
+
prepare(root: string, worktree: string): Promise<DependencyPreparationResult>;
|
|
27
|
+
validate(worktree: string): Promise<DependencyValidationResult>;
|
|
28
|
+
cleanup(worktree: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class NpmStrategy implements DependencyStrategy {
|
|
32
|
+
public readonly name = 'npm';
|
|
33
|
+
|
|
34
|
+
public async detect(root: string): Promise<boolean> {
|
|
35
|
+
try {
|
|
36
|
+
await fs.access(path.resolve(root, 'package-lock.json'));
|
|
37
|
+
return true;
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async prepare(root: string, worktree: string): Promise<DependencyPreparationResult> {
|
|
44
|
+
const sourceNodeModules = path.resolve(root, 'node_modules');
|
|
45
|
+
const targetNodeModules = path.resolve(worktree, 'node_modules');
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await fs.access(sourceNodeModules);
|
|
49
|
+
const linkType = process.platform === 'win32' ? 'junction' : 'dir';
|
|
50
|
+
await fs.symlink(sourceNodeModules, targetNodeModules, linkType);
|
|
51
|
+
return {
|
|
52
|
+
isolationLevel: 'IMMUTABLE_SHARED',
|
|
53
|
+
strategy: 'npm',
|
|
54
|
+
linkedPaths: [targetNodeModules],
|
|
55
|
+
};
|
|
56
|
+
} catch {
|
|
57
|
+
return {
|
|
58
|
+
isolationLevel: 'UNSUPPORTED',
|
|
59
|
+
strategy: 'npm',
|
|
60
|
+
linkedPaths: [],
|
|
61
|
+
warning: 'Root node_modules not found. npm install must be run in repository root.',
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public async validate(worktree: string): Promise<DependencyValidationResult> {
|
|
67
|
+
const target = path.resolve(worktree, 'node_modules');
|
|
68
|
+
try {
|
|
69
|
+
const stats = await fs.lstat(target);
|
|
70
|
+
const isValid = stats.isSymbolicLink() || stats.isDirectory();
|
|
71
|
+
return {
|
|
72
|
+
isValid,
|
|
73
|
+
isolationLevel: 'IMMUTABLE_SHARED',
|
|
74
|
+
};
|
|
75
|
+
} catch (err: any) {
|
|
76
|
+
return {
|
|
77
|
+
isValid: false,
|
|
78
|
+
isolationLevel: 'UNSUPPORTED',
|
|
79
|
+
error: `node_modules junction missing in worktree: ${err.message}`,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public async cleanup(worktree: string): Promise<void> {
|
|
85
|
+
const target = path.resolve(worktree, 'node_modules');
|
|
86
|
+
try {
|
|
87
|
+
const stats = await fs.lstat(target).catch(() => null);
|
|
88
|
+
if (stats && stats.isSymbolicLink()) {
|
|
89
|
+
await fs.unlink(target);
|
|
90
|
+
}
|
|
91
|
+
} catch {
|
|
92
|
+
// Ignore if already deleted
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export class PnpmStrategy implements DependencyStrategy {
|
|
98
|
+
public readonly name = 'pnpm';
|
|
99
|
+
|
|
100
|
+
public async detect(root: string): Promise<boolean> {
|
|
101
|
+
try {
|
|
102
|
+
await fs.access(path.resolve(root, 'pnpm-lock.yaml'));
|
|
103
|
+
return true;
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public async prepare(root: string, worktree: string): Promise<DependencyPreparationResult> {
|
|
110
|
+
const sourceNodeModules = path.resolve(root, 'node_modules');
|
|
111
|
+
const targetNodeModules = path.resolve(worktree, 'node_modules');
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
await fs.access(sourceNodeModules);
|
|
115
|
+
const linkType = process.platform === 'win32' ? 'junction' : 'dir';
|
|
116
|
+
await fs.symlink(sourceNodeModules, targetNodeModules, linkType);
|
|
117
|
+
|
|
118
|
+
// In pnpm virtual store layouts, mutable cache directories (e.g. .cache, .vite, .prisma)
|
|
119
|
+
// can leak state between worktrees. We flag SHARED_MUTABLE.
|
|
120
|
+
return {
|
|
121
|
+
isolationLevel: 'SHARED_MUTABLE',
|
|
122
|
+
strategy: 'pnpm',
|
|
123
|
+
linkedPaths: [targetNodeModules],
|
|
124
|
+
warning: 'pnpm virtual store detected. Mutable build caches (.cache, .vite) may be shared across worktrees.',
|
|
125
|
+
};
|
|
126
|
+
} catch {
|
|
127
|
+
return {
|
|
128
|
+
isolationLevel: 'UNSUPPORTED',
|
|
129
|
+
strategy: 'pnpm',
|
|
130
|
+
linkedPaths: [],
|
|
131
|
+
warning: 'Root node_modules not found for pnpm.',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
public async validate(worktree: string): Promise<DependencyValidationResult> {
|
|
137
|
+
const target = path.resolve(worktree, 'node_modules');
|
|
138
|
+
try {
|
|
139
|
+
await fs.lstat(target);
|
|
140
|
+
return {
|
|
141
|
+
isValid: true,
|
|
142
|
+
isolationLevel: 'SHARED_MUTABLE',
|
|
143
|
+
};
|
|
144
|
+
} catch (err: any) {
|
|
145
|
+
return {
|
|
146
|
+
isValid: false,
|
|
147
|
+
isolationLevel: 'UNSUPPORTED',
|
|
148
|
+
error: err.message,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
public async cleanup(worktree: string): Promise<void> {
|
|
154
|
+
const target = path.resolve(worktree, 'node_modules');
|
|
155
|
+
try {
|
|
156
|
+
const stats = await fs.lstat(target).catch(() => null);
|
|
157
|
+
if (stats && stats.isSymbolicLink()) {
|
|
158
|
+
await fs.unlink(target);
|
|
159
|
+
}
|
|
160
|
+
} catch {
|
|
161
|
+
// Ignore
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export class YarnPnpStrategy implements DependencyStrategy {
|
|
167
|
+
public readonly name = 'yarn-pnp';
|
|
168
|
+
|
|
169
|
+
public async detect(root: string): Promise<boolean> {
|
|
170
|
+
try {
|
|
171
|
+
await fs.access(path.resolve(root, '.pnp.cjs'));
|
|
172
|
+
return true;
|
|
173
|
+
} catch {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
public async prepare(_root: string, _worktree: string): Promise<DependencyPreparationResult> {
|
|
179
|
+
return {
|
|
180
|
+
isolationLevel: 'UNSUPPORTED',
|
|
181
|
+
strategy: 'yarn-pnp',
|
|
182
|
+
linkedPaths: [],
|
|
183
|
+
warning: 'Yarn Berry PlugnPlay (PnP) does not use node_modules directory. Unlinking is unsupported.',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public async validate(_worktree: string): Promise<DependencyValidationResult> {
|
|
188
|
+
return {
|
|
189
|
+
isValid: false,
|
|
190
|
+
isolationLevel: 'UNSUPPORTED',
|
|
191
|
+
error: 'Yarn PnP not supported for directory junction linking',
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public async cleanup(_worktree: string): Promise<void> {}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export class DependencyStrategyResolver {
|
|
199
|
+
private static strategies: DependencyStrategy[] = [
|
|
200
|
+
new YarnPnpStrategy(),
|
|
201
|
+
new PnpmStrategy(),
|
|
202
|
+
new NpmStrategy(),
|
|
203
|
+
];
|
|
204
|
+
|
|
205
|
+
public static async resolve(root: string): Promise<DependencyStrategy> {
|
|
206
|
+
for (const strategy of DependencyStrategyResolver.strategies) {
|
|
207
|
+
if (await strategy.detect(root)) {
|
|
208
|
+
return strategy;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// Default fallback to NpmStrategy
|
|
212
|
+
return new NpmStrategy();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
|
|
5
|
+
export interface ExecutionOptions {
|
|
6
|
+
cwd: string;
|
|
7
|
+
args?: string[];
|
|
8
|
+
env?: Record<string, string>;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ExecutionResult {
|
|
13
|
+
exitCode: number;
|
|
14
|
+
stdout: string;
|
|
15
|
+
stderr: string;
|
|
16
|
+
durationMs: number;
|
|
17
|
+
timedOut: boolean;
|
|
18
|
+
truncated: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class ExecutionRunner {
|
|
22
|
+
public static readonly MAX_OUTPUT_BYTES = 16 * 1024 * 1024; // 16 MB max byte buffer limit
|
|
23
|
+
|
|
24
|
+
private static readonly SAFE_ENV_KEYS = new Set([
|
|
25
|
+
'PATH',
|
|
26
|
+
'Path',
|
|
27
|
+
'PATHEXT',
|
|
28
|
+
'SYSTEMROOT',
|
|
29
|
+
'SystemRoot',
|
|
30
|
+
'SYSTEMDRIVE',
|
|
31
|
+
'SystemDrive',
|
|
32
|
+
'TEMP',
|
|
33
|
+
'TMP',
|
|
34
|
+
'HOMEDRIVE',
|
|
35
|
+
'HOMEPATH',
|
|
36
|
+
'USERPROFILE',
|
|
37
|
+
'APPDATA',
|
|
38
|
+
'LOCALAPPDATA',
|
|
39
|
+
'LANG',
|
|
40
|
+
'LC_ALL',
|
|
41
|
+
'NODE_ENV',
|
|
42
|
+
'TERM',
|
|
43
|
+
'SHELL',
|
|
44
|
+
'PWD',
|
|
45
|
+
'COMSPEC',
|
|
46
|
+
'ComSpec',
|
|
47
|
+
'CI',
|
|
48
|
+
'PW_INTELLIGENCE_REPRODUCE',
|
|
49
|
+
'PLAYWRIGHT_BROWSERS_PATH',
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
private static readonly DANGEROUS_ENV_KEYS = new Set([
|
|
53
|
+
'NODE_OPTIONS',
|
|
54
|
+
'LD_PRELOAD',
|
|
55
|
+
'LD_LIBRARY_PATH',
|
|
56
|
+
'DYLD_INSERT_LIBRARIES',
|
|
57
|
+
'DYLD_LIBRARY_PATH',
|
|
58
|
+
'PERL5OPT',
|
|
59
|
+
'PYTHONPATH',
|
|
60
|
+
'RUBYOPT',
|
|
61
|
+
'BASH_ENV',
|
|
62
|
+
'ENV',
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
private static readonly SIGNAL_MAP: Record<string, number> = {
|
|
66
|
+
SIGHUP: 1,
|
|
67
|
+
SIGINT: 2,
|
|
68
|
+
SIGQUIT: 3,
|
|
69
|
+
SIGILL: 4,
|
|
70
|
+
SIGTRAP: 5,
|
|
71
|
+
SIGABRT: 6,
|
|
72
|
+
SIGBUS: 7,
|
|
73
|
+
SIGFPE: 8,
|
|
74
|
+
SIGKILL: 9,
|
|
75
|
+
SIGUSR1: 10,
|
|
76
|
+
SIGSEGV: 11,
|
|
77
|
+
SIGUSR2: 12,
|
|
78
|
+
SIGPIPE: 13,
|
|
79
|
+
SIGALRM: 14,
|
|
80
|
+
SIGTERM: 15,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Sanitizes inherited and explicit environment variables (AUDIT-15).
|
|
85
|
+
* Strictly filters against SAFE_ENV_KEYS and explicitly blocks dangerous
|
|
86
|
+
* interpreter-injection keys like NODE_OPTIONS.
|
|
87
|
+
*/
|
|
88
|
+
public static getSanitizedEnv(explicitEnv?: Record<string, string | undefined>): Record<string, string> {
|
|
89
|
+
const sanitized: Record<string, string> = {};
|
|
90
|
+
|
|
91
|
+
for (const [key, val] of Object.entries(process.env)) {
|
|
92
|
+
if (ExecutionRunner.SAFE_ENV_KEYS.has(key) && val !== undefined) {
|
|
93
|
+
sanitized[key] = val;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (explicitEnv) {
|
|
98
|
+
for (const [key, val] of Object.entries(explicitEnv)) {
|
|
99
|
+
if (val !== undefined) {
|
|
100
|
+
const upperKey = key.toUpperCase();
|
|
101
|
+
if (ExecutionRunner.DANGEROUS_ENV_KEYS.has(upperKey)) {
|
|
102
|
+
// Reject dangerous interpreter override keys
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
// Allow explicit test variables matching safe prefixes or safe allowlist
|
|
106
|
+
if (
|
|
107
|
+
ExecutionRunner.SAFE_ENV_KEYS.has(key) ||
|
|
108
|
+
key.startsWith('PLAYWRIGHT_') ||
|
|
109
|
+
key.startsWith('TEST_') ||
|
|
110
|
+
key.startsWith('PW_') ||
|
|
111
|
+
key === 'DEBUG' ||
|
|
112
|
+
key === 'PORT'
|
|
113
|
+
) {
|
|
114
|
+
sanitized[key] = val;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return sanitized;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Executes a command safely using child_process.spawn with an explicit argument array.
|
|
125
|
+
* Eliminates shell injection risks, sanitizes environment, bounds buffer sizes strictly by bytes,
|
|
126
|
+
* preserves signal exit codes, and terminates entire process trees upon timeout.
|
|
127
|
+
*/
|
|
128
|
+
public static async run(
|
|
129
|
+
command: string,
|
|
130
|
+
options: ExecutionOptions
|
|
131
|
+
): Promise<ExecutionResult> {
|
|
132
|
+
const args = options.args ?? [];
|
|
133
|
+
const timeoutMs = options.timeoutMs ?? 120000; // Default 2 minutes
|
|
134
|
+
const startTime = Date.now();
|
|
135
|
+
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
|
+
let stdoutBytes = 0;
|
|
138
|
+
let stderrBytes = 0;
|
|
139
|
+
const stdoutChunks: Buffer[] = [];
|
|
140
|
+
const stderrChunks: Buffer[] = [];
|
|
141
|
+
let timedOut = false;
|
|
142
|
+
let truncated = false;
|
|
143
|
+
|
|
144
|
+
// On Windows, resolve npx/npm directly via node.exe with bundled CLI scripts to avoid cmd.exe shell injection
|
|
145
|
+
const isWindows = process.platform === 'win32';
|
|
146
|
+
let executable = command;
|
|
147
|
+
let finalArgs = args;
|
|
148
|
+
|
|
149
|
+
if (isWindows && (command === 'npx' || command === 'npm')) {
|
|
150
|
+
const cliName = command === 'npx' ? 'npx-cli.js' : 'npm-cli.js';
|
|
151
|
+
const bundledCli = path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', cliName);
|
|
152
|
+
const cmdScript = path.join(path.dirname(process.execPath), `${command}.cmd`);
|
|
153
|
+
if (fs.existsSync(bundledCli)) {
|
|
154
|
+
executable = process.execPath;
|
|
155
|
+
finalArgs = [bundledCli, ...args];
|
|
156
|
+
} else if (fs.existsSync(cmdScript)) {
|
|
157
|
+
executable = cmdScript;
|
|
158
|
+
finalArgs = args;
|
|
159
|
+
} else {
|
|
160
|
+
executable = `${command}.cmd`;
|
|
161
|
+
finalArgs = args;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const child = spawn(executable, finalArgs, {
|
|
166
|
+
cwd: options.cwd,
|
|
167
|
+
env: ExecutionRunner.getSanitizedEnv(options.env),
|
|
168
|
+
shell: false,
|
|
169
|
+
windowsHide: true,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const timer = setTimeout(() => {
|
|
173
|
+
timedOut = true;
|
|
174
|
+
if (child.pid) {
|
|
175
|
+
if (isWindows) {
|
|
176
|
+
try {
|
|
177
|
+
spawnSync('taskkill', ['/pid', String(child.pid), '/T', '/F'], { windowsHide: true });
|
|
178
|
+
} catch {
|
|
179
|
+
child.kill();
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
child.kill('SIGTERM');
|
|
183
|
+
setTimeout(() => {
|
|
184
|
+
try {
|
|
185
|
+
child.kill('SIGKILL');
|
|
186
|
+
} catch {
|
|
187
|
+
// process already dead
|
|
188
|
+
}
|
|
189
|
+
}, 2000);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}, timeoutMs);
|
|
193
|
+
|
|
194
|
+
child.stdout?.on('data', (chunk: Buffer | string) => {
|
|
195
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, 'utf-8');
|
|
196
|
+
if (stdoutBytes + buf.length <= ExecutionRunner.MAX_OUTPUT_BYTES) {
|
|
197
|
+
stdoutChunks.push(buf);
|
|
198
|
+
stdoutBytes += buf.length;
|
|
199
|
+
} else {
|
|
200
|
+
const remaining = ExecutionRunner.MAX_OUTPUT_BYTES - stdoutBytes;
|
|
201
|
+
if (remaining > 0) {
|
|
202
|
+
stdoutChunks.push(buf.subarray(0, remaining));
|
|
203
|
+
stdoutBytes += remaining;
|
|
204
|
+
}
|
|
205
|
+
truncated = true;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
child.stderr?.on('data', (chunk: Buffer | string) => {
|
|
210
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, 'utf-8');
|
|
211
|
+
if (stderrBytes + buf.length <= ExecutionRunner.MAX_OUTPUT_BYTES) {
|
|
212
|
+
stderrChunks.push(buf);
|
|
213
|
+
stderrBytes += buf.length;
|
|
214
|
+
} else {
|
|
215
|
+
const remaining = ExecutionRunner.MAX_OUTPUT_BYTES - stderrBytes;
|
|
216
|
+
if (remaining > 0) {
|
|
217
|
+
stderrChunks.push(buf.subarray(0, remaining));
|
|
218
|
+
stderrBytes += remaining;
|
|
219
|
+
}
|
|
220
|
+
truncated = true;
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
child.on('error', (err) => {
|
|
225
|
+
clearTimeout(timer);
|
|
226
|
+
const stdoutStr = Buffer.concat(stdoutChunks).toString('utf-8');
|
|
227
|
+
const stderrStr = Buffer.concat(stderrChunks).toString('utf-8');
|
|
228
|
+
resolve({
|
|
229
|
+
exitCode: -1,
|
|
230
|
+
stdout: stdoutStr,
|
|
231
|
+
stderr: stderrStr + `\nProcess error: ${err.message}`,
|
|
232
|
+
durationMs: Date.now() - startTime,
|
|
233
|
+
timedOut,
|
|
234
|
+
truncated,
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
child.on('close', (code, signal) => {
|
|
239
|
+
clearTimeout(timer);
|
|
240
|
+
// Correct signal-terminated process handling (AUDIT-08): never map code === null to 0
|
|
241
|
+
let exitCode: number;
|
|
242
|
+
if (code !== null) {
|
|
243
|
+
exitCode = code;
|
|
244
|
+
} else if (timedOut) {
|
|
245
|
+
exitCode = -1;
|
|
246
|
+
} else if (signal) {
|
|
247
|
+
const sigNum = ExecutionRunner.SIGNAL_MAP[signal] ?? 15;
|
|
248
|
+
exitCode = 128 + sigNum;
|
|
249
|
+
} else {
|
|
250
|
+
exitCode = 1;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const stdoutStr = Buffer.concat(stdoutChunks).toString('utf-8');
|
|
254
|
+
const stderrStr = Buffer.concat(stderrChunks).toString('utf-8');
|
|
255
|
+
|
|
256
|
+
resolve({
|
|
257
|
+
exitCode,
|
|
258
|
+
stdout: stdoutStr,
|
|
259
|
+
stderr: stderrStr,
|
|
260
|
+
durationMs: Date.now() - startTime,
|
|
261
|
+
timedOut,
|
|
262
|
+
truncated,
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Executes a Playwright test specification via npx in the specified working directory.
|
|
270
|
+
* Guarantees process isolation, command sanitization, and true execution proofs.
|
|
271
|
+
*/
|
|
272
|
+
public static async runPlaywrightTest(options: {
|
|
273
|
+
cwd: string;
|
|
274
|
+
testFilePath: string;
|
|
275
|
+
configPath?: string | undefined;
|
|
276
|
+
grep?: string | undefined;
|
|
277
|
+
timeoutMs?: number | undefined;
|
|
278
|
+
env?: Record<string, string> | undefined;
|
|
279
|
+
}): Promise<ExecutionResult> {
|
|
280
|
+
const relOrNormPath = path.isAbsolute(options.testFilePath)
|
|
281
|
+
? path.relative(options.cwd, options.testFilePath).replace(/\\/g, '/') || options.testFilePath.replace(/\\/g, '/')
|
|
282
|
+
: options.testFilePath.replace(/\\/g, '/');
|
|
283
|
+
const args = ['playwright', 'test', relOrNormPath, '--reporter=line'];
|
|
284
|
+
if (options.configPath) {
|
|
285
|
+
args.push('--config', options.configPath);
|
|
286
|
+
}
|
|
287
|
+
if (options.grep) {
|
|
288
|
+
args.push('-g', options.grep);
|
|
289
|
+
}
|
|
290
|
+
const runnerOptions: ExecutionOptions = {
|
|
291
|
+
cwd: options.cwd,
|
|
292
|
+
args,
|
|
293
|
+
timeoutMs: options.timeoutMs ?? 60000,
|
|
294
|
+
};
|
|
295
|
+
if (options.env) {
|
|
296
|
+
runnerOptions.env = options.env;
|
|
297
|
+
}
|
|
298
|
+
return ExecutionRunner.run('npx', runnerOptions);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Computes the two-sided Wilson score confidence interval for binomial success rates.
|
|
303
|
+
* Provides mathematically rigorous confidence bounds for flaky test verification.
|
|
304
|
+
*/
|
|
305
|
+
public static computeWilsonScoreInterval(k: number, n: number, confidence = 0.95): WilsonScoreInterval {
|
|
306
|
+
if (n <= 0) {
|
|
307
|
+
return { lower: 0, upper: 0, center: 0, confidenceLevel: confidence };
|
|
308
|
+
}
|
|
309
|
+
const z = confidence === 0.99 ? 2.5758 : 1.95996;
|
|
310
|
+
const p = Math.max(0, Math.min(1, k / n));
|
|
311
|
+
const z2 = z * z;
|
|
312
|
+
const denominator = 1 + z2 / n;
|
|
313
|
+
const center = (p + z2 / (2 * n)) / denominator;
|
|
314
|
+
const margin = (z * Math.sqrt((p * (1 - p)) / n + z2 / (4 * n * n))) / denominator;
|
|
315
|
+
|
|
316
|
+
const lower = Math.max(0, parseFloat(((center - margin) * 100).toFixed(2)));
|
|
317
|
+
const upper = Math.min(100, parseFloat(((center + margin) * 100).toFixed(2)));
|
|
318
|
+
|
|
319
|
+
return {
|
|
320
|
+
lower,
|
|
321
|
+
upper,
|
|
322
|
+
center: parseFloat((center * 100).toFixed(2)),
|
|
323
|
+
confidenceLevel: confidence,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Executes repeated trials of a Playwright test specification to statistically
|
|
329
|
+
* evaluate flakiness and measure intent preservation with Wilson confidence intervals.
|
|
330
|
+
*/
|
|
331
|
+
public static async runRepeatedPlaywrightTrials(options: {
|
|
332
|
+
cwd: string;
|
|
333
|
+
testFilePath: string;
|
|
334
|
+
trials: number;
|
|
335
|
+
configPath?: string | undefined;
|
|
336
|
+
grep?: string | undefined;
|
|
337
|
+
timeoutMs?: number | undefined;
|
|
338
|
+
env?: Record<string, string> | undefined;
|
|
339
|
+
}): Promise<RepeatedExecutionSummary> {
|
|
340
|
+
const trialsCount = Math.max(1, options.trials);
|
|
341
|
+
const results: ExecutionResult[] = [];
|
|
342
|
+
const durations: number[] = [];
|
|
343
|
+
let passed = 0;
|
|
344
|
+
let failed = 0;
|
|
345
|
+
let timedOut = 0;
|
|
346
|
+
|
|
347
|
+
for (let i = 0; i < trialsCount; i++) {
|
|
348
|
+
const res = await ExecutionRunner.runPlaywrightTest({
|
|
349
|
+
cwd: options.cwd,
|
|
350
|
+
testFilePath: options.testFilePath,
|
|
351
|
+
configPath: options.configPath,
|
|
352
|
+
grep: options.grep,
|
|
353
|
+
timeoutMs: options.timeoutMs,
|
|
354
|
+
env: options.env,
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
results.push(res);
|
|
358
|
+
durations.push(res.durationMs);
|
|
359
|
+
|
|
360
|
+
if (res.exitCode === 0) {
|
|
361
|
+
passed++;
|
|
362
|
+
} else {
|
|
363
|
+
failed++;
|
|
364
|
+
if (res.timedOut) {
|
|
365
|
+
timedOut++;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const passRatePct = parseFloat(((passed / trialsCount) * 100).toFixed(2));
|
|
371
|
+
const isFlaky = passed > 0 && failed > 0;
|
|
372
|
+
const wilsonInterval95 = ExecutionRunner.computeWilsonScoreInterval(passed, trialsCount, 0.95);
|
|
373
|
+
const averageDurationMs = durations.reduce((acc, d) => acc + d, 0) / durations.length;
|
|
374
|
+
|
|
375
|
+
return {
|
|
376
|
+
totalTrials: trialsCount,
|
|
377
|
+
passedCount: passed,
|
|
378
|
+
failedCount: failed,
|
|
379
|
+
timedOutCount: timedOut,
|
|
380
|
+
passRatePct,
|
|
381
|
+
isFlaky,
|
|
382
|
+
wilsonInterval95,
|
|
383
|
+
averageDurationMs: parseFloat(averageDurationMs.toFixed(2)),
|
|
384
|
+
trialDurationsMs: durations,
|
|
385
|
+
trials: results,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export interface WilsonScoreInterval {
|
|
391
|
+
lower: number;
|
|
392
|
+
upper: number;
|
|
393
|
+
center: number;
|
|
394
|
+
confidenceLevel: number;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface RepeatedExecutionSummary {
|
|
398
|
+
totalTrials: number;
|
|
399
|
+
passedCount: number;
|
|
400
|
+
failedCount: number;
|
|
401
|
+
timedOutCount: number;
|
|
402
|
+
passRatePct: number;
|
|
403
|
+
isFlaky: boolean;
|
|
404
|
+
wilsonInterval95: WilsonScoreInterval;
|
|
405
|
+
averageDurationMs: number;
|
|
406
|
+
trialDurationsMs: number[];
|
|
407
|
+
trials: ExecutionResult[];
|
|
408
|
+
}
|