Skip to content

Commit 122a209

Browse files
authored
fix: async bugs fixes (#283)
1 parent 29d4aeb commit 122a209

28 files changed

+1320
-972
lines changed

cmd/internal/telemetry/telemetry.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func SetupOtelp(ctx context.Context, otelpURL, version string) (shutdown func(co
8989
}
9090

9191
func createReportDir(dir string) (string, error) {
92-
err := os.MkdirAll(dir, 0o755)
92+
err := os.MkdirAll(dir, 0o750)
9393
if err != nil {
9494
return "", err
9595
}
@@ -102,7 +102,7 @@ func createReportDir(dir string) (string, error) {
102102
path += "_" + strconv.Itoa(i)
103103
}
104104
if _, err := os.Stat(path); os.IsNotExist(err) {
105-
err := os.Mkdir(path, 0o755)
105+
err := os.Mkdir(path, 0o750)
106106
if err != nil {
107107
return "", err
108108
}
@@ -137,7 +137,7 @@ func SetupStdout(ctx context.Context, debugDir, version string) (shutdown func(c
137137
if err != nil {
138138
return nil, err
139139
}
140-
logFile, err := os.Create(filepath.Join(dir, "logs.json"))
140+
logFile, err := os.Create(filepath.Join(dir, "logs.json")) //nolint:gosec // Safe file path construction in a controlled directory
141141
if err != nil {
142142
return nil, err
143143
}
@@ -160,7 +160,7 @@ func SetupStdout(ctx context.Context, debugDir, version string) (shutdown func(c
160160
log.WithResource(resource),
161161
)
162162
global.SetLoggerProvider(logProvider)
163-
traceFile, err := os.Create(filepath.Join(dir, "traces.json"))
163+
traceFile, err := os.Create(filepath.Join(dir, "traces.json")) //nolint:gosec // Safe file path construction in a controlled directory
164164
if err != nil {
165165
handleErr(err)
166166
return
@@ -182,7 +182,7 @@ func SetupStdout(ctx context.Context, debugDir, version string) (shutdown func(c
182182
trace.WithResource(resource),
183183
)
184184
otel.SetTracerProvider(traceProvider)
185-
metricFile, err := os.Create(filepath.Join(dir, "metrics.json"))
185+
metricFile, err := os.Create(filepath.Join(dir, "metrics.json")) //nolint:gosec // Safe file path construction in a controlled directory
186186
if err != nil {
187187
handleErr(err)
188188
return

cmd/root.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ func Execute() {
194194
rootSpan.End()
195195
}
196196
if rootCleanup != nil {
197-
rootCleanup(rootCtx)
197+
if cleanupErr := rootCleanup(rootCtx); cleanupErr != nil {
198+
slog.ErrorContext(rootCtx, "Failed to clean up", "error", cleanupErr)
199+
}
198200
}
199201
os.Exit(exitCode)
200202
}

engine/depends_on_ref_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package engine
2+
3+
import "testing"
4+
5+
func TestDependsOnWithRefBlocks(t *testing.T) {
6+
renderTest(
7+
t, "depends_on with ref blocks",
8+
[]string{`
9+
section "foo" {
10+
title = "Foo title"
11+
12+
content text {
13+
value = "Foo text"
14+
}
15+
}
16+
17+
content text "baz" {
18+
value = "Baz text"
19+
}
20+
21+
document "test1" {
22+
// Define reference blocks first
23+
section ref "aaa" {
24+
base = section.foo
25+
title = "Foo overload 1"
26+
}
27+
28+
content ref "bbb" {
29+
base = content.text.baz
30+
}
31+
32+
// Then reference them in depends_on
33+
content text {
34+
depends_on = [
35+
"section.ref.aaa",
36+
"content.ref.bbb",
37+
]
38+
value = "Doc content is ready"
39+
}
40+
}
41+
`},
42+
[]string{
43+
"# Foo overload 1",
44+
"Foo text",
45+
"Baz text",
46+
"Doc content is ready",
47+
},
48+
optDocName("test1"),
49+
)
50+
51+
renderTest(
52+
t, "depends_on before ref blocks",
53+
[]string{`
54+
section "foo" {
55+
title = "Foo title"
56+
57+
content text {
58+
value = "Foo text"
59+
}
60+
}
61+
62+
content text "baz" {
63+
value = "Baz text"
64+
}
65+
66+
document "test1" {
67+
// Reference blocks in depends_on before they're defined
68+
content text {
69+
depends_on = [
70+
"section.ref.aaa",
71+
"content.ref.bbb",
72+
]
73+
value = "Doc content is ready"
74+
}
75+
76+
// Define reference blocks after depending on them
77+
section ref "aaa" {
78+
base = section.foo
79+
title = "Foo overload 1"
80+
}
81+
82+
content ref "bbb" {
83+
base = content.text.baz
84+
}
85+
}
86+
`},
87+
[]string{
88+
"Doc content is ready",
89+
"# Foo overload 1",
90+
"Foo text",
91+
"Baz text",
92+
},
93+
optDocName("test1"),
94+
)
95+
}

engine/engine_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,3 +832,78 @@ func TestEngineRenderContent(t *testing.T) {
832832
optDocName("test"),
833833
)
834834
}
835+
836+
func TestDependencyContextAccess(t *testing.T) {
837+
// Test case 1: Access dependency blocks via context
838+
renderTest(
839+
t, "Access dependency blocks via context",
840+
[]string{`
841+
document "test" {
842+
content text "foo" {
843+
value = "first result"
844+
}
845+
846+
content text "bar" {
847+
depends_on = ["content.text.foo"]
848+
value = "second result"
849+
}
850+
851+
content text "baz" {
852+
depends_on = ["content.text.foo", "content.text.bar"]
853+
value = "Dependency foo: {{ .dependency.content.text.foo.markdown }} and bar: {{ .dependency.content.text.bar.markdown }}"
854+
}
855+
}
856+
`},
857+
[]string{
858+
"first result",
859+
"second result",
860+
"Dependency foo: first result and bar: second result",
861+
},
862+
optDocName("test"),
863+
)
864+
865+
// Test case 2: Access section dependency blocks via context
866+
renderTest(
867+
t, "Access section dependency blocks via context",
868+
[]string{`
869+
section "foo" {
870+
title = "Foo section"
871+
content text {
872+
value = "foo content"
873+
}
874+
}
875+
876+
document "test" {
877+
section ref "bar" {
878+
base = section.foo
879+
title = "Bar section"
880+
}
881+
882+
content text {
883+
depends_on = ["section.ref.bar"]
884+
value = <<-EOT
885+
Dependency: {{ .dependency | toPrettyJson }}
886+
Section title: {{ .dependency.section.ref.bar.meta.title }}
887+
EOT
888+
}
889+
}
890+
`},
891+
[]string{
892+
"# Bar section",
893+
"foo content",
894+
"Dependency: {\n" +
895+
" \"section\": {\n" +
896+
" \"ref\": {\n" +
897+
" \"bar\": {\n" +
898+
" \"meta\": {\n" +
899+
" \"title\": \"foo\"\n" +
900+
" }\n" +
901+
" }\n" +
902+
" }\n" +
903+
" }\n" +
904+
"}\n" +
905+
"Section title: foo",
906+
},
907+
optDocName("test"),
908+
)
909+
}

engine/engine_vars_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ func TestEngineVarsHandling(t *testing.T) {
118118
"sectVar": "sectVar"
119119
}`,
120120
`3: {
121-
"docVar": "docVar"
121+
"docVar": "docVar",
122+
"sectVar": "sectVar"
122123
}`,
123124
},
124125
)

0 commit comments

Comments
 (0)