Add call graph fixtures for various languages and scenarios
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Findings Ledger CI / build-test (push) Has been cancelled
Findings Ledger CI / migration-validation (push) Has been cancelled
Findings Ledger CI / generate-manifest (push) Has been cancelled
Lighthouse CI / Lighthouse Audit (push) Has been cancelled
Lighthouse CI / Axe Accessibility Audit (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Reachability Corpus Validation / validate-corpus (push) Has been cancelled
Reachability Corpus Validation / validate-ground-truths (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Reachability Corpus Validation / determinism-check (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled

- Introduced `all-edge-reasons.json` to test edge resolution reasons in .NET.
- Added `all-visibility-levels.json` to validate method visibility levels in .NET.
- Created `dotnet-aspnetcore-minimal.json` for a minimal ASP.NET Core application.
- Included `go-gin-api.json` for a Go Gin API application structure.
- Added `java-spring-boot.json` for the Spring PetClinic application in Java.
- Introduced `legacy-no-schema.json` for legacy application structure without schema.
- Created `node-express-api.json` for an Express.js API application structure.
This commit is contained in:
master
2025-12-16 10:44:24 +02:00
parent 4391f35d8a
commit 5a480a3c2a
223 changed files with 19367 additions and 727 deletions

View File

@@ -0,0 +1,143 @@
using System.Text.Json;
using Microsoft.Extensions.Logging.Abstractions;
using StellaOps.ExportCenter.Core.EvidenceCache;
namespace StellaOps.ExportCenter.Tests.EvidenceCache;
public sealed class LocalEvidenceCacheServiceTests
{
[Fact]
public async Task CacheEvidenceAsync_WritesManifestAndUpdatesStatistics()
{
using var temp = new TempDirectory();
var service = new LocalEvidenceCacheService(TimeProvider.System, NullLogger<LocalEvidenceCacheService>.Instance);
var bundle = new CachedEvidenceBundle
{
AlertId = "alert-1",
ArtifactId = "scan-1",
ComputedAt = DateTimeOffset.Parse("2025-12-14T00:00:00Z"),
Reachability = new CachedEvidenceSection
{
Status = EvidenceStatus.Available,
Hash = "sha256:reach",
Proof = new { ok = true }
},
CallStack = new CachedEvidenceSection
{
Status = EvidenceStatus.Available
},
Provenance = new CachedEvidenceSection
{
Status = EvidenceStatus.PendingEnrichment,
UnavailableReason = "offline"
},
VexStatus = new CachedEvidenceSection
{
Status = EvidenceStatus.Available
}
};
var cacheResult = await service.CacheEvidenceAsync(temp.Path, bundle, CancellationToken.None);
Assert.True(cacheResult.Success);
var cacheDir = Path.Combine(temp.Path, ".evidence");
Assert.True(Directory.Exists(cacheDir));
Assert.True(File.Exists(Path.Combine(cacheDir, "manifest.json")));
Assert.True(File.Exists(Path.Combine(cacheDir, "bundles", "alert-1.evidence.json")));
Assert.True(File.Exists(Path.Combine(cacheDir, "enrichment_queue.json")));
var statistics = await service.GetStatisticsAsync(temp.Path, CancellationToken.None);
Assert.Equal(1, statistics.TotalBundles);
Assert.Equal(0, statistics.FullyAvailable);
Assert.Equal(0, statistics.PartiallyAvailable);
Assert.Equal(1, statistics.PendingEnrichment);
Assert.True(statistics.OfflineResolvablePercentage >= 99.99);
Assert.True(statistics.TotalSizeBytes > 0);
}
[Fact]
public async Task QueueEnrichmentAsync_DeduplicatesRequests()
{
using var temp = new TempDirectory();
var service = new LocalEvidenceCacheService(TimeProvider.System, NullLogger<LocalEvidenceCacheService>.Instance);
var request = new EnrichmentRequest
{
AlertId = "alert-1",
ArtifactId = "scan-1",
EvidenceType = "reachability",
Reason = "missing",
QueuedAt = DateTimeOffset.MinValue,
AttemptCount = 0
};
await service.QueueEnrichmentAsync(temp.Path, request, CancellationToken.None);
await service.QueueEnrichmentAsync(temp.Path, request with { Reason = "still missing" }, CancellationToken.None);
var queuePath = Path.Combine(temp.Path, ".evidence", "enrichment_queue.json");
Assert.True(File.Exists(queuePath));
using var document = JsonDocument.Parse(await File.ReadAllTextAsync(queuePath, CancellationToken.None));
var requests = document.RootElement.GetProperty("requests");
Assert.Equal(1, requests.GetArrayLength());
Assert.Equal("alert-1", requests[0].GetProperty("alert_id").GetString());
Assert.Equal("reachability", requests[0].GetProperty("evidence_type").GetString());
}
[Fact]
public async Task ProcessEnrichmentQueueAsync_IncrementsAttemptCounts()
{
using var temp = new TempDirectory();
var service = new LocalEvidenceCacheService(TimeProvider.System, NullLogger<LocalEvidenceCacheService>.Instance);
await service.QueueEnrichmentAsync(
temp.Path,
new EnrichmentRequest
{
AlertId = "alert-1",
ArtifactId = "scan-1",
EvidenceType = "provenance",
QueuedAt = DateTimeOffset.MinValue,
AttemptCount = 0
},
CancellationToken.None);
var result = await service.ProcessEnrichmentQueueAsync(temp.Path, CancellationToken.None);
Assert.Equal(0, result.ProcessedCount);
Assert.Equal(1, result.FailedCount);
Assert.Equal(1, result.RemainingCount);
var queuePath = Path.Combine(temp.Path, ".evidence", "enrichment_queue.json");
using var document = JsonDocument.Parse(await File.ReadAllTextAsync(queuePath, CancellationToken.None));
var requests = document.RootElement.GetProperty("requests");
Assert.Equal(1, requests.GetArrayLength());
Assert.Equal(1, requests[0].GetProperty("attempt_count").GetInt32());
}
private sealed class TempDirectory : IDisposable
{
public TempDirectory()
{
Path = Directory.CreateTempSubdirectory("stellaops-exportcache-").FullName;
}
public string Path { get; }
public void Dispose()
{
try
{
if (Directory.Exists(Path))
{
Directory.Delete(Path, recursive: true);
}
}
catch
{
}
}
}
}