Fourth and final R7b batch-2 port, checklist-first recipe (docs/design/php-kernel-port-checklist.md). Grammar bump first, validated standalone with the diff ENUMERATED + CLASSIFIED (unlike rust/ruby the php bump is NOT graph-neutral): tree-sitter-php ^0.22 (tree-sitter-wasms, 2023) → v0.24.2, the full HTML-interleaving `php` variant (the walker calls LANGUAGE_PHP, never PHP_ONLY) — crate pinned =0.24.2, wasm built from tag 5b5627f's checked-in php/src/parser.c + scanner.c + shared common/scanner.h (all sha-matched against the crates.io tarball, ABI 14→15). Old-vs-new full-init diffs decompose completely into: (1) the anonymous_class wrapper shape (anon-class nodes/methods re-shape — 2,532 rows), (2) grouped nested-clause skip (absent in the gate repos, fixture-pinned), (3) 32 formerly-erroring files parsing clean (monolog Level.php, symfony Request/Response with 8.4 property hooks), (4) a survey-missed category found at gate time: the 8.4 parenthesis-free `new X()->m()` chaining misparse fix (86 garbage instantiates refs disappear, precision-positive), plus resolution RIPPLE proven mechanically (every remaining ref-table flip pairs 1:1 with a resolved edge on the opposite side; node rows byte-stable outside 1/3/4). Walker (java.rs chassis + the php specifics) preserves bug-for-bug: the visitNode hook (const_declaration at ANY scope → bare `constant` nodes, values never walked; trait-use → implements refs WITH filePath via the ruby port's REF_FLAG_FILE_PATH wire slot), FIRST-namespace whole-file scoping (braced namespaces scope nothing; namespaced files DROP top-level const value-ref targets), the import trio (single/aliased/grouped incl. the nested-clause skip, include/require static-literal-only, `Foo\Bar::Baz` use refs), the call-encoding zoo (DOT-joined scoped calls, `this->prop.m` #1251 encoding, `Cls::factory().m` fluent with inner args dropped, nullsafe `?->` emitting nothing, unsuppressed literal receivers), interface multi-extends first-base-only drop, anon-class methods as file-level functions (top) or vanishing (in-body), property type-hints emitting no field refs, the final-modifier-as-type signature quirk, HOF-gated string callables (skipGate) + array callables, and the `name`-node value-ref reader. Gates: sweeps 0-diff monolog 217/217, laravel-framework 3007/3008, symfony 10726/10737 (13,950 files byte-parity; 12 deferrals = exactly the predicted genuinely-broken fixtures, ≈0–0.1%); full-init dumps byte-identical ×3 (16.1k/354.2k/702.8k lines); kernel-php-parity suite (torture + drupal .module + leading-HTML fixtures, CRLF variants, wire-flag pin, defer) + php grammar-parity row; full suite 2,622 green ×2 under CODEGRAPH_KERNEL_EXPECT=1. DEFAULT_ROUTED += php (13 languages). Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
71 lines
3.1 KiB
TypeScript
71 lines
3.1 KiB
TypeScript
/**
|
|
* Grammar-source parity gate (R1, migration plan §3.5).
|
|
*
|
|
* The native kernel compiles grammars from crates.io / vendored sources; the
|
|
* wasm fallback loads grammars from tree-sitter-wasms / src/extraction/wasm.
|
|
* If the two are built from different grammar revisions, a language's graph
|
|
* would depend on WHICH path extracted it — per-language routing (and the
|
|
* kernel-absent fallback) must be graph-neutral.
|
|
*
|
|
* Rather than trusting version metadata, this asserts the grammars are
|
|
* behaviorally identical where extraction can observe them: ABI version and
|
|
* the full node-kind and field tables, compared id by id.
|
|
*
|
|
* Runs wherever a kernel binary is staged (scripts/build-kernel.sh); skips
|
|
* otherwise. CI that builds the kernel sets CODEGRAPH_KERNEL_EXPECT=1 so the
|
|
* skip can't mask a missing build (asserted in kernel-scaffold.test.ts).
|
|
*/
|
|
|
|
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import type { Language as WasmLanguage } from 'web-tree-sitter';
|
|
import { getKernel, resetKernelForTests } from '../src/extraction/kernel';
|
|
import { initGrammars, loadGrammarsForLanguages, getParser } from '../src/extraction/grammars';
|
|
import type { Language } from '../src/types';
|
|
|
|
const KERNEL_PATH = path.join(
|
|
__dirname,
|
|
'..',
|
|
'codegraph-kernel',
|
|
'prebuilds',
|
|
`${process.platform}-${process.arch}`,
|
|
'codegraph-kernel.node'
|
|
);
|
|
const kernelBuilt = fs.existsSync(KERNEL_PATH);
|
|
|
|
// Every kernel-capable language. `jsx` shares the javascript grammar on BOTH
|
|
// paths (langs.rs mirrors WASM_GRAMMAR_FILES), so the distinct grammars are:
|
|
const GRAMMAR_LANGUAGES: Language[] = ['typescript', 'tsx', 'javascript', 'java', 'python', 'go', 'c', 'cpp', 'rust', 'csharp', 'ruby', 'php'];
|
|
|
|
describe.skipIf(!kernelBuilt)('kernel↔wasm grammar parity', () => {
|
|
beforeAll(async () => {
|
|
resetKernelForTests();
|
|
await initGrammars();
|
|
await loadGrammarsForLanguages(GRAMMAR_LANGUAGES);
|
|
});
|
|
|
|
it.each(GRAMMAR_LANGUAGES)('%s: node-kind and field tables are identical', (language) => {
|
|
const kernel = getKernel();
|
|
expect(kernel).not.toBeNull();
|
|
const native = kernel!.grammarInfo(language);
|
|
expect(native, `kernel has no grammar for ${language}`).not.toBeNull();
|
|
|
|
const wasmLang = getParser(language)?.language as WasmLanguage | null | undefined;
|
|
expect(wasmLang, `wasm grammar for ${language} not loaded`).toBeTruthy();
|
|
|
|
expect(native!.abiVersion, 'grammar ABI version').toBe(wasmLang!.abiVersion);
|
|
expect(native!.nodeKindCount, 'node-kind count').toBe(wasmLang!.nodeTypeCount);
|
|
expect(native!.fieldCount, 'field count').toBe(wasmLang!.fieldCount);
|
|
|
|
const wasmKinds: (string | null)[] = [];
|
|
for (let i = 0; i < wasmLang!.nodeTypeCount; i++) wasmKinds.push(wasmLang!.nodeTypeForId(i));
|
|
expect(native!.nodeKinds).toEqual(wasmKinds.map((k) => k ?? ''));
|
|
|
|
// Field ids are 1-based on both sides.
|
|
const wasmFields: (string | null)[] = [];
|
|
for (let i = 1; i <= wasmLang!.fieldCount; i++) wasmFields.push(wasmLang!.fieldNameForId(i));
|
|
expect(native!.fieldNames).toEqual(wasmFields.map((f) => f ?? ''));
|
|
});
|
|
});
|