docs(release): seal and deliver task agreement 1.25 with retained production state

This commit is contained in:
Agent Workbench Dev
2026-11-04 15:34:29 +08:00
parent 78976ac775
commit ddefe5f108
1444 changed files with 2161122 additions and 17 deletions
@@ -0,0 +1,3 @@
/dist/
.awb-*
node_modules/
@@ -0,0 +1,15 @@
# Delivery Report 工程验收样本
这是有意保留缺失功能的Node工程,用于验证“失败→跨文件修复→实际测试→审查→Git交付”。本目录是封存输入,不是已完成产品。
仅修改 `src/normalize.mjs`、`src/summary.mjs`、`src/render.mjs`、`src/cli.mjs`。测试、fixtures、构建脚本、package.json与本文保持原字节。没有第三方依赖。
1. normalizeTasks接受最多10000项的数组;每项必须是对象,id/title为非空字符串且trim,trim后的id唯一。
2. status严格限定todo/doing/done/blocked;minutes必须是0到1000000之间的安全整数,拒绝文本、NaN、负数或越界;返回独立的四字段记录,不改变输入对象。
3. summarize返回total、counts(四种状态都出现)、completedPercent(done/total四舍五入到整数,空数组为0)、remainingMinutes(所有非done记录分钟数之和)。空数组计数全部为0。
4. renderText精确输出三行:`交付进度:D/T(P%)`、`待办 A · 进行中 B · 已完成 D · 阻塞 C`、`剩余预计:M 分钟`,保持中文可读。
5. CLI用法 `node src/cli.mjs <JSON文件> [--json]`。默认输出上述三行加尾换行,--json输出同一个summary的可解析JSON加换行。
6. 参数缺失、未知选项、无效JSON、无效数据或文件读取失败均以退出码2和stderr中文前缀“输入错误:”报告;stdout为空。成功退出0。
7. build核对四模块语法并复制到dist。`node dist/cli.mjs fixtures/tasks.json --json`与源码入口结果一致。
先运行npm test保存真实失败,再修改四个模块;应用提案后重跑npm test与npm run build。验收器另核对保护文件hash、源文件diff和构建入口,不把修改测试或只输出“成功”当交付。
@@ -0,0 +1,6 @@
[
{ "id": " docs ", "title": " 编写交付文档 ", "status": "done", "minutes": 30 },
{ "id": "api", "title": "接口回归", "status": "doing", "minutes": 40 },
{ "id": "release", "title": "准备发行包", "status": "blocked", "minutes": 10 },
{ "id": "review", "title": "代码审查", "status": "done", "minutes": 20 }
]
@@ -0,0 +1,7 @@
{
"name": "delivery-report-lab",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": { "test": "node --test test/*.test.mjs", "build": "node scripts/build.mjs" }
}
@@ -0,0 +1,11 @@
import fs from 'node:fs';
import { spawnSync } from 'node:child_process';
const modules = ['normalize.mjs', 'summary.mjs', 'render.mjs', 'cli.mjs'];
for (const name of modules) {
const check = spawnSync(process.execPath, ['--check', 'src/' + name], { encoding: 'utf8', windowsHide: true });
if (check.status !== 0) { process.stderr.write(check.stderr); process.exit(1); }
}
fs.mkdirSync('dist', { recursive: true });
for (const name of modules) fs.copyFileSync('src/' + name, 'dist/' + name);
fs.writeFileSync('dist/package.json', '{"type":"module"}\n');
console.log('四个模块语法检查及可运行构建完成。');
@@ -0,0 +1,8 @@
import fs from 'node:fs';
import { normalizeTasks } from './normalize.mjs';
import { summarize } from './summary.mjs';
import { renderText } from './render.mjs';
try {
const tasks = normalizeTasks(JSON.parse(fs.readFileSync(process.argv[2], 'utf8')));
console.log(renderText(summarize(tasks)));
} catch (error) { console.error(error.message); }
@@ -0,0 +1,4 @@
export function normalizeTasks(input) {
if (!Array.isArray(input)) throw new TypeError('tasks must be an array');
return input;
}
@@ -0,0 +1,3 @@
export function renderText(summary) {
return `Done: ${summary.counts.done}/${summary.total}`;
}
@@ -0,0 +1,5 @@
export function summarize(tasks) {
const done = tasks.filter(task => task.status === 'done').length;
return { total: tasks.length, counts: { done }, completedPercent: tasks.length ? 100 : 0,
remainingMinutes: tasks.reduce((sum, task) => sum + task.minutes, 0) };
}
@@ -0,0 +1,26 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import { spawnSync } from 'node:child_process';
import { normalizeTasks } from '../src/normalize.mjs';
import { summarize } from '../src/summary.mjs';
import { renderText } from '../src/render.mjs';
const input = () => JSON.parse(fs.readFileSync('fixtures/tasks.json', 'utf8'));
const record = overrides => ({ id: 'one', title: '任务', status: 'todo', minutes: 5, ...overrides });
const expected = { total: 4, counts: { todo: 0, doing: 1, done: 2, blocked: 1 }, completedPercent: 50, remainingMinutes: 50 };
const invoke = (...args) => spawnSync(process.execPath, ['src/cli.mjs', ...args], { encoding: 'utf8', windowsHide: true });
test('normalize trims identifiers and titles into independent records', () => { const original = input(), before = structuredClone(original), result = normalizeTasks(original); assert.equal(result[0].id, 'docs'); assert.equal(result[0].title, '编写交付文档'); assert.notEqual(result, original); assert.notEqual(result[1], original[1]); assert.deepEqual(original, before); });
test('normalize rejects blank and duplicate normalized identifiers', () => { assert.throws(() => normalizeTasks([record({ id: ' ' })])); assert.throws(() => normalizeTasks([record({ title: ' ' })])); assert.throws(() => normalizeTasks([record(), record({ id: ' one ' })])); });
test('normalize validates record shape and bounded collection size', () => { assert.throws(() => normalizeTasks({})); assert.throws(() => normalizeTasks([null])); assert.throws(() => normalizeTasks(Array.from({ length: 10001 }, (_, i) => record({ id: String(i) })))); });
test('normalize supports all four states and rejects unknown states', () => { for (const status of ['todo', 'doing', 'done', 'blocked']) assert.equal(normalizeTasks([record({ status })])[0].status, status); assert.throws(() => normalizeTasks([record({ status: 'completed' })])); });
test('normalize rejects noninteger and out-of-range estimates', () => { for (const minutes of ['5', null, -1, 0.5, NaN, Infinity, 1000001]) assert.throws(() => normalizeTasks([record({ minutes })])); assert.equal(normalizeTasks([record({ minutes: 0 })])[0].minutes, 0); assert.equal(normalizeTasks([record({ minutes: 1000000 })])[0].minutes, 1000000); });
test('normalize emits only the declared four-field contract', () => assert.deepEqual(normalizeTasks([record({ unrelated: true })])[0], record()));
test('summary reports complete state counts and excludes completed work from remaining time', () => assert.deepEqual(summarize(normalizeTasks(input())), expected));
test('summary rounds progress instead of truncating percentages', () => assert.equal(summarize([record({ status: 'done' }), record({ id: 'two', status: 'done' }), record({ id: 'three' })]).completedPercent, 67));
test('summary handles an empty plan with every state present', () => assert.deepEqual(summarize([]), { total: 0, counts: { todo: 0, doing: 0, done: 0, blocked: 0 }, completedPercent: 0, remainingMinutes: 0 }));
test('text rendering keeps the required three readable Chinese lines', () => assert.equal(renderText(expected), '交付进度:2/4(50%)\n待办 0 · 进行中 1 · 已完成 2 · 阻塞 1\n剩余预计:50 分钟'));
test('CLI JSON output matches the summary contract and has a trailing newline', () => { const result = invoke('fixtures/tasks.json', '--json'); assert.equal(result.status, 0); assert.equal(result.stderr, ''); assert.deepEqual(JSON.parse(result.stdout), expected); assert.ok(result.stdout.endsWith('\n')); });
test('CLI text output is readable and matches the shared rendering', () => { const result = invoke('fixtures/tasks.json'); assert.equal(result.status, 0); assert.equal(result.stdout, renderText(expected) + '\n'); assert.equal(result.stderr, ''); });
test('CLI missing arguments and unknown options return exit 2 without output', () => { for (const args of [[], ['fixtures/tasks.json', '--unknown'], ['fixtures/tasks.json', '--json', '--json']]) { const result = invoke(...args); assert.equal(result.status, 2); assert.equal(result.stdout, ''); assert.match(result.stderr, /^输入错误:/); } });
test('CLI invalid JSON and missing files preserve the failure exit code', () => { for (const file of ['fixtures/invalid.json', 'fixtures/not-found.json']) { const result = invoke(file); assert.equal(result.status, 2); assert.equal(result.stdout, ''); assert.match(result.stderr, /^输入错误:/); } });