Skip to content

fix(tasks): honor constitution test-first principles in tasks generation - #5634

Open
TINGyu123644 wants to merge 1 commit into
github:mainfrom
TINGyu123644:fix/constitution-test-first-tasks
Open

TINGyu123644 wants to merge 1 commit into
github:mainfrom
TINGyu123644:fix/constitution-test-first-tasks

Conversation

@TINGyu123644

Copy link
Copy Markdown

Description

Fixes #5632. /speckit-tasks loads .specify/memory/constitution.md, but its task-generation rules still said tests are optional unless the feature spec or the user asks for TDD. A constitution principle such as "a failing test MUST exist and be observed failing before implementation" was therefore ignored, and the generated tasks.md could not pass /speckit-analyze's consistency checks.

This change makes the constitution an explicit third source of test-task requirements:

  • templates/commands/tasks.md: when a loaded constitution requires test-first development, generate the failing-test task before each implementation task; tests stay optional only when the constitution does not require them.
  • templates/tasks-template.md: the header note and all three user-story test headings now say tests are included when requested by the spec or required by the constitution.
  • tests/test_tasks_template_constraints.py: two prompt-contract regression tests covering both templates.

Testing

  • Ran relevant existing tests with a focused pytest invocation: python -m pytest --noconftest tests/test_tasks_template_constraints.py -q → 9 passed (7 existing + 2 new).
  • Confirmed the two new tests fail against the unmodified templates (2 failed) and pass with the patch.
  • Tested locally with .venv/bin/specify --help — not run: dependency installation stalled in this sandbox; no CLI behavior changes are included.
  • Ran the full tests suite — not run for the same dependency-install limitation; only the prompt-contract test file was executed.
  • Tested with a sample project — not applicable to a prompt-template text change.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: WorkBuddy (Tencent Hunyuan Hy, agent mode, autonomous with human-supervised submission) was used to inspect the issue and repository templates, draft the template wording and the two regression tests, and run the focused pytest verification. The change is limited to prompt/template documentation text and tests; no CLI runtime code was generated or modified.

@TINGyu123644
TINGyu123644 requested a review from mnriem as a code owner November 30, 2026 14:13
Copilot AI adaptive review requested due to automatic review settings November 30, 2026 14:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Contradictory test-trigger guidance across the command and output templates can still omit required story, contract, or phase test tasks, so the rules must be aligned.

2 open issues
What changed in this PR

This pull request updates task-generation prompts so constitution-mandated test-first development is recognized when producing tasks, and adds regression checks for the updated prompt contracts.

Changes:

  • Adds constitution-based test-task requirements and failing-test ordering guidance.
  • Updates the task output template’s test guidance and user-story headings.
  • Adds prompt-contract regression tests covering both templates.
File Description
tests/​test_tasks_template_constraints.py Adds regression assertions for constitution-related task-generation prompt requirements.
templates/​tasks-template.md Updates test-task notes and user-story test headings to reference constitution-driven requirements.
templates/​commands/​tasks.md Adds constitution-aware test-generation and failing-test ordering guidance.

Review effort: Lite (adaptive)

**CRITICAL**: Tasks MUST be organized by user story to enable independent implementation and testing.

**Tests are OPTIONAL**: Only generate test tasks if explicitly requested in the feature specification or if user requests TDD approach.
**Tests are OPTIONAL**: Only generate test tasks if explicitly requested in the feature specification, if the user requests a TDD approach, or if the loaded constitution requires test-first development. When a constitution principle mandates a failing test before implementation (for example, "a failing test MUST exist and be observed failing before implementation"), generate the failing-test task before each implementation task. Tests stay optional only for projects whose constitution does not require them.
**Prerequisites**: plan.md (required), spec.md (required for user stories), research.md, data-model.md, contracts/

**Tests**: The examples below include test tasks. Tests are OPTIONAL - only include them if explicitly requested in the feature specification.
**Tests**: The examples below include test tasks. Tests are OPTIONAL - only include them if explicitly requested in the feature specification or required by the project constitution (for example, a test-first principle).
@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Dec 1, 2026
@mnriem

mnriem commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for addressing this. Could we keep the prompt change concise and avoid prescribing test ordering? The “failing-test task before each implementation task” wording appears specific to the example constitution; each project should follow its own.

Could templates/commands/tasks.md and templates/tasks-template.md use the same concise guidance: “Tests are OPTIONAL: Only generate test tasks if explicitly requested in the feature specification or by the user, or required by the constitution.”

That keeps the generation instructions and output template aligned, while leaving test-first ordering to the project constitution.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /speckit-tasks treats tests as optional even when the constitution requires test-first

3 participants