work-rhythm 0.0.0-stage → 0.1.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/.agents/notes/AGENTS.md +86 -0
- package/.agents/notes/decisions/2026-11-28-long-term-goals-ride-existing-tasks.md +36 -0
- package/.agents/notes/decisions/2026-11-29-building-a-workdir-means-cloning-the-template.md +25 -0
- package/.agents/notes/decisions/2026-11-29-find-workdir-cwd-first-then-registered.md +32 -0
- package/.agents/notes/decisions/2026-11-30-bot-inbound-uses-websocket-and-a-responder-command.md +48 -0
- package/.agents/notes/decisions/2026-11-30-cost-entry-writes-into-empty-cells-directly.md +25 -0
- package/.agents/notes/decisions/2026-11-30-dependencies-are-allowed-user-installs-missing-ones.md +30 -0
- package/.agents/notes/decisions/2026-11-30-markdown-is-the-record-html-is-only-a-view.md +25 -0
- package/.agents/notes/decisions/2026-11-30-message-channels-are-preset-in-the-skill.md +34 -0
- package/.agents/notes/decisions/2026-11-30-no-workdir-offers-to-create-one-by-default.md +35 -0
- package/.agents/notes/decisions/2026-11-30-paging-requires-coverage-only-when-enabled.md +27 -0
- package/.agents/notes/decisions/2026-11-30-pending-decisions-asked-in-a-chat-and-logged-briefly.md +39 -0
- package/.agents/notes/decisions/2026-11-30-push-via-personal-robot-webhook.md +33 -0
- package/.agents/notes/decisions/2026-11-30-scheduling-moves-to-a-local-service.md +37 -0
- package/.agents/notes/decisions/2026-11-30-skill-ships-with-its-template-in-a-zip.md +30 -0
- package/.agents/notes/decisions/2026-11-30-skill-stays-generic-user-provides-cli-or-mcp.md +25 -0
- package/.agents/notes/decisions/2026-12-01-everything-is-js-behind-work-rhythm.md +46 -0
- package/.agents/notes/decisions/2026-12-01-repo-is-not-a-workdir-templates-hold-workdir-files.md +29 -0
- package/.agents/notes/decisions/2026-12-01-repo-stays-generic-personal-data-lives-in-workdirs.md +32 -0
- package/.agents/notes/decisions/2026-12-01-workdir-is-not-a-git-repository.md +25 -0
- package/.agents/notes/pitfalls/2026-11-29-do-not-hand-roll-git-log.md +22 -0
- package/.agents/notes/pitfalls/2026-11-29-empty-or-partial-collector-output.md +23 -0
- package/.agents/notes/pitfalls/2026-11-29-skill-description-is-truncated.md +21 -0
- package/.agents/notes/pitfalls/2026-11-29-tool-shell-is-zsh.md +24 -0
- package/.agents/notes/pitfalls/2026-11-30-compare-timestamps-as-digits.md +22 -0
- package/.agents/notes/pitfalls/2026-11-30-message-search-lags-after-sending.md +18 -0
- package/.agents/notes/pitfalls/2026-11-30-rewriting-a-file-with-empty-output-after-tool-failure.md +20 -0
- package/.agents/notes/pitfalls/2026-11-30-secret-scan-false-positive-on-hyphenated-file-names.md +18 -0
- package/.agents/notes/pitfalls/2026-11-30-selftest-must-not-inherit-local-config.md +29 -0
- package/.agents/notes/pitfalls/2026-11-30-yzj-cli-list-limit-is-20.md +25 -0
- package/.agents/notes/pitfalls/2026-11-30-zsh-no-word-splitting-special-names.md +23 -0
- package/.agents/notes/pitfalls/2026-12-01-node-test-hooks-cannot-register-after-callbacks.md +22 -0
- package/.agents/notes/pitfalls/2026-12-01-spawning-node-test-inside-a-test-runs-nothing.md +18 -0
- package/.agents/skills/work-rhythm/SKILL.md +278 -0
- package/AGENTS.md +19 -0
- package/README.md +69 -2
- package/collectors/approval-yzj.js +114 -0
- package/collectors/calendar-yzj.js +48 -0
- package/collectors/file-activity.js +131 -0
- package/collectors/git-activity.js +105 -0
- package/collectors/im-yzj.js +151 -0
- package/collectors/linky-issues.js +88 -0
- package/collectors/local.env.example +52 -0
- package/docs/channels.md +95 -0
- package/docs/formats.md +285 -0
- package/docs/im-adapters.md +79 -0
- package/docs/scheduled-tasks.md +115 -0
- package/docs/sources.md +104 -0
- package/package.json +35 -4
- package/scripts/cli.js +101 -0
- package/scripts/cmd/check.js +330 -0
- package/scripts/cmd/collect.js +25 -0
- package/scripts/cmd/decisions.js +236 -0
- package/scripts/cmd/goals.js +145 -0
- package/scripts/cmd/init.js +49 -0
- package/scripts/cmd/listen.js +91 -0
- package/scripts/cmd/notify.js +42 -0
- package/scripts/cmd/pack.js +104 -0
- package/scripts/cmd/rhythm.js +102 -0
- package/scripts/cmd/selftest.js +23 -0
- package/scripts/cmd/sync.js +73 -0
- package/scripts/cmd/today.js +29 -0
- package/scripts/cmd/workdir.js +81 -0
- package/scripts/lib/agent.js +270 -0
- package/scripts/lib/bot.js +376 -0
- package/scripts/lib/collector.js +74 -0
- package/scripts/lib/config.js +250 -0
- package/scripts/lib/launchd.js +82 -0
- package/scripts/lib/log.js +22 -0
- package/scripts/lib/markdown.js +208 -0
- package/scripts/lib/notify.js +43 -0
- package/scripts/lib/rhythm.js +508 -0
- package/scripts/lib/robot.js +64 -0
- package/scripts/lib/run.js +151 -0
- package/scripts/lib/template.js +149 -0
- package/scripts/lib/workdir.js +98 -0
- package/scripts/test/check.test.js +279 -0
- package/scripts/test/collectors.test.js +574 -0
- package/scripts/test/config.test.js +118 -0
- package/scripts/test/decisions.test.js +129 -0
- package/scripts/test/fake-webhook.js +31 -0
- package/scripts/test/goals.test.js +109 -0
- package/scripts/test/harness.js +277 -0
- package/scripts/test/init.test.js +123 -0
- package/scripts/test/listen.test.js +362 -0
- package/scripts/test/notify.test.js +176 -0
- package/scripts/test/pack.test.js +141 -0
- package/scripts/test/rhythm.test.js +333 -0
- package/scripts/test/stubs.js +140 -0
- package/scripts/test/today.test.js +73 -0
- package/scripts/test/workdir.test.js +152 -0
- package/scripts/work-rhythm.js +18 -0
- package/tasks/alerts-morning.md +24 -0
- package/tasks/carryover.md +16 -0
- package/tasks/daily-plan.md +29 -0
- package/tasks/evening-review.md +27 -0
- package/tasks/linky-cost-check.md +13 -0
- package/tasks/linky-cost-fill.md +20 -0
- package/tasks/noon-checkin.md +15 -0
- package/tasks/weekly-rhythm.md +18 -0
- package/templates/00-config/profile.example.yaml +54 -0
- package/templates/00-config/sources.yaml +115 -0
- package/templates/03-carryover/CARRYOVER.md +14 -0
- package/templates/03-carryover/DECISIONS.md +10 -0
- package/templates/04-patterns/WORK_RHYTHM.md +16 -0
- package/templates/AGENTS.md +31 -0
- package/templates/README.md +73 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { test } = require('node:test');
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { PACKAGE_ROOT, makeSandbox, run: rawRun, read, write, setKey } = require('./harness');
|
|
7
|
+
const os = require('node:os');
|
|
8
|
+
const { genericProblems } = require('../cmd/check').__test;
|
|
9
|
+
const { templateProblems } = require('../lib/template');
|
|
10
|
+
|
|
11
|
+
// 搭工作目录(空白模板)。check 的退出码:0 全部通过,1 有未通过的项
|
|
12
|
+
function setup(t) {
|
|
13
|
+
const box = makeSandbox(t);
|
|
14
|
+
box.workdir();
|
|
15
|
+
const profile = `${box.work}/00-config/profile.yaml`;
|
|
16
|
+
const sources = `${box.work}/00-config/sources.yaml`;
|
|
17
|
+
const stubs = box.stubs();
|
|
18
|
+
return {
|
|
19
|
+
box,
|
|
20
|
+
stubs,
|
|
21
|
+
profile,
|
|
22
|
+
sources,
|
|
23
|
+
setNotify: (value) => write(profile, setKey(read(profile), 'notify', value)),
|
|
24
|
+
localEnv: (text) => write(`${box.work}/collectors/local.env`, text),
|
|
25
|
+
check: (env = { STUB_KEYCHAIN: 'no' }) => box.run(['check'], { env }),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('check:干净的模板上全部通过', (t) => {
|
|
30
|
+
const s = setup(t);
|
|
31
|
+
const r = s.check();
|
|
32
|
+
assert.equal(r.code, 0, r.out);
|
|
33
|
+
assert.match(r.stdout, /== 1\/6 脚本语法 ==\n== 2\/6 文档内链 ==\n== 3\/6 预算 ==\n== 4\/6 配置自检 ==\n== 5\/6 疑似密钥 ==\n== 6\/6 笔记格式 ==\n全部通过\n/);
|
|
34
|
+
assert.equal(r.stderr, '');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('check:报出没配置的源、缺脚本的源、疑似密钥(含机器人 Webhook 的 token,只报位置)和断链', (t) => {
|
|
38
|
+
const s = setup(t);
|
|
39
|
+
write(s.sources, `${read(s.sources)}
|
|
40
|
+
|
|
41
|
+
- id: im-probe
|
|
42
|
+
name: 自测用
|
|
43
|
+
enabled: true
|
|
44
|
+
collector: im-yzj
|
|
45
|
+
cadence: on-demand
|
|
46
|
+
extract: |
|
|
47
|
+
仅用于自测。
|
|
48
|
+
|
|
49
|
+
- id: nofile
|
|
50
|
+
name: 自测用
|
|
51
|
+
enabled: true
|
|
52
|
+
collector: collectors/nope.sh
|
|
53
|
+
cadence: on-demand
|
|
54
|
+
extract: |
|
|
55
|
+
仅用于自测。
|
|
56
|
+
`);
|
|
57
|
+
write(`${s.box.work}/02-daily/2026-11/2026-11-27.md`, '# 2026-11-27\n\n## 备注\n\n- 密钥 sk-abcdefghijklmnop1234 不该出现在这里\n- 机器人地址 https://www.yunzhijia.com/gateway/robot/webhook/send?yzjtype=0&yzjtoken=abcdef0123456789abcd\n');
|
|
58
|
+
write(`${s.box.work}/docs/broken.md`, '[断链](nope.md)\n');
|
|
59
|
+
const r = s.check();
|
|
60
|
+
assert.equal(r.code, 1);
|
|
61
|
+
assert.match(r.stdout, /已启用的源 im-probe 需要 collectors\/local.env(从 local.env.example 复制后填写 YZJ_GROUP_IDS_IM_PROBE)/);
|
|
62
|
+
assert.match(r.stdout, /已启用的源 nofile 缺采集脚本: collectors\/nope.sh(关掉它,或把脚本补上)/);
|
|
63
|
+
assert.match(r.stdout, /疑似密钥,先删掉再提交(下面只是位置):\n02-daily\/2026-11\/2026-11-27.md:5\n02-daily\/2026-11\/2026-11-27.md:6\n/);
|
|
64
|
+
assert.match(r.stdout, /断链 \.\/docs\/broken.md -> nope.md/);
|
|
65
|
+
assert.ok(!r.stdout.includes('sk-abcdefghijklmnop1234'));
|
|
66
|
+
assert.ok(!r.stdout.includes('abcdef0123456789abcd'));
|
|
67
|
+
// 断链 1、源 2、密钥 2(两行各算一处)
|
|
68
|
+
assert.match(r.stdout, /5 项未通过\n/);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('check:源用内置采集器时,变量在 local.env 里配了就不报;要的命令没装就报', (t) => {
|
|
72
|
+
const s = setup(t);
|
|
73
|
+
let text = read(s.sources).replace(/(\n\s*- id: linky-issues[\s\S]*?enabled:) false/, '$1 true');
|
|
74
|
+
assert.notEqual(text, read(s.sources), 'sources.yaml 里没找到 linky-issues');
|
|
75
|
+
write(s.sources, text);
|
|
76
|
+
s.localEnv('YZJ_GROUP_IDS_IM_PROBE="g1|g2"\n');
|
|
77
|
+
// PATH 上没有假的 linky(也不带 stubs)
|
|
78
|
+
const r = s.check({ PATH: '/usr/bin:/bin' });
|
|
79
|
+
assert.equal(r.code, 1, r.out);
|
|
80
|
+
assert.match(r.stdout, /已启用的源 linky-issues 需要 linky,本机没有/);
|
|
81
|
+
// 装上就好
|
|
82
|
+
assert.equal(s.check({ ...s.stubs, PATH: `${s.box.bin}:/usr/bin:/bin` }).code, 0);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('check:local.env 引用未定义变量、写法不对时报出来', (t) => {
|
|
86
|
+
const s = setup(t);
|
|
87
|
+
s.localEnv('GIT_ACTIVITY_WORKSPACES="$HOME/ws"\nFILE_ACTIVITY_WORKSPACES="$UNDEFINED_THING/x"\n这一行不是赋值\n');
|
|
88
|
+
const r = s.check();
|
|
89
|
+
assert.equal(r.code, 1);
|
|
90
|
+
assert.match(r.stdout, /collectors\/local.env 第 2 行引用了未定义的变量 UNDEFINED_THING/);
|
|
91
|
+
assert.match(r.stdout, /collectors\/local.env 第 3 行不是 KEY=VALUE 的写法:这一行不是赋值/);
|
|
92
|
+
assert.ok(!r.stdout.includes('第 1 行'), '$HOME 是有定义的');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('check:自己写的采集器有语法错时报出来', (t) => {
|
|
96
|
+
const s = setup(t);
|
|
97
|
+
write(`${s.box.work}/collectors/broken.js`, 'const = 1;\n');
|
|
98
|
+
const r = s.check();
|
|
99
|
+
assert.equal(r.code, 1);
|
|
100
|
+
assert.match(r.stdout, /Unexpected token '='\n语法错误 collectors\/broken\.js\n/);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('check:报出文件名不对、没有 Verified、缺小节的踩坑笔记', (t) => {
|
|
104
|
+
const s = setup(t);
|
|
105
|
+
const dir = `${s.box.work}/.agents/notes/pitfalls`;
|
|
106
|
+
write(`${dir}/nodate.md`, '# 没写怎么验证的笔记\n\n## 现象\n\nx\n');
|
|
107
|
+
write(`${dir}/2026-11-29-incomplete.md`, '# 缺了小节的笔记\n\n## 现象\n\nx\n');
|
|
108
|
+
// 头部信息夹在 front matter 里(第 3、4 行)也算有
|
|
109
|
+
write(`${dir}/2026-11-28-frontmatter.md`, '---\ntitle: x\nVerified: 2026-11-28 · 再跑一遍\nOrigin: 2026-11-28 · 自测 · 跑出来\n---\n\n# 带头部信息的笔记\n\n## 现象\n\n## 原因\n\n## 怎么做\n');
|
|
110
|
+
const r = s.check();
|
|
111
|
+
assert.equal(r.code, 1, r.out);
|
|
112
|
+
assert.match(r.stdout, /笔记 \.agents\/notes\/pitfalls\/nodate\.md:文件名应为 yyyy-mm-dd-<英文短横线标题>\.md\n/);
|
|
113
|
+
assert.match(r.stdout, /incomplete\.md:前 6 行里没有「Verified: yyyy-mm-dd · <重新确认这个坑还在的方法>」/);
|
|
114
|
+
assert.match(r.stdout, /incomplete\.md:前 6 行里没有「Origin: yyyy-mm-dd · <在哪踩的> · <怎么发现的>」/);
|
|
115
|
+
assert.match(r.stdout, /incomplete\.md:缺少小节「## 原因」/);
|
|
116
|
+
assert.match(r.stdout, /incomplete\.md:缺少小节「## 怎么做」/);
|
|
117
|
+
assert.ok(!r.stdout.includes('frontmatter.md'), '头部信息写在 front matter 里也算有');
|
|
118
|
+
// 文件名不对的只报文件名,不再往下查
|
|
119
|
+
assert.equal(r.stdout.split('\n').filter((l) => l.includes('nodate.md')).length, 1);
|
|
120
|
+
assert.match(r.stdout, /5 项未通过\n/);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('check:报出 skill 头部里不认识的键和过长的 description', (t) => {
|
|
124
|
+
const s = setup(t);
|
|
125
|
+
const skill = `${s.box.work}/.agents/skills/work-rhythm/SKILL.md`;
|
|
126
|
+
const original = read(skill);
|
|
127
|
+
const padded = original.replace(/^(description: "[^"]*)"$/m, `$1${'追加的说明文字'.repeat(20)}"`);
|
|
128
|
+
assert.notEqual(padded, original, '没找到 description 那一行');
|
|
129
|
+
write(skill, padded.replace(/^name: work-rhythm$/m, 'name: work-rhythm\nversion: 9'));
|
|
130
|
+
const r = s.check();
|
|
131
|
+
assert.equal(r.code, 1, r.out);
|
|
132
|
+
assert.match(r.stdout, /SKILL\.md 的头部有 ZCode 不认识的键:version(会被忽略;其他信息放进 metadata)/);
|
|
133
|
+
assert.match(r.stdout, /SKILL\.md 的 description 超过 250 个字符(现在 \d+),超出的部分模型看不到/);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('check:SKILL.md 太长、AGENTS.md 的行数和 standing orders 超了也报', (t) => {
|
|
137
|
+
const s = setup(t);
|
|
138
|
+
const skill = `${s.box.work}/.agents/skills/work-rhythm/SKILL.md`;
|
|
139
|
+
write(skill, `${read(skill)}\n${Array.from({ length: 600 }, () => '填充').join('\n')}\n`);
|
|
140
|
+
write(`${s.box.work}/AGENTS.md`, `# x\n\n## Standing orders\n\n${Array.from({ length: 11 }, () => '- 一条').join('\n')}\n`);
|
|
141
|
+
const r = s.check();
|
|
142
|
+
assert.match(r.stdout, /SKILL\.md 超过 500 个非空行/);
|
|
143
|
+
assert.match(r.stdout, /AGENTS\.md 的 standing orders 超过 10 条/);
|
|
144
|
+
assert.ok(!r.stdout.includes('AGENTS.md 超过 60 个非空行'), 'AGENTS.md 没到 60 行');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('check:profile.yaml 缺了空白模板里声明的字段时报出来', (t) => {
|
|
148
|
+
const s = setup(t);
|
|
149
|
+
const original = read(s.profile);
|
|
150
|
+
write(s.profile, original.split('\n').filter((l) => !/^\s*notify:/.test(l)).join('\n'));
|
|
151
|
+
const r = s.check();
|
|
152
|
+
assert.equal(r.code, 1);
|
|
153
|
+
assert.match(r.stdout, /00-config\/profile\.yaml 缺了这些字段(对照 profile\.example\.yaml 补上): notify/);
|
|
154
|
+
assert.ok(!r.stdout.includes('alerts-morning'), '个人多加的字段不管');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('check:消息渠道 yzj-robot 配了、钥匙串里却没有地址时报出来,不打印地址', (t) => {
|
|
158
|
+
const s = setup(t);
|
|
159
|
+
s.setNotify('yzj-robot');
|
|
160
|
+
const r = s.check({ STUB_KEYCHAIN: 'no' });
|
|
161
|
+
assert.equal(r.code, 1);
|
|
162
|
+
assert.match(r.stdout, /消息渠道 yzj-robot:钥匙串里没有 work-rhythm-yzj-robot-webhook(开通步骤见 docs\/channels\.md「云之家」)/);
|
|
163
|
+
assert.ok(!r.stdout.includes('stubtoken'));
|
|
164
|
+
assert.equal(s.check({ STUB_KEYCHAIN: 'ok' }).code, 0);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('check:没装 security 时报出来', (t) => {
|
|
168
|
+
const s = setup(t);
|
|
169
|
+
s.setNotify('yzj-robot');
|
|
170
|
+
const empty = path.join(s.box.root, 'empty-bin');
|
|
171
|
+
fs.mkdirSync(empty, { recursive: true });
|
|
172
|
+
// PATH 上有 node 和 bash、没有 security(它在 /usr/bin 里)
|
|
173
|
+
const r = s.check({ PATH: `${path.dirname(process.execPath)}:/bin:${empty}` });
|
|
174
|
+
assert.equal(r.code, 1, r.out);
|
|
175
|
+
assert.match(r.stdout, /消息渠道 yzj-robot 需要 security,本机没有/);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('check:值守配的命令找不到时报出来', (t) => {
|
|
179
|
+
const s = setup(t);
|
|
180
|
+
s.setNotify('yzj-robot');
|
|
181
|
+
s.localEnv('YZJ_BOT_AGENT="/nonexistent/agent x"\nYZJ_MY_OPEN_ID="me-0001"\n');
|
|
182
|
+
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
183
|
+
assert.equal(r.code, 1);
|
|
184
|
+
assert.match(r.stdout, /YZJ_BOT_AGENT 的命令找不到: \/nonexistent\/agent/);
|
|
185
|
+
assert.ok(!r.stdout.includes('值守属于 yzj-robot 渠道'));
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('check:值守没写我的 openId 时报出来', (t) => {
|
|
189
|
+
const s = setup(t);
|
|
190
|
+
s.setNotify('yzj-robot');
|
|
191
|
+
s.localEnv('YZJ_BOT_AGENT="zcode"\n');
|
|
192
|
+
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
193
|
+
assert.match(r.stdout, /要写 YZJ_MY_OPEN_ID/);
|
|
194
|
+
assert.ok(!r.stdout.includes('值守属于 yzj-robot 渠道'));
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('check:notify 不是 yzj-robot 却配了值守时报出来;值守配好之后不再报它', (t) => {
|
|
198
|
+
const s = setup(t);
|
|
199
|
+
s.localEnv(`YZJ_BOT_AGENT="zcode"\nYZJ_MY_OPEN_ID="me-0001"\nZCODE_CLI="${s.stubs.ZCODE_CLI}"\n`);
|
|
200
|
+
s.setNotify('""');
|
|
201
|
+
assert.match(s.check({ STUB_KEYCHAIN: 'ok' }).stdout, /值守属于 yzj-robot 渠道:preferences\.notify 要设成 yzj-robot/);
|
|
202
|
+
s.setNotify('yzj-robot');
|
|
203
|
+
const ok = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
204
|
+
assert.equal(ok.code, 0, ok.out);
|
|
205
|
+
assert.ok(!ok.stdout.includes('值守'));
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('check:值守配了 dsh 却找不到它的配置时报出来', (t) => {
|
|
209
|
+
const s = setup(t);
|
|
210
|
+
s.setNotify('yzj-robot');
|
|
211
|
+
s.localEnv(`YZJ_BOT_AGENT="dsh"\nYZJ_MY_OPEN_ID="me-0001"\nDSH_HOME="${s.box.root}/no-such-home"\nDSH_NODE="${path.join(s.box.bin, 'fake-dsh-node')}"\nDSH_CLI="${path.join(s.box.bin, 'fake-dsh')}"\n`);
|
|
212
|
+
const r = s.check({ STUB_KEYCHAIN: 'ok' });
|
|
213
|
+
assert.equal(r.code, 1);
|
|
214
|
+
assert.match(r.stdout, /找不到 DSH 的配置/);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('check:这个包自己的仓库要全部通过——它不是工作目录,只放 skill 和 CLI,不带个人数据', (t) => {
|
|
218
|
+
// 站在仓库里跑:7 项,有「模板」「仓库保持通用」,没有「配置自检」
|
|
219
|
+
const r = rawRun(['check'], { cwd: PACKAGE_ROOT, env: { WORK_RHYTHM_CONFIG: path.join(os.tmpdir(), 'no-such-config.yaml') } });
|
|
220
|
+
assert.equal(r.code, 0, r.out);
|
|
221
|
+
assert.match(r.stdout, /== 1\/7 脚本语法 ==\n== 2\/7 文档内链 ==\n== 3\/7 预算 ==\n== 4\/7 模板 ==\n== 5\/7 疑似密钥 ==\n== 6\/7 笔记格式 ==\n== 7\/7 仓库保持通用 ==\n全部通过\n/);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('站在仓库里:check 查的是仓库,不是用户级登记的那个工作目录;别的命令说清这里不是工作目录', (t) => {
|
|
225
|
+
const box = makeSandbox(t);
|
|
226
|
+
box.workdir();
|
|
227
|
+
const cfg = path.join(box.root, 'cfg.yaml');
|
|
228
|
+
write(cfg, `workdir: ${box.work}\n`);
|
|
229
|
+
const env = { WORK_RHYTHM_CONFIG: cfg };
|
|
230
|
+
// 登记指向另一个工作目录,但人站在仓库里:check 查仓库(7 项),today 不偷偷落到登记的那个上
|
|
231
|
+
assert.equal(rawRun(['check'], { cwd: path.join(PACKAGE_ROOT, 'scripts'), env }).code, 0);
|
|
232
|
+
assert.match(rawRun(['check'], { cwd: path.join(PACKAGE_ROOT, 'scripts'), env }).stdout, /== 7\/7 仓库保持通用 ==/);
|
|
233
|
+
const today = rawRun(['today'], { cwd: PACKAGE_ROOT, env });
|
|
234
|
+
assert.equal(today.code, 3);
|
|
235
|
+
assert.match(today.stderr, /当前目录不是工作目录(这里是 work-rhythm 自己的仓库,不是工作目录)/);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('仓库保持通用:根目录出现工作目录才有的东西、个人配置,各报一条', (t) => {
|
|
239
|
+
const box = makeSandbox(t);
|
|
240
|
+
const repo = path.join(box.root, 'repo');
|
|
241
|
+
fs.cpSync(path.join(PACKAGE_ROOT, 'templates'), path.join(repo, 'templates'), { recursive: true });
|
|
242
|
+
const problems = () => {
|
|
243
|
+
const lines = [];
|
|
244
|
+
genericProblems({ root: repo, say: (l) => lines.push(l) });
|
|
245
|
+
return lines;
|
|
246
|
+
};
|
|
247
|
+
assert.deepEqual(problems(), []);
|
|
248
|
+
write(path.join(repo, '00-config', 'profile.yaml'), 'setup:\n status: done\n');
|
|
249
|
+
write(path.join(repo, '02-daily', '2026-01', '2026-01-01.md'), '# 2026-01-01\n');
|
|
250
|
+
write(path.join(repo, 'collectors', 'local.env'), 'A=1\n');
|
|
251
|
+
const found = problems();
|
|
252
|
+
assert.equal(found.length, 3);
|
|
253
|
+
assert.match(found.join('\n'), /仓库根目录里出现了 00-config:这个仓库只放 skill 和 CLI,不是工作目录/);
|
|
254
|
+
assert.match(found.join('\n'), /仓库根目录里出现了 02-daily/);
|
|
255
|
+
assert.match(found.join('\n'), /仓库里出现了个人配置 collectors\/local\.env/);
|
|
256
|
+
assert.ok(found.every((l) => !l.includes('templates/00-config')), 'templates/ 里的不算');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
test('模板:templates/ 下每份都在、profile 空白、源全关、记录没有行;坏了就报出来', (t) => {
|
|
260
|
+
const box = makeSandbox(t);
|
|
261
|
+
const pkg = path.join(box.root, 'pkg');
|
|
262
|
+
fs.cpSync(path.join(PACKAGE_ROOT, 'templates'), path.join(pkg, 'templates'), { recursive: true });
|
|
263
|
+
assert.deepEqual(templateProblems(pkg), []);
|
|
264
|
+
fs.rmSync(path.join(pkg, 'templates', 'README.md'));
|
|
265
|
+
write(path.join(pkg, 'templates', '00-config', 'sources.yaml'), read(path.join(pkg, 'templates', '00-config', 'sources.yaml')).replace('enabled: false', 'enabled: true'));
|
|
266
|
+
fs.appendFileSync(path.join(pkg, 'templates', '03-carryover', 'CARRYOVER.md'), '| 2026-01-01 | 旧 | 复盘 | P1 | 待开始 | 0 | |\n');
|
|
267
|
+
write(path.join(pkg, 'templates', '04-patterns', 'WORK_RHYTHM.md'), '# 我的规律\n\n数据范围:近 30 天\n');
|
|
268
|
+
const found = templateProblems(pkg);
|
|
269
|
+
assert.equal(found.length, 4);
|
|
270
|
+
assert.match(found.join('\n'), /templates\/README\.md 不存在/);
|
|
271
|
+
assert.match(found.join('\n'), /sources\.yaml 里有打开的源/);
|
|
272
|
+
assert.match(found.join('\n'), /CARRYOVER\.md 里带了记录/);
|
|
273
|
+
assert.match(found.join('\n'), /「数据范围」不是「尚未开始」/);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
test('check:用法不对时退出码为 2', (t) => {
|
|
277
|
+
const s = setup(t);
|
|
278
|
+
assert.equal(s.box.run(['check', '什么']).code, 2);
|
|
279
|
+
});
|