mirror of
https://github.com/apple/pkl.git
synced 2026-04-11 03:06:55 +02:00
Fix: use http.rewrites to configure the evaluator in message passing API (#1141)
This is a bugfix, where the `rewrites` option is currently ignored. Also: return any illegal argument errors from creating the evaluator as an error in the CreateEvaluatorResponse
This commit is contained in:
@@ -60,6 +60,26 @@ abstract class AbstractServerTest {
|
||||
|
||||
abstract val client: TestTransport
|
||||
|
||||
private val blankCreateEvaluatorRequest =
|
||||
CreateEvaluatorRequest(
|
||||
requestId = 1,
|
||||
http = null,
|
||||
allowedModules = null,
|
||||
allowedResources = null,
|
||||
clientModuleReaders = null,
|
||||
clientResourceReaders = null,
|
||||
modulePaths = null,
|
||||
env = null,
|
||||
properties = null,
|
||||
timeout = null,
|
||||
rootDir = null,
|
||||
cacheDir = null,
|
||||
outputFormat = null,
|
||||
project = null,
|
||||
externalModuleReaders = null,
|
||||
externalResourceReaders = null,
|
||||
)
|
||||
|
||||
@Test
|
||||
fun `create and close evaluator`() {
|
||||
val evaluatorId = client.sendCreateEvaluatorRequest(123)
|
||||
@@ -931,6 +951,50 @@ abstract class AbstractServerTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `http rewrites`() {
|
||||
val evaluatorId =
|
||||
client.sendCreateEvaluatorRequest(
|
||||
http =
|
||||
Http(
|
||||
caCertificates = null,
|
||||
proxy = null,
|
||||
rewrites = mapOf(URI("https://example.com/") to URI("https://example.example/")),
|
||||
)
|
||||
)
|
||||
client.send(
|
||||
EvaluateRequest(
|
||||
1,
|
||||
evaluatorId,
|
||||
URI("repl:text"),
|
||||
"res = import(\"https://example.com/foo.pkl\")",
|
||||
"output.text",
|
||||
)
|
||||
)
|
||||
val response = client.receive<EvaluateResponse>()
|
||||
assertThat(response.error)
|
||||
.contains(
|
||||
"request was rewritten: https://example.com/foo.pkl -> https://example.example/foo.pkl"
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `http rewrites -- invalid rule`() {
|
||||
client.send(
|
||||
blankCreateEvaluatorRequest.copy(
|
||||
http =
|
||||
Http(
|
||||
caCertificates = null,
|
||||
proxy = null,
|
||||
rewrites = mapOf(URI("https://example.com") to URI("https://example.example/")),
|
||||
)
|
||||
)
|
||||
)
|
||||
val response = client.receive<CreateEvaluatorResponse>()
|
||||
assertThat(response.error)
|
||||
.contains("Rewrite rule must end with '/', but was 'https://example.com'")
|
||||
}
|
||||
|
||||
private val ByteArray.debugYaml
|
||||
get() = MessagePackDebugRenderer(this).output.trimIndent()
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ class ServerMessagePackCodecTest {
|
||||
Http(
|
||||
proxy = Proxy(URI("http://foo.com:1234"), listOf("bar", "baz")),
|
||||
caCertificates = byteArrayOf(1, 2, 3, 4),
|
||||
rewrites = mapOf("https://foo.com" to "https://bar.com"),
|
||||
rewrites = mapOf(URI("https://foo.com/") to URI("https://bar.com/")),
|
||||
),
|
||||
externalModuleReaders = mapOf("external" to externalReader, "external2" to externalReader),
|
||||
externalResourceReaders = mapOf("external" to externalReader),
|
||||
|
||||
Reference in New Issue
Block a user