carlos / platform Public

test: verify and document static Markdown variants

Exercise negotiated static delivery through the edge with gzip, validators, ranges and shared-cache isolation. Cover twin addition, changes, removal and rollback through signed local releases. Add draft CLI documentation for the separate copy pass.
codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 69ee35bd1173f8c3e8cf9c7e523d85aa7dcf7891 parent fe7eccc
2 files changed, +295 −0
  • docs/site/cli.md +33 −0
  • internal/edge/static_markdown_test.go +262 −0

Intent

Human

<task-notification> <task-id>bhb8j5ntd</task-id> <tool-use-id>toolu_015J4qB63EvVDwrFpMbLnPXh</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/fadfb62a-03f5-4192-bd2b-e123c5e6663f/tasks/bhb8j5ntd.output</output-file> <status>completed</status> <summary>Background command "Wait for Task 1 Codex run to finish" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a7b17df8915eca50c</task-id> <tool-use-id>toolu_01MSB1wvkEdvoz3GXUNok4XM</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/fadfb62a-03f5-4192-bd2b-e123c5e6663f/tasks/a7b17df8915eca50c.output</output-file> <status>completed</status> <summary>Agent "Review Task 1 (spec + quality)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>READY. No P1 or P2 findings. The review found three P3 follow-ups. None of them blocks the merge: - **Extra guard check:** the new hard-tier check runs on every static file served, not just the selected Markdown twin. No current hard-tier rule can tell `page.html` from `page.md`, so it changes no outcome. Removing it would not fail any test, because the existing rewrite check already refuses `/blocked`. - **Empty Accept parameters:** a range like `text/html;;q=0.1` is valid in RFC 9110, but the parser drops it as malformed. That can only cost Markdown a win, never serve it wrongly. - **Test swaps a global:** the tag-budget test replaces the package-wide tag cache. It is restored afterwards, but it is the only test that does this. I ran `go vet ./internal/edge` (clean) and `go test ./internal/edge -run '^TestStaticMarkdown' -count=1` (passed). I did not run the broader regression set or the cross-compile build. The full review is in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/static-markdown-twins/.superpowers/sdd/2026-11-04-static-markdown-twins/task-1-review.md`.</result> <usage><subagent_tokens>97669</subagent_tokens><tool_uses>14</tool_uses><duration_ms>230108</duration_ms></usage> </task-notification>

diff --git a/docs/site/cli.md b/docs/site/cli.md
index 20646aa0c..57f116931 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -403,6 +403,39 @@ app is served only at its own platform address, so `--host` and
carlos deploy --temporary --ttl 3d ./dist
```
+#### Markdown variants for a static site (draft)
+
+<!-- DRAFT. Pending a separate copy pass. -->
+
+Ship `shop/index.html` beside `shop/index.md` to offer HTML and Markdown at
+`/shop/`. For a page at `/page.html`, ship `page.html` beside `page.md`.
+You write and ship both files. No application server or configuration switch
+is needed.
+
+The edge serves the Markdown file when the request's `Accept` header gives
+`text/markdown` a positive quality value (`q`) strictly higher than
+`text/html`. This request prefers Markdown.
+
+```sh
+curl -H 'Accept: text/markdown;q=1, text/html;q=0.5' https://example.com/shop/
+```
+
+Quality defaults to 1 when `q` is omitted. A more specific media range takes
+precedence over a wildcard when determining each type's quality. Equal
+qualities, a missing `Accept` header, or neither type being acceptable all
+fall back to HTML. A page without a Markdown twin also keeps serving HTML.
+A Markdown file on its own does not create an HTML page or a directory index.
+
+Negotiated Markdown has the content type `text/markdown; charset=utf-8`.
+Both representations of a page with a twin include `Vary: Accept`, including
+HEAD, conditional and range responses. Existing `Vary` values are preserved,
+with `Accept-Encoding` included when the response is compressed.
+
+The existing slash redirects and `_redirects` rules apply before selecting
+a representation. For example, `/shop` still redirects to `/shop/` unless
+your redirect rules override that behaviour. You can also request
+`/shop/index.md` or `/page.md` directly as ordinary files.
+
#### Redirects for a static site
Put a file named `_redirects` at the top of the site directory. It uses the
diff --git a/internal/edge/static_markdown_test.go b/internal/edge/static_markdown_test.go
index 42b9eceb9..2009c8a3c 100644
--- a/internal/edge/static_markdown_test.go
+++ b/internal/edge/static_markdown_test.go
@@ -13,6 +13,8 @@ import (
"testing"
"time"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/reqrec"
)
@@ -86,6 +88,266 @@ func TestStaticMarkdownPreference(t *testing.T) {
}
}
+func markdownDeliveryVary(t *testing.T, w *httptest.ResponseRecorder, want bool) {
+ t.Helper()
+ found := false
+ for _, name := range strings.Split(joinHeader(w.Header(), "Vary"), ",") {
+ found = found || strings.EqualFold(strings.TrimSpace(name), "Accept")
+ }
+ if found != want {
+ t.Errorf("Vary = %q, want Accept=%v", w.Header().Values("Vary"), want)
+ }
+}
+
+func markdownEdge(t *testing.T) (*Edge, func(*testing.T, string, map[string]string)) {
+ t.Helper()
+ t.Setenv("CARLOS_EDGE_GZIP", "1")
+ store := release.NewDirStore(filepath.Join(t.TempDir(), "store"))
+ priv, pub := testKeys(t)
+ reg := openReg(t)
+ if err := reg.Upsert(registry.Route{Host: "example.com", Kind: "static", App: "shop", Channel: "canary/x", Status: "ready"}); err != nil {
+ t.Fatal(err)
+ }
+ e, err := New(reg, nil)
+ if err != nil {
+ t.Fatal(err)
+ }
+ e.EnableCache(NewCache(DefaultCacheMaxEntries, DefaultCacheMaxBodyBytes))
+ e.EnableStatic(store, pub, filepath.Join(t.TempDir(), "cache"))
+ e.SetStaticRecheck(0)
+ if err := e.Reload(); err != nil {
+ t.Fatal(err)
+ }
+ return e, func(t *testing.T, version string, files map[string]string) {
+ t.Helper()
+ if files != nil {
+ shipSite(t, store, "shop", version, files)
+ }
+ if err := release.Promote(context.Background(), store, priv, release.OpsAccount, "shop", "canary/x", version); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+func markdownEdgeRequest(e *Edge, method, path, accept, encoding string, extra http.Header) *httptest.ResponseRecorder {
+ r := httptest.NewRequest(method, "http://example.com"+path, nil)
+ r.Header.Set("Accept", accept)
+ r.Header.Set("Accept-Encoding", encoding)
+ for name, values := range extra {
+ r.Header[name] = values
+ }
+ w := httptest.NewRecorder()
+ e.ServeHTTP(w, r)
+ return w
+}
+
+func markdownDecoded(t *testing.T, w *httptest.ResponseRecorder, compressed bool) string {
+ t.Helper()
+ if !compressed {
+ if got := w.Header().Get("Content-Encoding"); got != "" {
+ t.Fatalf("Content-Encoding = %q, want identity", got)
+ }
+ return w.Body.String()
+ }
+ if w.Header().Get("Content-Encoding") != "gzip" {
+ t.Fatalf("Content-Encoding = %q, want gzip", w.Header().Get("Content-Encoding"))
+ }
+ if !strings.Contains(joinHeader(w.Header(), "Vary"), "Accept-Encoding") {
+ t.Errorf("compressed Vary = %q, want Accept-Encoding", w.Header().Values("Vary"))
+ }
+ gz, err := gzip.NewReader(w.Body)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer gz.Close()
+ body, err := io.ReadAll(gz)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(body)
+}
+
+func markdownCacheSize(t *testing.T, e *Edge, want int) {
+ t.Helper()
+ e.cache.mu.Lock()
+ defer e.cache.mu.Unlock()
+ if got := len(e.cache.entries); got != want {
+ t.Fatalf("shared cache entries = %d, want %d", got, want)
+ }
+}
+
+func TestStaticMarkdownDelivery(t *testing.T) {
+ e, promote := markdownEdge(t)
+ bodies := map[string]string{
+ "text/html": strings.Repeat("<p>shop HTML</p>\n", 100),
+ "text/markdown": strings.Repeat("# shop Markdown\n", 120),
+ }
+ promote(t, "v1", map[string]string{
+ "shop/index.html": bodies["text/html"], "shop/index.md": bodies["text/markdown"],
+ "page.html": bodies["text/html"], "page.md": bodies["text/markdown"],
+ "_headers": "/*\n Cache-Control: public, max-age=300\n",
+ })
+ for _, path := range []string{"/shop/", "/page.html"} {
+ t.Run(path, func(t *testing.T) {
+ tags := make(map[string]string)
+ for _, accept := range []string{"text/html", "text/markdown"} {
+ w := markdownEdgeRequest(e, "GET", path, accept, "identity", nil)
+ if w.Code != 200 || markdownDecoded(t, w, false) != bodies[accept] || w.Header().Get("Content-Type") != accept+"; charset=utf-8" {
+ t.Fatalf("baseline %s = %d %v", accept, w.Code, w.Header())
+ }
+ tags[accept] = w.Header().Get("ETag")
+ markdownCacheSize(t, e, 0)
+ }
+ if tags["text/html"] == "" || tags["text/markdown"] == "" || tags["text/html"] == tags["text/markdown"] {
+ t.Fatalf("representation tags = %v, want distinct nonempty tags", tags)
+ }
+ for i, delivery := range []struct{ accept, encoding string }{
+ {"text/html", "identity"}, {"text/markdown", "gzip"},
+ {"text/html", "gzip"}, {"text/markdown", "identity"},
+ {"text/html", "identity"}, {"text/markdown", "gzip"},
+ } {
+ t.Run(fmt.Sprint(i), func(t *testing.T) {
+ accept, encoding := delivery.accept, delivery.encoding
+ other := "text/html"
+ if accept == other {
+ other = "text/markdown"
+ }
+ for _, request := range []struct {
+ name, method string
+ headers http.Header
+ status int
+ body string
+ }{
+ {"full", "GET", nil, 200, bodies[accept]},
+ {"head", "HEAD", nil, 200, ""},
+ {"matching tag", "GET", http.Header{"If-None-Match": {tags[accept]}}, 304, ""},
+ {"matching head", "HEAD", http.Header{"If-None-Match": {tags[accept]}}, 304, ""},
+ {"other tag", "GET", http.Header{"If-None-Match": {tags[other]}}, 200, bodies[accept]},
+ {"range", "GET", http.Header{"Range": {"bytes=0-15"}}, 206, bodies[accept][:16]},
+ } {
+ t.Run(request.name, func(t *testing.T) {
+ w := markdownEdgeRequest(e, request.method, path, accept, encoding, request.headers)
+ if w.Code != request.status {
+ t.Fatalf("status = %d, want %d: %v", w.Code, request.status, w.Header())
+ }
+ compressed := encoding == "gzip" && request.method == "GET" && request.status == 200
+ if got := markdownDecoded(t, w, compressed); got != request.body {
+ t.Errorf("decoded body = %q, want %q", got, request.body)
+ }
+ if request.status != 304 && w.Header().Get("Content-Type") != accept+"; charset=utf-8" {
+ t.Errorf("Content-Type = %q, want %s", w.Header().Get("Content-Type"), accept)
+ }
+ if w.Header().Get("ETag") != tags[accept] || w.Header().Get("X-Carlos-Version") != "v1" {
+ t.Errorf("validator/version = %v, want %s / v1", w.Header(), tags[accept])
+ }
+ if w.Header().Get("Cache-Control") != "public, max-age=300" {
+ t.Errorf("Cache-Control = %q", w.Header().Get("Cache-Control"))
+ }
+ if request.status == 206 && w.Header().Get("Content-Range") != fmt.Sprintf("bytes 0-15/%d", len(bodies[accept])) {
+ t.Errorf("Content-Range = %q", w.Header().Get("Content-Range"))
+ }
+ markdownDeliveryVary(t, w, true)
+ markdownCacheSize(t, e, 0)
+ })
+ }
+ })
+ }
+ for _, accept := range []string{"text/html", "text/markdown"} {
+ other := "text/html"
+ if accept == other {
+ other = "text/markdown"
+ }
+ for _, encoding := range []string{"identity", "gzip"} {
+ key := CacheKey{Host: "example.com", Method: "GET", Path: path}
+ seed := &CachedResponse{
+ StatusCode: 200, Body: []byte(bodies[other]), StoredAt: time.Now(), TTL: time.Minute,
+ Header: http.Header{"Content-Type": {other + "; charset=utf-8"}, "Etag": {tags[other]}, "X-Carlos-Version": {"v0"}},
+ }
+ e.cache.Put(key, "", seed)
+ r := httptest.NewRequest("GET", "http://example.com"+path, nil)
+ r.Header.Set("Accept", accept)
+ r.Header.Set("Accept-Encoding", encoding)
+ if got, hit := e.cache.GetFor(key, r); !hit || string(got.Body) != bodies[other] {
+ t.Fatal("wrong representation was not available as a shared cache hit")
+ }
+ w := markdownEdgeRequest(e, "GET", path, accept, encoding, nil)
+ if w.Code != 200 || markdownDecoded(t, w, encoding == "gzip") != bodies[accept] || w.Header().Get("Content-Type") != accept+"; charset=utf-8" || w.Header().Get("ETag") != tags[accept] || w.Header().Get("X-Carlos-Version") != "v1" {
+ t.Fatalf("seeded cache %s/%s = %d %v", accept, encoding, w.Code, w.Header())
+ }
+ markdownDeliveryVary(t, w, true)
+ markdownCacheSize(t, e, 1)
+ if got, hit := e.cache.GetFor(key, r); !hit || string(got.Body) != bodies[other] {
+ t.Fatal("static response replaced the seeded shared cache entry")
+ }
+ e.cache.PurgeHost("example.com")
+ }
+ }
+ })
+ }
+}
+
+func TestStaticMarkdownRelease(t *testing.T) {
+ e, promote := markdownEdge(t)
+ html := strings.Repeat("<p>shop HTML</p>\n", 100)
+ versions := []struct{ version, markdown string }{
+ {"v1", ""}, {"v2", strings.Repeat("# shop Markdown v2\n", 100)},
+ {"v3", strings.Repeat("# shop Markdown v3\n", 100)}, {"v4", ""},
+ }
+ tags := make(map[string]string)
+ previousTag := ""
+ for _, index := range []int{0, 1, 2, 3, 2, 1, 0} {
+ v := versions[index]
+ t.Run(v.version, func(t *testing.T) {
+ var files map[string]string
+ if tags[v.version] == "" {
+ files = map[string]string{"shop/index.html": html, "_headers": "/*\n Cache-Control: public, max-age=300\n"}
+ if v.markdown != "" {
+ files["shop/index.md"] = v.markdown
+ }
+ }
+ promote(t, v.version, files)
+ wantBody, wantType := html, "text/html; charset=utf-8"
+ if v.markdown != "" {
+ wantBody, wantType = v.markdown, "text/markdown; charset=utf-8"
+ }
+ w := markdownEdgeRequest(e, "GET", "/shop/", "text/markdown", "identity", http.Header{"If-None-Match": {previousTag}})
+ if w.Code != 200 || markdownDecoded(t, w, false) != wantBody || w.Header().Get("Content-Type") != wantType || w.Header().Get("X-Carlos-Version") != v.version {
+ t.Fatalf("release %s = %d %v", v.version, w.Code, w.Header())
+ }
+ markdownDeliveryVary(t, w, v.markdown != "")
+ markdownCacheSize(t, e, 0)
+ tag := w.Header().Get("ETag")
+ if tag == "" || tag == previousTag {
+ t.Fatalf("tag = %q, previous %q; want a new validator", tag, previousTag)
+ }
+ if old := tags[v.version]; old != "" && tag != old {
+ t.Errorf("rollback tag = %q, want original %q", tag, old)
+ }
+ if v.markdown == "" && tags["v1"] != "" && tag != tags["v1"] {
+ t.Errorf("unchanged HTML tag = %q, want %q", tag, tags["v1"])
+ }
+ tags[v.version], previousTag = tag, tag
+ for _, accept := range []string{"text/html", "text/markdown"} {
+ body, ctype, etag := wantBody, wantType, tag
+ if accept == "text/html" {
+ body, ctype, etag = html, "text/html; charset=utf-8", tags["v1"]
+ }
+ for _, encoding := range []string{"identity", "gzip"} {
+ w := markdownEdgeRequest(e, "GET", "/shop/", accept, encoding, nil)
+ if w.Code != 200 || markdownDecoded(t, w, encoding == "gzip") != body || w.Header().Get("Content-Type") != ctype || w.Header().Get("ETag") != etag || w.Header().Get("X-Carlos-Version") != v.version {
+ t.Errorf("%s/%s/%s = %d %v", v.version, accept, encoding, w.Code, w.Header())
+ }
+ if w.Header().Get("Cache-Control") != "public, max-age=300" {
+ t.Errorf("Cache-Control = %q", w.Header().Get("Cache-Control"))
+ }
+ markdownDeliveryVary(t, w, v.markdown != "")
+ markdownCacheSize(t, e, 0)
+ }
+ }
+ })
+ }
+}
+
func markdownTree(t *testing.T, files map[string]string) servedTree {
t.Helper()
tree := servedTree{dir: t.TempDir()}