@monkeytestai/monkeytest-core 0.0.0-stage → 0.4.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 (109) hide show
  1. package/CHANGELOG.md +160 -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 +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 +54 -0
  18. package/dist/explorer/index.d.ts.map +1 -0
  19. package/dist/explorer/index.js +491 -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/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 +24 -0
  46. package/dist/planner/faults.d.ts.map +1 -0
  47. package/dist/planner/faults.js +128 -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,160 @@
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
+ - README and the docs install from npm: `npm install @monkeytestai/monkeytest-core` (published 0.4.0). A clone remains the contributor path, including the no-key smoke script.
13
+ - 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.
14
+ - **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.
15
+ - `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.
16
+ - 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.
17
+ - 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.
18
+ - `monkeytest run` exits **3** when the explorer visits zero pages, instead of exiting 0 with an empty report.
19
+ - 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.
20
+
21
+ ### Added
22
+
23
+ - 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.
24
+ - `--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.
25
+ - 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).
26
+ - 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.
27
+ - Action traces on each flow and on each bug (locator, value, URL, timing, evidence).
28
+ - `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.
29
+ - `monkeytest rerun` replays the stored trace with no LLM calls. `--heal` re-resolves a step whose locator missed and marks that step `healed`.
30
+ - `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`.
31
+ - Vitest coverage for fingerprints, trace serialisation, verdicts, and `diffRuns`, plus an integration test. CI runs `npm test`.
32
+ - 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.
33
+ - 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`).
34
+
35
+ ### Fixed
36
+
37
+ - The release workflow grants `contents: write` so it can open the GitHub release after npm publish. Provenance still uses `id-token: write`. The release install command uses the package version with the leading `v` removed.
38
+ - 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`.
39
+ - 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.
40
+ - 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.
41
+ - 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.
42
+
43
+ ## [0.4.1] — 2026-10
44
+
45
+ ### Fixed
46
+
47
+ - The crawler compared outbound links with `URL.origin`, so a start URL of `http://shop.example/` that redirects to `https://www.shop.example/` never left the homepage: every rewritten link looked off-origin and the queue stopped. Crawl scope now treats the apex host and `www` as one site, and `http` and `https` as one site. Another subdomain, another host, or another explicit port is still skipped. A redirect that stays on the site is stored as the URL the browser landed on; the caller's `startUrl` is unchanged. The fault-surface link check uses the same site rule, so a homepage "Track order" or "Help" link rewritten onto `https://www` is still eligible when that path was not crawled. The public-form floor is unchanged and still requires the form page in the sitemap. `www` / scheme matching for HTTP 5xx oracles is unchanged.
48
+
49
+ ## [0.4.0] — 2026-05
50
+
51
+ The bug-finding loop release. The CLI is now a real product surface with
52
+ `init`, `run`, `rerun`, `diff`, and `report` subcommands; the engine ships
53
+ the primitives those commands stand on (`Monkey.runFromPlan`, `diffRuns`,
54
+ plus `savePlan`/`loadPlan`/`saveRun`/`loadRun`).
55
+
56
+ ### Added
57
+
58
+ - `Monkey.runFromPlan(plan, opts)` — re-execute a stored `TestPlan`
59
+ without re-crawling or re-planning. The deterministic, cheap path for
60
+ verifying that a fix actually landed.
61
+ - `diffRuns(prev, current)` — set diff over `BugReport.fingerprint`s plus
62
+ a severity-rank check. Returns `{ newBugs, fixedBugs, persistingBugs,
63
+ regressedBugs, stats }`. `summariseDiff()` for one-line CLI output.
64
+ - Persistence module: `savePlan` / `loadPlan` / `saveRun` / `loadRun` /
65
+ `listRuns` with versioned `schema` field. Stable on-disk layout under
66
+ `.monkeytest/{plan.json, runs/<id>.json, shots/}`.
67
+ - New CLI subcommands:
68
+ - `monkeytest init` — scaffold `.monkeytest/`.
69
+ - `monkeytest run <url>` — full pipeline + persisted plan + run.
70
+ - `monkeytest rerun [<runId>]` — re-execute the same stored plan.
71
+ - `monkeytest diff <runA> <runB>` — bug-fingerprint diff with shortcuts
72
+ `latest`/`prev`. Exits `1` on new bugs or severity escalations.
73
+ - `monkeytest report [<runId>]` — pretty-print a stored run.
74
+ - Consistent CLI exit codes (`0` ok, `1` bugs/regressions, `2` bad args,
75
+ `3` engine error) so CI can gate on results.
76
+
77
+ ### Changed
78
+
79
+ - CLI rewritten as a subcommand router with per-command help; old
80
+ single-command entrypoint deprecated but `explore` still works.
81
+ - Plan / run JSON gain a `schema: 1` field for forwards-compatibility.
82
+
83
+ ### Docs
84
+
85
+ - New guide: **The bug-finding loop** — explains the find-fix-rerun-diff
86
+ cycle and the SaaS variant.
87
+ - New reference page: **CLI** with every subcommand, flag, env var, exit
88
+ code, and the on-disk layout.
89
+ - Homepage and README updated to lead with the loop story.
90
+
91
+ ## [0.3.0] — 2026-05
92
+
93
+ First public npm release.
94
+
95
+ ### Added
96
+
97
+ - **Anthropic Claude** provider (`provider: 'anthropic'`) with full
98
+ `messages.create` integration and prompted JSON mode.
99
+ - **Mistral** provider (`provider: 'mistral'`) using native
100
+ `responseFormat: { type: 'json_object' }`.
101
+ - **Groq** provider (`provider: 'groq'`) routing through Groq's
102
+ OpenAI-compatible endpoint for low-latency runner calls.
103
+ - **OpenAI-compatible** provider (`provider: 'openai_compatible'`) with
104
+ `baseURL` for Ollama, vLLM, LM Studio, OpenRouter, Together, and any
105
+ other server speaking the OpenAI Chat Completions wire format. JSON mode
106
+ is auto-disabled for `localhost`/`127.0.0.1` endpoints.
107
+ - **Per-phase LLM tiers.** `MonkeyLLMConfig` now exposes a dedicated
108
+ `runner?: LLMConfig` slot so the hot-path per-step calls can use a cheap,
109
+ fast model while the planner uses a smarter one.
110
+ - **Optional triager polish pass.** Set `MonkeyConfig.llm.triager` to have
111
+ the engine rewrite each bug's `title`, `observed`, `expected`, and
112
+ `triageNotes` from the structured evidence the deterministic triager
113
+ already collected. Per-bug try/catch — a bad LLM response on one bug
114
+ never affects the others, and the deterministic copy is always preserved
115
+ on failure.
116
+ - **Prompt caching** for OpenAI (auto, prompt-prefix) and Anthropic
117
+ (`cache_control: { type: 'ephemeral' }` breakpoints on the system block
118
+ and the long stable user block). The planner prompt is restructured into
119
+ `system` + `cacheable` (site map) + `prompt` (per-call constraints) so
120
+ repeat runs against the same site reuse the cached prefix.
121
+ - **`LLM.lastUsage`** — token + cache stats from each call
122
+ (`inputTokens`, `cachedInputTokens`, `outputTokens`, `cacheWrite`).
123
+ Surfaced through the `plan.complete` / `triage.complete` events so SaaS
124
+ dashboards can render "saved $X via prompt cache".
125
+ - **`autoLLMConfig({ quality })`** ergonomic helper — auto-detects a
126
+ provider from env vars and applies `cheap` / `balanced` / `smart`
127
+ presets. Lets users start in two lines.
128
+ - **`detectProviderFromEnv`**, **`CHEAP_FAST_MODEL`**, **`SMART_MODEL`**
129
+ exports for advanced consumers.
130
+
131
+ ### Changed
132
+
133
+ - Planner prompt restructured for cache friendliness; identical behaviour
134
+ for callers using `Monkey` directly.
135
+ - Default Gemini model remains `gemini-flash-lite-latest`. Default OpenAI
136
+ model remains `gpt-4o-mini`. Anthropic defaults to `claude-haiku-4-5`,
137
+ Mistral to `mistral-small-latest`, Groq to `llama-3.3-70b-versatile`.
138
+ - `triage()` is unchanged and remains zero-LLM-cost. The new
139
+ `triagePolished()` is a separate async export for callers that want to
140
+ drive the polish pass directly.
141
+
142
+ ### Documentation
143
+
144
+ - New comprehensive docs site at **docs.monkeytest.ai** with sections:
145
+ Architecture, LLM providers, Cost & depth, Prompt caching, Triager
146
+ polish, Recipes, Use in CI, Troubleshooting.
147
+ - Hero image and value-led README.
148
+
149
+ ## [0.2.0] — 2026
150
+
151
+ ### Added
152
+
153
+ - Explorer, planner, runner, triager pipeline
154
+ - Playwright execution with per-step screenshots and optional flow video
155
+ - `EventBus` for live activity streams
156
+ - OpenAI and Gemini LLM backends
157
+
158
+ [0.4.1]: https://github.com/monkeytestai/monkeytest-core/releases/tag/v0.4.1
159
+ [0.3.0]: https://github.com/monkeytestai/monkeytest-core/releases/tag/v0.3.0
160
+ [0.2.0]: https://github.com/monkeytestai/monkeytest-core/releases/tag/v0.2.0