On this page
The short answerKnow where the examples liveWhy Starlight examples driftInventory and run JavaScript fencesAdd a build and check to CIHow DocsAlive reads StarlightTriage results in contextBuild a practical coverage planWhere DocsAlive fitsThe sources we checkedFAQThe short answer
Test Starlight examples from their source files as well as building the site: inventory the fences, identify complete runnable examples and intentional fragments, and run representative reader paths in a clean environment. Check each package-manager alternative separately when it matters, and include Markdoc pages in your own coverage plan.
Starlight renders documentation from Markdown and MDX, with Markdoc available through an experimental integration. A successful site build shows that the site can render; it does not establish that an install command still names the right package, that a CLI flag still exists, or that a copied example works with the version a reader installs.
DocsAlive handles a Starlight repository as plain Markdown and MDX in engine 0.6.3. It recognizes Starlight’s MDX tab form and preserves fence language when Expressive Code metadata is present. It does not scan .mdoc pages or Astro component files. The local script below provides a small, explicit inventory and isolated JavaScript check, including .mdoc source files.
For the broader workflow, see testing documentation code and testing static-site documentation.
Know where the examples live
A conventional Starlight project keeps documentation pages in src/content/docs/. Markdown and MDX pages need no additional format configuration, and subdirectories contribute path segments. Custom pages can also live in src/pages/; those pages may use Astro components or other formats and need their own test strategy.
Markdoc support uses the experimental Astro Markdoc integration and the Starlight Markdoc preset. Its source pages use .mdoc. If a repository mixes formats, an inventory limited to .md and .mdx leaves part of the authored documentation out. The Starlight page guide and Astro Markdoc integration guide describe the layouts.
Starlight uses Expressive Code to render code blocks. A fence can have a language followed by metadata for a title, line markers, inserted or deleted text, or a terminal frame. The language is still the first word of the info string. The remaining metadata affects presentation and can be important to the reader, but it should not accidentally become part of the code passed to an interpreter.
Tabs often present package-manager choices or alternative languages. Starlight’s Tabs and TabItem components let authors label the choices; syncKey can keep groups with matching keys and labels in sync. A reader who chooses one package manager may expect that choice to persist through a tutorial. Test that path as a sequence, rather than assuming one passing tab proves every alternative.
Why Starlight examples drift
Package-manager tabs are easy to update unevenly. A package can be renamed in the npm tab while the pnpm or yarn tab retains the old name. A CLI flag can disappear in a new release, or a tutorial can install one framework version and use an API from another.
Expressive Code can make a change clear on screen while hiding the full context needed to execute it. Inserted and deleted lines may be shown as a teaching aid rather than a complete file. A reader who copies a marked diff can end up with marker characters or an incomplete program. Test the complete file that the reader should have after applying the change, and make clear whether the displayed block is a fragment.
MDX introduces component and import concerns alongside code fences. Markdoc pages introduce another source format. A custom page may assemble an example in an Astro component rather than store it as a fenced block. An inventory of fences is useful, but it is not an inventory of every piece of code visible on the published site.
Tutorial order matters as well. A JavaScript block may use a value defined earlier in the page. Running it alone can fail even though the tutorial is coherent; silently supplying that value in a test can hide a missing instruction. Record the intended starting state and test the full sequence when the page promises one.
Separate the promises
| Source form | Appropriate check | Limit to record |
|---|---|---|
| Complete JavaScript example | Execute in the documented environment | An isolated run may omit earlier page state |
| Package-manager tab | Run each supported path in an appropriate environment | A single selected tab leaves alternatives unchecked |
| Intentional fragment | Review or embed in a complete fixture | A fragment alone may not be executable |
| Expressive Code diff or marked change | Apply it to the stated starting file and test the result | Display markers are not necessarily source code |
| Markdoc page | Include .mdoc in a separate inventory and test |
The engine does not scan that file type |
| Output sample | Assert stable claims in a dedicated test | Rendering the sample does not verify it |
| Astro custom page | Test the component and rendered behavior separately | Fenced Markdown scanning does not cover .astro source |
A useful inventory says what was checked, what was skipped and why. It should not turn an intentional fragment into an unexplained red build, or treat an unsupported form as evidence of a successful execution.
Inventory and run JavaScript fences
Save the following as check_starlight.py at the repository root. Run it with python3 check_starlight.py. It requires Python 3.12 or later and Node 20 or later.
The script walks src/content/docs, reads .md, .mdx and .mdoc files, and identifies fenced blocks. It uses the first word after the opening fence as the language, leaving metadata such as titles and line markers out of the language. It prints counts, flags unlabeled or unapproved labels, and runs js blocks in separate temporary files. A JavaScript block whose first line is // fragment is recorded as a fragment.
#!/usr/bin/env python3
from collections import Counter
from pathlib import Path
import re
import subprocess
import sys
import tempfile
ROOT = Path("src/content/docs")
SUFFIXES = {".md", ".mdx", ".mdoc"}
ALLOWED = {
"bash", "sh", "shell", "console", "curl", "http",
"js", "javascript", "jsx", "ts", "tsx", "json",
"yaml", "yml", "toml", "text", "diff", "html",
"css", "astro", "md", "mdx", "mdoc", "python", "py",
}
OPEN = re.compile(r"^ {0,3}(`{3,}|~{3,})(.*)$")
def blocks(path):
lines = path.read_text(encoding="utf-8").splitlines()
index = 0
while index < len(lines):
match = OPEN.match(lines[index])
if not match:
index += 1
continue
marker = match.group(1)
info = match.group(2).strip()
language = info.split()[0].lower() if info else ""
start = index + 1
index += 1
body = []
close = re.compile(
r"^ {0,3}" + re.escape(marker[0])
+ r"{" + str(len(marker)) + r",}\s*$"
)
while index < len(lines) and not close.match(lines[index]):
body.append(lines[index])
index += 1
yield start, language, "\n".join(body), index < len(lines)
index += 1
def main():
if not ROOT.is_dir():
print(f"Missing directory: {ROOT}", file=sys.stderr)
return 1
counts = Counter()
failures = 0
executed = 0
fragments = 0
for path in sorted(p for p in ROOT.rglob("*") if p.suffix in SUFFIXES):
for line, language, body, closed in blocks(path):
counts[language or "(unlabeled)"] += 1
location = f"{path}:{line}"
if not closed:
print(f"FAIL {location}: unclosed fence")
failures += 1
if not language:
print(f"FAIL {location}: unlabeled fence")
failures += 1
elif language not in ALLOWED:
print(f"FAIL {location}: label {language!r} is not allowed")
failures += 1
if language != "js":
continue
if body.splitlines() and body.splitlines()[0].strip() == "// fragment":
print(f"SKIP {location}: fragment")
fragments += 1
continue
with tempfile.TemporaryDirectory() as directory:
script = Path(directory) / "block.js"
script.write_text(body + "\n", encoding="utf-8")
try:
result = subprocess.run(
["node", str(script)],
capture_output=True,
text=True,
timeout=30,
check=False,
)
except (OSError, subprocess.TimeoutExpired) as error:
print(f"FAIL {location}: {error}")
failures += 1
continue
executed += 1
if result.returncode:
print(f"FAIL {location}: node exited {result.returncode}")
print(result.stderr, end="")
failures += 1
else:
print(f"PASS {location}")
print("\nBlocks by language:")
for language, count in sorted(counts.items()):
print(f" {language}: {count}")
print(f"Executed: {executed}; fragments: {fragments}; failures: {failures}")
return 1 if failures else 0
if __name__ == "__main__":
sys.exit(main())
The allowed-label set is a policy for this script, not a claim that every listed language is executed. Adapt it to the labels your authors use. An unlabeled block fails the check so a maintainer must decide whether to label it or change the policy.
Each js block gets its own temporary file. That makes failures easy to locate, but it means page state is not preserved and relative imports resolve from the temporary directory. A tutorial depending on earlier blocks, repository files, installed packages or a particular working directory needs a separate complete test. The script also does not execute javascript labels; add a deliberate policy if those should receive the same treatment.
The parser handles ordinary backtick and tilde fences, including longer closing fences. It is a small source scanner, not a full Markdown, MDX or Markdoc parser. Review unusual nesting and generated content separately. Never run untrusted documentation code in a privileged environment.
Mark fragments deliberately
A fragment marker is useful only if reviewers understand what it means. Put // fragment on the first line of a JavaScript block when the block is intentionally incomplete for this script. Then identify the complete file or preceding steps in the surrounding page.
Do not mark a broken complete example as a fragment merely to make CI pass. If the page tells readers to copy and run it, provide the setup it needs or test the complete reader path. A fragment can still have a separate fixture that verifies its final context.
Add a build and check to CI
The following workflow is illustrative configuration. It assumes the repository has a lockfile, a build script and the Python checker above at its root. Adjust triggers and commands to match the project.
name: Documentation checks
on:
push:
pull_request:
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm ci
- run: npm run build
- run: python3 check_starlight.py
The build and the script answer different questions. The build checks that the configured site can be produced. The script inventories source fences and runs a narrow subset of them. Neither alone verifies all tabs, remote services, prose or a multi-page tutorial.
Pin dependencies through the repository’s lockfile and decide which version of the documented package the examples should exercise. For release-sensitive docs, test the artifact intended for readers as well as the current checkout. The GitHub Actions documentation testing guide covers how to place checks in a wider workflow.
How DocsAlive reads Starlight
There is no dedicated Astro or Starlight detection in engine 0.6.3. The repository is handled as plain Markdown and MDX. If there is no top-level docs/ directory, the scan considers .md, .mdx and .markdown files under the repository root, including src/content/docs and the root README, while excluding known build, dependency and other ignored directories.
If a top-level docs/ directory exists, the default scan concentrates on that directory plus the README. Use the CLI option --docs-dir src/content/docs to point the scan at Starlight content stored there. Review the resulting page list: a repository can contain useful examples outside that directory.
The engine does not scan .mdoc files or .astro component files. Markdoc-specific syntax embedded in MDX is not understood. The local script above can inventory fences in .mdoc files, but a full Markdoc-aware test and site build remain useful when those pages contain significant examples.
| Block or page form | Engine behavior in 0.6.3 |
|---|---|
| Markdown or MDX fence in a scanned page | Extracted and planned according to its language and contents |
Starlight Tabs with labeled TabItem choices |
Recognized as a tab group; package-manager alternatives use the preference order described below |
| Tabs labeled as different languages | Every language tab is run rather than selecting one package-manager alternative |
| Expressive Code metadata | The first word remains the language; a title is read as the block title |
| Fence titled output, response or result | Recognized as output and skipped; contents are not validated |
diff fence |
Skipped as not executable, including a diff configured to display JavaScript |
.mdoc or .astro page |
Not scanned |
mdoc fence label or another unmapped label |
Reported as pass without being run or parsed; this is a known limitation |
jsx or tsx |
Not judged |
ts |
Simple type annotations are stripped before execution; other TypeScript-only syntax is not fully judged |
For package-manager alternatives, the preference order is npm, pip, uv, python, py, javascript, js, node, typescript, curl, bash, shell, linux and macos. A selected npm tab does not establish that a skipped pnpm tab works. Maintain separate coverage for alternatives you support.
Output handling has a specific boundary. A block introduced as output or response is skipped, and its contents are not compared. Printed output is compared only for pycon or python-repl sessions. If a JavaScript example promises a particular value, add your own assertion for that promise.
A network-requiring shell block can be skipped when --no-network is used. Credential placeholders are also skipped and classified as needing credentials. Commands for host tools such as pnpm or yarn may be skipped as host-tool commands. These reasons are coverage information, not evidence that the reader’s command succeeded.
Triage results in context
| Result | Question to ask | Next step |
|---|---|---|
| JavaScript block fails alone | Does it rely on earlier tutorial state? | Test the full sequence and clarify prerequisites |
| npm tab passes, another tab is skipped | Is the skipped package manager supported? | Run that path in a suitable CI job |
| A complete example uses an old flag | Which package version is the page meant to document? | Update the example or version-specific guidance |
| A marked diff cannot run | Is it intended to be a complete file? | Apply it to a fixture and test the resulting file |
.mdoc page is absent from the report |
Is its content covered elsewhere? | Add a Markdoc-aware inventory and test |
| Unmapped label reports pass | Was any checker actually applied? | Treat it as unchecked and use an appropriate tool |
| Output sample is skipped | Does the page promise a stable result? | Add a separate assertion for the promised value |
| Network or credential result | Is the environment authorized and available? | Review separately from a likely docs defect |
A failure should lead to a reproducible question, not an automatic rewrite. Record the source page and line, the runtime and package version, the setup and the expected reader path. A missing fixture may be a test setup issue, or it may reveal a prerequisite the page never explains.
Build a practical coverage plan
Start with high-value paths: installation, first use and common configuration. For each path, list the source files, relevant tabs, runtime, package version and expected outcome. Then decide which pieces can run in isolation and which need page-order state.
Test package-manager alternatives in separate clean environments when they have different lockfiles or tool requirements. Avoid executing all alternatives in one shell as though they were consecutive instructions. A tab is usually a choice, and its setup can conflict with another choice.
For Expressive Code, inspect the source as well as the rendered page. A highlighted line may be valid code, while an insertion or deletion display may describe a change to an existing file. Make the reader’s copyable final state clear. If a tutorial asks readers to edit a file, keep a fixture for the starting state and verify the resulting state.
For Markdoc, inventory .mdoc pages and document the coverage gap in the same report as Markdown and MDX results. The site build is valuable for rendering and integration errors, but a successful build does not execute every command shown to a reader.
Use this checklist in a pull request:
[ ] List the documentation source directories and formats.
[ ] Include Markdoc pages in a separate coverage plan.
[ ] Build the site with the intended dependency versions.
[ ] Inventory fence labels and review unlabeled blocks.
[ ] Mark intentional fragments and identify their complete context.
[ ] Test important package-manager alternatives separately.
[ ] Check tutorial sequences with their documented starting state.
[ ] Verify the final file represented by a diff or marked edit.
[ ] Assert important output in a dedicated test.
[ ] Review skipped, unsupported and credential-dependent blocks.
[ ] Record the package and runtime versions tested.
Where DocsAlive fits
DocsAlive extracts and plans supported examples, runs executable blocks in a fresh page environment and reports findings with reasons. It keeps blocks in page order, which can help with tutorials whose later examples depend on earlier setup. A scan without --execute only extracts and plans.
Use the CLI reference to choose the source directory and execution options, and the findings guide to interpret statuses. Keep your own checks for .mdoc, Astro components, unsupported labels, skipped tab alternatives and output assertions. The JavaScript documentation testing guide provides more detail on runtime and dependency choices.
For related layouts, compare Nextra documentation testing. If the pages contain API commands, use the curl and HTTP examples guide for status and response checks.
The sources we checked
These sources were read on November 11, 2026.
| Source | What it covers |
|---|---|
| Starlight pages | Documentation locations and supported page formats |
| Starlight authoring | Markdown authoring and code presentation |
| Starlight tabs | Tabs, labels and synchronized choices |
| Expressive Code highlighting | Code presentation and markers |
| Astro Markdoc integration | Markdoc integration |
| GitHub checkout action | Repository checkout in Actions |
| GitHub Node setup action | Selecting Node in Actions |
FAQ
Does a Starlight build test every example?
No. A build checks the site’s configured rendering path. Commands, package versions, response claims and tutorial sequences need their own tests.
Does DocsAlive scan Markdoc pages?
Engine 0.6.3 does not scan .mdoc files. Include those pages in a separate inventory and testing workflow.
Does the engine run every package-manager tab?
It recognizes Starlight tab groups and selects a preferred alternative for package-manager choices. Test supported alternatives separately, and review the report for skipped variants.
Do Expressive Code titles change the detected language?
The engine takes the first word of the fence info string as the language and reads a title as a block title. Display metadata does not turn a fragment or diff into a complete runnable example.
Why might the local script fail a valid tutorial fragment?
It runs each js block in a separate temporary file, so it does not preserve earlier page state or repository-relative imports. Mark intentional fragments and test complete sequences separately.
Is a passing unmapped label a successful test?
No. In engine 0.6.3 an unmapped label can be reported as passing without execution or parsing. Treat that result as unchecked and use a suitable independent checker.




