|
| 1 | +#!/usr/bin/env node |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const assert = require('assert') |
| 5 | +const fs = require('fs') |
| 6 | +const os = require('os') |
| 7 | +const path = require('path') |
| 8 | +const { spawnSync } = require('child_process') |
| 9 | + |
| 10 | +const ROOT = path.resolve(__dirname, '..') |
| 11 | +const SCRIPT = path.join(ROOT, 'scripts', 'validate-profile.js') |
| 12 | +const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')) |
| 13 | +const VERSION = pkg.version |
| 14 | +const PACKAGE_NAME = pkg.name |
| 15 | +const TEMP_ROOTS = [] |
| 16 | + |
| 17 | +function writeFile(root, relativePath, content) { |
| 18 | + const filePath = path.join(root, relativePath) |
| 19 | + fs.mkdirSync(path.dirname(filePath), { recursive: true }) |
| 20 | + fs.writeFileSync(filePath, content) |
| 21 | +} |
| 22 | + |
| 23 | +function createWorkspace(projectInfo) { |
| 24 | + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'devcodex-validate-profile-')) |
| 25 | + TEMP_ROOTS.push(root) |
| 26 | + |
| 27 | + writeFile(root, 'package.json', JSON.stringify({ name: PACKAGE_NAME }, null, 2)) |
| 28 | + writeFile(root, '.devcodex/profile/README.md', '# README\n') |
| 29 | + writeFile(root, '.devcodex/profile/02-架构约束.md', '# 02\n') |
| 30 | + writeFile(root, '.devcodex/profile/03-代码风格.md', '# 03\n') |
| 31 | + writeFile(root, '.devcodex/profile/config.json', JSON.stringify({ |
| 32 | + mode: 'dev', |
| 33 | + agent: 'claude-code', |
| 34 | + pluginVersion: VERSION |
| 35 | + }, null, 2)) |
| 36 | + writeFile(root, '.devcodex/profile/01-项目信息.md', projectInfo) |
| 37 | + |
| 38 | + return root |
| 39 | +} |
| 40 | + |
| 41 | +function runValidate(workspaceRoot) { |
| 42 | + return spawnSync(process.execPath, [SCRIPT], { |
| 43 | + cwd: workspaceRoot, |
| 44 | + encoding: 'utf8' |
| 45 | + }) |
| 46 | +} |
| 47 | + |
| 48 | +function legacyProjectInfo() { |
| 49 | + return [ |
| 50 | + '# 01 — 项目信息', |
| 51 | + '', |
| 52 | + '| 项目 | 值 |', |
| 53 | + '|------|----|', |
| 54 | + `| **当前版本** | ${VERSION} |`, |
| 55 | + `| **当前阶段** | ${VERSION} |`, |
| 56 | + '', |
| 57 | + '```', |
| 58 | + 'devcodex/skills/ → .github/skills/', |
| 59 | + 'devcodex/instructions/ → .github/instructions/', |
| 60 | + 'devcodex/prompts/ → .github/prompts/', |
| 61 | + 'devcodex/data/ → .github/data/', |
| 62 | + 'devcodex/instructions.md → .github/copilot-instructions.md', |
| 63 | + 'devcodex/RULES.md → .github/RULES.md', |
| 64 | + '```', |
| 65 | + '', |
| 66 | + '> 说明:`devcodex/agents/` 仍保留在源码仓中,但不再作为目标项目默认分发路径。', |
| 67 | + '', |
| 68 | + '## 授权层级', |
| 69 | + '', |
| 70 | + '| 层级 | 功能范围 |', |
| 71 | + '|------|---------|', |
| 72 | + '| **Free** | dev |', |
| 73 | + '| **Pro** | self-fix |', |
| 74 | + '' |
| 75 | + ].join('\n') |
| 76 | +} |
| 77 | + |
| 78 | +function currentProjectInfo() { |
| 79 | + return [ |
| 80 | + '# 01 — 项目信息', |
| 81 | + '', |
| 82 | + '| 项目 | 值 |', |
| 83 | + '|------|----|', |
| 84 | + `| **当前版本** | ${VERSION} |`, |
| 85 | + `| **当前阶段** | ${VERSION} |`, |
| 86 | + '| **需求总览** | `website/docs/versions/v1/<active-version>/requirements/index.md` — 当前活跃版本的 P0/P1/P2 分层总览 |', |
| 87 | + '', |
| 88 | + '```', |
| 89 | + 'devcodex/skills/ → .github/skills/', |
| 90 | + 'devcodex/instructions/ → .github/instructions/', |
| 91 | + 'devcodex/prompts/ → .github/prompts/', |
| 92 | + 'devcodex/data/ → .github/data/', |
| 93 | + 'devcodex/agents/ → .github/agents/(仅 Copilot 默认分发)', |
| 94 | + 'devcodex/instructions.md → .github/copilot-instructions.md(Copilot)', |
| 95 | + 'devcodex/RULES.md → .github/RULES.md', |
| 96 | + '```', |
| 97 | + '', |
| 98 | + '> 说明:`instructions.md` 是单源规范文件,安装时按平台 rename 到 `.github/copilot-instructions.md` 或 `CLAUDE.md`;`agents/` 当前仅在 Copilot 端默认分发,Claude Code 端仍通过 Skills 路由,不分发 agents。', |
| 99 | + '', |
| 100 | + '## 授权状态', |
| 101 | + '', |
| 102 | + '- 当前 `token-check` 仅为授权占位,不执行 tier 阻断。', |
| 103 | + '- 所有工作流和子类型当前全量开放。', |
| 104 | + '' |
| 105 | + ].join('\n') |
| 106 | +} |
| 107 | + |
| 108 | +function main() { |
| 109 | + try { |
| 110 | + const legacyRoot = createWorkspace(legacyProjectInfo()) |
| 111 | + const legacyResult = runValidate(legacyRoot) |
| 112 | + const legacyOutput = `${legacyResult.stdout}\n${legacyResult.stderr}` |
| 113 | + |
| 114 | + assert.strictEqual(legacyResult.status, 2, legacyOutput) |
| 115 | + assert.match(legacyOutput, /legacy agents distribution wording/) |
| 116 | + assert.match(legacyOutput, /legacy Free\/Pro authorization tiers/) |
| 117 | + assert.match(legacyOutput, /current formal requirement entry/) |
| 118 | + |
| 119 | + const currentRoot = createWorkspace(currentProjectInfo()) |
| 120 | + const currentResult = runValidate(currentRoot) |
| 121 | + const currentOutput = `${currentResult.stdout}\n${currentResult.stderr}` |
| 122 | + |
| 123 | + assert.strictEqual(currentResult.status, 0, currentOutput) |
| 124 | + console.log('\x1b[32m✓ validate-profile regression tests passed\x1b[0m') |
| 125 | + } finally { |
| 126 | + TEMP_ROOTS.forEach(root => fs.rmSync(root, { recursive: true, force: true })) |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +main() |
0 commit comments