Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix(e2e): match dockerignore patterns root-relative so nested context files reach the digest

Luigi Agostibcfd22af0160
diff --git a/.dockerignore b/.dockerignore
index 5a0637de..9e13f1b1 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -32,9 +32,15 @@ tests/
docs/
!docs/examples/
-# Development
+# Development.
+# Each nested tree needs its own line: docker matches .dockerignore patterns against the
+# context-root-relative path, so `node_modules/` excludes the root one and nothing else.
node_modules/
dashboard/node_modules/
+npm/node_modules/
+npm/dist/
+plugin/node_modules/
+plugin/dist/
*.log
# Build caches
diff --git a/TESTING.md b/TESTING.md
index 057bfa44..7b2e5859 100644
--- a/TESTING.md
+++ b/TESTING.md
@@ -119,11 +119,23 @@ this run is asking for, and the lane reuses it; an image whose inputs changed an
different tag, misses, and is rebuilt. Reuse is therefore never "a tag exists, skip it":
the tag cannot exist unless it was built from exactly these bytes.
-The digest is over content, not timestamps, so a checkout or a `touch` does not force a
-rebuild and an edit reverted byte-for-byte returns to the original tag. `.dockerignore`
-decides what counts as context, and `.alp/` is excluded there for the same reason as any
-other working state: it is rewritten every few minutes and would otherwise invalidate the
-image — and Docker's own `COPY` layer — on every write.
+The digest is over content, mode and symlink targets — not timestamps — so a checkout or a
+`touch` does not force a rebuild, an edit reverted byte-for-byte returns to the original
+tag, and a `chmod +x` or a retargeted link does not slip through unnoticed.
+
+`.dockerignore` decides what counts as context, and the digest reads it the way docker
+does: patterns match the context-root-relative path, so `node_modules/` excludes the root
+one and **not** `npm/node_modules` — each nested tree needs its own line. That is why the
+file lists `dashboard/node_modules/`, `npm/node_modules/` and `plugin/node_modules/`
+separately. Keeping those trees out is worth doing for its own sake: they are not build
+inputs for the Go binary, and every file in the context is a file docker hashes for its
+own `COPY` layer. `.alp/` is excluded for the same reason — it is rewritten every few
+minutes and would otherwise invalidate the image on every write.
+
+The digest deliberately errs towards rebuilding: anything the `.dockerignore` reader
+cannot decide exactly stays IN. Hashing a file docker ignores costs one rebuild that the
+run announces; missing a file docker sends is a stale image passing a run it should have
+failed.
Every run states its decision per image before the checks run, so a stale-image suspicion
is answerable from the log rather than by deleting tags:
@@ -137,11 +149,12 @@ Pass `--rebuild` to build regardless — that is what CI should use when it want
build. `PINCHTAB_DOCKER_SMOKE_RELEASE_IMAGE` and `PINCHTAB_DOCKER_SMOKE_CHROME_IMAGE`
still override an image outright, and such an image is never built.
-**What the lane costs.** Measured locally on an arm host: the host Docker checks are ~79s
-when both images have to be built and ~6s when both are reused, and a full `./dev e2e
-smoke` on reused images is ~83s wall for 43 tests, the balance being the compose stack and
-the smoke scenarios. The Chrome-for-Testing image is pinned `--platform linux/amd64` and
-so builds under emulation on arm, which is what made the rebuild worth avoiding.
+**What the lane costs.** Measured locally on an arm host: the host Docker checks are ~5-6s
+when both images are reused, against 70-125s when both have to be built — the spread on a
+build depends on how much of docker's own layer cache survived the change. A full `./dev
+e2e smoke` on reused images is 75-85s wall for 43 tests, the balance being the compose
+stack and the smoke scenarios. The Chrome-for-Testing image is pinned `--platform linux/amd64`
+and so builds under emulation on arm, which is what made the rebuild worth avoiding.
## Environment Variables
diff --git a/tests/tools/runner/internal/e2e/dockerimage.go b/tests/tools/runner/internal/e2e/dockerimage.go
index 5ab06f67..30322e91 100644
--- a/tests/tools/runner/internal/e2e/dockerimage.go
+++ b/tests/tools/runner/internal/e2e/dockerimage.go
@@ -192,14 +192,17 @@ func contextFiles(repoRoot string, excludedDirs map[string]bool) ([]string, erro
return nil
}
if entry.IsDir() {
- if excludedDirs[rel] || excludedDirs[filepath.Base(rel)] {
+ // Matched against the context-root-relative path, exactly as docker matches
+ // .dockerignore. A bare `node_modules/` entry excludes the root one and NOT
+ // a nested `npm/node_modules` — which is why this repo's .dockerignore lists
+ // `dashboard/node_modules/` on its own line. Matching on the base name
+ // instead would skip every directory of that name at any depth: files docker
+ // sends, absent from the digest, and a stale image reused for changed inputs.
+ if excludedDirs[rel] {
return filepath.SkipDir
}
return nil
}
- if entry.Type()&os.ModeSymlink != 0 {
- return nil
- }
files = append(files, rel)
return nil
})
@@ -210,14 +213,39 @@ func contextFiles(repoRoot string, excludedDirs map[string]bool) ([]string, erro
return files, nil
}
+// fileDigest hashes what the image ends up containing for this path: the executable bit
+// and then either the link target or the content. A symlink is hashed by where it points
+// rather than followed, so a retarget moves the digest and a loop cannot hang the walk.
func fileDigest(path string) (string, error) {
+ info, err := os.Lstat(path)
+ if err != nil {
+ return "", err
+ }
+
+ sum := sha256.New()
+ // The exec bit travels into the image, so a chmod +x is a change to what was built
+ // even when every byte is identical.
+ executable := 0
+ if info.Mode().Perm()&0o111 != 0 {
+ executable = 1
+ }
+ _, _ = fmt.Fprintf(sum, "exec:%d\n", executable)
+
+ if info.Mode()&os.ModeSymlink != 0 {
+ target, linkErr := os.Readlink(path)
+ if linkErr != nil {
+ return "", linkErr
+ }
+ _, _ = fmt.Fprintf(sum, "symlink:%s", target)
+ return hex.EncodeToString(sum.Sum(nil)), nil
+ }
+
file, err := os.Open(path) // #nosec G304 -- path comes from walking the repo's own build context
if err != nil {
return "", err
}
defer func() { _ = file.Close() }()
- sum := sha256.New()
if _, err := io.Copy(sum, file); err != nil {
return "", err
}
diff --git a/tests/tools/runner/internal/e2e/dockerimage_test.go b/tests/tools/runner/internal/e2e/dockerimage_test.go
index 836a491c..cbb9244b 100644
--- a/tests/tools/runner/internal/e2e/dockerimage_test.go
+++ b/tests/tools/runner/internal/e2e/dockerimage_test.go
@@ -4,6 +4,7 @@ import (
"bytes"
"os"
"path/filepath"
+ "runtime"
"strings"
"testing"
"time"
@@ -21,6 +22,11 @@ func writeProbeContext(t *testing.T) string {
"tests/tools/docker/cft.Dockerfile": "FROM ubuntu\nARG VERSION=1\n",
"docs/examples/enrich/main.go": "package main\n",
"node_modules/dep/index.js": "module.exports = 1\n",
+ // Nested trees whose BASE NAME matches a root-level exclude. Docker matches
+ // .dockerignore against the context-root-relative path, so it sends these — the
+ // fixture has to contain them or a walk that skips them looks correct.
+ "npm/node_modules/dep/index.js": "module.exports = 1\n",
+ "npm/tests/integration.test.ts": "test('x', () => {})\n",
} {
full := filepath.Join(root, filepath.FromSlash(path))
if err := os.MkdirAll(filepath.Dir(full), 0o755); err != nil {
@@ -127,9 +133,21 @@ func TestBuildInputDigestFollowsTheDockerignoreOnlyWhereItIsUnambiguous(t *testi
file: "tests/e2e/scenarios/probe.sh", body: "echo edited\n", wantChange: false,
},
{
- name: "an excluded directory nested anywhere does not affect the digest",
+ name: "the ROOT-LEVEL directory a bare pattern names does not affect the digest",
file: "node_modules/dep/index.js", body: "module.exports = 2\n", wantChange: false,
},
+ {
+ // The hole this fixture exists for. `node_modules/` excludes the root one and
+ // nothing else, so docker sends npm/node_modules and the digest must see it.
+ // Matching on the base name instead skipped 36k files docker was sending, and
+ // the previous fixture — a ROOT-level path — could not tell the two apart.
+ name: "a NESTED directory whose base name matches a root-level pattern still counts",
+ file: "npm/node_modules/dep/index.js", body: "module.exports = 2\n", wantChange: true,
+ },
+ {
+ name: "a nested directory named like the excluded tests/ still counts",
+ file: "npm/tests/integration.test.ts", body: "test('y', () => {})\n", wantChange: true,
+ },
{
name: "a directory with a negation stays in the digest, because the negation puts part of it back",
file: "docs/examples/enrich/main.go", body: "package main // edited\n", wantChange: true,
@@ -263,3 +281,59 @@ func TestDockerSmokeRunNamesEachImageAndWhy(t *testing.T) {
}
}
}
+
+// A file's mode and a symlink's target both travel into the image, so both are build
+// inputs. Content-only hashing is the same fail-open shape as the nested-directory hole:
+// the image changes, the tag does not, and a stale one is reused.
+func TestBuildInputDigestCoversModeAndSymlinkTargets(t *testing.T) {
+ t.Run("chmod +x on a context file changes the digest", func(t *testing.T) {
+ root := writeProbeContext(t)
+ before := digestOf(t, root, probeSpec)
+
+ script := filepath.Join(root, "scripts", "build.sh")
+ if err := os.Chmod(script, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if after := digestOf(t, root, probeSpec); after == before {
+ t.Error("making a context file executable did not change the digest, so an image built from a non-executable copy would be reused for one that needs the exec bit")
+ }
+ })
+
+ t.Run("retargeting a symlink changes the digest", func(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("symlink creation needs privileges on windows")
+ }
+ root := writeProbeContext(t)
+ link := filepath.Join(root, "current.go")
+ if err := os.Symlink("main.go", link); err != nil {
+ t.Fatal(err)
+ }
+ before := digestOf(t, root, probeSpec)
+
+ if err := os.Remove(link); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink("scripts/build.sh", link); err != nil {
+ t.Fatal(err)
+ }
+ if after := digestOf(t, root, probeSpec); after == before {
+ t.Error("pointing a symlink somewhere else did not change the digest, although the image now contains a different link")
+ }
+ })
+
+ t.Run("a symlink is hashed by its target rather than followed", func(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("symlink creation needs privileges on windows")
+ }
+ root := writeProbeContext(t)
+ if err := os.Symlink("loop.go", filepath.Join(root, "loop.go")); err != nil {
+ t.Fatal(err)
+ }
+ // A self-referential link is unreadable as a file; the digest must still complete,
+ // because failing here would fail the whole build-input hash and force a rebuild
+ // on every run.
+ if _, err := buildInputsDigest(root, probeSpec); err != nil {
+ t.Errorf("a symlink loop broke the digest: %v", err)
+ }
+ })
+}