dsh-project-flow 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +112 -0
- package/README.md +31 -10
- package/bin/flow.mjs +365 -36
- package/host/codex.mjs +292 -43
- package/package.json +2 -8
- package/runner/pipeline.mjs +30 -0
- package/tests/client-bundle.test.mjs +3 -3
- package/tests/codex-discovery.test.mjs +147 -0
- package/tests/e2e.mjs +1 -1
- package/tests/flow-cli.test.mjs +191 -0
- package/tests/flow-create.test.mjs +1 -1
- package/tests/flow-gate.test.mjs +1 -1
- package/tests/paths.mjs +27 -17
- package/tests/run-all.mjs +2 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI 入口本身:doctor / init / run 的隔空行为。
|
|
3
|
+
*
|
|
4
|
+
* 不 import bin/flow.mjs——那是个脚本,import 一次就把 main() 跑了。
|
|
5
|
+
* 全部用子进程调,看它吐什么、退出码是多少。这也更接近用户实际用法:
|
|
6
|
+
* 用户遇到的每一个问题都是「命令跑完,屏幕上那几行是什么」。
|
|
7
|
+
*
|
|
8
|
+
* 这一套不调模型、不花钱。run 只测到 --dry-run 为止。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { test } from 'node:test'
|
|
12
|
+
import assert from 'node:assert/strict'
|
|
13
|
+
import { spawnSync } from 'node:child_process'
|
|
14
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
15
|
+
import { tmpdir } from 'node:os'
|
|
16
|
+
import { join } from 'node:path'
|
|
17
|
+
import { pathToFileURL } from 'node:url'
|
|
18
|
+
import { sibling } from './paths.mjs'
|
|
19
|
+
|
|
20
|
+
const CLI = sibling('bin/flow.mjs')
|
|
21
|
+
|
|
22
|
+
const { findCodexBinary } = await import(
|
|
23
|
+
pathToFileURL(sibling('host/codex.mjs')).href + `?t=${Date.now()}`
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
const HAS_CODEX = findCodexBinary() !== ''
|
|
27
|
+
|
|
28
|
+
function run(args, cwd) {
|
|
29
|
+
const result = spawnSync(process.execPath, [CLI, ...args], {
|
|
30
|
+
cwd,
|
|
31
|
+
encoding: 'utf8',
|
|
32
|
+
timeout: 120000,
|
|
33
|
+
windowsHide: true,
|
|
34
|
+
})
|
|
35
|
+
return {
|
|
36
|
+
code: result.status,
|
|
37
|
+
out: String(result.stdout ?? ''),
|
|
38
|
+
err: String(result.stderr ?? ''),
|
|
39
|
+
all: `${result.stdout ?? ''}${result.stderr ?? ''}`,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function scratch(fn) {
|
|
44
|
+
const dir = mkdtempSync(join(tmpdir(), 'pf-cli-'))
|
|
45
|
+
try {
|
|
46
|
+
return fn(dir)
|
|
47
|
+
} finally {
|
|
48
|
+
rmSync(dir, { recursive: true, force: true, maxRetries: 6, retryDelay: 150 })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function writeJson(dir, name, value) {
|
|
53
|
+
const path = join(dir, name)
|
|
54
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`, 'utf8')
|
|
55
|
+
return path
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ── 用法与分发 ──────────────────────────────────────────
|
|
59
|
+
|
|
60
|
+
test('没有子命令:报用法,退出码 2', () => {
|
|
61
|
+
scratch(dir => {
|
|
62
|
+
const result = run([], dir)
|
|
63
|
+
assert.equal(result.code, 2)
|
|
64
|
+
// 三件事都得能看见,不然用户不知道从哪开始
|
|
65
|
+
assert.match(result.out, /flow doctor/u)
|
|
66
|
+
assert.match(result.out, /flow init/u)
|
|
67
|
+
assert.match(result.out, /flow run/u)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('不认识的子命令:说清不认识,并列出可用的', () => {
|
|
72
|
+
scratch(dir => {
|
|
73
|
+
const result = run(['frobnicate'], dir)
|
|
74
|
+
assert.equal(result.code, 2)
|
|
75
|
+
assert.match(result.err, /不认识的子命令/u)
|
|
76
|
+
assert.match(result.err, /doctor/u)
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
// ── init ────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
test('init 写出来的任务书是合法 JSON,字段能直接喂给 run', () => {
|
|
83
|
+
scratch(dir => {
|
|
84
|
+
const result = run(['init'], dir)
|
|
85
|
+
assert.equal(result.code, 0)
|
|
86
|
+
const path = join(dir, 'task.json')
|
|
87
|
+
assert.equal(existsSync(path), true)
|
|
88
|
+
const spec = JSON.parse(readFileSync(path, 'utf8'))
|
|
89
|
+
assert.equal(typeof spec.intent, 'string')
|
|
90
|
+
assert.ok(Array.isArray(spec.requirements) && spec.requirements.length > 0)
|
|
91
|
+
assert.ok(Array.isArray(spec.checks) && spec.checks.length > 0)
|
|
92
|
+
// 每一条 check 都得指向一条真实存在的要求,否则模板本身就交不了差
|
|
93
|
+
for (const item of spec.checks) {
|
|
94
|
+
assert.ok(Number.isInteger(item.req))
|
|
95
|
+
assert.ok(item.req >= 1 && item.req <= spec.requirements.length)
|
|
96
|
+
assert.equal(typeof item.check, 'string')
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('init 不覆盖已有文件,除非加 --force', () => {
|
|
102
|
+
scratch(dir => {
|
|
103
|
+
writeFileSync(join(dir, 'task.json'), '{"intent":"我自己写的"}', 'utf8')
|
|
104
|
+
const blocked = run(['init'], dir)
|
|
105
|
+
assert.equal(blocked.code, 2)
|
|
106
|
+
assert.match(blocked.err, /--force/u)
|
|
107
|
+
// 原文件必须一个字都没动
|
|
108
|
+
assert.match(readFileSync(join(dir, 'task.json'), 'utf8'), /我自己写的/u)
|
|
109
|
+
|
|
110
|
+
const forced = run(['init', '--force'], dir)
|
|
111
|
+
assert.equal(forced.code, 0)
|
|
112
|
+
assert.doesNotMatch(readFileSync(join(dir, 'task.json'), 'utf8'), /我自己写的/u)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
// ── run 的前置检查 ──────────────────────────────────────
|
|
117
|
+
|
|
118
|
+
test('没有任务书时说清缺什么、下一步干什么', () => {
|
|
119
|
+
scratch(dir => {
|
|
120
|
+
const result = run(['run'], dir)
|
|
121
|
+
assert.equal(result.code, 2)
|
|
122
|
+
assert.match(result.err, /找不到任务书/u)
|
|
123
|
+
assert.match(result.err, /flow init/u)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('任务书不是合法 JSON:翻成一句人话,还带下一步', () => {
|
|
128
|
+
scratch(dir => {
|
|
129
|
+
writeFileSync(join(dir, 'task.json'), '{ 这不是 JSON ', 'utf8')
|
|
130
|
+
const result = run(['run'], dir)
|
|
131
|
+
assert.equal(result.code, 1)
|
|
132
|
+
assert.match(result.err, /不是合法 JSON/u)
|
|
133
|
+
assert.match(result.err, /下一步/u)
|
|
134
|
+
// 堆栈不该糊在默认输出里
|
|
135
|
+
assert.doesNotMatch(result.err, /\n\s+at .+:\d+:\d+/u)
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
test('任务书缺 intent:指出缺哪个字段', () => {
|
|
140
|
+
scratch(dir => {
|
|
141
|
+
writeJson(dir, 'task.json', { requirements: ['一条'], checks: [] })
|
|
142
|
+
const result = run(['run'], dir)
|
|
143
|
+
assert.equal(result.code, 1)
|
|
144
|
+
assert.match(result.err, /缺 intent/u)
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
test('requirements 是空的:说清为什么验收无从谈起', () => {
|
|
149
|
+
scratch(dir => {
|
|
150
|
+
writeJson(dir, 'task.json', { intent: '做点什么', requirements: [], checks: [] })
|
|
151
|
+
const result = run(['run'], dir)
|
|
152
|
+
assert.equal(result.code, 1)
|
|
153
|
+
assert.match(result.err, /requirements 是空的/u)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
test('--dry-run 只检查环境:不花钱、不起会话', t => {
|
|
158
|
+
if (!HAS_CODEX) {
|
|
159
|
+
t.skip('这台机器上没有 codex,跳过')
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
scratch(dir => {
|
|
163
|
+
const result = run(['init'], dir)
|
|
164
|
+
assert.equal(result.code, 0)
|
|
165
|
+
const dry = run(['run', '--dry-run'], dir)
|
|
166
|
+
assert.equal(dry.code, 0)
|
|
167
|
+
assert.match(dry.out, /没花钱/u)
|
|
168
|
+
assert.match(dry.out, /要求 \d+ 条,判据 \d+ 条/u)
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
// ── doctor ──────────────────────────────────────────────
|
|
173
|
+
|
|
174
|
+
test('doctor 把每一项都报出来,缺什么指什么', () => {
|
|
175
|
+
scratch(dir => {
|
|
176
|
+
const result = run(['doctor', '--cwd', dir], dir)
|
|
177
|
+
// 环境齐全给 0,有阻断项给 1;两种都算正常输出
|
|
178
|
+
assert.ok(result.code === 0 || result.code === 1, `退出码 ${result.code}`)
|
|
179
|
+
for (const label of ['Node', 'codex', '依赖', '工作目录可写', 'sandbox', 'DSH 配置']) {
|
|
180
|
+
assert.match(result.out, new RegExp(label, 'u'))
|
|
181
|
+
}
|
|
182
|
+
assert.match(result.out, /结论:/u)
|
|
183
|
+
})
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
test('doctor 在结论里给出下一步,而不是只列问题', () => {
|
|
187
|
+
scratch(dir => {
|
|
188
|
+
const result = run(['doctor', '--cwd', dir], dir)
|
|
189
|
+
assert.match(result.out, /下一步/u)
|
|
190
|
+
})
|
|
191
|
+
})
|
|
@@ -142,7 +142,7 @@ test('cwd 在系统盘上时,根挪到别的盘', () => {
|
|
|
142
142
|
if (process.platform !== 'win32') return
|
|
143
143
|
const data = pickDataDrive()
|
|
144
144
|
if (data === undefined) return // 单盘机器,没得挪,跳过
|
|
145
|
-
const root = flowRootOf('C:\\Users\\
|
|
145
|
+
const root = flowRootOf('C:\\Users\\someone\\default-workspace', settingsOf())
|
|
146
146
|
assert.equal(onSystemDrive(root), false, `根不该落在系统盘上,实际 ${root}`)
|
|
147
147
|
assert.ok(root.startsWith(data), `应该挪到 ${data},实际 ${root}`)
|
|
148
148
|
})
|
package/tests/flow-gate.test.mjs
CHANGED
|
@@ -139,7 +139,7 @@ check('配了绝对 flowRoot 时按配置建,不看名字', async () => {
|
|
|
139
139
|
|
|
140
140
|
// ── 配了绝对路径:只在 strict 下认子树 ──────────────────
|
|
141
141
|
|
|
142
|
-
const ROOT = 'C:\\Users\\
|
|
142
|
+
const ROOT = 'C:\\Users\\someone\\流向'
|
|
143
143
|
check('strict + flowRoot 绝对路径:根可以开', () =>
|
|
144
144
|
insideFlow(ROOT, { flowRoot: ROOT, flowGate: 'strict' }) === true)
|
|
145
145
|
check('strict + flowRoot 绝对路径:子目录可以开', () =>
|
package/tests/paths.mjs
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* 想验别的副本仍然可以用 PF_LIVE_DIR 点名。
|
|
9
9
|
*/
|
|
10
10
|
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
11
|
+
import { createRequire } from 'node:module'
|
|
11
12
|
import { join, dirname } from 'node:path'
|
|
12
|
-
import { tmpdir } from 'node:os'
|
|
13
|
+
import { homedir, tmpdir } from 'node:os'
|
|
13
14
|
import { fileURLToPath } from 'node:url'
|
|
14
15
|
|
|
15
16
|
export const HERE = dirname(fileURLToPath(import.meta.url))
|
|
@@ -28,7 +29,10 @@ export const LIVE_DIR = (() => {
|
|
|
28
29
|
const parent = dirname(HERE)
|
|
29
30
|
// 包根里应该有 index.js;有就认它
|
|
30
31
|
if (existsSync(join(parent, 'index.js'))) return parent
|
|
31
|
-
|
|
32
|
+
// 兜底:本机 DSH profile 里装的那份。用 homedir() 拼,不要写死用户名——
|
|
33
|
+
// 别人 fork 下来跑测试时那个路径一定不存在,而报错会指向一个莫名其妙的
|
|
34
|
+
// 文件夹,看不出是「没指 PF_LIVE_DIR」。
|
|
35
|
+
return join(homedir(), '.dsh', 'profiles', 'desktop', 'node_modules', 'dsh-project-flow')
|
|
32
36
|
})()
|
|
33
37
|
|
|
34
38
|
/**
|
|
@@ -141,29 +145,35 @@ export function requireTarget() {
|
|
|
141
145
|
*
|
|
142
146
|
* 解压一个 tgz 不等于装好了:`index.js` 会 import `@deepseek-ai/schemastery`,
|
|
143
147
|
* 那是 peer 依赖,由宿主(DSH)或 `npm i` 提供。直接解压后跑测试会得到
|
|
144
|
-
*
|
|
148
|
+
* 一堆 ERR_MODULE_NOT_FOUND,报错长得像代码坏了——实际只是没装。
|
|
145
149
|
*
|
|
146
|
-
*
|
|
150
|
+
* 早先这里是看 `node_modules/@deepseek-ai` 目录在不在。那是个近似:
|
|
151
|
+
* 父目录里有别的包、或者 pnpm 的软链拓扑不一样,都会被误判成「装了」,
|
|
152
|
+
* 然后真正的报错还是在二十套测试里各炸一次。现在直接按 Node 的解析规则
|
|
153
|
+
* 试着 resolve 一次——能解析出来才算装了。
|
|
147
154
|
*/
|
|
155
|
+
export function dependencyPath() {
|
|
156
|
+
try {
|
|
157
|
+
const require = createRequire(join(LIVE_DIR, 'index.js'))
|
|
158
|
+
return require.resolve('@deepseek-ai/schemastery')
|
|
159
|
+
} catch {
|
|
160
|
+
return ''
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
148
164
|
export function checkDependencies() {
|
|
149
|
-
|
|
150
|
-
join(LIVE_DIR, 'node_modules', '@deepseek-ai'),
|
|
151
|
-
join(dirname(LIVE_DIR), '@deepseek-ai'),
|
|
152
|
-
// pnpm 的布局:.pnpm 下面放着真实包
|
|
153
|
-
join(dirname(LIVE_DIR), '.pnpm'),
|
|
154
|
-
]
|
|
155
|
-
if (markers.some(marker => existsSync(marker))) return true
|
|
165
|
+
if (dependencyPath() !== '') return true
|
|
156
166
|
|
|
157
167
|
console.error(''
|
|
158
|
-
+ '
|
|
168
|
+
+ '跑测试前缺依赖:从被验目录解析不到 @deepseek-ai/schemastery。\n'
|
|
159
169
|
+ `被验目录:${LIVE_DIR}\n`
|
|
160
170
|
+ '\n'
|
|
161
171
|
+ '三种办法,挑一种:\n'
|
|
162
|
-
+ ' 1.
|
|
163
|
-
+ ' PF_LIVE_DIR=<profile>/node_modules/dsh-project-flow node tests/run-all.mjs\n'
|
|
164
|
-
+ ' 2. 就地装依赖:\n'
|
|
172
|
+
+ ' 1. 就地装依赖(在包根,也就是 package.json 所在那一层):\n'
|
|
165
173
|
+ ' npm i\n'
|
|
166
|
-
+ '
|
|
167
|
-
+ ' node -
|
|
174
|
+
+ ' 2. 已经装进 DSH 的 profile 了,就指过去验:\n'
|
|
175
|
+
+ ' PF_LIVE_DIR=<profile>/node_modules/dsh-project-flow node tests/run-all.mjs\n'
|
|
176
|
+
+ ' 3. 只想确认包没缺文件,不想装东西:\n'
|
|
177
|
+
+ ' node -e "console.log(require(\'fs\').readdirSync(\'.\').join(\' \'))"\n')
|
|
168
178
|
return false
|
|
169
179
|
}
|
package/tests/run-all.mjs
CHANGED
|
@@ -34,6 +34,8 @@ const SUITES = [
|
|
|
34
34
|
['工作流目录门控', 'flow-gate.test.mjs'],
|
|
35
35
|
['交付模式', 'delivery-mode.test.mjs'],
|
|
36
36
|
['Codex 适配器', 'codex-adapter.test.mjs'],
|
|
37
|
+
['codex 自动发现', 'codex-discovery.test.mjs'],
|
|
38
|
+
['CLI 入口:doctor / init / run', 'flow-cli.test.mjs'],
|
|
37
39
|
['状态栏看哪个目录', 'watch-root.test.mjs'],
|
|
38
40
|
['质检读预览图的路径', 'preview-path.test.mjs'],
|
|
39
41
|
['diff / 停机说明 / 盲区记忆', 'feedback.test.mjs'],
|