dsh-project-flow 0.12.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.
@@ -456,12 +456,12 @@ check('不在工作流目录时,浮层说清工作流到底在哪', () => {
456
456
  ranBefore: false,
457
457
  projects: [],
458
458
  routes: undefined,
459
- cwd: 'C:\\Users\\ASUS\\OneDrive\\ドキュメント\\deepseek-harness\\default-workspace',
460
- wherePath: 'D:\\新建文件夹 (4)\\工作流',
459
+ cwd: 'C:\\Users\\someone\\OneDrive\\docs\\default-workspace',
460
+ wherePath: 'D:\\某个盘\\工作流',
461
461
  }, true)))
462
462
  return {
463
463
  ok: text.includes('不在工作流目录')
464
- && text.includes('工作流在:D:\\新建文件夹 (4)\\工作流')
464
+ && text.includes('工作流在:D:\\某个盘\\工作流')
465
465
  && !text.includes('当前工作区:')
466
466
  && !text.includes('停止第'),
467
467
  detail: text,
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Codex 适配器:把 `codex exec` 包成假 ctx。
3
+ *
4
+ * 这一层的价值在于「pipeline 一行都不用改就能换个宿主」。所以测的也是这件事:
5
+ * 事件解不解得对、工具边界配不配得上、退出码翻不翻得成 stopReason。
6
+ *
7
+ * 用假 codex(tests/fixtures/fake-codex.mjs)跑,不花钱、不联网。
8
+ * 真机那一条已经在 D:\flow-codex-test 上跑通过了,那个不用天天跑。
9
+ */
10
+
11
+ import { test } from 'node:test'
12
+ import { sibling } from './paths.mjs'
13
+ import { pathToFileURL } from 'node:url'
14
+ import assert from 'node:assert/strict'
15
+ import { mkdtemp, rm } from 'node:fs/promises'
16
+ import { tmpdir } from 'node:os'
17
+ import { join } from 'node:path'
18
+
19
+ const { createCodexCtx, findCodexBinary } = await import(
20
+ pathToFileURL(sibling('host/codex.mjs')).href + `?t=${Date.now()}`
21
+ )
22
+
23
+ const FAKE = sibling('tests/fixtures/fake-codex.mjs')
24
+ const NODE = process.execPath
25
+
26
+ /** 用假 codex 造一个 ctx。剧本走环境变量,用完还原。 */
27
+ async function withFake(script, fn) {
28
+ const cwd = await mkdtemp(join(tmpdir(), 'flow-codex-'))
29
+ const previous = process.env.FAKE_CODEX_SCRIPT
30
+ process.env.FAKE_CODEX_SCRIPT = script
31
+ const ctx = createCodexCtx({ bin: NODE, binArgs: [FAKE], cwd, model: 'fake-model', sandbox: 'read-only' })
32
+ try {
33
+ await fn(ctx, cwd)
34
+ } finally {
35
+ if (previous === undefined) delete process.env.FAKE_CODEX_SCRIPT
36
+ else process.env.FAKE_CODEX_SCRIPT = previous
37
+ // 子进程刚被杀掉时 Windows 还会占一小会儿目录,直接 rm 会 EBUSY。
38
+ // 这跟适配器无关,是文件系统的结算延迟。
39
+ await rm(cwd, { recursive: true, force: true, maxRetries: 6, retryDelay: 150 })
40
+ }
41
+ }
42
+
43
+ test('正常一轮:拿到文本、收到 usage', async () => {
44
+ await withFake('ok', async (ctx, cwd) => {
45
+ const activation = await ctx.subagents.startActivation({
46
+ label: '测试阶',
47
+ prompt: [{ type: 'text', text: '跑一下' }],
48
+ cwd,
49
+ })
50
+ assert.equal(activation.kind, 'external', '必须报 external:本地会话那套事件监听在这里没有对象可挂')
51
+ const result = await activation.result
52
+ assert.equal(result.stopReason, 'completed')
53
+ // output 必须是块数组。给字符串的话 textOf 会静默返回空串,而且不报错。
54
+ assert.ok(Array.isArray(result.output), 'output 要是内容块数组')
55
+ assert.match(result.output[0].text, /hello\.txt/u)
56
+ const usage = ctx.usage()
57
+ assert.equal(usage.turns, 1)
58
+ assert.equal(usage.input, 1000)
59
+ assert.equal(usage.output, 50)
60
+ assert.equal(usage.cached, 200)
61
+ })
62
+ })
63
+
64
+ test('命令执行的前后会被报成工具开始 / 结束', async () => {
65
+ await withFake('ok', async (ctx, cwd) => {
66
+ const events = []
67
+ const watchdog = {
68
+ touch: () => events.push('touch'),
69
+ toolStart: label => events.push(`start:${label}`),
70
+ toolEnd: () => events.push('end'),
71
+ }
72
+ const ctx2 = createCodexCtx({ bin: NODE, binArgs: [FAKE], cwd, watchdog })
73
+ const activation = await ctx2.subagents.startActivation({ label: 'x', prompt: '跑一下', cwd })
74
+ await activation.result
75
+
76
+ assert.ok(events.includes('start:echo hi'), `要报出工具开始并带上命令,实际:${events.join(',')}`)
77
+ // start 必须排在 end 前面,配不上就是泄漏或者永久 busy
78
+ const startAt = events.indexOf('start:echo hi')
79
+ const endAt = events.indexOf('end')
80
+ assert.ok(startAt >= 0 && endAt > startAt, `start/end 顺序不对:${events.join(',')}`)
81
+ assert.ok(events.filter(e => e === 'touch').length >= 3, '每个事件都该顶一下心跳')
82
+ void ctx
83
+ })
84
+ })
85
+
86
+ test('没跑到 turn.completed 要判失败,不能当成功', async () => {
87
+ await withFake('noturn', async (ctx, cwd) => {
88
+ const activation = await ctx.subagents.startActivation({ label: 'x', prompt: '跑一下', cwd })
89
+ const result = await activation.result
90
+ assert.equal(result.stopReason, 'error', '断了半截还给 completed,等于把没干完的活当成功')
91
+ assert.match(result.diagnostic, /turn\.completed/u, '要说清是没跑到收尾,而不是笼统一句失败')
92
+ })
93
+ })
94
+
95
+ test('退出码非零要把 stderr 带出来', async () => {
96
+ await withFake('fail', async (ctx, cwd) => {
97
+ const activation = await ctx.subagents.startActivation({ label: '实施', prompt: '跑一下', cwd })
98
+ const result = await activation.result
99
+ assert.equal(result.stopReason, 'error')
100
+ assert.match(result.diagnostic, /退出码 1/u)
101
+ assert.match(result.diagnostic, /something went wrong/u, '不带 stderr 的话用户只能盯着一个退出码猜')
102
+ })
103
+ })
104
+
105
+ test('取消能真的把子进程收掉', async () => {
106
+ await withFake('hang', async (ctx, cwd) => {
107
+ const controller = new AbortController()
108
+ const activation = await ctx.subagents.startActivation({
109
+ label: 'x',
110
+ prompt: '跑一下',
111
+ cwd,
112
+ signal: controller.signal,
113
+ })
114
+ setTimeout(() => controller.abort(), 300)
115
+ const result = await activation.result
116
+ assert.equal(result.stopReason, 'error')
117
+ assert.match(result.diagnostic, /已取消/u)
118
+ await activation.dispose()
119
+ })
120
+ })
121
+
122
+ test('prompt 是空的时候不许起空会话', async () => {
123
+ await withFake('ok', async (ctx, cwd) => {
124
+ const activation = await ctx.subagents.startActivation({ label: 'x', prompt: [], cwd })
125
+ const result = await activation.result
126
+ assert.equal(result.stopReason, 'error')
127
+ assert.match(result.diagnostic, /prompt 是空的/u, '空 prompt 起 codex 会白烧一次调用')
128
+ })
129
+ })
130
+
131
+ test('findCodexBinary 找不到时给空串,不抛', () => {
132
+ const got = findCodexBinary({ USERPROFILE: 'Z:\\definitely-not-here', HOME: 'Z:\\definitely-not-here' })
133
+ assert.equal(got, '')
134
+ assert.equal(typeof got, 'string')
135
+ })
136
+
137
+ test('createCodexCtx 缺 bin 要当场报错', () => {
138
+ assert.throws(() => createCodexCtx({}), /codex 可执行文件路径/u)
139
+ })
@@ -0,0 +1,147 @@
1
+ /**
2
+ * codex 可执行文件的自动发现。
3
+ *
4
+ * 这块错起来特别安静:找到的是旧那个 build,功能就是没生效,没有任何报错。
5
+ * 早先是 `found[found.length - 1]`——把目录枚举顺序当版本顺序用,Windows 上
6
+ * 那个顺序既不是字母序也不是时间序,纯看文件系统心情。
7
+ *
8
+ * 这里用假目录树把每一层都钉死,不碰真机上的 codex。
9
+ */
10
+
11
+ import { test } from 'node:test'
12
+ import assert from 'node:assert/strict'
13
+ import { mkdir, mkdtemp, rm, utimes, writeFile } from 'node:fs/promises'
14
+ import { tmpdir } from 'node:os'
15
+ import { dirname, join } from 'node:path'
16
+ import { pathToFileURL } from 'node:url'
17
+ import { sibling } from './paths.mjs'
18
+
19
+ const { findCodexBinary, newestCandidate } = await import(
20
+ pathToFileURL(sibling('host/codex.mjs')).href + `?t=${Date.now()}`
21
+ )
22
+
23
+ const BIN_NAME = process.platform === 'win32' ? 'codex.exe' : 'codex'
24
+
25
+ async function scratch(fn) {
26
+ const root = await mkdtemp(join(tmpdir(), 'pf-codex-find-'))
27
+ try {
28
+ await fn(root)
29
+ } finally {
30
+ await rm(root, { recursive: true, force: true, maxRetries: 6, retryDelay: 150 })
31
+ }
32
+ }
33
+
34
+ /** 造一个假 codex,mtime 往前挪 seconds 秒,用来排出「谁更新」。 */
35
+ async function touch(path, ageSeconds) {
36
+ await mkdir(dirname(path), { recursive: true })
37
+ await writeFile(path, '')
38
+ const when = new Date(Date.now() - ageSeconds * 1000)
39
+ await utimes(path, when, when)
40
+ return path
41
+ }
42
+
43
+ /**
44
+ * 干净的 env。
45
+ *
46
+ * PATH 一定要清空:本机真装着 codex,留着 PATH 的话每一条都会先命中它,
47
+ * 测试就变成「验证本机装没装 codex」,跟被测逻辑没关系了。
48
+ */
49
+ function envOf(root, extra = {}) {
50
+ return {
51
+ USERPROFILE: root,
52
+ HOME: root,
53
+ LOCALAPPDATA: join(root, 'AppData', 'Local'),
54
+ PATH: '',
55
+ ...extra,
56
+ }
57
+ }
58
+
59
+ function desktopBase(root) {
60
+ return join(root, 'AppData', 'Local', 'OpenAI', 'Codex', 'bin')
61
+ }
62
+
63
+ test('已知目录里有多个 build:取 mtime 最新的那个', async () => {
64
+ await scratch(async root => {
65
+ const base = desktopBase(root)
66
+ await touch(join(base, 'oldbuild', BIN_NAME), 3600)
67
+ const newest = await touch(join(base, 'newbuild', BIN_NAME), 60)
68
+ assert.equal(findCodexBinary(envOf(root)), newest)
69
+ })
70
+ })
71
+
72
+ test('目录名带版本号时按版本号比,不是按字符串也不是按时间', async () => {
73
+ await scratch(async root => {
74
+ const base = desktopBase(root)
75
+ // 1.9.0 更新(mtime 更近),但 1.10.0 版本更高。
76
+ // 按字符串比 '1.9.0' > '1.10.0',按时间比也是 1.9.0 赢——两条错路都在这儿。
77
+ await touch(join(base, '1.9.0', BIN_NAME), 10)
78
+ const higher = await touch(join(base, '1.10.0', BIN_NAME), 3600)
79
+ assert.equal(findCodexBinary(envOf(root)), higher)
80
+ })
81
+ })
82
+
83
+ test('CODEX_CLI_PATH 指哪打哪,压过 PATH 和 AppData', async () => {
84
+ await scratch(async root => {
85
+ const explicit = await touch(join(root, 'my-codex', BIN_NAME), 7200)
86
+ await touch(join(desktopBase(root), '9.9.9', BIN_NAME), 0)
87
+ await touch(join(root, 'npm-bin', BIN_NAME), 0)
88
+ const env = envOf(root, { CODEX_CLI_PATH: explicit, PATH: join(root, 'npm-bin') })
89
+ assert.equal(findCodexBinary(env), explicit)
90
+ })
91
+ })
92
+
93
+ test('CODEX_CLI_PATH 指到不存在的文件,当没配,继续往下找', async () => {
94
+ await scratch(async root => {
95
+ const fallback = await touch(join(desktopBase(root), '2.0.0', BIN_NAME), 0)
96
+ const env = envOf(root, { CODEX_CLI_PATH: join(root, 'nope', BIN_NAME) })
97
+ assert.equal(findCodexBinary(env), fallback)
98
+ })
99
+ })
100
+
101
+ test('PATH 上的 codex 优先于 AppData 里那份', async () => {
102
+ await scratch(async root => {
103
+ const onPath = await touch(join(root, 'npm-bin', BIN_NAME), 7200)
104
+ await touch(join(desktopBase(root), '9.9.9', BIN_NAME), 0)
105
+ const env = envOf(root, { PATH: [join(root, 'somewhere'), join(root, 'npm-bin')].join(process.platform === 'win32' ? ';' : ':') })
106
+ assert.equal(findCodexBinary(env), onPath)
107
+ })
108
+ })
109
+
110
+ test('哪儿都没有就给空串,不抛', async () => {
111
+ await scratch(async root => {
112
+ assert.equal(findCodexBinary(envOf(root)), '')
113
+ })
114
+ })
115
+
116
+ // ── 排序本身 ────────────────────────────────────────────
117
+
118
+ test('newestCandidate:空数组给空串', () => {
119
+ assert.equal(newestCandidate([]), '')
120
+ })
121
+
122
+ test('newestCandidate:有版本号的压过没版本号的', () => {
123
+ // build 目录是 hash 的时候 mtime 才可信;一旦有一个能读出真实版本,
124
+ // 那个版本是明确信息,比时间可靠。
125
+ const picked = newestCandidate([
126
+ { path: 'hash', name: '45e749ac65b97f3a', mtimeMs: 9e12 },
127
+ { path: 'versioned', name: '1.0.0', mtimeMs: 1 },
128
+ ])
129
+ assert.equal(picked, 'versioned')
130
+ })
131
+
132
+ test('newestCandidate:都没有版本号时按 mtime 降序', () => {
133
+ const picked = newestCandidate([
134
+ { path: 'a', name: 'alpha', mtimeMs: 100 },
135
+ { path: 'b', name: 'beta', mtimeMs: 300 },
136
+ { path: 'c', name: 'gamma', mtimeMs: 200 },
137
+ ])
138
+ assert.equal(picked, 'b')
139
+ })
140
+
141
+ test('newestCandidate:版本号相同再看 mtime', () => {
142
+ const picked = newestCandidate([
143
+ { path: 'a', name: '2.0.0', mtimeMs: 100 },
144
+ { path: 'b', name: '2.0.0', mtimeMs: 900 },
145
+ ])
146
+ assert.equal(picked, 'b')
147
+ })
package/tests/e2e.mjs CHANGED
@@ -15,7 +15,7 @@ import { LIVE_DIR } from './paths.mjs'
15
15
 
16
16
  const here = dirname(fileURLToPath(import.meta.url))
17
17
  const LIVE = join(LIVE_DIR, 'index.js')
18
- // 测试不读用户自己的运行时配置(C:\Users\ASUS\.dsh\project-flow.json):
18
+ // 测试不读用户自己的运行时配置(~/.dsh/project-flow.json):
19
19
  // 他在界面上设了哪三个模型是他的事,不该让这里的断言红得莫名其妙。
20
20
  process.env.DSH_HOME = await mkdtemp(join(tmpdir(), 'pf-e2e-home-'))
21
21
  const mod = await import(pathToFileURL(LIVE).href + `?t=${Date.now()}`)
@@ -0,0 +1,49 @@
1
+ /**
2
+ * 假的 codex:输出一串预设的 JSONL,用来测解析链。
3
+ *
4
+ * 真 codex 要花钱、要联网、要几十秒。而适配器里真正容易错的是
5
+ * 「事件怎么解、工具边界怎么配对、退出码怎么翻成 stopReason」——这些
6
+ * 只要事件流一样就能验,不必真调模型。
7
+ *
8
+ * 剧本从环境变量 FAKE_CODEX_SCRIPT 读,取值:
9
+ * ok 正常一轮,带一次命令执行
10
+ * noturn 没有 turn.completed(模拟中途断线)
11
+ * fail 退出码 1
12
+ * hang 一直不说话(测超时/取消)
13
+ */
14
+ const mode = process.env.FAKE_CODEX_SCRIPT ?? 'ok'
15
+
16
+ function emit(obj) {
17
+ process.stdout.write(`${JSON.stringify(obj)}\n`)
18
+ }
19
+
20
+ emit({ type: 'thread.started', thread_id: 'fake-thread' })
21
+ emit({ type: 'turn.started' })
22
+
23
+ if (mode === 'ok') {
24
+ emit({ type: 'item.completed', item: { id: 'i0', type: 'agent_message', text: '我来看一下工作目录。' } })
25
+ emit({
26
+ type: 'item.started',
27
+ item: { id: 'i1', type: 'command_execution', command: 'echo hi', aggregated_output: '', exit_code: null, status: 'in_progress' },
28
+ })
29
+ // 故意中间停一会儿:真 codex 跑命令就是这个节奏,这里要验的是
30
+ // 「命令已经 started、还没 completed」这段时间能不能被认出来。
31
+ setTimeout(() => {
32
+ emit({
33
+ type: 'item.completed',
34
+ item: { id: 'i1', type: 'command_execution', command: 'echo hi', aggregated_output: 'hi\n', exit_code: 0, status: 'completed' },
35
+ })
36
+ emit({ type: 'item.completed', item: { id: 'i2', type: 'agent_message', text: '做完了,hello.txt 里写的是 ok。' } })
37
+ emit({ type: 'turn.completed', usage: { input_tokens: 1000, output_tokens: 50, cached_input_tokens: 200 } })
38
+ process.exit(0)
39
+ }, 120)
40
+ } else if (mode === 'noturn') {
41
+ emit({ type: 'item.completed', item: { id: 'i0', type: 'agent_message', text: '说到一半' } })
42
+ process.exit(0)
43
+ } else if (mode === 'fail') {
44
+ process.stderr.write('something went wrong\n')
45
+ process.exit(1)
46
+ } else if (mode === 'hang') {
47
+ // 什么都不发,等被杀
48
+ setInterval(() => {}, 1000)
49
+ }
@@ -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\\ASUS\\default-workspace', settingsOf())
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
  })
@@ -139,7 +139,7 @@ check('配了绝对 flowRoot 时按配置建,不看名字', async () => {
139
139
 
140
140
  // ── 配了绝对路径:只在 strict 下认子树 ──────────────────
141
141
 
142
- const ROOT = 'C:\\Users\\ASUS\\流向'
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
- return 'C:/Users/ASUS/.dsh/profiles/desktop/node_modules/dsh-project-flow'
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
- * 九套 ERR_MODULE_NOT_FOUND,报错长得像代码坏了——实际只是没装。
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
- const markers = [
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
- + '跑测试前缺依赖:这个目录里找不到 @deepseek-ai/schemastery。\n'
168
+ + '跑测试前缺依赖:从被验目录解析不到 @deepseek-ai/schemastery。\n'
159
169
  + `被验目录:${LIVE_DIR}\n`
160
170
  + '\n'
161
171
  + '三种办法,挑一种:\n'
162
- + ' 1. 装进 DSH 的 profile,然后指过去验:\n'
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
- + ' 3. 只想确认包完整、不想装东西:\n'
167
- + ' node -e "require(\'fs\').readdirSync(\'.\').length" # 或者直接看文件在不在\n')
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
@@ -33,6 +33,9 @@ const SUITES = [
33
33
  ['命令把话送到模型', 'steer-command.test.mjs'],
34
34
  ['工作流目录门控', 'flow-gate.test.mjs'],
35
35
  ['交付模式', 'delivery-mode.test.mjs'],
36
+ ['Codex 适配器', 'codex-adapter.test.mjs'],
37
+ ['codex 自动发现', 'codex-discovery.test.mjs'],
38
+ ['CLI 入口:doctor / init / run', 'flow-cli.test.mjs'],
36
39
  ['状态栏看哪个目录', 'watch-root.test.mjs'],
37
40
  ['质检读预览图的路径', 'preview-path.test.mjs'],
38
41
  ['diff / 停机说明 / 盲区记忆', 'feedback.test.mjs'],