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
This commit is contained in:
@@ -48,6 +48,20 @@ type artifact struct {
|
|||||||
// when that is a directory of the module holding a package.json (the contracts folders: ts/seats/<seat>/, each with its
|
// when that is a directory of the module holding a package.json (the contracts folders: ts/seats/<seat>/, each with its
|
||||||
// own lock, ADR 0634 section 8), else the module's directory itself (a package that names no path, or source paths
|
// 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).
|
// 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 {
|
func (a artifact) packageDir(dir string) string {
|
||||||
if len(a.Paths) != 1 {
|
if len(a.Paths) != 1 {
|
||||||
return "."
|
return "."
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ func (m *Module) testLevel(ctx context.Context, args map[string]any) (*TestResul
|
|||||||
if where == "" {
|
if where == "" {
|
||||||
where = "."
|
where = "."
|
||||||
}
|
}
|
||||||
targets, err := testTargets(dir, where)
|
targets, err := testTargets(dir, where, narrowed(filepath.Join(root, "tree")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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
|
// 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
|
// package the module declares names one (ADR 0634 §8: its package.json, its lock, its tests), else the module's
|
||||||
// directory.
|
// directory. In a workspace narrowed to one artifact's paths (narrowedTree), a package whose path was left out is no
|
||||||
func testTargets(dir, where string) ([]testTarget, error) {
|
// 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}}
|
whole := []testTarget{{dir, where}}
|
||||||
raw, err := os.ReadFile(filepath.Join(dir, "module.json"))
|
raw, err := os.ReadFile(filepath.Join(dir, "module.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -362,6 +363,9 @@ func testTargets(dir, where string) ([]testTarget, error) {
|
|||||||
if a.Kind != "package" {
|
if a.Kind != "package" {
|
||||||
return whole, nil // a bundle is tested in its module's directory
|
return whole, nil // a bundle is tested in its module's directory
|
||||||
}
|
}
|
||||||
|
if narrowedTree && a.narrowedAway(dir) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
at := a.packageDir(dir)
|
at := a.packageDir(dir)
|
||||||
if at == "." {
|
if at == "." {
|
||||||
return whole, nil
|
return whole, nil
|
||||||
|
|||||||
@@ -300,6 +300,11 @@ func (m *Module) typeScriptModules(ctx context.Context, tree string) (dirs []str
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
d := filepath.ToSlash(filepath.Dir(l))
|
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" {
|
if a.Kind == "package" {
|
||||||
d = path.Join(d, a.packageDir(filepath.Join(tree, filepath.FromSlash(d))))
|
d = path.Join(d, a.packageDir(filepath.Join(tree, filepath.FromSlash(d))))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func (m *Module) lintStep(ctx context.Context, args map[string]any) (any, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,3 +91,54 @@ func TestAFolderModulesPackageIsBuiltAndTestedInItsPath(t *testing.T) {
|
|||||||
t.Errorf("unit level = %+v, ran tests in %v, want both package paths", r, tests)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type StepsAnswer struct {
|
|||||||
|
|
||||||
// detectSteps finds the steps of the package directories under dir.
|
// detectSteps finds the steps of the package directories under dir.
|
||||||
func detectSteps(dir string) ([]DetectedStep, error) {
|
func detectSteps(dir string) ([]DetectedStep, error) {
|
||||||
targets, err := testTargets(dir, ".")
|
targets, err := testTargets(dir, ".", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user