Skip to content

Commit a9aad2b

Browse files
authored
[spec-gen-sdk-runner] Align dependencies, add workflow to run unit tests (#33008)
1 parent 963f34e commit a9aad2b

File tree

7 files changed

+63
-317
lines changed

7 files changed

+63
-317
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: spec-gen-sdk-runner - Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- typespec-next
8+
pull_request:
9+
paths:
10+
- package-lock.json
11+
- package.json
12+
- tsconfig.json
13+
- .github/workflows/_reusable-eng-tools-test.yaml
14+
- .github/workflows/spec-gen-sdk-runner-test.yaml
15+
- eng/tools/package.json
16+
- eng/tools/tsconfig.json
17+
- eng/tools/spec-gen-sdk-runner/**
18+
workflow_dispatch:
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
specGenSdkRunner:
25+
name: spec-gen-sdk-runner
26+
uses: ./.github/workflows/_reusable-eng-tools-test.yaml
27+
with:
28+
package: spec-gen-sdk-runner
29+
lint: true
30+
sparse-checkout-paths: |
31+
specification/common-types
32+
specification/contosowidgetmanager

eng/tools/spec-gen-sdk-runner/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
"test:ci": "vitest run --coverage --reporter=verbose"
1616
},
1717
"engines": {
18-
"node": ">= 18.0.0"
18+
"node": ">=20.0.0"
1919
},
2020
"devDependencies": {
2121
"@types/node": "^18.19.31",
22-
"@vitest/coverage-c8": "^0.33.0",
22+
"@vitest/coverage-v8": "^3.0.5",
2323
"typescript": "~5.6.2",
24-
"vitest": "^3.0.7"
24+
"vitest": "^3.0.5"
2525
}
2626
}

eng/tools/spec-gen-sdk-runner/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function getArgumentValue(args: string[], flag: string, defaultValue: str
6060
* Get the relative path from the specification folder
6161
*/
6262
export function getRelativePathFromSpecification(absolutePath: string): string {
63-
const specificationIndex = absolutePath.indexOf("specification/");
63+
const specificationIndex = absolutePath.indexOf(path.normalize("specification/"));
6464
if (specificationIndex !== -1) {
6565
return absolutePath.slice(Math.max(0, specificationIndex));
6666
}

eng/tools/spec-gen-sdk-runner/test/utils/createCombinedSpecs.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, test, expect } from "vitest";
22
import { createCombinedSpecs, type SpecResults } from "../../src/utils.js";
3+
import path from "node:path";
34

45
describe("createCombinedSpecs", () => {
56
test("combines specs from readme and typespec paths", () => {
@@ -26,9 +27,9 @@ describe("createCombinedSpecs", () => {
2627
expect(result[0].specs).toContain("api.json");
2728
expect(result[0].specs).toContain("main.tsp");
2829
expect(result[0].specs).toContain("client.tsp");
29-
expect(result[0].readmeMd).toBe("specification/apicenter/data-plane/readme.md");
30+
expect(result[0].readmeMd).toBe(path.normalize("specification/apicenter/data-plane/readme.md"));
3031
expect(result[0].typespecProject).toBe(
31-
"specification/apicenter/ApiCenter.DataApi/tspconfig.yaml",
32+
path.normalize("specification/apicenter/ApiCenter.DataApi/tspconfig.yaml"),
3233
);
3334
});
3435

eng/tools/spec-gen-sdk-runner/test/utils/searchRelatedTypeSpecProjectBySharedLibrary.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ describe("searchRelatedTypeSpecProjectBySharedLibrary", () => {
1010

1111
test("finds related TypeSpec projects for shared libraries", () => {
1212
const sharedLibraries = [
13-
"specification/contosowidgetmanager/Contoso.WidgetManager.Shared/main.tsp",
13+
path.normalize("specification/contosowidgetmanager/Contoso.WidgetManager.Shared/main.tsp"),
1414
];
1515

1616
const result = searchRelatedTypeSpecProjectBySharedLibrary(sharedLibraries, {
1717
searchFileRegex: /^tspconfig\.yaml$/,
1818
specRepoFolder: repoRoot,
1919
});
20-
20+
const expectedPath = path.normalize("specification/contosowidgetmanager/Contoso.WidgetManager");
2121
expect(Object.keys(result)).toHaveLength(1);
22-
expect(result["specification/contosowidgetmanager/Contoso.WidgetManager"]).toBeDefined();
23-
expect(result["specification/contosowidgetmanager/Contoso.WidgetManager"]).toContain(
22+
expect(result[expectedPath]).toBeDefined();
23+
expect(result[expectedPath]).toContain(
2424
sharedLibraries[0],
2525
);
2626
});
@@ -35,7 +35,7 @@ describe("searchRelatedTypeSpecProjectBySharedLibrary", () => {
3535
});
3636

3737
test("handles non-existent directories", () => {
38-
const sharedLibraries = ["specification/nonexistent/Shared/main.tsp"];
38+
const sharedLibraries = [path.normalize("specification/nonexistent/Shared/main.tsp")];
3939

4040
const result = searchRelatedTypeSpecProjectBySharedLibrary(sharedLibraries, {
4141
searchFileRegex: /^tspconfig\.yaml$/,

eng/tools/spec-gen-sdk-runner/test/utils/utils.test.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ const repoRoot = path.resolve(path.dirname(currentFilePath), "../../../../../");
1414
describe("Utils", () => {
1515
describe("findFilesRecursive", () => {
1616
test("finds all tspconfig.yaml files recursively", () => {
17-
const results = findFilesRecursive(
18-
`${repoRoot}/specification/contosowidgetmanager`,
19-
"tspconfig.yaml",
20-
);
17+
const searchPath = path.normalize(`${repoRoot}/specification/contosowidgetmanager`);
18+
const results = findFilesRecursive(searchPath, "tspconfig.yaml");
2119
expect(results).toHaveLength(2);
2220
expect(results).toContain(
23-
"specification/contosowidgetmanager/Contoso.Management/tspconfig.yaml",
21+
path.normalize("specification/contosowidgetmanager/Contoso.Management/tspconfig.yaml"),
2422
);
2523
expect(results).toContain(
26-
"specification/contosowidgetmanager/Contoso.WidgetManager/tspconfig.yaml",
24+
path.normalize("specification/contosowidgetmanager/Contoso.WidgetManager/tspconfig.yaml"),
2725
);
2826
});
2927

@@ -46,10 +44,15 @@ describe("Utils", () => {
4644

4745
describe("findReadmeFiles", () => {
4846
test("finds all readme.md files in directory", () => {
49-
const results = findReadmeFiles(`${repoRoot}/specification/contosowidgetmanager`);
47+
const searchPath = path.normalize(`${repoRoot}/specification/contosowidgetmanager`);
48+
const results = findReadmeFiles(searchPath);
5049
expect(results).toHaveLength(2);
51-
expect(results).toContain("specification/contosowidgetmanager/resource-manager/readme.md");
52-
expect(results).toContain("specification/contosowidgetmanager/data-plane/readme.md");
50+
expect(results).toContain(
51+
path.normalize("specification/contosowidgetmanager/resource-manager/readme.md"),
52+
);
53+
expect(results).toContain(
54+
path.normalize("specification/contosowidgetmanager/data-plane/readme.md"),
55+
);
5356
});
5457

5558
test("returns empty array for directory without readme files", () => {
@@ -63,9 +66,9 @@ describe("Utils", () => {
6366
describe("getRelativePathFromSpecification", () => {
6467
test("extracts path from specification folder", () => {
6568
const result = getRelativePathFromSpecification(
66-
"/repo/root/specification/apicenter/resource-manager/readme.md",
69+
path.normalize("/repo/root/specification/apicenter/resource-manager/readme.md"),
6770
);
68-
expect(result).toBe("specification/apicenter/resource-manager/readme.md");
71+
expect(result).toBe(path.normalize("specification/apicenter/resource-manager/readme.md"));
6972
});
7073

7174
test("returns original path if specification is not found", () => {
@@ -76,9 +79,9 @@ describe("Utils", () => {
7679

7780
test("handles paths with multiple specification occurrences", () => {
7881
const result = getRelativePathFromSpecification(
79-
"/repo/root/specification/old/specification/apicenter/readme.md",
82+
path.normalize("/repo/root/specification/old/specification/apicenter/readme.md"),
8083
);
81-
expect(result).toBe("specification/old/specification/apicenter/readme.md");
84+
expect(result).toBe(path.normalize("specification/old/specification/apicenter/readme.md"));
8285
});
8386

8487
test("handles empty path", () => {

0 commit comments

Comments
 (0)