





















@@ -1,7 +1,8 @@
1+import { spawnSync } from "node:child_process";
12import fs from "node:fs";
23import path from "node:path";
34import { fileURLToPath } from "node:url";
4-import { describe, expect, it } from "vitest";
5+import { describe, expect, it, vi } from "vitest";
5667const repoRoot = fileURLToPath(new URL("../../..", import.meta.url));
78const srcRoot = path.join(repoRoot, "src");
@@ -23,7 +24,34 @@ const forbiddenGenericFixtureTerms = [
2324const importSpecifierPattern =
2425/\b(?:import|export)\s+(?:type\s+)?(?:[^'"]*?\s+from\s+)?["']([^"']+)["']|import\(\s*["']([^"']+)["']\s*\)/g;
252627+function listTrackedSourceFiles(dir: string): string[] | null {
28+const relativeDir = path.relative(repoRoot, dir).split(path.sep).join("/");
29+if (!relativeDir || relativeDir.startsWith("..")) {
30+return null;
31+}
32+const result = spawnSync("git", ["ls-files", "--", relativeDir], {
33+cwd: repoRoot,
34+encoding: "utf8",
35+stdio: ["ignore", "pipe", "ignore"],
36+});
37+if (result.status !== 0) {
38+return null;
39+}
40+return result.stdout
41+.split("\n")
42+.map((line) => line.trim().replaceAll("\\", "/"))
43+.filter((line) => line.length > 0 && line.endsWith(".ts") && !line.includes("/plugin-sdk/"))
44+.map((line) => path.join(repoRoot, ...line.split("/")))
45+.toSorted();
46+}
47+2648function collectSourceFiles(dir: string, files: string[] = []): string[] {
49+const trackedFiles = listTrackedSourceFiles(dir);
50+if (trackedFiles) {
51+files.push(...trackedFiles);
52+return files;
53+}
54+2755for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
2856if (entry.name === "plugin-sdk") {
2957continue;
@@ -45,6 +73,19 @@ function toRepoRelative(filePath: string): string {
4573}
46744775describe("core extension facade boundary", () => {
76+it("lists core facade boundary sources from git without walking src", () => {
77+const readDir = vi.spyOn(fs, "readdirSync");
78+try {
79+const files = collectSourceFiles(srcRoot);
80+81+expect(files.length).toBeGreaterThan(0);
82+expect(files.some((file) => file.includes("/plugin-sdk/"))).toBe(false);
83+expect(readDir).not.toHaveBeenCalled();
84+} finally {
85+readDir.mockRestore();
86+}
87+});
88+4889it("does not expose Ollama plugin facades from core plugin-sdk", () => {
4990expect(
5091forbiddenOllamaFacadeFiles.filter((file) => fs.existsSync(path.join(repoRoot, file))),
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。