Skip to content

Commit d1f02ab

Browse files
committed
ensure we never stomp on each other
1 parent 73c242a commit d1f02ab

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

test/debug_failing_example.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55

66
import * as validate from "../lib/validate";
77

8-
import { repoPath, clonePR } from "./utilities.helpers";
8+
import { clonePR } from "./utilities.helpers";
99

1010
const prNumber: number = 0;
1111
const prRepo: string = "azure/azure-rest-api-specs";
12-
const specPath = `${repoPath}/specification/storage/resource-manager/Microsoft.Storage/stable/2023-01-01/blob.json`;
12+
const specRelPath = `specification/storage/resource-manager/Microsoft.Storage/stable/2023-01-01/blob.json`;
1313

1414
jest.setTimeout(1000000); // Set the timeout in milliseconds
1515

1616
describe("Model Validation", () => {
1717
it("Debug an individual spec failing model validation.", async () => {
18-
clonePR(`https://github.com/${prRepo}.git`, prNumber);
18+
const repoPath = clonePR(`https://github.com/${prRepo}.git`, prNumber);
1919

20-
const result = await validate.validateExamples(specPath, undefined);
20+
const result = await validate.validateExamples(`${repoPath}/${specRelPath}`, undefined);
2121
console.log(result);
2222
});
2323
});

test/debug_failing_spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55

66
import * as validate from "../lib/validate";
77

8-
import { repoPath, clonePR } from "./utilities.helpers";
8+
import { clonePR } from "./utilities.helpers";
99

1010
const prNumber: number = 27067;
1111
const prRepo: string = "azure/azure-rest-api-specs";
12-
const specPath = `${repoPath}/specification/storage/resource-manager/Microsoft.Storage/stable/2023-01-01/blob.json`;
12+
const specRelPath = `specification/storage/resource-manager/Microsoft.Storage/stable/2023-01-01/blob.json`;
1313

1414
jest.setTimeout(1000000); // Set the timeout in milliseconds
1515

1616
describe("Semantic Validation", () => {
1717
it("Debug an individual spec failing semantic validation.", async () => {
18-
clonePR(`https://github.com/${prRepo}.git`, prNumber);
19-
20-
const result = await validate.validateSpec(specPath, undefined);
18+
const repoPath = clonePR(`https://github.com/${prRepo}.git`, prNumber);
19+
const result = await validate.validateSpec(`${repoPath}/${specRelPath}`, undefined);
2120
console.log(result);
2221
});
2322
});

test/utilities.helpers.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ const testPath = __dirname.replace("\\", "/");
1010
export const repoPath: string = path.join(testPath, "..", ".autopull");
1111

1212
// Function to clone a specific PR's code from the Git repo
13-
export function clonePR(url: string, prNumber: number): void {
13+
export function clonePR(url: string, prNumber: number): string {
1414
const prBranch = `pull/${prNumber}/head`;
15-
const execOptions = { cwd: repoPath };
15+
const finalRepoPath = path.join(repoPath, prNumber.toString());
16+
const execOptions = { cwd: finalRepoPath };
1617
const outputFile: string = path.join(execOptions.cwd, "stamp.txt");
1718
const existingData = getPRData(outputFile);
1819

@@ -21,10 +22,10 @@ export function clonePR(url: string, prNumber: number): void {
2122
`Previously downloaded spec repo does not match targeted prNumber ${prNumber} or repo ${url}`
2223
);
2324

24-
if (fs.existsSync(repoPath)) {
25-
fs.removeSync(repoPath);
25+
if (fs.existsSync(finalRepoPath)) {
26+
fs.removeSync(finalRepoPath);
2627
}
27-
fs.mkdirSync(repoPath);
28+
fs.mkdirSync(finalRepoPath);
2829

2930
try {
3031
if (prNumber !== 0) {
@@ -44,6 +45,8 @@ export function clonePR(url: string, prNumber: number): void {
4445
`Previously downloaded spec repo matches the expected PR Number ${prNumber} and repo ${url}. Skipping re-clone.`
4546
);
4647
}
48+
49+
return finalRepoPath;
4750
}
4851

4952
function writePRData(targetFile: string, data: PRData): void {

0 commit comments

Comments
 (0)