mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:00:43 +00:00
test: keep extension directory filters covered
This commit is contained in:
@@ -131,6 +131,17 @@ describe("createScopedVitestConfig", () => {
|
||||
expect(config.test?.include).toEqual(["slack/**/*.test.*"]);
|
||||
});
|
||||
|
||||
it("keeps broad scoped cli directory filters aligned with repo-root include patterns", () => {
|
||||
const config = createScopedVitestConfig([BUNDLED_PLUGIN_TEST_GLOB], {
|
||||
argv: ["vitest", "run", "extensions/speech-core"],
|
||||
dir: "extensions",
|
||||
env: {},
|
||||
passWithNoTests: true,
|
||||
});
|
||||
|
||||
expect(config.test?.include).toEqual(["speech-core/**/*.test.*"]);
|
||||
});
|
||||
|
||||
it("relativizes scoped include and exclude patterns to the configured dir", () => {
|
||||
const config = createScopedVitestConfig([BUNDLED_PLUGIN_TEST_GLOB], {
|
||||
dir: "extensions",
|
||||
|
||||
@@ -26,6 +26,31 @@ function looksLikeCliIncludePattern(value: string): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
function literalPrefixForGlobPattern(value: string): string {
|
||||
const normalized = value.replaceAll("\\", "/");
|
||||
const globIndex = normalized.search(/[?*[\]{}]/u);
|
||||
if (globIndex === -1) {
|
||||
return normalized;
|
||||
}
|
||||
const slashIndex = normalized.lastIndexOf("/", globIndex);
|
||||
return slashIndex === -1 ? "" : normalized.slice(0, slashIndex + 1);
|
||||
}
|
||||
|
||||
function patternsCouldOverlap(value: string, pattern: string): boolean {
|
||||
if (path.matchesGlob(value, pattern) || path.matchesGlob(pattern, value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const valuePrefix = literalPrefixForGlobPattern(value);
|
||||
const patternPrefix = literalPrefixForGlobPattern(pattern);
|
||||
return (
|
||||
patternPrefix === "" ||
|
||||
valuePrefix === "" ||
|
||||
valuePrefix.startsWith(patternPrefix) ||
|
||||
patternPrefix.startsWith(valuePrefix)
|
||||
);
|
||||
}
|
||||
|
||||
export function loadPatternListFile(filePath: string, label: string): string[] {
|
||||
const parsed = JSON.parse(fs.readFileSync(filePath, "utf8")) as unknown;
|
||||
if (!Array.isArray(parsed)) {
|
||||
@@ -99,9 +124,7 @@ export function narrowIncludePatternsForCli(
|
||||
}
|
||||
|
||||
const matched = cliPatterns.filter((value) =>
|
||||
includePatterns.some(
|
||||
(pattern) => path.matchesGlob(value, pattern) || path.matchesGlob(pattern, value),
|
||||
),
|
||||
includePatterns.some((pattern) => patternsCouldOverlap(value, pattern)),
|
||||
);
|
||||
|
||||
return [...new Set(matched)];
|
||||
|
||||
Reference in New Issue
Block a user