Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spec-gen-sdk-runner] Align dependencies, add workflow to run unit tests #33008

Merged
merged 9 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/spec-gen-sdk-runner-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: spec-gen-sdk-runner - Test

Check failure on line 1 in .github/workflows/spec-gen-sdk-runner-test.yaml

View workflow job for this annotation

GitHub Actions / Protected Files

File '.github/workflows/spec-gen-sdk-runner-test.yaml' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.

on:
push:
branches:
- main
- typespec-next
pull_request:
paths:
- package-lock.json
- package.json
- tsconfig.json
- .github/workflows/_reusable-eng-tools-test.yaml
- .github/workflows/spec-gen-sdk-runner-test.yaml
- eng/tools/package.json
- eng/tools/tsconfig.json
- eng/tools/spec-gen-sdk-runner/**
workflow_dispatch:

permissions:
contents: read

jobs:
specGenSdkRunner:
name: spec-gen-sdk-runner
uses: ./.github/workflows/_reusable-eng-tools-test.yaml
with:
package: spec-gen-sdk-runner
lint: true
sparse-checkout-paths: |
specification/common-types
specification/contosowidgetmanager
6 changes: 3 additions & 3 deletions eng/tools/spec-gen-sdk-runner/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check failure on line 1 in eng/tools/spec-gen-sdk-runner/package.json

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/spec-gen-sdk-runner/package.json' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
"name": "@azure-tools/spec-gen-sdk-runner",
"private": true,
"type": "module",
Expand All @@ -15,12 +15,12 @@
"test:ci": "vitest run --coverage --reporter=verbose"
},
"engines": {
"node": ">= 18.0.0"
"node": ">=20.0.0"
},
"devDependencies": {
"@types/node": "^18.19.31",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/coverage-v8": "^3.0.5",
"typescript": "~5.6.2",
"vitest": "^3.0.7"
"vitest": "^3.0.5"
}
}
2 changes: 1 addition & 1 deletion eng/tools/spec-gen-sdk-runner/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn, spawnSync, exec } from "node:child_process";

Check failure on line 1 in eng/tools/spec-gen-sdk-runner/src/utils.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/spec-gen-sdk-runner/src/utils.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
import path from "node:path";
import fs from "node:fs";
import { LogLevel, logMessage } from "./log.js";
Expand Down Expand Up @@ -60,7 +60,7 @@
* Get the relative path from the specification folder
*/
export function getRelativePathFromSpecification(absolutePath: string): string {
const specificationIndex = absolutePath.indexOf("specification/");
const specificationIndex = absolutePath.indexOf(path.normalize("specification/"));
if (specificationIndex !== -1) {
return absolutePath.slice(Math.max(0, specificationIndex));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, test, expect } from "vitest";

Check failure on line 1 in eng/tools/spec-gen-sdk-runner/test/utils/createCombinedSpecs.test.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/spec-gen-sdk-runner/test/utils/createCombinedSpecs.test.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
import { createCombinedSpecs, type SpecResults } from "../../src/utils.js";
import path from "node:path";

describe("createCombinedSpecs", () => {
test("combines specs from readme and typespec paths", () => {
Expand All @@ -26,9 +27,9 @@
expect(result[0].specs).toContain("api.json");
expect(result[0].specs).toContain("main.tsp");
expect(result[0].specs).toContain("client.tsp");
expect(result[0].readmeMd).toBe("specification/apicenter/data-plane/readme.md");
expect(result[0].readmeMd).toBe(path.normalize("specification/apicenter/data-plane/readme.md"));
expect(result[0].typespecProject).toBe(
"specification/apicenter/ApiCenter.DataApi/tspconfig.yaml",
path.normalize("specification/apicenter/ApiCenter.DataApi/tspconfig.yaml"),
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest";

Check failure on line 1 in eng/tools/spec-gen-sdk-runner/test/utils/searchRelatedTypeSpecProjectBySharedLibrary.test.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/spec-gen-sdk-runner/test/utils/searchRelatedTypeSpecProjectBySharedLibrary.test.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
import { searchRelatedTypeSpecProjectBySharedLibrary } from "../../src/utils.js";
import { fileURLToPath } from "node:url";
import path from "node:path";
Expand All @@ -10,17 +10,17 @@

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

const result = searchRelatedTypeSpecProjectBySharedLibrary(sharedLibraries, {
searchFileRegex: /^tspconfig\.yaml$/,
specRepoFolder: repoRoot,
});

const expectedPath = path.normalize("specification/contosowidgetmanager/Contoso.WidgetManager");
expect(Object.keys(result)).toHaveLength(1);
expect(result["specification/contosowidgetmanager/Contoso.WidgetManager"]).toBeDefined();
expect(result["specification/contosowidgetmanager/Contoso.WidgetManager"]).toContain(
expect(result[expectedPath]).toBeDefined();
expect(result[expectedPath]).toContain(
sharedLibraries[0],
);
});
Expand All @@ -35,7 +35,7 @@
});

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

const result = searchRelatedTypeSpecProjectBySharedLibrary(sharedLibraries, {
searchFileRegex: /^tspconfig\.yaml$/,
Expand Down
29 changes: 16 additions & 13 deletions eng/tools/spec-gen-sdk-runner/test/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, test, expect } from "vitest";

Check failure on line 1 in eng/tools/spec-gen-sdk-runner/test/utils/utils.test.ts

View workflow job for this annotation

GitHub Actions / Protected Files

File 'eng/tools/spec-gen-sdk-runner/test/utils/utils.test.ts' should only be updated by the Azure SDK team. If intentional, the PR may be merged by the Azure SDK team via bypassing the branch protections.
import {
findFilesRecursive,
findReadmeFiles,
Expand All @@ -14,16 +14,14 @@
describe("Utils", () => {
describe("findFilesRecursive", () => {
test("finds all tspconfig.yaml files recursively", () => {
const results = findFilesRecursive(
`${repoRoot}/specification/contosowidgetmanager`,
"tspconfig.yaml",
);
const searchPath = path.normalize(`${repoRoot}/specification/contosowidgetmanager`);
const results = findFilesRecursive(searchPath, "tspconfig.yaml");
expect(results).toHaveLength(2);
expect(results).toContain(
"specification/contosowidgetmanager/Contoso.Management/tspconfig.yaml",
path.normalize("specification/contosowidgetmanager/Contoso.Management/tspconfig.yaml"),
);
expect(results).toContain(
"specification/contosowidgetmanager/Contoso.WidgetManager/tspconfig.yaml",
path.normalize("specification/contosowidgetmanager/Contoso.WidgetManager/tspconfig.yaml"),
);
});

Expand All @@ -46,10 +44,15 @@

describe("findReadmeFiles", () => {
test("finds all readme.md files in directory", () => {
const results = findReadmeFiles(`${repoRoot}/specification/contosowidgetmanager`);
const searchPath = path.normalize(`${repoRoot}/specification/contosowidgetmanager`);
const results = findReadmeFiles(searchPath);
expect(results).toHaveLength(2);
expect(results).toContain("specification/contosowidgetmanager/resource-manager/readme.md");
expect(results).toContain("specification/contosowidgetmanager/data-plane/readme.md");
expect(results).toContain(
path.normalize("specification/contosowidgetmanager/resource-manager/readme.md"),
);
expect(results).toContain(
path.normalize("specification/contosowidgetmanager/data-plane/readme.md"),
);
});

test("returns empty array for directory without readme files", () => {
Expand All @@ -63,9 +66,9 @@
describe("getRelativePathFromSpecification", () => {
test("extracts path from specification folder", () => {
const result = getRelativePathFromSpecification(
"/repo/root/specification/apicenter/resource-manager/readme.md",
path.normalize("/repo/root/specification/apicenter/resource-manager/readme.md"),
);
expect(result).toBe("specification/apicenter/resource-manager/readme.md");
expect(result).toBe(path.normalize("specification/apicenter/resource-manager/readme.md"));
});

test("returns original path if specification is not found", () => {
Expand All @@ -76,9 +79,9 @@

test("handles paths with multiple specification occurrences", () => {
const result = getRelativePathFromSpecification(
"/repo/root/specification/old/specification/apicenter/readme.md",
path.normalize("/repo/root/specification/old/specification/apicenter/readme.md"),
);
expect(result).toBe("specification/old/specification/apicenter/readme.md");
expect(result).toBe(path.normalize("specification/old/specification/apicenter/readme.md"));
});

test("handles empty path", () => {
Expand Down
Loading
Loading