GitNexus/gitnexus/test/unit/node-table-layout.test.ts
zwxxb 282d82f1e0 refactor(move): simplify & harden the Move integration architecture (reduced scope)
Trimmed rebuild of 6ea5aa44 (fork PR #4): Move core (gitnexus/src/core/move/)
and Move tests, plus the functional minimum elsewhere.

Dropped from the original commit:
- .gitignore .codex/ entry (unrelated)
- cli/analyze.ts env-constant swap (cosmetic; same string literal)
- core/logger.ts warnRespectingProgressBar extraction and the
  filesystem-walker.ts reuse of it (Move code never imports the helper)
- scope-resolution callable-value-flow warning aggregation and pipeline/run.ts
  progress-warning formatting, with their two tests (warning-UX hardening,
  not Move-functional)
- process-detection interface doc-comment retuning (DEFAULT_CONFIG runtime
  values already match upstream; region left byte-identical to upstream)

Kept outside src/core/move/ and Move tests (one line each):
- gitnexus-shared/src/graph/types.ts: 'external' locationFidelity for
  dependency symbols
- gitnexus-shared/src/lbug/schema-constants.ts: 'Type' node table registration
- core/lbug/schema.ts: Type table schema + Move rel-table endpoint pairs
- core/lbug/node-table-layout.ts: TYPE_LAYOUT CSV layout
- core/lbug/csv-generator.ts: 'Type' in MULTI_LANG_TYPES routing
- core/lbug/lbug-adapter.ts: deleteAllExternalNodes + shared delete-by-label
  mechanics; Type backtick entry
- core/incremental/subgraph-extract.ts: external nodes get the
  delete-all-then-rebuild treatment
- core/run-analyze.ts: Move consistency digest to meta.json;
  deleteAllExternalNodes call; grouped Move meta; finally-based shutdown
- storage/repo-manager.ts: moveConsistency in RepoMeta;
  INCREMENTAL_SCHEMA_VERSION 13 (Type/EnumVariant persistence)
- core/ingestion/pipeline.ts: generic TStandaloneIngest output threading
- types/pipeline.ts: PipelineResult.standaloneIngest replaces ingestWarnings
- core/ingestion/process-processor.ts: ENTRY_POINT_OF explicit graph roots
- tests: schema, node-table-layout, process-processor,
  repo-manager-reconcile, call-summary-schema-version,
  incremental-subgraph-extract, run-analyze-fts-repair (unit);
  lbug-core-adapter (integration)

Gates: tsc clean; Move unit 185/185; full unit suite green except three
pre-existing Darwin-environment failures reproduced on the pristine base;
integration (move + lbug-core-adapter) 29/29.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-24 18:58:03 +02:00

110 lines
3.7 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { GraphNode } from 'gitnexus-shared';
import {
CONST_SCHEMA,
ENUM_SCHEMA,
ENUM_VARIANT_SCHEMA,
FUNCTION_SCHEMA,
MODULE_SCHEMA,
STRUCT_SCHEMA,
TYPE_SCHEMA,
} from '../../src/core/lbug/schema.js';
import {
getNodeTableCsvHeader,
NODE_TABLE_LAYOUTS,
type LayoutTableName,
} from '../../src/core/lbug/node-table-layout.js';
import { buildLayoutNodeRow, escapeCSVBoolean } from '../../src/core/lbug/csv-generator.js';
import { getCopyQuery } from '../../src/core/lbug/lbug-adapter.js';
const schemas: Record<LayoutTableName, string> = {
Function: FUNCTION_SCHEMA,
Struct: STRUCT_SCHEMA,
Enum: ENUM_SCHEMA,
Type: TYPE_SCHEMA,
EnumVariant: ENUM_VARIANT_SCHEMA,
Const: CONST_SCHEMA,
Module: MODULE_SCHEMA,
};
const ddlColumns = (ddl: string): string[] =>
ddl
.split('\n')
.map((line) => line.trim())
.filter((line) => line.endsWith(',') && !line.startsWith('PRIMARY KEY'))
.map((line) => line.split(/\s+/, 1)[0]);
const copyColumns = (query: string): string[] => {
const match = /^COPY\s+`?\w+`?\(([^)]+)\)/.exec(query);
if (!match) throw new Error(`Could not parse COPY query: ${query}`);
return match[1].split(',').map((value) => value.trim());
};
const csvCellCount = (row: string): number => {
let cells = 1;
let quoted = false;
for (let index = 0; index < row.length; index++) {
if (row[index] === '"') {
if (quoted && row[index + 1] === '"') index++;
else quoted = !quoted;
} else if (row[index] === ',' && !quoted) {
cells++;
}
}
return cells;
};
describe('shared node-table persistence layouts', () => {
it.each(Object.keys(NODE_TABLE_LAYOUTS) as LayoutTableName[])(
'%s keeps DDL, CSV, row encoding, and COPY order aligned',
(table) => {
const columns = NODE_TABLE_LAYOUTS[table].columns.map(({ name }) => name);
const node = {
id: `${table}:fixture`,
label: table,
properties: {
name: 'fixture',
filePath: 'src/fixture.move',
startLine: 1,
endLine: 2,
language: table === 'Function' ? 'typescript' : 'rust',
},
} as GraphNode;
expect(ddlColumns(schemas[table])).toEqual(columns);
expect(getNodeTableCsvHeader(table).split(',')).toEqual(columns);
expect(csvCellCount(buildLayoutNodeRow(table, node, 'fixture content'))).toBe(columns.length);
expect(copyColumns(getCopyQuery(table, '/tmp/fixture.csv'))).toEqual(columns);
},
);
it('escapeCSVBoolean matches the incremental path truthy coercion (!!v) for non-boolean inputs', () => {
// The bulk CSV path and the incremental CREATE/MERGE path (`!!properties.x`
// in lbug-adapter) must classify the same value identically, or an
// incremental top-up would flip a boolean column relative to a full
// rebuild. Exercise the values a misbehaving extractor could emit.
for (const value of [true, false, 1, 0, '0', '', 'false', undefined, null, {}]) {
expect(escapeCSVBoolean(value)).toBe(value ? 'true' : 'false');
}
});
it('rejects an unknown CSV column encoding instead of emitting an empty cell', () => {
const column = NODE_TABLE_LAYOUTS.Function.columns[0];
const mutableColumn = column as { csvEncoding: string };
const originalEncoding = column.csvEncoding;
const node = {
id: 'Function:fixture',
label: 'Function',
properties: { name: 'fixture', filePath: 'src/fixture.ts' },
} as GraphNode;
try {
mutableColumn.csvEncoding = 'future-encoding';
expect(() => buildLayoutNodeRow('Function', node, 'fixture content')).toThrow(
'Unsupported CSV column encoding: future-encoding',
);
} finally {
mutableColumn.csvEncoding = originalEncoding;
}
});
});