Skip to content

Build and serve the reference from a git ref (--base <ref>) #128

Closed as not planned

Description

@tmashara

What
Build and serve the reference side from a git ref: --base <ref> (or config base) creates a detached worktree of that commit, runs the project's build, serves it on a free port, uses it as the right origin, and removes the worktree afterwards.

Why
Base build vs change build is the comparison the skill recommends first. It was the decisive signal in the metabase.com run (feedback.md, item 1). Today the agent sets it up by hand every time: worktree, install, build, serve, pick two ports (skill Loop, step 1). That is five steps before the first shot, and each one can go wrong quietly. A stale build or the wrong commit gives a clean run that proves nothing.

@beprajwal/visual-diff does this with run --at <ref>:

  • a detached worktree under its own cache dir; it never touches the user's tree, index or HEAD;
  • every path asserted to be inside that dir before anything is deleted;
  • worktrees orphaned by a crash reaped at the start of the next run;
  • install with the package manager the lockfile names;
  • the server command run with $PORT from an OS-allocated port;
  • readiness polled, and the server log kept, so a failure prints its last lines.

#52 decided against a built-in --serve <dir>, because npx serve with serve.json already covers serving. This keeps that decision: the serve command stays the user's, and renderdiff only owns the worktree lifecycle, the build and the port.

How

base: {
  ref: "origin/main",                  // --base <ref> overrides
  build: "npm ci && npm run build",
  serve: "npx serve -l $PORT dist",
}
  • Worktree at <out>/.cache/base-<sha>, which survives the out-dir wipe as the right-side cache does. Reuse the build when the sha matches, so --rerun-failed doesn't rebuild.
  • If the build fails or the server never answers: exit 2 with the log tail.
  • results.json meta records the ref and sha the reference was built from, and the report says "reference: build of <sha>".

Open questions: is this worth it over a documented script in the skill? How do we handle monorepos and builds that need env vars? Can the worktree reuse the main tree's node_modules instead of a full install?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions