Files
osmedeus/internal/logger/logger_test.go
T
j3ssie f5840272c5 feat: add run cancellation, event enhancements, and performance optimizations
Major features:
- Add run registry for tracking active runs with PID management
- Add API-based run cancellation with process termination
- Add event trigger input vars syntax for multi-variable extraction
- Add filter_functions with utility function support in triggers
- Add event envelope injection for full event context in workflows
- Add write coordinator for batched database operations

API improvements:
- Add logout endpoint and diffs endpoints for assets/vulnerabilities
- Add step-results listing endpoint
- Update schedule model with target, workspace, params fields
- Change run_id to run_uuid across API responses

Performance:
- Add compiled JS program caching for 60-80% faster loop conditions
- Add parallel shard rendering for 20-40% faster workflow startup
- Add memory-mapped I/O for large file line counting
- Add efficient output buffer combining in runners
- Add mtime-based cache invalidation for workflow loader

Other changes:
- Rename trigger field from trigger to triggers in workflow YAML
- Disable pongo2 HTML autoescape for shell command templates
- Update JWT expiration default to 1440 minutes (1 day)
- Change CORS default to reflect-origin for credentials support
- Add source_type field to events (run, eval, api)
- Skip copying core Unix tools to external-binaries
2026-01-24 01:11:33 +08:00

98 lines
2.0 KiB
Go

package logger
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStripANSI(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "no ANSI codes",
input: "plain text",
expected: "plain text",
},
{
name: "single color code",
input: "\x1b[90mhello\x1b[0m",
expected: "hello",
},
{
name: "multiple color codes",
input: "\x1b[1m\x1b[31mred bold\x1b[0m",
expected: "red bold",
},
{
name: "color in middle of text",
input: "start \x1b[90mmiddle\x1b[0m end",
expected: "start middle end",
},
{
name: "timestamp with ANSI",
input: "\x1b[90m2026-01-23T17:59:20+08:00\x1b[0m",
expected: "2026-01-23T17:59:20+08:00",
},
{
name: "JSON block with embedded ANSI timestamp",
input: "{\"timestamp\": \"\x1b[90m2026-01-23T17:59:20+08:00\x1b[0m\"}",
expected: "{\"timestamp\": \"2026-01-23T17:59:20+08:00\"}",
},
{
name: "empty string",
input: "",
expected: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := stripANSI(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}
func TestColorJSONFields(t *testing.T) {
const gray = "\x1b[90m"
const reset = "\x1b[0m"
tests := []struct {
name string
input string
expected string
}{
{
name: "no JSON",
input: "plain text",
expected: "plain text",
},
{
name: "simple JSON block",
input: `{"key": "value"}`,
expected: gray + `{"key": "value"}` + reset,
},
{
name: "text with JSON",
input: `INFO message {"data": "test"}`,
expected: `INFO message ` + gray + `{"data": "test"}` + reset,
},
{
name: "JSON with embedded ANSI (stripped)",
input: "{\"timestamp\": \"\x1b[90m2026-01-23\x1b[0m\"}",
expected: gray + `{"timestamp": "2026-01-23"}` + reset,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := colorJSONFields(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}