From c747a271b6f8f82fa69fd42ff6d43360deeed41c Mon Sep 17 00:00:00 2001 From: mgillr <36207807+mgillr@users.noreply.github.com> Date: Tue, 27 Oct 2026 07:10:50 +0000 Subject: [PATCH] contract decompose: scope file to an unsigned proposal for merge I want one way to turn scoped work into contract tasks, the same in every repository. `proofline contract decompose --out ` reads a proofline-scope/1 file (an id prefix, tasks with title, acceptance checks, requirement ids, dependencies and an owner placeholder, plus shared defaults and criteria put before or after each task's own) and writes an unsigned proposal that `contract merge` accepts. - Byte-stable output: fixed key order, criterion ids -AC01..., two-space JSON and a final newline; the command prints the sha256. - Refuses a duplicate id (in the scope or in an --against contract), an unknown dependency, a cycle and a task `contract validate` would refuse; nothing is written then. --lint-warn reports the validate findings as warnings for contracts that already carry tasks of that shape. - Never writes proofline.json or a .sig. --check exits 1 when the committed proposal is not the output of its scope file, for CI. docs/DECOMPOSITION.md is the process: scope file, decompose, validate and coverage, proposal PR that leaves proofline.json alone, the owner's go, fold with `contract merge`, sign, verify-sig, with a CI job. Tests cover the golden file, duplicate refusal, the merge round-trip with validate and coverage, and the refusal to write a contract or signature, on a toy fixture. Signed-off-by: mgillr <36207807+mgillr@users.noreply.github.com> --- CHANGELOG.md | 6 + README.md | 1 + bin/proofline.mjs | 22 +- docs/00-index.md | 1 + docs/DECOMPOSITION.md | 184 ++++++++++++++ fixtures/decompose/REQUIREMENTS.md | 6 + .../decompose/example-project.proposal.json | 187 ++++++++++++++ fixtures/decompose/example-project.scope.json | 63 +++++ src/decompose.mjs | 235 ++++++++++++++++++ test/cli_unknown_flags.test.mjs | 1 + test/contract_decompose.test.mjs | 136 ++++++++++ 11 files changed, 841 insertions(+), 1 deletion(-) create mode 100644 docs/DECOMPOSITION.md create mode 100644 fixtures/decompose/REQUIREMENTS.md create mode 100644 fixtures/decompose/example-project.proposal.json create mode 100644 fixtures/decompose/example-project.scope.json create mode 100644 src/decompose.mjs create mode 100644 test/contract_decompose.test.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index b86e7cd..5bcb42f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable project changes are recorded here. Dates use ISO 8601 (`YYYY-MM-DD`). +## Unreleased + +### Added + +- `proofline contract decompose [--out ] [--against a.json,b.json] [--check] [--lint-warn]` turns a scope file (`proofline-scope/1`: an id prefix, tasks with title, acceptance checks, requirement ids, dependencies and an owner placeholder, plus shared defaults and criteria put before or after each task's own) into an unsigned proposal that `contract merge` accepts. The output is byte-stable: fixed key order, criterion ids `-AC01...`, two-space JSON and a final newline, and the command prints its sha256. A duplicate id (in the scope or in an `--against` contract), an unknown dependency, a cycle and a task `contract validate` would refuse are refused and nothing is written. It never writes `proofline.json` or a `.sig`. `--check` exits 1 when the `--out` file differs from what the scope gives. `docs/DECOMPOSITION.md` describes the process from scope file to proposal PR, fold with `merge`, `sign` and `verify-sig`, with a CI job. The toy fixture is `fixtures/decompose/`. + ## 0.2.0-next.2 (2026-10-21) ### Added diff --git a/README.md b/README.md index a4a5d2b..357b8fa 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,7 @@ Two or more builders can share one contract. A task may carry an `owner`, and `d `proofline contract merge [--owners a=b,c=d]` appends the fragment's tasks and any owner rule that is not already there. A duplicate id is refused and the file is left untouched. Existing tasks and the bytes around them stay. The command prints the sha256 of the result. `proofline contract coverage [--contracts a.json,b.json]` reads ids from lines of the form `- ID: text` and prints one line per id with the tasks that name it, or `MISSING`. A task that names an id the file does not list is `unknown`. The exit code is 1 when any id is missing or unknown. +`proofline contract decompose --out docs/proposals/.json [--against proofline.json] [--check]` turns a scope file (an id prefix and tasks with their title, acceptance checks, requirement ids, dependencies and an owner placeholder) into an unsigned proposal that `contract merge` accepts. The same scope always gives the same bytes. It refuses a duplicate id, an unknown dependency and a task `contract validate` would refuse, and it never writes `proofline.json` or a `.sig`. `--check` exits 1 when the committed proposal is not the output of its scope. [docs/DECOMPOSITION.md](docs/DECOMPOSITION.md) is the whole process, from scope file to signed contract, with a CI job. ### Git hooks diff --git a/bin/proofline.mjs b/bin/proofline.mjs index 483b62e..59e953c 100755 --- a/bin/proofline.mjs +++ b/bin/proofline.mjs @@ -9,10 +9,11 @@ import { buildReceipt } from '../src/receipt.mjs'; import { connectClaudeCode, hookStop } from '../src/hook-stop.mjs'; import * as G from '../src/guided.mjs'; import * as S from '../src/signature.mjs'; +import * as D from '../src/decompose.mjs'; const argv = process.argv.slice(2); const flags = {}; const pos = []; -const SWITCHES = ['fresh']; // never take a value: `verify --fresh T` keeps T as the task +const SWITCHES = ['fresh', 'check', 'lint-warn']; // never take a value: `verify --fresh T` keeps T as the task for (let i = 0; i < argv.length; i++) { const a = argv[i]; if (a.startsWith('--')) { const [k, v] = a.slice(2).split('='); if (v !== undefined) flags[k] = v; else if (!SWITCHES.includes(k) && argv[i + 1] && !argv[i + 1].startsWith('--')) flags[k] = argv[++i]; else flags[k] = true; } @@ -57,6 +58,9 @@ const HELP = `proofline: independent V&V and delivery controller append tasks and new owner rules; prints the sha256 contract coverage [--contracts a.json,b.json] one line per requirement id, or MISSING + contract decompose [--out proposal.json] [--against a.json,b.json] [--check] [--lint-warn] + scope file to an unsigned proposal for merge; never writes + proofline.json or a .sig; --check exits 1 when --out differs contract validate | show validate also warns when a grep already matches on the base revision next [--owner ] [--base ] the single next task with its full brief (marks it active); --owner limits the lane; --base re-pins the base @@ -90,6 +94,7 @@ const ACCEPTED_FLAGS = { 'contract create': ['from', 'id', 'title', 'phase', 'owner', 'description', 'depends', 'scope'], 'contract merge': ['owners'], 'contract coverage': ['contracts'], + 'contract decompose': ['out', 'against', 'check', 'lint-warn'], 'contract scaffold': ['title', 'scope', 'kind', 'id'], 'contract approve': [], 'contract sign': [], @@ -174,6 +179,21 @@ try { const out = P.C.coverageReport(root, path.resolve(root, req), { contracts: contracts.map((f) => path.resolve(root, f)) }); print(out, out.lines.join('\n')); process.exitCode = out.ok ? 0 : 1; + } else if (sub === 'decompose') { + const scope = pos[2]; + if (!scope) throw new Error('contract decompose needs a scope file'); + if (flags.out === true) throw new Error('--out needs a file'); + if (flags.against === true) throw new Error('--against needs a contract file'); + const against = flags.against ? String(flags.against).split(',').map((s) => s.trim()).filter(Boolean).map((f) => path.resolve(root, f)) : []; + const out = flags.out ? path.resolve(root, String(flags.out)) : undefined; + const r = D.decomposeFile(root, path.resolve(root, scope), { out, against, check: flags.check === true, lint: flags['lint-warn'] === true ? 'warn' : 'error' }); + for (const w of r.warnings) console.error(`warning: ${w}`); + const summary = { sha256: r.sha256, tasks: r.ids, out: out ? path.relative(root, out) : null, same: r.same }; + if (flags.check === true) { + if (r.same) print(summary, `${r.sha256}\n${summary.out} is current`); + else { print(summary, `${summary.out} differs from the scope; regenerate it with: proofline contract decompose ${scope} --out ${summary.out}${flags.against ? ` --against ${flags.against}` : ''}`); process.exitCode = 1; } + } else if (!out) { if (json) print({ ...summary, proposal: r.proposal }); else process.stdout.write(r.bytes); } + else print(summary, `${r.sha256}\nwrote ${summary.out}: ${r.ids.join(', ')}`); } else if (sub === 'scaffold') { if (typeof flags.title !== 'string') throw new Error('scaffold needs --title'); if (typeof flags.scope !== 'string') throw new Error('scaffold needs --scope'); diff --git a/docs/00-index.md b/docs/00-index.md index 1a3cd49..bb0fd37 100644 --- a/docs/00-index.md +++ b/docs/00-index.md @@ -21,6 +21,7 @@ This is the source of truth for the Proofline design. Requirements are normative - [12 — Roadmap](12-roadmap.md) - [13 — Interdependencies](13-interdependencies.md) - [14 — Metrics and evaluation](14-metrics.md) +- [Decomposition: from a scope file to a signed contract](DECOMPOSITION.md) ## Decisions and examples diff --git a/docs/DECOMPOSITION.md b/docs/DECOMPOSITION.md new file mode 100644 index 0000000..5f90bef --- /dev/null +++ b/docs/DECOMPOSITION.md @@ -0,0 +1,184 @@ +# Decomposition: from a scope file to a signed contract + +This is the one process for turning a piece of scoped work into Proofline tasks. It is the same for every project. Builders write and decompose scope files. The contract owner (or whoever holds the owner key) folds and signs. Nobody edits `proofline.json` by hand. + +```text +scope file ──decompose──▶ proposal JSON ──validate + coverage──▶ proposal PR (proofline.json untouched) + ▲ │ + └──────────── amend the scope file, never the proposal ◀─── review ───┤ + ▼ owner's go + verify-sig ◀── contract sign ◀── contract merge (the fold), on a sign branch +``` + +## 1. Write a scope file + +A scope file is JSON (the CLI has no runtime dependencies, so there is no YAML parser). It lives in the repository next to the contract it feeds, for example `docs/scopes/.scope.json`, and it is the source of truth for those tasks: to change a task, change the scope file and decompose again. + +```json +{ + "schema": "proofline-scope/1", + "prefix": "EX", + "pad": 2, + "proposal": { "about": "What this batch of work is", "proposed_by": "OWNER" }, + "owner_rules": ["Each task closes only on the evidence its criteria name."], + "defaults": { "phase": "implement", "owner": "OWNER", "scope": ["src/**", "test/**"] }, + "prepend": { "stop_rules": ["If a criterion cannot pass, STOP and report what blocks it."] }, + "append": { "requirements": ["REQ-QUALITY"], "criteria": ["scope", "pushed"] }, + "external": [], + "tasks": [ + { + "n": 1, + "title": "Greeting function", + "requirements": ["REQ-GREET"], + "description": "greet(name) returns a greeting.", + "acceptance": [ + { "statement": "The new test fails on the base and passes now", + "verifier": { "type": "test_red_green", "test_file": "test/greet.test.mjs", "cmd": "node --test {test}" } }, + { "statement": "suite green", "cmd": "npm test", "timeout_s": 120 } + ] + }, + { "n": 2, "title": "Command-line entry point", "depends_on": [1], "acceptance": [ "..." ] } + ] +} +``` + +A complete toy example is `fixtures/decompose/example-project.scope.json`, with its output in `fixtures/decompose/example-project.proposal.json`. + +| Key | Meaning | +| --- | --- | +| `schema` | Always `proofline-scope/1`. | +| `prefix`, `pad` | A task with `n` gets the id `-` (pad defaults to 2: `EX-01`). A task may give `id` instead; ids match `[A-Za-z][A-Za-z0-9-]*`. | +| `proposal` | Header fields copied into the proposal as they are (`about`, `proposed_by`, `target`, anything else). `schema`, `status`, `owner_rules` and `tasks` are written by decompose and may not be set here. | +| `owner_rules` | Rules `contract merge` adds to the contract when they are not already there. | +| `defaults` | `phase` (default `implement`), `owner`, `scope`, `stop_rules`, and `fields`: used when a task does not set them. | +| `prepend`, `append` | Lists put before or after every task's own `requirements`, `scope`, `criteria` (acceptance) and `stop_rules`. A task opts out with `"inherit": false`, or keeps only some with `"inherit": ["stop_rules"]`. | +| `external` | Ids of tasks that already exist elsewhere and may be named in `depends_on`. `--against ` does the same from a file. | +| `tasks[]` | `id` or `n`, `title`, `phase`, `owner`, `depends_on` (ids, or numbers that take the prefix), `requirements`, `description` (a string, or a list of strings joined with a space), `scope` (a list of path patterns, or `{ "allow": [...] }` with any other keys kept), `acceptance`, `stop_rules`, `fields` (extra task keys kept as they are, such as an estimate), `inherit`. | + +An acceptance item is one of: + +- `"scope"` or `"pushed"`: the standard scope and pushed criteria, with the same statements `contract scaffold` uses. +- `{ "statement": "...", "cmd": "...", "expect_exit": 0, "timeout_s": 120 }`: a command criterion. +- `{ "statement": "...", "verifier": { "type": "...", ... } }`: any verifier Proofline knows (`command`, `test_red_green`, `test_exists`, `metric`, `grep`, `wiring`, `scope`, `docs`, `pushed`, `file_exists`). + +Each criterion gets the id `-AC01`, `-AC02`, ... in order (prepended items first, appended items last), unless it gives its own `id`. `mandatory` defaults to true. Any other key on an item is kept. In every string, `{task}` becomes the task id, so a shared criterion in `append` can name the task it lands in. `{test}` and every other placeholder are left alone. + +A task with no stop rules gets the default stop rules `contract scaffold` uses. + +## 2. Decompose + +```sh +proofline contract decompose docs/scopes/.scope.json --out docs/proposals/.json --against proofline.json +``` + +- The output is an unsigned proposal: `{ "schema": "proofline/1", "status": "proposed", , "owner_rules": [...], "tasks": [...] }`. Task keys come in a fixed order (`id`, `title`, `phase`, `owner`, `depends_on`, `requirements`, `description`, the extra fields, `scope`, `criteria`, `stop_rules`), with two-space indentation and a final newline. The same scope always gives the same bytes, however the scope file is formatted. The command prints the sha256 of those bytes and the task ids. Without `--out` it prints the proposal. +- It refuses, and writes nothing, when an id appears twice in the scope or already exists in an `--against` contract, a dependency is not in the scope, `--against` or `external`, the tasks form a cycle, or a task would fail `contract validate` (no scope criterion, no stop rules, a criterion path outside the task scope, an expanding `sh -c`). `--lint-warn` turns the `contract validate` findings into warnings, for a contract that already carries tasks of that shape; a structural error is still a refusal. +- It never writes `proofline.json`, any file named `proofline.json`, or a `.sig` file. Reading `--against` is read-only. +- `--check` compares the generated bytes with the `--out` file and exits 1 when they differ, without writing. CI uses it to prove every committed proposal is the output of its committed scope file. + +## 3. Validate and check coverage + +```sh +proofline contract decompose docs/scopes/.scope.json --out docs/proposals/.json --against proofline.json --check +proofline contract coverage REQUIREMENTS.md --contracts proofline.json,docs/proposals/.json +``` + +Coverage reads requirement ids from lines of the form `- ID: text` and prints, per id, the tasks that name it or `MISSING`. Fix gaps in the scope file and decompose again. + +## 4. Open the proposal PR + +Commit the scope file and the proposal in one PR titled `Propose (unsigned)`. The PR adds or changes only the scope file and `docs/proposals/.json`. It never touches `proofline.json` or `proofline.json.sig`; a proposal folded into an unsigned contract leaves main unsigned, and the gate refuses every task until the owner signs again. + +Review comments are answered by editing the scope file and decomposing again, never by editing the proposal JSON. + +## 5. Owner's go, then fold + +After the owner approves the proposal, the fold happens on a separate branch, in one place, with one tool: + +```sh +git switch -c sign/ +proofline contract merge docs/proposals/.json --owners OWNER= +proofline contract validate +``` + +`merge` appends the tasks and any new owner rules, keeps every existing byte of `proofline.json`, refuses a duplicate id and leaves the file untouched when it does, and prints the sha256 of the result. `--owners` maps the placeholder owner in the scope to a real name. Fold several proposals by running `merge` once per proposal, in the order they were approved. Do not fold with a script, an editor or a re-serialiser: every other way of folding produces different bytes for the same tasks, and the review diff stops being readable. + +## 6. Sign and verify + +```sh +proofline contract sign +proofline contract verify-sig +``` + +Commit `proofline.json` and `proofline.json.sig` together, with the sha256 `merge` printed in the commit message, and open the sign PR. Where Proofline's git hooks are installed, that commit also needs the owner's approval marker for the new `proofline.json` bytes (README, Git hooks). Only the owner key signs. Once `guard/owner.pub` is pinned, `next`, `verify`, `gate` and the hooks refuse a contract whose signature is missing or does not match. + +## Amending a task that is already in the contract + +`decompose` and `merge` only add tasks. A proposal header may describe changes to existing tasks (any extra header key is carried as it is), but `merge` does not apply them, and a fold that runs `merge` alone leaves them out. A change to an existing task is a contract change: + +1. On the sign branch, after the merges, edit the named fields of `proofline.json` exactly as the proposal states them, and nothing else. +2. `proofline contract propose` writes the diff against HEAD to `.proofline/proposals/.diff` and prints the hash. Put that diff in the sign PR, so the owner reviews exactly those bytes. +3. `validate`, `sign` and `verify-sig` as above. The sign PR description lists every change it applied, so a reviewer can tick each one off against the proposal. + +## Roles + +| Who | Does | Never | +| --- | --- | --- | +| Builder (any agent or person) | writes or amends a scope file, runs `decompose`, `--check`, `coverage`, opens the proposal PR | edits `proofline.json` or a `.sig`, folds, signs | +| Reviewer | reviews the scope file and the proposal diff, asks for changes in the scope file | approves its own proposal | +| Owner | gives the go on a proposal | | +| Signer (holds the owner key) | runs `merge` on a sign branch, then `validate`, `sign`, `verify-sig`, and opens the sign PR | folds any other way, changes task content while folding | + +## CI + +This job checks, on every PR, that each committed proposal is the current output of its scope file and that each contract validates and carries a valid owner signature. Adjust the paths to the repository layout; the example keeps scope files in `docs/scopes/` and proposals in `docs/proposals/`. + +```yaml +name: contracts +on: + pull_request: + push: + branches: [main] +permissions: + contents: read +jobs: + contracts: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: actions/setup-node@v4 + with: + node-version: 22 + - run: npm install --global @optitransfer/proofline + - name: Every proposal is the output of its scope file + run: | + set -e + for s in docs/scopes/*.scope.json; do + [ -e "$s" ] || continue + n=$(basename "$s" .scope.json) + proofline contract decompose "$s" --out "docs/proposals/$n.json" --check + done + - name: The contract validates + run: proofline contract validate + - name: The contract carries the owner signature + run: proofline contract verify-sig + - name: Requirements are covered + if: hashFiles('REQUIREMENTS.md') != '' + run: proofline contract coverage REQUIREMENTS.md +``` + +A proposal that depends on tasks already in the contract needs `--against proofline.json` in the check step, or the ids in the scope's `external` list. For a repository with several contracts in subdirectories, run validate and verify-sig once per contract. Both read `proofline.json` (and verify-sig also `proofline.json.sig` and `guard/owner.pub`) under `--root `. When the contracts share one pinned key at the repository root, give each check a directory that holds those three files: + +```sh +set -e +for c in docs/contracts/*/proofline.json; do + d=$(dirname "$c"); t=$(mktemp -d) + mkdir -p "$t/guard" + cp "$c" "$c.sig" "$t/" && cp guard/owner.pub "$t/guard/" + echo "== $d" + proofline contract validate --root "$t" + proofline contract verify-sig --root "$t" +done +``` diff --git a/fixtures/decompose/REQUIREMENTS.md b/fixtures/decompose/REQUIREMENTS.md new file mode 100644 index 0000000..458514d --- /dev/null +++ b/fixtures/decompose/REQUIREMENTS.md @@ -0,0 +1,6 @@ +# example-project requirements + +- REQ-GREET: a greeting for a name +- REQ-CLI: a command-line entry point +- REQ-DOCS: usage is documented +- REQ-QUALITY: every change is tested and in scope diff --git a/fixtures/decompose/example-project.proposal.json b/fixtures/decompose/example-project.proposal.json new file mode 100644 index 0000000..63d9ab2 --- /dev/null +++ b/fixtures/decompose/example-project.proposal.json @@ -0,0 +1,187 @@ +{ + "schema": "proofline/1", + "status": "proposed", + "about": "Toy decomposition of example-project: a greeting library with a CLI and its docs.", + "proposed_by": "OWNER", + "target": "proofline.json tasks[]", + "owner_rules": [ + "Each task closes only on the evidence its criteria name." + ], + "tasks": [ + { + "id": "EX-01", + "title": "Greeting function", + "phase": "implement", + "owner": "OWNER", + "depends_on": [], + "requirements": [ + "REQ-GREET", + "REQ-QUALITY" + ], + "description": "greet(name) returns a greeting. An empty name is refused.", + "estimate_days": 1, + "scope": { + "allow": [ + "src/**", + "test/**" + ] + }, + "criteria": [ + { + "id": "EX-01-AC01", + "mandatory": true, + "statement": "The new test fails on the base and passes now", + "verifier": { + "type": "test_red_green", + "test_file": "test/greet.test.mjs", + "cmd": "node --test {test}" + } + }, + { + "id": "EX-01-AC02", + "mandatory": true, + "statement": "suite green", + "verifier": { + "type": "command", + "cmd": "npm test", + "expect_exit": 0, + "timeout_s": 120 + } + }, + { + "id": "EX-01-AC03", + "mandatory": true, + "statement": "Changes stay in scope", + "verifier": { + "type": "scope" + } + }, + { + "id": "EX-01-AC04", + "mandatory": true, + "statement": "Committed and pushed to main", + "verifier": { + "type": "pushed" + } + } + ], + "stop_rules": [ + "If a criterion cannot pass, STOP and report what blocks it, what was tried and what is needed." + ] + }, + { + "id": "EX-02", + "title": "Command-line entry point", + "phase": "implement", + "owner": "OWNER", + "depends_on": [ + "EX-01" + ], + "requirements": [ + "REQ-CLI", + "REQ-QUALITY" + ], + "description": "A bin script prints greet(argv[2]).", + "estimate_days": 2, + "scope": { + "allow": [ + "bin/**", + "test/**" + ] + }, + "criteria": [ + { + "id": "EX-02-AC01", + "mandatory": true, + "statement": "The CLI is wired to greet", + "verifier": { + "type": "wiring", + "entry": "bin/greet.mjs", + "symbol": "greet" + } + }, + { + "id": "EX-02-AC02", + "mandatory": true, + "statement": "suite green", + "verifier": { + "type": "command", + "cmd": "npm test" + } + }, + { + "id": "EX-02-AC03", + "mandatory": true, + "statement": "Changes stay in scope", + "verifier": { + "type": "scope" + } + }, + { + "id": "EX-02-AC04", + "mandatory": true, + "statement": "Committed and pushed to main", + "verifier": { + "type": "pushed" + } + } + ], + "stop_rules": [ + "If a criterion cannot pass, STOP and report what blocks it, what was tried and what is needed." + ] + }, + { + "id": "EX-DOCS", + "title": "Usage documented", + "phase": "verify", + "owner": "OWNER", + "depends_on": [ + "EX-02" + ], + "requirements": [ + "REQ-DOCS", + "REQ-QUALITY" + ], + "description": "", + "estimate_days": 1, + "scope": { + "allow": [ + "README.md" + ] + }, + "criteria": [ + { + "id": "EX-DOCS-USAGE", + "mandatory": true, + "statement": "README names the command", + "verifier": { + "type": "grep", + "file": "README.md", + "pattern": "greet ", + "must": "present" + } + }, + { + "id": "EX-DOCS-AC02", + "mandatory": true, + "statement": "Changes stay in scope", + "verifier": { + "type": "scope" + } + }, + { + "id": "EX-DOCS-AC03", + "mandatory": true, + "statement": "Committed and pushed to main", + "verifier": { + "type": "pushed" + } + } + ], + "stop_rules": [ + "If a criterion cannot pass, STOP and report what blocks it, what was tried and what is needed.", + "Docs describe what the code does today, nothing planned." + ] + } + ] +} diff --git a/fixtures/decompose/example-project.scope.json b/fixtures/decompose/example-project.scope.json new file mode 100644 index 0000000..f02aa9e --- /dev/null +++ b/fixtures/decompose/example-project.scope.json @@ -0,0 +1,63 @@ +{ + "schema": "proofline-scope/1", + "prefix": "EX", + "pad": 2, + "proposal": { + "about": "Toy decomposition of example-project: a greeting library with a CLI and its docs.", + "proposed_by": "OWNER", + "target": "proofline.json tasks[]" + }, + "owner_rules": [ + "Each task closes only on the evidence its criteria name." + ], + "defaults": { + "phase": "implement", + "owner": "OWNER", + "scope": ["src/**", "test/**"], + "fields": { "estimate_days": 1 } + }, + "prepend": { + "stop_rules": ["If a criterion cannot pass, STOP and report what blocks it, what was tried and what is needed."] + }, + "append": { + "requirements": ["REQ-QUALITY"], + "criteria": ["scope", "pushed"] + }, + "tasks": [ + { + "n": 1, + "title": "Greeting function", + "requirements": ["REQ-GREET"], + "description": ["greet(name) returns a greeting.", "An empty name is refused."], + "acceptance": [ + { "statement": "The new test fails on the base and passes now", "verifier": { "type": "test_red_green", "test_file": "test/greet.test.mjs", "cmd": "node --test {test}" } }, + { "statement": "suite green", "cmd": "npm test", "expect_exit": 0, "timeout_s": 120 } + ] + }, + { + "n": 2, + "title": "Command-line entry point", + "depends_on": [1], + "requirements": ["REQ-CLI"], + "description": "A bin script prints greet(argv[2]).", + "scope": ["bin/**", "test/**"], + "acceptance": [ + { "statement": "The CLI is wired to greet", "verifier": { "type": "wiring", "entry": "bin/greet.mjs", "symbol": "greet" } }, + { "statement": "suite green", "cmd": "npm test" } + ], + "fields": { "estimate_days": 2 } + }, + { + "id": "EX-DOCS", + "title": "Usage documented", + "phase": "verify", + "depends_on": ["EX-02"], + "requirements": ["REQ-DOCS"], + "scope": ["README.md"], + "acceptance": [ + { "id": "{task}-USAGE", "statement": "README names the command", "verifier": { "type": "grep", "file": "README.md", "pattern": "greet ", "must": "present" } } + ], + "stop_rules": ["Docs describe what the code does today, nothing planned."] + } + ] +} diff --git a/src/decompose.mjs b/src/decompose.mjs new file mode 100644 index 0000000..91e4cab --- /dev/null +++ b/src/decompose.mjs @@ -0,0 +1,235 @@ +// Scope file -> unsigned proposal. Pure: reads the scope (and any --against contracts), returns bytes. +// The output is a fragment `proofline contract merge` accepts. It never writes proofline.json or a .sig. +import fs from 'node:fs'; +import path from 'node:path'; +import * as C from './contract.mjs'; +import { sha256 } from './util.mjs'; + +export const SCOPE_SCHEMA = 'proofline-scope/1'; + +const CORE = ['id', 'title', 'phase', 'owner', 'depends_on', 'requirements', 'description', 'scope', 'criteria', 'stop_rules']; +const WRAP_KEYS = ['requirements', 'scope', 'criteria', 'stop_rules']; +const SCOPE_KEYS = ['schema', 'prefix', 'pad', 'proposal', 'owner_rules', 'defaults', 'prepend', 'append', 'external', 'tasks']; +const TASK_KEYS = ['id', 'n', 'title', 'phase', 'owner', 'depends_on', 'requirements', 'description', 'scope', 'acceptance', 'stop_rules', 'fields', 'inherit']; +const DEFAULT_KEYS = ['phase', 'owner', 'scope', 'stop_rules', 'fields']; +const ID_RE = /^[A-Za-z][A-Za-z0-9-]*$/; + +/** Standard criteria a scope file may name with a single word. Same statements as `contract scaffold`. */ +const STANDARD = { + scope: () => ({ statement: 'Changes stay in scope', verifier: { type: 'scope' } }), + pushed: () => ({ statement: 'Committed and pushed to main', verifier: { type: 'pushed' } }), +}; + +const clone = (v) => (v === undefined ? undefined : JSON.parse(JSON.stringify(v))); +const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v); +const list = (v, what) => { + if (v === undefined) return []; + if (!Array.isArray(v)) throw new Error(`${what} must be a list`); + return clone(v); +}; +const text = (v, what) => { + if (v === undefined) return ''; + if (typeof v === 'string') return v; + if (Array.isArray(v) && v.every((s) => typeof s === 'string')) return v.join(' '); + throw new Error(`${what} must be a string or a list of strings`); +}; + +/** `{task}` in any string becomes the task id. Nothing else is expanded. */ +function expand(v, id) { + if (typeof v === 'string') return v.split('{task}').join(id); + if (Array.isArray(v)) return v.map((x) => expand(x, id)); + if (isObj(v)) return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, expand(x, id)])); + return v; +} + +function unknownKeys(obj, allowed, where) { + const bad = Object.keys(obj).filter((k) => !allowed.includes(k)); + if (bad.length) throw new Error(`${where}: unknown key ${bad.join(', ')} (accepted: ${allowed.join(', ')})`); +} + +function taskId(t, i, prefix, pad) { + if (t.id !== undefined) { + if (t.n !== undefined) throw new Error(`task ${i + 1}: give id or n, not both`); + if (typeof t.id !== 'string' || !ID_RE.test(t.id)) throw new Error(`task ${i + 1}: id must match ${ID_RE}`); + return t.id; + } + if (!Number.isInteger(t.n) || t.n < 0) throw new Error(`task ${i + 1}: needs an id, or n (a whole number) with a scope prefix`); + if (!prefix) throw new Error(`task ${i + 1}: n needs a scope prefix`); + return `${prefix}-${String(t.n).padStart(pad, '0')}`; +} + +/** One acceptance item: a standard word, a command shorthand, or a criterion with its verifier. */ +function criterion(item, where) { + if (typeof item === 'string') { + if (!STANDARD[item]) throw new Error(`${where}: "${item}" is not a standard criterion (${Object.keys(STANDARD).join(', ')})`); + return criterion(STANDARD[item](), where); + } + if (!isObj(item)) throw new Error(`${where}: an acceptance item is a word or an object`); + const { id, mandatory, statement, verifier, cmd, expect_exit, timeout_s, ...rest } = clone(item); + if (typeof statement !== 'string' || !statement.trim()) throw new Error(`${where}: needs a statement`); + let v = verifier; + if (cmd !== undefined) { + if (v !== undefined) throw new Error(`${where}: give cmd or verifier, not both`); + v = { type: 'command', cmd, ...(expect_exit !== undefined ? { expect_exit } : {}), ...(timeout_s !== undefined ? { timeout_s } : {}) }; + } else if (expect_exit !== undefined || timeout_s !== undefined) throw new Error(`${where}: expect_exit and timeout_s go with cmd`); + if (!isObj(v)) throw new Error(`${where}: needs a verifier (or cmd)`); + if (mandatory !== undefined && typeof mandatory !== 'boolean') throw new Error(`${where}: mandatory must be true or false`); + return { ...(id !== undefined ? { id } : {}), mandatory: mandatory !== false, statement, verifier: v, ...rest }; +} + +function inheritOf(t, where) { + if (t.inherit === undefined || t.inherit === true) return new Set(WRAP_KEYS); + if (t.inherit === false) return new Set(); + if (Array.isArray(t.inherit) && t.inherit.every((k) => WRAP_KEYS.includes(k))) return new Set(t.inherit); + throw new Error(`${where}: inherit must be true, false or a list of ${WRAP_KEYS.join(', ')}`); +} + +function wrapOf(spec, key) { + const w = spec[key]; + if (w === undefined) return {}; + if (!isObj(w)) throw new Error(`${key} must be an object`); + unknownKeys(w, WRAP_KEYS, key); + return w; +} + +/** Build one task. Key order is fixed so the bytes are stable. */ +function buildTask(t, i, ctx) { + const where = `task ${i + 1}`; + if (!isObj(t)) throw new Error(`${where}: must be an object`); + unknownKeys(t, TASK_KEYS, where); + const id = taskId(t, i, ctx.prefix, ctx.pad); + const at = `${where} (${id})`; + if (typeof t.title !== 'string' || !t.title.trim()) throw new Error(`${at}: needs a title`); + const d = ctx.defaults; + const inherit = inheritOf(t, at); + const wrap = (key, own) => [ + ...(inherit.has(key) ? list(ctx.prepend[key], `prepend.${key}`) : []), + ...own, + ...(inherit.has(key) ? list(ctx.append[key], `append.${key}`) : []), + ]; + const phase = t.phase ?? d.phase ?? 'implement'; + if (!C.PHASES.includes(phase)) throw new Error(`${at}: unknown phase ${phase} (${C.PHASES.join(', ')})`); + const owner = t.owner ?? d.owner; + if (owner !== undefined && (typeof owner !== 'string' || !owner.trim())) throw new Error(`${at}: owner must be a name`); + const deps = list(t.depends_on, `${at}: depends_on`).map((x) => (Number.isInteger(x) ? taskId({ n: x }, i, ctx.prefix, ctx.pad) : x)); + for (const x of deps) if (typeof x !== 'string' || !ID_RE.test(x)) throw new Error(`${at}: depends_on entry ${JSON.stringify(x)} is not a task id`); + const requirements = wrap('requirements', list(t.requirements, `${at}: requirements`)); + const rawScope = clone(t.scope ?? d.scope); + const { allow: ownAllow, ...scopeRest } = isObj(rawScope) ? rawScope : { allow: rawScope }; + const scope = wrap('scope', list(ownAllow, `${at}: scope`)); + if (!scope.length) throw new Error(`${at}: needs a scope (task scope or defaults.scope)`); + const items = wrap('criteria', list(t.acceptance, `${at}: acceptance`)); + if (!items.length) throw new Error(`${at}: needs at least one acceptance check`); + const criteria = items.map((x, k) => { + const c = criterion(x, `${at} acceptance ${k + 1}`); + return { id: c.id ?? `${id}-AC${String(k + 1).padStart(2, '0')}`, ...c }; + }); + let stops = wrap('stop_rules', list(t.stop_rules ?? d.stop_rules, `${at}: stop_rules`)); + if (!stops.length) stops = [...C.DEFAULT_STOP_RULES]; + const fields = { ...(clone(d.fields) || {}), ...(clone(t.fields) || {}) }; + const clash = Object.keys(fields).filter((k) => CORE.includes(k)); + if (clash.length) throw new Error(`${at}: fields may not set ${clash.join(', ')}`); + const task = { + id, title: t.title, phase, ...(owner !== undefined ? { owner } : {}), + depends_on: deps, requirements, description: text(t.description, `${at}: description`), + ...fields, + scope: { allow: scope, ...scopeRest }, criteria, stop_rules: stops, + }; + const out = expand(task, id); + const seen = new Set(); + for (const c of out.criteria) { + if (seen.has(c.id)) throw new Error(`${at}: duplicate criterion id ${c.id}`); + seen.add(c.id); + } + return out; +} + +function idsOf(file) { + const c = C.loadFile(file); + return (Array.isArray(c) ? c : c.tasks || []).map((t) => t.id); +} + +/** A stand-in for a task that already exists elsewhere, so validate can resolve a dependency on it. */ +const stub = (id) => ({ id, title: id, phase: 'intake', depends_on: [], scope: { allow: ['**'] }, criteria: [{ id: `${id}-S`, verifier: { type: 'scope' } }], stop_rules: ['stop'] }); + +/** + * Decompose a parsed scope into a proposal. Throws (nothing returned) on a duplicate id, an unknown + * dependency, a cycle, or a task `contract validate` would refuse. With lint: 'warn', the lint findings + * (no scope criterion, no stop rules, a path outside scope, an expanding shell) come back as warnings. + */ +export function decompose(spec, { against = [], lint = 'error' } = {}) { + if (!isObj(spec)) throw new Error('a scope file is a JSON object'); + unknownKeys(spec, SCOPE_KEYS, 'scope'); + if (spec.schema !== SCOPE_SCHEMA) throw new Error(`scope schema must be ${SCOPE_SCHEMA}`); + const prefix = spec.prefix; + if (prefix !== undefined && (typeof prefix !== 'string' || !ID_RE.test(prefix))) throw new Error(`prefix must match ${ID_RE}`); + const pad = spec.pad ?? 2; + if (!Number.isInteger(pad) || pad < 1 || pad > 6) throw new Error('pad must be a whole number from 1 to 6'); + const defaults = spec.defaults ?? {}; + if (!isObj(defaults)) throw new Error('defaults must be an object'); + unknownKeys(defaults, DEFAULT_KEYS, 'defaults'); + if (!Array.isArray(spec.tasks) || !spec.tasks.length) throw new Error('scope needs a non-empty tasks list'); + const ctx = { prefix, pad, defaults, prepend: wrapOf(spec, 'prepend'), append: wrapOf(spec, 'append') }; + const tasks = spec.tasks.map((t, i) => buildTask(t, i, ctx)); + + const mine = new Set(); + for (const t of tasks) { + if (mine.has(t.id)) throw new Error(`duplicate task id ${t.id} in the scope file`); + mine.add(t.id); + } + const existing = new Map(); + for (const f of against) for (const id of idsOf(f)) if (!existing.has(id)) existing.set(id, f); + for (const t of tasks) if (existing.has(t.id)) throw new Error(`duplicate task id ${t.id}: already in ${existing.get(t.id)}`); + const external = list(spec.external, 'external'); + const known = new Set([...existing.keys(), ...external]); + for (const t of tasks) for (const dep of t.depends_on) { + if (!mine.has(dep) && !known.has(dep)) throw new Error(`${t.id}: depends on unknown ${dep} (not in this scope, --against or external)`); + } + + const probe = { ...C.skeleton('scope'), tasks: [...[...known].filter((id) => !mine.has(id)).map(stub), ...tasks] }; + const structural = C.validate(probe); + if (structural.length) throw new Error(`scope does not validate:\n${structural.join('\n')}`); + const lintFindings = C.lint(probe).errors.filter((e) => !structural.includes(e)); + if (lintFindings.length && lint !== 'warn') throw new Error(`scope does not pass contract validate:\n${lintFindings.join('\n')}\n(--lint-warn reports these as warnings)`); + + const header = spec.proposal ?? {}; + if (!isObj(header)) throw new Error('proposal must be an object'); + const reserved = Object.keys(header).filter((k) => ['schema', 'status', 'owner_rules', 'tasks'].includes(k)); + if (reserved.length) throw new Error(`proposal may not set ${reserved.join(', ')}; decompose writes them`); + const rules = list(spec.owner_rules, 'owner_rules'); + if (!rules.every((r) => typeof r === 'string' && r.trim())) throw new Error('owner_rules must be a list of sentences'); + const proposal = { schema: C.SCHEMA, status: 'proposed', ...clone(header), ...(rules.length ? { owner_rules: rules } : {}), tasks }; + const bytes = JSON.stringify(proposal, null, 2) + '\n'; + return { proposal, bytes, sha256: sha256(bytes), ids: tasks.map((t) => t.id), warnings: lint === 'warn' ? lintFindings : [] }; +} + +/** A path decompose refuses to write: any proofline.json, any signature, or the root contract itself. */ +export function forbiddenOut(root, out) { + const base = path.basename(out); + if (base === 'proofline.json' || base.endsWith('.sig')) return true; + return path.resolve(out) === path.resolve(C.contractPath(root)); +} + +/** + * The CLI step: read the scope, decompose, then print, write (--out) or compare (--check). + * With check, an out file whose bytes differ is reported and nothing is written. + */ +export function decomposeFile(root, scopePath, { out, against = [], check = false, lint } = {}) { + let spec; + try { spec = JSON.parse(fs.readFileSync(scopePath, 'utf8')); } catch (e) { throw new Error(`cannot read scope ${scopePath}: ${e.message}`); } + const r = decompose(spec, { against, lint }); + if (!out) { + if (check) throw new Error('--check needs --out'); + return { ...r, written: null, same: null }; + } + if (forbiddenOut(root, out)) throw new Error(`refusing to write ${out}: decompose writes proposals, never proofline.json or a signature`); + let have = null; + try { have = fs.readFileSync(out, 'utf8'); } catch { have = null; } + const same = have === r.bytes; + if (check) return { ...r, written: null, same }; + if (!same) { + fs.mkdirSync(path.dirname(out), { recursive: true }); + fs.writeFileSync(out, r.bytes); + } + return { ...r, written: out, same }; +} diff --git a/test/cli_unknown_flags.test.mjs b/test/cli_unknown_flags.test.mjs index c3cf420..7cd46f3 100644 --- a/test/cli_unknown_flags.test.mjs +++ b/test/cli_unknown_flags.test.mjs @@ -15,6 +15,7 @@ const COMMANDS = [ ['contract', 'create'], ['contract', 'merge'], ['contract', 'coverage'], + ['contract', 'decompose'], ['contract', 'scaffold'], ['contract', 'approve'], ['contract', 'sign'], diff --git a/test/contract_decompose.test.mjs b/test/contract_decompose.test.mjs new file mode 100644 index 0000000..79c56c7 --- /dev/null +++ b/test/contract_decompose.test.mjs @@ -0,0 +1,136 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; +import { spawnSync } from 'node:child_process'; +import { repo, BIN } from './helpers.mjs'; +import { decompose } from '../src/decompose.mjs'; +import { sha256 } from '../src/util.mjs'; + +const FIX = path.resolve(import.meta.dirname, '..', 'fixtures', 'decompose'); +const SCOPE = path.join(FIX, 'example-project.scope.json'); +const GOLDEN = path.join(FIX, 'example-project.proposal.json'); +const REQS = path.join(FIX, 'REQUIREMENTS.md'); +const scope = () => JSON.parse(fs.readFileSync(SCOPE, 'utf8')); +const cli = (args, cwd) => spawnSync(process.execPath, [BIN, ...args], { cwd, encoding: 'utf8' }); +const tmp = () => fs.mkdtempSync(path.join(os.tmpdir(), 'pl-decompose-')); + +test('decompose output is byte-identical to the golden file, run after run and however the scope is formatted', () => { + const golden = fs.readFileSync(GOLDEN, 'utf8'); + assert.equal(decompose(scope()).bytes, golden); + const dir = tmp(); + const compact = path.join(dir, 'compact.scope.json'); + fs.writeFileSync(compact, JSON.stringify(scope())); + const a = cli(['contract', 'decompose', SCOPE, '--root', dir], dir); + const b = cli(['contract', 'decompose', compact, '--root', dir], dir); + assert.equal(a.status, 0, a.stderr); + assert.equal(a.stdout, golden); + assert.equal(b.stdout, golden); + const out = cli(['contract', 'decompose', SCOPE, '--out', 'p.json', '--root', dir], dir); + assert.equal(out.status, 0, out.stderr); + assert.equal(out.stdout.split('\n')[0], sha256(golden)); + assert.equal(fs.readFileSync(path.join(dir, 'p.json'), 'utf8'), golden); +}); + +test('ids, criterion numbering, prepend/append, defaults and {task} follow the scope', () => { + const { proposal } = decompose(scope()); + assert.deepEqual(proposal.tasks.map((t) => t.id), ['EX-01', 'EX-02', 'EX-DOCS']); + const [one, two, docs] = proposal.tasks; + assert.deepEqual(one.criteria.map((c) => c.id), ['EX-01-AC01', 'EX-01-AC02', 'EX-01-AC03', 'EX-01-AC04']); + assert.deepEqual(one.criteria.slice(2).map((c) => c.verifier.type), ['scope', 'pushed']); + assert.ok(one.criteria.every((c) => c.mandatory === true)); + assert.deepEqual(one.criteria[1].verifier, { type: 'command', cmd: 'npm test', expect_exit: 0, timeout_s: 120 }); + assert.deepEqual(two.depends_on, ['EX-01']); + assert.equal(two.estimate_days, 2); + assert.equal(one.estimate_days, 1); + assert.equal(one.owner, 'OWNER'); + assert.deepEqual(one.requirements, ['REQ-GREET', 'REQ-QUALITY']); + assert.equal(docs.criteria[0].id, 'EX-DOCS-USAGE'); + assert.equal(docs.stop_rules.length, 2); + assert.equal(proposal.status, 'proposed'); + assert.equal(proposal.schema, 'proofline/1'); +}); + +test('a duplicate id is refused, inside the scope and against an existing contract, and nothing is written', () => { + const s = scope(); + s.tasks[1].n = 1; + delete s.tasks[1].depends_on; + assert.throws(() => decompose(s), /duplicate task id EX-01 in the scope file/); + + const r = repo(); + const contract = path.join(r, 'proofline.json'); + const c = JSON.parse(fs.readFileSync(contract, 'utf8')); + c.tasks.push({ id: 'EX-02', title: 'taken', phase: 'implement', depends_on: [], scope: { allow: ['**'] }, criteria: [{ id: 'EX-02-AC01', verifier: { type: 'scope' } }], stop_rules: ['stop'] }); + fs.writeFileSync(contract, JSON.stringify(c, null, 2) + '\n'); + const before = fs.readFileSync(contract); + const res = cli(['contract', 'decompose', SCOPE, '--against', 'proofline.json', '--out', 'docs/proposals/p.json', '--root', r], r); + assert.equal(res.status, 3); + assert.match(res.stderr, /duplicate task id EX-02: already in/); + assert.equal(fs.existsSync(path.join(r, 'docs/proposals/p.json')), false); + assert.deepEqual(fs.readFileSync(contract), before); +}); + +test('an unknown dependency, a cycle and a task validate would refuse are all refused', () => { + const s = scope(); + s.tasks[2].depends_on = ['EX-99']; + assert.throws(() => decompose(s), /EX-DOCS: depends on unknown EX-99/); + s.external = ['EX-99']; + assert.doesNotThrow(() => decompose(s)); + const loop = scope(); + loop.tasks[0].depends_on = ['EX-DOCS']; + assert.throws(() => decompose(loop), /dependency cycle/); + const bare = scope(); + bare.append = {}; + assert.throws(() => decompose(bare), /no scope criterion/); + assert.equal(decompose(bare, { lint: 'warn' }).warnings.length, 3); + const phase = scope(); + phase.tasks[0].phase = 'someday'; + assert.throws(() => decompose(phase), /unknown phase someday/); +}); + +test('decompose never writes proofline.json or a signature, and --check reports drift without writing', () => { + const r = repo(); + const contract = path.join(r, 'proofline.json'); + const before = fs.readFileSync(contract); + for (const out of ['proofline.json', 'sub/proofline.json', 'proofline.json.sig', 'p.sig']) { + const res = cli(['contract', 'decompose', SCOPE, '--out', out, '--root', r], r); + assert.equal(res.status, 3, out); + assert.match(res.stderr, /never proofline\.json or a signature/); + } + assert.deepEqual(fs.readFileSync(contract), before); + assert.equal(fs.existsSync(path.join(r, 'sub')), false); + const stale = path.join(r, 'p.json'); + fs.writeFileSync(stale, '{}\n'); + const check = cli(['contract', 'decompose', SCOPE, '--out', 'p.json', '--check', '--root', r], r); + assert.equal(check.status, 1); + assert.match(check.stdout, /differs from the scope/); + assert.equal(fs.readFileSync(stale, 'utf8'), '{}\n'); + assert.equal(cli(['contract', 'decompose', SCOPE, '--out', 'p.json', '--root', r], r).status, 0); + assert.equal(cli(['contract', 'decompose', SCOPE, '--out', 'p.json', '--check', '--root', r], r).status, 0); + assert.deepEqual(fs.readFileSync(contract), before); +}); + +test('the proposal round-trips through contract merge, then validate and coverage pass', () => { + const r = repo(); + const made = cli(['contract', 'decompose', SCOPE, '--out', 'docs/proposals/example.json', '--root', r], r); + assert.equal(made.status, 0, made.stderr); + const proposal = JSON.parse(fs.readFileSync(path.join(r, 'docs/proposals/example.json'), 'utf8')); + const merged = cli(['contract', 'merge', 'docs/proposals/example.json', '--owners', 'OWNER=alice', '--root', r], r); + assert.equal(merged.status, 0, merged.stderr); + const after = fs.readFileSync(path.join(r, 'proofline.json'), 'utf8'); + assert.equal(merged.stdout.trim(), sha256(after)); + const c = JSON.parse(after); + const want = proposal.tasks.map((t) => ({ ...t, owner: 'alice' })); + assert.deepEqual(c.tasks.slice(-3), want); + assert.ok(c.owner_rules.includes(proposal.owner_rules[0])); + const valid = cli(['contract', 'validate', '--root', r], r); + assert.equal(valid.status, 0, valid.stdout + valid.stderr); + assert.match(valid.stdout, /contract valid/); + const cov = cli(['contract', 'coverage', REQS, '--root', r], r); + assert.equal(cov.status, 0, cov.stdout); + assert.match(cov.stdout, /^REQ-QUALITY EX-01,EX-02,EX-DOCS$/m); + const again = cli(['contract', 'merge', 'docs/proposals/example.json', '--root', r], r); + assert.equal(again.status, 3); + assert.match(again.stderr, /duplicate task id EX-01/); +});