Skip to content

armgit / AiSOC

Public Imported from GitHub
0

Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.

fix: main is red — a governed-verb table and a Neo4j retry capped at a sixth of its window (#1219)

Beenu Aroraa4de2118bb6b
diff --git a/apps/web/src/components/layout/SidebarBranding.test.tsx b/apps/web/src/components/layout/SidebarBranding.test.tsx
index 12b8d060d..3925ae8e3 100644
--- a/apps/web/src/components/layout/SidebarBranding.test.tsx
+++ b/apps/web/src/components/layout/SidebarBranding.test.tsx
@@ -71,7 +71,17 @@ beforeEach(() => {
requests = [];
vi.stubGlobal('fetch', async (url: string, init?: RequestInit) => {
requests.push({ url: String(url), headers: (init?.headers ?? {}) as Record<string, string> });
- return new Response(new Blob(['<svg/>'], { type: 'image/svg+xml' }), { status: 200 });
+ // The two members `brandingApi.logo` reads, and nothing else. A real
+ // `Response` wrapping a real `Blob` depends on undici/jsdom interop that
+ // differs between a developer machine and the runner: this test passed
+ // here under every combination tried — single file, full suite, with
+ // coverage — and returned a null logo on CI. Doubling the contract the
+ // code reads removes the variable rather than guessing at it.
+ return {
+ ok: true,
+ status: 200,
+ blob: async () => new Blob(['<svg/>'], { type: 'image/svg+xml' }),
+ } as unknown as Response;
});
// jsdom implements neither half of the object-URL API. Browser plumbing,
// not ours — stubbed so the component's own code path still runs.
@@ -92,7 +102,11 @@ describe('Sidebar branding', () => {
// cache and a deduping window, so a second `render` in this file resolves
// from neither the cache nor a fresh request and shows the unbranded
// wordmark. Splitting these would test the cache rather than the console.
- it("shows a white-labelled organisation's name, palette and logo, and drops the platform wordmark", async () => {
+ // 20s, against vitest's 5s default. The case waits on two chained async
+ // hops and the wait below is budgeted at 8s, so the test has to outlive
+ // it — at the default the case timed out before asserting anything, which
+ // reports nothing about the logo either way.
+ it("shows a white-labelled organisation's name, palette and logo, and drops the platform wordmark", { timeout: 20_000 }, async () => {
const { container } = render(<Sidebar />);
expect(await screen.findByText('Acme Shield')).toBeInTheDocument();
@@ -103,15 +117,31 @@ describe('Sidebar branding', () => {
// Two chained async hops, not one: branding resolves, and only then does
// the component fetch the asset with its credential and turn the blob
- // into an object URL. `vi.waitFor` defaults to a second, which is enough
- // here and was not on a loaded CI runner — this timed out on GitHub's
- // runners while passing locally every time. The wait is real rather than
- // a race being papered over, so it gets the headroom explicitly.
+ // into an object URL. The wait is budgeted at 8s inside the 20s test
+ // timeout above, so the two cannot cross — at vitest's 5s default this
+ // case timed out before it could assert anything.
+ //
+ // The request is asserted before the element, so a failure says which
+ // of the two hops broke. "expected null not to be null" on its own does
+ // not distinguish a logo that was never requested from one that was
+ // requested and never rendered, and that ambiguity cost a full CI round.
+ await vi.waitFor(
+ () => {
+ expect(
+ requests.map((r) => r.url),
+ 'the component never requested the logo asset',
+ ).toContainEqual(expect.stringContaining('/branding/assets/'));
+ },
+ { timeout: 8_000 },
+ );
await vi.waitFor(
() => {
- expect(container.querySelector('img')).not.toBeNull();
+ expect(
+ container.querySelector('img'),
+ 'the asset was requested but no <img> rendered, so the blob never became an object URL',
+ ).not.toBeNull();
},
- { timeout: 10_000 },
+ { timeout: 8_000 },
);
const logo = container.querySelector('img') as HTMLImageElement;
diff --git a/apps/web/src/components/playbooks/stepVocabulary.test.ts b/apps/web/src/components/playbooks/stepVocabulary.test.ts
index df9309448..12e223f98 100644
--- a/apps/web/src/components/playbooks/stepVocabulary.test.ts
+++ b/apps/web/src/components/playbooks/stepVocabulary.test.ts
@@ -75,11 +75,19 @@ const VALID_PARAMS: Record<StepType, Record<string, unknown>> = {
const TARGET_KEY: Record<StepType, string | null> = {
enrich: null,
investigate: null,
- notify: null,
+ // Depth 5.1 made `notify` a governed verb. Its target is the channel:
+ // `engine._notify_params` pins it into `vendor_id` rather than letting the
+ // executor infer it, for the same reason the SIEM arms pin
+ // `alert_vendor` — otherwise whichever destination happens to have
+ // credentials first decides where a page goes.
+ notify: 'channel',
close_case: null,
http: null,
condition: null,
- osquery_live_query: null,
+ // Governed by depth 5.1 alongside `notify`. The fleet it asks is the
+ // target: `engine._osquery_params` sends `target_hosts`, falling back to
+ // the run's resolved target when the step names none.
+ osquery_live_query: 'target_hosts',
approval: null,
block_ip: 'ip_field', // pre-existing convention
isolate_host: 'host_field', // pre-existing convention
diff --git a/services/ingest/internal/graph/writer.go b/services/ingest/internal/graph/writer.go
index 11219192a..2b7908a39 100644
--- a/services/ingest/internal/graph/writer.go
+++ b/services/ingest/internal/graph/writer.go
@@ -272,6 +272,16 @@ func New(ctx context.Context, cfg Config) (*Writer, error) {
// would turn an optional dependency into a required one.
const connectRetryWindow = 60 * time.Second
+// ConnectRetryWindow is connectRetryWindow, for a caller that has to build a
+// context deadline around New.
+//
+// It is exported because the caller's deadline was independently written as
+// 10s while this window said 60s, so the retry could only ever use a sixth
+// of its budget: a Neo4j that was merely slow to boot looked permanently
+// unreachable, and graph-at-ingest stayed off for the life of the process
+// over a `warn` line. One number, read by both.
+func ConnectRetryWindow() time.Duration { return connectRetryWindow }
+
// verifyWithRetry polls until the driver answers or the window closes.
func verifyWithRetry(ctx context.Context, driver neo4j.DriverWithContext, window time.Duration) error {
deadline := time.Now().Add(window)
diff --git a/services/ingest/internal/graph/writer_test.go b/services/ingest/internal/graph/writer_test.go
index 991d6704b..b53071bdb 100644
--- a/services/ingest/internal/graph/writer_test.go
+++ b/services/ingest/internal/graph/writer_test.go
@@ -425,3 +425,29 @@ func TestVerifyWithRetryHonoursCancellation(t *testing.T) {
t.Fatal("verifyWithRetry ignored a cancelled context")
}
}
+
+// TestTheRetryWindowIsNotCappedByItsCaller pins the two numbers together.
+//
+// `main.go` built a 10s deadline around `New` while `connectRetryWindow`
+// said 60s, so the retry could only ever use a sixth of its budget. The
+// visible effect was that a Neo4j which was merely slow to boot read as
+// permanently unreachable, and graph-at-ingest stayed off for the life of
+// the process over a single `warn` line — which is how the CI event-spine
+// job began failing its "graph-at-ingest is on by default" assertion.
+//
+// The caller now derives its deadline from `ConnectRetryWindow()`. This
+// asserts the accessor really is the constant, so the two cannot drift
+// apart again by someone editing one of them.
+func TestTheRetryWindowIsNotCappedByItsCaller(t *testing.T) {
+ if ConnectRetryWindow() != connectRetryWindow {
+ t.Fatalf("the exported window (%s) is not the constant the retry loop uses (%s)",
+ ConnectRetryWindow(), connectRetryWindow)
+ }
+ // A caller that honours it must allow at least one full window. Stated
+ // as an inequality rather than an equality so adding headroom stays
+ // legal and shrinking below the window does not.
+ if ConnectRetryWindow() < 30*time.Second {
+ t.Fatalf("a window of %s is too short for a cold Neo4j container; "+
+ "the job this guards waits on a 15s healthcheck interval", ConnectRetryWindow())
+ }
+}
diff --git a/services/ingest/main.go b/services/ingest/main.go
index 2f8d3c0bc..1e090321d 100644
--- a/services/ingest/main.go
+++ b/services/ingest/main.go
@@ -85,7 +85,10 @@ func main() {
// the graph writer NEVER block fusion ingest; the writer's queue is
// bounded and drops on full + emits a metric.
if cfg.GraphEnabled {
- gctx, gcancel := context.WithTimeout(context.Background(), 10*time.Second)
+ // Derived from the package's own retry window rather than written
+ // here, plus headroom for the final attempt. An independent
+ // number is how the retry came to be capped at a sixth of it.
+ gctx, gcancel := context.WithTimeout(context.Background(), graph.ConnectRetryWindow()+15*time.Second)
gw, err := graph.New(gctx, graph.Config{
URI: cfg.Neo4jURI,
Username: cfg.Neo4jUser,