catalogue: Resolve keeps the digest of a templated module's archive as TemplatesDigest (A-481, A-481a)
Builds: design 47 G A-481, A-481a
This commit is contained in:
@@ -64,6 +64,7 @@ func (m Manifest) Resolve(built []Built) (Manifest, error) {
|
|||||||
// **Each template's text, as the build read it back from its templates archive** (novox/hq ADR 0349 §2): into
|
// **Each template's text, as the build read it back from its templates archive** (novox/hq ADR 0349 §2): into
|
||||||
// the file's content, so what the mesh holds and composes is what the same text inline would be.
|
// the file's content, so what the mesh holds and composes is what the same text inline would be.
|
||||||
var handed *Handed
|
var handed *Handed
|
||||||
|
templatesDigest := ""
|
||||||
if m.Templated() {
|
if m.Templated() {
|
||||||
name := TemplatesArtifact(m)
|
name := TemplatesArtifact(m)
|
||||||
texts := by[name].Texts
|
texts := by[name].Texts
|
||||||
@@ -90,12 +91,14 @@ func (m Manifest) Resolve(built []Built) (Manifest, error) {
|
|||||||
// And, for a moved module, where its templates are and which one each file and item is filled from
|
// And, for a moved module, where its templates are and which one each file and item is filled from
|
||||||
// (handed.go): read while its resources and items still name their templates.
|
// (handed.go): read while its resources and items still name their templates.
|
||||||
handed = handedBy(m, by[name])
|
handed = handedBy(m, by[name])
|
||||||
|
templatesDigest = by[name].Digest
|
||||||
m.Resources = filled
|
m.Resources = filled
|
||||||
m.Items = items
|
m.Items = items
|
||||||
}
|
}
|
||||||
|
|
||||||
out := m
|
out := m
|
||||||
out.Handed = handed
|
out.Handed = handed
|
||||||
|
out.TemplatesDigest = templatesDigest
|
||||||
out.Build = nil
|
out.Build = nil
|
||||||
// Read with the build, like Build: the manifest the mesh holds carries each file's text (issue 731).
|
// Read with the build, like Build: the manifest the mesh holds carries each file's text (issue 731).
|
||||||
out.Templates = ""
|
out.Templates = ""
|
||||||
|
|||||||
@@ -120,3 +120,19 @@ func TestAResourceNamingAPackageIsRefused(t *testing.T) {
|
|||||||
t.Fatal("a resource backed by a package was accepted; a package is not a resource")
|
t.Fatal("a resource backed by a package was accepted; a package is not a resource")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A templated module's resolved manifest keeps the digest of the archive its files were rendered from, handed or not
|
||||||
|
// (design 47 G A-481, A-481a); a module with no templates keeps none.
|
||||||
|
func TestResolveKeepsTheDigestOfTheTemplatesArchive(t *testing.T) {
|
||||||
|
m := Manifest{Module: "tidy", Build: &Build{Artifacts: []Artifact{{Name: "files", Kind: ArtifactArchive, From: "files"}}}, Resources: []map[string]any{
|
||||||
|
{"id": "tidy:conf", "type": "file", "path": "/etc/tidy.conf", TemplateField: "files/tidy.conf"}}}
|
||||||
|
digest := "sha256:" + strings.Repeat("c", 64)
|
||||||
|
got, err := m.Resolve([]Built{{Name: "files", Kind: ArtifactArchive, Digest: digest,
|
||||||
|
Reference: ArtifactStoreScheme + "tidy/files/blobs/" + digest, Texts: map[string]string{"tidy.conf": "x"}}})
|
||||||
|
if err != nil || got.TemplatesDigest != digest {
|
||||||
|
t.Fatalf("templates digest %q, %v; want %s", got.TemplatesDigest, err, digest)
|
||||||
|
}
|
||||||
|
if plain, err := buildable().Resolve(wasBuilt()); err != nil || plain.TemplatesDigest != "" {
|
||||||
|
t.Fatalf("a module with no templates keeps no templates digest: %q, %v", plain.TemplatesDigest, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -749,6 +749,9 @@ type Manifest struct {
|
|||||||
// Handed is what its build kept for that (handed.go): written by Resolve, never in a repository.
|
// Handed is what its build kept for that (handed.go): written by Resolve, never in a repository.
|
||||||
Moved bool `json:"moved,omitempty"`
|
Moved bool `json:"moved,omitempty"`
|
||||||
Handed *Handed `json:"handed,omitempty"`
|
Handed *Handed `json:"handed,omitempty"`
|
||||||
|
// TemplatesDigest is the digest of the archive a templated module's files were rendered from, "sha256:<hex>": written
|
||||||
|
// by Resolve, never in a repository; the composition names it (design 47 G A-481, A-481a).
|
||||||
|
TemplatesDigest string `json:"templates-digest,omitempty"`
|
||||||
|
|
||||||
// Binds is where this module wants to be told about something it requires, per requirement.
|
// Binds is where this module wants to be told about something it requires, per requirement.
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user