Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright 2026 Specter Ops, Inc.
#
# Licensed under the Apache License, Version 2.0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

name: Run Go tests

on:
pull_request:
branches:
- "main"
- "stage/**"
types:
- "opened"
- "synchronize"

jobs:

# TODO: fix existing issues before uncommenting
# vet:
# name: Vet source code
# runs-on: ubuntu-latest
# steps:
# - name: Checkout source code for this repository
# uses: actions/checkout@v4
#
# - name: Install Go
# uses: actions/setup-go@v5
# with:
# go-version-file: go.mod
# cache: true
# check-latest: true
#
# - name: Vet Code
# run: |
# go vet ./...

test:
runs-on: ubuntu-latest
steps:
- name: Checkout source code for this repository
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
check-latest: true

- name: Run Tests
run: |
go test ./...
3 changes: 2 additions & 1 deletion algo/reach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/specterops/dawgs/algo"
"github.com/specterops/dawgs/container"
"github.com/specterops/dawgs/container/util"
"github.com/specterops/dawgs/graph"
"github.com/stretchr/testify/require"
)
Expand All @@ -21,7 +22,7 @@ import (
// 8 → 9 (bridge from C to D)
func TestReachabilityCache(t *testing.T) {
var (
digraph = container.BuildGraph(container.NewCSRGraph, map[uint64][]uint64{
digraph = util.BuildGraph(container.NewCSRDigraphBuilder, map[uint64][]uint64{
0: {1},
1: {2},
2: {0, 3},
Expand Down
10 changes: 5 additions & 5 deletions algo/scc.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,30 +284,30 @@ func (s ComponentGraph) OriginReachable(startID, endID uint64) bool {
func NewComponentGraph(ctx context.Context, originGraph container.DirectedGraph) ComponentGraph {
var (
componentMembers, memberComponentLookup = StronglyConnectedComponents(ctx, originGraph)
componentDigraph = container.NewCSRGraph()
componentDigraphBuilder = container.NewCSRDigraphBuilder()
)

defer util.SLogMeasureFunction("NewComponentGraph")()

// Ensure all components are present as vertices, even if they have no edges
for componentID := range componentMembers {
componentDigraph.AddNode(uint64(componentID))
componentDigraphBuilder.AddNode(uint64(componentID))
}

originGraph.EachNode(func(node uint64) bool {
nodeComponent := memberComponentLookup[node]

originGraph.EachAdjacentNode(node, graph.DirectionInbound, func(adjacent uint64) bool {
if adjacentComponent := memberComponentLookup[adjacent]; nodeComponent != adjacentComponent {
componentDigraph.AddEdge(adjacentComponent, nodeComponent)
componentDigraphBuilder.AddEdge(adjacentComponent, nodeComponent)
}

return util.IsContextLive(ctx)
})

originGraph.EachAdjacentNode(node, graph.DirectionOutbound, func(adjacent uint64) bool {
if adjacentComponent := memberComponentLookup[adjacent]; nodeComponent != adjacentComponent {
componentDigraph.AddEdge(nodeComponent, adjacentComponent)
componentDigraphBuilder.AddEdge(nodeComponent, adjacentComponent)
}

return util.IsContextLive(ctx)
Expand All @@ -319,6 +319,6 @@ func NewComponentGraph(ctx context.Context, originGraph container.DirectedGraph)
return ComponentGraph{
componentMembers: componentMembers,
memberComponentLookup: memberComponentLookup,
digraph: componentDigraph,
digraph: componentDigraphBuilder.Build(),
}
}
11 changes: 6 additions & 5 deletions algo/scc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/specterops/dawgs/container"
"github.com/specterops/dawgs/container/util"
"github.com/specterops/dawgs/graph"
"github.com/stretchr/testify/require"
)
Expand All @@ -15,7 +16,7 @@ import (
// 0 -> 1 -> 2 -> 3
func TestSCC_Chain(t *testing.T) {
var (
digraph = container.BuildGraph(container.NewCSRGraph, map[uint64][]uint64{
digraph = util.BuildGraph(container.NewCSRDigraphBuilder, map[uint64][]uint64{
0: {1},
1: {2},
2: {3},
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestSCC_Chain(t *testing.T) {
// 1
func TestSCC_SimpleCycle(t *testing.T) {
var (
digraph = container.BuildGraph(container.NewCSRGraph, map[uint64][]uint64{
digraph = util.BuildGraph(container.NewCSRDigraphBuilder, map[uint64][]uint64{
0: {0}, // self‑loop component
1: {}, // isolated vertex – must be present as a key!
})
Expand All @@ -74,7 +75,7 @@ func TestSCC_SimpleCycle(t *testing.T) {
// 3 -> 1
func TestSCC_FigureEight(t *testing.T) {
var (
digraph = container.BuildGraph(container.NewCSRGraph, map[uint64][]uint64{
digraph = util.BuildGraph(container.NewCSRDigraphBuilder, map[uint64][]uint64{
0: {1},
1: {2, 3},
2: {0},
Expand Down Expand Up @@ -107,7 +108,7 @@ func TestSCC_FigureEight(t *testing.T) {
// 2 → 3 (bridge from A to B)
func TestComponentGraph_EdgeDeduplication(t *testing.T) {
var (
digraph = container.BuildGraph(container.NewCSRGraph, map[uint64][]uint64{
digraph = util.BuildGraph(container.NewCSRDigraphBuilder, map[uint64][]uint64{
0: {1},
1: {2},
2: {0, 3},
Expand Down Expand Up @@ -162,7 +163,7 @@ func TestComponentGraph_EdgeDeduplication(t *testing.T) {
// 6 -> 7 -> 8 -> 6
func TestComponentHistogram(t *testing.T) {
var (
digraph = container.BuildGraph(container.NewCSRGraph, map[uint64][]uint64{
digraph = util.BuildGraph(container.NewCSRDigraphBuilder, map[uint64][]uint64{
0: {1},
1: {2},
2: {0},
Expand Down
1 change: 1 addition & 0 deletions container/adjacencymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func BuildAdjacencyMapGraph(adj map[uint64][]uint64) MutableDirectedGraph {

return digraph
}

func (s *adjacencyMapDigraph) AddNode(node uint64) {
s.nodes.Add(node)
}
Expand Down
16 changes: 14 additions & 2 deletions container/adjacencymap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import (
"github.com/stretchr/testify/require"
)

func addAdjacencyMapToMutableDigraph(digraph container.MutableDirectedGraph, adj map[uint64][]uint64) {
for src, outs := range adj {
digraph.AddNode(src)

for _, dst := range outs {
digraph.AddNode(dst)
digraph.AddEdge(src, dst)
}
}
}

func TestAdjacencyMapDigraph(t *testing.T) {
var (
digraph = container.NewAdjacencyMapGraph()
Expand Down Expand Up @@ -50,7 +61,8 @@ func BenchmarkAdjacencyMapDigraphAdjacency(b *testing.B) {
}
}

csrGraph := container.BuildGraph(container.NewAdjacencyMapGraph, adj)
digraph := container.NewAdjacencyMapGraph()
addAdjacencyMapToMutableDigraph(digraph, adj)

// Use a simple delegate function for testing
delegate := func(adjacent uint64) bool {
Expand All @@ -62,7 +74,7 @@ func BenchmarkAdjacencyMapDigraphAdjacency(b *testing.B) {
node := uint64(0)

for b.Loop() {
csrGraph.EachAdjacentNode(node, graph.DirectionOutbound, delegate)
digraph.EachAdjacentNode(node, graph.DirectionOutbound, delegate)

if node += 1; node >= maxNodes {
node = 0
Expand Down
Loading