@canonical/design-system 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/PULL_REQUEST_TEMPLATE.md +15 -6
- package/.github/workflows/ci.yml +14 -4
- package/.github/workflows/sync-coda-manual.yml +13 -0
- package/.github/workflows/sync-coda-scheduled.yml +9 -0
- package/.github/workflows/sync-coda.yml +65 -1
- package/README.md +132 -79
- package/bun.lock +51 -12
- package/data/apps/component/file_tree.ttl +6 -1
- package/data/apps/component/key_value_pair.ttl +5 -1
- package/data/apps/component/navigation.ttl +5 -1
- package/data/apps/component/notification.ttl +5 -1
- package/data/apps/component/side_navigation.ttl +11 -0
- package/data/apps/component/skeleton_loading.ttl +5 -1
- package/data/apps/component/status_bar.ttl +5 -1
- package/data/apps/component/toolbar.ttl +5 -1
- package/data/apps/group/key_value_pairs.ttl +11 -0
- package/data/apps/group/notifications.ttl +5 -1
- package/data/apps/layout/application_layout.ttl +4 -0
- package/data/apps/layout/content_layout.ttl +11 -1
- package/data/apps/layout/empty_layout.ttl +5 -1
- package/data/apps/layout/list_page_layout.ttl +5 -1
- package/data/apps/layout/settings_page_layout.ttl +5 -1
- package/data/apps/layout/view_layout.ttl +4 -0
- package/data/apps/pattern/action_bar.ttl +11 -0
- package/data/apps/pattern/code_diff.ttl +5 -1
- package/data/apps/pattern/data_table.ttl +205 -2
- package/data/apps/pattern/destructive_modal.ttl +5 -1
- package/data/apps/pattern/drawer.ttl +12 -0
- package/data/apps/pattern/keyboard_shortcuts.ttl +5 -1
- package/data/apps/pattern/notification_center.ttl +19 -1
- package/data/apps/pattern/side_panel.ttl +6 -1
- package/data/apps/pattern/sidepanel_stacked.ttl +5 -1
- package/data/apps/subcomponent/data_table-action_bar.ttl +27 -0
- package/data/apps/subcomponent/data_table-body_cell.ttl +106 -0
- package/data/apps/subcomponent/data_table-group_header_row.ttl +58 -0
- package/data/apps/subcomponent/data_table-header_cell.ttl +73 -0
- package/data/apps/subcomponent/data_table-pagination_bar.ttl +44 -0
- package/data/apps/subcomponent/data_table-persistent_selection.ttl +50 -0
- package/data/apps/subcomponent/data_table-settings_menu.ttl +63 -0
- package/data/apps/subcomponent/drawer-content.ttl +12 -0
- package/data/apps/subcomponent/drawer-footer.ttl +12 -0
- package/data/apps/subcomponent/drawer-header.ttl +12 -0
- package/data/apps/subcomponent/file_tree-node.ttl +5 -1
- package/data/apps/subcomponent/log.ttl +11 -0
- package/data/apps/subcomponent/side_panel-content.ttl +12 -0
- package/data/apps/subcomponent/side_panel-footer.ttl +12 -0
- package/data/apps/subcomponent/side_panel-header.ttl +12 -0
- package/data/apps_anbox/component/theme_switcher.ttl +10 -0
- package/data/apps_anbox/pattern/side_menu.ttl +11 -1
- package/data/apps_debcrafters/component/example.ttl +10 -0
- package/data/apps_debcrafters/component/my_fancy_component.ttl +11 -0
- package/data/apps_debcrafters.ttl +4 -0
- package/data/apps_juju/pattern/single_select_multi_layered.ttl +4 -1
- package/data/apps_landscape/component/password_constraints.ttl +4 -1
- package/data/apps_landscape/component/truncated_cell.ttl +38 -0
- package/data/apps_launchpad/component/avatar.ttl +31 -0
- package/data/apps_launchpad/component/badge.ttl +11 -9
- package/data/apps_launchpad/component/breadcrumbs.ttl +5 -2
- package/data/apps_launchpad/component/button.ttl +11 -9
- package/data/apps_launchpad/component/checkbox_input.ttl +31 -0
- package/data/apps_launchpad/component/chip.ttl +11 -8
- package/data/apps_launchpad/component/combobox.ttl +16 -11
- package/data/apps_launchpad/component/description_list.ttl +8 -3
- package/data/apps_launchpad/component/drawer.ttl +38 -0
- package/data/apps_launchpad/component/log.ttl +58 -0
- package/data/apps_launchpad/component/modal.ttl +44 -0
- package/data/apps_launchpad/component/radio_input.ttl +37 -0
- package/data/apps_launchpad/component/select_input.ttl +38 -0
- package/data/apps_launchpad/component/switch.ttl +8 -4
- package/data/apps_launchpad/component/text_input.ttl +13 -9
- package/data/apps_launchpad/component/textarea_input.ttl +39 -0
- package/data/apps_launchpad/component/tooltip.ttl +12 -8
- package/data/apps_launchpad/subcomponent/combobox-checkbox_option.ttl +11 -9
- package/data/apps_launchpad/subcomponent/combobox-footer.ttl +8 -3
- package/data/apps_launchpad/subcomponent/combobox-group.ttl +10 -6
- package/data/apps_launchpad/subcomponent/combobox-helper.ttl +11 -6
- package/data/apps_launchpad/subcomponent/combobox-loading.ttl +9 -3
- package/data/apps_launchpad/subcomponent/combobox-no_results.ttl +8 -3
- package/data/apps_launchpad/subcomponent/combobox-radio_option.ttl +12 -10
- package/data/apps_launchpad/subcomponent/combobox-search.ttl +10 -6
- package/data/apps_launchpad/subcomponent/description_list-item.ttl +8 -3
- package/data/apps_launchpad/subcomponent/log-line.ttl +38 -0
- package/data/apps_launchpad/subcomponent/modal-content-body.ttl +18 -0
- package/data/apps_launchpad/subcomponent/modal-content-footer.ttl +18 -0
- package/data/apps_launchpad/subcomponent/modal-content-header-close_button.ttl +11 -0
- package/data/apps_launchpad/subcomponent/modal-content-header.ttl +19 -0
- package/data/apps_launchpad/subcomponent/modal-content.ttl +20 -0
- package/data/apps_launchpad/subcomponent/side_panel-content-body.ttl +11 -0
- package/data/apps_launchpad/subcomponent/side_panel-content-footer.ttl +11 -0
- package/data/apps_launchpad/subcomponent/side_panel-content-header-close_button.ttl +11 -0
- package/data/apps_launchpad/subcomponent/side_panel-content-header.ttl +12 -0
- package/data/apps_launchpad/subcomponent/side_panel-content.ttl +12 -0
- package/data/apps_lxd/component/back_link.ttl +29 -0
- package/data/apps_lxd/component/code_snippet_with_copy_button.ttl +54 -0
- package/data/apps_lxd/component/confirmation_checkbox.ttl +19 -3
- package/data/apps_lxd/component/doc_link.ttl +45 -0
- package/data/apps_lxd/component/meter.ttl +37 -0
- package/data/apps_lxd/component/output_field.ttl +48 -0
- package/data/apps_lxd/component/rename_header.ttl +74 -0
- package/data/apps_lxd/component/tab_links.ttl +35 -0
- package/data/apps_lxd/subcomponent/copy_to_clipboard.ttl +39 -0
- package/data/apps_lxd/view/network_topology.ttl +16 -2
- package/data/apps_notary.ttl +4 -0
- package/data/apps_portal/component/badge.ttl +3 -0
- package/data/apps_portal/component/credit_card_input.ttl +10 -0
- package/data/apps_portal/component/key_value_pair.ttl +10 -0
- package/data/apps_portal/pattern/purchase_summary.ttl +10 -0
- package/data/apps_portal/subcomponent/read_only_modal.ttl +10 -0
- package/data/apps_workplaceengineering/component/label-highlight.ttl +18 -0
- package/data/apps_workplaceengineering/component/rule.ttl +11 -0
- package/data/apps_workplaceengineering/component/skip_link.ttl +10 -0
- package/data/apps_workplaceengineering/component/theme_switcher.ttl +11 -0
- package/data/apps_workplaceengineering/pattern/callout_numbers_card.ttl +11 -0
- package/data/apps_workplaceengineering/pattern/event_timeline.ttl +11 -0
- package/data/apps_workplaceengineering/pattern/group_card.ttl +11 -0
- package/data/apps_workplaceengineering/pattern/travel_provider_card.ttl +12 -0
- package/data/apps_workplaceengineering.ttl +4 -0
- package/data/documentation/layout/documentation_layout.ttl +5 -1
- package/data/documentation/pattern/library_side_navigation.ttl +6 -2
- package/data/global/component/accordion.ttl +61 -2
- package/data/global/component/announcement.ttl +12 -2
- package/data/global/component/avatar.ttl +11 -0
- package/data/global/component/badge.ttl +42 -1
- package/data/global/component/breadcrumbs.ttl +18 -2
- package/data/global/component/button.ttl +36 -8
- package/data/global/component/button_link.ttl +5 -1
- package/data/global/component/card.ttl +33 -2
- package/data/global/component/checkbox_field.ttl +11 -0
- package/data/global/component/chip.ttl +74 -2
- package/data/global/component/choices_field.ttl +11 -0
- package/data/global/component/code_snippet-content.ttl +6 -2
- package/data/global/component/code_snippet-header.ttl +6 -2
- package/data/global/component/code_snippet.ttl +13 -2
- package/data/global/component/color_field.ttl +11 -0
- package/data/global/component/combobox_field.ttl +11 -0
- package/data/global/component/contextual_menu.ttl +22 -2
- package/data/global/component/data_tooltip.ttl +84 -0
- package/data/global/component/date_field.ttl +11 -0
- package/data/global/component/date_time_field.ttl +11 -0
- package/data/global/component/dropdown_button.ttl +18 -0
- package/data/global/component/file_upload_field.ttl +11 -0
- package/data/global/component/heading.ttl +5 -1
- package/data/global/component/hidden_field.ttl +11 -0
- package/data/global/component/icon.ttl +6 -2
- package/data/global/component/icon_in_container.ttl +5 -1
- package/data/global/component/inline_code.ttl +11 -0
- package/data/global/component/keyboard_key.ttl +7 -3
- package/data/global/component/markdown_field.ttl +11 -0
- package/data/global/component/mode_switcher.ttl +11 -0
- package/data/global/component/month_field.ttl +11 -0
- package/data/global/component/notification_inline.ttl +5 -1
- package/data/global/component/notification_toast.ttl +5 -1
- package/data/global/component/number_field.ttl +11 -0
- package/data/global/component/pagination.ttl +6 -2
- package/data/global/component/password_field.ttl +11 -0
- package/data/global/component/phone_field.ttl +11 -0
- package/data/global/component/popover.ttl +5 -1
- package/data/global/component/range_field.ttl +11 -0
- package/data/global/component/rating_field.ttl +11 -0
- package/data/global/component/relative_timestamp.ttl +10 -0
- package/data/global/component/rich_choices_field.ttl +11 -0
- package/data/global/component/rich_text_field.ttl +11 -0
- package/data/global/component/search_field.ttl +11 -0
- package/data/global/component/segmented_control_field.ttl +11 -0
- package/data/global/component/select_field.ttl +11 -0
- package/data/global/component/switch_field.ttl +11 -0
- package/data/global/component/table.ttl +7 -2
- package/data/global/component/tabs.ttl +7 -3
- package/data/global/component/tag.ttl +18 -0
- package/data/global/component/text_field.ttl +11 -0
- package/data/global/component/textarea_field.ttl +11 -0
- package/data/global/component/tile.ttl +24 -3
- package/data/global/component/time_field.ttl +11 -0
- package/data/global/component/timestamp.ttl +10 -0
- package/data/global/component/tooltip.ttl +75 -56
- package/data/global/component/tooltip_wrapper.ttl +81 -0
- package/data/global/group/buttons.ttl +12 -1
- package/data/global/group/cards.ttl +9 -1
- package/data/global/group/code_snippets.ttl +5 -1
- package/data/global/group/keyboard_keys.ttl +7 -3
- package/data/global/group/tiles.ttl +5 -1
- package/data/global/layout/error_layout.ttl +5 -1
- package/data/global/layout/form_layout.ttl +5 -1
- package/data/global/layout/identity_page_form.ttl +5 -1
- package/data/global/modifier/dark.ttl +1 -1
- package/data/global/modifier/information.ttl +1 -1
- package/data/global/modifier/light.ttl +1 -1
- package/data/global/modifier/modal.ttl +6 -0
- package/data/global/modifier/surface1.ttl +6 -0
- package/data/global/modifier/surface2.ttl +6 -0
- package/data/global/modifier/surface3.ttl +6 -0
- package/data/global/modifier_family/_emphasis.ttl +2 -1
- package/data/global/modifier_family/_other.ttl +2 -1
- package/data/global/modifier_family/anticipation.ttl +2 -1
- package/data/global/modifier_family/criticality.ttl +2 -1
- package/data/global/modifier_family/density.ttl +2 -1
- package/data/global/modifier_family/importance.ttl +2 -1
- package/data/global/modifier_family/lifecycle.ttl +2 -1
- package/data/global/modifier_family/mode.ttl +7 -0
- package/data/global/modifier_family/release.ttl +2 -1
- package/data/global/modifier_family/surface.ttl +7 -0
- package/data/global/pattern/description_list.ttl +11 -0
- package/data/global/pattern/field.ttl +11 -0
- package/data/global/pattern/form.ttl +10 -0
- package/data/global/pattern/form_login.ttl +10 -0
- package/data/global/pattern/info_table.ttl +5 -1
- package/data/global/pattern/modal.ttl +7 -2
- package/data/global/pattern/navigation.ttl +5 -1
- package/data/global/pattern/stepper.ttl +5 -1
- package/data/global/pattern/table_of_contents.ttl +5 -1
- package/data/global/pattern/timeline.ttl +33 -2
- package/data/global/subcomponent/accordion-item.ttl +10 -5
- package/data/global/subcomponent/breadcrumbs-item.ttl +7 -3
- package/data/global/subcomponent/card-content.ttl +8 -3
- package/data/global/subcomponent/card-footer.ttl +12 -0
- package/data/global/subcomponent/card-header.ttl +8 -3
- package/data/global/subcomponent/card-image.ttl +8 -3
- package/data/global/subcomponent/card-thumbnail.ttl +6 -1
- package/data/global/subcomponent/chart_legend.ttl +11 -0
- package/data/global/subcomponent/chart_legend_item.ttl +11 -0
- package/data/global/subcomponent/checkbox_input.ttl +11 -0
- package/data/global/subcomponent/color_input.ttl +11 -0
- package/data/global/subcomponent/combobox_input.ttl +11 -0
- package/data/global/subcomponent/date_input.ttl +11 -0
- package/data/global/subcomponent/date_time_input.ttl +11 -0
- package/data/global/subcomponent/field-description.ttl +11 -0
- package/data/global/subcomponent/field-label.ttl +11 -0
- package/data/global/subcomponent/file_upload_input.ttl +11 -0
- package/data/global/subcomponent/hidden_input.ttl +11 -0
- package/data/global/subcomponent/kvp_container.ttl +11 -0
- package/data/global/subcomponent/kvpitem_base.ttl +11 -0
- package/data/global/subcomponent/markdown_input.ttl +11 -0
- package/data/global/subcomponent/modal-content.ttl +5 -1
- package/data/global/subcomponent/modal-footer.ttl +5 -1
- package/data/global/subcomponent/modal-header.ttl +5 -1
- package/data/global/subcomponent/month_input.ttl +11 -0
- package/data/global/subcomponent/number_input.ttl +11 -0
- package/data/global/subcomponent/password_input.ttl +11 -0
- package/data/global/subcomponent/phone_input.ttl +11 -0
- package/data/global/subcomponent/radio_input.ttl +11 -0
- package/data/global/subcomponent/range_input.ttl +11 -0
- package/data/global/subcomponent/rating_input.ttl +11 -0
- package/data/global/subcomponent/rich_text_input.ttl +11 -0
- package/data/global/subcomponent/search_input.ttl +26 -0
- package/data/global/subcomponent/segmented_control_input.ttl +11 -0
- package/data/global/subcomponent/select_input.ttl +11 -0
- package/data/global/subcomponent/spin_button.ttl +11 -0
- package/data/global/subcomponent/spinner.ttl +7 -3
- package/data/global/subcomponent/switch_input.ttl +11 -0
- package/data/global/subcomponent/table-cell.ttl +5 -1
- package/data/global/subcomponent/table-row.ttl +5 -1
- package/data/global/subcomponent/text_input.ttl +11 -0
- package/data/global/subcomponent/textarea_input.ttl +33 -0
- package/data/global/subcomponent/tile-content.ttl +7 -3
- package/data/global/subcomponent/tile-header.ttl +13 -4
- package/data/global/subcomponent/time_input.ttl +11 -0
- package/data/global/subcomponent/timeline-content.ttl +7 -2
- package/data/global/subcomponent/timeline-event.ttl +8 -3
- package/data/global/subcomponent/timeline-expansion_indicator.ttl +6 -1
- package/data/global/subcomponent/timeline-header.ttl +6 -1
- package/data/global/variant/tooltip_dense.ttl +14 -0
- package/data/global/view/settings_view.ttl +5 -1
- package/data/sites/component/blog_card.ttl +11 -0
- package/data/sites/component/quote.ttl +11 -0
- package/data/sites/component/rule.ttl +11 -0
- package/data/sites/component/section.ttl +11 -0
- package/data/sites/group/blog_cards.ttl +11 -0
- package/data/sites/group/xblog_elements.ttl +10 -0
- package/data/sites/layout/blog_page_layout.ttl +11 -0
- package/data/{site → sites}/layout/case_study_layout.ttl +6 -2
- package/data/sites/layout/site_layout.ttl +11 -0
- package/data/sites/pattern/hero-github.ttl +11 -0
- package/data/sites/pattern/hero.ttl +11 -0
- package/data/sites/pattern/info_table.ttl +11 -0
- package/data/sites/pattern/pricing_section.ttl +11 -0
- package/data/sites/pattern/pricing_table.ttl +11 -0
- package/data/sites/pattern/read_more_section.ttl +11 -0
- package/data/sites/pattern/skip_link.ttl +11 -0
- package/data/{site.ttl → sites.ttl} +2 -2
- package/data/sites_webcomponentsprototype/component/blog_cards.ttl +4 -1
- package/data/sites_webcomponentsprototype/component/ctablock.ttl +4 -1
- package/data/sites_webcomponentsprototype/component/list.ttl +5 -2
- package/data/sites_webcomponentsprototype/component/tabs.ttl +5 -2
- package/data/sites_webcomponentsprototype/layout/site_layout.ttl +3 -0
- package/data/sites_webcomponentsprototype/pattern/basic_section.ttl +4 -1
- package/data/sites_webcomponentsprototype/pattern/blog_section.ttl +4 -1
- package/data/sites_webcomponentsprototype/pattern/ctasection.ttl +5 -2
- package/data/sites_webcomponentsprototype/pattern/equal_heights.ttl +5 -2
- package/data/sites_webcomponentsprototype/pattern/hero.ttl +5 -2
- package/data/sites_webcomponentsprototype/pattern/logo_section.ttl +5 -2
- package/data/sites_webcomponentsprototype/pattern/quote_wrapper.ttl +5 -2
- package/data/sites_webcomponentsprototype/pattern/tiered_list.ttl +5 -2
- package/data/tag/allgood.ttl +7 -0
- package/data/tag/beta.ttl +7 -0
- package/data/tag/candidate.ttl +7 -0
- package/data/tag/devbatch1.ttl +7 -0
- package/data/tag/devbatch2.ttl +7 -0
- package/data/tag/devexternal.ttl +7 -0
- package/data/tag/devreactapproved.ttl +7 -0
- package/data/tag/devreactbase.ttl +7 -0
- package/data/tag/devreactpreapproved.ttl +7 -0
- package/data/tag/devspecial.ttl +7 -0
- package/data/tag/devsveltedone.ttl +7 -0
- package/data/tag/devsveltein-progress.ttl +7 -0
- package/data/tag/divergent.ttl +7 -0
- package/data/tag/docscomplete.ttl +7 -0
- package/data/tag/draft.ttl +7 -0
- package/data/tag/edge.ttl +7 -0
- package/data/tag/global-docs-missing.ttl +7 -0
- package/data/tag/has-no-global-entry.ttl +7 -0
- package/data/tag/lpto-be-upstreamed.ttl +7 -0
- package/data/tag/lptriageblocked-reqs-design.ttl +7 -0
- package/data/tag/lptriageno-upstream.ttl +7 -0
- package/data/tag/lptriagereimplement-and-deprecate.ttl +7 -0
- package/data/tag/lptriagereimplement-and-keep.ttl +7 -0
- package/data/tag/lptriageupstream-and-deprecate.ttl +7 -0
- package/data/tag/minimal.ttl +7 -0
- package/data/tag/needsdefinition.ttl +7 -0
- package/data/tag/needsdiscussion.ttl +7 -0
- package/data/tag/needsdocumentation.ttl +7 -0
- package/data/tag/needsreview.ttl +7 -0
- package/data/tag/needstriage.ttl +7 -0
- package/data/tag/needsupdate.ttl +7 -0
- package/data/tag/notstarted.ttl +7 -0
- package/data/tag/specialadoption-docs.ttl +7 -0
- package/data/tag/stable.ttl +7 -0
- package/data/tag/stylesready.ttl +7 -0
- package/data/tag/triagedbacklog.ttl +7 -0
- package/data/tag/triagedrejected.ttl +7 -0
- package/data/tag/upstream-candidate.ttl +7 -0
- package/data/tag/upstream-compliant.ttl +7 -0
- package/data/tag/upstreamcandidate.ttl +7 -0
- package/data/tag/waiting-for-delta-review.ttl +7 -0
- package/data/tag/wpeinital-implementation.ttl +7 -0
- package/data/tag/wpetriageupstream-and-deprecate.ttl +6 -0
- package/data/tagcategory/channel.ttl +4 -0
- package/data/tagcategory/concept-status.ttl +4 -0
- package/data/tagcategory/concept-type.ttl +4 -0
- package/data/tagcategory/documentation-stage.ttl +4 -0
- package/data/tagcategory/implementation-status.ttl +4 -0
- package/data/tagcategory/lpupstream.ttl +4 -0
- package/data/tagcategory/review-status.ttl +4 -0
- package/data/tagcategory/tmp.ttl +4 -0
- package/definitions/ontology.ttl +133 -14
- package/examples/form-roster.target.json +550 -0
- package/package.json +5 -2
- package/skills/adoption-a1-styles/SKILL.md +115 -0
- package/skills/adoption-a2-components/SKILL.md +170 -0
- package/skills/adoption-a3-forms/SKILL.md +134 -0
- package/skills/anatomy-author/ANATOMY_DSL_SPEC.md +89 -106
- package/skills/anatomy-author/SKILL.md +318 -141
- package/skills/implement-component/SKILL.md +223 -0
- package/skills/specify-component/SKILL.md +195 -0
- package/skills/specify-pattern/SKILL.md +157 -0
- package/source.json +64 -2
- package/specs/README.md +17 -0
- package/src/cli.ts +23 -10
- package/src/commands/index.ts +1 -0
- package/src/commands/sync.tests.ts +430 -0
- package/src/commands/sync.ts +418 -0
- package/src/commands/transform.tests.ts +190 -5
- package/src/commands/transform.ts +163 -67
- package/src/constants.ts +1 -0
- package/src/providers/CodaProvider.tests.ts +94 -0
- package/src/providers/CodaProvider.ts +211 -1
- package/src/providers/detectSmartChips.tests.ts +42 -0
- package/src/providers/detectSmartChips.ts +60 -0
- package/src/scripts/checkDataDeletion.ts +68 -0
- package/src/scripts/evaluateDataDeletion.tests.ts +100 -0
- package/src/scripts/evaluateDataDeletion.ts +100 -0
- package/src/sync/constants.ts +52 -0
- package/src/sync/diffRoster.tests.ts +455 -0
- package/src/sync/diffRoster.ts +241 -0
- package/src/sync/loadTargetSpec.tests.ts +208 -0
- package/src/sync/loadTargetSpec.ts +139 -0
- package/src/sync/renderPlan.tests.ts +144 -0
- package/src/sync/renderPlan.ts +88 -0
- package/src/sync/snapshotTable.tests.ts +31 -0
- package/src/sync/snapshotTable.ts +20 -0
- package/src/sync/toLiveEntries.tests.ts +76 -0
- package/src/sync/toLiveEntries.ts +55 -0
- package/src/sync/types.ts +101 -0
- package/src/transform/collectDataMetrics.tests.ts +108 -0
- package/src/transform/collectDataMetrics.ts +114 -0
- package/src/transform/deltaGuards.tests.ts +136 -0
- package/src/transform/deltaGuards.ts +118 -0
- package/src/transform/expectedTables.tests.ts +99 -0
- package/src/transform/expectedTables.ts +34 -0
- package/src/transform/isValidReferenceUri.tests.ts +45 -0
- package/src/transform/isValidReferenceUri.ts +55 -0
- package/src/transform/materializeInverses.tests.ts +81 -0
- package/src/transform/materializeInverses.ts +78 -0
- package/src/transform/transform.tests.ts +22 -0
- package/src/transform/transform.ts +31 -3
- package/src/transform/transformRow.malformedRefs.tests.ts +127 -0
- package/src/transform/transformRow.tests.ts +82 -0
- package/src/transform/transformRow.ts +90 -7
- package/src/transform/types.ts +11 -0
- package/vitest.config.ts +29 -0
- package/data/apps/pattern/key_value_summary.ttl +0 -7
- package/data/apps_anbox/component/copy_to_clipboard.ttl +0 -7
- package/data/apps_launchpad/component/checkbox.ttl +0 -28
- package/data/apps_launchpad/component/radio.ttl +0 -34
- package/data/apps_launchpad/component/select.ttl +0 -34
- package/data/apps_launchpad/component/textarea.ttl +0 -35
- package/data/apps_launchpad/component/user_avatar.ttl +0 -25
- package/data/apps_lxd/component/copy_to_clipboard.ttl +0 -7
- package/data/apps_workplace/component/label-highlight.ttl +0 -7
- package/data/apps_workplace.ttl +0 -4
- package/data/apps_wpe.ttl +0 -4
- package/data/global/component/code.ttl +0 -7
- package/data/global/component/label.ttl +0 -14
- package/data/global/component/rich_text_editor.ttl +0 -7
- package/data/global/component/search_bar.ttl +0 -7
- package/data/global/component/theme_switcher.ttl +0 -7
- package/data/global/modifier/paper.ttl +0 -6
- package/data/global/pattern/dropdown_button.ttl +0 -7
- package/data/global/subcomponent/divider.ttl +0 -7
- package/data/global_form/component/checkbox_input.ttl +0 -7
- package/data/global_form/component/choices_input.ttl +0 -7
- package/data/global_form/component/combobox_input.ttl +0 -7
- package/data/global_form/component/custom_choices_input.ttl +0 -7
- package/data/global_form/component/datepicker_input.ttl +0 -7
- package/data/global_form/component/rating_input.ttl +0 -7
- package/data/global_form/component/rich_text_input.ttl +0 -7
- package/data/global_form/component/segmented_control_input.ttl +0 -7
- package/data/global_form/component/slider_input.ttl +0 -7
- package/data/global_form/component/switch_input.ttl +0 -7
- package/data/global_form/component/text_input.ttl +0 -7
- package/data/global_form/component/textarea_input.ttl +0 -7
- package/data/global_form/component/wysiwginput.ttl +0 -7
- package/data/global_form/pattern/field.ttl +0 -7
- package/data/global_form/pattern/form.ttl +0 -7
- package/data/global_form/subcomponent/field-description.ttl +0 -7
- package/data/global_form/subcomponent/field-label.ttl +0 -7
- package/data/global_form.ttl +0 -4
- package/data/site/component/blog_card.ttl +0 -7
- package/data/site/component/quote.ttl +0 -7
- package/data/site/component/rule.ttl +0 -7
- package/data/site/component/section.ttl +0 -7
- package/data/site/group/blog_cards.ttl +0 -7
- package/data/site/layout/blog_page_layout.ttl +0 -7
- package/data/site/layout/site_layout.ttl +0 -7
- package/data/site/pattern/hero-github.ttl +0 -7
- package/data/site/pattern/hero.ttl +0 -7
- package/data/site/pattern/info_table.ttl +0 -7
- package/data/site/pattern/pricing_section.ttl +0 -7
- package/data/site/pattern/pricing_table.ttl +0 -7
- package/data/site/pattern/read_more_section.ttl +0 -7
- package/data/site/pattern/skip_link.ttl +0 -7
- package/skills/component-specifier/SKILL.md +0 -412
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import loadTargetSpec from "./loadTargetSpec.js";
|
|
4
|
+
|
|
5
|
+
vi.mock("node:fs/promises");
|
|
6
|
+
|
|
7
|
+
const VALID_SPEC = {
|
|
8
|
+
scope: { documentId: "doc", table: "grid-x", tiers: ["Global"] },
|
|
9
|
+
entries: [],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Stub the file read with the given raw contents. */
|
|
13
|
+
function stubFile(raw: string): void {
|
|
14
|
+
vi.mocked(readFile).mockResolvedValue(raw);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A spec with the given single entry, sharing VALID_SPEC's scope. */
|
|
18
|
+
function specWithEntry(entry: unknown): string {
|
|
19
|
+
return JSON.stringify({ scope: VALID_SPEC.scope, entries: [entry] });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A well-formed `{ name, tier, type }` target shape. */
|
|
23
|
+
const VALID_TARGET = { name: "X", tier: "Global", type: "Component" };
|
|
24
|
+
|
|
25
|
+
describe("loadTargetSpec", () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
vi.mocked(readFile).mockReset();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("parses a valid spec from disk", async () => {
|
|
31
|
+
stubFile(JSON.stringify(VALID_SPEC));
|
|
32
|
+
const spec = await loadTargetSpec("spec.json");
|
|
33
|
+
expect(spec.scope.documentId).toBe("doc");
|
|
34
|
+
expect(spec.entries).toEqual([]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("rejects a non-object top level", async () => {
|
|
38
|
+
stubFile("42");
|
|
39
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
40
|
+
"target spec must be an object",
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("rejects a missing scope", async () => {
|
|
45
|
+
stubFile(JSON.stringify({ entries: [] }));
|
|
46
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
47
|
+
"must have a `scope` object",
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("rejects scope without string documentId/table", async () => {
|
|
52
|
+
stubFile(
|
|
53
|
+
JSON.stringify({
|
|
54
|
+
scope: { documentId: 1, table: "t", tiers: ["G"] },
|
|
55
|
+
entries: [],
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
59
|
+
"string `documentId` and `table`",
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("rejects an empty tiers array", async () => {
|
|
64
|
+
stubFile(
|
|
65
|
+
JSON.stringify({
|
|
66
|
+
scope: { documentId: "d", table: "t", tiers: [] },
|
|
67
|
+
entries: [],
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
71
|
+
"scope.tiers must be a non-empty array",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("rejects a missing entries array", async () => {
|
|
76
|
+
stubFile(
|
|
77
|
+
JSON.stringify({ scope: { documentId: "d", table: "t", tiers: ["G"] } }),
|
|
78
|
+
);
|
|
79
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
80
|
+
"must have an `entries` array",
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("propagates a JSON parse error", async () => {
|
|
85
|
+
stubFile("{ not json");
|
|
86
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("rejects a non-object entry (a1)", async () => {
|
|
90
|
+
stubFile(specWithEntry(42));
|
|
91
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
92
|
+
"entries[0] must be an object",
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("rejects an op that is not a legal kind (a2)", async () => {
|
|
97
|
+
stubFile(specWithEntry({ rowId: "i-1", target: VALID_TARGET, op: "frob" }));
|
|
98
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
99
|
+
'entries[0]: op must be one of [keep, move, rename, rename+retype, retype, merge, create] (got "frob")',
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("rejects a rowId that is neither string nor null (a3)", async () => {
|
|
104
|
+
stubFile(specWithEntry({ rowId: 7, target: VALID_TARGET, op: "rename" }));
|
|
105
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
106
|
+
"entries[0]: rowId must be a string or null",
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("rejects a target that is present but not a {name,tier,type} object (a4)", async () => {
|
|
111
|
+
stubFile(
|
|
112
|
+
specWithEntry({ rowId: "i-1", target: { name: "X" }, op: "rename" }),
|
|
113
|
+
);
|
|
114
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
115
|
+
"entries[0]: target must be a {name, tier, type} object or null",
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("rejects a create op with a null target (a5)", async () => {
|
|
120
|
+
stubFile(specWithEntry({ rowId: null, target: null, op: "create" }));
|
|
121
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
122
|
+
"entries[0]: create op must have a non-null target",
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("rejects a merge op whose target is not null (a6)", async () => {
|
|
127
|
+
stubFile(
|
|
128
|
+
specWithEntry({
|
|
129
|
+
rowId: "i-1",
|
|
130
|
+
target: VALID_TARGET,
|
|
131
|
+
op: "merge",
|
|
132
|
+
mergeInto: "i-2",
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
136
|
+
"entries[0]: merge op must have target null",
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("rejects a merge op with a non-string mergeInto (a7)", async () => {
|
|
141
|
+
stubFile(specWithEntry({ rowId: "i-1", target: null, op: "merge" }));
|
|
142
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
143
|
+
"entries[0]: merge op must have a string mergeInto",
|
|
144
|
+
);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("rejects a mutate op with a non-string rowId (a8)", async () => {
|
|
148
|
+
stubFile(
|
|
149
|
+
specWithEntry({ rowId: null, target: VALID_TARGET, op: "rename" }),
|
|
150
|
+
);
|
|
151
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
152
|
+
"entries[0]: rename op must have a string rowId",
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("rejects a mutate op with a null target (a9)", async () => {
|
|
157
|
+
// rowId is a string (passes a8) so the a9 null-target check is reached.
|
|
158
|
+
stubFile(specWithEntry({ rowId: "i-1", target: null, op: "move" }));
|
|
159
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
160
|
+
"entries[0]: move op must have a non-null target",
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("rejects a target that is a non-null primitive (isEntryShape non-object arm)", async () => {
|
|
165
|
+
// target is neither null nor an object → isEntryShape's typeof guard returns
|
|
166
|
+
// false on the non-object/null arm (distinct from a4's missing-field arm).
|
|
167
|
+
stubFile(specWithEntry({ rowId: "i-1", target: 42, op: "rename" }));
|
|
168
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
169
|
+
"entries[0]: target must be a {name, tier, type} object or null",
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("rejects a target whose tier/type are not strings (isEntryShape non-string arm)", async () => {
|
|
174
|
+
// target is an object with a string name but a non-string tier → isEntryShape
|
|
175
|
+
// returns false on the field-type arm (not the non-object arm of a4 above).
|
|
176
|
+
stubFile(
|
|
177
|
+
specWithEntry({
|
|
178
|
+
rowId: "i-1",
|
|
179
|
+
target: { name: "X", tier: 1, type: "Component" },
|
|
180
|
+
op: "rename",
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
await expect(loadTargetSpec("spec.json")).rejects.toThrow(
|
|
184
|
+
"entries[0]: target must be a {name, tier, type} object or null",
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("accepts a well-formed mutate entry (entry validation happy path)", async () => {
|
|
189
|
+
stubFile(specWithEntry({ rowId: "i-1", target: VALID_TARGET, op: "keep" }));
|
|
190
|
+
const spec = await loadTargetSpec("spec.json");
|
|
191
|
+
expect(spec.entries.at(0)?.op).toBe("keep");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("accepts a well-formed merge entry (merge happy path)", async () => {
|
|
195
|
+
// Exercises the not-taken (false) arms of the merge checks: target IS null
|
|
196
|
+
// and mergeInto IS a string, so neither a6 nor a7 fires.
|
|
197
|
+
stubFile(
|
|
198
|
+
specWithEntry({
|
|
199
|
+
rowId: "i-1",
|
|
200
|
+
target: null,
|
|
201
|
+
op: "merge",
|
|
202
|
+
mergeInto: "i-2",
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
205
|
+
const spec = await loadTargetSpec("spec.json");
|
|
206
|
+
expect(spec.entries.at(0)?.mergeInto).toBe("i-2");
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import type { OpKind, TargetSpec } from "./types.js";
|
|
3
|
+
|
|
4
|
+
/** The legal `op` kinds (mirrors {@link OpKind}). */
|
|
5
|
+
const OP_KINDS: readonly OpKind[] = [
|
|
6
|
+
"keep",
|
|
7
|
+
"move",
|
|
8
|
+
"rename",
|
|
9
|
+
"rename+retype",
|
|
10
|
+
"retype",
|
|
11
|
+
"merge",
|
|
12
|
+
"create",
|
|
13
|
+
] as const;
|
|
14
|
+
|
|
15
|
+
/** Op kinds that mutate an existing row in place (need a string `rowId` + non-null `target`). */
|
|
16
|
+
const MUTATE_KINDS: readonly OpKind[] = [
|
|
17
|
+
"keep",
|
|
18
|
+
"move",
|
|
19
|
+
"rename",
|
|
20
|
+
"rename+retype",
|
|
21
|
+
"retype",
|
|
22
|
+
] as const;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Load and validate a declarative target-spec file from disk.
|
|
26
|
+
*
|
|
27
|
+
* @param path - path to the target-spec JSON
|
|
28
|
+
* @returns the parsed, shape-checked target spec
|
|
29
|
+
* @throws if the file is missing, not JSON, or structurally invalid
|
|
30
|
+
* @note Impure — reads the file system.
|
|
31
|
+
*/
|
|
32
|
+
export default async function loadTargetSpec(
|
|
33
|
+
path: string,
|
|
34
|
+
): Promise<TargetSpec> {
|
|
35
|
+
const raw = await readFile(path, "utf-8");
|
|
36
|
+
const parsed: unknown = JSON.parse(raw);
|
|
37
|
+
assertValidSpec(parsed);
|
|
38
|
+
return parsed;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Narrow an unknown value to {@link TargetSpec}, throwing on the first structural fault.
|
|
43
|
+
*
|
|
44
|
+
* @param value - the parsed JSON
|
|
45
|
+
*/
|
|
46
|
+
function assertValidSpec(value: unknown): asserts value is TargetSpec {
|
|
47
|
+
if (typeof value !== "object" || value === null) {
|
|
48
|
+
throw new Error("target spec must be an object");
|
|
49
|
+
}
|
|
50
|
+
const spec = value as Record<string, unknown>;
|
|
51
|
+
|
|
52
|
+
const scope = spec.scope;
|
|
53
|
+
if (typeof scope !== "object" || scope === null) {
|
|
54
|
+
throw new Error("target spec must have a `scope` object");
|
|
55
|
+
}
|
|
56
|
+
const scopeObj = scope as Record<string, unknown>;
|
|
57
|
+
if (
|
|
58
|
+
typeof scopeObj.documentId !== "string" ||
|
|
59
|
+
typeof scopeObj.table !== "string"
|
|
60
|
+
) {
|
|
61
|
+
throw new Error("scope must have string `documentId` and `table`");
|
|
62
|
+
}
|
|
63
|
+
if (!Array.isArray(scopeObj.tiers) || scopeObj.tiers.length === 0) {
|
|
64
|
+
throw new Error("scope.tiers must be a non-empty array");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!Array.isArray(spec.entries)) {
|
|
68
|
+
throw new Error("target spec must have an `entries` array");
|
|
69
|
+
}
|
|
70
|
+
spec.entries.forEach(assertValidEntry);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Whether a value is a `{ name, tier, type }` shape with string fields. */
|
|
74
|
+
function isEntryShape(value: unknown): boolean {
|
|
75
|
+
if (typeof value !== "object" || value === null) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const v = value as Record<string, unknown>;
|
|
79
|
+
return (
|
|
80
|
+
typeof v.name === "string" &&
|
|
81
|
+
typeof v.tier === "string" &&
|
|
82
|
+
typeof v.type === "string"
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Validate one spec entry's structure (what is knowable from the JSON alone, per
|
|
88
|
+
* op kind). Semantic faults (op kind vs the actual live diff) are checked later
|
|
89
|
+
* in `diffRoster`; this layer fails fast on malformed authoring before any work.
|
|
90
|
+
*
|
|
91
|
+
* @param entry - the parsed entry
|
|
92
|
+
* @param i - its index (for error messages)
|
|
93
|
+
* @throws on the first structural fault
|
|
94
|
+
*/
|
|
95
|
+
function assertValidEntry(entry: unknown, i: number): void {
|
|
96
|
+
if (typeof entry !== "object" || entry === null) {
|
|
97
|
+
throw new Error(`entries[${i}] must be an object`);
|
|
98
|
+
}
|
|
99
|
+
const e = entry as Record<string, unknown>;
|
|
100
|
+
|
|
101
|
+
if (
|
|
102
|
+
typeof e.op !== "string" ||
|
|
103
|
+
!(OP_KINDS as readonly string[]).includes(e.op)
|
|
104
|
+
) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`entries[${i}]: op must be one of [${OP_KINDS.join(", ")}] (got ${JSON.stringify(e.op)})`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const op = e.op as OpKind;
|
|
110
|
+
|
|
111
|
+
if (typeof e.rowId !== "string" && e.rowId !== null) {
|
|
112
|
+
throw new Error(`entries[${i}]: rowId must be a string or null`);
|
|
113
|
+
}
|
|
114
|
+
if (e.target !== null && !isEntryShape(e.target)) {
|
|
115
|
+
throw new Error(
|
|
116
|
+
`entries[${i}]: target must be a {name, tier, type} object or null`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (op === "create" && e.target === null) {
|
|
121
|
+
throw new Error(`entries[${i}]: create op must have a non-null target`);
|
|
122
|
+
}
|
|
123
|
+
if (op === "merge") {
|
|
124
|
+
if (e.target !== null) {
|
|
125
|
+
throw new Error(`entries[${i}]: merge op must have target null`);
|
|
126
|
+
}
|
|
127
|
+
if (typeof e.mergeInto !== "string") {
|
|
128
|
+
throw new Error(`entries[${i}]: merge op must have a string mergeInto`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if ((MUTATE_KINDS as readonly string[]).includes(op)) {
|
|
132
|
+
if (typeof e.rowId !== "string") {
|
|
133
|
+
throw new Error(`entries[${i}]: ${op} op must have a string rowId`);
|
|
134
|
+
}
|
|
135
|
+
if (e.target === null) {
|
|
136
|
+
throw new Error(`entries[${i}]: ${op} op must have a non-null target`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import renderPlan from "./renderPlan.js";
|
|
3
|
+
import type { SyncPlan } from "./types.js";
|
|
4
|
+
|
|
5
|
+
const EMPTY: SyncPlan = { ops: [], violations: [], unmanaged: [] };
|
|
6
|
+
|
|
7
|
+
describe("renderPlan", () => {
|
|
8
|
+
it("summarises change vs unchanged counts", () => {
|
|
9
|
+
const plan: SyncPlan = {
|
|
10
|
+
...EMPTY,
|
|
11
|
+
ops: [
|
|
12
|
+
{
|
|
13
|
+
kind: "rename",
|
|
14
|
+
rowId: "i-1",
|
|
15
|
+
before: { name: "Text", tier: "Global/Form", type: "Component" },
|
|
16
|
+
after: { name: "TextField", tier: "Global/Form", type: "Component" },
|
|
17
|
+
changedFields: ["name"],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
kind: "keep",
|
|
21
|
+
rowId: "i-2",
|
|
22
|
+
before: { name: "Form", tier: "Global/Form", type: "Pattern" },
|
|
23
|
+
after: { name: "Form", tier: "Global/Form", type: "Pattern" },
|
|
24
|
+
changedFields: [],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const out = renderPlan(plan);
|
|
30
|
+
expect(out).toContain("1 change(s), 1 unchanged");
|
|
31
|
+
expect(out).toContain("~ rename Text [Global/Form/Component] → TextField");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("renders the ✓ verdict when there are no violations", () => {
|
|
35
|
+
expect(renderPlan(EMPTY)).toContain("✓ no guardrail violations");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("renders the ✗ verdict and lists each violation", () => {
|
|
39
|
+
const plan: SyncPlan = {
|
|
40
|
+
...EMPTY,
|
|
41
|
+
violations: ["X: bad tier", "Y: missing row"],
|
|
42
|
+
};
|
|
43
|
+
const out = renderPlan(plan);
|
|
44
|
+
expect(out).toContain("✗ 2 guardrail violation(s)");
|
|
45
|
+
expect(out).toContain("✗ X: bad tier");
|
|
46
|
+
expect(out).toContain("✗ Y: missing row");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("lists unmanaged in-scope rows", () => {
|
|
50
|
+
const plan: SyncPlan = {
|
|
51
|
+
...EMPTY,
|
|
52
|
+
unmanaged: [
|
|
53
|
+
{ rowId: "i-9", name: "Button", tier: "Global", type: "Component" },
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
const out = renderPlan(plan);
|
|
57
|
+
expect(out).toContain("Unmanaged in-scope rows (not in spec): 1");
|
|
58
|
+
expect(out).toContain("? Button [Global/Component] i-9");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("renders create and merge ops with their distinctive glyphs", () => {
|
|
62
|
+
const plan: SyncPlan = {
|
|
63
|
+
...EMPTY,
|
|
64
|
+
ops: [
|
|
65
|
+
{
|
|
66
|
+
kind: "create",
|
|
67
|
+
rowId: null,
|
|
68
|
+
before: null,
|
|
69
|
+
after: {
|
|
70
|
+
name: "SelectField",
|
|
71
|
+
tier: "Global/Form",
|
|
72
|
+
type: "Component",
|
|
73
|
+
},
|
|
74
|
+
note: "code-only input", // exercises noteSuffix's truthy branch
|
|
75
|
+
changedFields: [],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
kind: "merge",
|
|
79
|
+
rowId: "i-3",
|
|
80
|
+
before: {
|
|
81
|
+
name: "CustomChoices",
|
|
82
|
+
tier: "Global/Form",
|
|
83
|
+
type: "Component",
|
|
84
|
+
},
|
|
85
|
+
after: null,
|
|
86
|
+
mergeInto: "i-2",
|
|
87
|
+
changedFields: [],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const out = renderPlan(plan);
|
|
93
|
+
expect(out).toContain("+ create SelectField");
|
|
94
|
+
expect(out).toContain("— code-only input"); // note rendered
|
|
95
|
+
expect(out).toContain("− merge CustomChoices → i-2");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("renders fallback branches for degenerate ops", () => {
|
|
99
|
+
const plan: SyncPlan = {
|
|
100
|
+
...EMPTY,
|
|
101
|
+
ops: [
|
|
102
|
+
// keep with no after → empty name/tier fallback
|
|
103
|
+
{
|
|
104
|
+
kind: "keep",
|
|
105
|
+
rowId: "i-1",
|
|
106
|
+
before: null,
|
|
107
|
+
after: null,
|
|
108
|
+
changedFields: [],
|
|
109
|
+
},
|
|
110
|
+
// merge with no before → falls back to rowId
|
|
111
|
+
{
|
|
112
|
+
kind: "merge",
|
|
113
|
+
rowId: "i-2",
|
|
114
|
+
before: null,
|
|
115
|
+
after: null,
|
|
116
|
+
mergeInto: "i-9",
|
|
117
|
+
changedFields: [],
|
|
118
|
+
},
|
|
119
|
+
// mutate with neither before nor after → "(missing)" → "(removed)"
|
|
120
|
+
{
|
|
121
|
+
kind: "rename",
|
|
122
|
+
rowId: "i-3",
|
|
123
|
+
before: null,
|
|
124
|
+
after: null,
|
|
125
|
+
changedFields: [],
|
|
126
|
+
},
|
|
127
|
+
// create with no after → empty name + undefined tier/type fallback
|
|
128
|
+
{
|
|
129
|
+
kind: "create",
|
|
130
|
+
rowId: null,
|
|
131
|
+
before: null,
|
|
132
|
+
after: null,
|
|
133
|
+
changedFields: [],
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const out = renderPlan(plan);
|
|
139
|
+
expect(out).toContain("= keep");
|
|
140
|
+
expect(out).toContain("− merge i-2 → i-9");
|
|
141
|
+
expect(out).toContain("(missing) → (removed)");
|
|
142
|
+
expect(out).toContain("+ create ["); // null-after create renders empty name
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { PlannedOp, SyncPlan } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Render a sync plan as a human-readable before→after diff.
|
|
5
|
+
*
|
|
6
|
+
* Pure: returns the diff as a string (the caller decides whether to print it),
|
|
7
|
+
* so it is testable without capturing stdout.
|
|
8
|
+
*
|
|
9
|
+
* @param plan - the plan produced by `diffRoster`
|
|
10
|
+
* @returns a multi-line diff string suitable for console output
|
|
11
|
+
*/
|
|
12
|
+
export default function renderPlan(plan: SyncPlan): string {
|
|
13
|
+
const lines: string[] = [];
|
|
14
|
+
const actionable = plan.ops.filter((op) => op.kind !== "keep");
|
|
15
|
+
|
|
16
|
+
lines.push(
|
|
17
|
+
`Coda roster sync — ${actionable.length} change(s), ${plan.ops.length - actionable.length} unchanged`,
|
|
18
|
+
);
|
|
19
|
+
lines.push("");
|
|
20
|
+
|
|
21
|
+
for (const op of plan.ops) {
|
|
22
|
+
lines.push(renderOp(op));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (plan.unmanaged.length > 0) {
|
|
26
|
+
lines.push("");
|
|
27
|
+
lines.push(
|
|
28
|
+
`Unmanaged in-scope rows (not in spec): ${plan.unmanaged.length}`,
|
|
29
|
+
);
|
|
30
|
+
for (const row of plan.unmanaged) {
|
|
31
|
+
lines.push(` ? ${row.name} [${row.tier}/${row.type}] ${row.rowId}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
lines.push("");
|
|
36
|
+
if (plan.violations.length > 0) {
|
|
37
|
+
lines.push(
|
|
38
|
+
`✗ ${plan.violations.length} guardrail violation(s) — --apply refused:`,
|
|
39
|
+
);
|
|
40
|
+
for (const v of plan.violations) {
|
|
41
|
+
lines.push(` ✗ ${v}`);
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
lines.push("✓ no guardrail violations");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return lines.join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Render one planned operation as a single diff line. */
|
|
51
|
+
function renderOp(op: PlannedOp): string {
|
|
52
|
+
const symbol = symbolFor(op.kind);
|
|
53
|
+
if (op.kind === "keep") {
|
|
54
|
+
return ` ${symbol} keep ${op.after?.name ?? ""} [${op.after?.tier ?? ""}]`;
|
|
55
|
+
}
|
|
56
|
+
if (op.kind === "create") {
|
|
57
|
+
return ` ${symbol} create ${op.after?.name ?? ""} [${op.after?.tier}/${op.after?.type}]${noteSuffix(op)}`;
|
|
58
|
+
}
|
|
59
|
+
if (op.kind === "merge") {
|
|
60
|
+
return ` ${symbol} merge ${op.before?.name ?? op.rowId} → ${op.mergeInto}${noteSuffix(op)}`;
|
|
61
|
+
}
|
|
62
|
+
const beforeStr = op.before
|
|
63
|
+
? `${op.before.name} [${op.before.tier}/${op.before.type}]`
|
|
64
|
+
: "(missing)";
|
|
65
|
+
const afterStr = op.after
|
|
66
|
+
? `${op.after.name} [${op.after.tier}/${op.after.type}]`
|
|
67
|
+
: "(removed)";
|
|
68
|
+
return ` ${symbol} ${op.kind.padEnd(6)} ${beforeStr} → ${afterStr} Δ{${op.changedFields.join(",")}}${noteSuffix(op)}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A short glyph per op kind for the diff gutter. */
|
|
72
|
+
function symbolFor(kind: PlannedOp["kind"]): string {
|
|
73
|
+
switch (kind) {
|
|
74
|
+
case "create":
|
|
75
|
+
return "+";
|
|
76
|
+
case "merge":
|
|
77
|
+
return "−";
|
|
78
|
+
case "keep":
|
|
79
|
+
return "=";
|
|
80
|
+
default:
|
|
81
|
+
return "~";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Append the entry's note, when present. */
|
|
86
|
+
function noteSuffix(op: PlannedOp): string {
|
|
87
|
+
return op.note ? ` — ${op.note}` : "";
|
|
88
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import type { TableRow } from "../providers/index.js";
|
|
4
|
+
import snapshotTable from "./snapshotTable.js";
|
|
5
|
+
|
|
6
|
+
vi.mock("node:fs/promises");
|
|
7
|
+
|
|
8
|
+
const ROWS: TableRow[] = [{ _codaId: "i-1", name: "Text" }];
|
|
9
|
+
|
|
10
|
+
describe("snapshotTable", () => {
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
vi.mocked(writeFile).mockReset();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("writes the rows as pretty JSON and returns the path", async () => {
|
|
16
|
+
vi.mocked(writeFile).mockResolvedValue();
|
|
17
|
+
const path = await snapshotTable(ROWS, "snap.json");
|
|
18
|
+
|
|
19
|
+
expect(path).toBe("snap.json");
|
|
20
|
+
expect(writeFile).toHaveBeenCalledWith(
|
|
21
|
+
"snap.json",
|
|
22
|
+
JSON.stringify(ROWS, null, 2),
|
|
23
|
+
"utf-8",
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("propagates a write failure so the caller aborts the run", async () => {
|
|
28
|
+
vi.mocked(writeFile).mockRejectedValue(new Error("disk full"));
|
|
29
|
+
await expect(snapshotTable(ROWS, "snap.json")).rejects.toThrow("disk full");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { writeFile } from "node:fs/promises";
|
|
2
|
+
import type { TableRow } from "../providers/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Write a timestamped JSON snapshot of table rows to disk before any mutation,
|
|
6
|
+
* so destructive ops (row deletions) are reversible.
|
|
7
|
+
*
|
|
8
|
+
* @param rows - the rows to snapshot (as fetched, normalized)
|
|
9
|
+
* @param path - the snapshot file path
|
|
10
|
+
* @returns the path written
|
|
11
|
+
* @throws if the file cannot be written (caller must abort the write run)
|
|
12
|
+
* @note Impure — writes the file system.
|
|
13
|
+
*/
|
|
14
|
+
export default async function snapshotTable(
|
|
15
|
+
rows: TableRow[],
|
|
16
|
+
path: string,
|
|
17
|
+
): Promise<string> {
|
|
18
|
+
await writeFile(path, JSON.stringify(rows, null, 2), "utf-8");
|
|
19
|
+
return path;
|
|
20
|
+
}
|