qwen-code/scripts/tests/no-core-root-barrel-config.test.js
易良 10c647f320
refactor(core): remove root barrel self-imports and enforce the boundary (#9635)
* refactor(core): remove root barrel self-imports

* fix(core): activate root barrel boundary rule

* test(core): cover root barrel export visitors

* fix(core): remove unused boundary constant

* fix(core): correct misplaced imports flagged by root barrel rule

coreToolScheduler: ToolExecutionStatus is exported from core/turn.ts, not
tools/tools.ts; was also duplicated in the tools import block.
nonInteractiveToolExecutor: RuntimeContentGeneratorView is exported from
agents/runtime/agent-context.ts, not core/contentGenerator.ts.

Both were surfaced by the new no-core-root-barrel-import rule in #9152.

* fix(core): complete telemetry mock and harden barrel rule edge cases

extensionManager.test: the ../telemetry/loggers.js mock was missing
logExtensionInstallEvent, logExtensionUninstall, and logExtensionDisable,
which the source now imports from that path after the barrel cleanup.
This caused 53 test failures.

no-core-root-barrel-import.js: added package-specifier detection
(@qwen-code/qwen-code-core), template-literal dynamic import support,
depth-0 ./index.js handling, and __tests__ exemption parity with the
test-file check. Added trailing newline.

Tests: added coverage for all new edge cases in both rule test files.

Refs #9152

* fix(core): close package-level barrel gap and coverage holes

The barrel rule blocked only specifiers resolving to the src-level
index.{js,ts}; the package-level barrel (packages/core/index.ts, which
re-exports the src barrel) remained reachable via one extra ../ hop.
Match ../index.{js,ts} so core production files cannot re-import the
root barrel through that path.

Also: hoist the duplicated src-root marker to a single constant, reword
the rule message so it no longer hardcodes ../index.js, pin the .ts
spelling branch, fix the vacuous fixtures-exemption case, and add a
cross-directory flat-config fixture so a narrowed files glob fails the
integration test.

Refs #9152

* fix(core): flag barrel subpaths and inline type imports in the root barrel rule

* fix(core): harden no-core-root-barrel-import rule

Anchor the source-root marker on its last occurrence so nested checkouts resolve correctly, reject relative imports of the compiled dist barrel, and treat .spec files as tests. Adds regression coverage for each.
2026-08-22 13:42:10 +00:00

54 lines
1.9 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import { ESLint } from 'eslint';
describe('core root barrel flat-config integration', () => {
it('reports production self-imports (static, type-only, inline-type, and dynamic), ignores tests', async () => {
const eslint = new ESLint({
cwd: process.cwd(),
overrideConfigFile: 'eslint.config.js',
});
const [
prodStatic,
prodTypeOnly,
prodInlineType,
prodDynamic,
prodToolsStatic,
testStatic,
] = await Promise.all([
eslint.lintText("import value from '../index.js';", {
filePath: 'packages/core/src/core/fixture-boundary.ts',
}),
eslint.lintText("import type { Value } from '../index.js';", {
filePath: 'packages/core/src/core/fixture-boundary.ts',
}),
eslint.lintText("type Value = import('../index.js').Value;", {
filePath: 'packages/core/src/core/fixture-boundary.ts',
}),
eslint.lintText("import('../index.js');", {
filePath: 'packages/core/src/core/fixture-boundary.ts',
}),
eslint.lintText("import value from '../index.js';", {
filePath: 'packages/core/src/tools/foo.ts',
}),
eslint.lintText("import value from '../index.js';", {
filePath: 'packages/core/src/core/fixture-boundary.test.ts',
}),
]);
const hasViolation = (results) =>
results.some((r) =>
r.messages.some(
(m) => m.ruleId === 'architecture/no-core-root-barrel-import',
),
);
// production files: all import kinds are caught
expect(hasViolation(prodStatic)).toBe(true);
expect(hasViolation(prodTypeOnly)).toBe(true);
expect(hasViolation(prodInlineType)).toBe(true);
expect(hasViolation(prodDynamic)).toBe(true);
expect(hasViolation(prodToolsStatic)).toBe(true);
// test files stay exempt via the rule's own test/fixture exemption
expect(hasViolation(testStatic)).toBe(false);
});
});