@monkeytestai/monkeytest-core 0.0.0-stage → 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.
Files changed (109) hide show
  1. package/CHANGELOG.md +151 -0
  2. package/LICENSE +661 -0
  3. package/NOTICE +12 -0
  4. package/README.md +189 -2
  5. package/dist/cli.d.ts +43 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +771 -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 +49 -0
  18. package/dist/explorer/index.d.ts.map +1 -0
  19. package/dist/explorer/index.js +501 -0
  20. package/dist/explorer/index.js.map +1 -0
  21. package/dist/explorer/queue.d.ts +53 -0
  22. package/dist/explorer/queue.d.ts.map +1 -0
  23. package/dist/explorer/queue.js +143 -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/index.d.ts +79 -0
  30. package/dist/llm/index.d.ts.map +1 -0
  31. package/dist/llm/index.js +392 -0
  32. package/dist/llm/index.js.map +1 -0
  33. package/dist/llm/presets.d.ts +61 -0
  34. package/dist/llm/presets.d.ts.map +1 -0
  35. package/dist/llm/presets.js +101 -0
  36. package/dist/llm/presets.js.map +1 -0
  37. package/dist/monkey.d.ts +151 -0
  38. package/dist/monkey.d.ts.map +1 -0
  39. package/dist/monkey.js +323 -0
  40. package/dist/monkey.js.map +1 -0
  41. package/dist/persistence/index.d.ts +118 -0
  42. package/dist/persistence/index.d.ts.map +1 -0
  43. package/dist/persistence/index.js +196 -0
  44. package/dist/persistence/index.js.map +1 -0
  45. package/dist/planner/faults.d.ts +22 -0
  46. package/dist/planner/faults.d.ts.map +1 -0
  47. package/dist/planner/faults.js +136 -0
  48. package/dist/planner/faults.js.map +1 -0
  49. package/dist/planner/forms.d.ts +33 -0
  50. package/dist/planner/forms.d.ts.map +1 -0
  51. package/dist/planner/forms.js +163 -0
  52. package/dist/planner/forms.js.map +1 -0
  53. package/dist/planner/index.d.ts +31 -0
  54. package/dist/planner/index.d.ts.map +1 -0
  55. package/dist/planner/index.js +250 -0
  56. package/dist/planner/index.js.map +1 -0
  57. package/dist/planner/salvage.d.ts +16 -0
  58. package/dist/planner/salvage.d.ts.map +1 -0
  59. package/dist/planner/salvage.js +89 -0
  60. package/dist/planner/salvage.js.map +1 -0
  61. package/dist/runner/actions.d.ts +85 -0
  62. package/dist/runner/actions.d.ts.map +1 -0
  63. package/dist/runner/actions.js +610 -0
  64. package/dist/runner/actions.js.map +1 -0
  65. package/dist/runner/evidence.d.ts +37 -0
  66. package/dist/runner/evidence.d.ts.map +1 -0
  67. package/dist/runner/evidence.js +122 -0
  68. package/dist/runner/evidence.js.map +1 -0
  69. package/dist/runner/http5xx.d.ts +40 -0
  70. package/dist/runner/http5xx.d.ts.map +1 -0
  71. package/dist/runner/http5xx.js +189 -0
  72. package/dist/runner/http5xx.js.map +1 -0
  73. package/dist/runner/index.d.ts +88 -0
  74. package/dist/runner/index.d.ts.map +1 -0
  75. package/dist/runner/index.js +597 -0
  76. package/dist/runner/index.js.map +1 -0
  77. package/dist/runner/replay.d.ts +42 -0
  78. package/dist/runner/replay.d.ts.map +1 -0
  79. package/dist/runner/replay.js +440 -0
  80. package/dist/runner/replay.js.map +1 -0
  81. package/dist/runner/timeout.d.ts +16 -0
  82. package/dist/runner/timeout.d.ts.map +1 -0
  83. package/dist/runner/timeout.js +38 -0
  84. package/dist/runner/timeout.js.map +1 -0
  85. package/dist/trace/fingerprint.d.ts +78 -0
  86. package/dist/trace/fingerprint.d.ts.map +1 -0
  87. package/dist/trace/fingerprint.js +273 -0
  88. package/dist/trace/fingerprint.js.map +1 -0
  89. package/dist/trace/serialize.d.ts +15 -0
  90. package/dist/trace/serialize.d.ts.map +1 -0
  91. package/dist/trace/serialize.js +86 -0
  92. package/dist/trace/serialize.js.map +1 -0
  93. package/dist/triager/index.d.ts +64 -0
  94. package/dist/triager/index.d.ts.map +1 -0
  95. package/dist/triager/index.js +301 -0
  96. package/dist/triager/index.js.map +1 -0
  97. package/dist/types.d.ts +491 -0
  98. package/dist/types.d.ts.map +1 -0
  99. package/dist/types.js +10 -0
  100. package/dist/types.js.map +1 -0
  101. package/dist/verify/index.d.ts +52 -0
  102. package/dist/verify/index.d.ts.map +1 -0
  103. package/dist/verify/index.js +140 -0
  104. package/dist/verify/index.js.map +1 -0
  105. package/dist/verify/verdict.d.ts +34 -0
  106. package/dist/verify/verdict.d.ts.map +1 -0
  107. package/dist/verify/verdict.js +89 -0
  108. package/dist/verify/verdict.js.map +1 -0
  109. package/package.json +89 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,151 @@
1
+ # Changelog
2
+
3
+ All notable changes to **MonkeyTest Core** are documented here.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Changed
11
+
12
+ - Package name is `@monkeytestai/monkeytest-core` (version stays `0.4.0`). It was `@mtai/monkeytest-core`; that npm scope is taken. Imports, install docs, CI, and the Docker image use the new name. Runtime behavior and the AGPL-3.0 license are unchanged.
13
+ - **SaaS migration.** `new Monkey()` now defaults `strictOracles` and `failOn5xx` to **on**. A page error, a document HTTP 404, a disabled control a step tries to use, and a same-origin HTTP ≥500 (document, xhr, or fetch) become a failed step and a blocking bug. Bug counts and `flowsFailed` will rise. To keep the previous counts, pass `strictOracles: false` and `failOn5xx: false` on the constructor, or the same fields on one `run` / `replay` / `verify` call. `www` and the apex host still match. Other ports, third-party hosts, and image/font responses stay evidence only.
14
+ - `runPlan`, `replayTraces`, `verifyBugs`, and `triage(run)` still leave those switches off unless the caller passes them, so triaging a run you already built does not rewrite it. `Monkey` passes the constructor values (now on) into the run and into `triage`. `RunResult` fields are unchanged.
15
+ - The planner keeps grounded flows, within `maxFlows`, for a crawled public form, one enabled non-submit button, one same-origin link whose target was not crawled, and one disabled non-submit button. Labels and URLs come from the crawl (`SiteMapPage.controls`, optional). Leftover model flows are the ones replaced when the budget is full.
16
+ - The runner performs `Click "Save order"` and `Fill the "email" field` itself when that label is on the page. Other steps still go to the runner model.
17
+ - `monkeytest run` exits **3** when the explorer visits zero pages, instead of exiting 0 with an empty report.
18
+ - The live e2e script starts the CLI as an asynchronous child. `spawnSync` froze the in-process demo server, the homepage timed out, and the buggy fixture exited 0.
19
+
20
+ ### Added
21
+
22
+ - Multi-stage `Dockerfile` (Node 22, `bookworm-slim`) and [DOCKER.md](./DOCKER.md). `npm ci` and `npm run build` produce `/opt/monkeytest-core` (`dist/`, `package.json`, license files, production dependencies) for a `file:` install or `COPY --from`. Playwright browsers are not downloaded. Engine audit behavior is unchanged.
23
+ - `--fail-on-5xx` (CLI default on, `--no-fail-on-5xx` opts out) fails a passed or skipped step that observed a same-origin HTTP ≥500 on a document, xhr, or fetch, and the triager files it as a critical bug. `new Monkey()` now defaults this **on** as well. Pass `failOn5xx: false` to opt out. `www` and the apex host match. Other ports, third-party hosts, and image/font responses stay evidence only.
24
+ - The crawler reserves a few `maxPages` slots for help, contact, support, about, and other form-style links it actually saw, and keeps those links even when they sit past the ordinary link cap. `SiteMapPage.forms` records scraped forms (optional; existing readers can ignore it).
25
+ - When the crawl contains a public form and `maxFlows` is at least 1, the planner keeps a form-submit flow grounded in that page's URL, fields, and submit label. A header search box does not take that slot. The model is asked for the same flow; the deterministic pass is the floor.
26
+ - Action traces on each flow and on each bug (locator, value, URL, timing, evidence).
27
+ - `fingerprintV2` and `fingerprintParts` (version 2) from failure category, URL template, element role + name, and a normalised error signal. `fingerprint` stays the legacy v1 hash so stored bugs still match. Diff and verify use v2 only when both sides have it.
28
+ - `monkeytest rerun` replays the stored trace with no LLM calls. `--heal` re-resolves a step whose locator missed and marks that step `healed`.
29
+ - `monkeytest verify` replays each bug trace and reports `fixed`, `still_broken`, `flaky`, `healed`, or `blocked`. Exit `1` when any bug is `still_broken` or `flaky`.
30
+ - Vitest coverage for fingerprints, trace serialisation, verdicts, and `diffRuns`, plus an integration test. CI runs `npm test`.
31
+ - Strict oracles fail a step when the page throws, a document returns HTTP 404, an action returns HTTP 5xx, or the clicked control is disabled. They default **on** for `new Monkey()` and for the CLI. Pass `strictOracles: false` to opt out. Replay uses the same switch. `runPlan` still defaults it off unless the caller passes it.
32
+ - Reusable buggy/fixed demo app under `test/fixtures/demo-app`. `npm test` covers it with a stub LLM. `.github/workflows/e2e-live.yml` runs the same app with a real model (manual, nightly, and pushes to `main`).
33
+
34
+ ### Fixed
35
+
36
+ - A valid planner response can no longer drop a public form the crawl already saw. The form-submit flow is a reserved slot: shopping-only plans, and plans whose only submit is a vague "submit" on that page, still include the grounded flow and its action URL (for example `/api/contact`). Fault-surface flows cannot take that slot. Help, contact, and about reads are dropped only after shop flows. `SiteMapForm.inputs` optionally records label, name, placeholder, and type; `fields` is unchanged. Fill steps use that label, then a `name` CSS selector, instead of an invented placeholder such as `placeholder:Email`.
37
+ - Replay and verify keep going when a step the original run already marked `skipped` has a locator that still misses. A soft skip (for example a placeholder fill that never matched) no longer becomes `locator_mismatch` and hides a later bug, such as a form POST that returned HTTP 500. A step that originally passed or failed still stops the flow. Fingerprints are unchanged.
38
+ - A planner model response that is invalid JSON, fails schema validation, or includes a flow with empty `steps` no longer wipes the plan. Usable model flows are kept. The public-form submit flow and scraped fault-control flows are still added, up to `maxFlows`. `plan()` records the model error on `TestPlan.notes` and emits `engine.error`. `executeAndTriage` runs that plan. An empty plan remains only when the crawl has no public form and no fault control. `RunResult` fields are unchanged. `groundedTestPlan(siteMap, maxFlows)` is the same crawl-only floor, for a host that catches a planner failure itself.
39
+ - The per-flow timeout no longer leaves its timer running after the flow finishes, and it closes the browser context when the budget is exceeded.
40
+
41
+ ## [0.4.0] — 2026-05
42
+
43
+ The bug-finding loop release. The CLI is now a real product surface with
44
+ `init`, `run`, `rerun`, `diff`, and `report` subcommands; the engine ships
45
+ the primitives those commands stand on (`Monkey.runFromPlan`, `diffRuns`,
46
+ plus `savePlan`/`loadPlan`/`saveRun`/`loadRun`).
47
+
48
+ ### Added
49
+
50
+ - `Monkey.runFromPlan(plan, opts)` — re-execute a stored `TestPlan`
51
+ without re-crawling or re-planning. The deterministic, cheap path for
52
+ verifying that a fix actually landed.
53
+ - `diffRuns(prev, current)` — set diff over `BugReport.fingerprint`s plus
54
+ a severity-rank check. Returns `{ newBugs, fixedBugs, persistingBugs,
55
+ regressedBugs, stats }`. `summariseDiff()` for one-line CLI output.
56
+ - Persistence module: `savePlan` / `loadPlan` / `saveRun` / `loadRun` /
57
+ `listRuns` with versioned `schema` field. Stable on-disk layout under
58
+ `.monkeytest/{plan.json, runs/<id>.json, shots/}`.
59
+ - New CLI subcommands:
60
+ - `monkeytest init` — scaffold `.monkeytest/`.
61
+ - `monkeytest run <url>` — full pipeline + persisted plan + run.
62
+ - `monkeytest rerun [<runId>]` — re-execute the same stored plan.
63
+ - `monkeytest diff <runA> <runB>` — bug-fingerprint diff with shortcuts
64
+ `latest`/`prev`. Exits `1` on new bugs or severity escalations.
65
+ - `monkeytest report [<runId>]` — pretty-print a stored run.
66
+ - Consistent CLI exit codes (`0` ok, `1` bugs/regressions, `2` bad args,
67
+ `3` engine error) so CI can gate on results.
68
+
69
+ ### Changed
70
+
71
+ - CLI rewritten as a subcommand router with per-command help; old
72
+ single-command entrypoint deprecated but `explore` still works.
73
+ - Plan / run JSON gain a `schema: 1` field for forwards-compatibility.
74
+
75
+ ### Docs
76
+
77
+ - New guide: **The bug-finding loop** — explains the find-fix-rerun-diff
78
+ cycle and the SaaS variant.
79
+ - New reference page: **CLI** with every subcommand, flag, env var, exit
80
+ code, and the on-disk layout.
81
+ - Homepage and README updated to lead with the loop story.
82
+
83
+ ## [0.3.0] — 2026-05
84
+
85
+ First public npm release.
86
+
87
+ ### Added
88
+
89
+ - **Anthropic Claude** provider (`provider: 'anthropic'`) with full
90
+ `messages.create` integration and prompted JSON mode.
91
+ - **Mistral** provider (`provider: 'mistral'`) using native
92
+ `responseFormat: { type: 'json_object' }`.
93
+ - **Groq** provider (`provider: 'groq'`) routing through Groq's
94
+ OpenAI-compatible endpoint for low-latency runner calls.
95
+ - **OpenAI-compatible** provider (`provider: 'openai_compatible'`) with
96
+ `baseURL` for Ollama, vLLM, LM Studio, OpenRouter, Together, and any
97
+ other server speaking the OpenAI Chat Completions wire format. JSON mode
98
+ is auto-disabled for `localhost`/`127.0.0.1` endpoints.
99
+ - **Per-phase LLM tiers.** `MonkeyLLMConfig` now exposes a dedicated
100
+ `runner?: LLMConfig` slot so the hot-path per-step calls can use a cheap,
101
+ fast model while the planner uses a smarter one.
102
+ - **Optional triager polish pass.** Set `MonkeyConfig.llm.triager` to have
103
+ the engine rewrite each bug's `title`, `observed`, `expected`, and
104
+ `triageNotes` from the structured evidence the deterministic triager
105
+ already collected. Per-bug try/catch — a bad LLM response on one bug
106
+ never affects the others, and the deterministic copy is always preserved
107
+ on failure.
108
+ - **Prompt caching** for OpenAI (auto, prompt-prefix) and Anthropic
109
+ (`cache_control: { type: 'ephemeral' }` breakpoints on the system block
110
+ and the long stable user block). The planner prompt is restructured into
111
+ `system` + `cacheable` (site map) + `prompt` (per-call constraints) so
112
+ repeat runs against the same site reuse the cached prefix.
113
+ - **`LLM.lastUsage`** — token + cache stats from each call
114
+ (`inputTokens`, `cachedInputTokens`, `outputTokens`, `cacheWrite`).
115
+ Surfaced through the `plan.complete` / `triage.complete` events so SaaS
116
+ dashboards can render "saved $X via prompt cache".
117
+ - **`autoLLMConfig({ quality })`** ergonomic helper — auto-detects a
118
+ provider from env vars and applies `cheap` / `balanced` / `smart`
119
+ presets. Lets users start in two lines.
120
+ - **`detectProviderFromEnv`**, **`CHEAP_FAST_MODEL`**, **`SMART_MODEL`**
121
+ exports for advanced consumers.
122
+
123
+ ### Changed
124
+
125
+ - Planner prompt restructured for cache friendliness; identical behaviour
126
+ for callers using `Monkey` directly.
127
+ - Default Gemini model remains `gemini-flash-lite-latest`. Default OpenAI
128
+ model remains `gpt-4o-mini`. Anthropic defaults to `claude-haiku-4-5`,
129
+ Mistral to `mistral-small-latest`, Groq to `llama-3.3-70b-versatile`.
130
+ - `triage()` is unchanged and remains zero-LLM-cost. The new
131
+ `triagePolished()` is a separate async export for callers that want to
132
+ drive the polish pass directly.
133
+
134
+ ### Documentation
135
+
136
+ - New comprehensive docs site at **docs.monkeytest.ai** with sections:
137
+ Architecture, LLM providers, Cost & depth, Prompt caching, Triager
138
+ polish, Recipes, Use in CI, Troubleshooting.
139
+ - Hero image and value-led README.
140
+
141
+ ## [0.2.0] — 2026
142
+
143
+ ### Added
144
+
145
+ - Explorer, planner, runner, triager pipeline
146
+ - Playwright execution with per-step screenshots and optional flow video
147
+ - `EventBus` for live activity streams
148
+ - OpenAI and Gemini LLM backends
149
+
150
+ [0.3.0]: https://github.com/monkeytestai/monkeytest-core/releases/tag/v0.3.0
151
+ [0.2.0]: https://github.com/monkeytestai/monkeytest-core/releases/tag/v0.2.0