Skip to content

Commit e5e1d2e

Browse files
ergunshDevtools-frontend LUCI CQ
authored andcommitted
[AutoRun] Move all files to TS in a new folder, add npm scripts
Bug: none Change-Id: Icea4a123a218ecbc2db184d4fed201ab270782fc Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6519933 Reviewed-by: Mathias Bynens <mathias@chromium.org> Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> Commit-Queue: Ergün Erdoğmuş <ergunsh@chromium.org>
1 parent 2b94987 commit e5e1d2e

File tree

8 files changed

+34
-34
lines changed

8 files changed

+34
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config.gypi
2626
npm-debug.log
2727
/scripts/protocol_typescript/*.js
2828
/scripts/ai_assistance/data
29+
/scripts/ai_assistance/auto-run/data
2930
/scripts/ai_assistance/performance-trace-downloads
3031

3132
/build

scripts/ai_assistance/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
This directory contains scripts for the prompt iteration & evaluation process for AI Assistance.
44

5-
Mainly, `auto-run.ts` script takes example URLs, runs the examples and outputs the results to the `data/` directory. Then, the HTML page in `eval/` folder
6-
takes these results and presents them in a UI for evaluation.
5+
Mainly, `auto-run/auto-run.ts` script takes example URLs, runs the examples and outputs the results to the `auto-run/data/` directory. Then, the HTML page in `eval/` folder takes these results and presents them in a UI for evaluation.
76

87
## Running
98

@@ -22,16 +21,16 @@ takes these results and presents them in a UI for evaluation.
2221

2322
3. Close the DevTools window for the initial `about:blank` page but keep the tab open.
2423

25-
4. Run the following command. See below for the list of values `--test-target` supports. This flag is used to determine which AI experience is evaluated.
24+
4. Run the following command from the `scripts/ai_assistance` folder. See below for the list of values `--test-target` supports. This flag is used to determine which AI experience is evaluated.
2625
```
27-
node --no-warnings --experimental-strip-types scripts/ai_assistance/auto-run.ts --test-target elements --example-urls <example-url-1> <example-url-2>
26+
npm run auto-run -- --test-target elements --example-urls <example-url-1> <example-url-2>
2827
```
2928

30-
At the end of these steps, the examples in the urls `<example-url-1>` and `<example-url-2>` should be run and the results must be saved to the `data/` folder.
29+
At the end of these steps, the examples in the urls `<example-url-1>` and `<example-url-2>` should be run and the results must be saved to the `auto-run/data/` folder.
3130

3231
Tip: You can add a `--label <label>` argument to the run to label the dataset. For example:
3332
```
34-
node --no-warnings --experimental-strip-types scripts/ai_assistance/auto-run.ts --label title-change --example-urls <example-url-1> <example-url-2>
33+
npm run auto-run -- --label title-change --example-urls <example-url-1> <example-url-2>
3534
```
3635

3736
## `--test-target` values
@@ -49,7 +48,7 @@ compatible with the eval UI.
4948
## Evaluating the results
5049

5150
**Steps**
52-
1. Serve the `scripts/ai_assistance` folder by using a simple file server. For example:
51+
1. Serve the `scripts/ai_assistance` folder in 8000 port by using a simple file server. For example:
5352
```
5453
python3 -m http.server
5554
```

scripts/ai_assistance/auto-run-helpers.js renamed to scripts/ai_assistance/auto-run/auto-run-helpers.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424
* @param {string} comment The comment string to split.
2525
* @return {Record<string, string>} An object containing the found keys and their values.
2626
*/
27-
export function parseComment(comment) {
27+
export function parseComment(comment: string): Record<string, string> {
2828
// Tracks which section of the comment we are in so we know where to
2929
// associate lines with.
30-
/** @type {string|null} */
31-
let activeKey = null;
30+
let activeKey: string|null = null;
3231

33-
/** @type {Record<string, string[]>} */
34-
const lines = {
32+
const lines: Record<string, string[]> = {
3533
// We may get other keys, but these two are required.
3634
explanation: [],
3735
prompt: [],
@@ -70,21 +68,15 @@ export function parseComment(comment) {
7068
}
7169
}
7270

73-
/** @type {Record<string, string>} */
74-
const result = {};
71+
const result: Record<string, string> = {};
7572
Object.keys(lines).forEach(lineKey => {
7673
result[lineKey] = lines[lineKey].join('\n');
7774
});
7875
return result;
7976
}
8077

81-
/**
82-
* @param {Record<string, string>} comment
83-
* @return {string[]}
84-
*/
85-
export function parseFollowUps(comment) {
86-
/** @type {string[]} */
87-
const followUpPrompts = [];
78+
export function parseFollowUps(comment: Record<string, string>): string[] {
79+
const followUpPrompts: string[] = [];
8880
const FOLLOW_UP_PREFIX = 'followup';
8981
Object.entries(comment).forEach(([key, value]) => {
9082
if (key.toLowerCase().startsWith(FOLLOW_UP_PREFIX)) {

scripts/ai_assistance/auto-run.test.js renamed to scripts/ai_assistance/auto-run/auto-run.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
/**
66
* Tests for parts of the AI Assistance auto-run script.
77
* NOTE: these are not run on CQ but exist to help you locally.
8-
* Run these with `npx mocha scripts/ai_assistance/auto-run.test.js`
8+
* Run these with `npm run auto-run:test` from `scripts/ai_assistance` folder.
99
*/
10+
import {assert} from 'chai';
1011

11-
const {assert} = require('chai');
12-
13-
const {parseComment, parseFollowUps} = require('./auto-run-helpers.js');
12+
import {parseComment, parseFollowUps} from './auto-run-helpers.ts';
1413

1514
describe('parsing comments', () => {
1615
it('parses out the prompt and evaluation sections using the "old" syntax', () => {

scripts/ai_assistance/auto-run.ts renamed to scripts/ai_assistance/auto-run/auto-run.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// found in the LICENSE file.
44

55
import * as fs from 'fs';
6+
// We don't have types for `js-yaml` in the codebase.
7+
// @ts-expect-error
68
import * as yaml from 'js-yaml';
79
import * as url from 'node:url';
810
import * as path from 'path';
@@ -11,9 +13,10 @@ import puppeteer from 'puppeteer-core';
1113
import {hideBin} from 'yargs/helpers';
1214
import yargs from 'yargs/yargs';
1315

14-
import {parseComment, parseFollowUps} from './auto-run-helpers.js';
1516
import type {
16-
ExampleMetadata, ExecutedExample, IndividualPromptRequestResponse, Logs, PatchTest, RunResult} from './types.js';
17+
ExampleMetadata, ExecutedExample, IndividualPromptRequestResponse, Logs, PatchTest, RunResult} from '../types';
18+
19+
import {parseComment, parseFollowUps} from './auto-run-helpers.ts';
1720

1821
// eslint-disable-next-line @typescript-eslint/naming-convention
1922
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

scripts/ai_assistance/eval/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
const FREESTYLER_SERVER_URL = 'http://localhost:8000';
5+
const DATA_URL = 'http://localhost:8000/auto-run/data';
66
const Utils = {
77
jsonToAsciiTable(data) {
88
const exampleIdEvaluations = {};
@@ -138,7 +138,7 @@ const Utils = {
138138
const examplesMapCache = {};
139139
const API = {
140140
fetchDatasets: async () => {
141-
const datasetNamesHtml = await (await fetch(`${FREESTYLER_SERVER_URL}/data`)).text();
141+
const datasetNamesHtml = await (await fetch(DATA_URL)).text();
142142
const parser = new DOMParser();
143143
const document = parser.parseFromString(datasetNamesHtml, 'text/html');
144144
const links = document.querySelectorAll('a');
@@ -150,7 +150,7 @@ const API = {
150150
return examplesMapCache[title];
151151
}
152152

153-
const {examples, metadata} = await (await fetch(`${FREESTYLER_SERVER_URL}/data/${title}`)).json();
153+
const {examples, metadata} = await (await fetch(`${DATA_URL}/${title}`)).json();
154154
examples.sort((ex1, ex2) => ex1.exampleId > ex2.exampleId ? 1 : ex1.exampleId < ex2.exampleId ? -1 : 0);
155155
const examplesMap = {};
156156
for (const example of examples) {

scripts/ai_assistance/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
{
2-
"type": "module"
3-
}
2+
"type": "module",
3+
"scripts": {
4+
"auto-run": "node --no-warnings --experimental-strip-types auto-run/auto-run.ts",
5+
"auto-run:test": "npx --node-options='--no-warnings --experimental-strip-types' mocha auto-run/auto-run.test.ts"
6+
}
7+
}

scripts/ai_assistance/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"allowJs": true,
77
"module": "ESNext",
88
"moduleResolution": "Bundler",
9-
"target": "ESNext"
9+
"target": "ESNext",
10+
"noEmit": true,
11+
"allowImportingTsExtensions": true,
1012
},
11-
"include": ["./auto-run-helpers.js", "auto-run.ts", "./auto-run.test.js"]
13+
"include": ["auto-run/*"]
1214
}

0 commit comments

Comments
 (0)