GitNexus/eval/workflow_bench/oracles/inv-feature-c-include-provenance.oracle.test.ts
Gergő Magyar 2251adeeb2
fix(eval): grade real C include provenance (#3611)
* fix(eval): verify independent C repairs and reject broken controls

* fix(eval): replace invalid C task with provenance behavior

* fix(eval): grade real C include provenance

* test(eval): add independent typed C reference repairs

* docs(eval): record C oracle evidence contract

* fix(eval): remove invalid synthetic C oracle

* fix(eval): remove type-invalid C reference

* docs: remove C oracle planning document

* test(eval): tolerate formatting in C oracle mutants

* test(eval): clarify C oracle node and file bindings
2026-10-17 15:03:42 +01:00

67 lines
2.8 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { getCParser } from '../gitnexus/src/core/ingestion/languages/c/query.js';
import { splitCInclude } from '../gitnexus/src/core/ingestion/languages/c/import-decomposer.js';
import { interpretCImport } from '../gitnexus/src/core/ingestion/languages/c/interpret.js';
import { cScopeResolver } from '../gitnexus/src/core/ingestion/languages/c/scope-resolver.js';
function parseInclude(spelling: string) {
const tree = getCParser().parse(`#include ${spelling}\n`);
const node = tree.rootNode.namedChildren.find((child) => child.type === 'preproc_include');
if (node === undefined) throw new Error('native parser must produce an include node');
const captures = splitCInclude(node);
return captures === null ? null : interpretCImport(captures);
}
// Header identity is public behavior. Bare targets or targets carrying their
// literal delimiters are both valid; no private marker field is prescribed.
function headerIdentity(target: string): string {
if (
(target.startsWith('<') && target.endsWith('>')) ||
(target.startsWith('"') && target.endsWith('"'))
)
return target.slice(1, -1);
return target;
}
const workspaceFiles = new Set([
'src/main.c',
'src/stdio.h',
'include/project.h',
'src/local.h',
'include/util.h',
]);
describe.each([
{ name: 'workspace headers', files: workspaceFiles, resolutionConfig: undefined },
{
name: 'discovered headers',
files: new Set(['src/main.c']),
resolutionConfig: new Set([...workspaceFiles].filter((file) => file.endsWith('.h'))),
},
])('hidden oracle: retained C include provenance ($name)', ({ files, resolutionConfig }) => {
it.each([
['<stdio.h>', 'stdio.h', null],
['<project.h>', 'project.h', null],
['"stdio.h"', 'stdio.h', 'src/stdio.h'],
['"local.h"', 'local.h', 'src/local.h'],
['"../include/util.h"', '../include/util.h', 'include/util.h'],
] as const)('retains and resolves literal %s', (spelling, header, expected) => {
const parsedImport = parseInclude(spelling);
expect(parsedImport, `literal include ${spelling} must be retained`).not.toBeNull();
expect(parsedImport!.kind).toBe('wildcard');
expect(headerIdentity(parsedImport!.targetRaw), 'retained header identity').toBe(header);
const resolved = cScopeResolver.resolveImportTarget(
parsedImport!.targetRaw,
'src/main.c',
files,
resolutionConfig,
{ parsedFiles: [], parsedImport: parsedImport! },
);
const targets = resolved === null ? [] : typeof resolved === 'string' ? [resolved] : resolved;
expect(targets, `include ${spelling} resolution`).toEqual(expected === null ? [] : [expected]);
});
it('does not invent a literal import for a computed macro include', () => {
expect(parseInclude('HEADER_MACRO')).toBeNull();
});
});