Skip to content

Commit

Permalink
Initial test framework for emitter (#1394)
Browse files Browse the repository at this point in the history
* Initial test framework for emitter

* Remove the modules folder
  • Loading branch information
dolauli authored Nov 1, 2024
1 parent d3ec4d1 commit ba4d6fe
Show file tree
Hide file tree
Showing 579 changed files with 157,416 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .azure-pipelines/test-emitter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
pool: pool-windows-2019

steps:
- task: NodeTool@0
displayName: 'Use Node 18'
inputs:
versionSpec: 18.x

- task: Npm@1
displayName: 'Install @typespec/compiler@latest'
inputs:
command: custom
verbose: false
customCommand: 'install -g "@typespec/compiler"'

- task: Npm@1
displayName: 'Install @microsoft/rush'
inputs:
command: custom
verbose: false
customCommand: 'install -g @microsoft/[email protected]'

- task: CmdLine@2
displayName: 'Rush sync-versions'
inputs:
script: 'rush sync-versions'

- task: CmdLine@2
displayName: 'Rush Update'
inputs:
script: 'rush update'

- task: CmdLine@2
displayName: 'Rush Rebuild'
inputs:
script: 'rush rebuild'

- script: npm install
displayName: 'Run npm install in tests-emitter'
workingDirectory: 'tests-upgrade/tests-emitter'

- pwsh: |
./EmitterTest.ps1 -AllowList
workingDirectory: 'tests-upgrade/tests-emitter'
displayName: 'Verify Typespec emitter'

- task: PublishPipelineArtifact@0
displayName: 'Save artifacts'
inputs:
artifactName: CompareResult
targetPath: tests-upgrade/tests-emitter/CompareResult
condition: succeededOrFailed()
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,13 @@ package-deps.json

!/tests/**/test/*

.vscode/
.vscode/

# Ignore generated files for tests-emitter
tests-upgrade/tests-emitter/*/generated/
tests-upgrade/tests-emitter/*/target/generated/modules/
tests-upgrade/tests-emitter/*/tsp-output/
tests-upgrade/tests-emitter/CompareResult

# Ignore the node_modules directory for tests-emitter
tests-upgrade/tests-emitter/node_modules/
4 changes: 4 additions & 0 deletions tests-upgrade/tests-emitter/AzureAI.Assets/client.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import "@azure-tools/typespec-client-generator-core";
import "./main.tsp";

using Azure.ClientGenerator.Core;
30 changes: 30 additions & 0 deletions tests-upgrade/tests-emitter/AzureAI.Assets/common.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;

namespace Microsoft.MachineLearningServices;

@doc("Metadata pertaining to creation and last modification of the resource.")
model SystemData {
@visibility("read")
@doc("The timestamp the resource was created at.")
createdAt?: utcDateTime;

@visibility("read")
@doc("The identity that created the resource.")
createdBy?: string;

@visibility("read")
@doc("The identity type that created the resource.")
createdByType?: string;

@visibility("read")
@doc("The timestamp of resource last modification (UTC)")
lastModifiedAt?: utcDateTime;
}
56 changes: 56 additions & 0 deletions tests-upgrade/tests-emitter/AzureAI.Assets/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import "@typespec/http";
import "@typespec/rest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "./routes.tsp";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;
using Azure.Core.Traits;

@useAuth(
OAuth2Auth<[
{
type: OAuth2FlowType.implicit,
authorizationUrl: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
scopes: ["https://ml.azure.com/.default"],
}
]>
)
@service({
title: "Azure Machine Learning Data Plane Services",
})
@server(
"{endpoint}/genericasset/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}",
"Machinelearning Services Asset APIs",
{
@doc("""
Supported Azure-AI asset endpoints.
""")
endpoint: url,

@doc("The ID of the target subscription.")
subscriptionId: string,

@doc("The name of the Resource Group.")
resourceGroupName: string,

@doc("The name of the AzureML workspace or AI project.")
workspaceName: string,
}
)
@versioned(Versions)
namespace Microsoft.MachineLearningServices;

@doc("Azure Machine Learning Services api versions.")
enum Versions {
@doc("Azure Machine Learning Services api version 2024-04-01-preview.")
@useDependency(Azure.Core.Versions.v1_0_Preview_2)
`2024-04-01-preview`,

@doc("Azure Machine Learning Services api version 2024-05-01-preview.")
@useDependency(Azure.Core.Versions.v1_0_Preview_2)
`2024-05-01-preview`,
}
99 changes: 99 additions & 0 deletions tests-upgrade/tests-emitter/AzureAI.Assets/model.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import "@typespec/rest";
import "@azure-tools/typespec-autorest";
import "@typespec/versioning";
import "@azure-tools/typespec-azure-core";
import "./common.tsp";
import "@typespec/openapi";
import "@typespec/versioning";

using TypeSpec.OpenAPI;
using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.Versioning;
using Azure.Core;
using Azure.Core.Traits;

namespace Microsoft.MachineLearningServices;

@doc("AssetVersion Definition")
model AssetVersion {
@doc("Fully qualified resource Id: azureml://workspace/{workspaceName}/indexes/{name}/versions/{version} of the index.")
@visibility("read")
id: string;

@doc("Update stage to 'Archive' to archive the asset. Default is Development, which means the asset is under development.")
stage?: string = "Development";

@doc("Description information of the asset.")
description?: string;

@doc("Metadata containing createdBy and modifiedBy information.")
@visibility("read")
systemData?: SystemData;

@doc("Asset's tags. Unlike properties, tags are fully mutable.")
tags?: Record<string>;

@doc("Asset's properties. Unlike tags, properties are add-only. Once added, a property cannot be removed.")
properties?: Record<string>;
}

@doc("Index resource Definition")
model Index is AssetVersion {
@doc("Default workspace blob storage Uri. Should work across storage types and auth scenarios.")
storageUri: string;
}

@doc("Paged collection of IndexVersion items.")
@pagedResult
model PagedIndex {
@doc("The list of Indexes.")
@extension("x-ms-identifiers", [])
@items
value: Index[];

@doc("The link to the next page of items")
@nextLink
nextLink?: ResourceLocation<Index>;
}

@doc("Prompt resource definition")
@added(Versions.`2024-05-01-preview`)
model Prompt is AssetVersion {
@doc("Default workspace blob storage Ui. Should work across storage types and auth scenarios.")
dataUri: string;

@doc("Relative path of the prompt data file at the dataUri location")
templatePath: string;
}

@doc("Paged collection of PromptVersion items")
@pagedResult
@added(Versions.`2024-05-01-preview`)
model PagedPrompt {
@doc("The list of Prompts.")
@extension("x-ms-identifiers", [])
@items
value: Prompt[];

@doc("The link to the next page of items")
@nextLink
nextLink?: ResourceLocation<Prompt>;
}

@doc("Next version definition.")
model VersionInfo {
@doc("Next version as defined by the server. The server keeps track of all versions that are string-representations of integers. If one exists, the nextVersion will be a string representation of the highest integer value + 1. Otherwise, the nextVersion will default to '1'.")
nextVersion?: int64;

@doc("Current latest version of the resource.")
latestVersion: string;
}

#suppress "@azure-tools/typespec-providerhub/no-inline-model" "Need to create reponses correctly"
alias ResourceCreatedResponse<T extends TypeSpec.Reflection.Model> = TypeSpec.Http.Response<201> &
T;

#suppress "@azure-tools/typespec-providerhub/no-inline-model" "Need to create reponses correctly"
alias ResourceCreatedOrOkResponse<T extends TypeSpec.Reflection.Model> = ResourceCreatedResponse<T> | (TypeSpec.Http.Response<200> &
T);
Loading

0 comments on commit ba4d6fe

Please sign in to comment.