mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-11-29 23:37:41 +00:00
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
* test(java): pin on-demand import behaviour to JLS scenarios Fourteen scenarios for `import pkg.*;` taken from JLS SE 21 (7.5.2, 6.4.1, 6.5.5.1, 6.5.4.2, 6.6.1), each asserting the exact CALLS, EXTENDS and IMPORTS edges the resolver emits today. Nine agree with the JLS. Five are labelled as known semantic gaps (a name supplied by one on-demand package resolves only for the class link, accessibility is not applied, member types of a class are not imported on demand); they are pinned so a change of import representation cannot move them by accident, not endorsed. Baseline for the import-group memory work, which must leave every row unchanged. Refs #3695 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * refactor(scope-resolution): put import visibility behind one interface `ScopeResolutionIndexes.imports` was a public map of edge arrays, so every reader depended on one stored edge per imported file. It is now an `ImportVisibility`: the only way to ask what a scope imports, with one operation per question a reader has. - `edgesAt`: the imports a reader can select by name, definition or kind - `reaches` / `reachesDirectory`: does this scope import that file or any file of that directory - `membership`: the same question asked repeatedly at one scope - `forEachTarget`: every imported file in statement order, with the edge that describes how it is imported - `scopes`: every scope finalize recorded `createEagerImportVisibility` implements it over the edge map finalize already produces; storage is unchanged. All 26 readers of the map are migrated to the operation they need. The two file-grounding checks ask `reaches`; inheritance disambiguation asks `reaches` and `reachesDirectory`; File->File IMPORTS emission and the Java on-demand fallback use `forEachTarget`; unique-name property narrowing asks a cached `membership` per importing scope instead of building a set of imported files for every file up front; readers that select by name or kind, and each language's own provider code, use `edgesAt`. No intended semantic change. Test fixtures that built an index by hand wrap their edge map with the eager implementation; no expected result changes. The import-emission benchmark gains `--map-input` for an emitter that predates the interface. Refs #3695 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * test(scope-resolution): contract suite for ImportVisibility and a graph-identity helper The contract is checked against a description of each import relation (per scope, the statements as written and the files each resolves to), not against any implementation's storage: 11 hand-written relations and 60 from a seeded generator, covering duplicates, overlaps, self-targets, unresolved targets, empty lists and explicit imports interleaved with wildcards. Each case compares scope order, recorded-versus-absent scopes, the imports selectable by name, definition or kind, ordered targets with the metadata a consumer reads, and every membership answer. A second implementation runs the same cases by passing its builder. `graphIdentity` gives a canonical form of a knowledge graph (node ids, labels and properties; relationship ids, types, endpoints and properties) for comparing two runs. It normalizes storage order only. Refs #3695 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * test(scope-resolution): address review notes on the contract tests - The duplicate-target coverage check compared target arrays by identity. It now compares them by content, which is what "the same list written twice" means. - The contract helper's header named a function that does not exist; it now says how to run the cases against an implementation. - The JLS scenario comment said every importer uses `T` three ways; S12 and S14 do not, and the comment says so. Tests and comments only. Refs #3695 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
70 lines
3 KiB
TypeScript
70 lines
3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { createEagerImportVisibility } from 'gitnexus-shared';
|
|
import {
|
|
edgeMapOf,
|
|
expectedVisibility,
|
|
generatedRelations,
|
|
namedRelations,
|
|
observeVisibility,
|
|
} from '../../helpers/import-visibility-contract.js';
|
|
|
|
/**
|
|
* Contract of `ImportVisibility`, checked against a description of each import
|
|
* relation rather than against any implementation's storage. An implementation
|
|
* that stores imports differently runs the same relations and must give the
|
|
* same answers.
|
|
*/
|
|
describe('ImportVisibility contract: one edge per imported file', () => {
|
|
it.each([...namedRelations, ...generatedRelations])('$name', (relation) => {
|
|
const visibility = createEagerImportVisibility(edgeMapOf(relation));
|
|
expect(observeVisibility(relation, visibility)).toEqual(expectedVisibility(relation));
|
|
});
|
|
|
|
it('hands back the stored edge list itself, and undefined for a scope it never saw', () => {
|
|
const relation = namedRelations[2]!;
|
|
const edges = edgeMapOf(relation);
|
|
const visibility = createEagerImportVisibility(edges);
|
|
const scope = relation.scopes[0]!.id;
|
|
expect(visibility.edgesAt(scope)).toBe(edges.get(scope));
|
|
expect(visibility.edgesAt('absent')).toBeUndefined();
|
|
});
|
|
|
|
it('returns the same membership view each time a scope is asked', () => {
|
|
const relation = namedRelations[2]!;
|
|
const visibility = createEagerImportVisibility(edgeMapOf(relation));
|
|
const scope = relation.scopes[0]!.id;
|
|
expect(visibility.membership(scope)).toBe(visibility.membership(scope));
|
|
});
|
|
|
|
it('answers from its own edge map: a later finalize result gets a fresh view', () => {
|
|
const relation = namedRelations[2]!;
|
|
const scope = relation.scopes[0]!.id;
|
|
const first = createEagerImportVisibility(edgeMapOf(relation));
|
|
const later = createEagerImportVisibility(new Map([[scope, []]]));
|
|
expect(first.membership(scope).has('src/a/One.java')).toBe(true);
|
|
expect(later.membership(scope).has('src/a/One.java')).toBe(false);
|
|
expect(later.membership(scope)).not.toBe(first.membership(scope));
|
|
});
|
|
|
|
it('covers duplicates, overlaps, self-targets, unresolved targets and empty lists', () => {
|
|
const statements = generatedRelations.flatMap((relation) =>
|
|
relation.scopes.flatMap((scope) => scope.statements),
|
|
);
|
|
const targetLists = statements.map((statement) => statement.targets);
|
|
expect(targetLists.some((targets) => targets.length === 0)).toBe(true);
|
|
expect(targetLists.some((targets) => targets.includes(null))).toBe(true);
|
|
expect(
|
|
targetLists.some((targets) => targets.some((target) => /^Self/.test(target ?? ''))),
|
|
).toBe(true);
|
|
// The same target list written twice in one scope, compared by content.
|
|
expect(
|
|
generatedRelations.some((relation) =>
|
|
relation.scopes.some(
|
|
(scope) =>
|
|
new Set(scope.statements.map((statement) => JSON.stringify(statement.targets))).size <
|
|
scope.statements.length,
|
|
),
|
|
),
|
|
).toBe(true);
|
|
});
|
|
});
|