Skip to content

fix(cli): create --template uses KB schema fields and defaults (#1598) - #1657

Open
prateeknitcse wants to merge 2 commits into
pyrite-wiki:devfrom
prateeknitcse:fix/1598-create-template-uses-kb-schema
Open

prateeknitcse wants to merge 2 commits into
pyrite-wiki:devfrom
prateeknitcse:fix/1598-create-template-uses-kb-schema

Conversation

@prateeknitcse

Copy link
Copy Markdown
Contributor

Closes #1598.

Summary of Changes

  • pyrite create -k <kb> -t <type> --template now resolves the entry type against the specified KB's schema and builds the skeleton with declared fields and defaults (matching the fields and defaults written by create).
  • Undeclared types in a KB that declares types are refused with UNDECLARED_TYPE (or undeclared mapping targets), matching the behavior and error of a real create.
  • Without -k, pyrite create -t <type> --template retains the standalone core types skeleton.
  • Added regression tests in tests/test_create_template_kb_schema.py.
  • Added changelog fragment changelog.d/1598-create-template-kb-schema.fixed.md.

@markramm markramm added the state: needs-review No review on the current head: the next move is ours label Nov 17, 2026

@markramm markramm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for taking #1598. The approach is the one the groom describes: create -k <kb> --template now asks the KB service for the skeleton, using the same declared-fields code (_with_declared_fields) that a real create uses, and refuses undeclared types with the create's own error. The no--k path is unchanged. The tests use the cli_world fixture, which is the right choice. Two things need attention before this can merge: another open PR for the same issue, and a gap between "what the template shows" and "what a create writes".

Blocking

  1. Duplicate PR. #1605 (swastiktawate, opened 2026-11-17 12:11Z, about eight hours before this one) also closes #1598. It touches the same files and already has a review with specific requests. Which one lands: #1605 was first, so it keeps #1598 while its author works on it. If #1605 has no answer to its review by 2026-11-20, this PR becomes the one that lands, and #1605 is credited for its approach. In the meantime it is fine to keep this branch ready. The findings below are the same asks #1605 has, so the work is not wasted either way.

  2. tests/test_create_template_kb_schema.py: the groom's first acceptance bullet asks that the template be compared with the file a real create -k proj -t backlog_item --title x writes. The test hand-lists a few keys (status, priority, kind, effort, assignee) instead. Please run the real create in the same KB, read the written frontmatter, and assert that the template's keys and defaults equal it (apart from id, title, tags). A parametrised version over a few (KB, type) pairs is the strongest form; it would also catch the next two points.

  3. pyrite/services/kb_service.py, template_frontmatter, and --allow-undeclared: with the flag, a skeleton is printed for any type. In a KB with validation.enforce on, the real create with the same flag is refused (rule known_type), so the template shows a skeleton for a create that fails. Please make the template answer what the create answers, and test it by running both with the same flags. (The review on #1605, item 2, shows the exact reproduction.)

  4. template_frontmatter and plugin type mappings: the method resolves the type with _resolve_entry_type, which is good, but nothing tests a mapped type (for example event in a journalism-investigation KB, which a create stores as investigation_event). Please add that KB as a test case and check the template's type equals the written one.

Non-blocking

  • entry_commands.py: entry_type = resolved_type is assigned inside the with block but the non--k branch keeps the old inline skeleton; a short comment saying the two are deliberately separate would help the next reader.
  • The PR description says tests cover "plugin types" but only backlog_item in a software KB is exercised; fine once item 4 is added.
  • Unknown -k is already handled by cli_context (it raises the usual KB-not-found error); a one-line test would pin it, since the groom lists it as a regime.

CI: at review time only lock passed and changes was still pending; the test jobs had not started. Please look again once they run. In particular tests/test_production_wiring_guard.py should stay green (your tests do not patch load_config, which is good).

Triggers: touches pyrite/services/kb_service.py (a service shared by CLI, REST and MCP) and changes what a CLI command prints, and there is a competing PR on the same issue. This is the maintainer's merge.

There is a changelog fragment (changelog.d/1598-create-template-kb-schema.fixed.md). No new flag or REST/MCP field is added; MCP and REST have no template call, as the groom notes.

Recommendation: request changes.

@markramm markramm added state: needs-author Changes requested on the current head: the next move is the author's and removed state: needs-review No review on the current head: the next move is ours labels Nov 17, 2026
@prateeknitcse
prateeknitcse force-pushed the fix/1598-create-template-uses-kb-schema branch from 136021e to 22a16a3 Compare November 17, 2026 20:44

@markramm markramm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the new head 22a16a3.

Previous items:

  1. Duplicate PR (#1605): still open and unchanged (#1605 head 1e2af29, last commit 2026-11-17 12:10Z, no author reply since our note). Note stands: #1605 keeps #1598 until 2026-11-20.
  2. Test does not compare with a real create: not fixed. tests/test_create_template_kb_schema.py::test_create_template_with_software_kb_matches_create_fields (line ~34-52) still asserts a hand-listed set of keys and never runs a real create -k proj -t backlog_item --title x. The name says "matches create" but nothing compares them.
  3. --allow-undeclared parity: not fixed. pyrite/services/kb_service.py template_frontmatter still skips the refusal whenever allow_undeclared is true, with no check of validation.enforce (rule known_type) that the real create applies. No test passes --allow-undeclared to both commands.
  4. Mapped type: not fixed. No test uses a plugin-mapped type (e.g. event in a journalism-investigation KB, stored as investigation_event).

The only change since the last review is commit 22a16a3 (a refactor of fence/output handling); it does not touch these items.

New blocking findings: none beyond the items above.

Non-blocking:

  • pyrite/cli/entry_commands.py (template branch): a one-line comment saying the non--k skeleton is deliberately separate would help the next reader (asked last time, not added).
  • A one-line test for an unknown -k would pin the KB-not-found error.

Recommendation: request changes (items 2..4); #1605 lands #1598 unless it has no answer by 2026-11-20, in which case #1657 lands with #1605 credited.

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

Labels

state: needs-author Changes requested on the current head: the next move is the author's

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create --template ignores the KB: a backlog_item skeleton shows none of the fields a create writes

2 participants