-
Notifications
You must be signed in to change notification settings - Fork 3k
refactor(cli): enforce utils leaf-layer dependency direction (#9146) #9737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a983ece
refactor(cli): enforce utils leaf-layer dependency direction (#9146)
yiliang114 7735a3b
fix: use Qwen Team 2026 license header on new files (#9146)
yiliang114 204b3c3
chore: refresh stale utils/ path references after leaf-layer move (#9…
yiliang114 21d21a0
Merge remote-tracking branch 'origin/main' into codex/9146-utils-leaf…
yiliang114 a81cbe7
docs: reconcile no-utils-upward-import header with the allowed type-o…
yiliang114 beab2dc
fix(cli): allowlist sandbox process.env accesses after leaf-layer mov…
yiliang114 1e48458
chore(ci): re-record qwen-autofix.yml size baseline after #9677 (#9146)
yiliang114 0566edc
fix(review): drop the stale utils/findings.ts digest root after the l…
yiliang114 0dca7b0
fix(review): colocate seatbelt profiles with the sandbox module (#9146)
yiliang114 25670ab
fix(review): exempt inline type-only specifiers from the utils upward…
yiliang114 21cfacf
fix(review): report upward inline type-specifier imports under verbat…
yiliang114 6980025
test(review): pin mixed-specifier and zero-specifier upward imports i…
yiliang114 bf6b9ba
test(review): anchor the nested-checkout utils rule fixture on the la…
yiliang114 8071456
test(review): pin that the utils/findings.ts digest root stays remove…
yiliang114 256abb1
Merge remote-tracking branch 'origin/main' into codex/9146-utils-leaf…
yiliang114 1b870e2
fix(review): reword stale-bundle SCOPE header to the post-move helper…
yiliang114 ab039d6
test(review): drop the pre-move utils/findings.ts from the skill-pari…
yiliang114 25687c4
test(serve): derive the seatbelt colocation tripwire from BUILTIN_SEA…
yiliang114 764d603
fix(architecture): fail closed on computed dynamic imports in the uti…
yiliang114 98f0134
fix(cli): point settings.test.ts at the post-move settingsUtils path …
yiliang114 e81731f
fix(cli): close utils boundary review gaps
yiliang114 85320da
Merge remote-tracking branch 'origin/main' into codex/pr-9737-closeou…
yiliang114 1445a76
test(cli): cover utils boundary allow paths
yiliang114 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import path from 'node:path'; | ||
|
|
||
| /** | ||
| * `packages/cli/src/utils/` is the leaf layer that every other directory | ||
| * imports. It must not import back up into a domain directory (`config/`, | ||
| * `ui/`, `i18n/`, `nonInteractive/`, `commands/`, `serve/`, | ||
| * `acp-integration/`, ...): that is the dependency-direction invariant | ||
| * tracked in #9146. | ||
| * | ||
| * The only permitted "upward" references are `import type` specifiers. A | ||
| * type-only import is erased at compile time, so it cannot create a runtime | ||
| * module cycle. The two remaining instances (`Settings` in | ||
| * `modelConfigUtils.ts`, `CommandContext` in `sessionPaths.ts`) are this | ||
| * irreducible type-level coupling. | ||
| */ | ||
|
|
||
| const CLI_UTILS_MARKER = 'packages/cli/src/utils/'; | ||
| const TEST_OR_FIXTURE_SEGMENTS = new Set(['__tests__', 'fixtures']); | ||
|
|
||
| function isCliUtilsProductionFile(filename) { | ||
| if (!filename || filename === '<input>' || filename === '<text>') { | ||
| return false; | ||
| } | ||
| const normalized = path.normalize(filename).replaceAll('\\', '/'); | ||
| const start = normalized.lastIndexOf(CLI_UTILS_MARKER); | ||
| if (start < 0) { | ||
| return false; | ||
| } | ||
| const relativePath = normalized.slice(start + CLI_UTILS_MARKER.length); | ||
| if (/\.(test|spec)\.[cm]?[jt]sx?$/.test(relativePath)) { | ||
| return false; | ||
| } | ||
| return !relativePath.split('/').some((s) => TEST_OR_FIXTURE_SEGMENTS.has(s)); | ||
| } | ||
|
|
||
| function escapesUtils(filename, importedPath) { | ||
| const normalized = path.normalize(filename).replaceAll('\\', '/'); | ||
| const utilsRoot = normalized.slice( | ||
| 0, | ||
| normalized.lastIndexOf(CLI_UTILS_MARKER) + CLI_UTILS_MARKER.length, | ||
| ); | ||
| const resolved = path.resolve(path.dirname(filename), importedPath); | ||
| return path | ||
| .relative(utilsRoot, resolved) | ||
| .replaceAll('\\', '/') | ||
| .startsWith('..'); | ||
| } | ||
|
|
||
| export default { | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
| description: | ||
| 'packages/cli/src/utils must not import outside utils/ (leaf-layer dependency direction).', | ||
| }, | ||
| messages: { | ||
| noUtilsUpwardImport: | ||
| 'packages/cli/src/utils must not import outside utils/. ' + | ||
| 'Invert the dependency (pass the value in) or move the module to the ' + | ||
| 'domain directory that owns it (#9146).', | ||
| }, | ||
| }, | ||
| create(context) { | ||
| const { filename } = context; | ||
| if (!isCliUtilsProductionFile(filename)) { | ||
| return {}; | ||
| } | ||
|
|
||
| const reportIfEscaping = (sourceNode, importedPath) => { | ||
| if ( | ||
| typeof importedPath === 'string' && | ||
| importedPath.startsWith('.') && | ||
|
yiliang114 marked this conversation as resolved.
Outdated
|
||
| escapesUtils(filename, importedPath) | ||
| ) { | ||
|
yiliang114 marked this conversation as resolved.
yiliang114 marked this conversation as resolved.
|
||
| context.report({ node: sourceNode, messageId: 'noUtilsUpwardImport' }); | ||
| } | ||
| }; | ||
|
|
||
| const checkStatic = (node) => { | ||
| // Type-only imports (`import type`, `export type ... from`) are erased at | ||
| // compile time and cannot create a runtime cycle. | ||
| if (node.importKind === 'type' || node.exportKind === 'type') { | ||
| return; | ||
| } | ||
|
yiliang114 marked this conversation as resolved.
|
||
| reportIfEscaping(node.source, node.source?.value); | ||
| }; | ||
|
|
||
| const checkDynamic = (node) => { | ||
| const { source } = node; | ||
| if (source.type === 'Literal') { | ||
| reportIfEscaping(source, source.value); | ||
| } else if ( | ||
| source.type === 'TemplateLiteral' && | ||
| source.quasis.length === 1 | ||
| ) { | ||
|
yiliang114 marked this conversation as resolved.
Outdated
yiliang114 marked this conversation as resolved.
Outdated
|
||
| reportIfEscaping(source, source.quasis[0].value.cooked); | ||
| } | ||
| }; | ||
|
|
||
| return { | ||
| ImportDeclaration: checkStatic, | ||
| ExportNamedDeclaration: checkStatic, | ||
| ExportAllDeclaration: checkStatic, | ||
| ImportExpression: checkDynamic, | ||
| // TSImportType (`import('../config/x').T`) is type-only by definition, so | ||
| // it is intentionally not reported. | ||
| }; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.