Skip to content

Commit 6bd3f7d

Browse files
committed
clean up formatting and tests for passing
1 parent 8096d88 commit 6bd3f7d

File tree

9 files changed

+322
-862
lines changed

9 files changed

+322
-862
lines changed

apps/web/app/routes/ws/deployments/_components/trace-utils.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,16 @@ export function getSpanContext(span: DeploymentTraceSpan): {
221221
resource?: string;
222222
} {
223223
const attrs = span.attributes ?? {};
224-
224+
225225
return {
226-
environment: typeof attrs["ctrlplane.environment"] === "string"
227-
? attrs["ctrlplane.environment"]
228-
: undefined,
229-
resource: typeof attrs["ctrlplane.resource"] === "string"
230-
? attrs["ctrlplane.resource"]
231-
: undefined,
226+
environment:
227+
typeof attrs["ctrlplane.environment"] === "string"
228+
? attrs["ctrlplane.environment"]
229+
: undefined,
230+
resource:
231+
typeof attrs["ctrlplane.resource"] === "string"
232+
? attrs["ctrlplane.resource"]
233+
: undefined,
232234
};
233235
}
234236

@@ -249,10 +251,11 @@ export function getSpanDisplayInfo(span: DeploymentTraceSpan): {
249251
attrs.name ?? attrs.label ?? attrs.resourceName ?? attrs.targetName;
250252
const type = attrs.type ?? attrs.kind ?? attrs.action;
251253
const identifier = attrs.id ?? attrs.identifier ?? attrs.key;
252-
254+
253255
// Extract reason/message information
254-
const reason = attrs.reason ?? attrs.message ?? attrs.error ?? attrs.description;
255-
256+
const reason =
257+
attrs.reason ?? attrs.message ?? attrs.error ?? attrs.description;
258+
256259
// Extract environment and resource
257260
const context = getSpanContext(span);
258261

@@ -271,12 +274,18 @@ export function getSpanDisplayInfo(span: DeploymentTraceSpan): {
271274
}
272275

273276
// Add identifier if available and not already in primary text
274-
if (identifier && typeof identifier === "string" && !primaryText.includes(identifier)) {
275-
secondaryText = secondaryText ? `${secondaryText} (${identifier})` : identifier;
277+
if (
278+
identifier &&
279+
typeof identifier === "string" &&
280+
!primaryText.includes(identifier)
281+
) {
282+
secondaryText = secondaryText
283+
? `${secondaryText} (${identifier})`
284+
: identifier;
276285
}
277286

278-
return {
279-
primaryText,
287+
return {
288+
primaryText,
280289
secondaryText,
281290
reason: reason && typeof reason === "string" ? reason : undefined,
282291
environment: context.environment,

apps/workspace-engine/pkg/workspace/releasemanager/deployment/planner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func (p *Planner) findDeployableVersion(
341341
}
342342

343343
if eligible {
344-
if planning != nil {
344+
if planning != nil {
345345
for _, result := range results {
346346
evaluation := planning.StartEvaluation(result.Message)
347347
display := version.Name

apps/workspace-engine/pkg/workspace/releasemanager/trace/memory_store_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestInMemoryStore_GetSpans(t *testing.T) {
7878
rt := NewReconcileTarget("workspace-1", "api-service-production")
7979
rt.Complete(StatusCompleted)
8080
spans := rt.exporter.getSpans()
81-
81+
8282
err := store.WriteSpans(ctx, spans)
8383
if err != nil {
8484
t.Fatalf("WriteSpans failed: %v", err)
@@ -107,7 +107,7 @@ func TestInMemoryStore_GetSpansCopy(t *testing.T) {
107107
rt := NewReconcileTarget("workspace-1", "api-service-production")
108108
rt.Complete(StatusCompleted)
109109
spans := rt.exporter.getSpans()
110-
110+
111111
err := store.WriteSpans(ctx, spans)
112112
if err != nil {
113113
t.Fatalf("WriteSpans failed: %v", err)
@@ -138,7 +138,7 @@ func TestInMemoryStore_Clear(t *testing.T) {
138138
planning.End()
139139
rt.Complete(StatusCompleted)
140140
spans := rt.exporter.getSpans()
141-
141+
142142
err := store.WriteSpans(ctx, spans)
143143
if err != nil {
144144
t.Fatalf("WriteSpans failed: %v", err)
@@ -187,7 +187,7 @@ func TestInMemoryStore_ConcurrentWrites(t *testing.T) {
187187

188188
// All spans should be stored
189189
allSpans := store.GetSpans()
190-
190+
191191
// We expect at least numGoroutines * 2 spans (root + planning per goroutine)
192192
expectedMin := numGoroutines * 2
193193
if len(allSpans) < expectedMin {
@@ -205,7 +205,7 @@ func TestInMemoryStore_ConcurrentReads(t *testing.T) {
205205
planning.End()
206206
rt.Complete(StatusCompleted)
207207
spans := rt.exporter.getSpans()
208-
208+
209209
if err := store.WriteSpans(ctx, spans); err != nil {
210210
t.Fatalf("WriteSpans failed: %v", err)
211211
}
@@ -218,7 +218,7 @@ func TestInMemoryStore_ConcurrentReads(t *testing.T) {
218218
wg.Add(1)
219219
go func(id int) {
220220
defer wg.Done()
221-
221+
222222
retrieved := store.GetSpans()
223223
if len(retrieved) == 0 {
224224
t.Errorf("reader %d: expected non-empty spans", id)
@@ -258,7 +258,7 @@ func TestInMemoryStore_ConcurrentReadWrite(t *testing.T) {
258258
wg.Add(1)
259259
go func(id int) {
260260
defer wg.Done()
261-
261+
262262
// Just read, don't validate count since writes are happening
263263
_ = store.GetSpans()
264264
}(i)
@@ -281,7 +281,7 @@ func TestInMemoryStore_MultipleWrites(t *testing.T) {
281281
rt1 := NewReconcileTarget("workspace-1", "test-1")
282282
rt1.Complete(StatusCompleted)
283283
spans1 := rt1.exporter.getSpans()
284-
284+
285285
err := store.WriteSpans(ctx, spans1)
286286
if err != nil {
287287
t.Fatalf("first WriteSpans failed: %v", err)
@@ -293,7 +293,7 @@ func TestInMemoryStore_MultipleWrites(t *testing.T) {
293293
rt2 := NewReconcileTarget("workspace-1", "test-2")
294294
rt2.Complete(StatusCompleted)
295295
spans2 := rt2.exporter.getSpans()
296-
296+
297297
err = store.WriteSpans(ctx, spans2)
298298
if err != nil {
299299
t.Fatalf("second WriteSpans failed: %v", err)
@@ -320,19 +320,19 @@ func TestInMemoryStore_LargeBatch(t *testing.T) {
320320
// Create a trace with many spans
321321
rt := NewReconcileTarget("workspace-1", "test")
322322
planning := rt.StartPlanning()
323-
323+
324324
// Create many evaluations
325325
for i := 0; i < 100; i++ {
326326
eval := planning.StartEvaluation("Policy")
327327
eval.SetResult(ResultAllowed, "Approved")
328328
eval.End()
329329
}
330-
330+
331331
planning.End()
332332
rt.Complete(StatusCompleted)
333333

334334
spans := rt.exporter.getSpans()
335-
335+
336336
err := store.WriteSpans(ctx, spans)
337337
if err != nil {
338338
t.Fatalf("WriteSpans failed: %v", err)
@@ -366,15 +366,15 @@ func TestInMemoryStore_PreservesSpanData(t *testing.T) {
366366
rt.Complete(StatusCompleted)
367367

368368
spans := rt.exporter.getSpans()
369-
369+
370370
err := store.WriteSpans(ctx, spans)
371371
if err != nil {
372372
t.Fatalf("WriteSpans failed: %v", err)
373373
}
374374

375375
// Retrieve and verify span data
376376
storedSpans := store.GetSpans()
377-
377+
378378
// Find the evaluation span
379379
var evalSpan sdktrace.ReadOnlySpan
380380
for _, span := range storedSpans {
@@ -423,7 +423,7 @@ func TestInMemoryStore_ClearAfterMultipleWrites(t *testing.T) {
423423
rt := NewReconcileTarget("workspace-1", "test")
424424
rt.Complete(StatusCompleted)
425425
spans := rt.exporter.getSpans()
426-
426+
427427
if err := store.WriteSpans(ctx, spans); err != nil {
428428
t.Fatalf("WriteSpans %d failed: %v", i, err)
429429
}
@@ -446,7 +446,7 @@ func TestInMemoryStore_ClearAfterMultipleWrites(t *testing.T) {
446446
rt := NewReconcileTarget("workspace-1", "test")
447447
rt.Complete(StatusCompleted)
448448
spans := rt.exporter.getSpans()
449-
449+
450450
if err := store.WriteSpans(ctx, spans); err != nil {
451451
t.Fatalf("WriteSpans after clear failed: %v", err)
452452
}
@@ -476,4 +476,3 @@ func TestInMemoryStore_NilContext(t *testing.T) {
476476
t.Error("spans should be stored even with nil context")
477477
}
478478
}
479-

apps/workspace-engine/pkg/workspace/releasemanager/trace/phases_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,4 +781,3 @@ func TestPhase_NestedDepth(t *testing.T) {
781781
}
782782
}
783783
}
784-

apps/workspace-engine/pkg/workspace/workspace.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ func New(ctx context.Context, id string, options ...WorkspaceOption) *Workspace
1313
s := store.New(id, cs)
1414

1515
ws := &Workspace{
16-
ID: id,
17-
store: s,
18-
changeset: cs,
16+
ID: id,
17+
store: s,
18+
changeset: cs,
1919
traceStore: trace.NewInMemoryStore(),
2020
}
2121

apps/workspace-engine/test/e2e/engine_trace_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,3 @@ func TestEngine_Trace_ConcurrentDeployments(t *testing.T) {
513513

514514
t.Logf("Captured %d unique traces with %d total spans", len(traceIDs), len(spans))
515515
}
516-

apps/workspace-engine/test/integration/trace_helpers.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func VerifyTraceTimeline(t *testing.T, spans []sdktrace.ReadOnlySpan) {
148148
// ExtractTraceMetadata extracts metadata from span events
149149
func ExtractTraceMetadata(span sdktrace.ReadOnlySpan) map[string]interface{} {
150150
metadata := make(map[string]interface{})
151-
151+
152152
for _, event := range span.Events() {
153153
for _, attr := range event.Attributes {
154154
key := string(attr.Key)
@@ -164,7 +164,7 @@ func ExtractTraceMetadata(span sdktrace.ReadOnlySpan) map[string]interface{} {
164164
}
165165
}
166166
}
167-
167+
168168
return metadata
169169
}
170170

@@ -222,13 +222,13 @@ func VerifySequenceNumbers(t *testing.T, spans []sdktrace.ReadOnlySpan) {
222222

223223
var sequences []int
224224
seenSequences := make(map[int]bool)
225-
225+
226226
for _, span := range spans {
227227
seqAttr, hasSeq := GetSpanAttribute(span, "ctrlplane.sequence")
228228
if hasSeq {
229229
seq := int(seqAttr.AsInt64())
230230
sequences = append(sequences, seq)
231-
231+
232232
// Check for duplicates
233233
if seenSequences[seq] {
234234
t.Errorf("duplicate sequence number found: %d in sequences %v", seq, sequences)
@@ -245,7 +245,7 @@ func VerifySequenceNumbers(t *testing.T, spans []sdktrace.ReadOnlySpan) {
245245
break
246246
}
247247
}
248-
248+
249249
// Check no sequence is out of range
250250
for seq := range seenSequences {
251251
if seq < 0 || seq >= n {
@@ -259,14 +259,14 @@ func VerifySequenceNumbers(t *testing.T, spans []sdktrace.ReadOnlySpan) {
259259
func DumpTrace(t *testing.T, spans []sdktrace.ReadOnlySpan) {
260260
t.Helper()
261261
t.Logf("=== Trace Dump (%d spans) ===", len(spans))
262-
262+
263263
for i, span := range spans {
264264
depth, _ := GetSpanAttribute(span, "ctrlplane.depth")
265265
seq, _ := GetSpanAttribute(span, "ctrlplane.sequence")
266266
phase, _ := GetSpanAttribute(span, "ctrlplane.phase")
267267
nodeType, _ := GetSpanAttribute(span, "ctrlplane.node_type")
268268
status, _ := GetSpanAttribute(span, "ctrlplane.status")
269-
269+
270270
t.Logf("[%d] %s (phase=%s, type=%s, status=%s, depth=%d, seq=%d)",
271271
i,
272272
span.Name(),
@@ -294,7 +294,7 @@ func CountSpansByType(spans []sdktrace.ReadOnlySpan, nodeType trace.NodeType) in
294294
// AssertSpanExists verifies a span with specific name exists
295295
func AssertSpanExists(t *testing.T, spans []sdktrace.ReadOnlySpan, name string) sdktrace.ReadOnlySpan {
296296
t.Helper()
297-
297+
298298
span, found := FindSpanByName(spans, name)
299299
if !found {
300300
t.Fatalf("span %q not found in trace", name)
@@ -305,7 +305,7 @@ func AssertSpanExists(t *testing.T, spans []sdktrace.ReadOnlySpan, name string)
305305
// AssertSpanCount verifies the total number of spans
306306
func AssertSpanCount(t *testing.T, spans []sdktrace.ReadOnlySpan, expected int) {
307307
t.Helper()
308-
308+
309309
if len(spans) != expected {
310310
t.Errorf("expected %d spans, got %d", expected, len(spans))
311311
DumpTrace(t, spans)
@@ -315,7 +315,7 @@ func AssertSpanCount(t *testing.T, spans []sdktrace.ReadOnlySpan, expected int)
315315
// AssertPhaseExists verifies a phase span exists
316316
func AssertPhaseExists(t *testing.T, spans []sdktrace.ReadOnlySpan, phase trace.Phase) sdktrace.ReadOnlySpan {
317317
t.Helper()
318-
318+
319319
phaseSpans := FindSpansByPhase(spans, phase)
320320
if len(phaseSpans) == 0 {
321321
t.Fatalf("phase %s not found in trace", phase)
@@ -324,11 +324,10 @@ func AssertPhaseExists(t *testing.T, spans []sdktrace.ReadOnlySpan, phase trace.
324324
return phaseSpans[0]
325325
}
326326

327-
328327
// VerifyNoTrace ensures no trace was created (for blocked/skipped deployments)
329328
func VerifyNoTrace(t *testing.T, spans []sdktrace.ReadOnlySpan, phaseName string) {
330329
t.Helper()
331-
330+
332331
for _, span := range spans {
333332
if span.Name() == phaseName {
334333
t.Errorf("unexpected span %s found in trace", phaseName)
@@ -341,7 +340,7 @@ func GetSpanByPhaseAndType(spans []sdktrace.ReadOnlySpan, phase trace.Phase, nod
341340
for _, span := range spans {
342341
phaseAttr, hasPhase := GetSpanAttribute(span, "ctrlplane.phase")
343342
typeAttr, hasType := GetSpanAttribute(span, "ctrlplane.node_type")
344-
343+
345344
if hasPhase && hasType &&
346345
phaseAttr.AsString() == string(phase) &&
347346
typeAttr.AsString() == string(nodeType) {
@@ -350,4 +349,3 @@ func GetSpanByPhaseAndType(spans []sdktrace.ReadOnlySpan, phase trace.Phase, nod
350349
}
351350
return nil, fmt.Errorf("span with phase=%s and type=%s not found", phase, nodeType)
352351
}
353-

0 commit comments

Comments
 (0)