Skip to content

Commit 6524d59

Browse files
committed
chore(test): implement POC for ai.json-based tests
Signed-off-by: Tibor Dancs <[email protected]>
1 parent 417f1d7 commit 6524d59

File tree

6 files changed

+168
-12
lines changed

6 files changed

+168
-12
lines changed

tests/playwright/src/ai-lab-extension.spec.ts

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,58 @@ import * as fs from 'node:fs';
5656
import * as path from 'node:path';
5757
import { fileURLToPath } from 'node:url';
5858
import type { AILabTryInstructLabPage } from './model/ai-lab-try-instructlab-page';
59+
import type { AIJsonDto } from './model/ai-json-dto';
60+
61+
const __filename = fileURLToPath(import.meta.url);
62+
const __dirname = path.dirname(__filename);
63+
const TEST_AUDIO_FILE_PATH: string = path.resolve(
64+
__dirname,
65+
'..',
66+
'..',
67+
'playwright',
68+
'resources',
69+
`test-audio-to-text.wav`,
70+
);
71+
const AI_JSON_FILE_PATH: string = path.resolve(
72+
__dirname,
73+
'..',
74+
'..',
75+
'..',
76+
'packages',
77+
'backend',
78+
'src',
79+
'assets',
80+
'ai.json',
81+
);
82+
83+
const aiJSONFile = fs.readFileSync(AI_JSON_FILE_PATH, 'utf8');
84+
const AI_JSON: AIJsonDto = JSON.parse(aiJSONFile) as AIJsonDto;
85+
const AI_APP_MODELS: Set<string> = new Set();
86+
AI_JSON.recipes.forEach(recipe => {
87+
recipe.recommended.forEach(model => {
88+
AI_APP_MODELS.add(model);
89+
});
90+
});
91+
// Create a set of AI models that are not the first recommended model for any app
92+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
93+
const _AI_APP_UNUSED_MODELS: string[] = [
94+
...AI_APP_MODELS.values().filter(model => {
95+
// Check if the model is not the first recommended model for any app
96+
return !Array.from(AI_JSON.recipes).some(recipe => {
97+
return recipe.recommended[0] === model;
98+
});
99+
}),
100+
];
101+
const AI_APP_MODEL_AND_NAMES: Map<string, string[]> = new Map();
102+
AI_JSON.recipes.forEach(recipe => {
103+
const recommendedModel = recipe.recommended.at(0);
104+
if (recommendedModel) {
105+
if (!AI_APP_MODEL_AND_NAMES.has(recommendedModel)) {
106+
AI_APP_MODEL_AND_NAMES.set(recommendedModel, []);
107+
}
108+
AI_APP_MODEL_AND_NAMES.get(recommendedModel)?.push(recipe.name);
109+
}
110+
});
59111

60112
const AI_LAB_EXTENSION_OCI_IMAGE =
61113
process.env.EXTENSION_OCI_IMAGE ?? 'ghcr.io/containers/podman-desktop-extension-ai-lab:nightly';
@@ -83,17 +135,6 @@ const AI_APPS: AiApp[] = [
83135
{ appName: 'Object Detection', appModel: 'facebook/detr-resnet-101' },
84136
];
85137

86-
const __filename = fileURLToPath(import.meta.url);
87-
const __dirname = path.dirname(__filename);
88-
const TEST_AUDIO_FILE_PATH: string = path.resolve(
89-
__dirname,
90-
'..',
91-
'..',
92-
'playwright',
93-
'resources',
94-
`test-audio-to-text.wav`,
95-
);
96-
97138
test.use({
98139
runnerOptions: new RunnerOptions(runnerOptions),
99140
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export interface AIJsonCategoryDto {
20+
id: string;
21+
name: string;
22+
description: string;
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
import type { AIJsonRecipeDto } from './ai-json-recipe-dto';
20+
import type { AIJsonModelDto } from './ai-json-model-dto';
21+
import type { AIJsonCategoryDto } from './ai-json-category-dto';
22+
23+
export interface AIJsonDto {
24+
version: string;
25+
recipes: AIJsonRecipeDto[];
26+
models: AIJsonModelDto[];
27+
categories: AIJsonCategoryDto[];
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export interface AIJsonModelDto {
20+
id: string;
21+
name: string;
22+
description: string;
23+
registry: string;
24+
licence?: string;
25+
url: string;
26+
memory: number;
27+
properties?: Record<string, string>;
28+
sha256: string;
29+
backend: string;
30+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**********************************************************************
2+
* Copyright (C) 2025 Red Hat, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
***********************************************************************/
18+
19+
export interface AIJsonRecipeDto {
20+
id: string;
21+
description: string;
22+
name: string;
23+
repository: string;
24+
ref: string;
25+
icon?: string;
26+
categories: string[];
27+
basedir: string;
28+
readme?: string;
29+
recommended: string[];
30+
backend: string;
31+
languages: string[];
32+
frameworks: string[];
33+
}

tests/playwright/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"compilerOptions": {
33
"target": "esnext",
44
"module": "esnext",
5-
"moduleResolution":"node",
5+
"moduleResolution": "node",
66
"strict": true,
77
"preserveValueImports": false,
88
"skipLibCheck": false,
99
"baseUrl": ".",
10+
"resolveJsonModule": true
1011
},
1112
"include": ["src/**/*.ts", "playwright.config.ts"],
1213
"exclude": ["node_modules/**"]

0 commit comments

Comments
 (0)