mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-05-23 07:43:50 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { findCodeRegions, isInsideCode } from "./code-regions.js";
|
|
|
|
describe("shared/text/code-regions", () => {
|
|
function expectCodeRegionSlices(text: string, expectedSlices: readonly string[]) {
|
|
const regions = findCodeRegions(text);
|
|
expect(regions).toHaveLength(expectedSlices.length);
|
|
expect(regions.map((region) => text.slice(region.start, region.end))).toEqual(expectedSlices);
|
|
}
|
|
|
|
function expectInsideCodeCase(params: {
|
|
positionSelector: (text: string, regionEnd: number) => number;
|
|
expected: boolean;
|
|
}) {
|
|
const text = "plain `code` done";
|
|
const regions = findCodeRegions(text);
|
|
const regionEnd = regions[0]?.end ?? -1;
|
|
expect(isInsideCode(params.positionSelector(text, regionEnd), regions)).toBe(params.expected);
|
|
}
|
|
|
|
it.each([
|
|
{
|
|
name: "finds fenced and inline code regions without double-counting inline code inside fences",
|
|
text: ["before `inline` after", "```ts", "const a = `inside fence`;", "```", "tail"].join(
|
|
"\n",
|
|
),
|
|
expectedSlices: ["`inline`", "```ts\nconst a = `inside fence`;\n```"],
|
|
},
|
|
{
|
|
name: "accepts alternate fence markers and unterminated trailing fences",
|
|
text: "~~~js\nconsole.log(1)\n~~~\nplain\n```\nunterminated",
|
|
expectedSlices: ["~~~js\nconsole.log(1)\n~~~", "```\nunterminated"],
|
|
},
|
|
{
|
|
name: "keeps adjacent inline code outside fenced regions",
|
|
text: ["```ts", "const a = 1;", "```", "after `inline` tail"].join("\n"),
|
|
expectedSlices: ["```ts\nconst a = 1;\n```", "`inline`"],
|
|
},
|
|
] as const)("$name", ({ text, expectedSlices }) => {
|
|
expectCodeRegionSlices(text, expectedSlices);
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
name: "inside code",
|
|
positionSelector: (text: string) => text.indexOf("code"),
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "outside code",
|
|
positionSelector: (text: string) => text.indexOf("plain"),
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "at region end",
|
|
positionSelector: (_text: string, regionEnd: number) => regionEnd,
|
|
expected: false,
|
|
},
|
|
] as const)("reports whether positions are inside discovered regions: $name", (testCase) => {
|
|
expectInsideCodeCase(testCase);
|
|
});
|
|
});
|