diff --git a/examples/sop/check.mjs b/examples/sop/check.mjs new file mode 100644 index 0000000..6c5af52 --- /dev/null +++ b/examples/sop/check.mjs @@ -0,0 +1,32 @@ +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import YAML from 'yaml'; + +const here = (name) => new URL(name, import.meta.url); +const readYaml = async (name) => YAML.parse(await readFile(here(name), 'utf8')); + +const task = await readYaml('task-v1.yaml'); +const sop = await readYaml('development-1.0.0.yaml'); + +assert.equal(sop.sop, task.sop, 'SOP 版本应与任务稿一致'); + +const taskRef = `${task.task}@${task.version}`; +for (const [step, lane] of Object.entries(sop.lanes)) { + const handoff = await readYaml(lane.handoff); + assert.deepEqual(Object.keys(handoff).sort(), ['artifact', 'sop', 'step', 'task', 'template']); + assert.equal(handoff.sop, sop.sop); + assert.equal(handoff.template, 'development-result@1.0.0'); + assert.equal(handoff.task, taskRef); + assert.equal(handoff.step, step); + assert.equal(handoff.artifact, lane.artifact); +} + +const { subtotal } = await import(here('subtotal.mjs')); +const { fee } = await import(here('fee.mjs')); + +const { unit_cents, quantity, subtotal_cents, total_cents } = task.acceptance; +const computed = subtotal(unit_cents, quantity); +assert.equal(computed, subtotal_cents, 'subtotal 与任务稿不符'); +assert.equal(computed + fee(computed), total_cents, 'subtotal + fee 与任务稿总额不符'); + +console.log('check ok'); diff --git a/examples/sop/develop-a.yaml b/examples/sop/develop-a.yaml new file mode 100644 index 0000000..9711b2e --- /dev/null +++ b/examples/sop/develop-a.yaml @@ -0,0 +1,5 @@ +sop: development@1.0.0 +template: development-result@1.0.0 +task: AC-01@1 +step: develop-a +artifact: subtotal.mjs diff --git a/examples/sop/develop-b.yaml b/examples/sop/develop-b.yaml new file mode 100644 index 0000000..be3dc95 --- /dev/null +++ b/examples/sop/develop-b.yaml @@ -0,0 +1,5 @@ +sop: development@1.0.0 +template: development-result@1.0.0 +task: AC-01@1 +step: develop-b +artifact: fee.mjs diff --git a/examples/sop/development-1.0.0.yaml b/examples/sop/development-1.0.0.yaml new file mode 100644 index 0000000..c6bb8e0 --- /dev/null +++ b/examples/sop/development-1.0.0.yaml @@ -0,0 +1,19 @@ +sop: development@1.0.0 +lanes: + develop-a: + artifact: subtotal.mjs + handoff: develop-a.yaml + develop-b: + artifact: fee.mjs + handoff: develop-b.yaml +integrate: + check: node examples/sop/check.mjs + on_failure: 退回缺失或失败的一路 +review: + after: integrate + independent: true + on_failure: integrate +pull_request: + after: review + count: 1 + on_failure: review diff --git a/examples/sop/fee.mjs b/examples/sop/fee.mjs new file mode 100644 index 0000000..e13adfb --- /dev/null +++ b/examples/sop/fee.mjs @@ -0,0 +1,3 @@ +export function fee(subtotalCents) { + return Math.round(subtotalCents * 0.1); +} diff --git a/examples/sop/subtotal.mjs b/examples/sop/subtotal.mjs new file mode 100644 index 0000000..7f3129c --- /dev/null +++ b/examples/sop/subtotal.mjs @@ -0,0 +1,3 @@ +export function subtotal(unitCents, quantity) { + return unitCents * quantity; +} diff --git a/examples/sop/task-v1.yaml b/examples/sop/task-v1.yaml new file mode 100644 index 0000000..cfa671f --- /dev/null +++ b/examples/sop/task-v1.yaml @@ -0,0 +1,13 @@ +task: AC-01 +version: 1 +sop: development@1.0.0 +goal: Demonstrate delivery from an approved task draft through parallel development, testing, code review, and one pull request. +scope: examples/sop/ +acceptance: + unit_cents: 1200 + quantity: 2 + subtotal_cents: 2400 + total_cents: 2640 +checks: + - node examples/sop/check.mjs + - npm test