Skip to content

Commit

Permalink
Merge branch 'main' into user/raych1/add-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raych1 authored Mar 5, 2025
2 parents 8432328 + a0dc634 commit 6663932
Show file tree
Hide file tree
Showing 767 changed files with 34,257 additions and 7,490 deletions.
16 changes: 15 additions & 1 deletion eng/common/scripts/Package-Properties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
$additionalValidationPackages = @()
$lookup = @{}

# Sort so that we very quickly find any directly changed packages before hitting service level changes.
# This is important because due to the way we traverse the changed files, the instant we evaluate a pkg
# as directly or indirectly changed, we exit the file loop and move on to the next pkg.
# The problem is, a package may be detected as indirectly changed _before_ we get to the file that directly changed it!
# To avoid this without wonky changes to the detection algorithm, we simply sort our files by their depth, so we will always
# detect direct package changes first!
$targetedFiles = $targetedFiles | Sort-Object { ($_.Split("/").Count) } -Descending

# this is the primary loop that identifies the packages that have changes
foreach ($pkg in $allPackageProperties) {
$pkgDirectory = Resolve-Path "$($pkg.DirectoryPath)"
Expand Down Expand Up @@ -263,9 +271,15 @@ function Get-PrPkgProperties([string]$InputDiffJson) {
# we can assume that the path to the ci.yml will successfully resolve.
$ciYml = Join-Path $RepoRoot $yml
# ensure we terminate the service directory with a /
$directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/") + "/"
$directory = [System.IO.Path]::GetDirectoryName($ciYml).Replace("`\", "/")
$soleCIYml = (Get-ChildItem -Path $directory -Filter "ci*.yml" -File).Count -eq 1

# we should only continue with this check if the file being changed is "in the service directory"
$serviceDirectoryChange = (Split-Path $filePath -Parent).Replace("`\", "/") -eq $directory
if (!$serviceDirectoryChange) {
break
}

if ($soleCIYml -and $filePath.Replace("`\", "/").StartsWith($directory)) {
if (-not $shouldInclude) {
$pkg.IncludedForValidation = $true
Expand Down
33 changes: 18 additions & 15 deletions eng/tools/typespec-validation/src/rules/sdk-tspconfig-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class TspConfigGoAzInjectSpansTrueSubRule extends TspconfigEmitterOptions
}
}

// ----- Python management sub rules -----
// ----- Python management plane sub rules -----
export class TspConfigPythonMgmtPackageDirectorySubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-python", "package-dir", new RegExp(/^azure-mgmt(-[a-z]+){1,2}$/));
Expand All @@ -355,31 +355,33 @@ export class TspConfigPythonMgmtPackageDirectorySubRule extends TspconfigEmitter
}
}

export class TspConfigPythonMgmtPackageNameEqualStringSubRule extends TspconfigEmitterOptionsSubRuleBase {
// ----- Python data plane sub rules -----
export class TspConfigPythonDpPackageDirectorySubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-python", "package-name", "{package-dir}");
super("@azure-tools/typespec-python", "package-dir", new RegExp(/^azure(-[a-z]+){1,3}$/));
}
protected skip(_: any, folder: string) {
return skipForDataPlane(folder);
return skipForManagementPlane(folder);
}
}

export class TspConfigPythonMgmtGenerateTestTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
// ----- Python azure sub rules -----
export class TspConfigPythonAzPackageNameEqualStringSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-python", "generate-test", true);
super("@azure-tools/typespec-python", "package-name", "{package-dir}");
}
protected skip(_: any, folder: string) {
return skipForDataPlane(folder);
}

export class TspConfigPythonAzGenerateTestTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-python", "generate-test", true);
}
}

export class TspConfigPythonMgmtGenerateSampleTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
export class TspConfigPythonAzGenerateSampleTrueSubRule extends TspconfigEmitterOptionsSubRuleBase {
constructor() {
super("@azure-tools/typespec-python", "generate-sample", true);
}
protected skip(_: any, folder: string) {
return skipForDataPlane(folder);
}
}

// ----- CSharp sub rules -----
Expand Down Expand Up @@ -431,9 +433,10 @@ export const defaultRules = [
new TspConfigGoDpPackageDirectoryMatchPatternSubRule(),
new TspConfigGoDpModuleMatchPatternSubRule(),
new TspConfigPythonMgmtPackageDirectorySubRule(),
new TspConfigPythonMgmtPackageNameEqualStringSubRule(),
new TspConfigPythonMgmtGenerateTestTrueSubRule(),
new TspConfigPythonMgmtGenerateSampleTrueSubRule(),
new TspConfigPythonDpPackageDirectorySubRule(),
new TspConfigPythonAzPackageNameEqualStringSubRule(),
new TspConfigPythonAzGenerateTestTrueSubRule(),
new TspConfigPythonAzGenerateSampleTrueSubRule(),
new TspConfigCsharpAzPackageDirectorySubRule(),
new TspConfigCsharpAzNamespaceEqualStringSubRule(),
new TspConfigCsharpAzClearOutputFolderTrueSubRule(),
Expand Down
62 changes: 52 additions & 10 deletions eng/tools/typespec-validation/test/sdk-tspconfig-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import {
TspConfigGoDpServiceDirMatchPatternSubRule,
TspConfigJavaAzPackageDirectorySubRule,
TspConfigPythonMgmtPackageDirectorySubRule,
TspConfigPythonMgmtPackageNameEqualStringSubRule,
TspConfigPythonMgmtGenerateTestTrueSubRule,
TspConfigPythonMgmtGenerateSampleTrueSubRule,
TspConfigPythonAzPackageNameEqualStringSubRule,
TspConfigPythonAzGenerateTestTrueSubRule,
TspConfigPythonAzGenerateSampleTrueSubRule,
TspConfigCsharpAzPackageDirectorySubRule,
TspConfigCsharpAzNamespaceEqualStringSubRule,
TspConfigCsharpAzClearOutputFolderTrueSubRule,
TspConfigCsharpMgmtPackageDirectorySubRule,
TspconfigSubRuleBase,
TspConfigPythonDpPackageDirectorySubRule,
} from "../src/rules/sdk-tspconfig-validation.js";
import { TsvTestHost } from "./tsv-test-host.js";
import { join } from "path";
Expand Down Expand Up @@ -112,16 +113,17 @@ function createEmitterOptionTestCases(
): Case[] {
const cases: Case[] = [];

const language = emitterName.split("-").pop();
cases.push({
description: `Validate ${emitterName}'s option:${key} with valid value ${validValue}`,
description: `Validate ${language}'s option:${key} with valid value ${validValue}`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName, { key: key, value: validValue }),
success: true,
subRules,
});

cases.push({
description: `Validate ${emitterName}'s option:${key} with invalid value ${invalidValue}`,
description: `Validate ${language}'s option:${key} with invalid value ${invalidValue}`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName, {
key: key,
Expand All @@ -132,7 +134,7 @@ function createEmitterOptionTestCases(
});

cases.push({
description: `Validate ${emitterName}'s option:${key} with undefined value`,
description: `Validate ${language}'s option:${key} with undefined value`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName),
success: allowUndefined ? true : false,
Expand All @@ -141,7 +143,7 @@ function createEmitterOptionTestCases(

if (!allowUndefined && key.includes(".")) {
cases.push({
description: `Validate ${emitterName}'s option:${key} with incomplete key`,
description: `Validate ${language}'s option:${key} with incomplete key`,
folder,
tspconfigContent: createEmitterOptionExample(emitterName, {
key: key.split(".").slice(0, -1).join("."),
Expand Down Expand Up @@ -368,7 +370,7 @@ const pythonManagementPackageNameTestCases = createEmitterOptionTestCases(
"package-name",
"{package-dir}",
"aaa",
[new TspConfigPythonMgmtPackageNameEqualStringSubRule()],
[new TspConfigPythonAzPackageNameEqualStringSubRule()],
);

const pythonManagementGenerateTestTestCases = createEmitterOptionTestCases(
Expand All @@ -377,7 +379,7 @@ const pythonManagementGenerateTestTestCases = createEmitterOptionTestCases(
"generate-test",
true,
false,
[new TspConfigPythonMgmtGenerateTestTrueSubRule()],
[new TspConfigPythonAzGenerateTestTrueSubRule()],
);

const pythonManagementGenerateSampleTestCases = createEmitterOptionTestCases(
Expand All @@ -386,7 +388,43 @@ const pythonManagementGenerateSampleTestCases = createEmitterOptionTestCases(
"generate-sample",
true,
false,
[new TspConfigPythonMgmtGenerateSampleTrueSubRule()],
[new TspConfigPythonAzGenerateSampleTrueSubRule()],
);

const pythonDpPackageDirTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-python",
"",
"package-dir",
"azure-aaa-bbb-ccc",
"azure-aa-b-c-d",
[new TspConfigPythonDpPackageDirectorySubRule()],
);

const pythonAzPackageNameTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-python",
"",
"package-name",
"{package-dir}",
"aaa",
[new TspConfigPythonAzPackageNameEqualStringSubRule()],
);

const pythonAzGenerateTestTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-python",
"",
"generate-test",
true,
false,
[new TspConfigPythonAzGenerateTestTrueSubRule()],
);

const pythonAzGenerateSampleTestCases = createEmitterOptionTestCases(
"@azure-tools/typespec-python",
"",
"generate-sample",
true,
false,
[new TspConfigPythonAzGenerateSampleTrueSubRule()],
);

const csharpAzPackageDirTestCases = createEmitterOptionTestCases(
Expand Down Expand Up @@ -457,6 +495,10 @@ describe("tspconfig", function () {
...pythonManagementPackageNameTestCases,
...pythonManagementGenerateTestTestCases,
...pythonManagementGenerateSampleTestCases,
...pythonDpPackageDirTestCases,
...pythonAzPackageNameTestCases,
...pythonAzGenerateTestTestCases,
...pythonAzGenerateSampleTestCases,
// csharp
...csharpAzPackageDirTestCases,
...csharpAzNamespaceTestCases,
Expand Down
Loading

0 comments on commit 6663932

Please sign in to comment.