-
Notifications
You must be signed in to change notification settings - Fork 45
feat(cli): vouch new <kind> — scaffold a typed page/entity proposal (closes #330) #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
e11734937-beep
wants to merge
2
commits into
vouchdev:main
Choose a base branch
from
e11734937-beep:feat/vouch-new-scaffold
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+309
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| """``vouch new <kind>`` — scaffold a typed page/entity proposal (issue #330). | ||
|
|
||
| The scaffold reads the page-kind registry (or ``EntityType``) for the kind, | ||
| stubs every required field, and files a *pending* proposal through the normal | ||
| review gate. It reuses ``propose_page`` / ``propose_entity`` verbatim, so it | ||
| never writes an approved artifact and never weakens validation: an unfilled | ||
| required field is flagged the same way any other proposal is. ``--dry-run`` | ||
| shows the stubbed shape (and the missing-field list) without filing anything. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| import yaml | ||
| from click.testing import CliRunner | ||
|
|
||
| from vouch.cli import cli | ||
| from vouch.models import ProposalKind, ProposalStatus | ||
| from vouch.storage import KBStore | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def store(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> KBStore: | ||
| s = KBStore.init(tmp_path) | ||
| monkeypatch.chdir(s.root) | ||
| return s | ||
|
|
||
|
|
||
| def _declare_kind(store: KBStore, name: str, **spec: Any) -> None: | ||
| """Write a ``config.yaml`` ``page_kinds.<name>`` entry for the test kb.""" | ||
| cfg = store.kb_dir / "config.yaml" | ||
| data = yaml.safe_load(cfg.read_text(encoding="utf-8")) if cfg.exists() else {} | ||
| data = data or {} | ||
| data.setdefault("page_kinds", {})[name] = spec | ||
| cfg.write_text(yaml.safe_dump(data), encoding="utf-8") | ||
|
|
||
|
|
||
| def test_page_scaffold_creates_pending_with_required_fields(store: KBStore) -> None: | ||
| _declare_kind(store, "decision-record", required_fields=["status", "owner"]) | ||
| r = CliRunner().invoke( | ||
| cli, | ||
| [ | ||
| "new", "decision-record", "--title", "pick db", | ||
| "--field", "status=open", "--field", "owner=alice", | ||
| ], | ||
| ) | ||
| assert r.exit_code == 0, r.output | ||
| pr = store.get_proposal(r.output.strip()) | ||
| assert pr.status == ProposalStatus.PENDING | ||
| assert pr.kind == ProposalKind.PAGE | ||
| md = pr.payload["metadata"] | ||
| assert md["status"] == "open" | ||
| assert md["owner"] == "alice" | ||
|
|
||
|
|
||
| def test_dry_run_stubs_required_fields_and_files_nothing(store: KBStore) -> None: | ||
| _declare_kind(store, "decision-record", required_fields=["status", "owner"]) | ||
| before = len(store.list_proposals()) | ||
| r = CliRunner().invoke( | ||
| cli, | ||
| ["new", "decision-record", "--title", "x", "--field", "status=open", "--dry-run"], | ||
| ) | ||
| assert r.exit_code == 0, r.output | ||
| # every required field is stubbed into the draft; the unfilled one is listed. | ||
| assert "status" in r.output and "owner" in r.output | ||
| assert "missing required" in r.output | ||
| assert len(store.list_proposals()) == before # nothing filed | ||
|
|
||
|
|
||
| def test_unfilled_required_field_is_flagged(store: KBStore) -> None: | ||
| # propose_page re-validates, so an empty required field is flagged, not | ||
| # silently written — the scaffold never weakens validation. | ||
| _declare_kind(store, "decision-record", required_fields=["status"]) | ||
| r = CliRunner().invoke(cli, ["new", "decision-record", "--title", "x"]) | ||
| assert r.exit_code != 0 | ||
| assert "Traceback" not in r.output | ||
| assert "status" in r.output | ||
|
|
||
|
|
||
| def test_field_is_parsed_as_yaml(store: KBStore) -> None: | ||
| _declare_kind(store, "meeting", required_fields=["attendees"]) | ||
| r = CliRunner().invoke( | ||
| cli, ["new", "meeting", "--title", "sync", "--field", "attendees=[a, b]"] | ||
| ) | ||
| assert r.exit_code == 0, r.output | ||
| pr = store.get_proposal(r.output.strip()) | ||
| assert pr.payload["metadata"]["attendees"] == ["a", "b"] | ||
|
|
||
|
|
||
| def test_entity_scaffold_routes_to_propose_entity(store: KBStore) -> None: | ||
| r = CliRunner().invoke(cli, ["new", "person", "--name", "alice-example"]) | ||
| assert r.exit_code == 0, r.output | ||
| pr = store.get_proposal(r.output.strip()) | ||
| assert pr.kind == ProposalKind.ENTITY | ||
| assert pr.status == ProposalStatus.PENDING | ||
| assert pr.payload["name"] == "alice-example" | ||
|
|
||
|
|
||
| def test_collision_defaults_to_page_and_entity_flag_forces_entity(store: KBStore) -> None: | ||
| # ``decision`` is both a built-in page type and an EntityType member. | ||
| r_page = CliRunner().invoke(cli, ["new", "decision", "--title", "d1"]) | ||
| assert r_page.exit_code == 0, r_page.output | ||
| assert store.get_proposal(r_page.output.strip()).kind == ProposalKind.PAGE | ||
|
|
||
| r_ent = CliRunner().invoke(cli, ["new", "decision", "--entity", "--name", "d-ent"]) | ||
| assert r_ent.exit_code == 0, r_ent.output | ||
| assert store.get_proposal(r_ent.output.strip()).kind == ProposalKind.ENTITY | ||
|
|
||
|
|
||
| def test_unknown_kind_errors_with_known_list(store: KBStore) -> None: | ||
| r = CliRunner().invoke(cli, ["new", "no-such-kind", "--title", "x"]) | ||
| assert r.exit_code != 0 | ||
| assert "unknown kind" in r.output | ||
|
|
||
|
|
||
| def test_scaffold_only_files_a_pending_proposal(store: KBStore) -> None: | ||
| r = CliRunner().invoke(cli, ["new", "concept", "--title", "graphs"]) | ||
| assert r.exit_code == 0, r.output | ||
| pid = r.output.strip() | ||
| assert store.get_proposal(pid).status == ProposalStatus.PENDING | ||
| pending_ids = [p.id for p in store.list_proposals(ProposalStatus.PENDING)] | ||
| assert pid in pending_ids |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.