@piwitests/reporter 0.23.0 → 0.24.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.
@@ -107,7 +107,15 @@ var PIWI_ENV_KEYS = {
107
107
  captureServerTraces: "PIWI_CAPTURE_SERVER_TRACES",
108
108
  inspectOnFailure: "PIWI_INSPECT_ON_FAIL",
109
109
  pickLocatorOnFailure: "PIWI_PICK_LOCATOR_ON_FAIL",
110
- outputFile: "PIWI_OUTPUT_FILE"
110
+ outputFile: "PIWI_OUTPUT_FILE",
111
+ aiMode: "PIWI_AI",
112
+ aiDir: "PIWI_AI_DIR",
113
+ aiOnMiss: "PIWI_AI_ON_MISS",
114
+ aiMaxSteps: "PIWI_AI_MAX_FLOW_STEPS",
115
+ aiMaxSnapshotChars: "PIWI_AI_MAX_SNAPSHOT_CHARS",
116
+ aiOptionalProbeTimeout: "PIWI_AI_OPTIONAL_PROBE_TIMEOUT",
117
+ aiResponseWaitTimeout: "PIWI_AI_RESPONSE_WAIT_TIMEOUT",
118
+ aiScreenshotFallback: "PIWI_AI_SCREENSHOT_FALLBACK"
111
119
  };
112
120
  var PIWI_DESKTOP_CONFIG_ENV = "PIWI_DESKTOP_CONFIG";
113
121
  function readBool(val) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FullConfig, Suite, TestCase, TestResult, FullResult } from '@playwright/test/reporter';
2
- import { PlaywrightTestConfig } from '@playwright/test';
2
+ import { PlaywrightTestConfig, Locator, TestType, Page, Fixtures, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions } from '@playwright/test';
3
3
  export { PlaywrightTestConfig } from '@playwright/test';
4
4
  export { PiwiFixtures, extendPiwiFixtures, piwiFixtures } from './internal/capture/capture-fixtures.js';
5
5
  import '@piwitests/picker-dom';
@@ -114,6 +114,61 @@ interface PiwiDashboardOptions {
114
114
  tags?: string[];
115
115
  /** Additional custom metadata as key-value pairs */
116
116
  customData?: Record<string, unknown>;
117
+ /**
118
+ * Natural-language locators and flows (`page.piwiLocator(...)` /
119
+ * `page.piwiRun(...)`). An agent resolves each prompt once into a committed,
120
+ * deterministic artifact; every run replays that artifact with plain
121
+ * Playwright calls — zero LLM calls in the default `replay` mode.
122
+ */
123
+ ai?: {
124
+ /**
125
+ * `replay` (default) executes committed artifacts read-only and fails closed
126
+ * on a miss; `resolve` authors missing entries; `heal` repairs entries that
127
+ * no longer replay. Can also be set with `PIWI_AI`.
128
+ */
129
+ mode?: 'replay' | 'resolve' | 'heal';
130
+ /**
131
+ * Directory name (per spec) that holds the committed entries. Defaults to
132
+ * `__piwi__`. Can also be set with `PIWI_AI_DIR`.
133
+ */
134
+ dir?: string;
135
+ /**
136
+ * On a replay miss: `fail` (default) errors with repro instructions, or
137
+ * `fixme` marks the test fixme (yellow) instead. Can also be set with
138
+ * `PIWI_AI_ON_MISS`.
139
+ */
140
+ onMiss?: 'fail' | 'fixme';
141
+ /**
142
+ * Max steps the agent may take resolving one `piwiRun` flow (the authoring
143
+ * budget). Defaults to `20`. Can also be set with `PIWI_AI_MAX_FLOW_STEPS`.
144
+ */
145
+ maxSteps?: number;
146
+ /**
147
+ * Max characters of the page ARIA snapshot sent to the authoring model per
148
+ * iteration (cost control). Defaults to `24000`. Can also be set with
149
+ * `PIWI_AI_MAX_SNAPSHOT_CHARS`.
150
+ */
151
+ maxSnapshotChars?: number;
152
+ /**
153
+ * Timeout (ms) for the existence probe of an `optional` step during replay.
154
+ * Defaults to `2000`. Can also be set with `PIWI_AI_OPTIONAL_PROBE_TIMEOUT`.
155
+ */
156
+ optionalProbeTimeout?: number;
157
+ /**
158
+ * Timeout (ms) for a step's `waitForResponse` (the Ajax wait) during replay,
159
+ * and the network-settle window during authoring. Omitted uses Playwright's
160
+ * default action timeout. Can also be set with `PIWI_AI_RESPONSE_WAIT_TIMEOUT`.
161
+ */
162
+ responseWaitTimeout?: number;
163
+ /**
164
+ * Send a screenshot to the authoring model as a vision fallback when the page's
165
+ * ARIA snapshot is empty (a canvas-heavy page the model otherwise can't ground
166
+ * against). **Requires a vision-capable model** — leave it off (the default) for
167
+ * models that don't accept images. Only affects `resolve`/`heal`, never replay.
168
+ * Can also be set with `PIWI_AI_SCREENSHOT_FALLBACK`.
169
+ */
170
+ screenshotFallback?: boolean;
171
+ };
117
172
  /**
118
173
  * Write a JSON file with the submitted run's dashboard URL, id, project id and
119
174
  * status after the run lands, so a CI pipeline can consume it (e.g. feed the
@@ -228,6 +283,59 @@ declare class PiwiDashboardReporter {
228
283
  onEnd(result: FullResult): Promise<void>;
229
284
  }
230
285
 
286
+ /**
287
+ * Parameters are first-class: a template like `row for {name}` is the cache key,
288
+ * so one entry serves every value. Placeholders survive compilation as `{{name}}`
289
+ * markers inside locator args and step values; replay substitutes the runtime
290
+ * value locally. Param values are masked out of any snapshot sent to the model,
291
+ * so secrets never leave the machine.
292
+ */
293
+
294
+ /**
295
+ * Extract the placeholder names from a template string literal at the type level,
296
+ * so a missing or misspelled parameter is a compile error. Placeholder names are
297
+ * assumed brace-free (`{email}`, not `{a{b}}`).
298
+ */
299
+ type ExtractParams<S extends string> = S extends `${string}{${infer Param}}${infer Rest}` ? Param | ExtractParams<Rest> : never;
300
+ /**
301
+ * The parameter argument list for a template: no argument when the template has
302
+ * no placeholders, otherwise a required record of every placeholder → string.
303
+ */
304
+ type ParamArgs<S extends string> = [ExtractParams<S>] extends [never] ? [] : [params: Record<ExtractParams<S>, string>];
305
+
306
+ /** How the fixture behaves on a cache miss. */
307
+ type AiMode = 'replay' | 'resolve' | 'heal';
308
+ /** What to do when replay finds no committed entry. */
309
+ type AiOnMiss = 'fail' | 'fixme';
310
+ /**
311
+ * The natural-language surface attached to `page`. Template-literal types make a
312
+ * missing or misspelled `{param}` a compile error (`ParamArgs`): a template with
313
+ * placeholders requires a matching params object, one without takes no argument.
314
+ */
315
+ interface PiwiAi {
316
+ /** Resolve a single element by description. Returns a real, synchronous `Locator`. */
317
+ piwiLocator<S extends string>(template: S, ...params: ParamArgs<S>): Locator;
318
+ /** Replay a compiled flow (steps + postcondition oracle). */
319
+ piwiRun<S extends string>(template: S, ...params: ParamArgs<S>): Promise<void>;
320
+ }
321
+ /** Local `{ [key: string]: any }` used by the extend signature (mirrors capture fixtures). */
322
+ type FixtureArgs = {
323
+ [key: string]: any;
324
+ };
325
+ /**
326
+ * Fixtures that override `page` to carry the `PiwiAi` surface. Composable with
327
+ * `piwiFixtures`; keep this separate so a project can opt into AI steps without
328
+ * the capture fixtures (and vice versa).
329
+ */
330
+ declare const piwiAiFixtures: Fixtures<{}, {}, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>;
331
+ /**
332
+ * Add the `PiwiAi` surface to a test's `page`. Compose over `extendPiwiFixtures`
333
+ * (or a base `test`) — e.g. `export const test = extendPiwiAi(extendPiwiFixtures(base))`.
334
+ */
335
+ declare function extendPiwiAi<TestArgs extends FixtureArgs, WorkerArgs extends FixtureArgs>(test: TestType<TestArgs, WorkerArgs>): TestType<TestArgs & {
336
+ page: Page & PiwiAi;
337
+ }, WorkerArgs>;
338
+
231
339
  /**
232
340
  * Public API of `@piwitests/reporter`.
233
341
  *
@@ -237,4 +345,4 @@ declare class PiwiDashboardReporter {
237
345
  * exported from this file, it isn't part of the supported API.
238
346
  */
239
347
 
240
- export { type PiwiDashboardOptions, PiwiDashboardReporter, createGlobalSetup, PiwiDashboardReporter as default, wrapConfig };
348
+ export { type AiMode, type AiOnMiss, type PiwiAi, type PiwiDashboardOptions, PiwiDashboardReporter, createGlobalSetup, PiwiDashboardReporter as default, extendPiwiAi, piwiAiFixtures, wrapConfig };