@veraxhq/verax 0.2.1 → 0.4.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/README.md +10 -6
- package/bin/verax.js +11 -11
- package/package.json +29 -8
- package/src/cli/commands/baseline.js +103 -0
- package/src/cli/commands/default.js +51 -6
- package/src/cli/commands/doctor.js +29 -0
- package/src/cli/commands/ga.js +246 -0
- package/src/cli/commands/gates.js +95 -0
- package/src/cli/commands/inspect.js +4 -2
- package/src/cli/commands/release-check.js +215 -0
- package/src/cli/commands/run.js +45 -6
- package/src/cli/commands/security-check.js +212 -0
- package/src/cli/commands/truth.js +113 -0
- package/src/cli/entry.js +30 -20
- package/src/cli/util/angular-component-extractor.js +179 -0
- package/src/cli/util/angular-navigation-detector.js +141 -0
- package/src/cli/util/angular-network-detector.js +161 -0
- package/src/cli/util/angular-state-detector.js +162 -0
- package/src/cli/util/ast-interactive-detector.js +544 -0
- package/src/cli/util/ast-network-detector.js +603 -0
- package/src/cli/util/ast-promise-extractor.js +581 -0
- package/src/cli/util/ast-usestate-detector.js +602 -0
- package/src/cli/util/atomic-write.js +12 -1
- package/src/cli/util/bootstrap-guard.js +86 -0
- package/src/cli/util/console-reporter.js +72 -0
- package/src/cli/util/detection-engine.js +105 -41
- package/src/cli/util/determinism-runner.js +124 -0
- package/src/cli/util/determinism-writer.js +129 -0
- package/src/cli/util/digest-engine.js +359 -0
- package/src/cli/util/dom-diff.js +226 -0
- package/src/cli/util/evidence-engine.js +287 -0
- package/src/cli/util/expectation-extractor.js +151 -5
- package/src/cli/util/findings-writer.js +3 -0
- package/src/cli/util/framework-detector.js +572 -0
- package/src/cli/util/idgen.js +1 -1
- package/src/cli/util/interaction-planner.js +529 -0
- package/src/cli/util/learn-writer.js +2 -0
- package/src/cli/util/ledger-writer.js +110 -0
- package/src/cli/util/monorepo-resolver.js +162 -0
- package/src/cli/util/observation-engine.js +127 -278
- package/src/cli/util/observe-writer.js +2 -0
- package/src/cli/util/project-discovery.js +284 -0
- package/src/cli/util/project-writer.js +2 -0
- package/src/cli/util/run-id.js +23 -27
- package/src/cli/util/run-resolver.js +64 -0
- package/src/cli/util/run-result.js +778 -0
- package/src/cli/util/selector-resolver.js +235 -0
- package/src/cli/util/source-requirement.js +55 -0
- package/src/cli/util/summary-writer.js +2 -0
- package/src/cli/util/svelte-navigation-detector.js +163 -0
- package/src/cli/util/svelte-network-detector.js +80 -0
- package/src/cli/util/svelte-sfc-extractor.js +146 -0
- package/src/cli/util/svelte-state-detector.js +242 -0
- package/src/cli/util/trust-activation-integration.js +496 -0
- package/src/cli/util/trust-activation-wrapper.js +85 -0
- package/src/cli/util/trust-integration-hooks.js +164 -0
- package/src/cli/util/types.js +153 -0
- package/src/cli/util/url-validation.js +40 -0
- package/src/cli/util/vue-navigation-detector.js +178 -0
- package/src/cli/util/vue-sfc-extractor.js +161 -0
- package/src/cli/util/vue-state-detector.js +215 -0
- package/src/types/fs-augment.d.ts +23 -0
- package/src/types/global.d.ts +137 -0
- package/src/types/internal-types.d.ts +35 -0
- package/src/verax/cli/init.js +4 -18
- package/src/verax/core/action-classifier.js +4 -3
- package/src/verax/core/artifacts/registry.js +139 -0
- package/src/verax/core/artifacts/verifier.js +990 -0
- package/src/verax/core/baseline/baseline.enforcer.js +137 -0
- package/src/verax/core/baseline/baseline.snapshot.js +233 -0
- package/src/verax/core/capabilities/gates.js +505 -0
- package/src/verax/core/capabilities/registry.js +475 -0
- package/src/verax/core/confidence/confidence-compute.js +144 -0
- package/src/verax/core/confidence/confidence-invariants.js +234 -0
- package/src/verax/core/confidence/confidence-report-writer.js +112 -0
- package/src/verax/core/confidence/confidence-weights.js +44 -0
- package/src/verax/core/confidence/confidence.defaults.js +65 -0
- package/src/verax/core/confidence/confidence.loader.js +80 -0
- package/src/verax/core/confidence/confidence.schema.js +94 -0
- package/src/verax/core/confidence-engine-refactor.js +489 -0
- package/src/verax/core/confidence-engine.js +625 -0
- package/src/verax/core/contracts/index.js +29 -0
- package/src/verax/core/contracts/types.js +186 -0
- package/src/verax/core/contracts/validators.js +456 -0
- package/src/verax/core/decisions/decision.trace.js +278 -0
- package/src/verax/core/determinism/contract-writer.js +89 -0
- package/src/verax/core/determinism/contract.js +139 -0
- package/src/verax/core/determinism/diff.js +405 -0
- package/src/verax/core/determinism/engine.js +222 -0
- package/src/verax/core/determinism/finding-identity.js +149 -0
- package/src/verax/core/determinism/normalize.js +466 -0
- package/src/verax/core/determinism/report-writer.js +93 -0
- package/src/verax/core/determinism/run-fingerprint.js +123 -0
- package/src/verax/core/dynamic-route-intelligence.js +529 -0
- package/src/verax/core/evidence/evidence-capture-service.js +308 -0
- package/src/verax/core/evidence/evidence-intent-ledger.js +166 -0
- package/src/verax/core/evidence-builder.js +487 -0
- package/src/verax/core/execution-mode-context.js +77 -0
- package/src/verax/core/execution-mode-detector.js +192 -0
- package/src/verax/core/failures/exit-codes.js +88 -0
- package/src/verax/core/failures/failure-summary.js +76 -0
- package/src/verax/core/failures/failure.factory.js +225 -0
- package/src/verax/core/failures/failure.ledger.js +133 -0
- package/src/verax/core/failures/failure.types.js +196 -0
- package/src/verax/core/failures/index.js +10 -0
- package/src/verax/core/ga/ga-report-writer.js +43 -0
- package/src/verax/core/ga/ga.artifact.js +49 -0
- package/src/verax/core/ga/ga.contract.js +435 -0
- package/src/verax/core/ga/ga.enforcer.js +87 -0
- package/src/verax/core/guardrails/guardrails-report-writer.js +109 -0
- package/src/verax/core/guardrails/policy.defaults.js +210 -0
- package/src/verax/core/guardrails/policy.loader.js +84 -0
- package/src/verax/core/guardrails/policy.schema.js +110 -0
- package/src/verax/core/guardrails/truth-reconciliation.js +136 -0
- package/src/verax/core/guardrails-engine.js +505 -0
- package/src/verax/core/incremental-store.js +1 -0
- package/src/verax/core/integrity/budget.js +138 -0
- package/src/verax/core/integrity/determinism.js +342 -0
- package/src/verax/core/integrity/integrity.js +208 -0
- package/src/verax/core/integrity/poisoning.js +108 -0
- package/src/verax/core/integrity/transaction.js +140 -0
- package/src/verax/core/observe/run-timeline.js +318 -0
- package/src/verax/core/perf/perf.contract.js +186 -0
- package/src/verax/core/perf/perf.display.js +65 -0
- package/src/verax/core/perf/perf.enforcer.js +91 -0
- package/src/verax/core/perf/perf.monitor.js +209 -0
- package/src/verax/core/perf/perf.report.js +200 -0
- package/src/verax/core/pipeline-tracker.js +243 -0
- package/src/verax/core/product-definition.js +127 -0
- package/src/verax/core/release/provenance.builder.js +130 -0
- package/src/verax/core/release/release-report-writer.js +40 -0
- package/src/verax/core/release/release.enforcer.js +164 -0
- package/src/verax/core/release/reproducibility.check.js +222 -0
- package/src/verax/core/release/sbom.builder.js +292 -0
- package/src/verax/core/replay-validator.js +2 -0
- package/src/verax/core/replay.js +4 -0
- package/src/verax/core/report/cross-index.js +195 -0
- package/src/verax/core/report/human-summary.js +362 -0
- package/src/verax/core/route-intelligence.js +420 -0
- package/src/verax/core/run-id.js +6 -3
- package/src/verax/core/run-manifest.js +4 -3
- package/src/verax/core/security/secrets.scan.js +329 -0
- package/src/verax/core/security/security-report.js +50 -0
- package/src/verax/core/security/security.enforcer.js +128 -0
- package/src/verax/core/security/supplychain.defaults.json +38 -0
- package/src/verax/core/security/supplychain.policy.js +334 -0
- package/src/verax/core/security/vuln.scan.js +265 -0
- package/src/verax/core/truth/truth.certificate.js +252 -0
- package/src/verax/core/ui-feedback-intelligence.js +481 -0
- package/src/verax/detect/conditional-ui-silent-failure.js +84 -0
- package/src/verax/detect/confidence-engine.js +62 -34
- package/src/verax/detect/confidence-helper.js +34 -0
- package/src/verax/detect/dynamic-route-findings.js +338 -0
- package/src/verax/detect/expectation-chain-detector.js +417 -0
- package/src/verax/detect/expectation-model.js +2 -2
- package/src/verax/detect/failure-cause-inference.js +293 -0
- package/src/verax/detect/findings-writer.js +131 -35
- package/src/verax/detect/flow-detector.js +2 -2
- package/src/verax/detect/form-silent-failure.js +98 -0
- package/src/verax/detect/index.js +46 -5
- package/src/verax/detect/invariants-enforcer.js +147 -0
- package/src/verax/detect/journey-stall-detector.js +558 -0
- package/src/verax/detect/navigation-silent-failure.js +82 -0
- package/src/verax/detect/problem-aggregator.js +361 -0
- package/src/verax/detect/route-findings.js +219 -0
- package/src/verax/detect/summary-writer.js +477 -0
- package/src/verax/detect/test-failure-cause-inference.js +314 -0
- package/src/verax/detect/ui-feedback-findings.js +207 -0
- package/src/verax/detect/view-switch-correlator.js +242 -0
- package/src/verax/flow/flow-engine.js +2 -1
- package/src/verax/flow/flow-spec.js +0 -6
- package/src/verax/index.js +4 -0
- package/src/verax/intel/ts-program.js +1 -0
- package/src/verax/intel/vue-navigation-extractor.js +3 -0
- package/src/verax/learn/action-contract-extractor.js +3 -0
- package/src/verax/learn/ast-contract-extractor.js +1 -1
- package/src/verax/learn/flow-extractor.js +1 -0
- package/src/verax/learn/project-detector.js +5 -0
- package/src/verax/learn/react-router-extractor.js +2 -0
- package/src/verax/learn/source-instrumenter.js +1 -0
- package/src/verax/learn/state-extractor.js +2 -1
- package/src/verax/learn/static-extractor.js +1 -0
- package/src/verax/observe/coverage-gaps.js +132 -0
- package/src/verax/observe/expectation-handler.js +126 -0
- package/src/verax/observe/incremental-skip.js +46 -0
- package/src/verax/observe/index.js +51 -155
- package/src/verax/observe/interaction-executor.js +192 -0
- package/src/verax/observe/interaction-runner.js +782 -513
- package/src/verax/observe/network-firewall.js +86 -0
- package/src/verax/observe/observation-builder.js +169 -0
- package/src/verax/observe/observe-context.js +205 -0
- package/src/verax/observe/observe-helpers.js +192 -0
- package/src/verax/observe/observe-runner.js +230 -0
- package/src/verax/observe/observers/budget-observer.js +185 -0
- package/src/verax/observe/observers/console-observer.js +102 -0
- package/src/verax/observe/observers/coverage-observer.js +107 -0
- package/src/verax/observe/observers/interaction-observer.js +471 -0
- package/src/verax/observe/observers/navigation-observer.js +132 -0
- package/src/verax/observe/observers/network-observer.js +87 -0
- package/src/verax/observe/observers/safety-observer.js +82 -0
- package/src/verax/observe/observers/ui-feedback-observer.js +99 -0
- package/src/verax/observe/page-traversal.js +138 -0
- package/src/verax/observe/snapshot-ops.js +94 -0
- package/src/verax/observe/ui-feedback-detector.js +742 -0
- package/src/verax/scan-summary-writer.js +2 -0
- package/src/verax/shared/artifact-manager.js +25 -5
- package/src/verax/shared/caching.js +1 -0
- package/src/verax/shared/css-spinner-rules.js +204 -0
- package/src/verax/shared/expectation-tracker.js +1 -0
- package/src/verax/shared/view-switch-rules.js +208 -0
- package/src/verax/shared/zip-artifacts.js +6 -0
- package/src/verax/shared/config-loader.js +0 -169
- /package/src/verax/shared/{expectation-proof.js → expectation-validation.js} +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PHASE 20 — Angular Network Detector
|
|
3
|
+
*
|
|
4
|
+
* Detects network calls (HttpClient, fetch) in Angular component methods and services.
|
|
5
|
+
* Reuses AST network detector but ensures it works with Angular TypeScript files.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { extractAngularComponent, extractTemplateBindings, mapTemplateHandlersToClass } from './angular-component-extractor.js';
|
|
9
|
+
import { detectNetworkCallsAST } from './ast-network-detector.js';
|
|
10
|
+
import { relative } from 'path';
|
|
11
|
+
import { readFileSync, existsSync } from 'fs';
|
|
12
|
+
import { parse } from '@babel/parser';
|
|
13
|
+
import traverse from '@babel/traverse';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Detect network promises in Angular component
|
|
17
|
+
*
|
|
18
|
+
* @param {string} filePath - Path to .ts file
|
|
19
|
+
* @param {string} content - Full file content
|
|
20
|
+
* @param {string} projectRoot - Project root directory
|
|
21
|
+
* @returns {Array} Array of network expectations
|
|
22
|
+
*/
|
|
23
|
+
export function detectAngularNetwork(filePath, content, projectRoot) {
|
|
24
|
+
const expectations = [];
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const component = extractAngularComponent(content, filePath, projectRoot);
|
|
28
|
+
|
|
29
|
+
// Extract event handlers from template to identify UI-bound handlers
|
|
30
|
+
let templateBindings = null;
|
|
31
|
+
if (component.template) {
|
|
32
|
+
let templateContent = null;
|
|
33
|
+
|
|
34
|
+
if (component.template.isInline) {
|
|
35
|
+
templateContent = component.template.content;
|
|
36
|
+
} else if (existsSync(component.template.path)) {
|
|
37
|
+
templateContent = readFileSync(component.template.path, 'utf8');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (templateContent) {
|
|
41
|
+
templateBindings = extractTemplateBindings(templateContent);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const mappedHandlers = component.componentClass && templateBindings
|
|
46
|
+
? mapTemplateHandlersToClass(templateBindings.eventHandlers, component.componentClass.content)
|
|
47
|
+
: [];
|
|
48
|
+
|
|
49
|
+
const uiBoundHandlers = new Set(mappedHandlers.map(h => h.methodName));
|
|
50
|
+
|
|
51
|
+
// Process component class
|
|
52
|
+
if (component.componentClass && component.componentClass.content) {
|
|
53
|
+
// Use AST network detector on class content
|
|
54
|
+
const networkCalls = detectNetworkCallsAST(component.componentClass.content, filePath, relative(projectRoot, filePath));
|
|
55
|
+
|
|
56
|
+
// Also detect HttpClient calls specifically
|
|
57
|
+
const httpClientCalls = detectHttpClientCalls(component.componentClass.content, component.componentClass.startLine);
|
|
58
|
+
|
|
59
|
+
// Combine and filter network calls
|
|
60
|
+
const allNetworkCalls = [...networkCalls, ...httpClientCalls];
|
|
61
|
+
|
|
62
|
+
for (const networkCall of allNetworkCalls) {
|
|
63
|
+
// Check if this is in a UI-bound handler
|
|
64
|
+
const isUIBound = networkCall.context && uiBoundHandlers.has(networkCall.context);
|
|
65
|
+
|
|
66
|
+
// Skip analytics-only calls (filtered by guardrails later)
|
|
67
|
+
if (networkCall.target && (
|
|
68
|
+
networkCall.target.includes('/api/analytics') ||
|
|
69
|
+
networkCall.target.includes('/api/track') ||
|
|
70
|
+
networkCall.target.includes('/api/beacon')
|
|
71
|
+
)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
expectations.push({
|
|
76
|
+
type: 'network',
|
|
77
|
+
target: networkCall.target || networkCall.url,
|
|
78
|
+
method: networkCall.method || 'GET',
|
|
79
|
+
context: networkCall.context || 'component',
|
|
80
|
+
sourceRef: {
|
|
81
|
+
file: filePath,
|
|
82
|
+
line: networkCall.line || component.componentClass.startLine,
|
|
83
|
+
snippet: networkCall.snippet || '',
|
|
84
|
+
},
|
|
85
|
+
proof: networkCall.proof || 'LIKELY_EXPECTATION',
|
|
86
|
+
metadata: {
|
|
87
|
+
isUIBound,
|
|
88
|
+
handlerContext: networkCall.context,
|
|
89
|
+
networkKind: networkCall.kind || 'http',
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
// Skip if extraction fails
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return expectations;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Detect HttpClient calls (get, post, put, delete, etc.)
|
|
103
|
+
*
|
|
104
|
+
* @param {string} classContent - Component class content
|
|
105
|
+
* @param {number} startLine - Starting line number
|
|
106
|
+
* @returns {Array} Array of network call detections
|
|
107
|
+
*/
|
|
108
|
+
function detectHttpClientCalls(classContent, startLine) {
|
|
109
|
+
const calls = [];
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
const ast = parse(classContent, {
|
|
113
|
+
sourceType: 'module',
|
|
114
|
+
plugins: ['typescript', 'decorators-legacy', 'classProperties'],
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
traverse.default(ast, {
|
|
118
|
+
CallExpression(path) {
|
|
119
|
+
const { node } = path;
|
|
120
|
+
|
|
121
|
+
// Detect http.get(), http.post(), etc.
|
|
122
|
+
if (
|
|
123
|
+
node.callee.type === 'MemberExpression' &&
|
|
124
|
+
['get', 'post', 'put', 'delete', 'patch'].includes(node.callee.property.name)
|
|
125
|
+
) {
|
|
126
|
+
const method = node.callee.property.name.toUpperCase();
|
|
127
|
+
const firstArg = node.arguments[0];
|
|
128
|
+
let url = null;
|
|
129
|
+
|
|
130
|
+
if (firstArg && firstArg.type === 'StringLiteral') {
|
|
131
|
+
url = firstArg.value;
|
|
132
|
+
} else if (firstArg && firstArg.type === 'TemplateLiteral' && firstArg.quasis.length === 1) {
|
|
133
|
+
url = firstArg.quasis[0].value.raw;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (url) {
|
|
137
|
+
const location = node.loc;
|
|
138
|
+
const line = startLine + (location ? location.start.line - 1 : 0);
|
|
139
|
+
|
|
140
|
+
calls.push({
|
|
141
|
+
target: url,
|
|
142
|
+
method,
|
|
143
|
+
line,
|
|
144
|
+
snippet: classContent.substring(
|
|
145
|
+
node.start - (ast.program.body[0]?.start || 0),
|
|
146
|
+
node.end - (ast.program.body[0]?.start || 0)
|
|
147
|
+
),
|
|
148
|
+
kind: 'httpClient',
|
|
149
|
+
proof: firstArg.type === 'StringLiteral' ? 'PROVEN_EXPECTATION' : 'LIKELY_EXPECTATION',
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
} catch (parseError) {
|
|
156
|
+
// Skip if parsing fails
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return calls;
|
|
160
|
+
}
|
|
161
|
+
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PHASE 20 — Angular State Detector
|
|
3
|
+
*
|
|
4
|
+
* Detects state mutations (component properties, services) in Angular components.
|
|
5
|
+
* Only emits state promises if state is user-visible (used in template bindings).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { extractAngularComponent, extractTemplateBindings } from './angular-component-extractor.js';
|
|
9
|
+
import { parse } from '@babel/parser';
|
|
10
|
+
import traverse from '@babel/traverse';
|
|
11
|
+
import { readFileSync, existsSync } from 'fs';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Detect state promises in Angular component
|
|
15
|
+
*
|
|
16
|
+
* @param {string} filePath - Path to .ts file
|
|
17
|
+
* @param {string} content - Full file content
|
|
18
|
+
* @param {string} projectRoot - Project root directory
|
|
19
|
+
* @returns {Array} Array of state expectations
|
|
20
|
+
*/
|
|
21
|
+
export function detectAngularState(filePath, content, projectRoot) {
|
|
22
|
+
const expectations = [];
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const component = extractAngularComponent(content, filePath, projectRoot);
|
|
26
|
+
|
|
27
|
+
// Extract template bindings to identify user-visible state
|
|
28
|
+
let templateBindings = null;
|
|
29
|
+
let templateContent = null;
|
|
30
|
+
|
|
31
|
+
if (component.template) {
|
|
32
|
+
if (component.template.isInline) {
|
|
33
|
+
templateContent = component.template.content;
|
|
34
|
+
} else if (existsSync(component.template.path)) {
|
|
35
|
+
templateContent = readFileSync(component.template.path, 'utf8');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (templateContent) {
|
|
39
|
+
templateBindings = extractTemplateBindings(templateContent);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Collect all state variables used in template
|
|
44
|
+
const templateStateVars = new Set();
|
|
45
|
+
|
|
46
|
+
// From property bindings: [property]="value"
|
|
47
|
+
if (templateBindings) {
|
|
48
|
+
templateBindings.propertyBindings.forEach(binding => {
|
|
49
|
+
templateStateVars.add(binding.value);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// From structural directives: *ngIf="condition"
|
|
53
|
+
templateBindings.structuralDirectives.forEach(directive => {
|
|
54
|
+
// Extract variable names from expressions
|
|
55
|
+
const varMatch = directive.expression.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
56
|
+
if (varMatch) {
|
|
57
|
+
templateStateVars.add(varMatch[1]);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// From template interpolation: {{ variable }}
|
|
63
|
+
if (templateContent) {
|
|
64
|
+
const interpolationRegex = /\{\{\s*([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\}\}/g;
|
|
65
|
+
let varMatch;
|
|
66
|
+
while ((varMatch = interpolationRegex.exec(templateContent)) !== null) {
|
|
67
|
+
templateStateVars.add(varMatch[1]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Process component class to find state mutations
|
|
72
|
+
if (component.componentClass && component.componentClass.content) {
|
|
73
|
+
try {
|
|
74
|
+
const ast = parse(component.componentClass.content, {
|
|
75
|
+
sourceType: 'module',
|
|
76
|
+
plugins: ['typescript', 'decorators-legacy', 'classProperties'],
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
traverse.default(ast, {
|
|
80
|
+
// Detect property assignments: this.property = value
|
|
81
|
+
AssignmentExpression(path) {
|
|
82
|
+
const { node } = path;
|
|
83
|
+
|
|
84
|
+
if (
|
|
85
|
+
node.left.type === 'MemberExpression' &&
|
|
86
|
+
node.left.object.type === 'ThisExpression' &&
|
|
87
|
+
node.left.property.type === 'Identifier'
|
|
88
|
+
) {
|
|
89
|
+
const propertyName = node.left.property.name;
|
|
90
|
+
|
|
91
|
+
// Only emit if property is used in template
|
|
92
|
+
if (templateStateVars.has(propertyName)) {
|
|
93
|
+
const location = node.loc;
|
|
94
|
+
const line = component.componentClass.startLine + (location ? location.start.line - 1 : 0);
|
|
95
|
+
|
|
96
|
+
expectations.push({
|
|
97
|
+
type: 'state',
|
|
98
|
+
expectedTarget: propertyName,
|
|
99
|
+
context: 'property-assignment',
|
|
100
|
+
sourceRef: {
|
|
101
|
+
file: filePath,
|
|
102
|
+
line,
|
|
103
|
+
snippet: component.componentClass.content.substring(
|
|
104
|
+
node.start - (ast.program.body[0]?.start || 0),
|
|
105
|
+
node.end - (ast.program.body[0]?.start || 0)
|
|
106
|
+
),
|
|
107
|
+
},
|
|
108
|
+
proof: 'PROVEN_EXPECTATION',
|
|
109
|
+
metadata: {
|
|
110
|
+
templateUsage: Array.from(templateStateVars).filter(v => v === propertyName).length,
|
|
111
|
+
stateType: 'component-property',
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
// Detect property declarations: property: type = value
|
|
119
|
+
ClassProperty(path) {
|
|
120
|
+
const { node } = path;
|
|
121
|
+
|
|
122
|
+
if (node.key.type === 'Identifier') {
|
|
123
|
+
const propertyName = node.key.name;
|
|
124
|
+
|
|
125
|
+
// Only emit if property is used in template and has initializer
|
|
126
|
+
if (templateStateVars.has(propertyName) && node.value) {
|
|
127
|
+
const location = node.loc;
|
|
128
|
+
const line = component.componentClass.startLine + (location ? location.start.line - 1 : 0);
|
|
129
|
+
|
|
130
|
+
expectations.push({
|
|
131
|
+
type: 'state',
|
|
132
|
+
expectedTarget: propertyName,
|
|
133
|
+
context: 'property-declaration',
|
|
134
|
+
sourceRef: {
|
|
135
|
+
file: filePath,
|
|
136
|
+
line,
|
|
137
|
+
snippet: component.componentClass.content.substring(
|
|
138
|
+
node.start - (ast.program.body[0]?.start || 0),
|
|
139
|
+
node.end - (ast.program.body[0]?.start || 0)
|
|
140
|
+
),
|
|
141
|
+
},
|
|
142
|
+
proof: 'PROVEN_EXPECTATION',
|
|
143
|
+
metadata: {
|
|
144
|
+
templateUsage: Array.from(templateStateVars).filter(v => v === propertyName).length,
|
|
145
|
+
stateType: 'component-property',
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
} catch (parseError) {
|
|
153
|
+
// Skip if parsing fails
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} catch (error) {
|
|
157
|
+
// Skip if extraction fails
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return expectations;
|
|
161
|
+
}
|
|
162
|
+
|