Fix env in kernel.json serialized as array instead of JSON object (issue #1499) - #1666
Fix env in kernel.json serialized as array instead of JSON object (issue #1499)#1666alexarchambault with Copilot wants to merge 4 commits into
env in kernel.json serialized as array instead of JSON object (issue #1499)#1666Conversation
…sue #1499) Agent-Logs-Url: https://github.com/almond-sh/almond/sessions/439e350a-398b-4ff7-a53c-c97942efc16d Co-authored-by: alexarchambault <7063723+alexarchambault@users.noreply.github.com>
Agent-Logs-Url: https://github.com/almond-sh/almond/sessions/e8895e66-f46c-403a-bf2d-810905544233 Co-authored-by: alexarchambault <7063723+alexarchambault@users.noreply.github.com>
Fixed in 6f41165. The compilation errors were caused by a |
alexarchambault
left a comment
There was a problem hiding this comment.
Can't you instead introduce a custom case class ActualMap[T](map: Map[String, T]), define a codec for it, and use it in KernelSpec? So that we can keep using the jsoniter-scala macro when defining the KernelSpec codec
…codec to use macro Agent-Logs-Url: https://github.com/almond-sh/almond/sessions/6fd1f7a6-94b9-42a6-94c6-af186ee0cd7d Co-authored-by: alexarchambault <7063723+alexarchambault@users.noreply.github.com>
Done in 18f05dd. Introduced |
| final case class ActualMap[T](map: Map[String, T]) | ||
|
|
||
| object ActualMap { | ||
| implicit val stringCodec: JsonValueCodec[ActualMap[String]] = |
There was a problem hiding this comment.
Can't you define a more general implicit def codec[T: JsonValueCodec]: JsonValueCodec[ActualMap[T]] = ... here?
There was a problem hiding this comment.
Done in cb3654e. Replaced implicit val stringCodec with implicit def codec[T: JsonValueCodec]: JsonValueCodec[ActualMap[T]], using tCodec.decodeValue/tCodec.encodeValue for the value type instead of the String-specific methods.
Agent-Logs-Url: https://github.com/almond-sh/almond/sessions/fec25bc7-ddd1-4672-b8ce-09a77d91dadc Co-authored-by: alexarchambault <7063723+alexarchambault@users.noreply.github.com>
Summary
Fixes #1499.
Since v0.14.0-RC15, installing the Almond kernel would produce a broken
kernel.jsonwhere theenvfield was a JSON array of pairs instead of a JSON object:Jupyter rejects the broken format with:
Root Cause
The regression was introduced with the Scala 3 toolchain update between RC14 and RC15. In jsoniter-scala 2.13.5 under Scala 3, the macro does not recognise
Map[String, String]as a JSON-object type and instead falls back to treating it as anIterable[(String, String)], which is serialised as a JSON array of pairs.Fix
Introduce a new
ActualMap[T](map: Map[String, T])wrapper class with a generalimplicit def codec[T: JsonValueCodec]: JsonValueCodec[ActualMap[T]]that always serialises and deserialises as a JSON object. TheKernelSpec.envfield is changed fromMap[String, String]toActualMap[String], allowingKernelSpec.codecto remain a simpleJsonCodecMaker.make-derived codec — the macro picks up theActualMapcodec from its companion object, the same pattern used byRawJsonelsewhere in the codebase.A regression test is added to
ProtocolTeststhat assertsenvserialises as{"KEY":"VALUE"}and round-trips correctly.