@snaplens/testagent-core 0.0.0-stage → 0.2.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 CHANGED
@@ -1,3 +1,14 @@
1
- # Temporary Holding Version
1
+ # @snaplens/testagent-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **AST mutation parser, snapshot diff engine, and causal regression arbitrator for TestAgent.**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@snaplens/testagent-core.svg)](https://www.npmjs.com/package/@snaplens/testagent-core)
6
+ [![license](https://img.shields.io/npm/l/@snaplens/testagent-core.svg)](https://github.com/snaplens/testagent/blob/main/LICENSE)
7
+
8
+ `@snaplens/testagent-core` is the foundational engine behind TestAgent. It extracts JSX/TSX mutations from Git diffs using `ts-morph`, executes deterministic AST causal proofs, compares baseline vs. live ARIA snapshots for remote QA sites, interfaces with local/cloud LLMs (Ollama, Claude, GPT, Gemini), and patches test AST files.
9
+
10
+ ---
11
+
12
+ ## 📄 License
13
+
14
+ MIT © [Snaplens](https://github.com/snaplens)
@@ -0,0 +1,103 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const FailurePayloadSchema: z.ZodObject<{
4
+ testTitle: z.ZodString;
5
+ file: z.ZodString;
6
+ line: z.ZodNumber;
7
+ errorMessage: z.ZodString;
8
+ ariaSnapshot: z.ZodString;
9
+ baselineSnapshot: z.ZodOptional<z.ZodString>;
10
+ brokenSelector: z.ZodOptional<z.ZodString>;
11
+ targetUrl: z.ZodOptional<z.ZodString>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ testTitle: string;
14
+ file: string;
15
+ line: number;
16
+ errorMessage: string;
17
+ ariaSnapshot: string;
18
+ baselineSnapshot?: string | undefined;
19
+ brokenSelector?: string | undefined;
20
+ targetUrl?: string | undefined;
21
+ }, {
22
+ testTitle: string;
23
+ file: string;
24
+ line: number;
25
+ errorMessage: string;
26
+ ariaSnapshot: string;
27
+ baselineSnapshot?: string | undefined;
28
+ brokenSelector?: string | undefined;
29
+ targetUrl?: string | undefined;
30
+ }>;
31
+ type FailurePayload = z.infer<typeof FailurePayloadSchema>;
32
+ declare const CausalVerdictSchema: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
33
+ status: z.ZodLiteral<"healed">;
34
+ method: z.ZodOptional<z.ZodEnum<["deterministic-ast", "snapshot-diff", "llm-causal"]>>;
35
+ newCallExpression: z.ZodString;
36
+ evidence: z.ZodDefault<z.ZodString>;
37
+ confidence: z.ZodNumber;
38
+ }, "strip", z.ZodTypeAny, {
39
+ status: "healed";
40
+ newCallExpression: string;
41
+ evidence: string;
42
+ confidence: number;
43
+ method?: "deterministic-ast" | "snapshot-diff" | "llm-causal" | undefined;
44
+ }, {
45
+ status: "healed";
46
+ newCallExpression: string;
47
+ confidence: number;
48
+ method?: "deterministic-ast" | "snapshot-diff" | "llm-causal" | undefined;
49
+ evidence?: string | undefined;
50
+ }>, z.ZodObject<{
51
+ status: z.ZodLiteral<"bug">;
52
+ reason: z.ZodDefault<z.ZodString>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ status: "bug";
55
+ reason: string;
56
+ }, {
57
+ status: "bug";
58
+ reason?: string | undefined;
59
+ }>]>;
60
+ type CausalVerdict = z.infer<typeof CausalVerdictSchema>;
61
+ interface LLMProviderConfig {
62
+ provider: 'ollama' | 'anthropic' | 'openai' | 'gemini';
63
+ apiKey?: string;
64
+ model?: string;
65
+ baseUrl?: string;
66
+ }
67
+
68
+ interface JsxElementSnapshot {
69
+ tagName: string;
70
+ line: number;
71
+ attributes: Record<string, string>;
72
+ text: string;
73
+ }
74
+ interface ComponentMutation {
75
+ file: string;
76
+ line: number;
77
+ tagName: string;
78
+ removedAttrs: Record<string, string>;
79
+ addedAttrs: Record<string, string>;
80
+ oldText: string;
81
+ newText: string;
82
+ }
83
+ declare function getFrontendMutations(baseRef?: string, cwd?: string): {
84
+ mutations: ComponentMutation[];
85
+ rawDiff: string;
86
+ };
87
+
88
+ declare function verifyCausalityWithLLM(prompt: string, config: LLMProviderConfig): Promise<CausalVerdict>;
89
+
90
+ interface BrokenLocatorInfo {
91
+ type: 'xpath' | 'role' | 'label' | 'testid' | 'id' | 'text' | 'placeholder' | 'css' | 'unknown';
92
+ value: string;
93
+ role?: string;
94
+ raw?: string;
95
+ xpathTokens?: string[];
96
+ }
97
+ declare function extractIdentifiersFromXPath(xpath: string): string[];
98
+ declare function parseBrokenLocator(errorMessage: string): BrokenLocatorInfo;
99
+ declare function diffSnapshotsForElement(broken: BrokenLocatorInfo, baselineSnapshot?: string, liveSnapshot?: string): CausalVerdict | null;
100
+ declare function evaluateCausality(payload: FailurePayload, mutations: ComponentMutation[], rawDiff: string, llmConfig?: LLMProviderConfig): Promise<CausalVerdict>;
101
+ declare function applyLocatorPatch(testFilePath: string, failingLine: number, newCallExpression: string): boolean;
102
+
103
+ export { type BrokenLocatorInfo, type CausalVerdict, CausalVerdictSchema, type ComponentMutation, type FailurePayload, FailurePayloadSchema, type JsxElementSnapshot, type LLMProviderConfig, applyLocatorPatch, diffSnapshotsForElement, evaluateCausality, extractIdentifiersFromXPath, getFrontendMutations, parseBrokenLocator, verifyCausalityWithLLM };
@@ -0,0 +1,103 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const FailurePayloadSchema: z.ZodObject<{
4
+ testTitle: z.ZodString;
5
+ file: z.ZodString;
6
+ line: z.ZodNumber;
7
+ errorMessage: z.ZodString;
8
+ ariaSnapshot: z.ZodString;
9
+ baselineSnapshot: z.ZodOptional<z.ZodString>;
10
+ brokenSelector: z.ZodOptional<z.ZodString>;
11
+ targetUrl: z.ZodOptional<z.ZodString>;
12
+ }, "strip", z.ZodTypeAny, {
13
+ testTitle: string;
14
+ file: string;
15
+ line: number;
16
+ errorMessage: string;
17
+ ariaSnapshot: string;
18
+ baselineSnapshot?: string | undefined;
19
+ brokenSelector?: string | undefined;
20
+ targetUrl?: string | undefined;
21
+ }, {
22
+ testTitle: string;
23
+ file: string;
24
+ line: number;
25
+ errorMessage: string;
26
+ ariaSnapshot: string;
27
+ baselineSnapshot?: string | undefined;
28
+ brokenSelector?: string | undefined;
29
+ targetUrl?: string | undefined;
30
+ }>;
31
+ type FailurePayload = z.infer<typeof FailurePayloadSchema>;
32
+ declare const CausalVerdictSchema: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
33
+ status: z.ZodLiteral<"healed">;
34
+ method: z.ZodOptional<z.ZodEnum<["deterministic-ast", "snapshot-diff", "llm-causal"]>>;
35
+ newCallExpression: z.ZodString;
36
+ evidence: z.ZodDefault<z.ZodString>;
37
+ confidence: z.ZodNumber;
38
+ }, "strip", z.ZodTypeAny, {
39
+ status: "healed";
40
+ newCallExpression: string;
41
+ evidence: string;
42
+ confidence: number;
43
+ method?: "deterministic-ast" | "snapshot-diff" | "llm-causal" | undefined;
44
+ }, {
45
+ status: "healed";
46
+ newCallExpression: string;
47
+ confidence: number;
48
+ method?: "deterministic-ast" | "snapshot-diff" | "llm-causal" | undefined;
49
+ evidence?: string | undefined;
50
+ }>, z.ZodObject<{
51
+ status: z.ZodLiteral<"bug">;
52
+ reason: z.ZodDefault<z.ZodString>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ status: "bug";
55
+ reason: string;
56
+ }, {
57
+ status: "bug";
58
+ reason?: string | undefined;
59
+ }>]>;
60
+ type CausalVerdict = z.infer<typeof CausalVerdictSchema>;
61
+ interface LLMProviderConfig {
62
+ provider: 'ollama' | 'anthropic' | 'openai' | 'gemini';
63
+ apiKey?: string;
64
+ model?: string;
65
+ baseUrl?: string;
66
+ }
67
+
68
+ interface JsxElementSnapshot {
69
+ tagName: string;
70
+ line: number;
71
+ attributes: Record<string, string>;
72
+ text: string;
73
+ }
74
+ interface ComponentMutation {
75
+ file: string;
76
+ line: number;
77
+ tagName: string;
78
+ removedAttrs: Record<string, string>;
79
+ addedAttrs: Record<string, string>;
80
+ oldText: string;
81
+ newText: string;
82
+ }
83
+ declare function getFrontendMutations(baseRef?: string, cwd?: string): {
84
+ mutations: ComponentMutation[];
85
+ rawDiff: string;
86
+ };
87
+
88
+ declare function verifyCausalityWithLLM(prompt: string, config: LLMProviderConfig): Promise<CausalVerdict>;
89
+
90
+ interface BrokenLocatorInfo {
91
+ type: 'xpath' | 'role' | 'label' | 'testid' | 'id' | 'text' | 'placeholder' | 'css' | 'unknown';
92
+ value: string;
93
+ role?: string;
94
+ raw?: string;
95
+ xpathTokens?: string[];
96
+ }
97
+ declare function extractIdentifiersFromXPath(xpath: string): string[];
98
+ declare function parseBrokenLocator(errorMessage: string): BrokenLocatorInfo;
99
+ declare function diffSnapshotsForElement(broken: BrokenLocatorInfo, baselineSnapshot?: string, liveSnapshot?: string): CausalVerdict | null;
100
+ declare function evaluateCausality(payload: FailurePayload, mutations: ComponentMutation[], rawDiff: string, llmConfig?: LLMProviderConfig): Promise<CausalVerdict>;
101
+ declare function applyLocatorPatch(testFilePath: string, failingLine: number, newCallExpression: string): boolean;
102
+
103
+ export { type BrokenLocatorInfo, type CausalVerdict, CausalVerdictSchema, type ComponentMutation, type FailurePayload, FailurePayloadSchema, type JsxElementSnapshot, type LLMProviderConfig, applyLocatorPatch, diffSnapshotsForElement, evaluateCausality, extractIdentifiersFromXPath, getFrontendMutations, parseBrokenLocator, verifyCausalityWithLLM };