mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:10:49 +00:00
perf: harden test cargo traversal checks
This commit is contained in:
@@ -587,7 +587,6 @@ export function collectPackedTestCargoErrors(paths: Iterable<string>): string[]
|
||||
return errors.toSorted((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
async function main(): Promise<number> {
|
||||
async function main(): Promise<number> {
|
||||
const pkg = loadPackageJson();
|
||||
const now = new Date();
|
||||
|
||||
@@ -478,8 +478,8 @@ function walkFiles(rootDir, visitFile) {
|
||||
return;
|
||||
}
|
||||
const queue = [rootDir];
|
||||
while (queue.length > 0) {
|
||||
const currentDir = queue.shift();
|
||||
for (let index = 0; index < queue.length; index += 1) {
|
||||
const currentDir = queue[index];
|
||||
for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) {
|
||||
const fullPath = path.join(currentDir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
@@ -522,8 +522,8 @@ function pruneDependencyDirectoriesByBasename(depRoot, basenames) {
|
||||
}
|
||||
const basenameSet = new Set(basenames);
|
||||
const queue = [depRoot];
|
||||
while (queue.length > 0) {
|
||||
const currentDir = queue.shift();
|
||||
for (let index = 0; index < queue.length; index += 1) {
|
||||
const currentDir = queue[index];
|
||||
for (const entry of fs.readdirSync(currentDir, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) {
|
||||
continue;
|
||||
|
||||
@@ -415,6 +415,19 @@ describe("collectPackedTestCargoErrors", () => {
|
||||
]),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("normalizes Windows or mixed separators before classifying test cargo", () => {
|
||||
expect(
|
||||
collectPackedTestCargoErrors([
|
||||
String.raw`dist\extensions\fixture-plugin\node_modules\direct\__tests__\index.js`,
|
||||
String.raw`dist/extensions/fixture-plugin\node_modules/direct/src/runtime.spec.ts`,
|
||||
String.raw`dist\extensions\fixture-plugin\node_modules\direct\node_modules\test\index.js`,
|
||||
]),
|
||||
).toEqual([
|
||||
`npm package must not include test cargo "${String.raw`dist/extensions/fixture-plugin\node_modules/direct/src/runtime.spec.ts`}".`,
|
||||
`npm package must not include test cargo "${String.raw`dist\extensions\fixture-plugin\node_modules\direct\__tests__\index.js`}".`,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("collectReleaseTagErrors", () => {
|
||||
|
||||
Reference in New Issue
Block a user