runner: Design option pages need release/preview.json at mockups/<task>
Review fix round 1 of Task 2. sitePage accepted an output above
mockups/<task> or an option's own folder, so a page could pass the check
yet not be served at <preview-root>/<page>/ (spec 8.5, Task 12).
workPages now requires the snapshot's output to be exactly
mockups/<task> for this step's task (designstep.ErrSiteRoot otherwise)
and checks each page as <page>/index.html directly under that root, one
folder deep. submit_candidate refuses ErrSiteRoot with a fixed text:
release/preview.json must be {"output": "mockups/<task>"}.
TDD evidence
- go test ./internal/runner/designstep/ -run TestSubmit
RED 1: build failed (undefined: ErrSiteRoot). RED 2 (sentinel only):
"not the task's root: submit_candidate could not check the option
pages ... want release/preview.json must be {"output":
"mockups/<task>"}". GREEN after the change.
- go test ./internal/runner/thin/ -run 'TestDesignSubmitPage|TestDesignWorkPages'
(Task 3's untracked thin test files hidden with -overlay, since they
do not build yet) RED: "output above the task: Recorded 3 options";
"output mockups: [newsroom-2] <nil>, want ErrSiteRoot" and likewise
for mockups/tk1/newsroom, mockups/tk2, site. GREEN after the change.
TestDesignWorkPagesNeedTheTaskRoot also exports the committed site
with the preview's own exportStatic and finds every accepted page at
<root>/<page>/index.html.
- Wider: thin -run 'Design|TestRender|TestWorkSite|TestSnapshot|
TestPreview|MCP|Tool|Prompt' ok (224 s); designstep, thintest Design ok.
- Mutations (via -overlay, each alone): root check removed, loosened to
a mockups prefix, ignoring the task id, page looked up at the root,
one-folder guard (first a build kill; a deeper "newsroom/sub" case
added, then KILLED), ErrSiteRoot text mapping: all KILLED.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+85
−39
internal/runner/designstep/designstep.go+9 −0internal/runner/designstep/designstep_feedback_test.go+2 −0internal/runner/thin/design_feedback_test.go+60 −18internal/runner/thin/render_page.go+14 −21
diff --git a/internal/runner/designstep/designstep.go b/internal/runner/designstep/designstep.go| index 94e5e18d..7f485c56 100644 |
| --- a/internal/runner/designstep/designstep.go |
| +++ b/internal/runner/designstep/designstep.go |
| @@ -39,6 +39,12 @@ const ( |
| // refusal; any other failed check could not be made. |
| var ErrRenderRefused = errors.New("designstep: the instance refused the render") |
| +// ErrSiteRoot marks a WorkPages snapshot whose site is not the task's |
| +// options folder: release/preview.json's output must be exactly |
| +// mockups/<task>, so each page is served at <preview-root>/<page>/ |
| +// (spec 8.5). |
| +var ErrSiteRoot = errors.New("designstep: release/preview.json does not name mockups/<task>") |
| + |
| // Fixed replies. |
| const ( |
| // RenderRefusedText and RenderUnconfirmedText answer render_page for |
| @@ -63,6 +69,7 @@ const ( |
| submitBusyText = "submit_candidate could not check the option pages: the workspace could not be paused for its snapshot. Nothing was recorded: call it again shortly with the same options." |
| submitNoSiteText = "submit_candidate refused: the option pages could not be checked because your workspace has no site: release/preview.json is missing or refused, or the site breaks the export's rules or caps. Each page is a folder under mockups/<task>/, inside the folder release/preview.json names. Nothing was recorded: fix it and call again." |
| submitUncheckedText = "submit_candidate could not check the option pages in your workspace. Nothing was recorded: call it again with the same options." |
| + submitRootText = "submit_candidate refused: release/preview.json must be {\"output\": \"mockups/<task>\"}, with this step's task id, so each option's page is <page>/index.html directly under the preview's root. Nothing was recorded: fix it and call again." |
| ) |
| // capture is one capture render_page made in this attempt, as it wrote |
| @@ -287,6 +294,8 @@ func (a *Attempt) pagesRefusal(ctx context.Context, opts []wire.DesignOption) st |
| } |
| missing, err := a.WorkPages(ctx, pages) |
| switch { |
| + case errors.Is(err, ErrSiteRoot): |
| + return submitRootText |
| case err != nil && render.ErrorCode(err) == renderpage.CodeBusy: |
| return submitBusyText |
| case err != nil && render.ErrorCode(err) == renderpage.CodeNoSite: |
diff --git a/internal/runner/designstep/designstep_feedback_test.go b/internal/runner/designstep/designstep_feedback_test.go| index 20975135..c257f1ad 100644 |
| --- a/internal/runner/designstep/designstep_feedback_test.go |
| +++ b/internal/runner/designstep/designstep_feedback_test.go |
| @@ -245,6 +245,8 @@ func TestSubmitPageMustExist(t *testing.T) { |
| r.refused(t, "busy", submitArgs(explorations(3)...), "could not be paused") |
| r.pagesErr = renderpage.Refuse(renderpage.CodeNoSite, "no config") |
| r.refused(t, "no site", submitArgs(explorations(3)...), "release/preview.json") |
| + r.pagesErr = fmt.Errorf("output mockups: %w", ErrSiteRoot) |
| + r.refused(t, "not the task's root", submitArgs(explorations(3)...), `release/preview.json must be {"output": "mockups/<task>"}`) |
| r.pagesErr = errors.New("disk") |
| r.refused(t, "another error", submitArgs(explorations(3)...), "could not check") |
| r.pagesErr = nil |
diff --git a/internal/runner/thin/design_feedback_test.go b/internal/runner/thin/design_feedback_test.go| index ea29b9ef..403d4f93 100644 |
| --- a/internal/runner/thin/design_feedback_test.go |
| +++ b/internal/runner/thin/design_feedback_test.go |
| @@ -5,6 +5,7 @@ package thin |
| import ( |
| "context" |
| "encoding/json" |
| + "errors" |
| "os" |
| "path/filepath" |
| "slices" |
| @@ -12,6 +13,7 @@ import ( |
| "testing" |
| "amadan.net/oficina/equipo/internal/runner" |
| + "amadan.net/oficina/equipo/internal/runner/designstep" |
| "amadan.net/oficina/equipo/internal/runner/render" |
| "amadan.net/oficina/equipo/internal/runner/renderpage" |
| "amadan.net/oficina/equipo/internal/runner/workspace" |
| @@ -120,40 +122,80 @@ func TestDesignSubmitPageDeletedAfterRender(t *testing.T) { |
| os.Remove(filepath.Join(ws, "release/preview.json")) |
| refused("no site", "release/preview.json is missing") |
| os.WriteFile(filepath.Join(ws, "release/preview.json"), []byte(`{"output": "mockups/tk1"}`), 0o644) |
| + // The site is not the task's folder: refused, saying what it must be. |
| + os.WriteFile(filepath.Join(ws, "release/preview.json"), []byte(`{"output": "mockups"}`), 0o644) |
| + refused("output above the task", `release/preview.json must be {"output": "mockups/<task>"}`) |
| + os.WriteFile(filepath.Join(ws, "release/preview.json"), []byte(`{"output": "mockups/tk1"}`), 0o644) |
| + if text, isError := call("submit_candidate", threeOptions); isError { |
| + t.Fatalf("output restored: %q", text) |
| + } |
| // The sandbox cannot be paused. |
| spec.sandbox.drop() |
| refused("no sandbox", "could not be paused") |
| } |
| -// TestDesignWorkPagesFollowTheSite: a page is mockups/<task>/<page>/ |
| -// in the workspace, found in the snapshot of the site |
| -// release/preview.json names, wherever that folder is: in it, above it, |
| -// or the page folder itself; a page outside the site is missing. |
| -func TestDesignWorkPagesFollowTheSite(t *testing.T) { |
| +// TestDesignWorkPagesNeedTheTaskRoot (spec 8.3, 8.5): a page is |
| +// <page>/index.html directly under the site release/preview.json names, |
| +// which must be exactly mockups/<task> (this step's task), so the |
| +// preview serves it at <preview-root>/<page>/. Any other output, above |
| +// the task's folder, an option's own folder or elsewhere, is refused |
| +// (designstep.ErrSiteRoot), whatever it holds. |
| +func TestDesignWorkPagesNeedTheTaskRoot(t *testing.T) { |
| ctx := context.Background() |
| e, _ := renderEngineer(t, t.TempDir()) |
| h := &sandboxHandle{} |
| h.keep(stepSandbox(t, nil, "sleep 60")) |
| row := stepRow{DispatchCommand: designDispatch("s_site", 1)} |
| - for output, want := range map[string][]string{ |
| - "mockups/tk1": {"newsroom-2"}, |
| - "mockups": {"newsroom-2"}, |
| - "mockups/tk1/newsroom": {"writing-desk", "newsroom-2"}, |
| - "site": {"writing-desk", "newsroom", "newsroom-2"}, |
| - } { |
| + pages := []string{"writing-desk", "newsroom", "newsroom-2"} |
| + site := func(output string) map[string]string { |
| files := optionSite() |
| files["release/preview.json"] = `{"output": "` + output + `"}` |
| files["mockups/tk1/newsroom-2/about.html"] = "no index" |
| + files["mockups/tk1/newsroom/sub/index.html"] = "a deeper folder" |
| + files["mockups/tk2/index.html"] = "<h1>Another task</h1>" |
| + files["mockups/tk2/writing-desk/index.html"] = "another task's page" |
| files["site/index.html"] = "<h1>Site</h1>" |
| - files["site/mockups/tk1/writing-desk/index.html"] = "not the page" |
| - ws := workTree(t, files, nil) |
| - s := renderStep{row: row, tree: workspace.TaskTree{Dir: ws}, sandbox: h} |
| - got, err := e.workPages(ctx, s, []string{"writing-desk", "newsroom", "newsroom-2"}) |
| - if err != nil || !slices.Equal(got, want) { |
| - t.Errorf("output %s: missing %v %v, want %v", output, got, err, want) |
| + files["site/writing-desk/index.html"] = "not the page" |
| + return files |
| + } |
| + for _, output := range []string{"mockups", "mockups/tk1/newsroom", "mockups/tk2", "site"} { |
| + ws := workTree(t, site(output), nil) |
| + got, err := e.workPages(ctx, renderStep{row: row, tree: workspace.TaskTree{Dir: ws}, sandbox: h}, pages) |
| + if !errors.Is(err, designstep.ErrSiteRoot) || got != nil { |
| + t.Errorf("output %s: %v %v, want ErrSiteRoot", output, got, err) |
| } |
| } |
| - ws := workTree(t, optionSite(), nil) |
| + files := site("mockups/tk1") |
| + ws := workTree(t, files, nil) |
| + missing, err := e.workPages(ctx, renderStep{row: row, tree: workspace.TaskTree{Dir: ws}, sandbox: h}, pages) |
| + if err != nil || !slices.Equal(missing, []string{"newsroom-2"}) { |
| + t.Fatalf("mockups/tk1: missing %v %v", missing, err) |
| + } |
| + // A page is one folder directly under the root, never a deeper one. |
| + if deeper, err := e.workPages(ctx, renderStep{row: row, tree: workspace.TaskTree{Dir: ws}, sandbox: h}, []string{"newsroom/sub", "../tk1"}); err != nil || !slices.Equal(deeper, []string{"newsroom/sub", "../tk1"}) { |
| + t.Fatalf("deeper pages: missing %v %v", deeper, err) |
| + } |
| + // Every page accepted is reachable at <root>/<page>/index.html in the |
| + // site the preview publishes (exportPreview's export of the commit). |
| + gitDir, sha := siteRepo(t, files) |
| + cfg, err := readPreviewConfig(ctx, "/usr/bin/git", gitDir, sha) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + stage := filepath.Join(t.TempDir(), "preview") |
| + if _, err := exportStatic(ctx, "/usr/bin/git", gitDir, sha, cfg.Output, stage, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + served := staged(t, stage) |
| + for _, p := range pages { |
| + if slices.Contains(missing, p) { |
| + continue |
| + } |
| + if body, ok := served[p+"/index.html"]; !ok || body != files["mockups/tk1/"+p+"/index.html"] { |
| + t.Errorf("accepted page %s is not at <root>/%s/index.html in the preview: %v", p, p, served) |
| + } |
| + } |
| + ws = workTree(t, optionSite(), nil) |
| os.Remove(filepath.Join(ws, "release/preview.json")) |
| if _, err := e.workPages(ctx, renderStep{row: row, tree: workspace.TaskTree{Dir: ws}, sandbox: h}, []string{"newsroom"}); render.ErrorCode(err) != renderpage.CodeNoSite { |
| t.Fatalf("no site: %v", err) |
diff --git a/internal/runner/thin/render_page.go b/internal/runner/thin/render_page.go| index b8b892a8..bf64edec 100644 |
| --- a/internal/runner/thin/render_page.go |
| +++ b/internal/runner/thin/render_page.go |
| @@ -10,6 +10,7 @@ import ( |
| "path/filepath" |
| "strings" |
| + "amadan.net/oficina/equipo/internal/runner/designstep" |
| "amadan.net/oficina/equipo/internal/runner/render" |
| "amadan.net/oficina/equipo/internal/runner/renderpage" |
| "amadan.net/oficina/equipo/internal/runner/workspace" |
| @@ -237,9 +238,11 @@ func (s *State) countRender(ctx context.Context, r stepRow, captures int) (rende |
| // snapshot of s's workspace, taken as render_page takes its work tree |
| // (the paused sandbox, sandboxHandle.snapshot) into a stage of the |
| // step's scratch that is removed after: never an earlier render's |
| -// export. A page outside the site release/preview.json names is |
| -// missing. A sandbox that cannot be paused is busy; a site the rules or |
| -// caps refuse is no_site (renderpage's codes, as Site has them). |
| +// export. The site must be exactly mockups/<task> (designstep.ErrSiteRoot |
| +// otherwise), so each page is <page>/index.html at its root, which the |
| +// preview serves at <preview-root>/<page>/ (spec 8.5). A sandbox that |
| +// cannot be paused is busy; a site the rules or caps refuse is no_site |
| +// (renderpage's codes, as Site has them). |
| func (e *Engineer) workPages(ctx context.Context, s renderStep, pages []string) ([]string, error) { |
| stage := filepath.Join(stepRender{e, s}.Scratch(), "pages") |
| defer os.RemoveAll(stage) |
| @@ -254,6 +257,9 @@ func (e *Engineer) workPages(ctx context.Context, s renderStep, pages []string) |
| case err != nil: |
| return nil, err |
| } |
| + if ex.Output != optionsRoot(s.row.TaskID) { |
| + return nil, fmt.Errorf("%w: output %q", designstep.ErrSiteRoot, ex.Output) |
| + } |
| root, err := os.OpenRoot(stage) |
| if err != nil { |
| return nil, err |
| @@ -261,9 +267,9 @@ func (e *Engineer) workPages(ctx context.Context, s renderStep, pages []string) |
| defer root.Close() |
| var missing []string |
| for _, p := range pages { |
| - rel, ok := sitePage(ex.Output, s.row.TaskID, p) |
| + ok := cleanPreviewPath(p) && !strings.Contains(p, "/") |
| if ok { |
| - info, err := root.Lstat(rel) |
| + info, err := root.Lstat(p + "/index.html") |
| ok = err == nil && info.Mode().IsRegular() |
| } |
| if !ok { |
| @@ -273,19 +279,6 @@ func (e *Engineer) workPages(ctx context.Context, s renderStep, pages []string) |
| return missing, nil |
| } |
| -// sitePage is page's index.html (mockups/<task>/<page>/index.html in the |
| -// workspace) as a path in the site exported from output, and whether the |
| -// site holds that folder at all. |
| -func sitePage(output, task, page string) (string, bool) { |
| - dir := "mockups/" + task + "/" + page |
| - if !cleanPreviewPath(dir) || strings.Count(dir, "/") != 2 || !cleanPreviewPath(output) { |
| - return "", false |
| - } |
| - switch { |
| - case dir == output: |
| - return "index.html", true |
| - case strings.HasPrefix(dir, output+"/"): |
| - return dir[len(output)+1:] + "/index.html", true |
| - } |
| - return "", false |
| -} |
| +// optionsRoot is the folder a task's options live in, which |
| +// release/preview.json must name for them: mockups/<task>. |
| +func optionsRoot(task string) string { return "mockups/" + task } |