From b5ffccbaab46a652d64bbafc45269d3128991be5 Mon Sep 17 00:00:00 2001 From: Manfred Riem <15701806+mnriem@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:49:28 -0600 Subject: [PATCH 1/2] Avoid duplicate Full SDD convergence tasks Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../copilot-extension-hooks/README.md | 5 +- .../commands/lifecycle.md | 2 +- spec-kit-presets/copilot-full-sdd/README.md | 23 ++- .../commands/speckit.converge.md | 64 +++++--- .../tests/test_extension_hooks.py | 153 +++++++++++------- spec-kit-presets/tests/test_full_sdd.py | 23 ++- 6 files changed, 175 insertions(+), 95 deletions(-) diff --git a/spec-kit-presets/copilot-extension-hooks/README.md b/spec-kit-presets/copilot-extension-hooks/README.md index bf6adf05..75bf9918 100644 --- a/spec-kit-presets/copilot-extension-hooks/README.md +++ b/spec-kit-presets/copilot-extension-hooks/README.md @@ -82,7 +82,7 @@ hooks could not be checked, then the workflow continues, as in core. An unavailable, denied, or failed mandatory invocation instead stops the invocation and reports failure. Completion post-hooks do not run after a baseline prerequisite/gate/validation stop. The wrapper preserves each command's -checkpoint, including a completed Lean convergence assessment that leaves +checkpoint, including a completed Lean or Full convergence assessment that leaves existing open tasks unchanged: its reported remaining work is not convergence, but it still reaches `after_converge`. Blocked assessments do not. It keeps an invocation-local dispatch record to avoid @@ -155,7 +155,8 @@ command, and also checks that baseline execution was not attempted. Reporting checks inspect final assistant responses for mandatory-hook failures and assistant-authored warnings for malformed YAML, not matching tool output. Negative transcript cases reject tool-only evidence and contradictory success. -Separate Lean convergence cases cover existing open work and blocked assessment. +Separate Lean and Full convergence cases cover existing open work and blocked +assessment. The Full case also covers a mixed set of findings and a repeat run. The marker-hook cases seed registrations and command skills directly; they do not exercise extension installation. diff --git a/spec-kit-presets/copilot-extension-hooks/commands/lifecycle.md b/spec-kit-presets/copilot-extension-hooks/commands/lifecycle.md index 3bedba78..150833cb 100644 --- a/spec-kit-presets/copilot-extension-hooks/commands/lifecycle.md +++ b/spec-kit-presets/copilot-extension-hooks/commands/lifecycle.md @@ -26,7 +26,7 @@ Apply these checkpoints exactly once per invocation: its summary. - For `analyze`, after the analysis report and remediation offer. - For `converge`, after producing and reporting `converged` or `tasks_appended` - in-session, before listing hooks. A completed Lean assessment that reports + in-session, before listing hooks. A completed Lean or Full assessment that reports remaining work already covered by existing open tasks also reaches this checkpoint, even when nothing is appended. This is not convergence and must not be reported as such. Blocked or unverified assessments do not reach it. diff --git a/spec-kit-presets/copilot-full-sdd/README.md b/spec-kit-presets/copilot-full-sdd/README.md index 53ef8696..30c9d867 100644 --- a/spec-kit-presets/copilot-full-sdd/README.md +++ b/spec-kit-presets/copilot-full-sdd/README.md @@ -8,13 +8,14 @@ at revision `27d14e20c187c1f2916540ea201ecbdc9f8ed588`. Copyright GitHub, Inc.; [MIT licensed](LICENSE). The upstream commands omit extension lifecycle-hook dispatch, -its separators, and dependent branch/report/checklist references. The only other -deviation is in `specify`: it rejects missing or whitespace-only descriptions +its separators, and dependent branch/report/checklist references. The `specify` +command also rejects missing or whitespace-only descriptions before writing files, uses the resolved template only for new specs, preserves unrelated content in an explicitly selected existing spec, and sets the active feature only after saving the spec. Its quality checklist and validation flow -remain unchanged. Script metadata and portable command references remain for -Specify to render for the project. +remain unchanged. The `converge` command also avoids appending work already +covered by unchecked tasks. Script metadata and portable command references +remain for Specify to render for the project. This is a Specify preset, not a `copilot plugin` package. ## Installation and prerequisites @@ -59,7 +60,12 @@ prerequisites. They are supplied by `specify init`, not bundled again here. | `analyze` | `spec.md`, `plan.md`, complete `tasks.md`, constitution | Read-only consistency/coverage report; constitution violations are CRITICAL; edits require separate approval | | `checklist` | Active feature, `spec.md`, nonempty `plan.md`, resolved checklist template; `tasks.md` if present | Append-only `checklists/.md`; requirements-quality questions, not implementation tests; new items unchecked and reviewer-owned | | `implement` | `plan.md`, complete `tasks.md`, existing checklists and available design artifacts | Code, validation and task progress; checklist approval gate, phase/dependency ordering, failure reporting and completion checks | -| `converge` | `spec.md`, `plan.md`, complete `tasks.md`, implementation already attempted; constitution | Only append traceable remediation tasks; no code/spec/plan edits, no existing-task rewriting; leave tasks byte-identical when converged | +| `converge` | `spec.md`, `plan.md`, complete `tasks.md`, implementation already attempted; constitution | Report open tasks that already cover findings; append only uncovered remediation; leave tasks byte-identical when nothing is appended; no code/spec/plan edits or existing-task rewrites | + +`converge` checks actual behavior even for checked tasks. An unmet finding +covered only by checked tasks can still get a new task. Work already tracked +by an unchecked task in any phase, including a prior Convergence phase, is +reported with its task ID and does not count as convergence. `clarify` normally runs after specify and before plan. `analyze` requires tasks; `checklist` requires a nonempty `plan.md` through the Spec Kit 1.2.3 setup script; @@ -94,10 +100,11 @@ each preset with its own compatible CLI. Leaving `FULL_SPECIFY_BIN` unset skips only Full's real-CLI checks, even when `SPECIFY_BIN` is set for Lean. Set `FULL_PRESET_ARCHIVE` to a local release zip for archive verification. Set `FULL_CORE_SOURCE` to a checkout of the pinned Spec Kit source for -source comparison against pinned Git blob IDs. Eight commands must exactly match +source comparison against pinned Git blob IDs. Seven commands must exactly match core with only the enumerated hook-related deletions and no added bytes. For -`specify`, the tests verify both the hook-stripped upstream baseline and the -reviewed downstream version, including an exact match for the quality workflow. +`specify` and `converge`, the tests verify both the hook-stripped upstream +baseline and the reviewed downstream version. The `specify` quality workflow +must still match core exactly. Digest, source, and archive comparisons use the same CRLF-to-LF normalization so checkout line-ending conversion does not change their results. These checks cover package and instruction contracts, not model compliance or diff --git a/spec-kit-presets/copilot-full-sdd/commands/speckit.converge.md b/spec-kit-presets/copilot-full-sdd/commands/speckit.converge.md index b84a5ff6..4c0b7a3b 100644 --- a/spec-kit-presets/copilot-full-sdd/commands/speckit.converge.md +++ b/spec-kit-presets/copilot-full-sdd/commands/speckit.converge.md @@ -1,5 +1,5 @@ --- -description: Assess the current codebase against the feature's spec, plan, and tasks, then append any remaining unbuilt work as new tasks to tasks.md so implement can complete it. +description: Assess the current codebase against the feature's spec, plan, and tasks, then append only remaining work not already covered by open tasks. scripts: sh: scripts/bash/check-prerequisites.sh --json --require-spec --require-tasks --include-tasks ps: scripts/powershell/check-prerequisites.ps1 -Json -RequireSpec -RequireTasks -IncludeTasks @@ -20,17 +20,20 @@ Close the gap between what a feature's specification, plan, and tasks call for a codebase currently implements. Read `spec.md`, `plan.md`, and `tasks.md` as the **sole source of intent** (with the constitution as governing constraints), assess the current state of the code, determine which requirements, acceptance criteria, plan decisions, and -existing tasks are unmet, incomplete, or only partially satisfied, and **append each piece -of remaining work as a new, traceable task** at the bottom of `tasks.md` so that +existing tasks are unmet, incomplete, or only partially satisfied, and **append only +remaining work not already covered by open tasks** at the bottom of `tasks.md` so that `__SPECKIT_COMMAND_IMPLEMENT__` can complete it. This command MUST run only after -`__SPECKIT_COMMAND_IMPLEMENT__` has run on the current `tasks.md`, and after `__SPECKIT_COMMAND_TASKS__` has produced a complete `tasks.md`. +`__SPECKIT_COMMAND_TASKS__` has produced a complete `tasks.md` and +`__SPECKIT_COMMAND_IMPLEMENT__` has attempted implementation for the feature. +A repeat assessment does not require another implementation pass on tasks appended +by an earlier Convergence run. This is **not** a diff tool and does **not** track changes. It assesses the present state of the code relative to the feature's artifacts — no git, no branch comparison, no history. ## Operating Constraints -**APPEND-ONLY, NEVER REWRITE**: The command's **only** write is appending a new +**APPEND-ONLY, NEVER REWRITE**: The command's **only permitted write** is appending a new `## Phase N: Convergence` section to `tasks.md`. It MUST NOT: - modify `spec.md` or `plan.md` in any way; @@ -39,13 +42,14 @@ of the code relative to the feature's artifacts — no git, no branch comparison - modify, create, or delete any application code — completing the appended tasks is the job of `__SPECKIT_COMMAND_IMPLEMENT__`. -When the codebase already satisfies everything, the command MUST leave `tasks.md` -**byte-for-byte unchanged** (no empty Convergence header) and report a clean result. +When no new tasks are needed, the command MUST leave `tasks.md` +**byte-for-byte unchanged** (no empty Convergence header). Report a clean result only +when the assessment finds no remaining work. **Constitution Authority**: The project constitution (`/memory/constitution.md`) is **non-negotiable**. Code that violates a MUST principle is the highest-severity finding and -produces a corresponding remediation task. If the constitution is an unfilled template, -skip constitution checks gracefully rather than failing. +requires a corresponding remediation task unless already covered by an open task. If the +constitution is an unfilled template, skip constitution checks gracefully rather than failing. ## Execution Steps @@ -84,7 +88,7 @@ Load only the minimal necessary context from each artifact: **From tasks.md:** - Task IDs (to compute the next ID and next phase number) -- Descriptions, phase grouping, and referenced file paths +- Checkbox states, descriptions, phase grouping, source references, and referenced file paths **From constitution (if not an unfilled template):** @@ -125,6 +129,14 @@ For each item in the intent inventory, inspect the current code in scope and pro Each `Finding` records: a stable id, the `source-ref` it traces to, the `gap-type`, a severity, and a short human-readable description with the evidence (the file/area observed). +For every actionable finding, compare the concrete remaining work with unchecked +tasks (`- [ ]`) across all phases, including prior Convergence phases. If open tasks +already cover the work, mark the finding **already tracked** and record the covering +task IDs. Match by the work those tasks would complete, not by exact wording or a +shared source reference alone. If open tasks cover only part of the work, report +the tracked portion and append only the uncovered remainder. A checked task alone +does not cover a still-unmet finding; that finding remains eligible for a new task. + **Edge cases:** - **Little or no code yet**: treat the entire specified scope as `missing` remaining work @@ -147,9 +159,12 @@ Before appending anything, output a compact, severity-graded summary (no file wr ## Convergence Findings -| ID | Gap Type | Severity | Source | Evidence | Remaining Work | -|----|----------|----------|--------|----------|----------------| -| F1 | missing | HIGH | FR-008 | Example: no append-only guard detected in path/to/module.py when writing tasks.md | Add append-only enforcement | +| ID | Gap Type | Severity | Source | Evidence | Remaining Work | Tracking | +|----|----------|----------|--------|----------|----------------|----------| +| F1 | missing | HIGH | FR-008 | Example: no append-only guard detected in path/to/module.py when writing tasks.md | Add append-only enforcement | Already tracked by T041 | + +Report already-tracked findings alongside uncovered findings. Cite the open task IDs +for tracked work and distinguish any uncovered remainder that needs a new task. **Summary metrics:** @@ -159,17 +174,18 @@ Before appending anything, output a compact, severity-graded summary (no file wr - Findings by gap type (missing / partial / contradicts / unrequested) - Findings by severity -### 7. Append Convergence Tasks (or report converged) +### 7. Append Convergence Tasks (or report without changes) -**If there are one or more actionable findings** (`tasks_appended` outcome): +**If there is any uncovered actionable work** (`tasks_appended` outcome): Append to the **end** of `tasks.md`, per the append contract: 1. Scan all existing task IDs; let `M` be the maximum. Determine the next phase number `N` (highest existing phase + 1). 2. Write a single new section header `## Phase N: Convergence`. -3. Emit one checklist item per actionable finding, ordered CRITICAL/HIGH first, assigning - zero-padded IDs `T{M+1:03d}, T{M+2:03d}, …`: +3. Emit one checklist item per actionable finding with uncovered work, describing only + that uncovered work. Order CRITICAL/HIGH first, assigning zero-padded IDs + `T{M+1:03d}, T{M+2:03d}, …`: ```markdown - [ ] T042 per () @@ -185,7 +201,13 @@ Append to the **end** of `tasks.md`, per the append contract: 4. Never reuse or renumber existing IDs. If a prior Convergence phase exists, add a new, separately-numbered one below it — do not touch the old one. -**If there are no actionable findings** (`converged` outcome): +**If all remaining work is already tracked by open tasks**: + +- Do **not** modify `tasks.md` at all. +- Report that work remains, cite the covering task IDs, and state that no new tasks + were appended. Do not report `converged` or `tasks_appended`. + +**If a completed assessment finds no remaining work** (`converged` outcome): - Do **not** modify `tasks.md` at all — no empty phase header. - Report: **"✅ Converged — the implementation satisfies the spec, plan, and tasks."** @@ -194,7 +216,9 @@ Append to the **end** of `tasks.md`, per the append contract: ### 8. Provide Next Actions (Handoff) - On `tasks_appended`: state how many tasks were appended under which phase, and recommend - running `__SPECKIT_COMMAND_IMPLEMENT__` to complete them; note that a follow-up converge - run will find fewer or no remaining items. + running `__SPECKIT_COMMAND_IMPLEMENT__` to complete them and any already-tracked work + identified above. +- When remaining work is already tracked and nothing was appended, recommend running + `__SPECKIT_COMMAND_IMPLEMENT__` on the cited open tasks before assessing again. - On `converged`: recommend proceeding to review / opening a PR. No further implement pass is needed for this feature's specified scope. diff --git a/spec-kit-presets/tests/test_extension_hooks.py b/spec-kit-presets/tests/test_extension_hooks.py index 7974f544..9d7fa045 100644 --- a/spec-kit-presets/tests/test_extension_hooks.py +++ b/spec-kit-presets/tests/test_extension_hooks.py @@ -433,6 +433,7 @@ def test_instruction_contract_not_a_runtime_compliance_test(self): "do not invoke it twice", "not a persistent lock", "before** the baseline Completion Report", "after producing and reporting `converged` or `tasks_appended`", + "A completed Lean or Full assessment", "remaining work already covered by existing open tasks", "Blocked or unverified assessments do not reach it", "To execute: `{invocation}`", "Command: `{command}`", @@ -812,32 +813,54 @@ def test_bounded_cli_invocation_wait_skips_duplicates_and_failures(self): ["speckit.fixture.optional", "speckit.fixture.optional-default"], ) - def test_lean_convergence_with_existing_open_work_and_blocked_assessment(self): - for blocked in (False, True): - with self.subTest(blocked=blocked), tempfile.TemporaryDirectory() as temp: + def test_convergence_reports_open_work_before_hooks_and_skips_hooks_when_blocked(self): + cases = [ + ("lean", "open-work"), ("lean", "blocked"), + ("full", "open-work"), ("full", "blocked"), ("full", "mixed"), + ] + for baseline, case in cases: + with self.subTest(baseline=baseline, case=case), tempfile.TemporaryDirectory() as temp: + blocked, mixed = case == "blocked", case == "mixed" root = Path(temp) - project = self.make_project(root, "copilot-lean-sdd", "success") + project = self.make_project(root, f"copilot-{baseline}-sdd", "success") feature = project / "specs/fixture" tasks = feature / "tasks.md" + checked_task = "- [x] T005 Set label.txt to ready per FR-002.\n" if mixed else "" + prior_phase = "\n## Phase 2: Convergence\n\n" if baseline == "full" else "" tasks.write_text( "# Tasks\n\n## Phase 1: Marker\n\n" "- [x] T000 [US1] Initial implementation of result.txt was attempted.\n" + f"{checked_task}{prior_phase}" "- [ ] T001 [US1] Fix result.txt to contain exactly done and a newline; " "verify with `python3 fixture.py verify`.\n", encoding="utf-8", ) before = tasks.read_bytes() (project / "result.txt").write_bytes(b"pending\n") + if mixed: + spec = feature / "spec.md" + spec.write_text( + spec.read_text(encoding="utf-8") + + "\nFR-002: label.txt contains exactly `ready` and a newline.\n", + encoding="utf-8", + ) + (project / "label.txt").write_bytes(b"pending\n") + plan_detail = { + "lean": "An assertion failure is remaining implementation work already covered " + "by T001, not a missing validation prerequisite.\n", + "full": "Set label.txt to ready and a newline as required by FR-002.\n" if mixed else "", + }[baseline] (feature / "plan.md").write_text( "# Plan\n\nresult.txt must contain exactly done and a newline. " "The implementation has been attempted but remains incomplete. " "The documented local validation is `python3 fixture.py verify`. " - "An assertion failure is remaining implementation work already covered " - "by T001, not a missing validation prerequisite.\n", encoding="utf-8", + f"{plan_detail}\n", + encoding="utf-8", ) - digest = hashlib.sha256(before).hexdigest() + verify_tasks = f"tasks.startswith({before!r})" if mixed else f"tasks == {before!r}" (project / "convergence-hook.py").write_text( - "import hashlib\nfrom pathlib import Path\n" - f"assert hashlib.sha256(Path('specs/fixture/tasks.md').read_bytes()).hexdigest() == {digest!r}\n" + "from pathlib import Path\n" + "tasks = Path('specs/fixture/tasks.md').read_bytes()\n" + f"assert {verify_tasks}\n" "with Path('convergence-hook.log').open('a') as output:\n" " output.write('after_converge\\n')\n" "print('AFTER_CONVERGE_COMPLETED')\n", encoding="utf-8", @@ -856,56 +879,72 @@ def test_lean_convergence_with_existing_open_work_and_blocked_assessment(self): }), encoding="utf-8") if blocked: (feature / "spec.md").unlink() - result = subprocess.run( - [ - str(Path(COPILOT).resolve()), "-C", str(project), "-p", - "Run the installed speckit-converge skill for the active feature and report " - "the actual assessment outcome. Follow the selected baseline and lifecycle " - "rules. Use local files only; do not implement remaining work, change fixture " - "scripts, skills, extensions.yml, global configuration, or spawn agents.", - "--trust-folder", "--allow-all-tools", "--disable-builtin-mcps", - "--available-tools=bash,view,rg,glob,skill,apply_patch", - "--deny-tool=shell(gh:*)", "--deny-tool=shell(curl:*)", - "--log-dir", str(root / "host-logs"), "--output-format", "json", - ], - text=True, encoding="utf-8", capture_output=True, timeout=300, - ) hook_log = project / "convergence-hook.log" - evidence = os.environ.get("HOOKS_EVIDENCE_DIR") - if evidence: - folder = Path(evidence) / ("lean-converge-blocked" if blocked else "lean-converge-open-work") - folder.mkdir(parents=True, exist_ok=True) - (folder / "host.jsonl").write_text(result.stdout, encoding="utf-8") - (folder / "stderr.txt").write_text(result.stderr, encoding="utf-8") - (folder / "tasks.md").write_bytes(tasks.read_bytes()) - (folder / "hook.log").write_text(hook_log.read_text() if hook_log.exists() else "") - self.assertEqual(result.returncode, 0, result.stderr[-2000:]) - self.assertEqual(tasks.read_bytes(), before, "Existing open work must not be duplicated or rewritten") - events = [json.loads(line) for line in result.stdout.splitlines()] - messages = [event["data"] for event in events if event["type"] == "assistant.message"] - finals = [m["content"] for m in messages if m.get("phase") == "final_answer"] - self.assertTrue(finals) - if blocked: - self.assertFalse(hook_log.exists()) - self.assertRegex(finals[-1].lower(), r"missing|blocked|unverified|stopped") - else: - self.assertEqual(hook_log.read_text(), "after_converge\n") - self.assertRegex(finals[-1], r"T001") - self.assertRegex(finals[-1].lower(), r"remaining|incomplete|not converged|open") - hook_index = next( - index for index, event in enumerate(events) if event["type"] == "assistant.message" - and any( - request.get("name") == "skill" - and request.get("arguments", {}).get("skill") == "speckit-fixture-convergence" - for request in event["data"].get("toolRequests", []) - ) - ) - before_hook = "\n".join( - event["data"].get("content", "") for event in events[:hook_index] - if event["type"] == "assistant.message" + for run in range(1, (2 if mixed else 1) + 1): + result = subprocess.run( + [ + str(Path(COPILOT).resolve()), "-C", str(project), "-p", + "Run the installed speckit-converge skill for the active feature and report " + "the actual assessment outcome. Follow the selected baseline and lifecycle " + "rules. Use local files only; do not implement remaining work, change fixture " + "scripts, skills, extensions.yml, global configuration, or spawn agents.", + "--trust-folder", "--allow-all-tools", "--disable-builtin-mcps", + "--available-tools=bash,view,rg,glob,skill,apply_patch", + "--deny-tool=shell(gh:*)", "--deny-tool=shell(curl:*)", + "--log-dir", str(root / "host-logs"), "--output-format", "json", + ], + text=True, encoding="utf-8", capture_output=True, timeout=300, ) - self.assertIn("T001", before_hook) - self.assertRegex(before_hook.lower(), r"remaining|incomplete|not converged|open") + after = tasks.read_bytes() + evidence = os.environ.get("HOOKS_EVIDENCE_DIR") + if evidence: + folder = Path(evidence) / f"{baseline}-converge-{case}-{run}" + folder.mkdir(parents=True, exist_ok=True) + (folder / "host.jsonl").write_text(result.stdout, encoding="utf-8") + (folder / "stderr.txt").write_text(result.stderr, encoding="utf-8") + (folder / "tasks.md").write_bytes(after) + (folder / "hook.log").write_text(hook_log.read_text() if hook_log.exists() else "") + self.assertEqual(result.returncode, 0, result.stderr[-2000:]) + if mixed and run == 1: + self.assertTrue(after.startswith(before), "Existing tasks must not be rewritten") + addition = after[len(before):].decode() + self.assertEqual(re.findall(r"^## .+", addition, re.M), ["## Phase 3: Convergence"]) + appended = re.findall(r"^- \[.\] .+", addition, re.M) + self.assertEqual(len(appended), 1) + self.assertRegex(appended[0], r"^- \[ \] T006 .*label\.txt") + self.assertRegex(appended[0], r"\b(?:FR-002|T005)\b") + before = after + else: + self.assertEqual(after, before, "Existing open work must not be duplicated or rewritten") + events = [json.loads(line) for line in result.stdout.splitlines()] + messages = [event["data"] for event in events if event["type"] == "assistant.message"] + finals = [m["content"] for m in messages if m.get("phase") == "final_answer"] + self.assertTrue(finals) + if blocked: + self.assertFalse(hook_log.exists()) + self.assertRegex(finals[-1].lower(), r"missing|blocked|unverified|stopped") + else: + self.assertEqual(hook_log.read_text(), "after_converge\n" * run) + self.assertIn("T001", finals[-1]) + self.assertRegex(finals[-1].lower(), r"remaining|incomplete|not converged|open|tracked") + self.assertNotIn("the implementation satisfies the spec", finals[-1].lower()) + hook_index = next( + index for index, event in enumerate(events) if event["type"] == "assistant.message" + and any( + request.get("name") == "skill" + and request.get("arguments", {}).get("skill") == "speckit-fixture-convergence" + for request in event["data"].get("toolRequests", []) + ) + ) + before_hook = "\n".join( + event["data"].get("content", "") for event in events[:hook_index] + if event["type"] == "assistant.message" + ) + self.assertIn("T001", before_hook) + self.assertRegex(before_hook.lower(), r"remaining|incomplete|not converged|open|tracked") + if mixed and run == 2: + self.assertIn("T006", finals[-1]) + self.assertIn("T006", before_hook) @unittest.skipUnless(os.environ.get("HOOKS_SPECIFY_SOURCE"), "Set HOOKS_SPECIFY_SOURCE for installed Git extension exercises") def test_installed_git_extension_registers_and_executes_before_specify(self): diff --git a/spec-kit-presets/tests/test_full_sdd.py b/spec-kit-presets/tests/test_full_sdd.py index 9dec8d2c..e46d63ca 100644 --- a/spec-kit-presets/tests/test_full_sdd.py +++ b/spec-kit-presets/tests/test_full_sdd.py @@ -27,7 +27,7 @@ "hooks.before_", "hooks.after_", "Extension Hooks", "Mandatory Post-Execution Hooks", "before_specify", ) -# Reviewed command bodies: hook-stripped core, plus the specify write safeguards. +# Reviewed command bodies: hook-stripped core, plus the specify and converge safeguards. REVIEWED_SHA256 = { "constitution": "775a220b62d7d59b8740df9f01b36465478cea511e619d21ae3d558599946143", "specify": "bb1543d4527e9edf336fca129277eeb40c76a52ee2980a5ce0366ae131cb76ce", @@ -37,9 +37,12 @@ "analyze": "e03e7c94a7253d2537fab197e5f2365a7ed9b9cdc6ef8fbec9d3c2663a7c9588", "checklist": "cca87df5a8586b0681ef3b0a3e6baca063748eed9546c52775d2f342abcaa143", "implement": "7658bcbfff7a78bfb8f6e3ae29b50b7f327f9e6da1e0cf1f57fcc27c5d4e1b55", + "converge": "68948b28e9ee57861e1c052bb30a4fdc9846fa40f97b621d6ed31e01984a4a98", +} +HOOK_STRIPPED_BASELINE_SHA256 = { + "specify": "090c4af532316e6529373e722d7957bec2f27cd74b3f18d525fdbeeaa1aae320", "converge": "2a3cbec425ccf205e7d048f0629584f0d3242d2b92402da196a0c3022198c79e", } -HOOK_STRIPPED_SPECIFY_SHA256 = "090c4af532316e6529373e722d7957bec2f27cd74b3f18d525fdbeeaa1aae320" CORE_GIT_BLOBS = { "analyze": "7de2d28f0da797998e5e30d6323b7316a74e60ff", "checklist": "6e33f5d4225c539fa1c3860e5409f098a6a8d827", @@ -156,9 +159,14 @@ def test_authenticated_core_comparison(self): ) expected = expected.rstrip("\n") + "\n" actual = lf_bytes((PACKAGE / f"commands/speckit.{name}.md").read_bytes()) - if name == "specify": - self.assertEqual(hashlib.sha256(expected.encode()).hexdigest(), HOOK_STRIPPED_SPECIFY_SHA256) + if name in HOOK_STRIPPED_BASELINE_SHA256: + self.assertEqual( + hashlib.sha256(expected.encode()).hexdigest(), HOOK_STRIPPED_BASELINE_SHA256[name], + ) self.assertEqual(hashlib.sha256(actual).hexdigest(), REVIEWED_SHA256[name]) + else: + self.assertEqual(actual, expected.encode(), "Non-hook instructions must match after LF normalization") + if name == "specify": quality_blocks = [] for text in (expected, actual.decode()): _, start, rest = text.partition("\n8. **Specification Quality Validation**") @@ -166,10 +174,8 @@ def test_authenticated_core_comparison(self): self.assertTrue(start and end, "Quality workflow must be present") quality_blocks.append(quality) self.assertEqual(*quality_blocks, "Specify quality workflow must match core exactly") - else: - self.assertEqual(actual, expected.encode(), "Non-hook instructions must match after LF normalization") source_iterator = iter(original) - hook_stripped = expected.encode() if name == "specify" else actual + hook_stripped = expected.encode() if name in HOOK_STRIPPED_BASELINE_SHA256 else actual self.assertTrue(all(byte in source_iterator for byte in hook_stripped), "No added bytes allowed") def test_no_lifecycle_dispatch_and_preserved_script_metadata(self): @@ -235,6 +241,9 @@ def test_full_artifact_and_quality_contracts(self): "byte-for-byte unchanged", "completion claims are not evidence", "Never reuse or renumber existing IDs", "Constitution-violation tasks MUST", "MUST run only after", + "prior Convergence phases", "append only the uncovered remainder", + "does not cover a still-unmet finding", "Do not report `converged` or `tasks_appended`", + "A repeat assessment does not require another implementation pass", ], } for name, contracts in expected.items(): From 361633afaf20c2724d3ef571e829c32b3b176304 Mon Sep 17 00:00:00 2001 From: Manfred Riem <15701806+mnriem@users.noreply.github.com> Date: Fri, 20 Nov 2026 09:20:40 -0600 Subject: [PATCH 2/2] Verify convergence tasks exist before the completion hook Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../tests/test_extension_hooks.py | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/spec-kit-presets/tests/test_extension_hooks.py b/spec-kit-presets/tests/test_extension_hooks.py index 9d7fa045..4c579e4e 100644 --- a/spec-kit-presets/tests/test_extension_hooks.py +++ b/spec-kit-presets/tests/test_extension_hooks.py @@ -856,11 +856,21 @@ def test_convergence_reports_open_work_before_hooks_and_skips_hooks_when_blocked f"{plan_detail}\n", encoding="utf-8", ) - verify_tasks = f"tasks.startswith({before!r})" if mixed else f"tasks == {before!r}" - (project / "convergence-hook.py").write_text( + remediation = r"^- \[ \] T006 (?=.*label\.txt)(?=.*\b(?:FR-002|T005)\b)" + if mixed: + verify_tasks = ( + f"assert tasks.startswith({before!r})\n" + f"assert re.search({remediation!r}, tasks[{len(before)}:].decode(), re.M), " + "'T006 remediation must be appended before after_converge'\n" + ) + else: + verify_tasks = f"assert tasks == {before!r}\n" + hook_script = project / "convergence-hook.py" + hook_script.write_text( "from pathlib import Path\n" + "import re\n" "tasks = Path('specs/fixture/tasks.md').read_bytes()\n" - f"assert {verify_tasks}\n" + f"{verify_tasks}" "with Path('convergence-hook.log').open('a') as output:\n" " output.write('after_converge\\n')\n" "print('AFTER_CONVERGE_COMPLETED')\n", encoding="utf-8", @@ -880,6 +890,14 @@ def test_convergence_reports_open_work_before_hooks_and_skips_hooks_when_blocked if blocked: (feature / "spec.md").unlink() hook_log = project / "convergence-hook.log" + if mixed: + premature = subprocess.run( + ["python3", str(hook_script)], cwd=project, text=True, + capture_output=True, timeout=30, + ) + self.assertNotEqual(premature.returncode, 0) + self.assertIn("T006 remediation must be appended before after_converge", premature.stderr) + self.assertFalse(hook_log.exists()) for run in range(1, (2 if mixed else 1) + 1): result = subprocess.run( [ @@ -911,8 +929,7 @@ def test_convergence_reports_open_work_before_hooks_and_skips_hooks_when_blocked self.assertEqual(re.findall(r"^## .+", addition, re.M), ["## Phase 3: Convergence"]) appended = re.findall(r"^- \[.\] .+", addition, re.M) self.assertEqual(len(appended), 1) - self.assertRegex(appended[0], r"^- \[ \] T006 .*label\.txt") - self.assertRegex(appended[0], r"\b(?:FR-002|T005)\b") + self.assertRegex(appended[0], remediation) before = after else: self.assertEqual(after, before, "Existing open work must not be duplicated or rewritten")