Move SSD truth store JSON envelopes to typed Kotlin
ober
f1aaa475c993355aac58798cec917c2888b0278d
--- a/.build.yml +++ b/.build.yml @@ -5,7 +5,7 @@ packages: - make=4.4.1-r4 sources: # Build dependency: full immutable commit, mirrored in dependencies.lock.json. - - "https://git.sr.ht/~lisp/jerboa#4e842a4908d69ef7b0e797548bcb6d2600c3962c" + - "https://git.sr.ht/~lisp/jerboa#a00ba7377703ede19f3df6957fd5d1bdc629f568" # The second source is the build subject selected by the SourceHut submitter. - https://git.sr.ht/~lisp/jerboa-android tasks: @@ -14,6 +14,6 @@ tasks: test "$(apk info -v chez-scheme)" = chez-scheme-10.3.0-r2 test "$(apk info -v git)" = git-2.54.0-r0 test "$(apk info -v make)" = make-4.4.1-r4 - test "$(git -C ../jerboa rev-parse HEAD)" = 4e842a4908d69ef7b0e797548bcb6d2600c3962c - test "$(git -C ../jerboa rev-parse 'HEAD^{tree}')" = ba29fe6f6815eb1ebddb124d1f3b1b8101aa6769 + test "$(git -C ../jerboa rev-parse HEAD)" = a00ba7377703ede19f3df6957fd5d1bdc629f568 + test "$(git -C ../jerboa rev-parse 'HEAD^{tree}')" = 9f30077ca1a84204d07c2812e2f6cfe40ff3d90d JERBOA="chez --libdirs .:../jerboa/lib --script" make test --- a/dependencies.lock.json +++ b/dependencies.lock.json @@ -11,8 +11,8 @@ "generator_runtime": { "name": "jerboa", "repository": "https://git.sr.ht/~lisp/jerboa", - "commit": "4e842a4908d69ef7b0e797548bcb6d2600c3962c", - "tree": "ba29fe6f6815eb1ebddb124d1f3b1b8101aa6769" + "commit": "a00ba7377703ede19f3df6957fd5d1bdc629f568", + "tree": "9f30077ca1a84204d07c2812e2f6cfe40ff3d90d" }, "assurance_tools": { "osv_scanner": { --- a/scripts/verify-supply-chain.sh +++ b/scripts/verify-supply-chain.sh @@ -3,8 +3,8 @@ set -eu repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd -P) lock="$repo/dependencies.lock.json" -jerboa_commit=4e842a4908d69ef7b0e797548bcb6d2600c3962c # gitsafe:ignore -jerboa_tree=ba29fe6f6815eb1ebddb124d1f3b1b8101aa6769 # gitsafe:ignore +jerboa_commit=a00ba7377703ede19f3df6957fd5d1bdc629f568 # gitsafe:ignore +jerboa_tree=9f30077ca1a84204d07c2812e2f6cfe40ff3d90d # gitsafe:ignore gradle_sha=20f1b1176237254a6fc204d8434196fa11a4cfb387567519c61556e8710aed78 jdk_macos_sha=8fa1eff40bb637a33613b2ccb8b12c70dc3661cc22cf8e784943715769a05336 jdk_linux_sha=d8afc263758141a66e0e3aafc321e783f7016696f4eaea067d340a269037d331 --- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -3486,6 +3486,29 @@ (SsdSession-sourceKey session) details)))) + (typed-kotlin-file "com/sfb/ssdreview/TruthStoreJson.kt" + (kotlin-imports (org json JSONArray) (org json JSONObject)) + (typed-library (com sfb ssdreview) + (export learnedExamplesDocument autosaveTruthPayloadJson) + (type JSONArray) + (type JSONObject) + (type Int32) + (def (learnedExamplesDocument (examples : JSONArray) (maxExamples : Int32)) : JSONObject + (let ((out (json-object-empty))) + (begin + (json-object-put-int32! out "schema_version" (int32 1)) + (json-object-put-int! out "generated_at" (system-current-time-millis)) + (json-object-put-int32! out "example_count" (json-array-length examples)) + (json-object-put-bool! out "capped" (>= (json-array-length examples) maxExamples)) + (json-object-put-json-array! out "examples" examples) + out))) + (def (autosaveTruthPayloadJson (truth : JSONObject)) : JSONObject + (let ((out (json-object-empty))) + (begin + (json-object-put-string! out "reason" "android_autosave") + (json-object-put-json-object! out "truth" truth) + out))))) + (typed-kotlin-file "com/sfb/ssdreview/TruthIndexSelect.kt" (typed-library (com sfb ssdreview) (export bestTruthIndexForSession) @@ -6977,12 +7000,7 @@ " examples.put(learnedExampleFromTruthGroup(truth, file.name, group))" " }" " }" - " val learned = JSONObject()" - " .put(\"schema_version\", 1)" - " .put(\"generated_at\", System.currentTimeMillis())" - " .put(\"example_count\", examples.length())" - " .put(\"capped\", examples.length() >= MAX_LEARNED_EXAMPLES)" - " .put(\"examples\", examples)" + " val learned = learnedExamplesDocument(examples, MAX_LEARNED_EXAMPLES)" " atomicWriteText(containedLeaf(learnedDir, \"group_examples.json\"), learned.toString(2))" " }" "" @@ -7149,10 +7167,7 @@ " }" "" " private fun pushTruthAsync(truth: JSONObject) {" - " val payload = JSONObject()" - " .put(\"reason\", \"android_autosave\")" - " .put(\"truth\", truth)" - " .toString()" + " val payload = autosaveTruthPayloadJson(truth).toString()" " thread(name = \"sfb-truth-autosave\") {" " try {" " val bytes = payload.toByteArray(Charsets.UTF_8)"