Files
SnapOtter/tests/unit/api/enterprise-flags.test.ts
T
SnapOtterandGitHub 3fb8164fa5 feat: add OpenTelemetry distributed tracing (enterprise) (#232)
* feat(tracing): add OpenTelemetry dependencies and --import preload flag

* feat(enterprise): add distributed_tracing feature gate

* feat(tracing): add SDK bootstrap with enterprise gating

* fix(tracing): correct test coverage for enterprise-unavailable path and prevent double-init

Test 2 now mocks @snapotter/enterprise to throw an import error, exercising
the catch block in the preload. Test 3 imports with no endpoint so the preload
is a no-op, avoiding leaked SDK from double-initialization. Added idempotency
guard to initTracing() as a safety net.

* feat(tracing): add Pino trace mixin and shared logger

When OTel tracing is active, every Pino log line now includes traceId,
spanId, and traceFlags fields for log-to-trace correlation. The mixin
is a no-op when no SDK is registered (community users).

* feat(tracing): add _otel to ToolJobData and inject trace context at enqueue

Add optional _otel carrier field to ToolJobData for W3C trace context
propagation across BullMQ job boundaries. When an active OTel span exists,
propagation.inject() writes traceparent/tracestate into the job data before
queue.add(). When no SDK is registered (community edition), the carrier
stays empty and _otel remains undefined -- zero overhead.

* feat(tracing): extract trace context and create spans in BullMQ worker

* feat(tracing): inject trace context into Python sidecar calls

* feat(tracing): add trace context extraction to Python sidecar

* feat(tracing): add shutdownTracing to graceful shutdown sequence

* feat(tracing): enrich HTTP spans with tool_id and user_id attributes

* docs: add OpenTelemetry env var documentation to .env.example

* test(tracing): add lifecycle integration tests for trace propagation

* fix(tracing): inject trace context into pipeline and batch flow jobs

* fix(tracing): add sidecar.execute Node-side span and remove unnecessary comment

Wraps PythonDispatcher.run() with a sidecar.execute span on the Node
side so traces show the full round-trip (Node span -> Python span).
Also removes an obvious comment from logger.ts.
2026-06-15 12:53:06 +08:00

45 lines
1.7 KiB
TypeScript

import { ENTERPRISE_FEATURES, PLAN_FEATURES } from "@snapotter/enterprise";
import { describe, expect, it } from "vitest";
describe("enterprise feature flags", () => {
it("includes all Phase 1 flags", () => {
expect(ENTERPRISE_FEATURES).toContain("siem_forwarding");
expect(ENTERPRISE_FEATURES).toContain("tamper_resistant_audit");
});
it("includes all Phase 2-4 flags", () => {
expect(ENTERPRISE_FEATURES).toContain("legal_hold");
expect(ENTERPRISE_FEATURES).toContain("gdpr_lifecycle");
expect(ENTERPRISE_FEATURES).toContain("admin_alerts");
});
it("team plan includes operational features", () => {
expect(PLAN_FEATURES.team).toContain("siem_forwarding");
expect(PLAN_FEATURES.team).toContain("audit_export");
expect(PLAN_FEATURES.team).toContain("upgrade_management");
expect(PLAN_FEATURES.team).toContain("admin_alerts");
});
it("team plan does NOT include compliance features", () => {
expect(PLAN_FEATURES.team).not.toContain("tamper_resistant_audit");
expect(PLAN_FEATURES.team).not.toContain("legal_hold");
expect(PLAN_FEATURES.team).not.toContain("gdpr_lifecycle");
});
it("enterprise plan includes everything", () => {
for (const feature of ENTERPRISE_FEATURES) {
expect(PLAN_FEATURES.enterprise).toContain(feature);
}
});
it("has exactly 19 features total", () => {
expect(ENTERPRISE_FEATURES).toHaveLength(19);
});
it("includes distributed_tracing in enterprise plan only", () => {
expect(ENTERPRISE_FEATURES).toContain("distributed_tracing");
expect(PLAN_FEATURES.enterprise).toContain("distributed_tracing");
expect(PLAN_FEATURES.team).not.toContain("distributed_tracing");
});
});