From 2a9511613312969b4f5351e9b4e024d9c03d42be Mon Sep 17 00:00:00 2001 From: "ccf-factory[bot]" Date: Fri, 27 Nov 2026 17:48:25 +0000 Subject: [PATCH 1/5] feat(tutorials): add CopyBlock and CodeGroup for tutorial pages --- src/components/tutorials/CodeGroup.tsx | 104 +++++++++++++++++++++++++ src/components/tutorials/CopyBlock.tsx | 43 ++++++++++ src/css/custom.css | 17 ++++ src/theme/MDXComponents/index.tsx | 12 +++ 4 files changed, 176 insertions(+) create mode 100644 src/components/tutorials/CodeGroup.tsx create mode 100644 src/components/tutorials/CopyBlock.tsx create mode 100644 src/theme/MDXComponents/index.tsx diff --git a/src/components/tutorials/CodeGroup.tsx b/src/components/tutorials/CodeGroup.tsx new file mode 100644 index 0000000..4ba8df7 --- /dev/null +++ b/src/components/tutorials/CodeGroup.tsx @@ -0,0 +1,104 @@ +// The files of one tutorial step, shown as tabs so the page stays short: the reader opens the file +// they need and copies it. Each tab shows one CopyBlock, so every file keeps its own copy button. +// src/theme/MDXComponents/index.tsx registers it as , so tutorial pages use it without +// an import. +import React, {type KeyboardEvent, type ReactNode, useId, useRef, useState} from 'react'; +import clsx from 'clsx'; +import CopyBlock from './CopyBlock'; + +export type CodeGroupItem = { + /** The tab's label: the file the snippet belongs to, such as `compliance.yaml`. */ + title: string; + /** The file's text: what the tab shows, and what its copy button copies. */ + code: string; + /** Prism language to highlight the file with, such as `sh`, `yaml` or `json`. */ + language?: string; +}; + +export type CodeGroupProps = { + /** The files, in tab order. */ + items: CodeGroupItem[]; + /** Label of the file to open first; the first file when it matches none. */ + defaultTab?: string; + /** Classes added to the group. */ + className?: string; +}; + +export default function CodeGroup({items, defaultTab, className}: CodeGroupProps): ReactNode { + const group = useId(); + const tabs = useRef<(HTMLButtonElement | null)[]>([]); + const [selected, setSelected] = useState(Math.max(0, items.findIndex((item) => item.title === defaultTab))); + if (items.length === 0) { + return null; + } + // items can shrink below the selected index only in a hot reload, so clamp instead of crashing. + const active = Math.min(selected, items.length - 1); + + // The tablist moves the selection with the arrow keys, and to either end with Home and End. + function onSelectKey(event: KeyboardEvent) { + const last = items.length - 1; + const moved = + event.key === 'ArrowRight' ? (active + 1) % items.length + : event.key === 'ArrowLeft' ? (active - 1 + items.length) % items.length + : event.key === 'Home' ? 0 + : event.key === 'End' ? last + : undefined; + if (moved === undefined) { + return; + } + event.preventDefault(); + setSelected(moved); + tabs.current[moved]?.focus(); + } + + return ( +
+
item.title).join(', ')} + onKeyDown={onSelectKey} + className="flex flex-wrap gap-1 border-b border-[var(--ifm-color-emphasis-300)] bg-[var(--ifm-color-emphasis-100)] px-2 pt-2" + > + {items.map((item, index) => { + const isSelected = index === active; + return ( + + ); + })} +
+
+ {/* No title: the tab above the file already names it. */} + +
+
+ ); +} diff --git a/src/components/tutorials/CopyBlock.tsx b/src/components/tutorials/CopyBlock.tsx new file mode 100644 index 0000000..7d5f3ac --- /dev/null +++ b/src/components/tutorials/CopyBlock.tsx @@ -0,0 +1,43 @@ +// One copy-pastable snippet: commands, config or file contents, shown as a code block the reader +// can copy in one click. It is Docusaurus's own code block (so it keeps the site's prism +// github/dracula highlighting and its copy button, made always visible in src/css/custom.css) with +// a title row and text that copies exactly as it is shown. src/theme/MDXComponents/index.tsx +// registers it as , so tutorial pages use it without an import. +import React, {type ReactNode} from 'react'; +import CodeBlock from '@theme/CodeBlock'; +import clsx from 'clsx'; + +export type CopyBlockProps = { + /** The snippet. Give this or a plain-text child, not both. */ + code?: string; + /** The snippet as text children, e.g. a template literal that spans several lines. */ + children?: string | Array; + /** Prism language to highlight the snippet with, such as `sh`, `yaml` or `json`. */ + language?: string; + /** Label above the snippet: the file it goes in, or what running it does. */ + title?: string; + /** Classes added to the block. */ + className?: string; +}; + +/** + * The text the block shows and copies: the `code` prop, or the children joined. Blank lines at the + * ends are dropped and the indentation every line shares is removed, so a snippet written as an + * indented template literal in MDX reads the way the author wrote it and copies what the reader + * sees. + */ +export function snippetText(code: string | undefined, children: CopyBlockProps['children']): string { + const raw = code ?? (Array.isArray(children) ? children.join('') : (children ?? '')); + const lines = raw.replace(/^\n+/, '').replace(/\s+$/, '').split('\n'); + const indents = lines.filter((line) => line.trim() !== '').map((line) => /^[ \t]*/.exec(line)![0].length); + const indent = indents.length > 0 ? Math.min(...indents) : 0; + return lines.map((line) => line.slice(indent)).join('\n'); +} + +export default function CopyBlock({code, children, language, title, className}: CopyBlockProps): ReactNode { + return ( + + {snippetText(code, children)} + + ); +} diff --git a/src/css/custom.css b/src/css/custom.css index c566c99..83cd575 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -35,3 +35,20 @@ --ifm-color-primary-lightest: #4fddbf; --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3); } + +/* The tutorial blocks (src/components/tutorials) read the site's Infima variables, so they follow + the light and dark themes on their own. These two rules reach into Docusaurus's code block. */ + +/* A reader is meant to copy these snippets, so their buttons stay visible instead of fading in + only when the block is hovered. !important beats the theme's own hover opacity rules. */ +.ccf-copy-block button.clean-btn { + opacity: 1 !important; +} + +/* Inside a code group, the group's own border, radius and shadow are the block's chrome, so the + file shown drops its own, along with the margin that separates two standalone blocks. */ +.ccf-code-group .ccf-copy-block { + border-radius: 0; + box-shadow: none; + margin-bottom: 0; +} diff --git a/src/theme/MDXComponents/index.tsx b/src/theme/MDXComponents/index.tsx new file mode 100644 index 0000000..4e94a5a --- /dev/null +++ b/src/theme/MDXComponents/index.tsx @@ -0,0 +1,12 @@ +// Registers the tutorial components on every page's MDX scope, so a tutorial page writes +// and without importing them. Docusaurus reads the MDX component scope +// from this module, and the wrapper keeps the theme's own mappings (code, a, ul, admonition...). +import MDXComponents from '@theme-original/MDXComponents'; +import CopyBlock from '@site/src/components/tutorials/CopyBlock'; +import CodeGroup from '@site/src/components/tutorials/CodeGroup'; + +export default { + ...MDXComponents, + CopyBlock, + CodeGroup, +}; From 09545007c0e9845014e5ab98d8a195030efc3c4f Mon Sep 17 00:00:00 2001 From: "ccf-factory[bot]" Date: Fri, 27 Nov 2026 17:54:16 +0000 Subject: [PATCH 2/5] test(tutorials): cover the snippet text helper of CopyBlock --- package.json | 2 +- src/components/tutorials/CopyBlock.tsx | 15 +------ src/components/tutorials/snippetText.mjs | 21 ++++++++++ src/components/tutorials/snippetText.test.mjs | 41 +++++++++++++++++++ 4 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 src/components/tutorials/snippetText.mjs create mode 100644 src/components/tutorials/snippetText.test.mjs diff --git a/package.json b/package.json index 6e69562..470fda0 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "write-translations": "docusaurus write-translations", "write-heading-ids": "docusaurus write-heading-ids", "typecheck": "tsc", - "test": "node --test scripts/openapi-display.test.mjs scripts/gen-config-ref.test.mjs scripts/sync-catalog.test.mjs", + "test": "node --test scripts/openapi-display.test.mjs scripts/gen-config-ref.test.mjs scripts/sync-catalog.test.mjs src/components/tutorials/snippetText.test.mjs", "spellcheck": "cspell \"**/*.md\" \"**/*.mdx\" --no-progress" }, "dependencies": { diff --git a/src/components/tutorials/CopyBlock.tsx b/src/components/tutorials/CopyBlock.tsx index 7d5f3ac..db4eb6e 100644 --- a/src/components/tutorials/CopyBlock.tsx +++ b/src/components/tutorials/CopyBlock.tsx @@ -6,6 +6,7 @@ import React, {type ReactNode} from 'react'; import CodeBlock from '@theme/CodeBlock'; import clsx from 'clsx'; +import {snippetText} from './snippetText.mjs'; export type CopyBlockProps = { /** The snippet. Give this or a plain-text child, not both. */ @@ -20,20 +21,6 @@ export type CopyBlockProps = { className?: string; }; -/** - * The text the block shows and copies: the `code` prop, or the children joined. Blank lines at the - * ends are dropped and the indentation every line shares is removed, so a snippet written as an - * indented template literal in MDX reads the way the author wrote it and copies what the reader - * sees. - */ -export function snippetText(code: string | undefined, children: CopyBlockProps['children']): string { - const raw = code ?? (Array.isArray(children) ? children.join('') : (children ?? '')); - const lines = raw.replace(/^\n+/, '').replace(/\s+$/, '').split('\n'); - const indents = lines.filter((line) => line.trim() !== '').map((line) => /^[ \t]*/.exec(line)![0].length); - const indent = indents.length > 0 ? Math.min(...indents) : 0; - return lines.map((line) => line.slice(indent)).join('\n'); -} - export default function CopyBlock({code, children, language, title, className}: CopyBlockProps): ReactNode { return ( diff --git a/src/components/tutorials/snippetText.mjs b/src/components/tutorials/snippetText.mjs new file mode 100644 index 0000000..81573fc --- /dev/null +++ b/src/components/tutorials/snippetText.mjs @@ -0,0 +1,21 @@ +// The text a tutorial block shows and copies, shared by CopyBlock and CodeGroup. Plain ESM with +// JSDoc types, like the scripts/ the site builds from, so `yarn test` can cover the trimming and +// dedent it does without a browser. + +/** + * The text of a snippet: the code, or the children joined. Blank lines at the ends are dropped and + * the indentation every line shares is removed, so a snippet written in MDX as an indented template + * literal reads the way its author wrote it, and copies exactly what the reader sees. + * + * @param {string | undefined} code The snippet, when it is given as the code prop. + * @param {string | Array | undefined} children The snippet, when it is given as + * text children. + * @returns {string} + */ +export function snippetText(code, children) { + const raw = code ?? (Array.isArray(children) ? children.join('') : (children ?? '')); + const lines = raw.replace(/^\n+/, '').replace(/\s+$/, '').split('\n'); + const indents = lines.filter((line) => line.trim() !== '').map((line) => /^[ \t]*/.exec(line)[0].length); + const indent = indents.length > 0 ? Math.min(...indents) : 0; + return lines.map((line) => line.slice(indent)).join('\n'); +} diff --git a/src/components/tutorials/snippetText.test.mjs b/src/components/tutorials/snippetText.test.mjs new file mode 100644 index 0000000..8d7a7af --- /dev/null +++ b/src/components/tutorials/snippetText.test.mjs @@ -0,0 +1,41 @@ +// node --test src/components/tutorials/snippetText.test.mjs (or `yarn test`) +import assert from 'node:assert/strict'; +import test from 'node:test'; +import {snippetText} from './snippetText.mjs'; + +test('the code prop is the text, minus the blank lines at its ends', () => { + assert.equal(snippetText('kubectl get pods\n', undefined), 'kubectl get pods'); + assert.equal(snippetText('\n\nccf evidence list\n\n', undefined), 'ccf evidence list'); +}); + +test('children are joined, so a snippet can be split across expressions', () => { + assert.equal(snippetText(undefined, ['name: k8s\n', 'version: 1\n']), 'name: k8s\nversion: 1'); + assert.equal(snippetText(undefined, ['port: ', 8080]), 'port: 8080'); +}); + +test('the indentation every line shares is dropped and the rest kept, as an indented MDX literal writes it', () => { + const drafted = '\n plugins:\n - name: k8s\n namespace: compliance\n '; + assert.equal(snippetText(undefined, drafted), 'plugins:\n - name: k8s\n namespace: compliance'); +}); + +test('a snippet that already starts at column zero is left alone', () => { + assert.equal(snippetText('plugins:\n - name: k8s', undefined), 'plugins:\n - name: k8s'); +}); + +test('blank lines and shorter-indented lines inside the snippet are kept', () => { + assert.equal(snippetText('a:\n\n b: 1', undefined), 'a:\n\n b: 1'); +}); + +test('tabs count as indentation', () => { + assert.equal(snippetText('\t\tccf catalog apply c.yaml\n\t\t --dry-run', undefined), 'ccf catalog apply c.yaml\n --dry-run'); +}); + +test('code wins when the author gives both it and children', () => { + assert.equal(snippetText('from code', ['from children']), 'from code'); +}); + +test('no snippet gives no text', () => { + assert.equal(snippetText(undefined, undefined), ''); + assert.equal(snippetText(undefined, []), ''); + assert.equal(snippetText(' \n \n', undefined), ''); +}); From 80980a980a9e4b066e207ae651f51afd66f5f697 Mon Sep 17 00:00:00 2001 From: "ccf-factory[bot]" Date: Fri, 27 Nov 2026 17:56:43 +0000 Subject: [PATCH 3/5] fix(tutorials): drop leading blank lines from a snippet --- src/components/tutorials/CodeGroup.tsx | 2 +- src/components/tutorials/snippetText.mjs | 2 +- src/components/tutorials/snippetText.test.mjs | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/tutorials/CodeGroup.tsx b/src/components/tutorials/CodeGroup.tsx index 4ba8df7..ff4a2b4 100644 --- a/src/components/tutorials/CodeGroup.tsx +++ b/src/components/tutorials/CodeGroup.tsx @@ -27,7 +27,7 @@ export type CodeGroupProps = { export default function CodeGroup({items, defaultTab, className}: CodeGroupProps): ReactNode { const group = useId(); const tabs = useRef<(HTMLButtonElement | null)[]>([]); - const [selected, setSelected] = useState(Math.max(0, items.findIndex((item) => item.title === defaultTab))); + const [selected, setSelected] = useState(() => Math.max(0, items.findIndex((item) => item.title === defaultTab))); if (items.length === 0) { return null; } diff --git a/src/components/tutorials/snippetText.mjs b/src/components/tutorials/snippetText.mjs index 81573fc..14d280e 100644 --- a/src/components/tutorials/snippetText.mjs +++ b/src/components/tutorials/snippetText.mjs @@ -14,7 +14,7 @@ */ export function snippetText(code, children) { const raw = code ?? (Array.isArray(children) ? children.join('') : (children ?? '')); - const lines = raw.replace(/^\n+/, '').replace(/\s+$/, '').split('\n'); + const lines = raw.replace(/^(\s*\n)+/, '').replace(/\s+$/, '').split('\n'); const indents = lines.filter((line) => line.trim() !== '').map((line) => /^[ \t]*/.exec(line)[0].length); const indent = indents.length > 0 ? Math.min(...indents) : 0; return lines.map((line) => line.slice(indent)).join('\n'); diff --git a/src/components/tutorials/snippetText.test.mjs b/src/components/tutorials/snippetText.test.mjs index 8d7a7af..a3c82ca 100644 --- a/src/components/tutorials/snippetText.test.mjs +++ b/src/components/tutorials/snippetText.test.mjs @@ -6,6 +6,7 @@ import {snippetText} from './snippetText.mjs'; test('the code prop is the text, minus the blank lines at its ends', () => { assert.equal(snippetText('kubectl get pods\n', undefined), 'kubectl get pods'); assert.equal(snippetText('\n\nccf evidence list\n\n', undefined), 'ccf evidence list'); + assert.equal(snippetText(undefined, ' \n plugins:\n - name: k8s'), 'plugins:\n - name: k8s'); }); test('children are joined, so a snippet can be split across expressions', () => { From 31d2176ca38de7e1b7a0f339d69b17411fc287ea Mon Sep 17 00:00:00 2001 From: "ccf-factory[bot]" Date: Fri, 27 Nov 2026 18:29:03 +0000 Subject: [PATCH 4/5] fix: address review feedback --- package.json | 2 +- src/components/tutorials/CodeGroup.tsx | 19 +++---- src/components/tutorials/codeGroupTabs.mjs | 50 +++++++++++++++++++ .../tutorials/codeGroupTabs.test.mjs | 49 ++++++++++++++++++ 4 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 src/components/tutorials/codeGroupTabs.mjs create mode 100644 src/components/tutorials/codeGroupTabs.test.mjs diff --git a/package.json b/package.json index 470fda0..172754c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "write-translations": "docusaurus write-translations", "write-heading-ids": "docusaurus write-heading-ids", "typecheck": "tsc", - "test": "node --test scripts/openapi-display.test.mjs scripts/gen-config-ref.test.mjs scripts/sync-catalog.test.mjs src/components/tutorials/snippetText.test.mjs", + "test": "node --test scripts/openapi-display.test.mjs scripts/gen-config-ref.test.mjs scripts/sync-catalog.test.mjs src/components/tutorials/snippetText.test.mjs src/components/tutorials/codeGroupTabs.test.mjs", "spellcheck": "cspell \"**/*.md\" \"**/*.mdx\" --no-progress" }, "dependencies": { diff --git a/src/components/tutorials/CodeGroup.tsx b/src/components/tutorials/CodeGroup.tsx index ff4a2b4..0b51af2 100644 --- a/src/components/tutorials/CodeGroup.tsx +++ b/src/components/tutorials/CodeGroup.tsx @@ -5,6 +5,7 @@ import React, {type KeyboardEvent, type ReactNode, useId, useRef, useState} from 'react'; import clsx from 'clsx'; import CopyBlock from './CopyBlock'; +import {clampTab, initialTab, nextTab} from './codeGroupTabs.mjs'; export type CodeGroupItem = { /** The tab's label: the file the snippet belongs to, such as `compliance.yaml`. */ @@ -27,22 +28,16 @@ export type CodeGroupProps = { export default function CodeGroup({items, defaultTab, className}: CodeGroupProps): ReactNode { const group = useId(); const tabs = useRef<(HTMLButtonElement | null)[]>([]); - const [selected, setSelected] = useState(() => Math.max(0, items.findIndex((item) => item.title === defaultTab))); + const [selected, setSelected] = useState(() => initialTab(items, defaultTab)); if (items.length === 0) { return null; } - // items can shrink below the selected index only in a hot reload, so clamp instead of crashing. - const active = Math.min(selected, items.length - 1); + const active = clampTab(selected, items.length); - // The tablist moves the selection with the arrow keys, and to either end with Home and End. + // The tablist moves the selection with the arrow keys, and to either end with Home and End; the + // decision of where a key goes lives in codeGroupTabs.mjs, where `yarn test` covers it. function onSelectKey(event: KeyboardEvent) { - const last = items.length - 1; - const moved = - event.key === 'ArrowRight' ? (active + 1) % items.length - : event.key === 'ArrowLeft' ? (active - 1 + items.length) % items.length - : event.key === 'Home' ? 0 - : event.key === 'End' ? last - : undefined; + const moved = nextTab(active, event.key, items.length); if (moved === undefined) { return; } @@ -56,7 +51,7 @@ export default function CodeGroup({items, defaultTab, className}: CodeGroupProps className={clsx( 'ccf-code-group my-4 overflow-hidden rounded-[var(--ifm-code-border-radius)] border', 'border-[var(--ifm-color-emphasis-300)] bg-[var(--ifm-background-surface-color)]', - 'shadow-[var(--ifm-global-shadow-lw)]', + 'shadow-[shadow:var(--ifm-global-shadow-lw)]', className, )} > diff --git a/src/components/tutorials/codeGroupTabs.mjs b/src/components/tutorials/codeGroupTabs.mjs new file mode 100644 index 0000000..0f8339f --- /dev/null +++ b/src/components/tutorials/codeGroupTabs.mjs @@ -0,0 +1,50 @@ +// The tab selection decisions of CodeGroup. Plain ESM with JSDoc types, like snippetText.mjs, so +// `yarn test` can cover the lookup, the clamping and the keyboard wrap-around without a browser. + +/** + * The tab to open first: the index of the item titled defaultTab, or 0 when it matches none, so + * the group opens the first file. + * + * @param {{title: string}[]} items The files, in tab order. + * @param {string | undefined} defaultTab The label of the file to open first. + * @returns {number} + */ +export function initialTab(items, defaultTab) { + return Math.max(0, items.findIndex((item) => item.title === defaultTab)); +} + +/** + * The tab the selected index must show, clamped to the last item so items shrinking below the + * selected index, which only happens in a hot reload, cannot crash the group. + * + * @param {number} selected The index selected with clicks or the keyboard. + * @param {number} count The number of items. + * @returns {number} + */ +export function clampTab(selected, count) { + return Math.min(selected, count - 1); +} + +/** + * The tab a key on the tablist moves to, wrapping around at both ends, or undefined for a key the + * tablist does not handle. + * + * @param {number} active The tab currently shown. + * @param {string} key The key pressed. + * @param {number} count The number of tabs. + * @returns {number | undefined} + */ +export function nextTab(active, key, count) { + switch (key) { + case 'ArrowRight': + return (active + 1) % count; + case 'ArrowLeft': + return (active - 1 + count) % count; + case 'Home': + return 0; + case 'End': + return count - 1; + default: + return undefined; + } +} diff --git a/src/components/tutorials/codeGroupTabs.test.mjs b/src/components/tutorials/codeGroupTabs.test.mjs new file mode 100644 index 0000000..135747a --- /dev/null +++ b/src/components/tutorials/codeGroupTabs.test.mjs @@ -0,0 +1,49 @@ +// node --test src/components/tutorials/codeGroupTabs.test.mjs (or `yarn test`) +import assert from 'node:assert/strict'; +import test from 'node:test'; +import {clampTab, initialTab, nextTab} from './codeGroupTabs.mjs'; + +const files = [{title: 'compliance.yaml'}, {title: 'filter.yaml'}, {title: 'run.sh'}]; + +test('defaultTab opens that file, by title', () => { + assert.equal(initialTab(files, 'filter.yaml'), 1); + assert.equal(initialTab(files, 'run.sh'), 2); +}); + +test('a defaultTab that matches no title, or is absent, opens the first file', () => { + assert.equal(initialTab(files, 'missing.yaml'), 0); + assert.equal(initialTab(files, undefined), 0); + assert.equal(initialTab([], 'compliance.yaml'), 0); +}); + +test('the first title wins when two files share it', () => { + assert.equal(initialTab([...files, {title: 'run.sh'}], 'run.sh'), 2); +}); + +test('selection stays put while it is within the items and clamps when they shrink below it', () => { + assert.equal(clampTab(1, 3), 1); + assert.equal(clampTab(2, 3), 2); + assert.equal(clampTab(4, 3), 2); +}); + +test('ArrowRight advances and wraps from the last tab to the first', () => { + assert.equal(nextTab(0, 'ArrowRight', 3), 1); + assert.equal(nextTab(2, 'ArrowRight', 3), 0); +}); + +test('ArrowLeft steps back and wraps from the first tab to the last', () => { + assert.equal(nextTab(1, 'ArrowLeft', 3), 0); + assert.equal(nextTab(0, 'ArrowLeft', 3), 2); +}); + +test('Home and End jump to either end', () => { + assert.equal(nextTab(1, 'Home', 3), 0); + assert.equal(nextTab(1, 'End', 3), 2); + assert.equal(nextTab(0, 'End', 1), 0); +}); + +test('a key the tablist does not handle moves nothing', () => { + assert.equal(nextTab(1, 'Enter', 3), undefined); + assert.equal(nextTab(1, 'Tab', 3), undefined); + assert.equal(nextTab(1, 'ArrowDown', 3), undefined); +}); From 9d1ce7978ca68c08bde2f219952d2e391c47ad1b Mon Sep 17 00:00:00 2001 From: "ccf-factory[bot]" Date: Sat, 28 Nov 2026 12:46:26 +0000 Subject: [PATCH 5/5] test(tutorials): keep snippet fixtures to real CLI commands and config Review (DOCS-ACC-001): the fixtures taught 'ccf evidence list', 'ccf catalog apply --dry-run' and a plugins list with name/namespace. The documented CLI is the 'api' binary (api dashboards export, api digest test --dry-run) and agentconfig.Config keys plugins by identifier (plugins: { k8s: { enabled: ... } }). Fixtures now use those real forms. --- src/components/tutorials/snippetText.test.mjs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/tutorials/snippetText.test.mjs b/src/components/tutorials/snippetText.test.mjs index a3c82ca..3f47310 100644 --- a/src/components/tutorials/snippetText.test.mjs +++ b/src/components/tutorials/snippetText.test.mjs @@ -5,8 +5,8 @@ import {snippetText} from './snippetText.mjs'; test('the code prop is the text, minus the blank lines at its ends', () => { assert.equal(snippetText('kubectl get pods\n', undefined), 'kubectl get pods'); - assert.equal(snippetText('\n\nccf evidence list\n\n', undefined), 'ccf evidence list'); - assert.equal(snippetText(undefined, ' \n plugins:\n - name: k8s'), 'plugins:\n - name: k8s'); + assert.equal(snippetText('\n\napi dashboards export f.json\n\n', undefined), 'api dashboards export f.json'); + assert.equal(snippetText(undefined, ' \n plugins:\n k8s:'), 'plugins:\n k8s:'); }); test('children are joined, so a snippet can be split across expressions', () => { @@ -15,12 +15,12 @@ test('children are joined, so a snippet can be split across expressions', () => }); test('the indentation every line shares is dropped and the rest kept, as an indented MDX literal writes it', () => { - const drafted = '\n plugins:\n - name: k8s\n namespace: compliance\n '; - assert.equal(snippetText(undefined, drafted), 'plugins:\n - name: k8s\n namespace: compliance'); + const drafted = '\n plugins:\n k8s:\n enabled: true\n '; + assert.equal(snippetText(undefined, drafted), 'plugins:\n k8s:\n enabled: true'); }); test('a snippet that already starts at column zero is left alone', () => { - assert.equal(snippetText('plugins:\n - name: k8s', undefined), 'plugins:\n - name: k8s'); + assert.equal(snippetText('plugins:\n k8s:', undefined), 'plugins:\n k8s:'); }); test('blank lines and shorter-indented lines inside the snippet are kept', () => { @@ -28,7 +28,7 @@ test('blank lines and shorter-indented lines inside the snippet are kept', () => }); test('tabs count as indentation', () => { - assert.equal(snippetText('\t\tccf catalog apply c.yaml\n\t\t --dry-run', undefined), 'ccf catalog apply c.yaml\n --dry-run'); + assert.equal(snippetText('\t\tapi digest test\n\t\t --dry-run', undefined), 'api digest test\n --dry-run'); }); test('code wins when the author gives both it and children', () => {