Skip to content

Commit

Permalink
Fixes for review
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka committed Jan 15, 2025
1 parent 0f51f3a commit 048060c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
@file:Suppress("FunctionName", "ClassName", "unused", "EnumEntryName", "UnusedImport")
package com.sourcegraph.cody.agent.protocol_generated;

import com.google.gson.annotations.SerializedName;

data class CodyContextFilterItem(
val repoNamePattern: String,
val repoNamePattern: RepoNamePatternEnum, // Oneof: .*
val filePathPatterns: List<String>? = null,
)
) {

enum class RepoNamePatternEnum {
@SerializedName(".*") ``,
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package com.sourcegraph.cody.agent.protocol_generated;

object Constants {
const val `` = ".*"
const val Applied = "Applied"
const val Applying = "Applying"
const val Automatic = "Automatic"
Expand All @@ -15,6 +16,7 @@ object Constants {
const val agentic = "agentic"
const val ask = "ask"
const val assistant = "assistant"
const val `auth-config-error` = "auth-config-error"
const val authenticated = "authenticated"
const val autocomplete = "autocomplete"
const val balanced = "balanced"
Expand Down
18 changes: 10 additions & 8 deletions lib/shared/src/configuration/auth-resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ describe('auth-resolver', () => {
})

test('resolve custom auth provider', async () => {
const futureExpirationEpoch = 1000 * 1000 * 1000 * 1000
const futureEpoch = Date.UTC(2050) / 1000
const credentialsJson = JSON.stringify({
headers: { Authorization: 'token X' },
expiration: futureExpirationEpoch,
expiration: futureEpoch,
})

const auth = await resolveAuth(
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('auth-resolver', () => {
expect(auth.serverEndpoint).toBe('https://my-server.com/')

const headerCredential = auth.credentials as HeaderCredential
expect(headerCredential.expiration).toBe(futureExpirationEpoch)
expect(headerCredential.expiration).toBe(futureEpoch)
expect(headerCredential.getHeaders()).toStrictEqual({
Authorization: 'token X',
})
Expand All @@ -108,7 +108,7 @@ describe('auth-resolver', () => {
{
endpoint: 'https://my-server.com',
executable: {
commandLine: ['echo '],
commandLine: ['echo x'],
shell: isWindows() ? process.env.ComSpec : '/bin/bash',
timeout: 5000,
windowsHide: true,
Expand All @@ -124,14 +124,14 @@ describe('auth-resolver', () => {
expect(auth.serverEndpoint).toBe('https://my-server.com/')

expect(auth.credentials).toBe(undefined)
expect(auth.error.message).toContain('Unexpected end of JSON input')
expect(auth.error.message).toContain('Unexpected token \'x\', "x" is not valid JSON')

Check failure on line 127 in lib/shared/src/configuration/auth-resolver.test.ts

View workflow job for this annotation

GitHub Actions / test-unit (ubuntu, 18)

src/configuration/auth-resolver.test.ts > auth-resolver > resolve custom auth provider error handling - bad JSON

AssertionError: expected 'Failed to execute external auth comma…' to contain 'Unexpected token \'x\', "x" is not va…' Expected: "Unexpected token 'x', "x" is not valid JSON" Received: "Failed to execute external auth command: Unexpected token x in JSON at position 0" ❯ src/configuration/auth-resolver.test.ts:127:36
})

test('resolve custom auth provider error handling - bad expiration', async () => {
const pastExpirationEpoch = 1000 * 1000 * 1000
const expiredEpoch = Date.UTC(2020) / 1000
const credentialsJson = JSON.stringify({
headers: { Authorization: 'token X' },
expiration: pastExpirationEpoch,
expiration: expiredEpoch,
})

const auth = await resolveAuth(
Expand Down Expand Up @@ -159,6 +159,8 @@ describe('auth-resolver', () => {
expect(auth.serverEndpoint).toBe('https://my-server.com/')

expect(auth.credentials).toBe(undefined)
expect(auth.error.message).toContain('Credentials expiration cannot be se to the past date')
expect(auth.error.message).toContain(
'Credentials expiration cannot be set to a date in the past'
)
})
})
5 changes: 2 additions & 3 deletions lib/shared/src/configuration/auth-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ export async function resolveAuth(
if (credentials) {
if (credentials?.expiration) {
const expirationMs = credentials?.expiration * 1000
const expireInMs = expirationMs - Date.now()
if (expireInMs < 0) {
if (expirationMs < Date.now()) {
throw new Error(
'Credentials expiration cannot be se to the past date: ' +
'Credentials expiration cannot be set to a date in the past: ' +
`${new Date(expirationMs)} (${credentials.expiration})`
)
}
Expand Down
3 changes: 1 addition & 2 deletions lib/shared/src/configuration/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ async function resolveConfiguration({
const auth = await resolveAuth(serverEndpoint, clientConfiguration, clientSecrets)
const cred = auth.credentials
if (cred !== undefined && 'expiration' in cred && cred.expiration !== undefined) {
const expirationMs = cred.expiration * 1000
const expireInMs = expirationMs - Date.now()
const expireInMs = cred.expiration * 1000 - Date.now()
setInterval(() => _refreshConfigRequests.next(), expireInMs)
}
return { configuration: clientConfiguration, clientState, auth, isReinstall }
Expand Down

0 comments on commit 048060c

Please sign in to comment.