From 0b834bbca7d0225be770d955f6e3d8b2ff42e2b0 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 16:01:19 +0100 Subject: [PATCH] mesh-build-node-narrowed-packages: a package narrowed out of a step's workspace is no module of it A step of one TypeScript package of a module with several (mesh-contracts' root: ts-meshbroker beside ts-meshrecovery, pipeline main.3 of 2026-11-20) fetches a workspace narrowed to that package's path. The fetch and the lint and test levels read every package artifact of the manifest, and one whose path the narrowing left out fell back to the module's directory, which holds no lock: every TypeScript step of mesh-contracts ended "could not run: the package in . has no package-lock.json". Such a package is now left out of the fetch's install and of the levels' targets; an unnarrowed tree is read as before. Builds: design 47 H H-A-136 (a step's workspace holds the artifact's paths; nothing else is fetched), ADR 0499 clause 4 --- .../cmd/mesh-build-node/build.go | 14 +++++ .../cmd/mesh-build-node/check.go | 10 ++-- .../cmd/mesh-build-node/fetch.go | 5 ++ .../cmd/mesh-build-node/lint.go | 2 +- .../cmd/mesh-build-node/package_paths_test.go | 51 +++++++++++++++++++ .../cmd/mesh-build-node/steps.go | 2 +- 6 files changed, 79 insertions(+), 5 deletions(-) diff --git a/modules/mesh-build-node/cmd/mesh-build-node/build.go b/modules/mesh-build-node/cmd/mesh-build-node/build.go index 85406fb0f..9a09e3941 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/build.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/build.go @@ -48,6 +48,20 @@ type artifact struct { // when that is a directory of the module holding a package.json (the contracts folders: ts/seats//, each with its // own lock, ADR 0634 section 8), else the module's directory itself (a package that names no path, or source paths // beside the module's package.json: today's form). +// narrowedAway says whether the package's one named path is absent from the module's directory dir: in a workspace +// narrowed to another artifact's paths, it is not this build's. +func (a artifact) narrowedAway(dir string) bool { + if len(a.Paths) != 1 { + return false + } + p := path.Clean(strings.TrimSuffix(a.Paths[0], "/")) + if p == "." || path.IsAbs(p) || p == ".." || strings.HasPrefix(p, "../") { + return false + } + _, err := os.Lstat(filepath.Join(dir, filepath.FromSlash(p))) + return os.IsNotExist(err) +} + func (a artifact) packageDir(dir string) string { if len(a.Paths) != 1 { return "." diff --git a/modules/mesh-build-node/cmd/mesh-build-node/check.go b/modules/mesh-build-node/cmd/mesh-build-node/check.go index 7945ba240..0ecdd56bb 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/check.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/check.go @@ -135,7 +135,7 @@ func (m *Module) testLevel(ctx context.Context, args map[string]any) (*TestResul if where == "" { where = "." } - targets, err := testTargets(dir, where) + targets, err := testTargets(dir, where, narrowed(filepath.Join(root, "tree"))) if err != nil { return nil, err } @@ -338,8 +338,9 @@ type testTarget struct{ dir, where string } // testTargets are the directories a module's tests run in: each TypeScript package artifact's own path when every // package the module declares names one (ADR 0634 ยง8: its package.json, its lock, its tests), else the module's -// directory. -func testTargets(dir, where string) ([]testTarget, error) { +// directory. In a workspace narrowed to one artifact's paths (narrowedTree), a package whose path was left out is no +// target of this step (ADR 0499 clause 4; design 47 H, H-A-136). +func testTargets(dir, where string, narrowedTree bool) ([]testTarget, error) { whole := []testTarget{{dir, where}} raw, err := os.ReadFile(filepath.Join(dir, "module.json")) if err != nil { @@ -362,6 +363,9 @@ func testTargets(dir, where string) ([]testTarget, error) { if a.Kind != "package" { return whole, nil // a bundle is tested in its module's directory } + if narrowedTree && a.narrowedAway(dir) { + continue + } at := a.packageDir(dir) if at == "." { return whole, nil diff --git a/modules/mesh-build-node/cmd/mesh-build-node/fetch.go b/modules/mesh-build-node/cmd/mesh-build-node/fetch.go index 397da7046..bbae1ed46 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/fetch.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/fetch.go @@ -300,6 +300,11 @@ func (m *Module) typeScriptModules(ctx context.Context, tree string) (dirs []str continue } d := filepath.ToSlash(filepath.Dir(l)) + if a.Kind == "package" && narrowed(tree) && a.narrowedAway(filepath.Join(tree, filepath.FromSlash(d))) { + // A package of the module whose own path the narrowing left out (ADR 0499 clause 4; design 47 H, H-A-136: + // nothing else is fetched): no module of this build, never the module's directory, which holds no lock. + continue + } if a.Kind == "package" { d = path.Join(d, a.packageDir(filepath.Join(tree, filepath.FromSlash(d)))) } diff --git a/modules/mesh-build-node/cmd/mesh-build-node/lint.go b/modules/mesh-build-node/cmd/mesh-build-node/lint.go index 2afeb2fb1..67c90ccee 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/lint.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/lint.go @@ -22,7 +22,7 @@ func (m *Module) lintStep(ctx context.Context, args map[string]any) (any, error) if err != nil { return nil, err } - targets, err := testTargets(mdir, filepath.ToSlash(filepath.Clean(dir))) + targets, err := testTargets(mdir, filepath.ToSlash(filepath.Clean(dir)), narrowed(filepath.Join(root, "tree"))) if err != nil { return nil, err } diff --git a/modules/mesh-build-node/cmd/mesh-build-node/package_paths_test.go b/modules/mesh-build-node/cmd/mesh-build-node/package_paths_test.go index 98dd5f781..56ac043df 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/package_paths_test.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/package_paths_test.go @@ -91,3 +91,54 @@ func TestAFolderModulesPackageIsBuiltAndTestedInItsPath(t *testing.T) { t.Errorf("unit level = %+v, ran tests in %v, want both package paths", r, tests) } } + +// A step of one package of a root module with several (mesh-contracts' ts-meshbroker beside ts-meshrecovery, pipeline +// main.3 of 2026-11-20) fetches a workspace narrowed to that package's path (ADR 0499 clause 4; design 47 H, H-A-136: +// nothing else is fetched). The other packages' paths are not in it: they are no module of this build, never the +// module's directory, which holds no lock ("the package in . has no package-lock.json"). +func TestANarrowedFetchOfOneFolderPackageLeavesTheOthersOut(t *testing.T) { + m, f := fetchMachine(t, folderFiles(""), nil) + args := map[string]any{"repository": "novox/mesh-contracts", "commit": commitSHA, "dir": ".", "paths": []any{"ts/seats/a"}} + out, err := m.fetch(context.Background(), args) + if err != nil { + t.Fatal(err) + } + r := out.(FetchResult) + if strings.Join(r.Modules, ",") != "ts/seats/a" || strings.Join(r.Installed, ",") != "ts/seats/a" { + t.Errorf("modules %v, installed %v; want only the named package ts/seats/a", r.Modules, r.Installed) + } + if n := len(npmCalls(f)); n != 1 { + t.Errorf("%d npm commands, want the one install of the named package", n) + } +} + +// The lint and test levels of that narrowed workspace run in the named package's path alone: a package whose path was +// left out is no target, and the module's directory is not tested whole in its place (H-A-136). +func TestANarrowedWorkspaceTestsOnlyItsPackage(t *testing.T) { + work := t.TempDir() + files := folderFiles("") + for p := range files { + if strings.HasPrefix(p, "ts/seats/b/") { + delete(files, p) + } + } + for p, body := range files { + write(t, filepath.Join(work, filepath.FromSlash(p)), body, 0o644) + } + for _, tc := range []struct { + narrowed bool + want string + }{{true, "ts/seats/a"}, {false, "."}} { + got, err := testTargets(work, ".", tc.narrowed) + if err != nil { + t.Fatal(err) + } + var where []string + for _, g := range got { + where = append(where, g.where) + } + if strings.Join(where, ",") != tc.want { + t.Errorf("narrowed %v: targets %v, want %s", tc.narrowed, where, tc.want) + } + } +} diff --git a/modules/mesh-build-node/cmd/mesh-build-node/steps.go b/modules/mesh-build-node/cmd/mesh-build-node/steps.go index ff4e7d2fb..20301d5a6 100644 --- a/modules/mesh-build-node/cmd/mesh-build-node/steps.go +++ b/modules/mesh-build-node/cmd/mesh-build-node/steps.go @@ -45,7 +45,7 @@ type StepsAnswer struct { // detectSteps finds the steps of the package directories under dir. func detectSteps(dir string) ([]DetectedStep, error) { - targets, err := testTargets(dir, ".") + targets, err := testTargets(dir, ".", false) if err != nil { return nil, err }