Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
chore(lint): prevent new legacy app store imports (#43729)
yyhf9241b59fe4f
diff --git a/lint.config.ts b/lint.config.tsindex 74036a4a95a..a15f16bfb3c 100644--- a/lint.config.ts+++ b/lint.config.ts@@ -486,6 +486,7 @@ export const lintConfig = {'vars-on-top': 'error',yoda: ['error', 'never'],'unicorn/no-abusive-eslint-disable': 'error',+ 'dify/no-app-store-imports': 'error','dify/no-file-wide-disable': 'error','dify/require-disable-directive-description': 'error','dify/require-i18n-namespace': 'error',diff --git a/oxlint-suppressions.json b/oxlint-suppressions.jsonindex bf4893a8ac6..246d50b6228 100644--- a/oxlint-suppressions.json+++ b/oxlint-suppressions.json@@ -57,6 +57,16 @@"count": 3}},+ "web/app/(commonLayout)/app/(appDetailLayout)/[appId]/__tests__/layout-main.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/(commonLayout)/app/(appDetailLayout)/[appId]/layout-main.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/tracing/provider-panel.tsx": {"jsx-a11y/click-events-have-key-events": {"count": 3@@ -86,6 +96,11 @@"count": 1}},+ "web/app/components/app/__tests__/app-detail-loading.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/app/annotation/__tests__/index.spec.tsx": {"typescript/no-explicit-any": {"count": 7@@ -247,10 +262,18 @@}},"web/app/components/app/configuration/config-var/config-modal/__tests__/index-logic.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ },"typescript/no-explicit-any": {"count": 3}},+ "web/app/components/app/configuration/config-var/config-modal/__tests__/index.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/app/configuration/config-var/config-modal/__tests__/type-select.spec.tsx": {"typescript/no-explicit-any": {"count": 2@@ -262,6 +285,9 @@}},"web/app/components/app/configuration/config-var/config-modal/index.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ },"typescript/no-explicit-any": {"count": 4}@@ -448,6 +474,11 @@"count": 3}},+ "web/app/components/app/configuration/hooks/configuration-lifecycle/use-configuration-app-context.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/app/configuration/prompt-value-panel/__tests__/index.spec.tsx": {"typescript/no-explicit-any": {"count": 2@@ -463,6 +494,16 @@"count": 2}},+ "web/app/components/app/deploy/built-in-environment-card/index.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/app/deploy/index.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/app/deploy/shared/deployment-configuration/use-deployment-configuration-queries.ts": {"@tanstack/query/prefer-query-options": {"count": 2@@ -1880,6 +1921,11 @@"count": 2}},+ "web/app/components/goto-anything/actions/commands/use-command-context.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/header/account-setting/data-source-page-new/hooks/index.ts": {"no-barrel-files/no-barrel-files": {"count": 2@@ -1989,11 +2035,21 @@"count": 1}},+ "web/app/components/main-nav/__tests__/layout.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/main-nav/components/workspace-switcher.tsx": {"jsx-a11y/no-autofocus": {"count": 1}},+ "web/app/components/main-nav/layout.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/plugins/install-plugin/hooks.ts": {"typescript/no-explicit-any": {"count": 4@@ -2427,21 +2483,71 @@"count": 4}},+ "web/app/components/workflow-app/__tests__/provider-contract.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow-app/components/__tests__/workflow-children.spec.tsx": {"eslint-react/static-components": {"count": 2}},+ "web/app/components/workflow-app/components/__tests__/workflow-main.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow-app/components/workflow-children.tsx": {"typescript/no-explicit-any": {"count": 2}},+ "web/app/components/workflow-app/components/workflow-header/__tests__/features-trigger.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/workflow-app/components/workflow-header/features-trigger.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/workflow-app/components/workflow-header/index.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/workflow-app/components/workflow-main.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/workflow-app/components/workflow-panel.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/workflow-app/hooks/use-is-chat-mode.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts": {"no-restricted-imports": {"count": 1}},+ "web/app/components/workflow-app/hooks/use-workflow-init.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/workflow-app/hooks/use-workflow-refresh-draft.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow-app/hooks/use-workflow-run-callbacks.ts": {"no-restricted-imports": {"count": 2@@ -2453,15 +2559,26 @@}},"web/app/components/workflow-app/hooks/use-workflow-run.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ },"no-restricted-imports": {"count": 2}},"web/app/components/workflow-app/hooks/use-workflow-template.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ },"typescript/no-explicit-any": {"count": 2}},+ "web/app/components/workflow-app/index.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow-app/store/workflow/workflow-slice.ts": {"typescript/no-explicit-any": {"count": 2@@ -2563,7 +2680,15 @@"count": 1}},+ "web/app/components/workflow/hooks/use-auto-generate-webhook-url.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow/hooks/use-checklist.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ },"typescript/no-empty-object-type": {"count": 1}@@ -2841,6 +2966,9 @@}},"web/app/components/workflow/nodes/_base/components/workflow-panel/index.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ },"eslint-react/set-state-in-effect": {"count": 2},@@ -2899,6 +3027,14 @@"web/app/components/workflow/nodes/agent-v2/__tests__/hooks.spec.tsx": {"@tanstack/query/prefer-query-options": {"count": 6+ },+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/workflow/nodes/agent-v2/components/__tests__/agent-orchestrate-panel-content.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1}},"web/app/components/workflow/nodes/agent/__tests__/integration.spec.tsx": {@@ -3013,6 +3149,11 @@"count": 5}},+ "web/app/components/workflow/nodes/human-input/components/delivery-method/__tests__/test-email-sender.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow/nodes/human-input/components/delivery-method/method-selector.tsx": {"jsx-a11y/click-events-have-key-events": {"count": 2@@ -3043,6 +3184,9 @@}},"web/app/components/workflow/nodes/human-input/components/delivery-method/test-email-sender.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ },"jsx-a11y/no-autofocus": {"count": 1}@@ -3052,6 +3196,11 @@"count": 2}},+ "web/app/components/workflow/nodes/human-input/hooks/use-single-run-form-params.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow/nodes/if-else/components/condition-list/condition-input.tsx": {"typescript/no-explicit-any": {"count": 1@@ -3423,6 +3572,11 @@"count": 4}},+ "web/app/components/workflow/nodes/trigger-webhook/__tests__/use-config.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow/nodes/trigger-webhook/components/generic-table.tsx": {"dify/require-disable-directive-description": {"count": 1@@ -3433,6 +3587,11 @@"count": 1}},+ "web/app/components/workflow/nodes/trigger-webhook/use-config.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow/nodes/utils.ts": {"typescript/no-explicit-any": {"count": 1@@ -3512,7 +3671,15 @@"count": 2}},+ "web/app/components/workflow/panel/chat-record/__tests__/index.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow/panel/chat-record/index.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ },"jsx-a11y/click-events-have-key-events": {"count": 1},@@ -3573,6 +3740,16 @@"count": 3}},+ "web/app/components/workflow/panel/debug-and-preview/__tests__/chat-wrapper.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },+ "web/app/components/workflow/panel/debug-and-preview/__tests__/components.spec.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/app/components/workflow/panel/debug-and-preview/__tests__/hooks.spec.ts": {"no-restricted-imports": {"count": 1@@ -3609,6 +3786,9 @@}},"web/app/components/workflow/panel/debug-and-preview/chat-wrapper.tsx": {+ "dify/no-app-store-imports": {+ "count": 1+ },"typescript/no-explicit-any": {"count": 5}@@ -4027,6 +4207,11 @@"count": 1}},+ "web/features/agent-v2/analytics.ts": {+ "dify/no-app-store-imports": {+ "count": 1+ }+ },"web/features/new-rag/__tests__/use-query-data-update-count.spec.tsx": {"@tanstack/query/prefer-query-options": {"count": 1diff --git a/web/plugins/eslint/index.js b/web/plugins/eslint/index.jsindex 6ede72704e2..c60f76916a8 100644--- a/web/plugins/eslint/index.js+++ b/web/plugins/eslint/index.js@@ -1,5 +1,6 @@import consistentPlaceholders from './rules/consistent-placeholders.js'import i18nFlatKey from './rules/i18n-flat-key.js'+import noAppStoreImports from './rules/no-app-store-imports.js'import noExtraKeys from './rules/no-extra-keys.js'import noFileWideDisable from './rules/no-file-wide-disable.js'import preferTailwindIcons from './rules/prefer-tailwind-icons.js'@@ -17,6 +18,7 @@ const plugin = {rules: {'consistent-placeholders': consistentPlaceholders,'i18n-flat-key': i18nFlatKey,+ 'no-app-store-imports': noAppStoreImports,'no-extra-keys': noExtraKeys,'no-file-wide-disable': noFileWideDisable,'prefer-tailwind-icons': preferTailwindIcons,diff --git a/web/plugins/eslint/rules/no-app-store-imports.js b/web/plugins/eslint/rules/no-app-store-imports.jsnew file mode 100644index 00000000000..dbfe8798f10--- /dev/null+++ b/web/plugins/eslint/rules/no-app-store-imports.js@@ -0,0 +1,75 @@+import path from 'node:path'++const webRoot = path.resolve(import.meta.dirname, '../../..')+const appStorePath = path.join(webRoot, 'app/components/app/store')++function isAppStore(source, filename) {+ if (typeof source !== 'string') return false+ const modulePath = source.replace(/[?#].*$/u, '')+ let resolved+ if (modulePath.startsWith('@/') || modulePath.startsWith('~@/')) {+ resolved = path.resolve(webRoot, modulePath.replace(/^~?@\//u, ''))+ } else if (modulePath.startsWith('.') || path.isAbsolute(modulePath)) {+ resolved = path.resolve(path.dirname(filename), modulePath)+ } else {+ return false+ }+ return resolved.replace(/\.(?:[cm]?[jt]s|[jt]sx)$/u, '') === appStorePath+}++function isUnshadowedRequire(sourceCode, node) {+ if (node.callee.type !== 'Identifier' || node.callee.name !== 'require') return false+ let scope = sourceCode.getScope(node)+ while (scope) {+ const variable = scope.set.get('require')+ if (variable) return variable.defs.length === 0+ scope = scope.upper+ }+ return true+}++/** @type {import('eslint').Rule.RuleModule} */+export default {+ meta: {+ type: 'problem',+ docs: {+ description: 'Disallow imports and re-exports of the legacy app detail store.',+ },+ schema: [],+ messages: {+ legacyAppStore:+ 'Do not import the legacy app store. Read app details through generated consoleQuery APIs keyed by appId, and keep UI state in the owning feature.',+ },+ },+ create(context) {+ function checkSource(source) {+ if (source && isAppStore(source.value, context.filename)) {+ context.report({ node: source, messageId: 'legacyAppStore' })+ }+ }++ return {+ ImportDeclaration(node) {+ checkSource(node.source)+ },+ ExportNamedDeclaration(node) {+ checkSource(node.source)+ },+ ExportAllDeclaration(node) {+ checkSource(node.source)+ },+ ImportExpression(node) {+ checkSource(node.source)+ },+ TSImportType(node) {+ checkSource(node.source)+ },+ TSExternalModuleReference(node) {+ checkSource(node.expression)+ },+ CallExpression(node) {+ if (isUnshadowedRequire(context.sourceCode, node)) checkSource(node.arguments[0])+ },+ }+ },+}diff --git a/web/plugins/eslint/rules/no-app-store-imports.test.js b/web/plugins/eslint/rules/no-app-store-imports.test.jsnew file mode 100644index 00000000000..d133a140dcc--- /dev/null+++ b/web/plugins/eslint/rules/no-app-store-imports.test.js@@ -0,0 +1,135 @@+import { spawnSync } from 'node:child_process'+import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'+import { createRequire } from 'node:module'+import { tmpdir } from 'node:os'+import { dirname, join, relative, resolve } from 'node:path'+import { expect, it } from 'vite-plus/test'++const appStore = resolve(import.meta.dirname, '../../../app/components/app/store')+const message =+ 'Do not import the legacy app store. Read app details through generated consoleQuery APIs keyed by appId, and keep UI state in the owning feature.'++function withFixture(run) {+ const require = createRequire(import.meta.url)+ const viteRequire = createRequire(require.resolve('vite-plus/package.json'))+ const oxlintBin = join(dirname(dirname(viteRequire.resolve('oxlint'))), 'bin', 'oxlint')+ const directory = realpathSync(mkdtempSync(join(tmpdir(), 'dify-app-store-imports-')))+ try {+ writeFileSync(+ join(directory, 'plugin.mjs'),+ `export { default } from ${JSON.stringify(require.resolve('../index.js'))};`,+ )+ writeFileSync(+ join(directory, '.oxlintrc.json'),+ JSON.stringify({+ categories: { correctness: 'off' },+ jsPlugins: ['./plugin.mjs'],+ rules: { 'dify/no-app-store-imports': 'error' },+ }),+ )+ function lint(...args) {+ const result = spawnSync(+ process.execPath,+ [oxlintBin, '--config', '.oxlintrc.json', '--format', 'json', ...args],+ { cwd: directory, encoding: 'utf8' },+ )+ expect(result.error).toBeUndefined()+ expect([0, 1], result.stderr + result.stdout).toContain(result.status)+ return { status: result.status, ...JSON.parse(result.stdout) }+ }+ return run({ directory, lint })+ } finally {+ rmSync(directory, { recursive: true, force: true })+ }+}++it('rejects value, type, namespace, and side-effect imports through both aliases', () => {+ withFixture(({ directory, lint }) => {+ writeFileSync(+ join(directory, 'fixture.tsx'),+ [+ "import { useStore as renamed } from '@/app/components/app/store'",+ "import * as store from '~@/app/components/app/store.ts'",+ "import type { useStore } from '@/app/components/app/store'",+ "import '@/app/components/app/store'",+ "import '@/app/components/app/store.ts?legacy'",+ "export * from '~@/app/components/app/store#legacy'",+ ].join('\n'),+ )+ const result = lint('fixture.tsx')+ expect(result.status).toBe(1)+ expect(+ result.diagnostics.map(({ code, message: diagnostic, labels }) => ({+ code,+ message: diagnostic,+ line: labels[0].span.line,+ })),+ ).toEqual(+ [1, 2, 3, 4, 5, 6].map((line) => ({+ code: 'dify(no-app-store-imports)',+ message,+ line,+ })),+ )+ })+})++it('rejects resolved relative paths, re-exports, dynamic imports, and require forms', () => {+ withFixture(({ directory, lint }) => {+ const source = JSON.stringify(relative(directory, appStore))+ writeFileSync(+ join(directory, 'fixture.ts'),+ [+ `import { useStore } from ${source}`,+ `export { useStore as store } from ${source}`,+ `export * from ${source}`,+ `export type { useStore as StoreType } from ${source}`,+ `const lazy = import(${source})`,+ `const required = require(${source})`,+ `import store = require(${source})`,+ `type Store = typeof import(${source})`,+ `import ${JSON.stringify(`${appStore}.js`)}`,+ `const variant = import(${JSON.stringify(`${relative(directory, appStore)}.ts?legacy#source`)})`,+ ].join('\n'),+ )+ const result = lint('fixture.ts')+ expect(result.status).toBe(1)+ expect(result.diagnostics.map(({ labels }) => labels[0].span.line)).toEqual([+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,+ ])+ })+})++it('allows other feature stores, computed sources, mocks, and shadowed require', () => {+ withFixture(({ directory, lint }) => {+ writeFileSync(+ join(directory, 'fixture.ts'),+ [+ "import { useStore } from '@/app/components/workflow-app/store'",+ "export * from '@/app/components/workflow/store'",+ "import './store'",+ "import type { AppDetailWithSite } from '@dify/contracts/api/console/apps/types.gen'",+ "vi.mock('@/app/components/app/store', () => ({}))",+ "function local(require: Function) { require('@/app/components/app/store') }",+ 'function dynamic(source: string) { return import(source) }',+ ].join('\n'),+ )+ expect(lint('fixture.ts').diagnostics).toEqual([])+ })+})++it('baselines existing imports while rejecting a new file and an increased import count', () => {+ withFixture(({ directory, lint }) => {+ const source = "import { useStore } from '@/app/components/app/store'\n"+ writeFileSync(join(directory, 'existing.ts'), source)+ lint('--suppress-all', 'existing.ts')+ expect(JSON.parse(readFileSync(join(directory, 'oxlint-suppressions.json'), 'utf8'))).toEqual({+ 'existing.ts': { 'dify/no-app-store-imports': { count: 1 } },+ })+ expect(lint('existing.ts').diagnostics).toEqual([])+ writeFileSync(join(directory, 'added.ts'), source)+ expect(lint('added.ts').status).toBe(1)+ writeFileSync(join(directory, 'existing.ts'), `${source}import '@/app/components/app/store'`)+ expect(lint('existing.ts').status).toBe(1)+ })+})