qa 0.1.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ide/index.js DELETED
@@ -1,184 +0,0 @@
1
- import url from 'node:url';
2
- import path from 'node:path';
3
- import logger from '@wdio/logger';
4
- import getPort from 'get-port';
5
- import Fastify from 'fastify';
6
- import staticServer from '@fastify/static';
7
- import websocket from '@fastify/websocket';
8
- import { v4 as uuidv4 } from 'uuid';
9
- import { NeuralSpec } from 'neuralspec';
10
- import { WebSocketClient } from '@vollq/contracts';
11
- import { spinner, log } from '@clack/prompts';
12
- import { setupBrowserEnvironment, attachTokenToWindow, getCacheDir } from './utils.js';
13
- import { login } from '../commands/login.js';
14
- const cacheDir = await getCacheDir();
15
- logger.setLevel('@wdio/utils', 'error');
16
- logger.setLevel('webdriver', 'error');
17
- export class IDE {
18
- #spinner = spinner();
19
- #isShuttingDown = false;
20
- #cacheDir = cacheDir;
21
- #token;
22
- #messager;
23
- #fastify;
24
- #ideSession;
25
- #workbenchSession;
26
- static start(token) {
27
- const ideApp = new IDE(token);
28
- return ideApp.start();
29
- }
30
- constructor(token) {
31
- this.#token = token;
32
- this.#fastify = Fastify({
33
- logger: {
34
- file: path.resolve(cacheDir, 'ide.log'),
35
- level: 'info'
36
- }
37
- });
38
- }
39
- async start() {
40
- this.#spinner.start('Starting VollQ IDE...');
41
- const [url] = await Promise.all([
42
- this.#startApplication(),
43
- setupBrowserEnvironment(this.#cacheDir, this.#token).then(({ ide, workbench }) => {
44
- this.#ideSession = ide;
45
- this.#workbenchSession = workbench;
46
- })
47
- ]);
48
- await this.#startSessions(url);
49
- this.#spinner.stop(`VollQ IDE is running on ${url}.`);
50
- log.message('Welcome 😊👐!');
51
- log.message('Press CTRL+C to shutdown the application');
52
- return this;
53
- }
54
- async handleShutdown() {
55
- if (this.#isShuttingDown) {
56
- return;
57
- }
58
- this.#spinner.start('Shutting down the VollQ IDE...');
59
- this.#isShuttingDown = true;
60
- try {
61
- this.#messager = undefined;
62
- this.#fastify.log.info('Shutting down the VollQ IDE');
63
- await Promise.all([
64
- this.#ideSession?.deleteSession(),
65
- this.#workbenchSession?.deleteSession(),
66
- this.#fastify.close()
67
- ]).catch((err) => {
68
- this.#fastify.log.error('Failed to close the application', err);
69
- });
70
- this.#spinner.stop('See you next time 👋');
71
- process.exit(0);
72
- }
73
- catch (error) {
74
- console.error('Error during shutdown:', error);
75
- process.exit(1);
76
- }
77
- }
78
- async #startApplication() {
79
- try {
80
- const appPath = path.dirname(url.fileURLToPath(import.meta.resolve('@vollq/ide')));
81
- /**
82
- * do all this async work in parallel
83
- */
84
- const [port] = await Promise.all([
85
- /**
86
- * pick between 6000 and 6005 which are whitelisted ports to access the API without CORS
87
- */
88
- getPort({ port: [...Array(5)].map((_, i) => i + 8000) }),
89
- this.#fastify.register(websocket),
90
- this.#fastify.register(staticServer, {
91
- root: appPath,
92
- prefix: '/',
93
- index: 'index.html'
94
- })
95
- ]);
96
- this.#fastify.log.info(`Serve IDE from ${appPath}`);
97
- this.#fastify.get('/ws', { websocket: true }, (socket) => {
98
- this.#messager = new WebSocketClient(socket);
99
- this.#messager.onCommand('runWorkflow', this.#runSuggestion.bind(this));
100
- this.#messager.onCommand('runTest', this.#runTest.bind(this));
101
- this.#messager.onCommand('closeApp', this.handleShutdown.bind(this));
102
- this.#messager.onCommand('login', this.#login.bind(this));
103
- });
104
- const ideUrl = await this.#fastify.listen({ port });
105
- this.#fastify.log.info(`IDE is running on ${ideUrl}`);
106
- return ideUrl;
107
- }
108
- catch (err) {
109
- this.#fastify.log.error('Failed to start the VollQ IDE', err);
110
- throw err;
111
- }
112
- }
113
- async #startSessions(url) {
114
- if (!this.#ideSession || !this.#workbenchSession) {
115
- throw new Error('IDE session is not available');
116
- }
117
- try {
118
- /**
119
- * Inject the token into the IDE session
120
- */
121
- if (this.#token) {
122
- await this.#registerToken(this.#token);
123
- }
124
- await Promise.all([
125
- this.#ideSession.url(url),
126
- this.#workbenchSession.url('https://vollq.ai'),
127
- ]);
128
- }
129
- catch (err) {
130
- console.error('Failed to start the VollQ IDE', err);
131
- }
132
- }
133
- #registerToken(token) {
134
- return Promise.all([
135
- this.#ideSession?.addInitScript(attachTokenToWindow, token),
136
- this.#ideSession?.execute(attachTokenToWindow, token)
137
- ]).catch((err) => {
138
- this.#fastify.log.error('Failed to attach token to the IDE session', err);
139
- });
140
- }
141
- async #runSuggestion({ prompt }) {
142
- if (!this.#workbenchSession) {
143
- throw new Error('Workbench session is not available');
144
- }
145
- const ai = new NeuralSpec({
146
- driver: this.#workbenchSession,
147
- token: this.#token
148
- });
149
- ai.onAgentEvent((event) => {
150
- this.#messager?.emit('agentEvent', event);
151
- });
152
- return ai.do(prompt).end({ closeBrowserSession: false })
153
- .then(({ workflowId }) => {
154
- if (workflowId) {
155
- this.#messager?.emit('workflowFinished', { workflowId });
156
- }
157
- return ({ result: 'success', workflowId });
158
- }, (err) => {
159
- const error = err instanceof Error ? err : new Error(`An error occurred: ${err}`);
160
- const message = `Failed to run the suggestion: ${prompt}, ${error.message}`;
161
- this.#fastify.log.error(error.stack);
162
- return { error: message, result: 'error' };
163
- });
164
- }
165
- async #runTest({ name }) {
166
- if (!this.#workbenchSession) {
167
- throw new Error('IDE session is not available');
168
- }
169
- this.#fastify.log.info(`Run test "${name}" in workbench`);
170
- await this.#workbenchSession.startTest(name);
171
- }
172
- async #login() {
173
- const ticket = uuidv4();
174
- try {
175
- const token = await login(ticket, this.#fastify.log.info.bind(this.#fastify.log));
176
- await this.#registerToken(token);
177
- return { token };
178
- }
179
- catch (err) {
180
- this.#fastify.log.error(`Failed to log-in: ${err.message}`);
181
- return {};
182
- }
183
- }
184
- }
@@ -1,19 +0,0 @@
1
- declare const appSettings: {
2
- readonly ide: {
3
- readonly size: "500,900";
4
- readonly position: "1590,100";
5
- };
6
- readonly workbench: {
7
- readonly size: "1440,900";
8
- readonly position: "100,100";
9
- };
10
- };
11
- export declare function getCapabilities(appName: keyof typeof appSettings, token?: string): WebdriverIO.Capabilities;
12
- export declare function getCacheDir(): Promise<string>;
13
- export declare function attachTokenToWindow(token: string): void;
14
- export declare function setupBrowserEnvironment(cacheDir: string, token?: string): Promise<{
15
- workbench: WebdriverIO.Browser;
16
- ide: WebdriverIO.Browser;
17
- }>;
18
- export {};
19
- //# sourceMappingURL=utils.d.ts.map
package/dist/ide/utils.js DELETED
@@ -1,102 +0,0 @@
1
- import os from 'node:os';
2
- import path from 'node:path';
3
- import fs from 'node:fs/promises';
4
- import LocalDriver from 'localdriver';
5
- import { remote } from 'webdriverio';
6
- // @ts-expect-error types are missing
7
- import { setupDriver, setupBrowser } from '@wdio/utils/node';
8
- const appSettings = {
9
- ide: {
10
- size: '500,900',
11
- position: '1590,100'
12
- },
13
- workbench: {
14
- size: '1440,900',
15
- position: '100,100'
16
- }
17
- };
18
- export function getCapabilities(appName, token) {
19
- const appArgs = [
20
- '--use-mock-keychain',
21
- '--password-store=basic',
22
- '--disable-password-manager',
23
- '--disable-save-password-bubble',
24
- '--disable-notifications',
25
- '--disable-infobars'
26
- ];
27
- const prefs = {
28
- 'profile.password_manager_leak_detection': false
29
- };
30
- /**
31
- * when in development, open IDE with devtools opened
32
- */
33
- if (typeof process.argv[1] === 'string' && process.argv[1].includes('packages/qa/') && appName === 'ide') {
34
- appArgs.push('auto-open-devtools-for-tabs', 'new-window', 'start-maximized', 'disable-infobars');
35
- Object.assign(prefs, {
36
- devtools: {
37
- preferences: {
38
- 'panel-selectedTab': '"console"',
39
- currentDockState: '"undocked"',
40
- }
41
- }
42
- });
43
- }
44
- return {
45
- browserName: 'chrome',
46
- browserVersion: 'latest',
47
- 'wdio:chromedriverOptions': {
48
- /**
49
- * spawn driver process in detached mode so we can smoothly close the process
50
- */
51
- spawnOpts: {
52
- detached: true
53
- }
54
- },
55
- 'goog:chromeOptions': {
56
- args: [
57
- `window-size=${appSettings[appName].size}`,
58
- `window-position=${appSettings[appName].position}`,
59
- ...appArgs
60
- ],
61
- prefs
62
- },
63
- ...(token ? { 'vollq:token': token } : {})
64
- };
65
- }
66
- export async function getCacheDir() {
67
- const cacheDir = path.join(os.tmpdir(), '.vollq');
68
- await fs.mkdir(cacheDir, { recursive: true });
69
- return cacheDir;
70
- }
71
- export function attachTokenToWindow(token) {
72
- // @ts-expect-error missing window types
73
- globalThis.window.__VOLLQ_TOKEN = token;
74
- }
75
- export async function setupBrowserEnvironment(cacheDir, token) {
76
- const workbenchConfig = {
77
- /**
78
- * run workbench with `localdriver` package so we can request tests to
79
- * execute from the cloud
80
- */
81
- automationProtocol: LocalDriver.protocolPath,
82
- logLevel: 'info',
83
- outputDir: cacheDir,
84
- cacheDir,
85
- capabilities: getCapabilities('workbench', token),
86
- };
87
- const ideConfig = {
88
- logLevel: 'info',
89
- outputDir: cacheDir,
90
- cacheDir,
91
- capabilities: getCapabilities('ide', token)
92
- };
93
- await Promise.all([
94
- setupDriver(workbenchConfig, [workbenchConfig.capabilities]),
95
- setupBrowser(workbenchConfig, [workbenchConfig.capabilities]),
96
- ]);
97
- const [workbench, ide] = await Promise.all([
98
- remote(workbenchConfig),
99
- remote(ideConfig)
100
- ]);
101
- return { workbench, ide };
102
- }
package/dist/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export declare function run(): Promise<{
2
- [x: string]: unknown;
3
- _: (string | number)[];
4
- $0: string;
5
- } | {
6
- [x: string]: unknown;
7
- _: (string | number)[];
8
- $0: string;
9
- }>;
10
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js DELETED
@@ -1,24 +0,0 @@
1
- import yargs from 'yargs';
2
- import { hideBin } from 'yargs/helpers';
3
- import { pkg, CLI_EPILOGUE } from './constants.js';
4
- import { commands } from './commands/index.js';
5
- const DESCRIPTION = [
6
- 'The `qa` command allows you to ...',
7
- '',
8
- '$ qa test my-test-project',
9
- '',
10
- 'For more information, visit: https://vollq.ai/docs/cli'
11
- ];
12
- export async function run() {
13
- const argv = yargs(hideBin(process.argv))
14
- .command(commands)
15
- .example('qa start', 'Starts the VollQ IDE')
16
- .example('qa login', 'Logs you into the platform')
17
- .example('qa init', 'Creates a new VollQ project')
18
- .example('qa test myAPI', 'Runs test on API named "myAPI"')
19
- .updateStrings({ 'Commands:': `${DESCRIPTION.join('\n')}\n\nCommands:` })
20
- .version(pkg.version)
21
- .demandCommand()
22
- .epilogue(CLI_EPILOGUE);
23
- return argv.parse();
24
- }
@@ -1,8 +0,0 @@
1
- import { type TestEvent } from 'node:test/reporters';
2
- export declare class CLIReporter {
3
- #private;
4
- constructor();
5
- emitEvent(events: TestEvent[]): void;
6
- end(): void;
7
- }
8
- //# sourceMappingURL=reporter.d.ts.map
package/dist/reporter.js DELETED
@@ -1,24 +0,0 @@
1
- import { spec } from 'node:test/reporters';
2
- export class CLIReporter {
3
- #reporter;
4
- constructor() {
5
- this.#reporter = new spec();
6
- console.log('');
7
- }
8
- emitEvent(events) {
9
- events.map((ev) => {
10
- if (ev.type === 'test:fail') {
11
- const error = ev.data.details.error.cause;
12
- if (typeof error === 'object' && 'message' in error && 'stack' in error) {
13
- const newError = new Error(error.message);
14
- newError.stack = error.stack;
15
- ev.data.details.error.cause = newError;
16
- }
17
- }
18
- return ev;
19
- }).forEach((ev) => (this.#reporter._transform(ev, 'utf-8', (_, report) => process.stdout.write(report || ''))));
20
- }
21
- end() {
22
- this.#reporter._flush((_, log) => process.stdout.write(log || ''));
23
- }
24
- }
@@ -1,3 +0,0 @@
1
- import type { TestCommandParameters } from '../commands/types.js';
2
- export declare function runUITest(token: string, argv: TestCommandParameters): Promise<void>;
3
- //# sourceMappingURL=index.d.ts.map
package/dist/ui/index.js DELETED
@@ -1,29 +0,0 @@
1
- import LocalDriver from 'localdriver';
2
- import { remote } from 'webdriverio';
3
- import { CLIReporter } from '../reporter.js';
4
- export async function runUITest(token, argv) {
5
- let driver;
6
- const reporterProcess = new CLIReporter();
7
- try {
8
- driver = await remote({
9
- automationProtocol: LocalDriver.protocolPath,
10
- logLevel: 'error',
11
- capabilities: {
12
- browserName: 'chrome',
13
- // @ts-expect-error not yet types
14
- 'vollq:token': token
15
- }
16
- });
17
- await driver.startTest(argv.project, reporterProcess.emitEvent.bind(reporterProcess));
18
- }
19
- catch (err) {
20
- const error = err instanceof Error ? err : new Error(`Failed to run test: ${err}`);
21
- console.error(error);
22
- process.exit(1);
23
- }
24
- finally {
25
- await driver?.deleteSession();
26
- reporterProcess.end();
27
- console.log('');
28
- }
29
- }