Skip to content

Commit 361dc54

Browse files
committed
fix app uri printing bug
sdk was ignoring the port for url printing, which broke links to braintrust hosted on nonstandard ports
1 parent f9f1e44 commit 361dc54

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

‎src/main/java/dev/braintrust/config/BraintrustConfig.java‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,17 @@ URI fetchProjectURI(BraintrustApiClient client) {
9696
try {
9797
var orgAndProject = client.getProjectAndOrgInfo().orElseThrow();
9898
var baseURI = new URI(appUrl());
99+
var path =
100+
"/app/%s/p/%s"
101+
.formatted(
102+
orgAndProject.orgInfo().name(), orgAndProject.project().name());
99103
return new URI(
100104
baseURI.getScheme(),
105+
baseURI.getUserInfo(),
101106
baseURI.getHost(),
102-
baseURI.getPath()
103-
+ "/app/"
104-
+ orgAndProject.orgInfo().name()
105-
+ "/p/"
106-
+ orgAndProject.project().name(),
107+
baseURI.getPort(),
108+
path,
109+
null,
107110
null);
108111
} catch (URISyntaxException e) {
109112
throw new RuntimeException(e);

‎src/test/java/dev/braintrust/config/BraintrustConfigTest.java‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,27 @@ void projectUriFetching() {
4646
new dev.braintrust.api.BraintrustApiClient.OrganizationAndProjectInfo(
4747
orgInfo, project);
4848
var client = new dev.braintrust.api.BraintrustApiClient.InMemoryImpl(orgAndProjectInfo);
49-
var config =
50-
BraintrustConfig.of(
51-
"BRAINTRUST_API_KEY", "foobar",
52-
"BRAINTRUST_API_URL", "https://api.braintrust.dev",
53-
"BRAINTRUST_APP_URL", "https://braintrust.dev",
54-
"BRAINTRUST_DEFAULT_PROJECT_ID", projectId);
55-
assertEquals(
56-
"https://braintrust.dev/app/Test%20Org/p/some%20project",
57-
config.fetchProjectURI(client).toASCIIString());
49+
{ // standard braintrust.dev
50+
var config =
51+
BraintrustConfig.of(
52+
"BRAINTRUST_API_KEY", "foobar",
53+
"BRAINTRUST_API_URL", "https://api.braintrust.dev",
54+
"BRAINTRUST_APP_URL", "https://braintrust.dev",
55+
"BRAINTRUST_DEFAULT_PROJECT_ID", projectId);
56+
assertEquals(
57+
"https://braintrust.dev/app/Test%20Org/p/some%20project",
58+
config.fetchProjectURI(client).toASCIIString());
59+
}
60+
{ // self-hosted with a non-standard port
61+
var config =
62+
BraintrustConfig.of(
63+
"BRAINTRUST_API_KEY", "foobar",
64+
"BRAINTRUST_API_URL", "http://someselfhost:8080",
65+
"BRAINTRUST_APP_URL", "http://someselfhost:3001",
66+
"BRAINTRUST_DEFAULT_PROJECT_ID", projectId);
67+
assertEquals(
68+
"http://someselfhost:3001/app/Test%20Org/p/some%20project",
69+
config.fetchProjectURI(client).toASCIIString());
70+
}
5871
}
5972
}

0 commit comments

Comments
 (0)