From b1ad56c335ce16d43f33ea370712639c1a7fe970 Mon Sep 17 00:00:00 2001 From: nguyenyou Date: Sun, 13 Sep 2026 13:39:56 +0700 Subject: [PATCH] fix(scalex): restore native Java parsing parity Register the five fields read reflectively by JavaParser validation, invalidate cached failures, and check JVM metadata coverage plus native parsing in CI and releases. Co-Authored-By: Codex GPT-6 Astra --- .github/workflows/check.yml | 4 ++ .github/workflows/release.yml | 1 + CHANGELOG.md | 1 + docs/DEVELOPMENT.md | 1 + docs/ROADMAP.md | 11 ++++- .../native-image/scalex/reflect-config.json | 22 ++++++++++ scripts/check-native.sh | 44 +++++++++++++++++++ src/index/persistence.scala | 3 +- tests/native-metadata.test.scala | 24 ++++++++++ 9 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 resources/META-INF/native-image/scalex/reflect-config.json create mode 100644 scripts/check-native.sh create mode 100644 tests/native-metadata.test.scala diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 8acb78e2..6d7b41b7 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -28,3 +28,7 @@ jobs: run: ./mill --no-daemon mill.scalalib.scalafmt/checkFormatAll '__.sources' - name: Validate shared skill run: ./scripts/check-skill-frontmatter.sh + - name: Check native Java parsing + run: | + ./mill --no-daemon nativeCopy --dest ./scalex-check + bash scripts/check-native.sh ./scalex-check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 36d42fff..a02c386e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,6 +42,7 @@ jobs: - name: Test binary run: | + bash scripts/check-native.sh ./${{ matrix.artifact }} ./${{ matrix.artifact }} help ./${{ matrix.artifact }} index . ./${{ matrix.artifact }} search . Scalex diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e72b8ff..1e2fe045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Codex CLI and desktop plugin packaging and repository marketplace, sharing the existing skill and binary bootstrap with Claude Code. ### Fixed +- Native Java parsing retains the five AST fields inspected by JavaParser's validator. Classes with fields, local variables, arrays, intersection casts, and multi-catch types now parse like the JVM build. Existing indexes rebuild once to discard previously cached parse failures. - Test repositories configure their own Git identity and disable commit signing, so the suite runs on clean CI machines without developer Git settings. - Output budgets preserve complete JSON documents, apply to symbol summaries, and count Unicode characters correctly. Oversized JSON returns truncation metadata instead of a broken prefix. - CLI usage errors exit 2 and Git failures exit 1, with structured JSON errors when requested. Invalid Git refs no longer look like successful empty diffs. diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md index 0d12a644..cc793d8b 100644 --- a/docs/DEVELOPMENT.md +++ b/docs/DEVELOPMENT.md @@ -169,6 +169,7 @@ When adding or changing commands/flags: - **Guava group ID**: `com.google.guava:guava`, NOT `com.google.common:guava` - **GraalVM native image**: Guava needs `--initialize-at-run-time=com.google.common.hash.Striped64,com.google.common.hash.LongAdder,com.google.common.hash.BloomFilter,com.google.common.hash.BloomFilterStrategies` (see `build-native.sh`) +- **JavaParser native validation**: `resources/META-INF/native-image/scalex/reflect-config.json` retains the five AST fields read reflectively by the non-empty-list validator. The metadata test checks coverage against the installed JavaParser version; `bash scripts/check-native.sh ` exercises those constructs in the compiled executable. PR CI and every release platform run this check. - **No `.par` in Scala 3**: Use `list.asJava.parallelStream()` instead of `list.par` - **No non-local `return` in Scala 3**: `return` inside lambdas/closures is deprecated. Use `scala.util.boundary` + `boundary.break` instead. This includes `return` inside `.foreach`, `.map`, `try`/`catch` blocks inside lambdas, etc. - **Scalameta `Pkg.children` wraps stats in `PkgBody`**: Use `pkg.stats` to access direct children (Import, Defn.Class, etc.), not `pkg.children` which nests them inside a `PkgBody` wrapper node. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index fceaa725..b02efd6b 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -2,6 +2,15 @@ ## Pending +### Native parsing parity and measured query performance + +- [x] Reproduce and fix native-only Java parse failures, with a native regression check (492 JVM tests; full-workspace native/JVM parity) +- [ ] Reuse deserialized file paths and avoid full name-map construction for isolated lookups +- [ ] Reuse reference confidence, sort keys, and classification patterns without changing results +- [ ] Measure complete requests and command/render phases without double-counting nested timings +- [ ] Document opt-in native heap tuning; keep portable defaults unchanged +- [ ] Validate native/JVM parity, tests, and separate before/after performance measurements + ### Architecture and reliability cleanup - [x] Upgrade Scala, Mill, libraries, and formatting tools to the latest stable releases and validate compatibility @@ -15,7 +24,7 @@ - [x] Run tests, fatal-warning compilation, and shared skill validation in PR CI - [x] Consolidate contributor/build documentation and normalize Scala brace/import conventions - [x] Validate all 491 tests, fatal-warning compilation, formatting, and native CLI smoke checks -- [ ] Benchmark the latest build separately: cold index, warm index, query latency, and cache size +- [x] Benchmark the latest build separately: cold index, warm index, query latency, cache size, CPU/allocation profiles, and native GC - [x] Codex CLI and desktop plugin packaging, marketplace installation, and shared skill validation (local install verified with Codex CLI 0.153.4) - [ ] Publish Codex marketplace changes and verify installation from GitHub; optionally submit to OpenAI's public plugin directory diff --git a/resources/META-INF/native-image/scalex/reflect-config.json b/resources/META-INF/native-image/scalex/reflect-config.json new file mode 100644 index 00000000..d72681bd --- /dev/null +++ b/resources/META-INF/native-image/scalex/reflect-config.json @@ -0,0 +1,22 @@ +[ + { + "name": "com.github.javaparser.ast.body.FieldDeclaration", + "fields": [{ "name": "variables" }] + }, + { + "name": "com.github.javaparser.ast.expr.ArrayCreationExpr", + "fields": [{ "name": "levels" }] + }, + { + "name": "com.github.javaparser.ast.expr.VariableDeclarationExpr", + "fields": [{ "name": "variables" }] + }, + { + "name": "com.github.javaparser.ast.type.IntersectionType", + "fields": [{ "name": "elements" }] + }, + { + "name": "com.github.javaparser.ast.type.UnionType", + "fields": [{ "name": "elements" }] + } +] diff --git a/scripts/check-native.sh b/scripts/check-native.sh new file mode 100644 index 00000000..078b2434 --- /dev/null +++ b/scripts/check-native.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -euo pipefail + +case "${1:-./scalex}" in + /*) binary="${1:-./scalex}" ;; + *) binary="$PWD/${1:-./scalex}" ;; +esac +workspace=$(mktemp -d) +trap 'rm -rf "$workspace"' EXIT + +cat > "$workspace/Counter.java" <<'JAVA' +package example; + +/** A counter with both primitive and generic fields. */ +public class Counter { + private int value; + private java.util.List items; + public static final int DEFAULT = 0; + public Counter(int initial) { value = initial; } + public int current() { return value; } + public void exercise() { + int[] numbers = new int[2]; + Object action = (Runnable & java.io.Serializable) () -> {}; + try { throw new java.io.IOException(); } + catch (java.io.IOException | IllegalArgumentException error) {} + } +} +JAVA +git -C "$workspace" init -q +git -C "$workspace" add Counter.java + +stats=$("$binary" index "$workspace" --json) +if ! grep -q '"parseFailures":0' <<< "$stats"; then + echo "Native Java parsing regression: $stats" >&2 + exit 1 +fi +members=$("$binary" members "$workspace" Counter --json) +for name in value items DEFAULT current; do + if ! grep -q "\"name\":\"$name\"" <<< "$members"; then + echo "Native Java member missing: $name" >&2 + exit 1 + fi +done +echo 'Native Java parsing and member extraction passed.' diff --git a/src/index/persistence.scala b/src/index/persistence.scala index 7a516fb8..99b2eb92 100644 --- a/src/index/persistence.scala +++ b/src/index/persistence.scala @@ -14,7 +14,8 @@ import com.google.common.hash.{BloomFilter, Funnels} object IndexPersistence { private val MAGIC = 0x53584458 - private val VERSION: Byte = 8 + // Invalidate cached Java parse failures from native images missing validator metadata. + private val VERSION: Byte = 9 def indexPath(workspace: Path): Path = workspace.resolve(".scalex").resolve("index.bin") diff --git a/tests/native-metadata.test.scala b/tests/native-metadata.test.scala new file mode 100644 index 00000000..9e306348 --- /dev/null +++ b/tests/native-metadata.test.scala @@ -0,0 +1,24 @@ +package scalex + +import com.github.javaparser.metamodel.JavaParserMetaModel +import munit.FunSuite +import scala.jdk.CollectionConverters.* +import scala.util.Using + +class NativeMetadataSuite extends FunSuite { + test("native metadata covers every field read by JavaParser's non-empty-list validator") { + val required = JavaParserMetaModel.getNodeMetaModels.asScala.flatMap { node => + node.getAllPropertyMetaModels.asScala.collect { + case property if property.isNonEmpty && property.isNodeList => + (owner = property.getContainingNodeMetaModel.getType.getName, field = property.getName) + } + }.toSet + val resource = getClass.getResourceAsStream("/META-INF/native-image/scalex/reflect-config.json") + assert(resource != null, "Native metadata must be included in the application resources") + val metadata = Using.resource(resource)(stream => ujson.read(stream.readAllBytes())) + val registered = metadata.arr.flatMap { entry => + entry("fields").arr.map(field => (owner = entry("name").str, field = field("name").str)) + }.toSet + assertEquals(registered, required) + } +}