Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
regional-assistant
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c6c7e451
authored
Aug 21, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: add miniprogram knowledge graph core
1 parent
608ebded
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
404 additions
and
0 deletions
scripts/knowledge-graph/build-knowledge-graph.mjs
tests/knowledge-graph/buildKnowledgeGraph.test.mjs
tests/knowledge-graph/fixtures/mini-program/.codex-tmp/ignored.js
tests/knowledge-graph/fixtures/mini-program/.cursor/ignored.md
tests/knowledge-graph/fixtures/mini-program/.vscode/settings.json
tests/knowledge-graph/fixtures/mini-program/api/order.js
tests/knowledge-graph/fixtures/mini-program/app.json
tests/knowledge-graph/fixtures/mini-program/components/card/card.js
tests/knowledge-graph/fixtures/mini-program/components/card/card.json
tests/knowledge-graph/fixtures/mini-program/components/card/card.wxml
tests/knowledge-graph/fixtures/mini-program/docs/COMPONENT-PAGE-INDEX.md
tests/knowledge-graph/fixtures/mini-program/docs/generated/ignored.md
tests/knowledge-graph/fixtures/mini-program/docs/home.md
tests/knowledge-graph/fixtures/mini-program/docs/knowledge/domain-catalog.json
tests/knowledge-graph/fixtures/mini-program/docs/knowledge/known-gaps.json
tests/knowledge-graph/fixtures/mini-program/pages/home/home.js
tests/knowledge-graph/fixtures/mini-program/pages/home/home.json
tests/knowledge-graph/fixtures/mini-program/pages/home/home.wxml
tests/knowledge-graph/fixtures/mini-program/pages/home/services/order-service.js
tests/knowledge-graph/fixtures/mini-program/pkg/pages/confirm/confirm.js
tests/knowledge-graph/fixtures/mini-program/pkg/pages/confirm/confirm.json
tests/knowledge-graph/fixtures/mini-program/pkg/pages/confirm/confirm.wxml
tests/knowledge-graph/fixtures/mini-program/pkg/pages/detail/detail.js
tests/knowledge-graph/fixtures/mini-program/pkg/pages/detail/detail.json
tests/knowledge-graph/fixtures/mini-program/pkg/pages/detail/detail.wxml
tests/knowledge-graph/fixtures/mini-program/tests/.migration-readiness-fixture/ignored.js
tests/knowledge-graph/fixtures/mini-program/tests/home.test.mjs
tests/knowledge-graph/fixtures/mini-program/tests/main-unrelated.test.mjs
tests/knowledge-graph/fixtures/mini-program/tests/order-service.test.mjs
tests/knowledge-graph/fixtures/mini-program/utils/helper.js
tests/knowledge-graph/fixtures/mini-program/utils/request.js
scripts/knowledge-graph/build-knowledge-graph.mjs
0 → 100644
View file @
c6c7e45
This diff is collapsed.
Click to expand it.
tests/knowledge-graph/buildKnowledgeGraph.test.mjs
0 → 100644
View file @
c6c7e45
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath, pathToFileURL } from 'node:url'
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')
const fixtureRoot = path.join(
projectRoot,
'tests/knowledge-graph/fixtures/mini-program',
)
const builderPath = path.join(
projectRoot,
'scripts/knowledge-graph/build-knowledge-graph.mjs',
)
async function loadBuilder() {
assert.equal(
fs.existsSync(builderPath),
true,
'knowledge graph builder must exist',
)
return import(pathToFileURL(builderPath))
}
function findEdge(graph, type, fromIncludes, toIncludes) {
return graph.edges.find(
(edge) =>
edge.type === type &&
edge.from.includes(fromIncludes) &&
edge.to.includes(toIncludes),
)
}
test('builds the public graph contract from mini-program facts', async () => {
const { buildKnowledgeGraph } = await loadBuilder()
const graph = await buildKnowledgeGraph({ rootDir: fixtureRoot })
assert.equal(graph.schemaVersion, '1.0.0')
assert.deepEqual(Object.keys(graph), [
'schemaVersion',
'nodes',
'edges',
'unresolved',
'stats',
])
const nodeTypes = new Set(graph.nodes.map((node) => node.type))
for (const type of [
'domain',
'page',
'component',
'module',
'method',
'apiOperation',
'endpoint',
'globalState',
'test',
'document',
]) {
assert.equal(nodeTypes.has(type), true, `missing ${type} node`)
}
const homePage = graph.nodes.find((node) => node.id === 'page:pages/home/home')
assert.equal(homePage.tabBar, true)
assert.deepEqual(homePage.preloads, ['pkg'])
assert.ok(findEdge(graph, 'usesComponent', 'pages/home/home', 'components/card/card'))
assert.ok(findEdge(graph, 'imports', 'pages/home/home.js', 'api/order.js'))
assert.ok(findEdge(graph, 'imports', 'pages/home/home.js', 'utils/helper.js'))
assert.ok(findEdge(graph, 'bindsEvent', 'pages/home/home', '#loadPageData'))
assert.ok(findEdge(graph, 'bindsEvent', 'components/card/card', '#captureSelect'))
assert.ok(findEdge(graph, 'calls', '#onShow', '#loadPageData'))
assert.ok(findEdge(graph, 'navigatesTo', 'pages/home/home', 'pkg/pages/detail/detail'))
assert.ok(findEdge(graph, 'navigatesTo', 'pkg/pages/detail/detail', 'pkg/pages/confirm/confirm'))
assert.ok(findEdge(graph, 'callsApi', '#loadPageData', 'api/order.js#fetchOrder'))
assert.ok(
findEdge(
graph,
'callsApi',
'pages/home/services/order-service.js#refreshOrders',
'api/order.js#fetchOrder',
),
)
assert.equal(
graph.nodes.some(
(node) => node.id === 'endpoint:dj.api.fixture.notEndpoint',
),
false,
)
assert.ok(
graph.nodes.some(
(node) => node.id === 'endpoint:dj.pad.api.fixture.audit',
),
)
assert.ok(
graph.unresolved.some(
(item) =>
item.kind === 'endpoint' &&
item.path === 'api/order.js' &&
item.reason === 'dynamic-endpoint-expression',
),
)
assert.ok(findEdge(graph, 'callsEndpoint', 'api/order.js#fetchOrder', '/fixture/orders/list'))
assert.ok(
findEdge(
graph,
'callsEndpoint',
'api/order.js#fetchOrderDetail',
'dj.api.fixture.order.detail',
),
)
assert.ok(findEdge(graph, 'writesState', '#loadPageData', 'wx.$orderListRefresh'))
assert.ok(
findEdge(
graph,
'writesState',
'pages/home/services/order-service.js#refreshOrders',
'wx.$orderListRefresh',
),
)
assert.ok(findEdge(graph, 'readsState', '#loadPageData', 'globalData.yqMerchantId'))
assert.ok(findEdge(graph, 'coveredBy', 'pages/home/home.js', 'tests/home.test.mjs'))
assert.ok(findEdge(graph, 'coveredBy', 'utils/helper.js', 'tests/home.test.mjs'))
assert.ok(findEdge(graph, 'documentedBy', 'pages/home/home.js', 'docs/home.md'))
for (const edge of graph.edges) {
assert.equal(typeof edge.confidence, 'number')
assert.match(edge.evidence.path, /^[^\\]+/)
assert.equal(Number.isInteger(edge.evidence.line), true)
assert.equal(Number.isInteger(edge.evidence.column), true)
}
})
test('records dynamic expressions without copying source literals', async () => {
const { buildKnowledgeGraph } = await loadBuilder()
const graph = await buildKnowledgeGraph({ rootDir: fixtureRoot })
assert.ok(
graph.unresolved.some(
(item) =>
item.kind === 'route' && item.path === 'pages/home/home.js',
),
)
assert.ok(
graph.unresolved.some(
(item) =>
item.kind === 'import' && item.path === 'tests/home.test.mjs',
),
)
assert.ok(
graph.unresolved.some(
(item) =>
item.kind === 'testSource' && item.path === 'tests/home.test.mjs',
),
)
const serialized = JSON.stringify(graph)
assert.equal(serialized.includes('id=fixture'), false)
assert.equal(serialized.includes('wx.navigateTo({ url: target })'), false)
assert.equal(
graph.unresolved.some((item) => item.path.startsWith('.vscode/')),
false,
)
for (const ignoredRoot of ['.svn/', '.cursor/', '.codex-tmp/']) {
assert.equal(
graph.nodes.some((node) => node.path?.startsWith(ignoredRoot)),
false,
)
assert.equal(
graph.unresolved.some((item) => item.path.startsWith(ignoredRoot)),
false,
)
}
assert.equal(
graph.nodes.some((node) =>
node.path?.startsWith('tests/.migration-readiness-'),
),
false,
)
assert.equal(
graph.unresolved.some((item) =>
item.path.startsWith('tests/.migration-readiness-'),
),
false,
)
assert.equal(
graph.nodes.some(
(node) =>
node.type === 'document' &&
(node.path?.startsWith('docs/generated/') ||
node.path === 'docs/COMPONENT-PAGE-INDEX.md'),
),
false,
)
})
test('merges every registered alias for a shared component', async () => {
const { buildKnowledgeGraph } = await loadBuilder()
const graph = await buildKnowledgeGraph({ rootDir: fixtureRoot })
const card = graph.nodes.find(
(node) => node.id === 'component:components/card/card',
)
assert.deepEqual(card?.aliases, ['app-card', 'local-card'])
})
test('produces byte-stable output across consecutive builds', async () => {
const { buildKnowledgeGraph, serializeGraph } = await loadBuilder()
const first = serializeGraph(await buildKnowledgeGraph({ rootDir: fixtureRoot }))
const second = serializeGraph(await buildKnowledgeGraph({ rootDir: fixtureRoot }))
assert.equal(first, second)
assert.equal(first.endsWith('\n'), true)
})
tests/knowledge-graph/fixtures/mini-program/.codex-tmp/ignored.js
0 → 100644
View file @
c6c7e45
this
is
intentionally
invalid
JavaScript
tests/knowledge-graph/fixtures/mini-program/.cursor/ignored.md
0 → 100644
View file @
c6c7e45
`pages/home/home.js`
tests/knowledge-graph/fixtures/mini-program/.vscode/settings.json
0 → 100644
View file @
c6c7e45
{
//
Editor
JSONC
must
not
enter
business
parsing.
"editor.formatOnSave"
:
true
}
tests/knowledge-graph/fixtures/mini-program/api/order.js
0 → 100644
View file @
c6c7e45
import
request
from
'../utils/request.js'
export
function
fetchOrder
()
{
return
request
({
url
:
'/fixture/orders/list'
})
}
export
function
fetchOrderDetail
()
{
void
[
'fixture'
].
includes
(
'dj.api.fixture.notEndpoint'
)
request
(
'dj.pad.api.fixture.audit'
)
return
request
(
'dj.api.fixture.order.detail'
)
}
export
function
fetchDynamicEndpoint
(
suffix
)
{
return
request
(
'dj.api.fixture.'
+
suffix
)
}
tests/knowledge-graph/fixtures/mini-program/app.json
0 → 100644
View file @
c6c7e45
{
"pages"
:
[
"pages/home/home"
],
"subpackages"
:
[
{
"root"
:
"pkg"
,
"pages"
:
[
"pages/detail/detail"
,
"pages/confirm/confirm"
]
}
],
"tabBar"
:
{
"list"
:
[
{
"pagePath"
:
"pages/home/home"
,
"text"
:
"首页"
}
]
},
"usingComponents"
:
{
"app-card"
:
"/components/card/card"
},
"preloadRule"
:
{
"pages/home/home"
:
{
"packages"
:
[
"pkg"
]
}
},
"resolveAlias"
:
{
"~/*"
:
"/*"
}
}
tests/knowledge-graph/fixtures/mini-program/components/card/card.js
0 → 100644
View file @
c6c7e45
Component
({
methods
:
{
select
()
{
this
.
triggerEvent
(
'select'
)
},
captureSelect
()
{},
},
})
tests/knowledge-graph/fixtures/mini-program/components/card/card.json
0 → 100644
View file @
c6c7e45
{
"component"
:
true
}
tests/knowledge-graph/fixtures/mini-program/components/card/card.wxml
0 → 100644
View file @
c6c7e45
<button bindtap="select" capture-bind:touchstart="captureSelect">选择</button>
tests/knowledge-graph/fixtures/mini-program/docs/COMPONENT-PAGE-INDEX.md
0 → 100644
View file @
c6c7e45
# Generated component index
This generated compatibility index must not be ingested as source documentation.
tests/knowledge-graph/fixtures/mini-program/docs/generated/ignored.md
0 → 100644
View file @
c6c7e45
# Generated document
This generated file must never become an input to its own knowledge graph.
tests/knowledge-graph/fixtures/mini-program/docs/home.md
0 → 100644
View file @
c6c7e45
# 首页
-
[
首页源码
](
../pages/home/home.js
)
-
路由:
`pkg/pages/detail/detail`
tests/knowledge-graph/fixtures/mini-program/docs/knowledge/domain-catalog.json
0 → 100644
View file @
c6c7e45
{
"schemaVersion"
:
1
,
"domains"
:
[
{
"name"
:
"main"
,
"aliases"
:
[
"首页"
],
"roots"
:
[
"pages"
,
"components"
,
"api"
,
"utils"
],
"entrypoints"
:
[
"pages/home/home"
],
"riskKeywords"
:
[
"orderListRefresh"
],
"documents"
:
[
"docs/home.md"
]
},
{
"name"
:
"pkg"
,
"aliases"
:
[
"详情"
],
"roots"
:
[
"pkg"
],
"entrypoints"
:
[
"pkg/pages/detail/detail"
],
"riskKeywords"
:
[],
"documents"
:
[]
}
]
}
tests/knowledge-graph/fixtures/mini-program/docs/knowledge/known-gaps.json
0 → 100644
View file @
c6c7e45
{
"schemaVersion"
:
1
,
"gaps"
:
[
{
"domain"
:
"pkg"
,
"reason"
:
"fixture business semantics are not documented"
,
"nextStep"
:
"calibrate the detail flow on first change"
}
]
}
tests/knowledge-graph/fixtures/mini-program/pages/home/home.js
0 → 100644
View file @
c6c7e45
import
{
fetchOrder
as
loadOrder
}
from
'~/api/order.js'
import
{
normalizeOrder
}
from
'./services/order-service.js'
const
helper
=
require
(
'../../utils/helper.js'
)
Page
({
onShow
()
{
this
.
loadPageData
()
},
loadPageData
()
{
normalizeOrder
(
loadOrder
())
loadOrder
()
helper
.
touch
()
wx
.
navigateTo
({
url
:
'/pkg/pages/detail/detail?id=fixture'
})
wx
.
$orderListRefresh
=
false
wx
.
$orderListRefresh
=
true
return
getApp
().
globalData
.
yqMerchantId
},
openDynamic
(
target
)
{
wx
.
navigateTo
({
url
:
target
})
},
})
tests/knowledge-graph/fixtures/mini-program/pages/home/home.json
0 → 100644
View file @
c6c7e45
{
"usingComponents"
:
{
"local-card"
:
"/components/card/card"
}
}
tests/knowledge-graph/fixtures/mini-program/pages/home/home.wxml
0 → 100644
View file @
c6c7e45
<view>
<local-card bind:select="loadPageData" />
<app-card />
<navigator url="/pkg/pages/detail/detail">详情</navigator>
</view>
tests/knowledge-graph/fixtures/mini-program/pages/home/services/order-service.js
0 → 100644
View file @
c6c7e45
import
{
fetchOrder
}
from
'../../../api/order.js'
export
function
normalizeOrder
(
order
)
{
return
order
||
null
}
export
function
refreshOrders
()
{
wx
.
$orderListRefresh
=
true
return
fetchOrder
()
}
tests/knowledge-graph/fixtures/mini-program/pkg/pages/confirm/confirm.js
0 → 100644
View file @
c6c7e45
Page
({})
tests/knowledge-graph/fixtures/mini-program/pkg/pages/confirm/confirm.json
0 → 100644
View file @
c6c7e45
{}
tests/knowledge-graph/fixtures/mini-program/pkg/pages/confirm/confirm.wxml
0 → 100644
View file @
c6c7e45
<view>确认</view>
tests/knowledge-graph/fixtures/mini-program/pkg/pages/detail/detail.js
0 → 100644
View file @
c6c7e45
Page
({
onLoad
()
{
const
shouldRefresh
=
wx
.
$orderListRefresh
if
(
shouldRefresh
)
wx
.
$orderListRefresh
=
false
wx
.
$router
.
go
(
'confirm'
)
},
})
tests/knowledge-graph/fixtures/mini-program/pkg/pages/detail/detail.json
0 → 100644
View file @
c6c7e45
{}
tests/knowledge-graph/fixtures/mini-program/pkg/pages/detail/detail.wxml
0 → 100644
View file @
c6c7e45
<view>详情</view>
tests/knowledge-graph/fixtures/mini-program/tests/.migration-readiness-fixture/ignored.js
0 → 100644
View file @
c6c7e45
this
is
intentionally
invalid
JavaScript
tests/knowledge-graph/fixtures/mini-program/tests/home.test.mjs
0 → 100644
View file @
c6c7e45
import fs from 'node:fs'
import { fetchOrder } from '../api/order.js'
fs.readFileSync(new URL('../pages/home/home.js', import.meta.url), 'utf8')
await import('../utils/helper.js')
export async function loadDynamic(target) {
return import(target)
}
export function dynamicSourceUrl(relativePath) {
return new URL(relativePath, import.meta.url)
}
void fetchOrder
tests/knowledge-graph/fixtures/mini-program/tests/main-unrelated.test.mjs
0 → 100644
View file @
c6c7e45
import assert from 'node:assert/strict'
import test from 'node:test'
import request from '../utils/request.js'
test('keeps the owning domain suite visible to affected selection', () => {
assert.deepEqual(request({ ok: true }), { ok: true })
})
tests/knowledge-graph/fixtures/mini-program/tests/order-service.test.mjs
0 → 100644
View file @
c6c7e45
import assert from 'node:assert/strict'
import test from 'node:test'
import { normalizeOrder } from '../pages/home/services/order-service.js'
test('normalizes an empty order', () => {
assert.equal(normalizeOrder(undefined), null)
})
tests/knowledge-graph/fixtures/mini-program/utils/helper.js
0 → 100644
View file @
c6c7e45
module
.
exports
=
{
touch
()
{
return
true
},
}
tests/knowledge-graph/fixtures/mini-program/utils/request.js
0 → 100644
View file @
c6c7e45
export
default
function
request
(
options
)
{
return
options
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment