Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/sop/check.mjs
Original file line number Diff line number Diff line change
@@ -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');
5 changes: 5 additions & 0 deletions examples/sop/develop-a.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions examples/sop/develop-b.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions examples/sop/development-1.0.0.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions examples/sop/fee.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function fee(subtotalCents) {
return Math.round(subtotalCents * 0.1);
}
3 changes: 3 additions & 0 deletions examples/sop/subtotal.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function subtotal(unitCents, quantity) {
return unitCents * quantity;
}
13 changes: 13 additions & 0 deletions examples/sop/task-v1.yaml
Original file line number Diff line number Diff line change
@@ -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