carlos / platform Public

test: demo e2e downloads the locked closure before building

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev 2eec87e9a98f3a6f5c12c3653a014cd0f73784fe parent a2091e3
2 files changed, +55 −108
  • internal/console/demo_e2e_test.go +55 −72
  • internal/console/testdata/demo-stdlib/main.go +0 −36

CI passed — run details

diff --git a/internal/console/demo_e2e_test.go b/internal/console/demo_e2e_test.go
index fb6b08bbf..b42706a94 100644
--- a/internal/console/demo_e2e_test.go
+++ b/internal/console/demo_e2e_test.go
@@ -32,24 +32,18 @@ import (
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
- "golang.org/x/mod/module"
"golang.org/x/net/websocket"
)
// Only the compiler and root launcher are substituted in this local witness.
// Admission, box authentication, grants, uploads, release signing, record and
-// policy reconciliation and exact-host edge requests use real code. SQLite is
-// covered when the locked dependency closure is cached (R23).
-func TestDemoSourceToLiveAndUpdate(t *testing.T) { testDemoSourceToLiveAndUpdate(t, false) }
-func TestDemoSourceToLiveAndUpdateWithoutClosure(t *testing.T) {
- testDemoSourceToLiveAndUpdate(t, true)
-}
-func testDemoSourceToLiveAndUpdate(t *testing.T, forceFileFixture bool) {
+// policy reconciliation, SQLite and exact-host edge requests use real code.
+func TestDemoSourceToLiveAndUpdate(t *testing.T) {
if os.Getenv("CARLOS_DEMO_TOOLCHAIN_DIR") != "" {
t.Fatal("local witness requires an absent toolchain bundle; run the designated dev witness for root compilation")
}
- t.Log("R6: no real toolchain bundle: fake builder returns prebuilt linux-arm64 output; native build uses a local-only Go 1.26.0 directive; R23 permits a stdlib file-persistence fixture when the locked closure is absent. Submitted source retains the locked Go version. This is not kernel or dev deployment evidence.")
- archives, arm, native := demoE2EBuilds(t, forceFileFixture)
+ t.Log("R6: no real toolchain bundle: fake builder returns prebuilt linux-arm64 output; native build uses a local-only Go 1.26.0 directive; R23b downloads and verifies the locked closure before building the real starter offline. Submitted source retains the locked Go version. This is not kernel or dev deployment evidence.")
+ archives, arm, native := demoE2EBuilds(t)
started := time.Now()
s, _ := demoJobServer(t)
// Configuration fixtures may create an account and box, but no demo rows,
@@ -465,25 +459,12 @@ func demoE2EJSON(t *testing.T, c *http.Client, r *http.Request, want int) map[st
return value
}
-func demoE2EBuilds(t *testing.T, forceFileFixture bool) (archives [2][]byte, arm [2][]byte, native [2]string) {
+func demoE2EBuilds(t *testing.T) (archives [2][]byte, arm [2][]byte, native [2]string) {
t.Helper()
- cmd := exec.CommandContext(t.Context(), "go", "env", "GOMODCACHE")
- rawCache, err := cmd.Output()
- if err != nil {
- t.Fatal(err)
- }
lock, err := demobuild.DefaultLock()
if err != nil {
t.Fatal(err)
}
- cached := demoE2EClosureCached(strings.TrimSpace(string(rawCache)), lock)
- if forceFileFixture {
- cached = false
- t.Log("R23: forcing the missing-closure path for covering-test evidence")
- }
- if !cached {
- t.Log("R23 FALLBACK: locked Rastrillo closure unavailable or deliberately excluded; compiling stdlib file-persistence fixture. SQLite internals are NOT covered. Submitted archive remains the locked starter.")
- }
for i, revision := range []string{"one", "two"} {
dir := t.TempDir()
@@ -528,24 +509,30 @@ func demoE2EBuilds(t *testing.T, forceFileFixture bool) (archives [2][]byte, arm
t.Fatal("fixture exceeds compressed cap")
}
- if !cached {
- raw, err := os.ReadFile("testdata/demo-stdlib/main.go")
- if err != nil {
- t.Fatal(err)
- }
- raw = bytes.ReplaceAll(raw, []byte(`const revision = "one"`), []byte(`const revision = "`+revision+`"`))
- if err := os.WriteFile(filepath.Join(dir, "main.go"), raw, 0600); err != nil {
- t.Fatal(err)
- }
- if err := os.WriteFile(filepath.Join(dir, "go.mod"), []byte("module demo.local/app\n\ngo 1.26.0\n"), 0600); err != nil {
- t.Fatal(err)
+ if i == 0 {
+ // R23b: warm the default cache using the public proxy and sumdb.
+ // Both revisions then build the real starter without network access.
+ for _, m := range lock.Modules {
+ cmd := exec.CommandContext(t.Context(), "go", "mod", "download", "-json", m.Path+"@"+m.Version)
+ cmd.Dir = dir
+ cmd.Env = append(os.Environ(), "GOPROXY=https://proxy.golang.org,direct", "GOSUMDB=sum.golang.org", "GOPRIVATE=", "GONOPROXY=none", "GONOSUMDB=none", "GOENV=off", "GOTOOLCHAIN=local", "GOWORK=off", "GOFLAGS=")
+ var stderr bytes.Buffer
+ cmd.Stderr = &stderr
+ out, err := cmd.Output()
+ if err != nil {
+ t.Fatalf("download locked demo closure %s@%s before offline build: %v\n%s\n%s", m.Path, m.Version, err, out, stderr.String())
+ }
+ if err := demoE2EVerifyDownload(out, m); err != nil {
+ t.Fatalf("verify locked demo closure %s@%s before offline build: %v", m.Path, m.Version, err)
+ }
}
}
+
for _, arch := range []string{"arm64", runtime.GOARCH} {
output := filepath.Join(t.TempDir(), "app")
cmd := exec.CommandContext(t.Context(), "go", "build", "-mod=readonly", "-trimpath", "-buildvcs=false", "-o", output, ".")
cmd.Dir = dir
- cmd.Env = append(os.Environ(), "GOOS="+runtime.GOOS, "GOARCH="+arch, "CGO_ENABLED=0", "GOPROXY=off", "GOSUMDB=off", "GOTOOLCHAIN=local", "GOWORK=off", "GOFLAGS=")
+ cmd.Env = append(os.Environ(), "GOOS="+runtime.GOOS, "GOARCH="+arch, "CGO_ENABLED=0", "GOPROXY=off", "GOSUMDB=off", "GOTOOLCHAIN=local", "GOWORK=off", "GOFLAGS=-mod=readonly")
if arch == "arm64" {
cmd.Env = append(cmd.Env, "GOOS=linux")
}
@@ -687,44 +674,40 @@ func demoE2EEdge(t *testing.T, component string, cfg demo.Config, reg *registry.
})
return e, err
}
-func demoE2EClosureCached(cache string, lock demobuild.Lock) bool {
- for _, m := range lock.Modules {
- path, err := module.EscapePath(m.Path)
- if err != nil {
- return false
- }
- version, err := module.EscapeVersion(m.Version)
- if err != nil {
- return false
- }
- for _, name := range []string{filepath.Join(cache, path+"@"+version, "go.mod"), filepath.Join(cache, "cache/download", path, "@v", version+".mod")} {
- if st, err := os.Stat(name); err != nil || !st.Mode().IsRegular() {
- return false
- }
- }
+func demoE2EVerifyDownload(raw []byte, want demobuild.Module) error {
+ var got struct{ Path, Version, Sum, GoModSum, Error string }
+ if err := json.Unmarshal(raw, &got); err != nil {
+ return fmt.Errorf("decode go mod download output: %w", err)
}
- return true
-}
-func TestDemoE2EClosureSelection(t *testing.T) {
- cache := t.TempDir()
- lock := demobuild.Lock{Modules: []demobuild.Module{{Path: "example.com/module", Version: "v1.0.0"}}}
- if demoE2EClosureCached(cache, lock) {
- t.Fatal("absent closure accepted")
- }
- for _, name := range []string{"example.com/module@v1.0.0/go.mod", "cache/download/example.com/module/@v/v1.0.0.mod"} {
- file := filepath.Join(cache, name)
- if err := os.MkdirAll(filepath.Dir(file), 0755); err != nil {
- t.Fatal(err)
- }
- if err := os.WriteFile(file, []byte("module example.com/module\n"), 0600); err != nil {
- t.Fatal(err)
- }
+ if got.Error != "" {
+ return fmt.Errorf("go mod download: %s", got.Error)
+ }
+ if got.Path != want.Path || got.Version != want.Version || got.Sum != want.Sum || got.GoModSum != want.GoModSum {
+ return fmt.Errorf("download does not match lock: got %s@%s sum=%q go.mod=%q; want %s@%s sum=%q go.mod=%q", got.Path, got.Version, got.Sum, got.GoModSum, want.Path, want.Version, want.Sum, want.GoModSum)
}
- if !demoE2EClosureCached(cache, lock) {
- t.Fatal("cached closure ignored")
+ return nil
+}
+
+func TestDemoE2EDownloadMatchesLock(t *testing.T) {
+ want := demobuild.Module{Path: "example.com/module", Version: "v1.0.0", Sum: "h1:module", GoModSum: "h1:gomod"}
+ for _, field := range []string{"", "Path", "Version", "Sum", "GoModSum", "Error"} {
+ t.Run("changed-"+field, func(t *testing.T) {
+ got := map[string]string{"Path": want.Path, "Version": want.Version, "Sum": want.Sum, "GoModSum": want.GoModSum}
+ if field != "" {
+ got[field] = "unexpected"
+ }
+ raw, err := json.Marshal(got)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := demoE2EVerifyDownload(raw, want); (err != nil) != (field != "") {
+ t.Fatalf("changed %q: verification error = %v", field, err)
+ }
+ })
}
- lock.Modules = append(lock.Modules, demobuild.Module{Path: "example.com/missing", Version: "v1.0.0"})
- if demoE2EClosureCached(cache, lock) {
- t.Fatal("partial closure accepted")
+ for _, raw := range []string{`{`, `{}`, `{"Path":"example.com/module","Version":"v1.0.0"}`} {
+ if err := demoE2EVerifyDownload([]byte(raw), want); err == nil {
+ t.Fatalf("accepted invalid or incomplete download: %s", raw)
+ }
}
}
diff --git a/internal/console/testdata/demo-stdlib/main.go b/internal/console/testdata/demo-stdlib/main.go
deleted file mode 100644
index 41a1a8b4c..000000000
--- a/internal/console/testdata/demo-stdlib/main.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package main
-
-import (
- "fmt"
- "log"
- "net"
- "net/http"
- "os"
-)
-
-const revision = "one"
-
-func main() {
- listener, err := net.Listen("unix", os.Getenv("CARLOS_SOCKET"))
- if err != nil {
- log.Fatal(err)
- }
- defer listener.Close()
- handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Cache-Control", "no-store")
- db := os.Getenv("CARLOS_DB")
- if r.Method == http.MethodPost {
- if err := os.WriteFile(db, []byte(r.URL.Query().Get("value")), 0600); err != nil {
- http.Error(w, "write failed", 500)
- return
- }
- }
- value, err := os.ReadFile(db)
- if err != nil && !os.IsNotExist(err) {
- http.Error(w, "read failed", 500)
- return
- }
- fmt.Fprintf(w, "%s:%s", revision, value)
- })
- log.Fatal(http.Serve(listener, handler))
-}