agentDocsLayout.test.mjs
5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
const resolveProjectPath = (relativePath) => path.join(projectRoot, relativePath);
test('Codex and Cursor share canonical agent instructions and skills', () => {
for (const relativePath of [
'AGENTS.md',
'.agents/skills/requirement-impact-analysis/SKILL.md',
'.agents/skills/requirement-impact-analysis/references/reference.md',
'.agents/skills/requirement-impact-analysis/references/reference-full.md',
'tabWorkOrder/pages/createOrder/AGENTS.md',
]) {
assert.ok(existsSync(resolveProjectPath(relativePath)), `${relativePath} must exist`);
}
for (const relativePath of ['.cursor/rules', '.cursor/skills']) {
assert.equal(existsSync(resolveProjectPath(relativePath)), false, `${relativePath} must be retired`);
}
});
test('canonical agent files expose required project and workflow contracts', () => {
const rootAgents = readFileSync(resolveProjectPath('AGENTS.md'), 'utf8');
assert.match(rootAgents, /# 项目 Agent 约定/);
assert.match(rootAgents, /## 迁移门禁/);
assert.match(rootAgents, /## 影响面检查/);
assert.match(rootAgents, /## 实现规范/);
assert.match(rootAgents, /## 测试与完成标准/);
const skill = readFileSync(
resolveProjectPath('.agents/skills/requirement-impact-analysis/SKILL.md'),
'utf8',
);
assert.match(skill, /^---\r?\nname: requirement-impact-analysis\r?\n/m);
assert.match(skill, /description: >-\r?\n\s+Use when/);
assert.match(skill, /做需求/);
assert.match(skill, /快改/);
assert.match(skill, /只分析/);
const createOrderAgents = readFileSync(
resolveProjectPath('tabWorkOrder/pages/createOrder/AGENTS.md'),
'utf8',
);
assert.match(createOrderAgents, /员工选择/);
assert.match(createOrderAgents, /礼券/);
assert.match(createOrderAgents, /orderCouponEffects\.js/);
});
test('durable documents use canonical tool-neutral locations', () => {
for (const relativePath of [
'docs/designs/2026-08-17-agent-and-docs-directory-governance-design.md',
'docs/plans/2026-08-17-agent-and-docs-directory-governance.md',
'docs/reports/2026-08-10-store-daily-report-final-fix.md',
'docs/reference/api/README.md',
'docs/reference/api/rop-swagger-2026-07-22.json',
'packageEquity/docs/SUBPACKAGE-ANALYSIS.md',
'tabWorkOrder/docs/createOrder.md',
]) {
assert.ok(existsSync(resolveProjectPath(relativePath)), `${relativePath} must exist`);
}
for (const relativePath of [
'docs/superpowers',
'docs/packageEquity',
'docs/tabWorkOrder',
]) {
assert.equal(existsSync(resolveProjectPath(relativePath)), false, `${relativePath} must be retired`);
}
});
test('retired tool directories are absent', () => {
for (const relativePath of ['.cursor', '.codex', '.idea', '.cloudbase', '.superpowers']) {
assert.equal(existsSync(resolveProjectPath(relativePath)), false, `${relativePath} must be absent`);
}
});
test('portable agent references resolve locally and avoid vendor-specific workflows', () => {
const referencePaths = [
'.agents/skills/requirement-impact-analysis/SKILL.md',
'.agents/skills/requirement-impact-analysis/references/reference.md',
'.agents/skills/requirement-impact-analysis/references/reference-full.md',
'tabIndex/docs/ROADMAP.md',
];
for (const relativePath of referencePaths) {
const absolutePath = resolveProjectPath(relativePath);
const markdown = readFileSync(absolutePath, 'utf8').replace(/```[\s\S]*?```/g, '');
for (const match of markdown.matchAll(/\[[^\]]*\]\(([^)]+)\)/g)) {
const target = match[1].split('#')[0].split('?')[0].trim();
if (!target || /^(?:https?:|mailto:|\/)/.test(target)) continue;
const resolvedTarget = path.resolve(path.dirname(absolutePath), decodeURIComponent(target));
assert.ok(existsSync(resolvedTarget), `${relativePath} has a broken link: ${match[1]}`);
}
}
const skillText = referencePaths
.slice(0, 3)
.map(relativePath => readFileSync(resolveProjectPath(relativePath), 'utf8'))
.join('\n');
assert.doesNotMatch(skillText, /\bCursor\b|CreatePlan|Agent \/ Plan \/ Ask|wechat-change-standards/);
});
test('store mock extraction requires an explicit transcript path', () => {
const emptyHome = mkdtempSync(path.join(tmpdir(), 'store-mock-transcript-'));
const env = { ...process.env };
delete env.STORE_MOCK_TRANSCRIPT;
env.USERPROFILE = emptyHome;
env.HOME = emptyHome;
let result;
try {
result = spawnSync(
process.execPath,
[resolveProjectPath('packageDynamicForm/scripts/extract-store-mock-jsonContent.cjs')],
{ cwd: projectRoot, env, encoding: 'utf8' },
);
} finally {
rmSync(emptyHome, { recursive: true, force: true });
}
assert.equal(result.status, 1);
assert.match(result.stderr, /STORE_MOCK_TRANSCRIPT is required/);
assert.doesNotMatch(result.stderr, /\.cursor[\\/]/);
});