@capagents/forgeqe 3.1.2 → 3.1.3

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 (170) hide show
  1. package/HOW_TO_USE.md +5003 -2077
  2. package/README.md +155 -449
  3. package/dist/docs-site/docs/app-theme.css +30 -9
  4. package/dist/docs-site/docs/architecture/index.html +45 -515
  5. package/dist/docs-site/docs/architecture-reference/index.html +1781 -0
  6. package/dist/docs-site/docs/area-api/index.html +257 -116
  7. package/dist/docs-site/docs/area-automated-tests/index.html +1229 -419
  8. package/dist/docs-site/docs/area-browser/index.html +167 -125
  9. package/dist/docs-site/docs/area-data/index.html +178 -188
  10. package/dist/docs-site/docs/area-desktop/index.html +329 -282
  11. package/dist/docs-site/docs/area-mobile/index.html +138 -86
  12. package/dist/docs-site/docs/area-operations/index.html +567 -393
  13. package/dist/docs-site/docs/area-pull-requests/index.html +114 -32
  14. package/dist/docs-site/docs/area-quality/index.html +111 -49
  15. package/dist/docs-site/docs/area-release/index.html +180 -65
  16. package/dist/docs-site/docs/area-setup/index.html +742 -339
  17. package/dist/docs-site/docs/area-systems/index.html +32 -48
  18. package/dist/docs-site/docs/area-test-cases/index.html +387 -154
  19. package/dist/docs-site/docs/containers/index.html +87 -101
  20. package/dist/docs-site/docs/cost-architecture/index.html +4 -3
  21. package/dist/docs-site/docs/custom-agents-first-run/index.html +108 -50
  22. package/dist/docs-site/docs/desktop/index.html +277 -297
  23. package/dist/docs-site/docs/desktop-ci/index.html +15 -5
  24. package/dist/docs-site/docs/docs-tabs.js +56 -0
  25. package/dist/docs-site/docs/evidence/index.html +50 -49
  26. package/dist/docs-site/docs/feature-test-prompts/index.html +34 -24
  27. package/dist/docs-site/docs/get-started/index.html +464 -168
  28. package/dist/docs-site/docs/graphify/index.html +8 -7
  29. package/dist/docs-site/docs/guardrails/index.html +20 -4
  30. package/dist/docs-site/docs/index.html +4 -3
  31. package/dist/docs-site/docs/mobile/index.html +96 -76
  32. package/dist/docs-site/docs/model-routing/index.html +44 -18
  33. package/dist/docs-site/docs/overview/index.html +23 -7
  34. package/dist/docs-site/docs/product-graph/index.html +13 -12
  35. package/dist/docs-site/docs/product-knowledge/index.html +16 -5
  36. package/dist/docs-site/docs/product-views/index.html +7 -6
  37. package/dist/docs-site/docs/reference/index.html +95 -65
  38. package/dist/docs-site/docs/search.js +1 -1
  39. package/dist/docs-site/docs/using/index.html +444 -126
  40. package/dist/docs-site/docs/web-app/index.html +54 -51
  41. package/dist/forgeqe.js +1822 -1822
  42. package/dist/web/assets/Agent-3pV8Rwap.js +8 -0
  43. package/dist/web/assets/AgentWork-DAnmH0My.js +2 -0
  44. package/dist/web/assets/ApiTests-DW4MRFzG.js +10 -0
  45. package/dist/web/assets/Browse-Bd0ZZfc2.js +1 -0
  46. package/dist/web/assets/Chat-DnBUm_97.js +3 -0
  47. package/dist/web/assets/CommandPalette-B1O9aDTk.js +1 -0
  48. package/dist/web/assets/Compare-1v7_ca7z.js +1 -0
  49. package/dist/web/assets/Cost-CWrc4McH.js +1 -0
  50. package/dist/web/assets/Data-rWSiG4Cq.js +6 -0
  51. package/dist/web/assets/Desktop-3x6EQqos.js +1 -0
  52. package/dist/web/assets/DesktopReview-cSA10Rm3.js +1 -0
  53. package/dist/web/assets/Evidence-CKy3o7cw.js +1 -0
  54. package/dist/web/assets/{Explore-ObkEpUyS.js → Explore-CMAxWE_8.js} +2 -2
  55. package/dist/web/assets/Features-haQchkhA.js +1 -0
  56. package/dist/web/assets/{Flags-0-RniPJm.js → Flags-BaQjYi_t.js} +2 -2
  57. package/dist/web/assets/Flaky-DUuC0qTn.js +1 -0
  58. package/dist/web/assets/Impact-CP0H8ygo.js +3 -0
  59. package/dist/web/assets/Jobs-cYxoYd3i.js +5 -0
  60. package/dist/web/assets/KindPage-DWW8gN5_.js +6 -0
  61. package/dist/web/assets/Migration-Bsm7WU1d.js +2 -0
  62. package/dist/web/assets/PageAgent-c95zT2PJ.js +1 -0
  63. package/dist/web/assets/Product-BQSiR28a.js +7 -0
  64. package/dist/web/assets/Production-CAv0Vtoy.js +1 -0
  65. package/dist/web/assets/Quality-aQPaPYQc.js +1 -0
  66. package/dist/web/assets/Readiness-CkknP87n.js +1 -0
  67. package/dist/web/assets/Record-09IsC9U-.js +1 -0
  68. package/dist/web/assets/Regression-BL4MfN47.js +5 -0
  69. package/dist/web/assets/RelationGraph-Dg4fqt7l.js +1 -0
  70. package/dist/web/assets/Reports-CMV1l-iS.js +2 -0
  71. package/dist/web/assets/Response-DTBFBeKB.js +9 -0
  72. package/dist/web/assets/Responsive-DBRQ9FUO.js +3 -0
  73. package/dist/web/assets/RunDiff-CMDrnsA3.js +1 -0
  74. package/dist/web/assets/Runs-Dkeu6_vZ.js +2 -0
  75. package/dist/web/assets/Settings-KjKm8h-_.js +21 -0
  76. package/dist/web/assets/{Steps-D-YG0eJy.js → Steps-HYHK9psI.js} +1 -1
  77. package/dist/web/assets/TestCases-Cv6-OSv0.js +1 -0
  78. package/dist/web/assets/TestData-DbEfNlUE.js +2 -0
  79. package/dist/web/assets/TestDebt-DzHQIU4X.js +1 -0
  80. package/dist/web/assets/TestManagement-BgRTGHMT.js +1 -0
  81. package/dist/web/assets/Tosca-DZpHAtnH.js +3 -0
  82. package/dist/web/assets/WhatsNew-jp0c4WSV.js +1 -0
  83. package/dist/web/assets/coverage-BB9BLjGz.js +5 -0
  84. package/dist/web/assets/{dataParts-DbeCj9ga.js → dataParts-DEPK4eQE.js} +2 -2
  85. package/dist/web/assets/{diff-BStuTmsN.js → diff-CcNwLCX6.js} +1 -1
  86. package/dist/web/assets/{families-BBFFrUlo.js → families-gkpkloLT.js} +1 -1
  87. package/dist/web/assets/filters-C7phIFfd.js +1 -0
  88. package/dist/web/assets/fold-i73P-EDV.js +1 -0
  89. package/dist/web/assets/head-BtTqyLlj.js +1 -0
  90. package/dist/web/assets/{highlight-BcFZIf59.js → highlight-DZI39CzZ.js} +1 -1
  91. package/dist/web/assets/index-ClFOh63x.css +2 -0
  92. package/dist/web/assets/index-YGWJEkAT.js +64 -0
  93. package/dist/web/assets/input-C2vQ9O3a.js +1 -0
  94. package/dist/web/assets/logos-BmbNTDu2.js +1 -0
  95. package/dist/web/assets/palette-XFlqvgZl.js +1 -0
  96. package/dist/web/assets/{paletteCommands-Co-RlQ8q.js → paletteCommands-DsbD2ASU.js} +1 -1
  97. package/dist/web/assets/parts-DEVx2Sea.js +1 -0
  98. package/dist/web/assets/productParts-Bi-XjszL.js +1 -0
  99. package/dist/web/assets/qualityParts-Dbu01g7G.js +1 -0
  100. package/dist/web/assets/{recordTest-Cez2sDJO.js → recordTest--Wr40QdN.js} +1 -1
  101. package/dist/web/assets/route-Dg53WdFu.js +1 -0
  102. package/dist/web/index.html +6 -7
  103. package/docs/ARCHITECTURE.md +50 -563
  104. package/docs/ARCHITECTURE_REFERENCE.md +1484 -0
  105. package/docs/CONTAINERS.md +87 -87
  106. package/docs/CUSTOM_AGENTS_FIRST_RUN.md +125 -43
  107. package/docs/DESKTOP-CI.md +18 -3
  108. package/docs/DESKTOP.md +298 -297
  109. package/docs/MOBILE.md +103 -71
  110. package/docs/MODEL_ROUTING.md +48 -15
  111. package/docs/WEB_APP.md +49 -44
  112. package/docs/feature-test-prompts.md +29 -16
  113. package/docs/user-guide.html +5263 -2453
  114. package/guardrails/README.md +22 -2
  115. package/knowledge/README.md +15 -2
  116. package/package.json +1 -1
  117. package/prompts/brain.md +1 -0
  118. package/py/forgeqe_engine/recordsession.py +100 -24
  119. package/dist/web/assets/Agent-CPhmZdFX.js +0 -8
  120. package/dist/web/assets/AgentWork-BXdN9xgi.js +0 -2
  121. package/dist/web/assets/ApiTests-Do3xLjfB.js +0 -10
  122. package/dist/web/assets/Browse-WVkJT6Bs.js +0 -2
  123. package/dist/web/assets/Chat-CDc9UcQX.js +0 -3
  124. package/dist/web/assets/CommandPalette-BAZm62lV.js +0 -1
  125. package/dist/web/assets/Compare-Br6n9T9L.js +0 -1
  126. package/dist/web/assets/Cost-BBUyBu3Y.js +0 -1
  127. package/dist/web/assets/Data-Ch2DPEWp.js +0 -6
  128. package/dist/web/assets/Desktop-Qzoq-cQv.js +0 -1
  129. package/dist/web/assets/DesktopReview-CF_jQYAM.js +0 -1
  130. package/dist/web/assets/Evidence-C72Lj5_Q.js +0 -1
  131. package/dist/web/assets/Features-CQzNo_WP.js +0 -1
  132. package/dist/web/assets/Flaky-BPJvNLCA.js +0 -1
  133. package/dist/web/assets/Impact-CfccsL_k.js +0 -3
  134. package/dist/web/assets/Jobs-T6m4zhDy.js +0 -5
  135. package/dist/web/assets/KindPage-BDUvWe2p.js +0 -6
  136. package/dist/web/assets/Migration-Dqeh4x5u.js +0 -2
  137. package/dist/web/assets/PageAgent-DNjzIgeY.js +0 -1
  138. package/dist/web/assets/Product-nYV_scOV.js +0 -7
  139. package/dist/web/assets/Production-CGSbEWVa.js +0 -1
  140. package/dist/web/assets/Quality-BIypojZm.js +0 -1
  141. package/dist/web/assets/Readiness-BlRjwJRg.js +0 -1
  142. package/dist/web/assets/Record-v2KLI-_Z.js +0 -1
  143. package/dist/web/assets/Regression-B-jSt4Jz.js +0 -5
  144. package/dist/web/assets/RelationGraph-8J98lOVG.js +0 -1
  145. package/dist/web/assets/Reports-GI4u6SyW.js +0 -2
  146. package/dist/web/assets/Response-mhBThq2b.js +0 -9
  147. package/dist/web/assets/Responsive-DXu7Ra7K.js +0 -3
  148. package/dist/web/assets/RunDiff-D0SHDNp0.js +0 -1
  149. package/dist/web/assets/Runs-C1Gjdi9M.js +0 -2
  150. package/dist/web/assets/Settings-BGGeuvyF.js +0 -21
  151. package/dist/web/assets/TestCases-DC4w77eQ.js +0 -1
  152. package/dist/web/assets/TestData-CvKWRVVV.js +0 -2
  153. package/dist/web/assets/TestDebt-D8YzN29_.js +0 -1
  154. package/dist/web/assets/TestManagement-C5cDCqrD.js +0 -1
  155. package/dist/web/assets/Tosca-BGUv3RiJ.js +0 -3
  156. package/dist/web/assets/WhatsNew-B_Gyuv8O.js +0 -1
  157. package/dist/web/assets/coverage-BMP6ELFJ.js +0 -5
  158. package/dist/web/assets/filters-CnAMr286.js +0 -1
  159. package/dist/web/assets/fold-D_O_VZui.js +0 -1
  160. package/dist/web/assets/head-CRo48rPt.js +0 -1
  161. package/dist/web/assets/index-B3JsM7tv.js +0 -64
  162. package/dist/web/assets/index-CafApcbZ.css +0 -2
  163. package/dist/web/assets/input-CtzK50ZF.js +0 -1
  164. package/dist/web/assets/line-icons-rdF8DYDJ.js +0 -1
  165. package/dist/web/assets/logos-D4oVWzqa.js +0 -1
  166. package/dist/web/assets/palette-DAaGSao7.js +0 -1
  167. package/dist/web/assets/parts-D357Wolo.js +0 -1
  168. package/dist/web/assets/productParts-B8oHRCJF.js +0 -1
  169. package/dist/web/assets/qualityParts-BLkmIfDY.js +0 -1
  170. package/dist/web/assets/route-BloYJWgw.js +0 -1
@@ -4,10 +4,30 @@ The team's own rules for every agent ForgeQE runs, to keep them grounded. Each b
4
4
  `.txt` file in this folder is one guardrail; headings, other lines and HTML comments are ignored. `guardrails.md` is
5
5
  the file ForgeQE's agent adds to when you ask it for a new rule.
6
6
 
7
- How the agents use them:
7
+ **Adding guardrails.**
8
+
9
+ **Web app**
10
+
11
+ 1. Open **Guardrails**.
12
+ 2. Press **Add**.
13
+ 3. Give it a **Name** and **What it is for**, and under **Agents that follow it** pick **Every agent** or **Chosen
14
+ agents**.
15
+ 4. Type or paste the **Rules**, one `- rule` line each, or press **Upload** for a `.md` file.
16
+ 5. Press **Add**.
17
+
18
+ **Terminal**
19
+
20
+ ```bash
21
+ forgeqe guardrails # the rules every agent follows, and where each comes from
22
+ forgeqe guardrails add "Never open a production URL" # one rule, for every agent, added to guardrails.md
23
+ ```
24
+
25
+ Or write a `.md` file in this folder and commit it.
26
+
27
+ **How the agents use them.**
8
28
 
9
29
  - A file can be for some agents only: start it with a header that names them, by their names in `forgeqe context`
10
- (the Settings › Guardrails page writes it for you when you add a file there, pasted or uploaded):
30
+ (the web app writes it for you when you pick **Chosen agents**):
11
31
 
12
32
  ```
13
33
  ---
@@ -4,13 +4,26 @@ What ForgeQE's agents should know about your product, written once and used on e
4
4
  the words your team uses, the rules it follows, the data to test with, and where it runs. Fill in the files below (or add
5
5
  your own `.md` or `.txt` files, in folders if you like) and commit them.
6
6
 
7
- How the agents use it:
7
+ **Adding or editing a knowledge file.**
8
+
9
+ **Web app**
10
+
11
+ 1. Open **Knowledge**.
12
+ 2. Press **Add** for a new file and give its **File name** (a folder before the name groups files), or open a file and
13
+ pick **Edit**.
14
+ 3. Write it in Markdown and press **Save**.
15
+
16
+ **Terminal**
17
+
18
+ Edit the `.md` or `.txt` files in this folder with any editor, and commit them.
19
+
20
+ **How the agents use it.**
8
21
 
9
22
  - **ForgeQE's agent** sees the list of these files and reads the ones a request needs (planning tests, judging a test
10
23
  case, answering about the product).
11
24
  - **Planning agents** (exploratory charters, API scenarios) get the sections that match the story or scenario.
12
25
  - **The browser agent** gets the few sections that match the goal (at most `knowledge.browser_max_chars`, default 1500
13
- characters, so runs stay cheap).
26
+ characters, so runs stay cheap; **Knowledge per browser run** in **Settings › Product knowledge**).
14
27
 
15
28
  Sections are found by their headings, so give each topic its own `##` heading. A file you have not changed since
16
29
  `forgeqe init` copied it is left out: the templates' examples never reach an agent.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capagents/forgeqe",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "description": "ForgeQE: a browser agent CLI that runs goals and test cases in local Chrome or Chromium, or BrowserStack and TestMu AI/LambdaTest when configured, and turns passing runs into tests in your repo",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
package/prompts/brain.md CHANGED
@@ -461,6 +461,7 @@ For REST, GraphQL, SOAP, and gRPC:
461
461
  - To run API tests that are already in the repository, you MUST use find_tests, then run_tests. You MUST NOT run them with the shell.
462
462
  - Before api_new_set or api_add_calls, and whenever a set id is not in the conversation (a conversation picked up again), you MUST look for the API and the call with api_find_calls and reuse what is there. You MUST NOT make a second API or call with the same method and path; when you cannot tell which API is meant, ask the user.
463
463
  - To send API calls found in the repository's code, read the code, then use api_new_set and api_add_calls. To make tests of them, use write_api_tests.
464
+ - To delete an API (a set, a folder on the API tests Workbench), you MUST use api_delete_set with its set id (api_find_calls finds it); ForgeQE asks the user to confirm. You MUST NOT open the Workbench in a browser to delete, rename or change an API. When api_delete_set cannot delete it, tell the user why and stop.
464
465
 
465
466
  ### Monitoring
466
467
  - The settings are under monitor: in forgeqe.yaml: checks (test case sources), every (the interval), replay (verify or trust), fail_after, remind_every, and alerts (teams with webhook_env, email with host, port, username_env, password_env, from, and to).
@@ -61,6 +61,13 @@ CDP_TIMEOUT = 5.0
61
61
  # While a browser dialog is open the page's scripts wait for the person's answer, and so does a call into the page: it is
62
62
  # waited for (up to this long) rather than given up after CDP_TIMEOUT.
63
63
  DIALOG_WAIT = 600.0
64
+ # Stop is taken as soon as it is asked, ahead of the page's events: what the recorder is doing then gets this long to
65
+ # finish, and is then given up, so a page that does not answer (a dialog open, a frame that hangs) never holds Stop.
66
+ STOP_GRACE = 1.5
67
+ # The model's look at the typed and checked values when the recording stops: the saving waits this long for it at most.
68
+ REVIEW_SECONDS = 30.0
69
+ # And the pages' last typing and the last step's picture are waited for this long at most.
70
+ STOP_FLUSH = 4.0
64
71
  # A step's picture of the page: taken this long after the step, once the page has answered it; at most this many.
65
72
  SHOT_SETTLE = 0.7
66
73
  MAX_SHOTS = 400
@@ -248,6 +255,10 @@ class RecordSession:
248
255
  kw: Dict[str, Any] = {"params": params} if params is not None else {}
249
256
  if sid:
250
257
  kw["session_id"] = sid
258
+ if self.stop_reason and self._dialogs:
259
+ # Stopped with a dialog open: a call into the page would only wait for it. Given up at once (each caller
260
+ # takes a failed call as no answer), so the browser closes now.
261
+ raise asyncio.TimeoutError()
251
262
  call = asyncio.ensure_future(fn(**kw))
252
263
  waited = 0.0
253
264
  while True:
@@ -256,8 +267,9 @@ class RecordSession:
256
267
  if done:
257
268
  return call.result() or {}
258
269
  waited += CDP_TIMEOUT
259
- # A dialog open now, or one that opened meanwhile: the page waits for the person, and the call with it.
260
- if (self._dialogs or self._dialog_count != seen) and waited < DIALOG_WAIT:
270
+ # A dialog open now, or one that opened meanwhile: the page waits for the person, and the call with it. Not once
271
+ # the tester stopped: the browser is closing, and nobody answers that dialog.
272
+ if (self._dialogs or self._dialog_count != seen) and waited < DIALOG_WAIT and not self.stop_reason:
261
273
  continue
262
274
  call.cancel()
263
275
  raise asyncio.TimeoutError()
@@ -280,6 +292,8 @@ class RecordSession:
280
292
  # When it happened: a click handled late (its page navigating) is still before the back that followed it.
281
293
  if isinstance(event, dict):
282
294
  event.setdefault("_at", time.monotonic())
295
+ if kind == "binding" and self._page_stop(event, session_id):
296
+ return
283
297
  self.queue.put_nowait((kind, event, session_id))
284
298
 
285
299
  return handler
@@ -421,7 +435,8 @@ class RecordSession:
421
435
  await self.send("Page.stopScreencast", {}, sid)
422
436
  if self.browser is not None and self.profile is None:
423
437
  try:
424
- self.profile = await asyncio.wait_for(browser_profile(self.browser, self.launch), timeout=8)
438
+ # A dialog left open holds the page's part of it: not waited for, so the window goes when the tester stops.
439
+ self.profile = await asyncio.wait_for(browser_profile(self.browser, self.launch), timeout=1.5 if self._dialogs else 8)
425
440
  except Exception:
426
441
  self.profile = {}
427
442
  # Nothing is sent to the page any more (the panel, a log line): it is going.
@@ -462,24 +477,51 @@ class RecordSession:
462
477
  item = await asyncio.wait_for(self.queue.get(), timeout=min(left, 1.0))
463
478
  except asyncio.TimeoutError:
464
479
  continue
465
- await self._handle(item)
466
- # Typing not yet reported (the tester stopped with the caret still in a field), in a frame too.
467
- for tab in list(self.pages):
468
- await self._frame_calls(tab, "__fqeRec.flush()")
469
- for sid, page in list(self.pages.items()):
470
- ctx = page.get("ctx")
471
- if ctx:
472
- try:
473
- await self.send("Runtime.evaluate", {"expression": "globalThis.__fqeRec && __fqeRec.flush()", "contextId": ctx}, sid)
474
- except Exception:
475
- pass
480
+ await self._handle_until_stop(item)
481
+ # Typing not yet reported (the tester stopped with the caret still in a field), in a frame too: as long as the
482
+ # pages answer within STOP_FLUSH, never longer.
483
+ async def flush() -> None:
484
+ for tab in list(self.pages):
485
+ await self._frame_calls(tab, "__fqeRec.flush()")
486
+ for sid, page in list(self.pages.items()):
487
+ ctx = page.get("ctx")
488
+ if ctx:
489
+ try:
490
+ await self.send("Runtime.evaluate", {"expression": "globalThis.__fqeRec && __fqeRec.flush()", "contextId": ctx}, sid)
491
+ except Exception:
492
+ pass
493
+
494
+ try:
495
+ await asyncio.wait_for(flush(), timeout=STOP_FLUSH)
496
+ except asyncio.TimeoutError:
497
+ logger.info("record: the pages did not report their last typing within %.0f s of the stop", STOP_FLUSH)
476
498
  stopping = self.stop_reason
477
499
  await self._drain(0.6, stopping=True)
478
500
  self.stop_reason = stopping
479
501
  # The last step's picture, now rather than after its pause.
480
502
  if self._shot_task and not self._shot_task.done():
481
503
  self._shot_task.cancel()
482
- await self.shoot()
504
+ with contextlib.suppress(asyncio.TimeoutError):
505
+ await asyncio.wait_for(self.shoot(), timeout=STOP_FLUSH)
506
+
507
+ async def _handle_until_stop(self, item: Any) -> None:
508
+ """
509
+ One event, as _handle does it; but once the tester stopped, what is still going (a call the page does not answer)
510
+ gets STOP_GRACE more and is then given up, so Stop never waits for the page.
511
+ """
512
+ task = asyncio.ensure_future(self._handle(item))
513
+ while not task.done():
514
+ if self.stop_reason:
515
+ done, _ = await asyncio.wait({task}, timeout=STOP_GRACE)
516
+ if not done:
517
+ task.cancel()
518
+ with contextlib.suppress(asyncio.CancelledError, Exception):
519
+ await task
520
+ logger.info("record: an event still being handled when the recording stopped was given up (%s)", item[0])
521
+ return
522
+ await asyncio.wait({task}, timeout=0.25)
523
+ with contextlib.suppress(asyncio.CancelledError):
524
+ task.result()
483
525
 
484
526
  async def _drain(self, seconds: float, stopping: bool = False) -> None:
485
527
  end = time.monotonic() + seconds
@@ -493,7 +535,7 @@ class RecordSession:
493
535
  return
494
536
  if stopping and item[0] == "cmd":
495
537
  continue
496
- await self._handle(item)
538
+ await self._handle_until_stop(item)
497
539
 
498
540
  async def _handle(self, item: Any) -> None:
499
541
  kind, event, sid = item
@@ -1294,6 +1336,39 @@ class RecordSession:
1294
1336
 
1295
1337
  # -- commands: from the Recorder panel, the page's key commands, and the terminal -----------------------------------
1296
1338
 
1339
+ def ask_stop(self, data: Dict[str, Any]) -> bool:
1340
+ """
1341
+ Stop, as soon as it is asked: called where the command arrives (stdin, the page's binding), never queued behind the
1342
+ page's events, so a page that keeps the recorder busy or waiting cannot hold it. False before the recording has
1343
+ begun (it is queued then, for the loop to take). A test case with expected results not checked yet warns once.
1344
+ """
1345
+ rec = self.rec
1346
+ if rec is None:
1347
+ return False
1348
+ if self.stop_reason:
1349
+ return True
1350
+ gaps = rec.case_gaps()
1351
+ if gaps and not data.get("force") and not self.gaps_warned:
1352
+ self.gaps_warned = True
1353
+ listed = "; ".join(f"step {g['n']} expects {g['expected']!r}" for g in gaps[:4]) + ("; …" if len(gaps) > 4 else "")
1354
+ self.log(f"No check yet for {listed}. Add one (pick the case step, then Check), or press Stop again to stop.", "warn")
1355
+ return True
1356
+ self.stop_reason = "stopped"
1357
+ return True
1358
+
1359
+ def _page_stop(self, event: Any, sid: Optional[str]) -> bool:
1360
+ """The page's Stop (the bar's button, the S key): taken at once, only from the recorder's own binding in a tab or frame it follows."""
1361
+ if not isinstance(event, dict) or event.get("name") != self.binding or not sid or (sid not in self.pages and sid not in self.frames):
1362
+ return False
1363
+ try:
1364
+ data = json.loads(event.get("payload") or "{}")
1365
+ except (TypeError, ValueError):
1366
+ return False
1367
+ if not isinstance(data, dict) or data.get("kind") != "command" or data.get("cmd") != "stop":
1368
+ return False
1369
+ return self.ask_stop({"force": data.get("force") is True})
1370
+
1371
+
1297
1372
  async def command(self, data: Dict[str, Any]) -> None:
1298
1373
  rec = self.rec
1299
1374
  if rec is None:
@@ -1301,13 +1376,7 @@ class RecordSession:
1301
1376
  cmd = str(data.get("cmd") or "")
1302
1377
  msg: Optional[str] = None
1303
1378
  if cmd == "stop":
1304
- gaps = rec.case_gaps()
1305
- if gaps and not data.get("force") and not self.gaps_warned:
1306
- self.gaps_warned = True
1307
- listed = "; ".join(f"step {g['n']} expects {g['expected']!r}" for g in gaps[:4]) + ("; …" if len(gaps) > 4 else "")
1308
- self.log(f"No check yet for {listed}. Add one (pick the case step, then Check), or press Stop again to stop.", "warn")
1309
- return
1310
- self.stop_reason = "stopped"
1379
+ self.ask_stop(data)
1311
1380
  return
1312
1381
  if cmd == "case_step":
1313
1382
  msg = rec.set_case_step(int(data.get("n") or 0))
@@ -1483,8 +1552,12 @@ class RecordSession:
1483
1552
  )
1484
1553
  user = "\n".join(f"{it['n']}. {it['what']} on {it['label']!r}: {it['value']!r}" for it in items[:40])
1485
1554
  try:
1486
- res = await self.llm.ainvoke([SystemMessage(content=system), UserMessage(content=user)], output_format=Values)
1555
+ # The tester is waiting for the recording to save: a model that is slow to answer is not waited for.
1556
+ res = await asyncio.wait_for(self.llm.ainvoke([SystemMessage(content=system), UserMessage(content=user)], output_format=Values), timeout=REVIEW_SECONDS)
1487
1557
  answers = res.completion.values if isinstance(res.completion, Values) else []
1558
+ except asyncio.TimeoutError:
1559
+ self.log(f"Live data was not reviewed: the model did not answer within {REVIEW_SECONDS:.0f} s; the values stay as recorded (change them in the review).", "warn")
1560
+ return
1488
1561
  except Exception as ex:
1489
1562
  self.log(f"Live data was not reviewed by the model ({type(ex).__name__}); the patterns ForgeQE found stand.", "warn")
1490
1563
  return
@@ -2149,6 +2222,9 @@ async def record_web(payload: Dict[str, Any], emit: Emit, commands: asyncio.Queu
2149
2222
  async def relay() -> None:
2150
2223
  while True:
2151
2224
  cmd = await commands.get()
2225
+ # Stop is taken at once, ahead of the page's events (ask_stop); the rest in their turn.
2226
+ if isinstance(cmd, dict) and cmd.get("cmd") == "stop" and s.ask_stop(cmd):
2227
+ continue
2152
2228
  s.queue.put_nowait(("cmd", cmd, None))
2153
2229
 
2154
2230
  relay_task = asyncio.ensure_future(relay())