@nifrajs/e2e 0.0.0-stage → 5.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/LICENSE +21 -0
- package/README.md +127 -2
- package/dist/agent.d.ts +119 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +312 -0
- package/dist/agent.js.map +1 -0
- package/dist/cache.d.ts +84 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +162 -0
- package/dist/cache.js.map +1 -0
- package/dist/decision.d.ts +54 -0
- package/dist/decision.d.ts.map +1 -0
- package/dist/decision.js +122 -0
- package/dist/decision.js.map +1 -0
- package/dist/engine.d.ts +75 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +13 -0
- package/dist/engine.js.map +1 -0
- package/dist/evidence.d.ts +14 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +49 -0
- package/dist/evidence.js.map +1 -0
- package/dist/expect.d.ts +28 -0
- package/dist/expect.d.ts.map +1 -0
- package/dist/expect.js +88 -0
- package/dist/expect.js.map +1 -0
- package/dist/fake.d.ts +35 -0
- package/dist/fake.d.ts.map +1 -0
- package/dist/fake.js +124 -0
- package/dist/fake.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/record.d.ts +3 -0
- package/dist/internal/record.d.ts.map +1 -0
- package/dist/internal/record.js +4 -0
- package/dist/internal/record.js.map +1 -0
- package/dist/locator.d.ts +53 -0
- package/dist/locator.d.ts.map +1 -0
- package/dist/locator.js +102 -0
- package/dist/locator.js.map +1 -0
- package/dist/params.d.ts +44 -0
- package/dist/params.d.ts.map +1 -0
- package/dist/params.js +93 -0
- package/dist/params.js.map +1 -0
- package/dist/playwright.d.ts +72 -0
- package/dist/playwright.d.ts.map +1 -0
- package/dist/playwright.js +165 -0
- package/dist/playwright.js.map +1 -0
- package/dist/replay.d.ts +34 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +105 -0
- package/dist/replay.js.map +1 -0
- package/dist/route.d.ts +7 -0
- package/dist/route.d.ts.map +1 -0
- package/dist/route.js +20 -0
- package/dist/route.js.map +1 -0
- package/dist/session.d.ts +62 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +98 -0
- package/dist/session.js.map +1 -0
- package/dist/snapshot.d.ts +8 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +44 -0
- package/dist/snapshot.js.map +1 -0
- package/package.json +73 -4
- package/src/agent.ts +525 -0
- package/src/cache.ts +229 -0
- package/src/decision.ts +152 -0
- package/src/engine.ts +92 -0
- package/src/evidence.ts +58 -0
- package/src/expect.ts +171 -0
- package/src/fake.ts +185 -0
- package/src/index.ts +64 -0
- package/src/internal/record.ts +5 -0
- package/src/locator.ts +157 -0
- package/src/params.ts +128 -0
- package/src/playwright.ts +237 -0
- package/src/replay.ts +153 -0
- package/src/route.ts +26 -0
- package/src/session.ts +178 -0
- package/src/snapshot.ts +46 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @nifrajs/e2e
|
|
2
|
+
|
|
3
|
+
## 5.14.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ec5ac0d: No behavior change for consumers. Tooling moves to Biome 2.6; `@nifrajs/web` now throws a named error, not a bare TypeError, if an error render is asked for an `_error` module its manifest does not list.
|
|
8
|
+
- Updated dependencies [b87c76c]
|
|
9
|
+
- Updated dependencies [afba797]
|
|
10
|
+
- Updated dependencies [b8e98c0]
|
|
11
|
+
- Updated dependencies [b1ae79d]
|
|
12
|
+
- Updated dependencies [ae57f24]
|
|
13
|
+
- @nifrajs/core@5.14.0
|
|
14
|
+
- @nifrajs/node@5.14.0
|
|
15
|
+
- @nifrajs/testing@5.14.0
|
|
16
|
+
|
|
17
|
+
## 5.13.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- 2e7a043: Add `@nifrajs/e2e`: browser end-to-end tests for Nifra apps. `e2e(app)` serves the app on an ephemeral port and drives it through a browser engine (Playwright by default, an in-memory engine at `@nifrajs/e2e/fake`). `open()` takes only paths the app declares and requires their `:params`. Locators (`getByRole`, `getByLabel`, `getByText`, `getByTestId`, `filter`) and retrying assertions (`toBeVisible`, `toHaveText`, `toHaveCount`, `toHaveURL` and more, each with `.not`) run in any test runner. On a page that loads a module script, actions wait for `data-nifra-hydrated`. `t.agent` adds goal-driven steps over a model you supply: `act`, `assert`, `waitFor` and `extract`, with call, action and time budgets, `Secret` params the model never reads, and a pruned page outline. A replay cache makes the second run of an `act` model-free: it is written only after a later check passes, replays only when each control still matches exactly, and hands off to the model from where it stopped. Modes are `read-write`, `read-only`, `strict` and `off`; `unique()` keeps run-varying data from missing.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [591f74e]
|
|
26
|
+
- Updated dependencies [b427443]
|
|
27
|
+
- Updated dependencies [3b39e39]
|
|
28
|
+
- Updated dependencies [16023e9]
|
|
29
|
+
- Updated dependencies [d75437b]
|
|
30
|
+
- Updated dependencies [9c8a464]
|
|
31
|
+
- @nifrajs/core@5.13.0
|
|
32
|
+
- @nifrajs/node@5.13.0
|
|
33
|
+
- @nifrajs/testing@5.13.0
|
|
34
|
+
|
|
35
|
+
## 5.12.1
|
|
36
|
+
|
|
37
|
+
- Initial release: browser end-to-end tests for Nifra apps, with typed paths, locators, retrying assertions, agent steps and a replay cache.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nifra Authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,128 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nifrajs/e2e
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Browser end-to-end tests for Nifra apps. It serves your app on an ephemeral port, drives it through
|
|
4
|
+
a browser engine, and gives you locators and retrying assertions. The route table types `open()`.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { test } from "bun:test"
|
|
8
|
+
import { e2e, expect } from "@nifrajs/e2e"
|
|
9
|
+
import { app } from "../src/app"
|
|
10
|
+
|
|
11
|
+
test("a user page renders", async () => {
|
|
12
|
+
await using t = await e2e(app)
|
|
13
|
+
await t.open("/users/:id", { params: { id: 42 } }) // a path or param the app lacks fails typecheck
|
|
14
|
+
await expect(t.screen.getByRole("heading")).toHaveText("User 42")
|
|
15
|
+
await t.screen.getByLabel("Nickname").fill("grace")
|
|
16
|
+
await expect(t).toHaveURL("/users/42")
|
|
17
|
+
})
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`await using` closes the browser and the server at scope exit; `t.close()` does the same by hand.
|
|
21
|
+
|
|
22
|
+
## Locators and assertions
|
|
23
|
+
|
|
24
|
+
`getByRole(role, name)`, `getByLabel`, `getByText`, `getByTestId`, `.filter({ hasText })`, and chaining
|
|
25
|
+
to scope into a row. Names and text match as a case-insensitive substring; pass `{ exact: true }` for
|
|
26
|
+
a full match. Actions: `tap`, `fill`, `press`. Assertions retry until they pass or `assertionTimeout`
|
|
27
|
+
(default 5000 ms) runs out: `toBeVisible`, `toBeHidden`, `toHaveText`, `toContainText`, `toHaveCount`,
|
|
28
|
+
`toHaveValue`, `toHaveURL`, each with `.not`.
|
|
29
|
+
|
|
30
|
+
A locator that matches several elements is an error for `tap`, `fill`, `press` and the one-element
|
|
31
|
+
assertions (`LOCATOR_AMBIGUOUS`, or a failed assertion naming the count).
|
|
32
|
+
|
|
33
|
+
## Hydration
|
|
34
|
+
|
|
35
|
+
On a page that loads a module script, the Playwright engine waits for `data-nifra-hydrated` on `<html>`
|
|
36
|
+
after each navigation and before each action, so a tap does not land before its handler exists. Pass
|
|
37
|
+
`hydration: "off"` for a page that is not a hydrated Nifra page.
|
|
38
|
+
|
|
39
|
+
## Signed-in sessions
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
const { client, cookies } = testSession<typeof app>(app)
|
|
43
|
+
await client.auth.login.post(credentials)
|
|
44
|
+
await using t = await e2e(app, { cookies })
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Agent steps
|
|
48
|
+
|
|
49
|
+
Say what you want in words; a model you supply drives the page. Locators and agent steps mix in one test.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
await using t = await e2e(app, { model, agentContext: "Acme calls a plan a seat" })
|
|
53
|
+
await t.open("/login")
|
|
54
|
+
await t.agent.act("sign in as {email} with {password}", {
|
|
55
|
+
params: { email: "ada@example.test", password: new Secret("password", process.env.PASSWORD ?? "") },
|
|
56
|
+
})
|
|
57
|
+
await t.agent.assert("the dashboard greets Ada")
|
|
58
|
+
await t.agent.waitFor("the export is finished", { timeout: 60_000 })
|
|
59
|
+
const plan = await t.agent.extract("the current plan", { schema: PlanSchema })
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`model` is `{ decide(request) }`: the request carries the goal, a pruned outline of the page and what was
|
|
63
|
+
already tried, and the answer is `{ kind: "tap" | "fill" | "press" | "goto" | "done" | "fail", ... }` for
|
|
64
|
+
`act`, `{ pass, reason }` for `assert` and `waitFor`, and `{ value }` for `extract`. Nothing here names a
|
|
65
|
+
vendor; you own the credentials, the retries and the cost. Without `model`, agent steps reject with
|
|
66
|
+
`MODEL_MISSING` and locator tests are unaffected.
|
|
67
|
+
|
|
68
|
+
- **Budgets.** `act` stops at `maxModelCalls` (12), `maxActions` (25) or `timeout` (120000 ms), each a
|
|
69
|
+
distinct error. The time limit is checked between decisions; it does not interrupt a `decide()` call
|
|
70
|
+
that never resolves, so enforce a deadline inside `decide` (the request carries a `signal`). A tap that finds no element or several goes back to the model, which can retry with `nth`.
|
|
71
|
+
- **Secrets.** A `Secret` is typed into the page by name. The model sees `{password}`, never the value,
|
|
72
|
+
and every snapshot a session sends has any secret it was given replaced by its placeholder.
|
|
73
|
+
- **Same origin.** `goto` takes an app path only; anything else is refused and reported to the model.
|
|
74
|
+
- **`extract`** validates the answer with your Standard Schema (`EXTRACT_INVALID` on a mismatch).
|
|
75
|
+
- **`waitFor`** asks the model again only when the page outline changed.
|
|
76
|
+
|
|
77
|
+
## Replay cache
|
|
78
|
+
|
|
79
|
+
The first run of an `act` asks the model; the next runs replay what it did, with no model call.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
await using t = await e2e(app, { model, cache: { testId: "member upgrades to Pro" } })
|
|
83
|
+
await t.open("/settings/billing")
|
|
84
|
+
await t.agent.act("upgrade the workspace to the {plan} plan", { params: { plan: "Pro" } })
|
|
85
|
+
await expect(t.screen.getByRole("status")).toHaveText("Pro") // a later check that passes saves the recording
|
|
86
|
+
console.log(formatReport(t.agent.report())) // Cache: 1 replayed - 0 handed off - 0 missed (0 model calls)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- **Written only after a later check passes.** A locator `expect` or `agent.assert`/`waitFor` that passes
|
|
90
|
+
saves what the `act`s before it recorded. One that fails deletes them. A test that ends with no check
|
|
91
|
+
records nothing.
|
|
92
|
+
- **Replay** needs the same start route, finds each control by the role, name, label, text or test id
|
|
93
|
+
it had, and requires it to match exactly as often as it did. It never taps a near miss. It then checks
|
|
94
|
+
the end route and the controls and headings that appeared or went away.
|
|
95
|
+
- **Hand-off.** When a replay stops (`target-not-found`, `ambiguous`, `end-mismatch`, `action-uncertain`,
|
|
96
|
+
`route-mismatch`) the actions it already did stay done, and the model finishes the goal from the current
|
|
97
|
+
page. `ActRequest.handoff` carries the reason and how many actions to leave alone. A passing check
|
|
98
|
+
re-records the repaired steps. If the goal then fails, the recording is deleted.
|
|
99
|
+
- **Modes** (`cache.mode`): `read-write` (default; `read-only` when `CI` is set), `read-only` (replays and
|
|
100
|
+
hands off, never writes or deletes), `strict` (replay only: a stale recording is `REPLAY_STALE`, a
|
|
101
|
+
missing one `REPLAY_MISSING`), `off`.
|
|
102
|
+
- **The key** is the test (`cache.testId`: pass it), the goal text, the params, `agentContext`, and
|
|
103
|
+
`cache.appIdentity`. Wrap run-varying data in `unique(value)` so a new value does not miss; it is
|
|
104
|
+
typed again on replay. A `Secret` is stored by name only, never by value.
|
|
105
|
+
- **Where.** `.nifra/e2e-cache/<hash>.json` under the working directory (`cache.dir`), small and meant to
|
|
106
|
+
be committed. `cache.store` swaps in your own store; `memoryCacheStore()` is one for tests. A store
|
|
107
|
+
that refuses a write is counted in the cache, not thrown. `cache: false` turns the whole thing off.
|
|
108
|
+
- Replay needs no model: in CI `model` can be left out and a stale recording then fails with
|
|
109
|
+
`MODEL_MISSING`. `assert`, `waitFor` and `extract` always ask the model.
|
|
110
|
+
|
|
111
|
+
## Engines
|
|
112
|
+
|
|
113
|
+
`e2e()` uses the Playwright engine by default; install `playwright` yourself (optional peer). The engine
|
|
114
|
+
is a six-method interface (`goto`, `url`, `resolve`, `act`, `snapshot`, `close`), so anything else can plug in with
|
|
115
|
+
`e2e(app, { engine })`. `@nifrajs/e2e/fake` is an in-memory engine with the same locator semantics, for
|
|
116
|
+
testing code built on this package without a browser.
|
|
117
|
+
|
|
118
|
+
## Not included yet
|
|
119
|
+
|
|
120
|
+
Token counts (the model port returns decisions, not usage) and a test runner. Use `bun:test` or Vitest.
|
|
121
|
+
|
|
122
|
+
## For AI agents
|
|
123
|
+
|
|
124
|
+
Start with [`LLM.md`](./LLM.md) - this package's contract card (the exports you call + its footguns),
|
|
125
|
+
one cheap read instead of the whole corpus. For the wider framework: the repo's
|
|
126
|
+
[`AGENTS.md`](../../AGENTS.md) is the copy-paste quick reference, and
|
|
127
|
+
[`llms-full.txt`](../../llms-full.txt) is the full machine-readable corpus. Run `nifra check` as the
|
|
128
|
+
done-gate, or `nifra mcp` to give the agent live project tools.
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type InferOutput, type StandardSchemaV1 } from "@nifrajs/core/schema";
|
|
2
|
+
import { type Cache } from "./cache.js";
|
|
3
|
+
import { type PerformedDecision } from "./decision.js";
|
|
4
|
+
import { type Clock, type Engine } from "./engine.js";
|
|
5
|
+
import { type Params } from "./params.js";
|
|
6
|
+
import { type StopReason } from "./replay.js";
|
|
7
|
+
/** One thing the agent tried inside a goal, and whether the page took it. */
|
|
8
|
+
export interface ActionRecord {
|
|
9
|
+
readonly action: PerformedDecision;
|
|
10
|
+
readonly ok: boolean;
|
|
11
|
+
readonly error?: string;
|
|
12
|
+
}
|
|
13
|
+
/** A recorded run that stopped partway: its actions are already done, so do not redo them. */
|
|
14
|
+
export interface HandOff {
|
|
15
|
+
readonly reason: StopReason;
|
|
16
|
+
readonly detail: string;
|
|
17
|
+
/** How many actions at the start of `history` the replay performed. */
|
|
18
|
+
readonly performed: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ActRequest {
|
|
21
|
+
readonly kind: "act";
|
|
22
|
+
readonly goal: string;
|
|
23
|
+
readonly context?: string;
|
|
24
|
+
readonly snapshot: string;
|
|
25
|
+
readonly history: readonly ActionRecord[];
|
|
26
|
+
/** Names of params whose values stay out of the goal and the snapshot; write `{name}` to type one. */
|
|
27
|
+
readonly secrets: readonly string[];
|
|
28
|
+
readonly modelCallsLeft: number;
|
|
29
|
+
readonly actionsLeft: number;
|
|
30
|
+
readonly handoff: HandOff | undefined;
|
|
31
|
+
readonly signal: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
export interface JudgeRequest {
|
|
34
|
+
readonly kind: "assert" | "waitFor";
|
|
35
|
+
readonly statement: string;
|
|
36
|
+
readonly context?: string;
|
|
37
|
+
readonly snapshot: string;
|
|
38
|
+
readonly secrets: readonly string[];
|
|
39
|
+
readonly signal: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
export interface ExtractRequest {
|
|
42
|
+
readonly kind: "extract";
|
|
43
|
+
readonly prompt: string;
|
|
44
|
+
readonly context?: string;
|
|
45
|
+
readonly snapshot: string;
|
|
46
|
+
readonly secrets: readonly string[];
|
|
47
|
+
/** The JSON Schema the caller supplied, to put in the prompt; the answer is validated against the real schema. */
|
|
48
|
+
readonly jsonSchema?: unknown;
|
|
49
|
+
readonly signal: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
export type ModelRequest = ActRequest | JudgeRequest | ExtractRequest;
|
|
52
|
+
/**
|
|
53
|
+
* The seam to a model. Answer an `act` request with a decision (`{ kind: "tap", target }`, `fill`,
|
|
54
|
+
* `press`, `goto`, `done` or `fail`), an `assert` or `waitFor` with `{ pass, reason }`, and an
|
|
55
|
+
* `extract` with `{ value }`. The answer is unknown until the runner has parsed it. Nothing here
|
|
56
|
+
* names a vendor; the caller owns credentials, retries and cost.
|
|
57
|
+
*/
|
|
58
|
+
export interface E2EModel {
|
|
59
|
+
decide(request: ModelRequest): unknown | PromiseLike<unknown>;
|
|
60
|
+
}
|
|
61
|
+
export interface StepOptions {
|
|
62
|
+
readonly params?: Params;
|
|
63
|
+
readonly signal?: AbortSignal;
|
|
64
|
+
}
|
|
65
|
+
export interface ActOptions extends StepOptions {
|
|
66
|
+
/** Model decisions one goal may use. Default 12. */
|
|
67
|
+
readonly maxModelCalls?: number;
|
|
68
|
+
/** Page actions one goal may take, failed ones included. Default 25. */
|
|
69
|
+
readonly maxActions?: number;
|
|
70
|
+
/** ms for the whole goal on the session clock. Default 120000. */
|
|
71
|
+
readonly timeout?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface WaitForOptions extends StepOptions {
|
|
74
|
+
/** ms to wait for the statement to hold. Default 30000. */
|
|
75
|
+
readonly timeout?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface ExtractOptions<S extends StandardSchemaV1> extends StepOptions {
|
|
78
|
+
readonly schema: S;
|
|
79
|
+
readonly jsonSchema?: unknown;
|
|
80
|
+
}
|
|
81
|
+
export interface ActResult {
|
|
82
|
+
/** `replay`: no model call. `handoff`: a recording stopped and the model finished the goal. */
|
|
83
|
+
readonly source: "model" | "replay" | "handoff";
|
|
84
|
+
readonly modelCalls: number;
|
|
85
|
+
/** The actions the page accepted, in order. */
|
|
86
|
+
readonly actions: readonly PerformedDecision[];
|
|
87
|
+
readonly summary?: string;
|
|
88
|
+
}
|
|
89
|
+
/** What the replay cache did for this session, and how many model calls it still took. */
|
|
90
|
+
export interface AgentReport {
|
|
91
|
+
readonly replayed: number;
|
|
92
|
+
readonly handedOff: number;
|
|
93
|
+
readonly missed: number;
|
|
94
|
+
readonly modelCalls: number;
|
|
95
|
+
}
|
|
96
|
+
export declare function formatReport(report: AgentReport): string;
|
|
97
|
+
export interface Agent {
|
|
98
|
+
report(): AgentReport;
|
|
99
|
+
act(goal: string, options?: ActOptions): Promise<ActResult>;
|
|
100
|
+
assert(statement: string, options?: StepOptions): Promise<void>;
|
|
101
|
+
waitFor(statement: string, options?: WaitForOptions): Promise<void>;
|
|
102
|
+
extract<S extends StandardSchemaV1>(prompt: string, options: ExtractOptions<S>): Promise<InferOutput<S>>;
|
|
103
|
+
}
|
|
104
|
+
export interface AgentDeps {
|
|
105
|
+
readonly engine: Engine;
|
|
106
|
+
readonly clock: Clock;
|
|
107
|
+
readonly pollInterval: number;
|
|
108
|
+
readonly actionTimeout: number;
|
|
109
|
+
readonly model: E2EModel | undefined;
|
|
110
|
+
readonly context: string | undefined;
|
|
111
|
+
readonly snapshotChars: number;
|
|
112
|
+
/** Origin of the app under test. */
|
|
113
|
+
readonly origin: string;
|
|
114
|
+
readonly cache: Cache | undefined;
|
|
115
|
+
/** Opens a same-origin path; refuses any other. */
|
|
116
|
+
readonly navigate: (path: string) => Promise<void>;
|
|
117
|
+
}
|
|
118
|
+
export declare function createAgent(deps: AgentDeps): Agent;
|
|
119
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,gBAAgB,EAAoB,MAAM,sBAAsB,CAAA;AAChG,OAAO,EAAE,KAAK,KAAK,EAAqD,MAAM,YAAY,CAAA;AAC1F,OAAO,EAEL,KAAK,iBAAiB,EAKvB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,KAAK,EAAY,KAAK,MAAM,EAAE,MAAM,aAAa,CAAA;AAE/D,OAAO,EAIL,KAAK,MAAM,EAIZ,MAAM,aAAa,CAAA;AACpB,OAAO,EAAe,KAAK,UAAU,EAA4B,MAAM,aAAa,CAAA;AAIpF,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;IAClC,QAAQ,CA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,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,oCAAoC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAA;IACjC,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACnD;AA+BD,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK,CAkVlD"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { validateStandard } from "@nifrajs/core/schema";
|
|
2
|
+
import { performedOf } from "./cache.js";
|
|
3
|
+
import { parseActDecision, parseExtraction, parseVerdict, targetSelector, } from "./decision.js";
|
|
4
|
+
import { E2EError } from "./engine.js";
|
|
5
|
+
import { diffEvidence } from "./evidence.js";
|
|
6
|
+
import { forModel, forPage, redactSecrets, Secret, templatize, } from "./params.js";
|
|
7
|
+
import { replayEntry, visibleCount, withoutNth } from "./replay.js";
|
|
8
|
+
import { normalizeRoute } from "./route.js";
|
|
9
|
+
import { pruneSnapshot } from "./snapshot.js";
|
|
10
|
+
export function formatReport(report) {
|
|
11
|
+
return `Cache: ${report.replayed} replayed - ${report.handedOff} handed off - ${report.missed} missed (${report.modelCalls} model calls)`;
|
|
12
|
+
}
|
|
13
|
+
const NEVER = new AbortController().signal;
|
|
14
|
+
function withContext(context) {
|
|
15
|
+
return context === undefined ? {} : { context };
|
|
16
|
+
}
|
|
17
|
+
function entryOf(goal, startRoute, actions, before, after, route, params) {
|
|
18
|
+
const changes = diffEvidence(before, after);
|
|
19
|
+
return {
|
|
20
|
+
version: 1,
|
|
21
|
+
instruction: goal,
|
|
22
|
+
startRoute,
|
|
23
|
+
actions,
|
|
24
|
+
end: {
|
|
25
|
+
route,
|
|
26
|
+
appeared: changes.appeared.map((line) => templatize(line, params)),
|
|
27
|
+
disappeared: changes.disappeared.map((line) => templatize(line, params)),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function createAgent(deps) {
|
|
32
|
+
const { engine, clock, cache } = deps;
|
|
33
|
+
const stats = { replayed: 0, handedOff: 0, missed: 0, modelCalls: 0 };
|
|
34
|
+
const requireModel = () => {
|
|
35
|
+
if (deps.model === undefined) {
|
|
36
|
+
throw new E2EError("MODEL_MISSING", "this step needs a model: pass `model` to e2e()");
|
|
37
|
+
}
|
|
38
|
+
return deps.model;
|
|
39
|
+
};
|
|
40
|
+
const ask = async (model, request) => {
|
|
41
|
+
stats.modelCalls += 1;
|
|
42
|
+
return model.decide(request);
|
|
43
|
+
};
|
|
44
|
+
const vault = [];
|
|
45
|
+
const remember = (params) => {
|
|
46
|
+
for (const [name, param] of Object.entries(params)) {
|
|
47
|
+
if (!(param instanceof Secret))
|
|
48
|
+
continue;
|
|
49
|
+
const known = vault.some(([, held]) => Secret.reveal(held) === Secret.reveal(param));
|
|
50
|
+
if (!known)
|
|
51
|
+
vault.push([name, param]);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const scrub = (text) => redactSecrets(text, vault);
|
|
55
|
+
const observe = async () => {
|
|
56
|
+
const raw = scrub(await engine.snapshot());
|
|
57
|
+
return { raw, shown: pruneSnapshot(raw, deps.snapshotChars) };
|
|
58
|
+
};
|
|
59
|
+
const look = async () => (await observe()).shown;
|
|
60
|
+
const perform = async (decision, params, recording) => {
|
|
61
|
+
try {
|
|
62
|
+
if (decision.kind === "goto") {
|
|
63
|
+
await deps.navigate(decision.path);
|
|
64
|
+
return {
|
|
65
|
+
record: { action: decision, ok: true },
|
|
66
|
+
recorded: recording
|
|
67
|
+
? { kind: "goto", path: templatize(decision.path, params) }
|
|
68
|
+
: undefined,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const selector = targetSelector(decision.target);
|
|
72
|
+
const matches = recording ? await visibleCount(engine, withoutNth(selector)) : 1;
|
|
73
|
+
let recorded;
|
|
74
|
+
if (decision.kind === "tap") {
|
|
75
|
+
await engine.act(selector, { kind: "tap" }, deps.actionTimeout);
|
|
76
|
+
recorded = { kind: "tap", target: decision.target, matches };
|
|
77
|
+
}
|
|
78
|
+
else if (decision.kind === "fill") {
|
|
79
|
+
const value = forPage(decision.value, params);
|
|
80
|
+
await engine.act(selector, { kind: "fill", value }, deps.actionTimeout);
|
|
81
|
+
recorded = {
|
|
82
|
+
kind: "fill",
|
|
83
|
+
target: decision.target,
|
|
84
|
+
matches,
|
|
85
|
+
value: templatize(decision.value, params),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
await engine.act(selector, { kind: "press", key: decision.key }, deps.actionTimeout);
|
|
90
|
+
recorded = { kind: "press", target: decision.target, matches, key: decision.key };
|
|
91
|
+
}
|
|
92
|
+
return { record: { action: decision, ok: true }, recorded: recording ? recorded : undefined };
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error instanceof E2EError || error instanceof TypeError) {
|
|
96
|
+
return {
|
|
97
|
+
record: { action: decision, ok: false, error: scrub(error.message) },
|
|
98
|
+
recorded: undefined,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
return {
|
|
105
|
+
report: () => ({ ...stats }),
|
|
106
|
+
async act(goal, options = {}) {
|
|
107
|
+
const params = options.params ?? {};
|
|
108
|
+
remember(params);
|
|
109
|
+
const { text, secrets } = forModel(goal, params);
|
|
110
|
+
const maxCalls = options.maxModelCalls ?? 12;
|
|
111
|
+
const maxActions = options.maxActions ?? 25;
|
|
112
|
+
const deadline = clock.now() + (options.timeout ?? 120_000);
|
|
113
|
+
const recording = cache?.canWrite === true;
|
|
114
|
+
const key = cache === undefined || cache.mode === "off"
|
|
115
|
+
? undefined
|
|
116
|
+
: cache.key(goal, params, deps.context);
|
|
117
|
+
const startRoute = normalizeRoute(await engine.url(), deps.origin);
|
|
118
|
+
const before = recording ? (await observe()).raw : "";
|
|
119
|
+
const history = [];
|
|
120
|
+
const taken = [];
|
|
121
|
+
let handoff;
|
|
122
|
+
if (cache !== undefined && key !== undefined) {
|
|
123
|
+
const entry = await cache.read(key);
|
|
124
|
+
if (entry === undefined) {
|
|
125
|
+
if (cache.mode === "strict") {
|
|
126
|
+
throw new E2EError("REPLAY_MISSING", `goal "${text}" has no recording and the cache is strict`);
|
|
127
|
+
}
|
|
128
|
+
stats.missed += 1;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const outcome = await replayEntry({ ...deps, observe: async () => (await observe()).raw }, entry, params);
|
|
132
|
+
if (outcome.ok) {
|
|
133
|
+
stats.replayed += 1;
|
|
134
|
+
cache.replayed(key);
|
|
135
|
+
return { source: "replay", modelCalls: 0, actions: entry.actions.map(performedOf) };
|
|
136
|
+
}
|
|
137
|
+
if (cache.mode === "strict") {
|
|
138
|
+
throw new E2EError("REPLAY_STALE", `goal "${text}" no longer replays (${outcome.reason}): ${outcome.detail}`);
|
|
139
|
+
}
|
|
140
|
+
stats.handedOff += 1;
|
|
141
|
+
handoff = {
|
|
142
|
+
reason: outcome.reason,
|
|
143
|
+
detail: scrub(outcome.detail),
|
|
144
|
+
performed: outcome.performed.length,
|
|
145
|
+
};
|
|
146
|
+
for (const action of outcome.performed) {
|
|
147
|
+
taken.push(action);
|
|
148
|
+
history.push({ action: performedOf(action), ok: true });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const runGoal = async () => {
|
|
153
|
+
let calls = 0;
|
|
154
|
+
for (;;) {
|
|
155
|
+
if (clock.now() >= deadline) {
|
|
156
|
+
throw new E2EError("STEP_TIMEOUT", `goal "${text}" ran past its time limit`);
|
|
157
|
+
}
|
|
158
|
+
if (calls >= maxCalls) {
|
|
159
|
+
throw new E2EError("STEP_BUDGET_EXCEEDED", `goal "${text}" used its ${maxCalls} model calls`);
|
|
160
|
+
}
|
|
161
|
+
const model = requireModel();
|
|
162
|
+
const seen = await observe();
|
|
163
|
+
calls += 1;
|
|
164
|
+
const raw = await ask(model, {
|
|
165
|
+
kind: "act",
|
|
166
|
+
goal: text,
|
|
167
|
+
...withContext(deps.context),
|
|
168
|
+
snapshot: seen.shown,
|
|
169
|
+
history,
|
|
170
|
+
secrets,
|
|
171
|
+
modelCallsLeft: maxCalls - calls,
|
|
172
|
+
actionsLeft: maxActions - history.length,
|
|
173
|
+
handoff,
|
|
174
|
+
signal: options.signal ?? NEVER,
|
|
175
|
+
});
|
|
176
|
+
const parsed = parseActDecision(raw);
|
|
177
|
+
if (!parsed.ok) {
|
|
178
|
+
throw new E2EError("MODEL_INVALID", `the model's decision was refused: ${parsed.reason}`);
|
|
179
|
+
}
|
|
180
|
+
const decision = parsed.value;
|
|
181
|
+
if (decision.kind === "fail") {
|
|
182
|
+
throw new E2EError("STEP_FAILED", `goal "${text}" failed: ${decision.reason}`);
|
|
183
|
+
}
|
|
184
|
+
if (decision.kind === "done") {
|
|
185
|
+
if (recording && cache !== undefined && key !== undefined && taken.length > 0) {
|
|
186
|
+
cache.stage(key, entryOf(goal, startRoute, taken, before, seen.raw, normalizeRoute(await engine.url(), deps.origin), params));
|
|
187
|
+
}
|
|
188
|
+
const result = {
|
|
189
|
+
source: handoff === undefined ? "model" : "handoff",
|
|
190
|
+
modelCalls: calls,
|
|
191
|
+
actions: history.filter((entry) => entry.ok).map((entry) => entry.action),
|
|
192
|
+
};
|
|
193
|
+
if (decision.summary !== undefined)
|
|
194
|
+
result.summary = decision.summary;
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
if (history.length >= maxActions) {
|
|
198
|
+
throw new E2EError("STEP_BUDGET_EXCEEDED", `goal "${text}" used its ${maxActions} actions`);
|
|
199
|
+
}
|
|
200
|
+
const step = await perform(decision, params, recording);
|
|
201
|
+
history.push(step.record);
|
|
202
|
+
if (step.recorded !== undefined)
|
|
203
|
+
taken.push(step.recorded);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
try {
|
|
207
|
+
return await runGoal();
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
const missingModel = error instanceof E2EError && error.code === "MODEL_MISSING";
|
|
211
|
+
if (handoff !== undefined && !missingModel && cache !== undefined && key !== undefined) {
|
|
212
|
+
await cache.discard(key);
|
|
213
|
+
}
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
async assert(statement, options = {}) {
|
|
218
|
+
const model = requireModel();
|
|
219
|
+
const params = options.params ?? {};
|
|
220
|
+
remember(params);
|
|
221
|
+
const { text, secrets } = forModel(statement, params);
|
|
222
|
+
const raw = await ask(model, {
|
|
223
|
+
kind: "assert",
|
|
224
|
+
statement: text,
|
|
225
|
+
...withContext(deps.context),
|
|
226
|
+
snapshot: await look(),
|
|
227
|
+
secrets,
|
|
228
|
+
signal: options.signal ?? NEVER,
|
|
229
|
+
});
|
|
230
|
+
const verdict = parseVerdict(raw);
|
|
231
|
+
if (!verdict.ok) {
|
|
232
|
+
throw new E2EError("MODEL_INVALID", `the model's verdict was refused: ${verdict.reason}`);
|
|
233
|
+
}
|
|
234
|
+
if (verdict.value.pass === true) {
|
|
235
|
+
await cache?.onCheck(true);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const reason = verdict.value.reason === "" ? "" : `: ${verdict.value.reason}`;
|
|
239
|
+
if (verdict.value.pass === "inconclusive") {
|
|
240
|
+
throw new E2EError("ASSERTION_INCONCLUSIVE", `could not tell whether "${text}"${reason}`);
|
|
241
|
+
}
|
|
242
|
+
await cache?.onCheck(false);
|
|
243
|
+
throw new E2EError("ASSERTION_FAILED", `"${text}" does not hold${reason}`);
|
|
244
|
+
},
|
|
245
|
+
async waitFor(statement, options = {}) {
|
|
246
|
+
const model = requireModel();
|
|
247
|
+
const params = options.params ?? {};
|
|
248
|
+
remember(params);
|
|
249
|
+
const { text, secrets } = forModel(statement, params);
|
|
250
|
+
const timeout = options.timeout ?? 30_000;
|
|
251
|
+
const deadline = clock.now() + timeout;
|
|
252
|
+
let seen;
|
|
253
|
+
let lastReason = "";
|
|
254
|
+
for (;;) {
|
|
255
|
+
const snapshot = await look();
|
|
256
|
+
if (snapshot !== seen) {
|
|
257
|
+
seen = snapshot;
|
|
258
|
+
const raw = await ask(model, {
|
|
259
|
+
kind: "waitFor",
|
|
260
|
+
statement: text,
|
|
261
|
+
...withContext(deps.context),
|
|
262
|
+
snapshot,
|
|
263
|
+
secrets,
|
|
264
|
+
signal: options.signal ?? NEVER,
|
|
265
|
+
});
|
|
266
|
+
const verdict = parseVerdict(raw);
|
|
267
|
+
if (!verdict.ok) {
|
|
268
|
+
throw new E2EError("MODEL_INVALID", `the model's verdict was refused: ${verdict.reason}`);
|
|
269
|
+
}
|
|
270
|
+
if (verdict.value.pass === true) {
|
|
271
|
+
await cache?.onCheck(true);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
lastReason = verdict.value.reason;
|
|
275
|
+
}
|
|
276
|
+
const remaining = deadline - clock.now();
|
|
277
|
+
if (remaining <= 0) {
|
|
278
|
+
await cache?.onCheck(false);
|
|
279
|
+
const reason = lastReason === "" ? "" : `: ${lastReason}`;
|
|
280
|
+
throw new E2EError("WAIT_TIMEOUT", `"${text}" did not hold within ${timeout} ms${reason}`);
|
|
281
|
+
}
|
|
282
|
+
await clock.sleep(Math.min(deps.pollInterval, remaining));
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
async extract(prompt, options) {
|
|
286
|
+
const model = requireModel();
|
|
287
|
+
const params = options.params ?? {};
|
|
288
|
+
remember(params);
|
|
289
|
+
const { text, secrets } = forModel(prompt, params);
|
|
290
|
+
const raw = await ask(model, {
|
|
291
|
+
kind: "extract",
|
|
292
|
+
prompt: text,
|
|
293
|
+
...withContext(deps.context),
|
|
294
|
+
snapshot: await look(),
|
|
295
|
+
secrets,
|
|
296
|
+
...(options.jsonSchema === undefined ? {} : { jsonSchema: options.jsonSchema }),
|
|
297
|
+
signal: options.signal ?? NEVER,
|
|
298
|
+
});
|
|
299
|
+
const extraction = parseExtraction(raw);
|
|
300
|
+
if (!extraction.ok) {
|
|
301
|
+
throw new E2EError("MODEL_INVALID", `the model's answer was refused: ${extraction.reason}`);
|
|
302
|
+
}
|
|
303
|
+
const checked = await validateStandard(options.schema, extraction.value);
|
|
304
|
+
if (!checked.ok) {
|
|
305
|
+
const issues = checked.issues.map((issue) => issue.message).join("; ");
|
|
306
|
+
throw new E2EError("EXTRACT_INVALID", `the extracted data does not match the schema: ${issues}`);
|
|
307
|
+
}
|
|
308
|
+
return checked.value;
|
|
309
|
+
},
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAChG,OAAO,EAA+B,WAAW,EAAuB,MAAM,YAAY,CAAA;AAC1F,OAAO,EAGL,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,cAAc,GACf,MAAM,eAAe,CAAA;AACtB,OAAO,EAAc,QAAQ,EAAe,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EACL,QAAQ,EACR,OAAO,EAGP,aAAa,EACb,MAAM,EACN,UAAU,GACX,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,WAAW,EAAmB,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAwG7C,MAAM,UAAU,YAAY,CAAC,MAAmB;IAC9C,OAAO,U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