waygraph 0.15.35 → 0.15.37
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/dist/engine/branch-regression.d.ts +46 -0
- package/dist/engine/branch-regression.js +117 -0
- package/dist/engine/engine-class.js +5 -0
- package/dist/engine.d.ts +1 -0
- package/dist/engine.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/mem-page.d.ts +8 -0
- package/dist/mem-page.js +14 -0
- package/examples/saucedemo/.waygraph-auto/527b6d76.log +0 -0
- package/examples/saucedemo/.waygraph-auto/7c99674f.log +0 -0
- package/examples/saucedemo/.waygraph-auto/7f1b4864.log +0 -0
- package/examples/saucedemo/.waygraph-auto/8481aa1c.log +0 -0
- package/examples/saucedemo/.waygraph-auto/bf85a598.log +0 -0
- package/examples/saucedemo/.waygraph-auto/db81ba7d.log +0 -0
- package/examples/saucedemo/.waygraph-auto/f43de83c.log +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Checkpoint } from "../types.js";
|
|
2
|
+
import type { Flow } from "./flow.js";
|
|
3
|
+
import type { RunGraphOptions } from "./run-graph.js";
|
|
4
|
+
import { MemPage } from "../mem-page.js";
|
|
5
|
+
import type { BrowserContext } from "@playwright/test";
|
|
6
|
+
/** One branch reachable from `flow`, possibly several `.branch()` levels deep. */
|
|
7
|
+
export interface BranchEntry {
|
|
8
|
+
/** `"Away"`, or `"Away > Far"` for a nested branch - the route tags that lead here, in order. */
|
|
9
|
+
path: string;
|
|
10
|
+
flow: Flow<any>;
|
|
11
|
+
}
|
|
12
|
+
/** This Flow's own immediate `.branch()` routes, or `undefined` if it wasn't built by `.branch()`. */
|
|
13
|
+
export declare function branchRoutes(flow: Flow<any>): ReadonlyMap<string, Flow<any> | null> | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Every branch Flow reachable from `flow`, at any depth, deduped by object identity (the same
|
|
16
|
+
* route Flow reused under two tags is only listed once). Doesn't include `flow` itself - only its
|
|
17
|
+
* `.branch()` continuations. Static - doesn't run anything.
|
|
18
|
+
*/
|
|
19
|
+
export declare function collectBranchFlows(flow: Flow<any>): BranchEntry[];
|
|
20
|
+
export interface BranchRunResult {
|
|
21
|
+
path: string;
|
|
22
|
+
status: "ok" | "failed";
|
|
23
|
+
result?: Checkpoint<string>;
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface RunBranchRegressionOptions extends RunGraphOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Default `true`: clone the real session (storageState + current URL) at every branch point, so
|
|
29
|
+
* every route runs from a genuine copy of the live state, not a fresh page. `false` runs the
|
|
30
|
+
* whole tree exactly once, through whichever single path the live state actually takes (same as
|
|
31
|
+
* calling `flow.run()` directly) - can't explore siblings, since the one real page has moved on
|
|
32
|
+
* once a branch's Blocks run.
|
|
33
|
+
*/
|
|
34
|
+
cloneSession?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Runs every path through `flow`'s `.branch()` tree - by default in a CLONED session per branch
|
|
38
|
+
* point (see this file's own header), so one branch finishing doesn't consume another's chance to
|
|
39
|
+
* run. Each explored branch gets its own `MemPage` (via {@link MemPage.clone}, seeded further with
|
|
40
|
+
* {@link seedMemStub} for anything a route alone requires that the shared prefix didn't already set).
|
|
41
|
+
* @example
|
|
42
|
+
* for (const r of await runBranchRegression(loginFlow, context)) {
|
|
43
|
+
* console.log(r.path, r.status, r.error ?? "");
|
|
44
|
+
* }
|
|
45
|
+
*/
|
|
46
|
+
export declare function runBranchRegression(flow: Flow<any>, context: BrowserContext, mem?: MemPage, options?: RunBranchRegressionOptions): Promise<BranchRunResult[]>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { MemPage } from "../mem-page.js";
|
|
2
|
+
import { seedMemStub } from "../mem-stub.js";
|
|
3
|
+
function branchInfo(flow) {
|
|
4
|
+
return flow.__wgBranch;
|
|
5
|
+
}
|
|
6
|
+
/** This Flow's own immediate `.branch()` routes, or `undefined` if it wasn't built by `.branch()`. */
|
|
7
|
+
export function branchRoutes(flow) {
|
|
8
|
+
const info = branchInfo(flow);
|
|
9
|
+
return info ? new Map(Object.entries(info.routes)) : undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Every branch Flow reachable from `flow`, at any depth, deduped by object identity (the same
|
|
13
|
+
* route Flow reused under two tags is only listed once). Doesn't include `flow` itself - only its
|
|
14
|
+
* `.branch()` continuations. Static - doesn't run anything.
|
|
15
|
+
*/
|
|
16
|
+
export function collectBranchFlows(flow) {
|
|
17
|
+
const out = [];
|
|
18
|
+
const seen = new Set();
|
|
19
|
+
const walk = (f, prefix) => {
|
|
20
|
+
const routes = branchRoutes(f);
|
|
21
|
+
if (!routes)
|
|
22
|
+
return;
|
|
23
|
+
for (const [tag, route] of routes) {
|
|
24
|
+
if (!route || seen.has(route))
|
|
25
|
+
continue;
|
|
26
|
+
seen.add(route);
|
|
27
|
+
const path = prefix ? `${prefix} > ${tag}` : tag;
|
|
28
|
+
out.push({ path, flow: route });
|
|
29
|
+
walk(route, path);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
walk(flow, "");
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Runs every path through `flow`'s `.branch()` tree - by default in a CLONED session per branch
|
|
37
|
+
* point (see this file's own header), so one branch finishing doesn't consume another's chance to
|
|
38
|
+
* run. Each explored branch gets its own `MemPage` (via {@link MemPage.clone}, seeded further with
|
|
39
|
+
* {@link seedMemStub} for anything a route alone requires that the shared prefix didn't already set).
|
|
40
|
+
* @example
|
|
41
|
+
* for (const r of await runBranchRegression(loginFlow, context)) {
|
|
42
|
+
* console.log(r.path, r.status, r.error ?? "");
|
|
43
|
+
* }
|
|
44
|
+
*/
|
|
45
|
+
export async function runBranchRegression(flow, context, mem = new MemPage(), options) {
|
|
46
|
+
const cloneSession = options?.cloneSession ?? true;
|
|
47
|
+
const results = [];
|
|
48
|
+
const browser = cloneSession ? context.browser() : null;
|
|
49
|
+
if (cloneSession && !browser) {
|
|
50
|
+
throw new Error("Waygraph runBranchRegression: cloneSession needs context.browser() (a persistent context " +
|
|
51
|
+
"has none) - pass { cloneSession: false } to run the single live path in this context instead.");
|
|
52
|
+
}
|
|
53
|
+
/** `entryPage`, when given, is already positioned (cloned session + navigated) - reused as-is,
|
|
54
|
+
* never replaced by a fresh `ctx.newPage()` (that would throw away the whole point of cloning). */
|
|
55
|
+
async function walk(f, ctx, m, path, entryPage) {
|
|
56
|
+
const info = branchInfo(f);
|
|
57
|
+
if (!info) {
|
|
58
|
+
// Leaf: whatever Blocks this route itself adds - run them to completion from the (possibly
|
|
59
|
+
// cloned, already-positioned) session already in place.
|
|
60
|
+
seedMemStub(m, f);
|
|
61
|
+
const page = entryPage ?? (await ctx.newPage());
|
|
62
|
+
try {
|
|
63
|
+
const result = await f.run(ctx, m, { ...options, page, closeOnFinish: true });
|
|
64
|
+
results.push({ path, status: "ok", result: result });
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
results.push({ path, status: "failed", error: err instanceof Error ? err.message : String(err) });
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
seedMemStub(m, info.before);
|
|
72
|
+
const page = entryPage ?? (await ctx.newPage());
|
|
73
|
+
let first;
|
|
74
|
+
try {
|
|
75
|
+
first = (await info.before.run(ctx, m, { ...options, page, closeOnFinish: false }));
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
results.push({ path, status: "failed", error: err instanceof Error ? err.message : String(err) });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!cloneSession) {
|
|
82
|
+
// Shared-session mode: only the ONE route the live state actually resolved to is reachable -
|
|
83
|
+
// the page has already moved past every other tag.
|
|
84
|
+
const route = info.routes[first.result.__state];
|
|
85
|
+
const tagPath = path ? `${path} > ${first.result.__state}` : first.result.__state;
|
|
86
|
+
if (!route) {
|
|
87
|
+
results.push({ path: tagPath, status: "ok", result: first.result });
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
await walk(route, ctx, m, tagPath, first.page);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const url = first.page.url();
|
|
94
|
+
const storageState = await ctx.storageState();
|
|
95
|
+
await first.page.close();
|
|
96
|
+
for (const [tag, route] of Object.entries(info.routes)) {
|
|
97
|
+
const branchPath = path ? `${path} > ${tag}` : tag;
|
|
98
|
+
if (!route) {
|
|
99
|
+
results.push({ path: branchPath, status: "ok", result: { __state: tag } });
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const branchContext = await browser.newContext({ storageState });
|
|
103
|
+
try {
|
|
104
|
+
const branchPage = await branchContext.newPage();
|
|
105
|
+
// Best-effort: land back on the same page the prefix ended on before this route's own
|
|
106
|
+
// Blocks run - restores cookies/localStorage AND which page was loaded, not just auth state.
|
|
107
|
+
await branchPage.goto(url).catch(() => { });
|
|
108
|
+
await walk(route, branchContext, m.clone(), branchPath, branchPage);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
await branchContext.close();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
await walk(flow, context, mem, "");
|
|
116
|
+
return results;
|
|
117
|
+
}
|
|
@@ -142,6 +142,11 @@ function buildBranchedFlow(before, routes) {
|
|
|
142
142
|
...(before.demoPace !== undefined ? { demoPace: before.demoPace } : {}),
|
|
143
143
|
...(before.highlightStyle !== undefined ? { highlightStyle: before.highlightStyle } : {}),
|
|
144
144
|
...(before.memStub !== undefined ? { memStub: before.memStub } : {}),
|
|
145
|
+
// Read by branchRoutes()/branchInfo() (branch-regression.ts) - real, ORDINARY (enumerable)
|
|
146
|
+
// properties, not hidden ones, specifically so a `with*` wrapper's `{ ...flow, ... }` spread
|
|
147
|
+
// (withSessionReset, withTitle, etc.) carries them through instead of silently dropping them -
|
|
148
|
+
// the same class of bug branch()'s missing copyWaygraphRuntime call already was.
|
|
149
|
+
__wgBranch: { before, routes },
|
|
145
150
|
// Static introspection (`waygraph graph`/list): the fixed prefix, plus every branch's own
|
|
146
151
|
// Blocks prefixed by the tag that leads to them - can't know at analysis time which one a real
|
|
147
152
|
// run takes, so this shows all of them rather than none.
|
package/dist/engine.d.ts
CHANGED
package/dist/engine.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ export { connect, checkpoint } from "./types.js";
|
|
|
3
3
|
export { MemKey, MemPage, key, keyGroup } from "./mem-page.js";
|
|
4
4
|
export { registerMemStub, seedMemStub, getMemStub } from "./mem-stub.js";
|
|
5
5
|
export { Trait, urlMatches, textEquals, visible, disabled, enabled, frameVisible, frameTextEquals, frameContainsText, } from "./trait.js";
|
|
6
|
-
export { runGraph, spawnTab, narrate, Engine, start, end, branch, withVerify, modVerify, modVerifyAll, defineBlock, defineNavBlock, defineNavClickBlock, defineMethodBlock, defineActionBlock, defineAssertBlock, definePageBlock, defineEffectBlock, defineMemEffectBlock, defineMemNavBlock, locate, composeBlock, fastForwardComposeBlock, isFastForwardBlock, preflight, withSessionReset, withTitle, withMemStub, withDemoPace, withBlockPace, withHighlightStyle, withExpectedFailure, withHighlightFixtures, withStubBefore, withStubAfter, withStubOnError, chainFlow, defineLayout, map, MapBuilder, } from "./engine.js";
|
|
6
|
+
export { runGraph, spawnTab, narrate, Engine, start, end, branch, withVerify, modVerify, modVerifyAll, defineBlock, defineNavBlock, defineNavClickBlock, defineMethodBlock, defineActionBlock, defineAssertBlock, definePageBlock, defineEffectBlock, defineMemEffectBlock, defineMemNavBlock, locate, composeBlock, fastForwardComposeBlock, isFastForwardBlock, preflight, withSessionReset, withTitle, withMemStub, withDemoPace, withBlockPace, withHighlightStyle, withExpectedFailure, withHighlightFixtures, withStubBefore, withStubAfter, withStubOnError, chainFlow, defineLayout, map, MapBuilder, branchRoutes, collectBranchFlows, runBranchRegression, } from "./engine.js";
|
|
7
|
+
export type { BranchEntry, BranchRunResult, RunBranchRegressionOptions } from "./engine/branch-regression.js";
|
|
7
8
|
export { resolveHighlightSlots, resolveSlides, runStubPhase, resolveFixtureDwellMs, resolveSlideDwellMs, formatHighlightCaption, hasAuthoredStubAfter, hasAuthoredStubOnError, normalizeHighlightTone, normalizeDemoPace, normalizeHighlightSize, normalizeHighlightWeight, applyHighlightStyleDefaults, toneIconPrefix, resolveStepDemoPace, demoPaceScale, demoPaceIsBlitz, demoPaceIsFast, demoPaceIsSlow, demoPaceGateMs, formatDemoPaceBadge, formatDemoPaceLabel, normalizeTodos, normalizeTodoPos, normalizeTodoStyle, buildTodoDock, applyTodoPhase, advanceTodoDock, completeSequentialTodoDock, applyDevicePhase, resolveDeviceState, normalizeDevicePreset, normalizeDeviceOrientation, applyOrientation, orientationFromViewport, DEVICE_PRESETS, resolveTodoDockUi, FIXTURE_DURATION_MS_DEFAULT, FIXTURE_DURATION_FAST_MS_DEFAULT, FIXTURE_DURATION_SLOW_MS_DEFAULT, SLIDE_DURATION_MS_DEFAULT, SLIDE_DURATION_FAST_MS_DEFAULT, WAYGRAPH_RING_CSS, } from "./highlights.js";
|
|
8
9
|
export type { WaygraphHighlightStub, WaygraphHighlightFixture, WaygraphSlide, WaygraphTodoItem, WaygraphTodoInput, WaygraphTodoGroup, WaygraphTodoGroupInput, WaygraphTodosOpts, TodoDockUiOpts, BannerPos, BannerUiOpts, TodoDockUiResolved, TodoDockState, TodoListStyle, FixtureDurationFields, HighlightStubPhase, HighlightStubPhaseName, HighlightFixtureMap, ResolvedHighlight, WaygraphHighlight, HighlightTone, HighlightSize, HighlightWeight, HighlightStyleDefaults, DemoPace, DemoPaceName, StubCtx, StubLifecycleFn, StubPhaseResult, StubPhaseFixtures, DevicePreset, DeviceViewport, DeviceState, DeviceOrientation, } from "./highlights.js";
|
|
9
10
|
export type { Flow, EngineConfig, ComposedBlock, FastForwardComposedBlock, RunGraphOptions, BlockInfo, NavBlock, NavBlockOptions, NavClickBlock, NavClickBlockOptions, MethodBlock, ActionBlock, AssertBlock, AssertBlockOptions, PageBlock, PageBlockOptions, PageMethodEntry, EffectBlock, MemEffectBlock, MemNavBlock, Layout, LayoutOptions, MapBuilderOptions, } from "./engine.js";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ export { connect, checkpoint } from "./types.js";
|
|
|
2
2
|
export { MemKey, MemPage, key, keyGroup } from "./mem-page.js";
|
|
3
3
|
export { registerMemStub, seedMemStub, getMemStub } from "./mem-stub.js";
|
|
4
4
|
export { Trait, urlMatches, textEquals, visible, disabled, enabled, frameVisible, frameTextEquals, frameContainsText, } from "./trait.js";
|
|
5
|
-
export { runGraph, spawnTab, narrate, Engine, start, end, branch, withVerify, modVerify, modVerifyAll, defineBlock, defineNavBlock, defineNavClickBlock, defineMethodBlock, defineActionBlock, defineAssertBlock, definePageBlock, defineEffectBlock, defineMemEffectBlock, defineMemNavBlock, locate, composeBlock, fastForwardComposeBlock, isFastForwardBlock, preflight, withSessionReset, withTitle, withMemStub, withDemoPace, withBlockPace, withHighlightStyle, withExpectedFailure, withHighlightFixtures, withStubBefore, withStubAfter, withStubOnError, chainFlow, defineLayout, map, MapBuilder, } from "./engine.js";
|
|
5
|
+
export { runGraph, spawnTab, narrate, Engine, start, end, branch, withVerify, modVerify, modVerifyAll, defineBlock, defineNavBlock, defineNavClickBlock, defineMethodBlock, defineActionBlock, defineAssertBlock, definePageBlock, defineEffectBlock, defineMemEffectBlock, defineMemNavBlock, locate, composeBlock, fastForwardComposeBlock, isFastForwardBlock, preflight, withSessionReset, withTitle, withMemStub, withDemoPace, withBlockPace, withHighlightStyle, withExpectedFailure, withHighlightFixtures, withStubBefore, withStubAfter, withStubOnError, chainFlow, defineLayout, map, MapBuilder, branchRoutes, collectBranchFlows, runBranchRegression, } from "./engine.js";
|
|
6
6
|
export { resolveHighlightSlots, resolveSlides, runStubPhase, resolveFixtureDwellMs, resolveSlideDwellMs, formatHighlightCaption, hasAuthoredStubAfter, hasAuthoredStubOnError, normalizeHighlightTone, normalizeDemoPace, normalizeHighlightSize, normalizeHighlightWeight, applyHighlightStyleDefaults, toneIconPrefix, resolveStepDemoPace, demoPaceScale, demoPaceIsBlitz, demoPaceIsFast, demoPaceIsSlow, demoPaceGateMs, formatDemoPaceBadge, formatDemoPaceLabel, normalizeTodos, normalizeTodoPos, normalizeTodoStyle, buildTodoDock, applyTodoPhase, advanceTodoDock, completeSequentialTodoDock, applyDevicePhase, resolveDeviceState, normalizeDevicePreset, normalizeDeviceOrientation, applyOrientation, orientationFromViewport, DEVICE_PRESETS, resolveTodoDockUi, FIXTURE_DURATION_MS_DEFAULT, FIXTURE_DURATION_FAST_MS_DEFAULT, FIXTURE_DURATION_SLOW_MS_DEFAULT, SLIDE_DURATION_MS_DEFAULT, SLIDE_DURATION_FAST_MS_DEFAULT, WAYGRAPH_RING_CSS, } from "./highlights.js";
|
|
7
7
|
export { discoverGraph, toMermaid, findOrphanBlocks, findBlockPath } from "./graph.js";
|
|
8
8
|
export { isFileSelectToken, parseBlocksSelect, matchBlocksSelect, globToRegExp, } from "./blocks-select.js";
|
package/dist/mem-page.d.ts
CHANGED
|
@@ -67,4 +67,12 @@ export declare class MemPage {
|
|
|
67
67
|
setAll<A, B, C, D>(p1: readonly [MemKey<A>, A], p2: readonly [MemKey<B>, B], p3: readonly [MemKey<C>, C], p4: readonly [MemKey<D>, D]): void;
|
|
68
68
|
setAll<A, B, C, D, E>(p1: readonly [MemKey<A>, A], p2: readonly [MemKey<B>, B], p3: readonly [MemKey<C>, C], p4: readonly [MemKey<D>, D], p5: readonly [MemKey<E>, E]): void;
|
|
69
69
|
setAll<A, B, C, D, E, F>(p1: readonly [MemKey<A>, A], p2: readonly [MemKey<B>, B], p3: readonly [MemKey<C>, C], p4: readonly [MemKey<D>, D], p5: readonly [MemKey<E>, E], p6: readonly [MemKey<F>, F]): void;
|
|
70
|
+
/**
|
|
71
|
+
* An independent copy of every key currently set - a later `.set()` on either the original or the
|
|
72
|
+
* clone never touches the other. For branch-session cloning (`runBranchRegression`): each explored
|
|
73
|
+
* branch gets its own mem, so one branch's writes can't bleed into a sibling that also gets tried
|
|
74
|
+
* from the same snapshot point. Shallow per value (same as `set()` always was - MemPage never
|
|
75
|
+
* owned deep-copying the values themselves, only which keys point to which).
|
|
76
|
+
*/
|
|
77
|
+
clone(): MemPage;
|
|
70
78
|
}
|
package/dist/mem-page.js
CHANGED
|
@@ -68,4 +68,18 @@ export class MemPage {
|
|
|
68
68
|
this.set(k, v);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* An independent copy of every key currently set - a later `.set()` on either the original or the
|
|
73
|
+
* clone never touches the other. For branch-session cloning (`runBranchRegression`): each explored
|
|
74
|
+
* branch gets its own mem, so one branch's writes can't bleed into a sibling that also gets tried
|
|
75
|
+
* from the same snapshot point. Shallow per value (same as `set()` always was - MemPage never
|
|
76
|
+
* owned deep-copying the values themselves, only which keys point to which).
|
|
77
|
+
*/
|
|
78
|
+
clone() {
|
|
79
|
+
const copy = new MemPage();
|
|
80
|
+
for (const [k, v] of this.store) {
|
|
81
|
+
copy.store.set(k, v);
|
|
82
|
+
}
|
|
83
|
+
return copy;
|
|
84
|
+
}
|
|
71
85
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|