@monkeytestai/monkeytester 0.0.0-stage → 0.5.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +179 -0
  2. package/LICENSE +661 -0
  3. package/NOTICE +12 -0
  4. package/README.md +196 -2
  5. package/dist/cli.d.ts +43 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +774 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/diff/index.d.ts +78 -0
  10. package/dist/diff/index.d.ts.map +1 -0
  11. package/dist/diff/index.js +119 -0
  12. package/dist/diff/index.js.map +1 -0
  13. package/dist/events.d.ts +66 -0
  14. package/dist/events.d.ts.map +1 -0
  15. package/dist/events.js +77 -0
  16. package/dist/events.js.map +1 -0
  17. package/dist/explorer/index.d.ts +131 -0
  18. package/dist/explorer/index.d.ts.map +1 -0
  19. package/dist/explorer/index.js +675 -0
  20. package/dist/explorer/index.js.map +1 -0
  21. package/dist/explorer/queue.d.ts +94 -0
  22. package/dist/explorer/queue.d.ts.map +1 -0
  23. package/dist/explorer/queue.js +277 -0
  24. package/dist/explorer/queue.js.map +1 -0
  25. package/dist/index.d.ts +36 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +22 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/llm/coerce.d.ts +59 -0
  30. package/dist/llm/coerce.d.ts.map +1 -0
  31. package/dist/llm/coerce.js +246 -0
  32. package/dist/llm/coerce.js.map +1 -0
  33. package/dist/llm/index.d.ts +79 -0
  34. package/dist/llm/index.d.ts.map +1 -0
  35. package/dist/llm/index.js +392 -0
  36. package/dist/llm/index.js.map +1 -0
  37. package/dist/llm/presets.d.ts +61 -0
  38. package/dist/llm/presets.d.ts.map +1 -0
  39. package/dist/llm/presets.js +101 -0
  40. package/dist/llm/presets.js.map +1 -0
  41. package/dist/monkey.d.ts +151 -0
  42. package/dist/monkey.d.ts.map +1 -0
  43. package/dist/monkey.js +323 -0
  44. package/dist/monkey.js.map +1 -0
  45. package/dist/persistence/index.d.ts +118 -0
  46. package/dist/persistence/index.d.ts.map +1 -0
  47. package/dist/persistence/index.js +196 -0
  48. package/dist/persistence/index.js.map +1 -0
  49. package/dist/planner/faults.d.ts +24 -0
  50. package/dist/planner/faults.d.ts.map +1 -0
  51. package/dist/planner/faults.js +128 -0
  52. package/dist/planner/faults.js.map +1 -0
  53. package/dist/planner/forms.d.ts +33 -0
  54. package/dist/planner/forms.d.ts.map +1 -0
  55. package/dist/planner/forms.js +163 -0
  56. package/dist/planner/forms.js.map +1 -0
  57. package/dist/planner/index.d.ts +31 -0
  58. package/dist/planner/index.d.ts.map +1 -0
  59. package/dist/planner/index.js +252 -0
  60. package/dist/planner/index.js.map +1 -0
  61. package/dist/planner/salvage.d.ts +16 -0
  62. package/dist/planner/salvage.d.ts.map +1 -0
  63. package/dist/planner/salvage.js +107 -0
  64. package/dist/planner/salvage.js.map +1 -0
  65. package/dist/runner/actions.d.ts +91 -0
  66. package/dist/runner/actions.d.ts.map +1 -0
  67. package/dist/runner/actions.js +659 -0
  68. package/dist/runner/actions.js.map +1 -0
  69. package/dist/runner/evidence.d.ts +37 -0
  70. package/dist/runner/evidence.d.ts.map +1 -0
  71. package/dist/runner/evidence.js +122 -0
  72. package/dist/runner/evidence.js.map +1 -0
  73. package/dist/runner/http5xx.d.ts +40 -0
  74. package/dist/runner/http5xx.d.ts.map +1 -0
  75. package/dist/runner/http5xx.js +189 -0
  76. package/dist/runner/http5xx.js.map +1 -0
  77. package/dist/runner/index.d.ts +88 -0
  78. package/dist/runner/index.d.ts.map +1 -0
  79. package/dist/runner/index.js +600 -0
  80. package/dist/runner/index.js.map +1 -0
  81. package/dist/runner/replay.d.ts +42 -0
  82. package/dist/runner/replay.d.ts.map +1 -0
  83. package/dist/runner/replay.js +458 -0
  84. package/dist/runner/replay.js.map +1 -0
  85. package/dist/runner/timeout.d.ts +16 -0
  86. package/dist/runner/timeout.d.ts.map +1 -0
  87. package/dist/runner/timeout.js +38 -0
  88. package/dist/runner/timeout.js.map +1 -0
  89. package/dist/trace/fingerprint.d.ts +78 -0
  90. package/dist/trace/fingerprint.d.ts.map +1 -0
  91. package/dist/trace/fingerprint.js +273 -0
  92. package/dist/trace/fingerprint.js.map +1 -0
  93. package/dist/trace/serialize.d.ts +15 -0
  94. package/dist/trace/serialize.d.ts.map +1 -0
  95. package/dist/trace/serialize.js +86 -0
  96. package/dist/trace/serialize.js.map +1 -0
  97. package/dist/triager/index.d.ts +86 -0
  98. package/dist/triager/index.d.ts.map +1 -0
  99. package/dist/triager/index.js +322 -0
  100. package/dist/triager/index.js.map +1 -0
  101. package/dist/types.d.ts +497 -0
  102. package/dist/types.d.ts.map +1 -0
  103. package/dist/types.js +10 -0
  104. package/dist/types.js.map +1 -0
  105. package/dist/verify/index.d.ts +52 -0
  106. package/dist/verify/index.d.ts.map +1 -0
  107. package/dist/verify/index.js +140 -0
  108. package/dist/verify/index.js.map +1 -0
  109. package/dist/verify/verdict.d.ts +34 -0
  110. package/dist/verify/verdict.d.ts.map +1 -0
  111. package/dist/verify/verdict.js +89 -0
  112. package/dist/verify/verdict.js.map +1 -0
  113. package/package.json +90 -4
@@ -0,0 +1,252 @@
1
+ /**
2
+ * Planner phase
3
+ *
4
+ * Converts a SiteMap into a TestPlan: a list of TestFlows that a real user
5
+ * would care about. The planner is told which pages the explorer found, what
6
+ * each one does, what's interactive on it — and asked to pick the most
7
+ * impactful flows to verify.
8
+ *
9
+ * It does NOT generate exhaustive test cases. The runner (next phase) is
10
+ * adversarial and will discover edge cases by behaviour. The planner only
11
+ * needs to give it well-shaped happy paths to anchor the exploration.
12
+ */
13
+ import { z } from 'zod';
14
+ import { noopBus } from '../events.js';
15
+ import { ensurePublicFormFlow } from './forms.js';
16
+ import { ensureFaultSurfaceFlows } from './faults.js';
17
+ import { salvageModelFlows } from './salvage.js';
18
+ /**
19
+ * Accept a partial model payload. One empty `steps` array must not reject
20
+ * the sibling flows. Broken JSON still throws from `generateJSON`; `plan`
21
+ * catches that and continues with the grounded flows.
22
+ */
23
+ const LoosePlanSchema = z.object({
24
+ flows: z.unknown().optional(),
25
+ notes: z.unknown().optional(),
26
+ }).passthrough();
27
+ export async function plan(siteMap, llm, opts = {}) {
28
+ const maxFlows = opts.maxFlows ?? 6;
29
+ const includeAuth = opts.includeAuthFlows ?? true;
30
+ const events = opts.events ?? noopBus();
31
+ if (siteMap.pages.length === 0) {
32
+ events.emit({
33
+ phase: 'planner', type: 'plan.skipped',
34
+ message: 'Planner skipped: no pages were successfully explored.',
35
+ });
36
+ return {
37
+ startUrl: siteMap.startUrl,
38
+ siteType: siteMap.siteType,
39
+ flows: [],
40
+ notes: 'Planner skipped: no pages were successfully explored.',
41
+ };
42
+ }
43
+ events.emit({
44
+ phase: 'planner', type: 'plan.start',
45
+ message: `Generating test plan from ${siteMap.pages.length} page${siteMap.pages.length === 1 ? '' : 's'}…`,
46
+ data: { pages: siteMap.pages.length, siteType: siteMap.siteType },
47
+ });
48
+ // Prompt is intentionally split into THREE parts to maximise prompt-cache
49
+ // hits across runs against the same site:
50
+ //
51
+ // 1. `system` — never changes. Identical across every planner call
52
+ // in the engine's lifetime. Anthropic caches it via
53
+ // a system-block ephemeral breakpoint; OpenAI caches
54
+ // it as part of the message-prefix hash.
55
+ // 2. `cacheable` — the long stable site-map dump. Identical across all
56
+ // calls against the same site. This is by far the
57
+ // largest token block in the prompt — caching it has
58
+ // the most impact.
59
+ // 3. `prompt` — the small per-call instructions (maxFlows, auth
60
+ // toggle, schema reminder). Tiny, cheap to re-send.
61
+ //
62
+ // Order matters: providers cache by *prefix*, so the dynamic bit goes LAST.
63
+ const system = `You are a senior QA architect. You have just been handed a structured crawl of a real website. Your job is to design a small set of high-quality user journeys — the kind a staff engineer would put on a release checklist — not a pile of brittle UI assertions.
64
+
65
+ How to think:
66
+ 1. First understand the product: who is the visitor, what jobs can they complete without an account, what is marketing vs. application vs. legal.
67
+ 2. Then pick DISTINCT journeys that protect the most user value (apply, shop, compare, contact, read a key page, complete a public form).
68
+ 3. Each flow must be a realistic anonymous-visitor path using ONLY controls the crawl actually saw.
69
+
70
+ Hard rules:
71
+ - Do NOT invent search boxes, menus, buttons, forms, or pages the crawl did not show.
72
+ - Do NOT assert exact document titles. Titles vary and are not user-critical.
73
+ - Prefer visible labels from the crawl ("Apply now", "Check eligibility") over CSS selectors.
74
+ - Steps must be executable by a Playwright agent with no human, OTP, email, or password.
75
+ - One goal per flow. Do not duplicate the same journey with different wording.
76
+ - Prefer 4–7 concrete steps. Skip "look at the page" filler.
77
+ - severityIfFails = critical only if a real user cannot complete a core job (apply, pay, submit, checkout). Visual polish is minor.
78
+
79
+ Each flow has the shape:
80
+ {
81
+ "id": kebab-case unique within the plan, e.g. "homepage-cta",
82
+ "name": short human title (max 80 chars),
83
+ "description": one sentence of what this flow tests and why it matters,
84
+ "kind": "happy_path" | "edge_case" | "auth_required" | "destructive" | "accessibility" | "visual",
85
+ "startUrl": absolute URL — usually one of the visited pages,
86
+ "steps": array of { "action": "...", "expectation"?: "..." }, 1–8 items,
87
+ "expectation": one-sentence success criterion for the whole flow,
88
+ "severityIfFails": "critical" | "major" | "minor"
89
+ }`;
90
+ const journeys = (siteMap.publicJourneys || []).filter(Boolean);
91
+ const authSurfaces = (siteMap.authSurfaces || []).filter(Boolean);
92
+ const cacheable = `Site: ${siteMap.startUrl}
93
+ Product: ${siteMap.productName || '(not named)'}
94
+ Site type: ${siteMap.siteType}
95
+ Description: ${siteMap.summary}
96
+ Public journeys a visitor can complete:
97
+ ${journeys.length ? journeys.map(j => ` - ${j}`).join('\n') : ' (none inferred — infer carefully from pages below)'}
98
+ Login / account surfaces noticed (do not enter unless instructed):
99
+ ${authSurfaces.length ? authSurfaces.map(s => ` - ${s}`).join('\n') : ' (none)'}
100
+
101
+ Pages explored:
102
+ ${siteMap.pages.map(p => `
103
+ - URL: ${p.url}
104
+ title: ${p.title}
105
+ summary: ${p.summary}
106
+ auth-gated: ${p.authGated}
107
+ interactive:
108
+ ${p.interactive.length === 0 ? '(none)' : p.interactive.map(i => `${i.kind} "${i.label}"`).join(', ')}
109
+ forms:
110
+ ${p.forms?.length
111
+ ? p.forms.map(f => `${(f.method || 'get').toUpperCase()} ${f.action || '(no action)'} fields=[${f.fields.join(', ') || 'none'}] submit="${f.submitLabel || ''}"`).join(' | ')
112
+ : '(none)'}
113
+ controls:
114
+ ${p.controls?.length
115
+ ? p.controls.slice(0, 12).map(c => `${c.kind}${c.disabled ? ' disabled' : ''} "${c.label}"${c.href ? ` -> ${c.href}` : ''}`).join(', ')
116
+ : '(none)'}
117
+ `).join('')}`;
118
+ const prompt = `Now produce the test plan.
119
+
120
+ Per-call constraints:
121
+ - Produce AT MOST ${maxFlows} flows total. Fill the quota with executable public journeys first.
122
+ - Every step must name a control or content that appears in the crawl above.
123
+ - ${includeAuth
124
+ ? 'You MAY add at most one kind="auth_required" flow that reaches a login/OTP wall and then stops. Do not invent credentials. The runner will skip executing it.'
125
+ : 'Do NOT include login, sign-in, sign-up, register, OTP, password-reset, or any flow that needs an account. Skip auth-gated pages. Fill the plan with public journeys only.'}
126
+ - If a crawled page lists a public form under "forms:", the engine reserves one flow that starts on that page and submits that form when the flow budget is at least 1, even if every other flow is a shopping journey. Prefer a POST contact, help, support, or feedback form over a search box. Use only the scraped fields and submit label. Do not invent a form URL or a field the crawl did not list. A flow that merely says "submit" on that page does not replace the reserved one.
127
+ - Scraped "controls:" are real buttons and links. The engine also keeps grounded flows for an enabled button, a link whose target was not crawled, and a disabled button when the budget allows. Do not invent a control that is not listed.
128
+
129
+ Reply with JSON:
130
+ {
131
+ "flows": [ ... ],
132
+ "notes": "(optional: what you understood about the site and what you deliberately skipped)"
133
+ }`;
134
+ let modelNotes;
135
+ let modelProblem;
136
+ let discardedModel = false;
137
+ let flows = [];
138
+ try {
139
+ const result = await llm.generateJSON({
140
+ label: 'planner.generate',
141
+ system,
142
+ cacheable,
143
+ prompt,
144
+ schema: LoosePlanSchema,
145
+ });
146
+ const salvaged = salvageModelFlows(result.flows);
147
+ flows = dedupeFlowIds(salvaged.flows);
148
+ modelNotes = typeof result.notes === 'string' ? result.notes : undefined;
149
+ const rawCount = Array.isArray(result.flows)
150
+ ? result.flows.length
151
+ : (result.flows && typeof result.flows === 'object' ? 1 : 0);
152
+ if (rawCount === 0 || salvaged.flows.length === 0) {
153
+ modelProblem = rawCount > 0
154
+ ? `Planner model returned ${rawCount} flow${rawCount === 1 ? '' : 's'} and none had a usable step.`
155
+ : 'Planner model returned no flow list.';
156
+ discardedModel = true;
157
+ }
158
+ else if (salvaged.dropped > 0) {
159
+ modelProblem = `Dropped ${salvaged.dropped} planner flow${salvaged.dropped === 1 ? '' : 's'} that had no usable steps.`;
160
+ }
161
+ }
162
+ catch (err) {
163
+ modelProblem = err instanceof Error ? err.message : String(err);
164
+ discardedModel = true;
165
+ flows = [];
166
+ }
167
+ if (!includeAuth) {
168
+ const publicOnly = flows.filter(f => !looksLikeLoginFlow(f));
169
+ if (publicOnly.length > 0)
170
+ flows = publicOnly;
171
+ }
172
+ const grounded = groundFlows(siteMap, flows, maxFlows);
173
+ flows = grounded.flows;
174
+ if (discardedModel && modelProblem) {
175
+ const kept = flows.length > 0
176
+ ? 'grounded flows were kept'
177
+ : 'the crawl had no public form or fault control to keep';
178
+ events.emit({
179
+ phase: 'planner', type: 'engine.error',
180
+ message: `Planner model response was unusable; ${kept}.`,
181
+ data: { error: modelProblem },
182
+ });
183
+ }
184
+ const notes = [
185
+ modelNotes,
186
+ modelProblem ? `Planner model response could not be used in full. ${truncate(modelProblem, 400)}` : '',
187
+ grounded.note,
188
+ ].filter(Boolean).join(' ') || undefined;
189
+ // Surface prompt-cache stats so the SaaS can display "saved $X" tooltips.
190
+ const usage = llm.lastUsage;
191
+ events.emit({
192
+ phase: 'planner', type: 'plan.complete',
193
+ message: `Plan ready: ${flows.length} flow${flows.length === 1 ? '' : 's'} to execute.`,
194
+ data: {
195
+ flows: flows.length,
196
+ flowNames: flows.map(f => f.name),
197
+ ...(usage ? { usage } : {}),
198
+ },
199
+ });
200
+ return {
201
+ startUrl: siteMap.startUrl,
202
+ siteType: siteMap.siteType,
203
+ flows,
204
+ notes,
205
+ };
206
+ }
207
+ /**
208
+ * Plan made only from the crawl: public form submit plus scraped fault
209
+ * controls, capped at `maxFlows`. Used when the planner model throws before
210
+ * `plan()` can finish, so `executeAndTriage` still has flows to run.
211
+ */
212
+ export function groundedTestPlan(siteMap, maxFlows, preface) {
213
+ const grounded = groundFlows(siteMap, [], maxFlows);
214
+ return {
215
+ startUrl: siteMap.startUrl,
216
+ siteType: siteMap.siteType,
217
+ flows: grounded.flows,
218
+ notes: [preface, grounded.note].filter(Boolean).join(' ') || undefined,
219
+ };
220
+ }
221
+ function groundFlows(siteMap, modelFlows, maxFlows) {
222
+ const capped = modelFlows.slice(0, Math.max(0, maxFlows));
223
+ const ensured = ensurePublicFormFlow(capped, siteMap, maxFlows);
224
+ const faults = ensureFaultSurfaceFlows(ensured.flows, siteMap, maxFlows);
225
+ const note = [
226
+ ensured.injected ? 'Added a form-submit flow for a public form found in the crawl.' : '',
227
+ faults.added.length
228
+ ? `Added fault-surface flows for controls the crawl saw (${faults.added.join(', ')}).`
229
+ : '',
230
+ ].filter(Boolean).join(' ') || undefined;
231
+ return { flows: faults.flows, note };
232
+ }
233
+ function dedupeFlowIds(flows) {
234
+ const seen = new Set();
235
+ return flows.map((flow, index) => {
236
+ let id = flow.id;
237
+ if (seen.has(id))
238
+ id = `${id}-${index + 1}`;
239
+ seen.add(id);
240
+ return id === flow.id ? flow : { ...flow, id };
241
+ });
242
+ }
243
+ function truncate(value, max) {
244
+ return value.length > max ? `${value.slice(0, max - 1)}…` : value;
245
+ }
246
+ function looksLikeLoginFlow(f) {
247
+ if (f.kind === 'auth_required')
248
+ return true;
249
+ const text = [f.name, f.description, ...f.steps.map(s => s.action)].join(' ').toLowerCase();
250
+ return /\b(log\s?in|sign\s?in|sign\s?up|register|create an account|otp|one[- ]time (code|password)|password reset|forgot password|verify (your )?(phone|email)|enter (your )?otp)\b/.test(text);
251
+ }
252
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/planner/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAiB,OAAO,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAWjD;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/B,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC7B,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC,WAAW,EAAE,CAAC;AAEjB,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,OAAgB,EAChB,GAAQ,EACR,OAAuB,EAAE;IAGzB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;IACpC,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC;IAClD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,OAAO,EAAE,CAAC;IAExC,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,EAAC,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC;YACV,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,cAAc;YACtC,OAAO,EAAE,uDAAuD;SACjE,CAAC,CAAC;QACH,OAAO;YACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,QAAQ,EAAE,OAAO,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,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC/B,IAAI,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACjB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,EAAE,GAAG,GAAG,EAAE,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC5C,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACb,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa,EAAE,GAAW;IAC1C,OAAO,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AACpE,CAAC;AAED,SAAS,kBAAkB,CAAC,CAAmF;IAC7G,IAAI,CAAC,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,IAAI,CAAC;IAC5C,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5F,OAAO,6KAA6K,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAClM,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Keep the usable part of a planner-model response.
3
+ *
4
+ * A strict schema used to reject the whole plan when one flow had an empty
5
+ * `steps` array (`flows[5].steps`). The crawl's form and fault flows then
6
+ * never ran. This pass drops only the broken flows. Callers still append
7
+ * the deterministic grounded flows afterwards.
8
+ */
9
+ import type { TestFlow } from '../types.js';
10
+ export interface SalvagedFlows {
11
+ flows: TestFlow[];
12
+ /** Model flows that had no usable step or start URL. */
13
+ dropped: number;
14
+ }
15
+ export declare function salvageModelFlows(raw: unknown): SalvagedFlows;
16
+ //# sourceMappingURL=salvage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"salvage.d.ts","sourceRoot":"","sources":["../../src/planner/salvage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAY,QAAQ,EAAY,MAAM,aAAa,CAAC;AAmBhE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CAW7D"}
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Keep the usable part of a planner-model response.
3
+ *
4
+ * A strict schema used to reject the whole plan when one flow had an empty
5
+ * `steps` array (`flows[5].steps`). The crawl's form and fault flows then
6
+ * never ran. This pass drops only the broken flows. Callers still append
7
+ * the deterministic grounded flows afterwards.
8
+ */
9
+ import { z } from 'zod';
10
+ import { coerceEnum } from '../llm/coerce.js';
11
+ const KINDS = ['happy_path', 'edge_case', 'auth_required', 'destructive', 'accessibility', 'visual'];
12
+ const SEVERITIES = ['critical', 'major', 'minor'];
13
+ const StrictFlowSchema = z.object({
14
+ id: z.string().min(1),
15
+ name: z.string().min(3),
16
+ description: z.string().min(3),
17
+ kind: z.enum(KINDS),
18
+ startUrl: z.string().url(),
19
+ steps: z.array(z.object({
20
+ action: z.string().min(3),
21
+ expectation: z.string().optional(),
22
+ })).min(1),
23
+ expectation: z.string().min(3),
24
+ severityIfFails: z.enum(SEVERITIES),
25
+ });
26
+ export function salvageModelFlows(raw) {
27
+ const list = Array.isArray(raw) ? raw : (raw && typeof raw === 'object' ? [raw] : null);
28
+ if (!list)
29
+ return { flows: [], dropped: 0 };
30
+ const flows = [];
31
+ let dropped = 0;
32
+ list.forEach((item, index) => {
33
+ const flow = coerceFlow(item, index);
34
+ if (flow)
35
+ flows.push(flow);
36
+ else
37
+ dropped += 1;
38
+ });
39
+ return { flows, dropped };
40
+ }
41
+ function coerceFlow(raw, index) {
42
+ const strict = StrictFlowSchema.safeParse(raw);
43
+ if (strict.success)
44
+ return strict.data;
45
+ if (!raw || typeof raw !== 'object')
46
+ return undefined;
47
+ const record = raw;
48
+ const startUrl = typeof record.startUrl === 'string' ? record.startUrl : '';
49
+ if (!z.string().url().safeParse(startUrl).success)
50
+ return undefined;
51
+ const steps = usableSteps(record.steps);
52
+ if (steps.length === 0)
53
+ return undefined;
54
+ return {
55
+ id: text(record.id, 1) || `model-flow-${index + 1}`,
56
+ name: text(record.name, 3) || `Flow ${index + 1}`,
57
+ description: text(record.description, 3) || 'Kept from a partial planner response.',
58
+ kind: coerceEnum(record.kind, KINDS, {
59
+ happy: 'happy_path',
60
+ edge: 'edge_case',
61
+ auth: 'auth_required',
62
+ login: 'auth_required',
63
+ a11y: 'accessibility',
64
+ }) ?? 'happy_path',
65
+ startUrl,
66
+ steps,
67
+ expectation: text(record.expectation, 3) || 'The journey completes.',
68
+ severityIfFails: coerceEnum(record.severityIfFails ?? record.severity, SEVERITIES, {
69
+ high: 'major',
70
+ medium: 'major',
71
+ med: 'major',
72
+ low: 'minor',
73
+ blocker: 'critical',
74
+ severe: 'critical',
75
+ }) ?? 'major',
76
+ };
77
+ }
78
+ function usableSteps(raw) {
79
+ const list = Array.isArray(raw)
80
+ ? raw
81
+ : (typeof raw === 'string' || (raw && typeof raw === 'object') ? [raw] : []);
82
+ const steps = [];
83
+ for (const item of list) {
84
+ if (typeof item === 'string') {
85
+ const action = item.trim();
86
+ if (action.length >= 3)
87
+ steps.push({ action });
88
+ continue;
89
+ }
90
+ if (!item || typeof item !== 'object')
91
+ continue;
92
+ const record = item;
93
+ const action = text(record.action, 3) || text(record.instruction, 3) || text(record.step, 3);
94
+ if (action.length < 3)
95
+ continue;
96
+ const expectation = text(record.expectation, 1) || undefined;
97
+ steps.push(expectation ? { action, expectation } : { action });
98
+ }
99
+ return steps;
100
+ }
101
+ function text(value, min) {
102
+ if (typeof value !== 'string')
103
+ return '';
104
+ const trimmed = value.trim();
105
+ return trimmed.length >= min ? trimmed : '';
106
+ }
107
+ //# sourceMappingURL=salvage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"salvage.js","sourceRoot":"","sources":["../../src/planner/salvage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,MAAM,KAAK,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,QAAQ,CAAU,CAAC;AAC9G,MAAM,UAAU,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAU,CAAC;AAE3D,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9B,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;IACnB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE;IAC1B,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;QACtB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACzB,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KACnC,C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E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,IAAI,CAAC,KAAc,EAAE,GAAW;IACvC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Translate a plan step into a Playwright action, execute it, and capture a
3
+ * stable locator (role, name, text, test id, CSS fallback) for later replay.
4
+ */
5
+ import type { Locator, Page } from 'playwright';
6
+ import { z } from 'zod';
7
+ import type { LLM } from '../llm/index.js';
8
+ import type { TestFlow, TestStep, StepStatus, TraceLocator } from '../types.js';
9
+ export declare const ActionSchema: z.ZodEffects<z.ZodObject<{
10
+ tool: z.ZodEnum<["click", "fill", "goto", "wait", "assert_text", "press", "noop"]>;
11
+ /** CSS selector, URL (for goto), test id, or text snippet (for assert_text). */
12
+ target: z.ZodOptional<z.ZodString>;
13
+ /** Value to type (for fill) or key chord (for press). */
14
+ value: z.ZodOptional<z.ZodString>;
15
+ /**
16
+ * Locator strategy hint. Role / text / label / testid survive DOM reshuffles
17
+ * better than a raw CSS selector.
18
+ */
19
+ locator: z.ZodOptional<z.ZodEnum<["css", "role", "text", "placeholder", "label", "testid"]>>;
20
+ /** One-sentence explanation, useful for the report timeline. */
21
+ rationale: z.ZodOptional<z.ZodString>;
22
+ }, "strip", z.ZodTypeAny, {
23
+ tool: "click" | "fill" | "goto" | "wait" | "assert_text" | "press" | "noop";
24
+ value?: string | undefined;
25
+ target?: string | undefined;
26
+ locator?: "role" | "text" | "placeholder" | "label" | "testid" | "css" | undefined;
27
+ rationale?: string | undefined;
28
+ }, {
29
+ tool: "click" | "fill" | "goto" | "wait" | "assert_text" | "press" | "noop";
30
+ value?: string | undefined;
31
+ target?: string | undefined;
32
+ locator?: "role" | "text" | "placeholder" | "label" | "testid" | "css" | undefined;
33
+ rationale?: string | undefined;
34
+ }>, {
35
+ tool: "click" | "fill" | "goto" | "wait" | "assert_text" | "press" | "noop";
36
+ value?: string | undefined;
37
+ target?: string | undefined;
38
+ locator?: "role" | "text" | "placeholder" | "label" | "testid" | "css" | undefined;
39
+ rationale?: string | undefined;
40
+ }, unknown>;
41
+ export type ResolvedAction = z.infer<typeof ActionSchema>;
42
+ export interface PageSkeletonForLLM {
43
+ url: string;
44
+ title: string;
45
+ headings: string[];
46
+ buttons: string[];
47
+ links: {
48
+ text: string;
49
+ href: string;
50
+ }[];
51
+ inputs: {
52
+ label?: string;
53
+ placeholder?: string;
54
+ name?: string;
55
+ type?: string;
56
+ }[];
57
+ }
58
+ /**
59
+ * Execute a step whose wording names a control that is already on screen.
60
+ *
61
+ * `Click "Save order"` and `Fill the "email" field` do not need a model.
62
+ * A step that does not quote a visible label returns null and the caller
63
+ * falls through to `resolveAction`.
64
+ */
65
+ export declare function directActionFromStep(action: string, skeleton: PageSkeletonForLLM): ResolvedAction | null;
66
+ /**
67
+ * A model often answers `placeholder:Email` for a box whose only identity is
68
+ * its label or `name`. Prefer those. Placeholder remains when it is all the
69
+ * page exposed.
70
+ */
71
+ export declare function groundFillAction(action: ResolvedAction, skeleton: PageSkeletonForLLM): ResolvedAction;
72
+ export declare function resolveAction(llm: LLM, flow: TestFlow, step: TestStep, skeleton: PageSkeletonForLLM): Promise<ResolvedAction>;
73
+ export interface ActionOutcome {
74
+ status: StepStatus;
75
+ observation: string;
76
+ error?: string;
77
+ }
78
+ export declare function executeAction(page: Page, action: ResolvedAction, timeoutMs: number, options?: {
79
+ strictOracles?: boolean;
80
+ }): Promise<ActionOutcome>;
81
+ export declare function buildLocator(page: Page, action: ResolvedAction): Locator;
82
+ /**
83
+ * Read role / accessible name / text / test id / CSS off the element the
84
+ * action is about to hit. Replay tries these in stability order and does not
85
+ * need the original LLM call.
86
+ */
87
+ export declare function captureLocator(page: Page, action: ResolvedAction): Promise<TraceLocator>;
88
+ export declare function skeletonForLLM(page: Page): Promise<PageSkeletonForLLM>;
89
+ export declare function settleSPA(page: Page): Promise<void>;
90
+ export declare function describeTarget(action: ResolvedAction): string;
91
+ //# sourceMappingURL=actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/runner/actions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EAEb,MAAM,aAAa,CAAC;AAkDrB,eAAO,MAAM,YAAY;;IAEvB,gFAAgF;;IAEhF,yDAAyD;;IAEzD;;;OAGG;;IAEH,gEAAgE;;;;;;;;;;;;;;;;;;;;WAE/D,CAAC;AAEJ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAE1D,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACxC,MAAM,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAClF;AAED;;;;;;GAMG;AACH,wB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