diff --git a/AGENTS.md b/AGENTS.md index 482a094..68d7089 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,7 +26,7 @@ Core pipeline: GitHub Webhook → Worker (verify + filter + format) → Discord - Per-group forge branding: optional `Group.forgeSources` (a list of `{ host, type: "github" | "gitea", name? }` the group defines itself) labels each message's footer with the first entry whose type matches the event's provider and whose host matches the repository URL's hostname (GitHub matches `github.com`, so two Gitea instances can be `git1.example.com`/`git2.example.com`); the label is the entry's optional `name` (fallback: host); links are derived from the repo URL and footer icons use raster PNGs Discord renders (GitHub's `fluidicon.png`, Gitea's `/assets/img/favicon.png` — `.ico` favicons are silently ignored); Discord shows the footer icon + name, Telegram a linked name - Delivery queue: when the `QUEUE` binding is present, webhook ingress enqueues one message per event (not per target) to a Cloudflare Queue (`webhooker-delivery`); a Nitro `cloudflare:queue` plugin consumes batches, dispatches, and retries retryable failures (5xx/network/429-exhaustion) with exponential backoff (5s/30s/2m/10m) up to the queue `max_retries`, after which the DLQ (`webhooker-delivery-dlq`) marks the delivery dead. Oversized payloads (>~100 KB) are parked in R2 (`webhooks/YYYY/MM/DD/*.json`, falling back to KV `queue:payload:*` without the R2 binding) and resolved by the consumer; delivery state is tracked as the D1 `delivery_state` table (KV `delivery-state:*` fallback). Without the `QUEUE` binding, dispatch stays inline (existing behavior) - Storage quotas: the design avoids KV write pressure (Workers Free KV allows ~1,000 writes/day) by keeping high-frequency ephemeral writes in D1 instead — webhook dedup (`dedup_keys`, atomic `ON CONFLICT` UPSERT), delivery state and message tracking all use D1 rows via `canUseD1` (prepare+batch probe) with automatic KV fallback when D1 is unavailable or unmigrated. D1 Free allows 100,000 rows written/day, so the per-event KV write cost drops to ~0; config stays cached in memory + KV with D1 authoritative -- Filter DSL: a route's flat `filters` can be replaced by a nested `ast` (`all`/`any`/`not` nodes, `server/lib/events/filter-ast.ts`) that takes precedence when present; the `field` filter type reads any payload value by JSONPath (`path`, arrays expand so any element matches) and 12 comparison operators (`op`: `eq`/`ne`/`contains`/`startsWith`/`endsWith`/`regex`/`gt`/`gte`/`lt`/`lte`/`in`/`exists`) extend the legacy glob/regex/case-insensitive-exact semantics; named filter fragments (D1 `d1_fragments` via `server/lib/fragments.ts`, per-group) are editor-side templates inlined into the route's `ast` on insert — the matcher never resolves fragment references; the route editor (`RouteEditor.vue`) exposes a recursive AST builder (`FilterNodeEditor.vue`), chip multi-value input (`TagInput.vue`), live explanation and a stateless `POST /admin/api/test-match` dry-run +- Filter DSL: a route's flat `filters` can be replaced by a nested `ast` (`all`/`any`/`not` nodes, `server/lib/events/filter-ast.ts`) that takes precedence when present; the `field` filter type reads any payload value by JSONPath (`path`, arrays expand so any element matches) and 12 comparison operators (`op`: `eq`/`ne`/`contains`/`startsWith`/`endsWith`/`regex`/`gt`/`gte`/`lt`/`lte`/`in`/`exists`) extend the legacy glob/regex/case-insensitive-exact semantics; named filter fragments (D1 `d1_fragments` via `server/lib/fragments.ts`, per-group) are editor-side templates inlined into the route's `ast` on insert — the matcher never resolves fragment references; the route editor (`RouteEditor.vue`) exposes a recursive AST builder (`FilterNodeEditor.vue`: plain selects for filter type/operator, an all/any segmented toggle, NOT toggle + delete pinned per condition), searchable multi-value / path inputs (`FilterCombobox.vue`) fed by a bilingual suggestion catalog (`app/utils/filter-catalog.ts`: GitHub events/actions from `@octokit/webhooks` plus Gitea extras, common payload paths and their known values, English keys searchable in either language) where custom values are allowed but rejected when the matcher could never match them (`validateFilterValue`), a live explanation and a stateless `POST /admin/api/test-match` dry-run - Local dev: wrangler + Miniflare ## Architecture @@ -38,7 +38,7 @@ app/ # Vue 3 UI (Nuxt app dir) ├── pages/ # index (landing), terms, privacy, admin/[...slug] (console SPA) ├── components/ # ConsolePage (sidebar shell + topbar), AdminHome (overview dashboard), │ # RouteList (drag/keyboard reorder mode) + RouteCard, RouteEditor (FilterNodeEditor -│ # AST builder + TagInput chips), GroupEditor, MembersPanel, WebhookPanel, +│ # AST builder + FilterCombobox searchable inputs), GroupEditor, MembersPanel, WebhookPanel, │ # ConfirmDialog (app-wide destructive-action confirm), SendLogs, AuditLog, MetricsPanel, │ # AppToasts, LegalLayout ├── composables/ # useI18n, useToasts, useConfirm (promise-based confirm), useGroups, useGroupRoutes, useFilterNode (AST helpers), useFragments, useLogs, diff --git a/app/assets/css/main.css b/app/assets/css/main.css index b9bba67..30fd9d6 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -213,26 +213,6 @@ @apply px-6 py-3 text-sm; } - .icon-btn { - @apply grid h-[30px] w-[30px] place-items-center cursor-pointer rounded-sm border border-border bg-transparent text-[13px] text-muted transition-all duration-150; - } - - .icon-btn:hover { - @apply border-accent bg-accent-dim text-accent; - } - - .icon-btn:disabled { - @apply cursor-not-allowed opacity-35; - } - - .icon-btn:disabled:hover { - @apply border-border bg-transparent text-muted; - } - - .icon-btn.danger:hover { - @apply border-bad bg-bad-dim text-bad; - } - /* ---- Cards ---- */ .card { @apply animate-rise rounded border border-border bg-surface p-5 transition-[border-color,transform] duration-150; @@ -610,10 +590,6 @@ @apply truncate text-base font-extrabold tracking-tight; } - .editor-head .icon-btn { - @apply h-8 w-8 rounded-full; - } - .editor-body { @apply flex-1 overflow-y-auto px-6 py-5; scrollbar-width: thin; @@ -1021,66 +997,155 @@ } } + /* ---- Filter tree editor ---- */ .node-editor { - @apply mb-1; + container-type: inline-size; } .node-nested { - @apply ml-4 border-l border-border pl-3; + @apply ml-3 border-l border-border pl-2.5; } + @container (max-width: 26rem) { + .node-nested { + @apply ml-1 pl-1.5; + } + } + + /* + * A condition: type · path · operator on one line with the NOT toggle and + * delete pinned top-right, values below. Narrow containers stack the fields + * under the type. Field filters add a path, keyword filters have no + * operator, and `exists` has no values. + */ .leaf-row { - @apply mb-1.5 flex flex-wrap items-center gap-2 rounded-sm border border-border bg-surface-2 p-2.5; + @apply grid items-start gap-2 rounded-lg border border-border bg-surface p-2.5; + grid-template-columns: minmax(0, 1fr) auto; + grid-template-areas: + "type actions" + "op op" + "values values"; } - .node-select { - @apply w-[120px] shrink-0 rounded border border-border-strong bg-surface px-2 py-1.5 font-ui text-[12.5px] font-medium text-text; + .leaf-row.is-field { + grid-template-areas: + "type actions" + "path path" + "op op" + "values values"; } - .node-path { - @apply w-[160px] shrink-0; + .leaf-row.is-keyword { + grid-template-areas: + "type actions" + "values values"; } - .node-values { - @apply min-w-[180px] flex-1; + .leaf-row.no-values { + grid-template-areas: + "type actions" + "op op"; } - .node-exclude { - @apply flex shrink-0 cursor-pointer items-center gap-1.5 text-[12px] font-medium text-muted; + .leaf-row.is-field.no-values { + grid-template-areas: + "type actions" + "path path" + "op op"; + } + + @container (min-width: 34rem) { + .leaf-row { + grid-template-columns: 9.5rem 9.5rem minmax(0, 1fr) auto; + grid-template-areas: + "type op . actions" + "values values values values"; + } + + .leaf-row.is-field { + grid-template-columns: 9.5rem minmax(0, 1fr) 9.5rem auto; + grid-template-areas: + "type path op actions" + "values values values values"; + } + + .leaf-row.is-keyword { + grid-template-columns: 9.5rem minmax(0, 1fr) auto; + grid-template-areas: + "type . actions" + "values values values"; + } + + .leaf-row.no-values { + grid-template-areas: "type op . actions"; + } + + .leaf-row.is-field.no-values { + grid-template-areas: "type path op actions"; + } + } + + .leaf-row.is-negated { + @apply border-bad/40; + } + + .leaf-type { + @apply min-w-0; + grid-area: type; + } + + .leaf-path { + @apply min-w-0; + grid-area: path; + } + + .leaf-op { + @apply min-w-0; + grid-area: op; + } + + .leaf-values { + @apply min-w-0; + grid-area: values; + } + + .leaf-actions { + @apply flex items-center gap-1 justify-self-end; + grid-area: actions; } .node-group { - @apply mb-1.5 rounded-sm border border-border bg-surface-2 p-2.5; + @apply flex flex-col gap-2 rounded-lg border border-border bg-surface-2 p-2.5; } .node-group-head { - @apply mb-2 flex flex-wrap items-center gap-2; + @apply flex flex-wrap items-center gap-2; } - .node-combo { - @apply w-[130px] rounded border border-border-strong bg-surface px-2 py-1.5 font-ui text-[12.5px] font-semibold text-text; + .node-kind > * { + @apply whitespace-nowrap; } - .node-combo-label { - @apply inline-flex items-center rounded border border-border-strong bg-surface px-2 py-1.5 font-ui text-[12.5px] font-semibold text-text; - } - - .node-actions { - @apply ml-auto flex flex-wrap items-center gap-1.5; - } - - .node-add { - @apply px-2 py-1 text-[12px]; + .node-not-label { + @apply inline-flex items-center rounded-md bg-bad-dim px-2.5 py-1 text-xs font-semibold text-bad; } .node-children { - @apply flex flex-col gap-1.5; + @apply flex flex-col gap-2; } .node-empty { @apply py-1 text-[12px] italic text-muted; } + .node-add { + @apply flex flex-wrap items-center gap-1; + } + + .test-event { + @apply max-w-sm; + } + .test-payload { @apply font-mono text-[12px]; } diff --git a/app/components/FilterNodeEditor.vue b/app/components/FilterNodeEditor.vue index 8011bc2..1aa47db 100644 --- a/app/components/FilterNodeEditor.vue +++ b/app/components/FilterNodeEditor.vue @@ -1,7 +1,15 @@ - - diff --git a/app/composables/useFilterNode.ts b/app/composables/useFilterNode.ts index 5ba5774..860d89d 100644 --- a/app/composables/useFilterNode.ts +++ b/app/composables/useFilterNode.ts @@ -1,11 +1,22 @@ +import { toRaw } from "vue"; +import type { ComputedRef, InjectionKey } from "vue"; import type { Filter, FilterNode, FilterOp, FilterType } from "~/types"; +/** Exact event names the edited route filters on (see `scopeEvents`). */ +export const FILTER_SCOPE_EVENTS: InjectionKey> = Symbol("filter-scope"); + export interface LeafForm { type: FilterType; path: string; op: FilterOp; values: string[]; exclude: boolean; + /** + * Text typed into the values input but not added yet (editor-only, never + * saved). It lives on the leaf so it follows the condition when the input + * remounts (a NOT unwrapped, the root wrapped by an inserted fragment). + */ + draft: string; } export type NodeKind = "leaf" | "all" | "any" | "not"; @@ -17,8 +28,22 @@ export interface NodeForm { child: NodeForm | null; } +const nodeKeys = new WeakMap(); +let lastNodeKey = 0; + +/** Stable render key of a node form (list indexes shift when siblings are removed). */ +export function nodeKey(nf: NodeForm): number { + const raw = toRaw(nf); + let key = nodeKeys.get(raw); + if (key === undefined) { + key = ++lastNodeKey; + nodeKeys.set(raw, key); + } + return key; +} + export function blankLeafForm(): LeafForm { - return { type: "event", path: "", op: "eq", values: [], exclude: false }; + return { type: "event", path: "", op: "eq", values: [], exclude: false, draft: "" }; } export function blankNode(kind: NodeKind): NodeForm { @@ -42,6 +67,7 @@ function leafToForm(f: Filter): LeafForm { op: f.op ?? "eq", values: matchToValues(f.match), exclude: !!f.exclude, + draft: "", }; } @@ -60,12 +86,14 @@ export function nodeToForm(node: FilterNode): NodeForm { export function formToLeaf(lf: LeafForm): Filter | null { const values = lf.values.map((v) => v.trim()).filter((v) => v.length > 0); - if (lf.op !== "exists" && values.length === 0) return null; + // Keyword filters ignore the operator on the server, so never store one. + const op: FilterOp = lf.type === "keyword" ? "eq" : lf.op; + if (op !== "exists" && values.length === 0) return null; if (lf.type === "field" && lf.path.trim().length === 0) return null; const filter: Filter = { type: lf.type }; if (lf.type === "field") filter.path = lf.path.trim(); - if (lf.op !== "eq") filter.op = lf.op; - if (lf.op !== "exists") filter.match = values.length === 1 ? values[0] : values; + if (op !== "eq") filter.op = op; + if (op !== "exists") filter.match = values.length === 1 ? values[0] : values; if (lf.exclude) filter.exclude = true; return filter; } @@ -116,6 +144,29 @@ export function nodeFormToRouteFilters(nf: NodeForm): { filters: Filter[]; ast?: return { filters: [], ast: ast ?? undefined }; } +/** + * Exact event names a route positively filters on (negated conditions, + * `not` groups, globs and regexes are skipped) — the context the filter + * editor uses to rank action and field suggestions. + */ +export function scopeEvents(nf: NodeForm): string[] { + const out = new Set(); + const walk = (n: NodeForm): void => { + if (n.kind === "leaf") { + const { type, op, exclude, values } = n.leaf; + if (type !== "event" || exclude || (op !== "eq" && op !== "in")) return; + for (const v of values) { + const value = v.trim(); + if (/^[a-z0-9_]+$/i.test(value)) out.add(value.toLowerCase()); + } + return; + } + if (n.kind === "all" || n.kind === "any") n.children.forEach(walk); + }; + walk(nf); + return [...out]; +} + /** * Whether a node holds nothing worth confirming before it is removed: an * untouched condition (default operator, no path, no values, not negated) or @@ -124,13 +175,22 @@ export function nodeFormToRouteFilters(nf: NodeForm): { filters: Filter[]; ast?: */ export function isBlankNode(nf: NodeForm): boolean { if (nf.kind === "leaf") { - const { exclude, op, path, values } = nf.leaf; - return !exclude && op === "eq" && !path.trim() && values.every((v) => !v.trim()); + const { draft, exclude, op, path, values } = nf.leaf; + return ( + !exclude && op === "eq" && !path.trim() && values.every((v) => !v.trim()) && !draft.trim() + ); } if (nf.kind === "all" || nf.kind === "any") return nf.children.every(isBlankNode); return !nf.child || isBlankNode(nf.child); } +/** Whether a condition of the tree still holds typed text that was not added. */ +export function hasPendingDraft(nf: NodeForm): boolean { + if (nf.kind === "leaf") return !!nf.leaf.draft.trim(); + if (nf.kind === "all" || nf.kind === "any") return nf.children.some(hasPendingDraft); + return !!nf.child && hasPendingDraft(nf.child); +} + export function collectEvents(node: FilterNode): string[] { const out: string[] = []; const walk = (n: FilterNode): void => { diff --git a/app/composables/useI18n.ts b/app/composables/useI18n.ts index 14a29ea..9693f24 100644 --- a/app/composables/useI18n.ts +++ b/app/composables/useI18n.ts @@ -261,7 +261,14 @@ const en: Dict = { "routeEditor.addGroup": "Add group", "routeEditor.addNot": "Add not", "routeEditor.remove": "Remove", + "routeEditor.removeCondition": "Delete condition", + "routeEditor.removeGroup": "Delete condition group", "routeEditor.removeTarget": "Remove target", + "routeEditor.path": "Field path", + "routeEditor.values": "Values", + "routeEditor.notHint": "Negate this condition", + "routeEditor.errDraft": "Add (press Enter) or clear the filter value still being typed", + "routeEditor.errInvalidValue": 'Invalid value "{value}": {reason}', "routeEditor.op": "Operator", "routeEditor.pathPlaceholder": "payload.path", "routeEditor.valuesPlaceholder": "Type a value and press Enter", @@ -272,6 +279,7 @@ const en: Dict = { "routeEditor.testMatched": "Matches", "routeEditor.testNotMatched": "Does not match", "routeEditor.testInvalidJson": "Invalid JSON", + "routeEditor.testEventInvalid": "Fix or clear the event type first", "routeEditor.fragments": "Fragments", "routeEditor.fragmentsPresets": "Presets", "routeEditor.fragmentsEmpty": "No fragments yet", @@ -685,7 +693,14 @@ const zh: Dict = { "routeEditor.addGroup": "添加分组", "routeEditor.addNot": "添加非", "routeEditor.remove": "删除", + "routeEditor.removeCondition": "删除条件", + "routeEditor.removeGroup": "删除条件组", "routeEditor.removeTarget": "删除目标", + "routeEditor.path": "字段路径", + "routeEditor.values": "匹配值", + "routeEditor.notHint": "对该条件取反", + "routeEditor.errDraft": "请先确认(回车)或清除尚未添加的过滤值", + "routeEditor.errInvalidValue": "无效的值“{value}”:{reason}", "routeEditor.op": "操作符", "routeEditor.pathPlaceholder": "payload.path", "routeEditor.valuesPlaceholder": "输入值后回车", @@ -696,6 +711,7 @@ const zh: Dict = { "routeEditor.testMatched": "匹配", "routeEditor.testNotMatched": "不匹配", "routeEditor.testInvalidJson": "无效的 JSON", + "routeEditor.testEventInvalid": "请先修正或清空事件类型", "routeEditor.fragments": "过滤器片段", "routeEditor.fragmentsPresets": "预设", "routeEditor.fragmentsEmpty": "暂无片段", diff --git a/docs/guide/filters.md b/docs/guide/filters.md index 25ada32..edff881 100644 --- a/docs/guide/filters.md +++ b/docs/guide/filters.md @@ -256,6 +256,8 @@ A route can use a nested `ast` to combine filters with explicit grouping instead When `ast` is present it takes precedence over `filters`. The admin console's route editor builds `ast` visually (all/any/not groups), shows a live explanation of the tree, and can test it against a pasted JSON payload via the **Test match** panel. +Values, field paths and the test event use searchable dropdowns. Suggestions come from GitHub's and Gitea's webhook definitions — events, the actions of the events the route filters on, common payload paths and their known values — each shown as its English key with a description in the console language; search matches the key first, then the English or Chinese description. Anything outside the list can still be typed and is validated before it is added; only values that can never match are rejected (an event name with spaces, a branch with characters git forbids, invalid regex syntax, a non-number for a comparison operator, …). Repository and actor values stay free-form because custom webhooks may carry any string. Text that is typed but not added with Enter blocks saving, fragment saving and test runs instead of being added or dropped silently. Arrays are expanded along a `field` path, but a path that **ends** on an array (e.g. `commits.modified`) is compared as a whole — match one of its elements with `contains`; the editor switches to `contains` when such a suggested path is picked. + ### Named filter fragments The route editor can save the current filter tree as a **named fragment** and insert it into other routes. Fragments are editor-side templates stored in D1 (`d1_fragments`); inserting a fragment inlines its node into the route's `ast`, so the matching engine itself never resolves fragment references. diff --git a/docs/zh/guide/filters.md b/docs/zh/guide/filters.md index f6bd12e..cb081f9 100644 --- a/docs/zh/guide/filters.md +++ b/docs/zh/guide/filters.md @@ -256,6 +256,8 @@ 当 `ast` 存在时,它优先于 `filters`。管理后台的路由编辑器会以可视化方式构建 `ast`(all/any/not 分组)、实时展示树状解释,并可通过「测试匹配」面板粘贴 JSON 载荷进行试匹配。 +匹配值、字段路径与测试事件均为可搜索的下拉框。候选项来自 GitHub 与 Gitea 的 webhook 定义——事件、路由所选事件的动作、常用载荷路径及其已知取值——以英文 key 展示,并附当前界面语言的说明;搜索优先匹配 key,其次匹配英文或中文说明。列表之外的值仍可直接输入,添加前会按匹配规则校验,只拒绝永远不可能匹配的值(含空格的事件名、含 git 禁用字符的分支、无效的正则、比较运算中的非数字等);仓库与操作者不做格式限制,因为自定义 webhook 可以携带任意字符串。已输入但未按回车添加的内容会阻止保存路由、存为片段和测试匹配,而不会被静默添加或丢弃。`field` 路径中途的数组会被展开,但以数组**结尾**的路径(如 `commits.modified`)会作为整体比较——要匹配其中某个元素请用「包含」;在编辑器中选择这类候选路径时会自动切换为「包含」。 + ### 命名过滤器片段 路由编辑器可将当前过滤器树保存为**命名片段**并插入其他路由。片段是编辑器侧的模板,存储在 D1(`d1_fragments`)中;插入片段会将其节点内联进路由的 `ast`,因此匹配引擎本身从不解析片段引用。 diff --git a/tests/filter-node.test.ts b/tests/filter-node.test.ts index 2020853..9e0914e 100644 --- a/tests/filter-node.test.ts +++ b/tests/filter-node.test.ts @@ -1,5 +1,47 @@ import { describe, it, expect } from "bun:test"; -import { blankNode, isBlankNode } from "../app/composables/useFilterNode"; +import { + blankNode, + formToLeaf, + hasPendingDraft, + isBlankNode, + nodeKey, + nodeToForm, + scopeEvents, +} from "../app/composables/useFilterNode"; +import type { LeafForm } from "../app/composables/useFilterNode"; + +function leaf(overrides: Partial): LeafForm { + return { + type: "event", + path: "", + op: "eq", + values: [], + exclude: false, + draft: "", + ...overrides, + }; +} + +describe("scopeEvents", () => { + it("collects exact event names the route positively filters on", () => { + const form = nodeToForm({ + all: [ + { type: "event", match: ["pull_request", "Issues"] }, + { + any: [ + { type: "event", match: "release" }, + { type: "repo", match: "acme/*" }, + ], + }, + { type: "event", match: "push", exclude: true }, + { not: { type: "event", match: "star" } }, + { type: "event", match: "check_*" }, + { type: "event", op: "ne", match: "fork" }, + ], + }); + expect(scopeEvents(form).sort()).toEqual(["issues", "pull_request", "release"]); + }); +}); describe("isBlankNode", () => { it("treats untouched conditions and groups as blank", () => { @@ -23,5 +65,56 @@ describe("isBlankNode", () => { exists.children[0]!.leaf.type = "branch"; exists.children[0]!.leaf.op = "exists"; expect(isBlankNode(exists)).toBe(false); + // Typed text not added yet is content as well. + const typed = blankNode("not"); + typed.child!.leaf.draft = "my_event"; + expect(isBlankNode(typed)).toBe(false); + }); +}); + +describe("hasPendingDraft", () => { + it("finds unadded text anywhere in the tree", () => { + const form = nodeToForm({ all: [{ type: "event", match: "push" }, { not: { type: "repo" } }] }); + expect(hasPendingDraft(form)).toBe(false); + form.children[1]!.child!.leaf.draft = " "; + expect(hasPendingDraft(form)).toBe(false); + form.children[1]!.child!.leaf.draft = "acme/*"; + expect(hasPendingDraft(form)).toBe(true); + }); + + it("follows the leaf when a NOT is unwrapped or the root is wrapped", () => { + const not = blankNode("not"); + not.child!.leaf.draft = "my_event"; + // What FilterNodeEditor's unwrap and RouteEditor's fragment insert do. + const unwrapped = { ...not, kind: not.child!.kind, leaf: not.child!.leaf }; + expect(hasPendingDraft(unwrapped)).toBe(true); + const wrapped = { ...blankNode("all"), children: [unwrapped, blankNode("leaf")] }; + expect(hasPendingDraft(wrapped)).toBe(true); + }); +}); + +describe("formToLeaf", () => { + it("never stores an operator on keyword filters", () => { + expect(formToLeaf(leaf({ type: "keyword", op: "exists", values: ["hotfix"] }))).toEqual({ + type: "keyword", + match: "hotfix", + }); + }); + + it("keeps operators on other filters", () => { + expect(formToLeaf(leaf({ type: "field", path: "pull_request.draft", op: "exists" }))).toEqual({ + type: "field", + path: "pull_request.draft", + op: "exists", + }); + }); +}); + +describe("nodeKey", () => { + it("is stable per node and unique across nodes", () => { + const a = blankNode("leaf"); + const b = blankNode("leaf"); + expect(nodeKey(a)).toBe(nodeKey(a)); + expect(nodeKey(a)).not.toBe(nodeKey(b)); }); });