From dda54b1739e8f606c1d3a21665ce174fcf83a41e Mon Sep 17 00:00:00 2001 From: Vladyslav Kuksiuk Date: Wed, 3 Jun 2026 16:51:12 +0200 Subject: [PATCH 1/4] Update files permissions. --- embedding/processor.go | 2 +- files/files.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/embedding/processor.go b/embedding/processor.go index 0a9b90d..2d5f5c2 100644 --- a/embedding/processor.go +++ b/embedding/processor.go @@ -118,7 +118,7 @@ func (p Processor) Embed() (*parsing.Context, error) { } if context.IsContainsEmbedding() && context.IsContentChanged() { data := []byte(strings.Join(context.GetResult(), "\n")) - err = os.WriteFile(p.DocFilePath, data, os.FileMode(files.ReadWriteExecPermission)) + err = os.WriteFile(p.DocFilePath, data, os.FileMode(files.DocumentationFilePermission)) if err != nil { return &context, err } diff --git a/files/files.go b/files/files.go index 2410a24..338c9c3 100644 --- a/files/files.go +++ b/files/files.go @@ -27,8 +27,10 @@ import ( ) const ( - ReadWriteExecPermission uint32 = 0777 - WritePermission uint32 = 0600 + // DocumentationFilePermission is the mode used when writing documentation data files. + DocumentationFilePermission uint32 = 0644 + // WritePermission is the mode used for private writable files in tests and fixtures. + WritePermission uint32 = 0600 ) // IsFileExist reports whether the given path (relative or absolute) to a file exists in the From c2c66204ad9bdc9ea7a908335b193d2bdc2722c7 Mon Sep 17 00:00:00 2001 From: Vladyslav Kuksiuk Date: Wed, 3 Jun 2026 17:05:24 +0200 Subject: [PATCH 2/4] Add `.gitignore`. --- .gitignore | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f39e70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# IDE metadata. +.idea/ +*.iml + +# OS metadata. +.DS_Store + +# Go build and test outputs. +/dist/ +/out/ +**/build/ +coverage.out From 1d2906e7ea8bf1d037f92a6118988771ebf810e0 Mon Sep 17 00:00:00 2001 From: Vladyslav Kuksiuk Date: Wed, 3 Jun 2026 17:19:35 +0200 Subject: [PATCH 3/4] Improve readability. --- embedding/processor.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/embedding/processor.go b/embedding/processor.go index 2d5f5c2..c1ac45a 100644 --- a/embedding/processor.go +++ b/embedding/processor.go @@ -143,12 +143,11 @@ func (p Processor) FindChangedEmbeddings() ([]parsing.Instruction, error) { return nil, nil } context, err := p.fillEmbeddingContext() - changedEmbeddings := context.FindChangedEmbeddings() if err != nil { - return changedEmbeddings, err + return nil, err } - return changedEmbeddings, nil + return context.FindChangedEmbeddings(), nil } // IsUpToDate reports whether the embedding of the target markdown is up-to-date with the code file. @@ -446,7 +445,7 @@ func getFilesByPatterns(root string, patterns []string) ([]string, error) { return result, nil } -// Returns the elements of the first array excluding those present in the second array. +// removeElements returns values from first that are not present in second. func removeElements(first, second []string) []string { secondMap := make(map[string]struct{}) for _, value := range second { From 1b84a54673014cc43a4d7996edb09c43adc58a9a Mon Sep 17 00:00:00 2001 From: Vladyslav Kuksiuk Date: Wed, 3 Jun 2026 17:31:24 +0200 Subject: [PATCH 4/4] Add list tests. --- type/list_test.go | 130 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 type/list_test.go diff --git a/type/list_test.go b/type/list_test.go new file mode 100644 index 0000000..4dc8ff4 --- /dev/null +++ b/type/list_test.go @@ -0,0 +1,130 @@ +// Copyright 2026, TeamDev. All rights reserved. +// +// Redistribution and use in source and/or binary forms, with or without +// modification, must retain the above copyright notice and the following +// disclaimer. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +package _type_test + +import ( + "testing" + + _type "embed-code/embed-code-go/type" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + "gopkg.in/yaml.v3" +) + +// TestTypes runs the type package specs. +func TestTypes(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Types Suite") +} + +var _ = Describe("NamedPathList", func() { + + It("should unmarshal a single path string", func() { + var config struct { + Paths _type.NamedPathList `yaml:"paths"` + } + + err := yaml.Unmarshal([]byte("paths: ' ../examples '\n"), &config) + + Expect(err).ShouldNot(HaveOccurred()) + Expect(config.Paths).Should(Equal(_type.NamedPathList{ + {Path: "../examples"}, + })) + }) + + It("should unmarshal a sequence of path strings", func() { + var config struct { + Paths _type.NamedPathList `yaml:"paths"` + } + + err := yaml.Unmarshal([]byte("paths:\n - ' ../examples '\n - ../runtime\n"), &config) + + Expect(err).ShouldNot(HaveOccurred()) + Expect(config.Paths).Should(Equal(_type.NamedPathList{ + {Path: "../examples"}, + {Path: "../runtime"}, + })) + }) + + It("should unmarshal a sequence of named paths", func() { + var config struct { + Paths _type.NamedPathList `yaml:"paths"` + } + + err := yaml.Unmarshal([]byte( + "paths:\n"+ + " - name: examples\n"+ + " path: ../examples\n"+ + " - name: runtime\n"+ + " path: ../runtime\n", + ), &config) + + Expect(err).ShouldNot(HaveOccurred()) + Expect(config.Paths).Should(Equal(_type.NamedPathList{ + {Name: "examples", Path: "../examples"}, + {Name: "runtime", Path: "../runtime"}, + })) + }) + + It("should reject mapping values", func() { + var config struct { + Paths _type.NamedPathList `yaml:"paths"` + } + + err := yaml.Unmarshal([]byte("paths:\n name: examples\n path: ../examples\n"), &config) + + Expect(err).Should(MatchError(ContainSubstring("invalid format for named paths"))) + }) +}) + +var _ = Describe("StringList", func() { + + It("should unmarshal a comma-separated string", func() { + var config struct { + Patterns _type.StringList `yaml:"patterns"` + } + + err := yaml.Unmarshal([]byte("patterns: ' docs/*.md, , guides/*.html '\n"), &config) + + Expect(err).ShouldNot(HaveOccurred()) + Expect(config.Patterns).Should(Equal(_type.StringList{"docs/*.md", "guides/*.html"})) + }) + + It("should unmarshal a sequence of strings", func() { + var config struct { + Patterns _type.StringList `yaml:"patterns"` + } + + err := yaml.Unmarshal([]byte("patterns:\n - ' docs/*.md '\n - guides/*.html\n"), &config) + + Expect(err).ShouldNot(HaveOccurred()) + Expect(config.Patterns).Should(Equal(_type.StringList{"docs/*.md", "guides/*.html"})) + }) + + It("should reject mapping values", func() { + var config struct { + Patterns _type.StringList `yaml:"patterns"` + } + + err := yaml.Unmarshal([]byte("patterns:\n markdown: docs/*.md\n"), &config) + + Expect(err).Should(MatchError(ContainSubstring("invalid format for string list"))) + }) +})