Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support tunneling #108

Merged
merged 3 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/api/llm/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function generateTest(
assertions: string[],
prevGoal: string = '',
creds: Credentials,
tunnelName: string,
tunnelOwner: string,
): [
WebSocket,
Observable<
Expand Down Expand Up @@ -81,6 +83,8 @@ export function generateTest(
platform: platform,
platform_version: platformVersion,
region: region,
tunnel_name: tunnelName,
tunnel_owner: tunnelOwner,
};

ws.onopen = () => {
Expand All @@ -90,6 +94,8 @@ export function generateTest(
data: {
username: username,
access_key: accessKey,
tunnel_name: tunnelName,
tunnel_owner: tunnelOwner,
app_name: appName,
goal: goal,
num_steps: maxTestSteps,
Expand Down
8 changes: 7 additions & 1 deletion src/editors/TestGenerationPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@

/**
* Sets up an event listener to listen for messages passed from the webview context and
* executes code based on the message that is recieved.
* executes code based on the message that is received.
*
* @param webview A reference to the extension webview
* @param context A reference to the extension context
*/
private _setWebviewMessageListener(webview: Webview) {
webview.onDidReceiveMessage(
async (message: any) => {

Check warning on line 253 in src/editors/TestGenerationPanel.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
switch (message.action) {
case 'ready':
this._msgQueue.ready();
Expand All @@ -265,6 +265,8 @@
message.data.platform,
message.data.platform_version,
message.data.assertions,
message.data.tunnel_name,
message.data.tunnel_owner,
'',
);
} catch (e) {
Expand Down Expand Up @@ -447,6 +449,8 @@
platform: Platform,
platformVersion: string,
assertions: string[],
tunnel_name: string,
tunnel_owner: string,
prevGoal: string,
) {
const creds = this.getCredentials();
Expand Down Expand Up @@ -512,6 +516,8 @@
assertions,
prevGoal,
creds,
tunnel_name,
tunnel_owner,
);
this._socket = ws;

Expand Down Expand Up @@ -558,7 +564,7 @@
}

class MessageQueue {
private _messages: any[];

Check warning on line 567 in src/editors/TestGenerationPanel.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
private _ready: boolean;
private _webview: Webview;

Expand All @@ -568,7 +574,7 @@
this._webview = webview;
}

enqueue(msg: any) {

Check warning on line 577 in src/editors/TestGenerationPanel.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
if (!this._ready) {
this._messages.push(msg);
return;
Expand Down
6 changes: 6 additions & 0 deletions src/panels/test-generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
*/
private subscribeToWebviewEvents(webview: vscode.Webview) {
webview.onDidReceiveMessage(
async (message: any) => {

Check warning on line 150 in src/panels/test-generation.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
switch (message.action) {
case 'stop-generation':
this.stopTestGeneration();
Expand All @@ -162,6 +162,8 @@
message.data.platform,
message.data.platform_version,
message.data.assertions,
message.data.tunnel_name,
message.data.tunnel_owner,
'',
);
} catch (e) {
Expand Down Expand Up @@ -308,6 +310,8 @@
platform: Platform,
platformVersion: string,
assertions: string[],
tunnelName: string,
tunnelOwner: string,
prevGoal: string,
) {
const creds = this.getCredentials();
Expand Down Expand Up @@ -367,6 +371,8 @@
assertions,
prevGoal,
creds,
tunnelName,
tunnelOwner,
);
this.socket = ws;

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface TestRecord {
screen_width?: number;
screen_height?: number;
scriptiq_llm_version?: string;
tunnel_name?: string;
tunnel_owner?: string;
}

export interface TestStep {
Expand Down
44 changes: 42 additions & 2 deletions webview-ui/test-generation/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
const [showAdditionalSettings, setShowAdditionalSettings] = useState(false);

useEffect(() => {
function handler(event: any) {

Check warning on line 29 in webview-ui/test-generation/src/App.tsx

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
const message = event.data as PostedMessage; // The json data that the extension sent

switch (message.action) {
Expand Down Expand Up @@ -106,8 +106,16 @@
});
}, []);

const { appName, assertions, testGoal, maxSteps, platform, status, steps } =
state;
const {
appName,
assertions,
testGoal,
maxSteps,
platform,
status,
steps,
tunnel,
} = state;

return (
<main>
Expand Down Expand Up @@ -166,6 +174,34 @@

{showAdditionalSettings && (
<section className="inputs">
<VSCodeTextField
placeholder="Sauce Connect tunnel name"
onInput={(e) => {
if (e.target && 'value' in e.target) {
dispatch({
type: 'setTunnelName',
value: e.target.value as string,
});
}
}}
value={state.tunnel?.name ?? ''}
>
Tunnel Name
</VSCodeTextField>
<VSCodeTextField
placeholder="Sauce Connect tunnel owner"
onInput={(e) => {
if (e.target && 'value' in e.target) {
dispatch({
type: 'setTunnelOwner',
value: e.target.value as string,
});
}
}}
value={state.tunnel?.owner ?? ''}
>
Tunnel Owner
</VSCodeTextField>
<VSCodeTextField
value={maxSteps.toString()}
onInput={(e) => {
Expand Down Expand Up @@ -260,6 +296,8 @@
devices: state.device ? [state.device] : [],
platform: platform.name,
platform_version: platform.version,
tunnel_name: tunnel?.name,
tunnel_owner: tunnel?.owner,
},
});
}}
Expand Down Expand Up @@ -377,6 +415,8 @@
state.job?.platform.version ?? '',
state.region ?? '',
state.platform.name,
state.tunnel?.name ?? '',
state.tunnel?.owner ?? '',
steps,
);

Expand Down
4 changes: 4 additions & 0 deletions webview-ui/test-generation/src/codegen/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @returns the line of code
*/
abstract genCodeLine(
bestIdentifier: any,

Check warning on line 22 in webview-ui/test-generation/src/codegen/base.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
action: string,
opts?: {
// No idea what this is
Expand Down Expand Up @@ -54,6 +54,8 @@
platform_version: string,
region: string,
platform: string,
tunnel_name: string,
tunnel_owner: string,
): string;

/**
Expand Down Expand Up @@ -82,7 +84,9 @@
platform_version: string,
region: string,
platform: string,
tunnel_name: string,
tunnel_owner: string,
steps: any[],

Check warning on line 89 in webview-ui/test-generation/src/codegen/base.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
): string;

abstract noOptionComment(): string;
Expand Down
8 changes: 8 additions & 0 deletions webview-ui/test-generation/src/codegen/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export class AppiumJava extends AbstractBaseGenerator {
platform_version: string,
region: string,
platform: string,
tunnel_name: string,
tunnel_owner: string,
) {
const automationName = platform == 'Android' ? 'UiAutomator2' : 'xcuitest';
const split_goal = this.splitComments(goal, false, `Goal: `);
Expand Down Expand Up @@ -133,6 +135,8 @@ public class TestGenerationAssistantTest {
sauceOptions.setCapability("name", name.getMethodName() + ": " + "${goal}");
sauceOptions.setCapability("username", System.getenv("SAUCE_USERNAME"));
sauceOptions.setCapability("accessKey", System.getenv("SAUCE_ACCESS_KEY"));
sauceOptions.setCapability("tunnelName", "${tunnel_name}");
sauceOptions.setCapability("tunnelOwner", "${tunnel_owner}");

capabilities.setCapability("sauce:options", sauceOptions);
}
Expand Down Expand Up @@ -190,6 +194,8 @@ public class TestGenerationAssistantTest {
platform_version: string,
region: string,
platform: string,
tunnel_name: string,
tunnel_owner: string,
steps: any[],
) {
const headerText = this.scriptHeaderCode(
Expand All @@ -199,6 +205,8 @@ public class TestGenerationAssistantTest {
platform_version,
region,
platform,
tunnel_name,
tunnel_owner,
);

let codeStepText = '';
Expand Down
8 changes: 8 additions & 0 deletions webview-ui/test-generation/src/codegen/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class AppiumPython extends AbstractBaseGenerator {
platform_version: string,
region: string,
platform: string,
tunnel_name: string,
tunnel_owner: string,
) {
const automationName = platform == 'Android' ? 'UiAutomator2' : 'xcuitest';
return `import os
Expand All @@ -100,6 +102,8 @@ options = UiAutomator2Options().load_capabilities(
"username": os.environ["SAUCE_USERNAME"],
"accessKey": os.environ["SAUCE_ACCESS_KEY"],
"appiumVersion": "latest",
"tunnelName": "${tunnel_name}",
"tunnelOwner": "${tunnel_owner}",
},
},
)
Expand Down Expand Up @@ -152,6 +156,8 @@ driver.quit()\n`;
platform_version: string,
region: string,
platform: string,
tunnel_name: string,
tunnel_owner: string,
steps: any[],
) {
const headerText = this.scriptHeaderCode(
Expand All @@ -161,6 +167,8 @@ driver.quit()\n`;
platform_version,
region,
platform,
tunnel_name,
tunnel_owner,
);

let codeStepText = '';
Expand Down
39 changes: 39 additions & 0 deletions webview-ui/test-generation/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface Step {
screen_descs: string[];
}

export interface Tunnel {
name?: string;
owner?: string;
}

export interface State {
appName: string;
testGoal: string;
Expand All @@ -71,6 +76,8 @@ export interface State {
credentials?: Credentials;

language: 'python' | 'java';

tunnel: Tunnel;
}

export const initialState: State = {
Expand All @@ -91,6 +98,10 @@ export const initialState: State = {
generationState: 'idle',
status: '',
language: 'python',
tunnel: {
name: '',
owner: '',
},
};

export type Action =
Expand All @@ -103,6 +114,8 @@ export type Action =
| { type: 'setStatus'; value: State['status'] }
| { type: 'setGenerationState'; value: State['generationState'] }
| { type: 'setDevice'; value: string }
| { type: 'setTunnelName'; value: State['tunnel']['name'] }
| { type: 'setTunnelOwner'; value: State['tunnel']['owner'] }
| { type: 'showTestRecord'; value: { testRecord: TestRecord; votes: Vote[] } }
| { type: 'loadNewRecord'; value: TestRecord }
| { type: 'addAssertion'; value: { key: string } }
Expand Down Expand Up @@ -341,6 +354,10 @@ export const reducer = (current: State, action: Action): State => {
key: uuidv4(),
value,
})),
tunnel: {
name: testRecord.tunnel_name,
owner: testRecord.tunnel_owner,
},
};
}
case 'showTestRecord': {
Expand Down Expand Up @@ -403,6 +420,10 @@ export const reducer = (current: State, action: Action): State => {
key: uuidv4(),
value,
})),
tunnel: {
name: testRecord.tunnel_name,
owner: testRecord.tunnel_owner,
},
};
}
case 'showVideo': {
Expand All @@ -413,6 +434,24 @@ export const reducer = (current: State, action: Action): State => {
credentials: action.value.credentials,
};
}
case 'setTunnelName': {
return {
...current,
tunnel: {
...current.tunnel,
name: action.value,
},
};
}
case 'setTunnelOwner': {
return {
...current,
tunnel: {
...current.tunnel,
owner: action.value,
},
};
}
default:
return current;
}
Expand Down
Loading