Skip to content

Commit

Permalink
Add agent test
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka committed Jan 10, 2025
1 parent 50049be commit fc591a2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package com.sourcegraph.cody.agent.protocol_generated;

data class ExtensionConfiguration(
val serverEndpoint: String,
val serverEndpoint: String? = null,
val proxy: String? = null,
val accessToken: String? = null,
val customHeaders: Map<String, String>,
Expand Down
2 changes: 1 addition & 1 deletion agent/src/TestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export function setupRecording(): void {
}

export class TestClient extends MessageHandler {
private secrets = new AgentStatelessSecretStorage()
private extensionConfigurationDuringInitialization: ExtensionConfiguration | undefined
public static create({ bin = 'node', ...params }: TestClientParams): TestClient {
setupRecording()
Expand Down Expand Up @@ -180,6 +179,7 @@ export class TestClient extends MessageHandler {
public workspaceEditParams: WorkspaceEditParams[] = []
public textDocumentEditParams: TextDocumentEditParams[] = []
public expectedEvents: string[] = []
public secrets = new AgentStatelessSecretStorage()

get serverEndpoint(): string {
return this.params.credentials.serverEndpoint
Expand Down
2 changes: 1 addition & 1 deletion agent/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ export class Agent extends MessageHandler implements ExtensionClient {
// If this is an authentication change we need to reauthenticate prior to firing events
// that update the clients
try {
if (isAuthChange || params?.forceAuthentication) {
if ((isAuthChange || params?.forceAuthentication) && config.serverEndpoint) {
await authProvider.validateAndStoreCredentials(
{
configuration: {
Expand Down
19 changes: 19 additions & 0 deletions agent/src/unauthed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ describe.skip(
expect(authStatus?.endpoint).toBe(TESTING_CREDENTIALS.dotcomUnauthed.serverEndpoint)
})

it('starts up with default andpoint and credentials if they are present in the secure store', async () => {
const newClient = TestClient.create({
workspaceRootUri: workspace.rootUri,
name: 'unauthed',
credentials: TESTING_CREDENTIALS.dotcomUnauthed,
})

newClient.secrets.store(
TESTING_CREDENTIALS.dotcom.serverEndpoint,
TESTING_CREDENTIALS.dotcom.token ?? 'invalid'
)

await newClient.beforeAll({ serverEndpoint: undefined }, { expectAuthenticated: true })
const authStatus = await newClient.request('extensionConfiguration/status', null)
expect(authStatus?.authenticated).toBe(true)
expect(authStatus?.endpoint).toBe(TESTING_CREDENTIALS.dotcom.serverEndpoint)
newClient.afterAll()
})

it('authenticates to same endpoint using valid credentials', async () => {
const authStatus = await client.request('extensionConfiguration/change', {
...client.info.extensionConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class CodyAgentClient(private val project: Project, private val webview: NativeW
return CompletableFuture.completedFuture(null)
}

@JsonRequest("window/showSaveDialog")
@JsonRequest("window/showSaveDialog")
fun window_showSaveDialog(params: SaveDialogOptionsParams): CompletableFuture<String> {
// Let's use the first possible extension as default.
val ext = params.filters?.firstOrNull()?.value?.firstOrNull() ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object ConfigUtil {

return ExtensionConfiguration(
anonymousUserID = CodyApplicationSettings.instance.anonymousUserId,
serverEndpoint = endpoint?.url ?: "",
serverEndpoint = endpoint?.url,
accessToken = token,
customHeaders = emptyMap(),
proxy = UserLevelConfig.getProxy(),
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/jsonrpc/agent-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export interface ServerInfo {
}

export interface ExtensionConfiguration {
serverEndpoint: string
serverEndpoint?: string | undefined | null
proxy?: string | undefined | null
accessToken?: string | undefined | null
customHeaders: Record<string, string>
Expand Down

0 comments on commit fc591a2

Please sign in to comment.