Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions scripts/site_demo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,45 @@ func TestWebsiteBuildAndDevRunTheDemoGenerator(t *testing.T) {
t.Error(".gitignore does not ignore the generated website/public/demo/")
}
}

// The apply link goes into the pages as given: a URL that holds `$&`, `$1` or `$$` is not read as a replacement pattern.
func TestDemoGeneratorKeepsDollarSignsInTheApplyLink(t *testing.T) {
url := "https://example.org/new?template=x.yml&a=$&&b=$1&c=$$&d=$`&e=$'"
// The URL goes through the environment: it holds a backtick, which a JavaScript template literal could not carry.
script := `import { render } from './scripts/build-demo.mjs'; process.stdout.write(render('<a href="{{APPLY_FORM}}">x</a> {{APPLY_FORM}}', '2026-10-11', process.env.APPLY_URL))`
cmd := exec.Command(nodeOrSkip(t), "--input-type=module", "-e", script)
cmd.Dir = "../website"
cmd.Env = append(os.Environ(), "APPLY_URL="+url)
b, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("render failed: %v\n%s", err, b)
}
want := `<a href="` + url + `">x</a> ` + url
if string(b) != want {
t.Errorf("render produced %q, want %q", b, want)
}
}

// A folder under the templates whose name ends in .html is not a page: the generator reads files only.
func TestDemoGeneratorReadsFilesOnlyFromTheTemplates(t *testing.T) {
templates, out := t.TempDir(), t.TempDir()
if err := os.WriteFile(filepath.Join(templates, "a.html"), []byte(`<p>{{APPLY_FORM}} 2026-10-11</p>`), 0o644); err != nil {
t.Fatal(err)
}
if err := os.MkdirAll(filepath.Join(templates, "folder.html"), 0o755); err != nil {
t.Fatal(err)
}
cmd := exec.Command(nodeOrSkip(t), "scripts/build-demo.mjs", "--date", "2027-03-05", "--out", out, "--templates", templates)
cmd.Dir = "../website"
if b, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("build-demo failed on a folder named .html: %v\n%s", err, b)
}
entries, err := os.ReadDir(out)
if err != nil || len(entries) != 1 || entries[0].Name() != "a.html" {
t.Errorf("output = %v (%v), want only a.html", entries, err)
}
got, _ := os.ReadFile(filepath.Join(out, "a.html"))
if !strings.Contains(string(got), "2027-03-05") {
t.Errorf("the date of the template did not move: %s", got)
}
}
58 changes: 47 additions & 11 deletions scripts/site_docker_claim_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scripts

import (
"fmt"
"os"
"path/filepath"
"regexp"
Expand All @@ -10,16 +11,19 @@ import (
"gopkg.in/yaml.v3"
)

// A page, a README or a Dockerfile that says there is a Docker image ("Official Docker image", "container images", an `ghcr.io/...` image to run) must be
// A page, a README or a Dockerfile that says there is a Docker image ("Official Docker image", "container images", a `ghcr.io/...` image to run) must be
// backed by a workflow that builds AND pushes one. For a long time the landing page said so while the repository only held docker/Dockerfile, no workflow
// pushed an image, and the Dockerfile's own header told people to `docker run` an image that does not resolve.
//
// What it reads: README.md, docker/README.md and docker/Dockerfile, the documentation of the repository (docs/, except the research, PRD and evidence
// folders, which describe history) and everything under website/src (pages, documentation pages). What counts as a claim: "Docker image(s)" or "container
// image(s)" (any case), and a `ghcr.io/` reference. What counts as publishing: a workflow step that uses docker/build-push-action with `push` not false (the
// folders, which describe history) and everything under website/src (pages, documentation pages). What counts as a claim: "Docker image(s)", "container
// image(s)" or "OCI image(s)" (any case; a hyphen, a line break or a non-breaking space `&nbsp;` for the space), a `ghcr.io/` reference, `docker pull` and "Docker Hub". What counts as publishing: a workflow step that uses docker/build-push-action with `push` not false (the
// action's default is not to push), or a `docker push` or `docker buildx build ... --push` command in a `run` script that is not a comment. Workflows are read
// as YAML, both *.yml and *.yaml. A phrase that only says what is NOT done ("no Docker image is published") is a claim too: say it without those words.
var dockerImageClaim = regexp.MustCompile(`(?i)\b(?:docker|container)\s+images?\b|\bghcr\.io/`)
//
// What it does not catch: a phrase split by markup (`<b>Docker</b> image`) or written with another HTML entity, other languages, and other wordings ("pull the
// image from GHCR", "an image on a registry"). It is a guard against the claim that was made, not a proof that no image is claimed.
var dockerImageClaim = regexp.MustCompile(`(?i)\b(?:docker|container|oci)(?:\s|-|&nbsp;|&#160;)+images?\b|\bghcr\.io/|\bdocker\s+pull\b|\bdocker\s+hub\b`)

// dockerRoots are the places the guard reads: a file, or a folder read for the extensions.
var dockerRoots = []struct {
Expand Down Expand Up @@ -162,20 +166,39 @@ func publishingWorkflowsIn(dir string) (publishing []string, read int, err error
return publishing, len(files), nil
}

// dockerGuardFloorProblem says when the guard read too little to mean anything: fewer than 30 files or 5 workflow files point to a wrong path.
func dockerGuardFloorProblem(filesRead, workflowFiles int) string {
if filesRead < 30 {
return fmt.Sprintf("read only %d files: the paths are wrong", filesRead)
}
if workflowFiles < 5 {
return fmt.Sprintf("found %d workflow files: the path is wrong", workflowFiles)
}
return ""
}

func TestDockerGuardFloors(t *testing.T) {
for _, c := range []struct {
files, workflows int
bad bool
}{{30, 5, false}, {29, 5, true}, {30, 4, true}, {0, 0, true}, {500, 40, false}} {
if got := dockerGuardFloorProblem(c.files, c.workflows) != ""; got != c.bad {
t.Errorf("floor(%d files, %d workflows) = problem %v, want %v", c.files, c.workflows, got, c.bad)
}
}
}

func TestRepositoryDoesNotClaimADockerImageWithoutAWorkflowThatPublishesOne(t *testing.T) {
claims, read, problems := dockerClaimsUnder("..")
for _, p := range problems {
t.Error(p)
}
if read < 30 {
t.Fatalf("read only %d files: the paths are wrong", read)
}
publishing, workflows, err := publishingWorkflowsIn("../.github/workflows")
if err != nil {
t.Fatal(err)
}
if workflows < 5 {
t.Fatalf("found %d workflow files: the path is wrong", workflows)
if p := dockerGuardFloorProblem(read, workflows); p != "" {
t.Fatal(p)
}
if len(claims) == 0 || len(publishing) > 0 {
return
Expand All @@ -193,6 +216,15 @@ func TestDockerImageClaimPattern(t *testing.T) {
"a container image": true,
"Container Images": true,
"docker run ghcr.io/x/ci:latest": true,
"Docker&nbsp;image": true,
"Docker&#160;images": true,
"the docker-image": true,
"an OCI image": true,
"an oci-image": true,
"docker pull example/ci": true,
"Docker Hub": true,
"docker build -t x .": false,
"a Dockerfile builds one": false,
"A Dockerfile for self-hosted": false,
"A Docker setup is available": false,
"Containers cannot run the iOS simulator": false,
Expand Down Expand Up @@ -271,6 +303,8 @@ func TestDockerClaimsUnderReadsEveryRoot(t *testing.T) {
write(base, rel, "text "+claim+" text\n")
}
write(base, "docs/research/old.md", "history: "+claim+"\n")
write(base, "docs/prd/plan.md", "history: "+claim+"\n")
write(base, "docs/evidence/log.md", "history: "+claim+"\n")
write(base, "docs/notes.txt", "not markdown: "+claim+"\n")
return base
}
Expand All @@ -290,8 +324,10 @@ func TestDockerClaimsUnderReadsEveryRoot(t *testing.T) {
t.Errorf("a claim planted in %s was not found: %v", want, found)
}
}
if found["docs/research/old.md"] || found["docs/notes.txt"] {
t.Errorf("a claim in a skipped folder or a non-markdown file was reported: %v", found)
for _, skipped := range []string{"docs/research/old.md", "docs/prd/plan.md", "docs/evidence/log.md", "docs/notes.txt"} {
if found[skipped] {
t.Errorf("a claim in %s (a skipped folder or a non-markdown file) was reported: %v", skipped, found)
}
}
if clean, _, p := dockerClaimsUnder(tree("an image")); len(clean) > 0 || len(p) > 0 {
t.Errorf("a clean tree reported %v %v", clean, p)
Expand Down
5 changes: 5 additions & 0 deletions scripts/site_internal_links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ func TestDemoPagesResolveFromTheirTemplates(t *testing.T) {
t.Fatal(err)
}
}
// A folder under demo-templates is not a page, even if its name ends in .html.
if err := os.MkdirAll(filepath.Join(root, "demo-templates", "folder.html"), 0o755); err != nil {
t.Fatal(err)
}
for text, want := range map[string]string{
"[a](/demo/)": "",
"[a](/demo)": "",
Expand All @@ -227,6 +231,7 @@ func TestDemoPagesResolveFromTheirTemplates(t *testing.T) {
"[a](/demo/missing.html)": "/demo/missing.html",
"[a](/demonstration/)": "/demonstration/",
"[a](/other/7-days.html)": "/other/7-days.html",
"[a](/demo/folder.html)": "/demo/folder.html",
} {
got := strings.Join(brokenInternalLinks(root, text), "|")
if got != want {
Expand Down
4 changes: 4 additions & 0 deletions website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

The website and docs (Astro and Starlight). `npm ci`, then `npm run dev` to work on it and `npm run build` to build it into `dist/`.

## The sample dashboard

The pages under `/demo/` are generated on every build (`npm run build` and `npm run dev`) by `scripts/build-demo.mjs` from the templates in `demo-templates/`; `public/demo/` is the output and is not committed. Every date in a template moves by whole days so that the newest day is the day of the build (UTC), and the design-partner link is read from `sellable.json`. **The dates are those of the last deploy:** they stay as they are until the site is built again, so the sample ages between deploys (a scheduled rebuild would keep it fresh and is not set up). The pages say that the data is made up and that the dates move with each build.

## What is sellable

`sellable.json` is the single source of truth for what the site may sell. For each plan it holds:
Expand Down
11 changes: 7 additions & 4 deletions website/scripts/build-demo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// newest day is the build day (or --date / DEMO_DATE), which keeps the sample from looking abandoned. Nothing else changes: the numbers, the
// verdicts and the notice that says the data is made up are the template's. The apply link comes from sellable.json, the one place that knows it.
//
// node scripts/build-demo.mjs [--date YYYY-MM-DD] [--out dir]
// node scripts/build-demo.mjs [--date YYYY-MM-DD] [--out dir] [--templates dir]
import { mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand All @@ -26,7 +26,8 @@ export function shiftDates(text, delta) {
export function render(template, date, applyForm) {
const delta = Math.round((parse(date) - parse(ANCHOR)) / DAY);
if (!template.includes('{{APPLY_FORM}}')) throw new Error('a demo template has no {{APPLY_FORM}} placeholder');
return shiftDates(template, delta).replaceAll('{{APPLY_FORM}}', applyForm);
// A function, not the string: a string replacement reads `$&`, `$1` and `$$` in it, and a URL may hold a `$`.
return shiftDates(template, delta).replaceAll('{{APPLY_FORM}}', () => applyForm);
}

function arg(name) {
Expand All @@ -41,9 +42,11 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
const out = arg('--out') || join(site, 'public', 'demo');
const applyForm = JSON.parse(readFileSync(join(site, 'sellable.json'), 'utf8')).apply.form;
mkdirSync(out, { recursive: true });
const names = readdirSync(join(site, 'demo-templates')).filter((n) => n.endsWith('.html')).sort();
const templates = arg('--templates') || join(site, 'demo-templates');
// Files only: a folder whose name ends in .html is not a page.
const names = readdirSync(templates, { withFileTypes: true }).filter((e) => e.isFile() && e.name.endsWith('.html')).map((e) => e.name).sort();
for (const name of names) {
writeFileSync(join(out, name), render(readFileSync(join(site, 'demo-templates', name), 'utf8'), date, applyForm));
writeFileSync(join(out, name), render(readFileSync(join(templates, name), 'utf8'), date, applyForm));
}
console.log(`build-demo: ${names.length} pages, newest day ${date}`);
}
Loading