A module of its own account needs a node-engine that gives a directory's contents (design 47 H2, H-A-554, H-A-556) #213

Merged
mesh-tools merged 1 commits from fix/gitea-runs-as into main 2026-11-23 11:31:54 +00:00
2 changed files with 15 additions and 1 deletions
+10
View File
@@ -83,6 +83,13 @@ func claimsAtMesh(top map[string]any, seat string) bool {
return false
}
// ReadDirectoryContentsOwner is the reader capability of a node-engine that, when a directory's owner changes, gives its
// contents the new owner too (novox/hq design 47 H2, H-A-545 (2), H-A-550, H-A-556): an engine before it changes the
// directory alone, and a module moved to an account of its own then cannot read what it wrote before. A manifest that
// declares runs-as needs it (ManifestNeeds), so the module graph orders such a module's move after that engine runs on
// its node (ADR 0614 §4). The engine states it itself; this contract does not (ManifestReads).
const ReadDirectoryContentsOwner = "directory-contents-owner"
// ofSeatReach is a manifest's value naming a seat's reach, `${seat:<seat>:reach}`.
var ofSeatReach = regexp.MustCompile(`\$\{seat:[a-z0-9][a-z0-9-]*:reach\}`)
@@ -179,6 +186,9 @@ func ManifestNeeds(raw []byte) ([]string, error) {
if claimsAtMesh(top, storeHolderSeat) {
used[ReadForm+ReferenceFormSeatReach] = true
}
if runsAs, _ := top["runs-as"].(string); runsAs != "" {
used[ReadDirectoryContentsOwner] = true
}
for _, r := range asList(top["resources"]) {
if obj, ok := r.(map[string]any); ok {
if _, has := obj[IfConfigField]; has {
+5 -1
View File
@@ -126,6 +126,9 @@ func TestOwnManifestUsesNoWordTheRunningControllerRefuses(t *testing.T) {
[]string{"form:config-json"}, []string{"form:config-json"}},
{"a template of the config form alone", `{"module":"z","version":"1","resources":[{"id":"f","type":"file","template":"files/k"}]}`,
[]string{"form:config"}, nil},
// A module of its own account needs an engine that gives a directory's contents its new owner (H-A-556).
{"a module of its own account", `{"module":"g","version":"1","runs-as":"g"}`,
[]string{"directory-contents-owner", "word:runs-as"}, []string{"directory-contents-owner"}},
{"a word this contract does not know", `{"module":"u","version":"1","newer-word":{"inside":1}}`, []string{"word:module"}, nil},
} {
templates := map[string]map[string]string{ // the templates' text a row's module names
@@ -164,7 +167,8 @@ func TestOwnManifestUsesNoWordTheRunningControllerRefuses(t *testing.T) {
if got := MissingManifestReads(needs, nil); !slices.Equal(got, row.missing) {
t.Errorf("%s: an engine stating nothing lacks %v, want %v", row.why, got, row.missing)
}
if got := MissingManifestReads(needs, reads); len(got) != 0 {
// The node-engine states directory-contents-owner itself, beside this contract's reads (H-A-556).
if got := MissingManifestReads(needs, append(slices.Clone(reads), ReadDirectoryContentsOwner)); len(got) != 0 {
t.Errorf("%s: this contract lacks %v", row.why, got)
}
}