Skip to content

fix(cli): create --template shows the fields a create writes in a KB (#1598) - #1605

Open
swastiktawate wants to merge 1 commit into
pyrite-wiki:devfrom
swastiktawate:fix-1598-create-template-kb-fields
Open

swastiktawate wants to merge 1 commit into
pyrite-wiki:devfrom
swastiktawate:fix-1598-create-template-kb-fields

Conversation

@swastiktawate

Copy link
Copy Markdown
Contributor

Fixes #1598.

pyrite create --template built its skeleton from the core types only, so it ignored the KB named with -k: a backlog_item skeleton had none of the fields a real create writes, and a type the KB does not declare was not refused.

With -k, the skeleton now reads the same place a create does. KBService.create_template_fields builds the entry the way _prepare builds one (_with_declared_fields + build_entry) and reads its declared frontmatter, so the skeleton shows the fields a create of that type in that KB would write, with their defaults. An undeclared type is refused with the same error a create gives (UNDECLARED_TYPE), unless --allow-undeclared is passed. A -k that names no KB is refused (KB_NOT_FOUND). Without -k, the skeleton is unchanged.

Verified:

  • create -k proj -t backlog_item --template now shows importance 5, kind, status proposed, priority medium, rank 0, effort "", assignee "", matching the file a real create writes.
  • A field a KB adds to a core type in kb.yaml appears in that KB's note skeleton, at its declared default.
  • create -k proj -t nosuch --template refuses with UNDECLARED_TYPE, the same error and message as a real create.
  • create -t person --template without -k prints today's skeleton.

Tests: new tests/test_create_template_kb.py (6 tests), all passing. Also ran tests/test_cli_commands.py, tests/test_cli_outcome_write_path.py, tests/test_help_texts_render.py, the create-related suites, and extensions/software-kb/tests/, all passing. One pre-existing failure in test_default_output_is_the_result.py (an embed test failing on a missing vec_entry table) also fails on the pristine tree.

…yrite-wiki#1598)

The template skeleton came from the core types only, so a backlog_item
skeleton had none of the fields a real create writes, and a type the KB
does not declare was not refused. With -k, the skeleton now reads the
same place a create does: KBService.create_template_fields builds the
entry the way _prepare builds one and reads its declared frontmatter.
Without -k, the skeleton is unchanged.

@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.

Automated review by the maintainer's conductor agent, of head 1e2af296: a cold read of the diff by a separate reader (read-only), then each item below re-run by the conductor in its own throwaway KBs. This touches pyrite/services/kb_service.py and what a CLI command answers, so the maintainer merges it.

Thank you: this does what the groom on #1598 asked. The refusals come from the same code a create uses (the JSON envelopes and exit codes are identical for an undeclared type and for an unknown -k), --template writes nothing (file hashes unchanged), the backlog_item skeleton equals a real create's frontmatter, and the output without -k is the old code unchanged. Three things stand between this and a merge. Items 2 and 3 are regimes the groom did not name; that gap is ours, not yours.

1. tests/test_create_template_kb.py: CI is red on tests/test_production_wiring_guard.py::test_no_file_adds_a_site ("3 load_config site(s), baseline 0"; ran it). The three sites are patch("pyrite.config.load_config") in the software_kb fixture (line 37) and the two patches in _patch_config (lines 59-60). Delete software_kb, _patch_config and init_app, and use the cli_world fixture from tests/conftest.py, which runs the real load_config against a throwaway config:

def test_template_backlog_item_matches_real_create(cli_world, tmp_path):
    world = cli_world()
    assert world.cli("init", "--template", "software", "--path", str(tmp_path / "proj"),
                     "--name", "proj", "--no-examples").exit_code == 0
    world.cli("create", "-k", "proj", "-t", "backlog_item", "--title", "x")
    result = world.cli("create", "-k", "proj", "-t", "backlog_item", "--template", "--format", "json")
    # compare result's frontmatter with the file the create wrote

2. KBService.create_template_fields and test_template_undeclared_type_allowed_with_flag: a create that is refused still gets a skeleton. In a KB from pyrite init --template software (ran both):

  • create -k proj -t nosuch --template --allow-undeclared prints a skeleton, exit 0;
  • create -k proj -t nosuch --title nz --allow-undeclared is refused, exit 1, rule known_type (that KB has validation.enforce on).

The test pins the first and never runs the second. Make the skeleton answer what the create answers here, and rewrite the test to run the real create with the same flags and compare the two outcomes.

3. KBService.create_template_fields: the type is not resolved the way _prepare resolves it. _prepare calls _resolve_entry_type (line 1594) and _refuse_undeclared_mapping_target; the new method skips both. In a KB with kb_type: journalism-investigation and no types: in kb.yaml (ran both):

  • create -k inv2 -t event --template prints type: event with location and actors;
  • create -k inv2 -t event --title e1 -d 2024-01-01 writes type: investigation_event with verification_status: unverified, and no location or actors.

Resolve the type with the same two calls before building, put the resolved type in the skeleton, and add that KB as a test case. Please do not restructure _prepare itself: #1601 is changing that function now, so keep your edit to the new method and merge dev after #1601 lands (one small conflict at most).

Smaller, same push if you can:

  • One parametrised test over (KB, type, flags) that runs a real create --title x, reads the file and compares its frontmatter with the skeleton (apart from id, title, tags), or compares the two error envelopes when both refuse. Today only backlog_item is compared with a real create; the severity == "low" case is a value written by hand. That one test would have caught items 2 and 3.
  • pyrite/cli/entry_commands.py:364: assert kb_config is not None disappears under python -O; use svc.require_kb(kb_name).
  • entry_commands.py:378: --template --importance 42 prints importance: 42 (ran). Since #1570 merged today, a create on dev refuses importance outside 1 to 10; once you merge dev, either refuse it here the same way or leave the default.
  • The fragment's first sentence becomes true once item 3 is in.

Not caused by this change: tests/test_mcp_dispatch_off_the_loop.py::test_one_slow_call_does_not_hold_up_another_caller ("the fast call waited 2.38s") is a timing test; the diff touches no MCP or server code. A re-run will clear it.

Not checked: a read-only KB (a create refuses there; the skeleton is printed; say which you intend in the PR body), and hooks that add fields at save.

Recommendation: merge after items 1 to 3.

@markramm markramm added the state: needs-rebase Conflicts with dev or CI is red label Nov 17, 2026
@markramm markramm added state: needs-author Changes requested on the current head: the next move is the author's state: needs-rebase Conflicts with dev or CI is red and removed state: needs-rebase Conflicts with dev or CI is red state: needs-author Changes requested on the current head: the next move is the author's labels Nov 17, 2026
@markramm

Copy link
Copy Markdown
Collaborator

A second PR for #1598 is open: #1657. #1605 was first, so it keeps the issue. If this PR has no answer to its review by 2026-11-20, #1657 becomes the one that lands, and this PR is credited for its approach. The asks in this PR's review still apply.

@markramm markramm added state: needs-rebase Conflicts with dev or CI is red state: needs-author Changes requested on the current head: the next move is the author's and removed state: needs-author Changes requested on the current head: the next move is the author's state: needs-rebase Conflicts with dev or CI is red labels Nov 17, 2026
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