Automation Library

@macavitymadcap/hyper-dank-automation contains reusable Bun automation helpers for Hyper-Dank apps. It keeps local script entrypoints small while app-specific routes, fixtures, and deployment choices remain in the app.

Library docsLibraries

Install

Install from npm with TypeScript-aware tooling:

npm install @macavitymadcap/hyper-dank-automation typescript

Package: view on npm.

import {
  buildImagesSection,
  createCommandGate,
  getGitHubRepo,
  getGitHubToken,
  runPa11yTargets,
  runVerification,
  smokeStaticSite,
  summariseScreenshotTargets,
  updateImagesSection,
  waitForHttp,
} from "@macavitymadcap/hyper-dank-automation";

import {
  buildAccessibilityStatementPage,
  buildStaticContentSite,
  createContentNavigation,
  escapeHtml,
  renderAccessibilityStatementMarkdown,
  renderChoiceListMarkdown,
  renderMarkdown,
} from "@macavitymadcap/hyper-dank-automation/content";

Helper Groups

GroupPurpose
Process helpersRun sync and async commands with predictable cwd, env, stdio, captured output, and allow-failure behaviour.
GitHub helpersParse repository remotes, discover tokens, make REST requests, find pull requests, and update PR bodies.
Verification helpersRun ordered gates, stop on failure, build command gates, and render Markdown verification reports.
Local server helpersStart Bun test servers, wrap app server setup/teardown, and wait for HTTP readiness.
Browser helpersOrchestrate Playwright screenshot flows, theme setup, and target summaries.
PR image helpersBuild and replace Markdown image sections for persisted PR screenshots.
A11y helpersRun Pa11y for one URL or named target lists with optional config paths and auth cookies while app routes stay local.
Static-site helpersAssert generated static artifacts and smoke-check expected file contents.
Content helpersParse front matter, render Markdown, rewrite content URLs, discover Markdown pages, and build static content through an app-owned document renderer.

Main Export Reference

Process

ExportContract
RunOptionsOptions shared by process helpers: cwd, env, input, stdio, and allowFailure.
RunResultCaptured stdout, stderr, and exitCode from sync commands.
runRuns a command synchronously and returns trimmed stdout. Throws on non-zero exit unless allowFailure is true.
runResultRuns a command synchronously and returns RunResult without throwing.
runAsyncRuns a command asynchronously with inherited stdio by default. Throws on non-zero exit unless allowFailure is true.

Verification

ExportContract
VerificationStatus"pass", "fail", or "not run".
VerificationGateCommand gate identity, command, arguments, name, and tooling label.
VerificationGateInputGate input accepted by createVerificationGate; tooling may be omitted.
VerificationResultGate plus status, output, exit code, and optional duration.
RunVerificationOptionsOptional cwd, environment, spawn implementation, stop-on-failure behaviour, and result callback.
createVerificationGateFills default tooling for a custom gate object.
createCommandGateBuilds a command-shaped VerificationGate.
runVerificationRuns gates in order and marks later gates as not run when stop-on-failure is enabled.
renderVerificationReportRenders a Markdown report with a summary table and command output sections.

Local Servers And Browser Evidence

ExportContract
StartedBunServerBun server, port, and base URL returned by startBunServer.
HttpFetchFetch-compatible function type for readiness polling.
StartBunServerOptionsHost, port, attempt, and fetch-handler options for an in-process Bun server.
WaitForHttpOptionsRetry, delay, fetch implementation, and success predicate for readiness checks.
AppServerHarnessStarted app server with URL and async stop() callback.
CreateAppServerHarnessOptionsStart, setup, stop, URL, readiness path, and wait options for app-owned server harnesses.
startBunServerStarts an in-process Bun server on a requested or dynamic port.
waitForHttpPolls a URL until the response passes the success predicate or times out.
createAppServerHarnessStarts an app-owned server, runs setup, waits for readiness, and returns a cleanup handle.
dynamicPortCandidateGenerates deterministic local port candidates from process id and attempt.
Theme"light" or "dark" screenshot theme.
ScreenshotFlowContextPage, server, and theme passed to screenshot setup hooks.
ScreenshotStateBehaviorState label, slug, path, auth user, and setup hooks for one screenshot state.
ScreenshotFlowApp-owned screenshot flow with label, description, states, and optional setup.
ScreenshotTargetSummaryFlattened screenshot target metadata for PR summaries.
CaptureScreenshotsOptionsBase URL, flows, output directory, Playwright page, server, auth setter, and themes.
captureScreenshotsRuns screenshot flows and writes themed images.
setThemeSets the documented theme localStorage key and HTML data attribute in a Playwright page.
summariseScreenshotTargetsReturns target summaries without needing a browser.

GitHub And PR Images

ExportContract
GitHubRepoRepository owner and name.
GitHubPullRequestMinimal PR shape used by local automation.
GitHubFetchFetch-compatible GitHub request function.
GitHubRequestOptionsOptional fetch implementation for tests.
parseGitHubRepoParses shorthand, SSH, and HTTPS GitHub remote strings.
getGitHubRepoReads the current origin remote and parses it.
getGitHubTokenReads GITHUB_TOKEN, GH_TOKEN, or the local Git credential helper.
getPullRequestFinds the explicit or branch-matching open pull request.
githubRequestSends a GitHub REST request with standard headers and error reporting.
ScreenshotResultPersisted screenshot metadata for a captured image.
ScreenshotStateSummaryPR-body summary of one screenshot state.
ScreenshotFlowSummaryPR-body summary of one screenshot flow.
BuildImagesSectionOptionsRepository, branch, flows, and screenshot records for PR image Markdown.
buildImagesSectionBuilds the managed PR screenshots section.
updateImagesSectionInserts or replaces the managed PR screenshots section in a PR body.

Pa11y And Static Artifacts

ExportContract
RunPa11yOptionsPa11y cwd, env, stdio, config path, cookie, and executable options.
A11yTargetNamed target with either a path under a base URL or a full URL.
RunPa11yTargetsOptionsBatch Pa11y options plus base URL and optional runner for tests.
runPa11yRuns Pa11y for one URL and passes cookies through PA11Y_COOKIE.
runPa11yTargetsRuns named Pa11y targets and returns checked names and URLs.
StaticArtifactAssertionRelative artifact path plus optional required content.
SmokeStaticSiteOptionsStatic root and route assertions for static-site smoke checks.
assertStaticArtifactChecks one generated file exists, stays inside the root, and contains expected strings.
smokeStaticSiteChecks a list of static artifact assertions.

Verification Example

import { createCommandGate, runVerification } from "@macavitymadcap/hyper-dank-automation";

const results = await runVerification([
  createCommandGate("check", "Static Checks", "bun", ["run", "check"], "Biome"),
]);

Compatibility Example

import {
  buildImagesSection,
  createCommandGate,
  parseGitHubRepo,
  renderVerificationReport,
  smokeStaticSite,
  summariseScreenshotTargets,
  waitForHttp,
} from "@macavitymadcap/hyper-dank-automation";

const repo = parseGitHubRepo("Macavitymadcap/hyper-dank");
const gate = createCommandGate("check", "Static Checks", "bun", ["run", "check"], "Biome");
const report = renderVerificationReport(
  [{ ...gate, status: "not run", stdout: "", stderr: "" }],
  "/workspace",
);
await waitForHttp("http://127.0.0.1:3000/healthz");
await smokeStaticSite({ root: "dist", routes: [{ path: "index.html" }] });
summariseScreenshotTargets([{ id: "home", label: "Home", description: "Home", states: [] }]);
buildImagesSection({ branch: "main", repo, flows: [], screenshots: [] });

createCommandGate() builds the common command-shaped verification entries used by runVerification(), while renderVerificationReport() turns completed or pending gate results into Markdown. smokeStaticSite() and assertStaticArtifact() are for generated local directories; they check relative paths and reject paths that escape the static root. summariseScreenshotTargets() describes app-owned screenshot flows for PR evidence without needing a browser page.

runVerification() runs gates in order and stops after the first failure. Each gate returns an id, name, status, stdout, stderr, and optional duration. Command gates accept a command, arguments, cwd, environment, display tooling name, and optional allow-failure setting, so apps can build local verifiers without duplicating process handling.

getGitHubRepo() and parseGitHubRepo() understand normal GitHub remote formats and return an owner/name pair. getGitHubToken() reads the token source used by local scripts, while githubRequest() applies the standard GitHub API headers. Higher-level helpers such as getPullRequest() and PR body update utilities keep app scripts focused on which section to update and what evidence to attach.

waitForHttp(url) polls until a local route is ready or times out. Pair it with startBunServer() or an app-owned server command when a script needs to start a temporary review app, run checks, and tear it down predictably.

For accessibility batches, pass named targets to runPa11yTargets():

await runPa11yTargets(
  [
    { name: "Home", path: "/" },
    { name: "Admin", path: "/admin", cookie: "session=admin" },
  ],
  { baseUrl: "http://127.0.0.1:3000", configPath: "pa11y-config.cjs" },
);

Content Example

import {
  buildStaticContentSite,
  escapeHtml,
  renderMarkdown,
} from "@macavitymadcap/hyper-dank-automation/content";

renderMarkdown("# Release notes", { basePath: "/docs" });

await buildStaticContentSite({
  assets: [{ from: "site/assets", to: "assets" }],
  basePath: "/docs",
  destinationDir: "public",
  renderDocument: ({ content, page }) =>
    `<!doctype html><title>${escapeHtml(page.title)}</title>${content}`,
  sourceDir: "site",
});

renderAccessibilityStatementMarkdown({
  contact: "Open an issue.",
  knownLimitations: ["Third-party embeds may vary."],
  siteName: "Docs",
  statementDate: "2026-05-21",
  supportSummary: "Docs uses semantic HTML and keyboard reachable controls.",
  testing: ["Pa11y checks", "Keyboard review"],
});

createContentNavigation(
  [
    { href: "/chapter-1/", label: "Chapter one", order: 1 },
    { href: "/chapter-2/", label: "Chapter two", order: 2 },
  ],
  "/chapter-1/",
);

renderChoiceListMarkdown([{ href: "/start/", label: "Begin" }]);

The /content subpath includes parseFrontMatter, renderMarkdown, renderInlineMarkdown, rewriteContentUrl, relativeContentUrl, discoverMarkdownPages, outputPathForContentPage, titleFromFilename, safeDestinationPath, buildStaticContentSite, renderAccessibilityStatementMarkdown, buildAccessibilityStatementPage, createContentNavigation, renderChoiceListMarkdown, escapeHtml, and escapeAttribute. These helpers return strings or typed page models and throw normal filesystem errors with the source paths supplied by the caller when files cannot be read or written.

Content Subpath Reference

ExportContract
ContentUrlOptionsBase path option used by URL and Markdown render helpers.
RenderMarkdownOptionsMarkdown render options; currently extends ContentUrlOptions.
FrontMatterResultParsed front matter metadata plus Markdown body.
ContentPageDiscovered content page metadata, source path, output path, route, title, and rendered content.
AccessibilityStatementInputApp-owned accessibility statement evidence and contact details.
BuildAccessibilityStatementPageOptionsOutput, route, and statement inputs for a static accessibility page.
OrderedContentItemOrdered item used for previous/next navigation.
ContentNavigationPrevious and next item output from createContentNavigation.
ChoiceListItemLink and label used by renderChoiceListMarkdown.
DiscoverMarkdownPagesOptionsSource directory for page discovery.
StaticContentAssetSource and destination asset copy instruction.
RenderStaticContentDocumentOptionsPage, content, and base path passed to an app-owned document renderer.
BuildStaticContentSiteOptionsSource, destination, base path, assets, and document renderer for static builds.
buildStaticContentSiteDiscovers Markdown pages, renders content, writes pretty routes, and copies assets.
buildAccessibilityStatementPageRenders and writes a static accessibility statement page.
renderAccessibilityStatementMarkdownTurns app-owned accessibility evidence into Markdown.
createContentNavigationBuilds previous/next links from ordered content around the current URL.
renderChoiceListMarkdownRenders a Markdown list of choices for static docs or branching content.
discoverMarkdownPagesReads Markdown files from a directory and derives route metadata.
outputPathForContentPageConverts file names and permalinks into pretty output paths.
safeDestinationPathResolves a destination path and rejects escapes outside the output directory.
renderMarkdownRenders headings, tables, lists, code, inline formatting, links, and allowed raw HTML blocks.
parseFrontMatterParses simple YAML-style string front matter and returns body Markdown.
renderInlineMarkdownRenders inline links, code, and emphasis.
rewriteContentUrlApplies docs base paths to root-relative and Liquid relative_url links.
relativeContentUrlJoins a root-relative URL with a base path.
titleFromFilenameConverts a Markdown filename into title text.
escapeHtmlEscapes text for HTML content.
escapeAttributeEscapes text for HTML attributes.

buildStaticContentSite() accepts the source directory, destination directory, base path, assets, and an app-owned document renderer. The helper discovers Markdown pages, renders Markdown, rewrites content URLs, writes pretty route output, and copies assets. The app still owns layout, CSS, search, feeds, accessibility evidence and claims, and any content model beyond front matter plus Markdown.

Adoption Boundary

Shared PackageConsuming App
Process execution and verification report mechanics.Which commands prove a product change.
GitHub request helpers and PR-body section replacement.PR narrative, release policy, and review expectations.
Dynamic local server and browser helpers.App routes, seeded users, fixtures, and smoke journeys.
Pa11y runner wrapper.A11y configuration and product-specific authentication cookies.
Markdown, URL, route, accessibility statement, and static-content build mechanics.Document chrome, CSS, deployment layout, taxonomy, RSS, search, accessibility evidence, legal claims, and product metadata.

For app-shape examples, see /recipes/.