From 7a77771571faf9b077f9723131365136d58f929f Mon Sep 17 00:00:00 2001 From: can1357 Date: Wed, 5 Aug 2026 21:44:52 +0200 Subject: [PATCH] test(coding-agent): require multiline flag for anchored rules --- .../test/discovery/builtin-defaults.test.ts | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/coding-agent/test/discovery/builtin-defaults.test.ts b/packages/coding-agent/test/discovery/builtin-defaults.test.ts index 3bf97344a..df313c167 100644 --- a/packages/coding-agent/test/discovery/builtin-defaults.test.ts +++ b/packages/coding-agent/test/discovery/builtin-defaults.test.ts @@ -6,7 +6,12 @@ */ import { describe, expect, it } from "bun:test"; import { getCapability } from "@oh-my-pi/pi-coding-agent/capability"; -import { BUILTIN_DEFAULTS_PROVIDER_ID, type Rule, ruleCapability } from "@oh-my-pi/pi-coding-agent/capability/rule"; +import { + BUILTIN_DEFAULTS_PROVIDER_ID, + compileRuleCondition, + type Rule, + ruleCapability, +} from "@oh-my-pi/pi-coding-agent/capability/rule"; import type { LoadContext } from "@oh-my-pi/pi-coding-agent/capability/types"; // Register all discovery providers as a side effect. import "@oh-my-pi/pi-coding-agent/discovery"; @@ -181,20 +186,20 @@ describe("builtin-defaults rule provider", () => { }), ).toEqual([]); }); - it("opens every bundled regex condition that uses a bare line anchor with a translatable inline flag", async () => { - // Without the (?m)/(?s) inline flags a bare ^ or $ anchors to the - // absolute start/end of input, so a rule whose condition is anchored to - // a line silently stops matching in real files (see #6890). Enforce the - // pairing at load time so the failure class stays closed. + it("opens every bundled regex condition that uses a bare line anchor with the multiline inline flag", async () => { + // Without the (?m) inline flag a bare ^ or $ anchors to the absolute + // start/end of input, so a rule whose condition is anchored to a line + // silently stops matching in real files (see #6890). Enforce the pairing + // at load time so the failure class stays closed. const rules = await loadBuiltinRules(); for (const rule of rules) { for (const condition of rule.condition ?? []) { const outsideCharClasses = condition.replace(/\[[^\]]*\]/g, ""); const hasBareAnchor = /(^|[^\\])[\^$]/.test(outsideCharClasses); - const opensWithTranslatableFlag = /^\(\?[ims]+\)/.test(condition); + const hasMultilineSemantics = compileRuleCondition(condition).multiline; expect( - hasBareAnchor ? opensWithTranslatableFlag : true, - `${rule.name}: a condition with a bare ^ or $ anchor must open with a translatable inline flag`, + hasBareAnchor ? hasMultilineSemantics : true, + `${rule.name}: a condition with a bare ^ or $ anchor must open with the multiline inline flag`, ).toBe(true); } }