Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Commit

Permalink
Merge branch 'main' into specs_fix-auth-mockapi
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Oct 16, 2024
2 parents 25e7de2 + afce8be commit 292a048
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@azure-tools/cadl-ranch-specs": patch
---

fix(test): adopt `coercedBodyEquals`
Back port fix on route mockapi.
5 changes: 0 additions & 5 deletions .changeset/serious-penguins-sniff.md

This file was deleted.

7 changes: 7 additions & 0 deletions .changeset/warm-wasps-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@azure-tools/cadl-ranch-coverage-sdk": minor
"@azure-tools/cadl-ranch-dashboard": minor
"@azure-tools/cadl-ranch": minor
---

Add dashboard for Azure Resource Manager.
5 changes: 4 additions & 1 deletion packages/cadl-ranch-coverage-sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export const GeneratorMode: string[] = ["azure", "standard"];
export enum GeneratorMode {
azure = "azure",
standard = "standard",
}
6 changes: 3 additions & 3 deletions packages/cadl-ranch-dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
## Dev

```bash
npm start
npm run start
# or
npm dev
npm run dev
```

## Show the test generator

Add `?showtest=true` query parameter to url https://localhost:5173/?showtest=true
Add `?showtest=true` query parameter to url http://localhost:5173/?showtest=true
54 changes: 32 additions & 22 deletions packages/cadl-ranch-dashboard/src/apis.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
CadlRanchCoverageClient,
GeneratorMode,
ResolvedCoverageReport,
ScenarioData,
ScenarioManifest,
GeneratorMode,
} from "@azure-tools/cadl-ranch-coverage-sdk";
import { TableConfig, TableConfigs } from "./constants.js";

const storageAccountName = "azuresdkcadlranch";

Expand Down Expand Up @@ -35,7 +37,7 @@ const generatorNames: GeneratorNames[] = [
export interface CoverageSummary {
manifest: ScenarioManifest;
generatorReports: Record<GeneratorNames, ResolvedCoverageReport | undefined>;
mode: string;
tableConfig: TableConfig;
}

let client: CadlRanchCoverageClient | undefined;
Expand All @@ -57,34 +59,42 @@ export async function getCoverageSummaries(): Promise<CoverageSummary[]> {
coverageClient.manifest.get(),
loadReports(coverageClient, generatorNames),
]);
return GeneratorMode.map((mode) => ({
manifest,
generatorReports: generatorReports[mode],
mode,
}));
return TableConfigs.map((config) => {
const copiedManifest: ScenarioManifest = JSON.parse(JSON.stringify(manifest));
copiedManifest.scenarios = manifest.scenarios.filter((scenarioData: ScenarioData) =>
config.scenarioFilter ? config.scenarioFilter(scenarioData.name) : () => true,
);
return {
manifest: copiedManifest,
generatorReports: generatorReports[config.mode],
tableConfig: config,
};
});
}

async function loadReports(
coverageClient: CadlRanchCoverageClient,
generatorNames: GeneratorNames[],
): Promise<{ [mode: string]: Record<GeneratorNames, ResolvedCoverageReport | undefined> }> {
const results = await Promise.all(
GeneratorMode.map(async (mode): Promise<[string, Record<GeneratorNames, ResolvedCoverageReport | undefined>]> => {
const items = await Promise.all(
generatorNames.map(async (generatorName): Promise<[GeneratorNames, ResolvedCoverageReport | undefined]> => {
try {
const report = await coverageClient.coverage.getLatestCoverageFor(generatorName, mode);
return [generatorName, report];
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error resolving report", error);
Object.keys(GeneratorMode).map(
async (mode): Promise<[string, Record<GeneratorNames, ResolvedCoverageReport | undefined>]> => {
const items = await Promise.all(
generatorNames.map(async (generatorName): Promise<[GeneratorNames, ResolvedCoverageReport | undefined]> => {
try {
const report = await coverageClient.coverage.getLatestCoverageFor(generatorName, mode);
return [generatorName, report];
} catch (error) {
// eslint-disable-next-line no-console
console.error("Error resolving report", error);

return [generatorName, undefined];
}
}),
);
return [mode, Object.fromEntries(items) as any];
}),
return [generatorName, undefined];
}
}),
);
return [mode, Object.fromEntries(items) as any];
},
),
);

return results.reduce<{ [mode: string]: Record<GeneratorNames, ResolvedCoverageReport | undefined> }>(
Expand Down
24 changes: 22 additions & 2 deletions packages/cadl-ranch-dashboard/src/components/dashboard-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,15 @@ const DashboardHeaderRow: FunctionComponent<DashboardHeaderRowProps> = ({ covera
}
return [language, getCompletedRatio(coverageSummary.manifest.scenarios, report), report];
});
let tableHeader;
if (coverageSummary.tableConfig.name) {
tableHeader = <th>Scenario name ({coverageSummary.tableConfig.name})</th>;
} else {
tableHeader = <th>Scenario name ({coverageSummary.tableConfig.mode})</th>;
}
return (
<tr>
<th>Scenario name (mode: {coverageSummary.mode})</th>
{tableHeader}
{data.map(([lang, status, report]) => (
<GeneratorHeaderCell key={lang} status={status} report={report} language={lang} />
))}
Expand Down Expand Up @@ -286,5 +292,19 @@ function createTree(manifest: ScenarioManifest): ManifestTreeNode {

current.scenario = scenario;
}
return root;

return cutTillMultipleChildren(root);
}

function cutTillMultipleChildren(node: ManifestTreeNode): ManifestTreeNode {
let newRoot: ManifestTreeNode = node;
while (newRoot.children) {
if (Object.keys(newRoot.children).length === 1) {
newRoot = Object.values(newRoot.children)[0];
} else {
break;
}
}

return newRoot;
}
21 changes: 21 additions & 0 deletions packages/cadl-ranch-dashboard/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GeneratorMode } from "@azure-tools/cadl-ranch-coverage-sdk";

export const Colors = {
bgSubtle: "#f7f7f7",
borderDefault: "#f0f0f0",
Expand Down Expand Up @@ -38,3 +40,22 @@ export const ScenarioStatusColors = {
notSupported: Colors.borderDefault,
fail: Colors.error,
};

export const TableConfigs: TableConfig[] = [
{
mode: GeneratorMode.azure,
scenarioFilter: (name) => !name.startsWith("Azure_ResourceManager_"),
name: "Azure DPG",
},
{ mode: GeneratorMode.azure, scenarioFilter: (name) => name.startsWith("Azure_ResourceManager_"), name: "Azure MPG" },
{
mode: GeneratorMode.standard,
scenarioFilter: (name) => !name.startsWith("Azure_ResourceManager_"),
},
];

export interface TableConfig {
mode: GeneratorMode;
scenarioFilter?: (scenarioName: string) => boolean;
name?: string;
}
7 changes: 7 additions & 0 deletions packages/cadl-ranch-specs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @azure-tools/cadl-ranch-specs

## 0.37.7

### Patch Changes

- ecfd2f0: fix(test): adopt `coercedBodyEquals`
- 86817b9: Fix explode array mockapi in routes.

## 0.37.6

### Patch Changes
Expand Down
31 changes: 13 additions & 18 deletions packages/cadl-ranch-specs/http/routes/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,29 @@ export const Scenarios: Record<string, ScenarioMockApi> = {};

function createTests(uri: string) {
const url = new URL("http://example.com" + uri);
const searchParams = url.searchParams;
const params: Record<string, any> = {};
for (const [key, value] of searchParams) {
params[key] = value;
const queryMap = new Map<string, string | string[]>();
for (const [key, value] of url.searchParams.entries()) {
if (queryMap.has(key)) {
const existing = queryMap.get(key)!;
if (Array.isArray(existing)) {
existing.push(value);
} else {
queryMap.set(key, [existing, value]);
}
} else {
queryMap.set(key, value);
}
}
return passOnSuccess({
uri: url.pathname,
method: "get",
request: {
params,
params: Object.fromEntries(queryMap),
},
response: {
status: 204,
},
handler: (req: MockRequest) => {
const queryMap = new Map<string, string | string[]>();
for (const [key, value] of url.searchParams.entries()) {
if (queryMap.has(key)) {
const existing = queryMap.get(key)!;
if (Array.isArray(existing)) {
existing.push(value);
} else {
queryMap.set(key, [existing, value]);
}
} else {
queryMap.set(key, value);
}
}
for (const [key, value] of queryMap.entries()) {
if (Array.isArray(value)) {
req.expect.containsQueryParam(key, value, "multi");
Expand Down
2 changes: 1 addition & 1 deletion packages/cadl-ranch-specs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/cadl-ranch-specs",
"version": "0.37.6",
"version": "0.37.7",
"description": "Cadl scenarios and mock apis",
"main": "dist/index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion packages/cadl-ranch/src/coverage/scenario-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export function createScenarioManifest(
};
return { name, scenarioDoc, location };
}),
modes: GeneratorMode,
modes: Object.values(GeneratorMode),
};
}

0 comments on commit 292a048

Please sign in to comment.