waygraph 0.15.40 → 0.15.41

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.
@@ -1,4 +1,4 @@
1
- export type PracticeKind = "wildcard-checkpoint" | "assert-no-type-arg" | "multi-input" | "combined-action" | "empty-verify";
1
+ export type PracticeKind = "wildcard-checkpoint" | "assert-no-type-arg" | "multi-input" | "combined-action" | "empty-verify" | "overcomplex-selector" | "inline-selector-should-use-sel-file";
2
2
  export interface PracticeWarning {
3
3
  kind: PracticeKind;
4
4
  file: string;
@@ -3,8 +3,8 @@
3
3
  * that compile but erode the typed graph. Warnings only (never fail exit code)
4
4
  * unless paired with `tsc` errors in `waygraph typecheck`.
5
5
  */
6
- import { readFileSync } from "node:fs";
7
- import { relative } from "node:path";
6
+ import { readFileSync, readdirSync } from "node:fs";
7
+ import { dirname, relative } from "node:path";
8
8
  /** define*Block<…Checkpoint<string>…> — prefer project Checkpoint types. */
9
9
  const WILDCARD_CHECKPOINT = /\bdefine(?:Method|Effect|Page|Nav|MemNav|NavClick|Action)Block\s*<[^>]*\bCheckpoint\s*<\s*string\s*>/;
10
10
  /** defineAssertBlock({ … }) with no explicit Out type — defaults to wildcard. */
@@ -23,6 +23,19 @@ const EMPTY_VERIFY_ARRAY = /\bverify\s*:\s*\[\s*\]/;
23
23
  /** Any `verify:` key at all, empty or not. */
24
24
  const HAS_VERIFY_KEY = /\bverify\s*:/;
25
25
  const SCAN_GLOB = /\.(block|flow)\.ts$/;
26
+ /**
27
+ * A selector string reaching for a regex-based Playwright text pseudo-class (`:has-text(/…/)`,
28
+ * `:text-matches(…)`) or a plain XPath - real, recurring pattern: an LLM asked to target a simple
29
+ * element (one class, one id, one data-attribute) instead writes a regex/XPath from scratch. Not a
30
+ * type error (Playwright's own selector syntax accepts all of this), so nothing else catches it.
31
+ */
32
+ const TEXT_MATCHES_PSEUDO = /:text-matches\(/;
33
+ const HAS_TEXT_REGEX_PSEUDO = /:has-text\(\s*\//;
34
+ const XPATH_LOCATOR = /\.locator\(\s*["'`](?:xpath=)?\/\//;
35
+ /** A selector string literal inline in a Block file (`.locator("…")`, `click: "…"`, `url: "…"`) -
36
+ * scoped to simple, single-token selectors (id/class/attr/tag) so this doesn't fire on the
37
+ * legitimate multi-part selectors `.sel.ts` files themselves are made of. */
38
+ const INLINE_SIMPLE_SELECTOR = /(?:\.locator|\bclick|\burl)\s*[:(]\s*["'`](#|\.)[\w-]+["'`]/;
26
39
  const METHOD_OR_EFFECT_FILE = /\.(method|effect)\.block\.ts$/;
27
40
  const METHOD_OR_EFFECT_DEFINE = /\bdefine(?:Method|Effect)Block\b/;
28
41
  /** Whole-file opt-out: `// waygraph-ignore-practices` */
@@ -107,6 +120,31 @@ export function collectPracticeWarnings(projectDir, walkDir, opts) {
107
120
  });
108
121
  }
109
122
  }
123
+ if (!isIgnored("overcomplex-selector", ignore) &&
124
+ (TEXT_MATCHES_PSEUDO.test(src) || HAS_TEXT_REGEX_PSEUDO.test(src) || XPATH_LOCATOR.test(src))) {
125
+ const via = TEXT_MATCHES_PSEUDO.test(src)
126
+ ? ":text-matches(...)"
127
+ : HAS_TEXT_REGEX_PSEUDO.test(src)
128
+ ? ":has-text(/regex/)"
129
+ : "an XPath locator";
130
+ warnings.push({
131
+ kind: "overcomplex-selector",
132
+ file: rel,
133
+ detail: `uses ${via} — reach for a plain CSS selector (id/class/data-attribute, via a .sel.ts ` +
134
+ "export) instead of a regex/XPath match unless the DOM genuinely has no stable selector",
135
+ });
136
+ }
137
+ if (!isIgnored("inline-selector-should-use-sel-file", ignore) && INLINE_SIMPLE_SELECTOR.test(src)) {
138
+ const siblingSelFile = readdirSync(dirname(file)).some((f) => f.endsWith(".sel.ts"));
139
+ if (siblingSelFile) {
140
+ warnings.push({
141
+ kind: "inline-selector-should-use-sel-file",
142
+ file: rel,
143
+ detail: "a selector string is inlined here, but this directory already has a *.sel.ts file — " +
144
+ "add/reuse the selector there instead of a new one-off literal",
145
+ });
146
+ }
147
+ }
110
148
  if (!isIgnored("empty-verify", ignore) && IS_ASSERT_BLOCK.test(src) && EMPTY_VERIFY_ARRAY.test(src)) {
111
149
  warnings.push({
112
150
  kind: "empty-verify",
@@ -130,6 +168,10 @@ export function practiceKindLabel(kind) {
130
168
  return "fill and click in one Block";
131
169
  case "empty-verify":
132
170
  return "empty verify — transition unconfirmed";
171
+ case "overcomplex-selector":
172
+ return "regex/XPath selector where a plain one would do";
173
+ case "inline-selector-should-use-sel-file":
174
+ return "inline selector — a .sel.ts file already exists here";
133
175
  default: {
134
176
  const _exhaustive = kind;
135
177
  return _exhaustive;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waygraph",
3
- "version": "0.15.40",
3
+ "version": "0.15.41",
4
4
  "type": "module",
5
5
  "description": "A typed graph of reusable Blocks for driving a browser through E2E flows.",
6
6
  "license": "MIT",
@@ -19,7 +19,14 @@ against a live site, use `--skill-pilot-blind`.
19
19
  (no goto) even when the app changes URL as a side effect of a button click.
20
20
  3. **Selectors in `*Sel`, never inline.** DOM strings live in a `*Sel` next to the page
21
21
  (static + `(id) => …`). Mem keys store values, not selectors. `waygraph check` warns on
22
- inline selector literals in `Trait.visible` / `Trait.text`.
22
+ inline selector literals in `Trait.visible` / `Trait.text`, and separately on any inline
23
+ selector literal (`.locator("#x")`, `click: "#x"`) in a directory that already has a `*Sel`.
24
+ **Plain CSS first, always.** An id, a class, or `[data-testid=…]` is the selector for
25
+ almost everything real apps have - reach for that before anything else. Don't invent a
26
+ regex/XPath match (`:has-text(/…/)`, `:text-matches(…)`, an XPath locator) for something a
27
+ one-line class or id selector already targets uniquely; `waygraph check` flags this too.
28
+ A regex/text match is for a genuinely unstable DOM with no stable attribute at all, not
29
+ the default first move.
23
30
  4. **Assert-only = `defineAssertBlock`.** Self-loop, no hand-written `act`/`resolve`. Pass
24
31
  an explicit type argument when it sits between two specifically-typed Blocks in a Flow.
25
32
  Not just static content or an action's result - it also names a *feature state* worth a