@obsunified/collector 2.2.3 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/auth.d.ts +1 -1
  2. package/dist/{chunk-ZSF5XP3B.js → chunk-RASSTGNB.js} +30 -22
  3. package/dist/chunk-RASSTGNB.js.map +1 -0
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.js +2562 -2311
  6. package/dist/index.js.map +1 -1
  7. package/dist/{ingest-auth-C5-8Mly5.d.ts → ingest-auth-BmP5-f96.d.ts} +32 -1
  8. package/dist/{openai-GSJZGFGL.js → openai-VDKVVZAV.js} +2 -2
  9. package/package.json +4 -2
  10. package/src/__tests__/autosre-closed-loop.test.ts +110 -0
  11. package/src/__tests__/db-parity.integration.test.ts +961 -0
  12. package/src/__tests__/internal-contracts-routes.test.ts +451 -0
  13. package/src/framework/env.ts +105 -0
  14. package/src/index.ts +13 -4
  15. package/src/lib/ai-store/evaluations.test.ts +3 -3
  16. package/src/lib/analyses-store.test.ts +6 -6
  17. package/src/lib/db-parity.ts +883 -0
  18. package/src/lib/eval-cases-store.test.ts +1 -1
  19. package/src/lib/eval-cases-store.ts +16 -4
  20. package/src/lib/evidence-references.ts +30 -22
  21. package/src/lib/stage6.test.ts +1 -1
  22. package/src/migrations/parity.test.ts +105 -3
  23. package/src/plugins/ai-receiver.ts +6 -1
  24. package/src/plugins/autosre-routes.ts +251 -140
  25. package/src/plugins/connected-routes/manifest.test.ts +114 -32
  26. package/src/plugins/connected-routes/manifest.ts +59 -76
  27. package/src/plugins/connected-routes.test.ts +10 -8
  28. package/src/plugins/connected-routes.ts +42 -12
  29. package/src/plugins/eval-cases-routes.ts +33 -10
  30. package/src/plugins/evidence-retrieval-routes.ts +60 -25
  31. package/dist/chunk-ZSF5XP3B.js.map +0 -1
  32. /package/dist/{openai-GSJZGFGL.js.map → openai-VDKVVZAV.js.map} +0 -0
@@ -135,6 +135,37 @@ interface CollectorEnv {
135
135
  /** @deprecated Use DASHBOARD_PASSWORD instead */
136
136
  TELEMETRY_QUERY_TOKEN?: string;
137
137
  }
138
+ /**
139
+ * Optional string settings on `CollectorEnv` that host adapters (such as
140
+ * `apps/collector-node`) forward directly from the process environment after
141
+ * trimming whitespace and coercing blank strings to `undefined`.
142
+ */
143
+ declare const COLLECTOR_OPTIONAL_STRING_ENV_KEYS: readonly ["RETENTION_HOURS", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "OPENAI_BASE_URL", "NARRATIVE_MODEL", "NARRATIVE_BUDGET_PER_HOUR", "ALERT_WEBHOOK_ALLOW_PRIVATE", "MAX_BODY_BYTES", "TELEMETRY_REDACT_FIELDS", "OBS_PAYLOAD_CAPTURE_DEFAULT"];
144
+ /**
145
+ * String settings on `CollectorEnv` that require explicit host handling (e.g.
146
+ * required auth secrets, CORS origin parsing, Worker-only self-instrumentation
147
+ * vars, or deprecated Worker tokens) and must not be blindly forwarded by the
148
+ * generic optional-env loop.
149
+ */
150
+ declare const COLLECTOR_HOST_MANAGED_ENV_KEYS: readonly ["INGEST_KEY", "DASHBOARD_PASSWORD", "DASHBOARD_TOKEN", "ALLOWED_ORIGINS", "ALLOW_UNAUTHENTICATED", "OBS_DASHBOARD_INGEST_KEY", "OBS_COLLECTOR_SELF_URL", "OBS_SELF_AWAIT_EXPORTS", "TELEMETRY_INGEST_TOKEN", "USAGE_INGEST_TOKEN", "TELEMETRY_QUERY_TOKEN"];
151
+ declare const COLLECTOR_STRING_ENV_MANIFEST: {
152
+ readonly forwarded: readonly ["RETENTION_HOURS", "ANTHROPIC_API_KEY", "OPENAI_API_KEY", "OPENAI_BASE_URL", "NARRATIVE_MODEL", "NARRATIVE_BUDGET_PER_HOUR", "ALERT_WEBHOOK_ALLOW_PRIVATE", "MAX_BODY_BYTES", "TELEMETRY_REDACT_FIELDS", "OBS_PAYLOAD_CAPTURE_DEFAULT"];
153
+ readonly hostManaged: readonly ["INGEST_KEY", "DASHBOARD_PASSWORD", "DASHBOARD_TOKEN", "ALLOWED_ORIGINS", "ALLOW_UNAUTHENTICATED", "OBS_DASHBOARD_INGEST_KEY", "OBS_COLLECTOR_SELF_URL", "OBS_SELF_AWAIT_EXPORTS", "TELEMETRY_INGEST_TOKEN", "USAGE_INGEST_TOKEN", "TELEMETRY_QUERY_TOKEN"];
154
+ };
155
+ type CollectorOptionalStringEnvKey = (typeof COLLECTOR_OPTIONAL_STRING_ENV_KEYS)[number];
156
+ type CollectorHostManagedEnvKey = (typeof COLLECTOR_HOST_MANAGED_ENV_KEYS)[number];
157
+ type CollectorManifestStringEnvKey = CollectorOptionalStringEnvKey | CollectorHostManagedEnvKey;
158
+ type CollectorObjectBindingKey = "DB" | "REPLAYS_BUCKET" | "PROFILES_BUCKET" | "TAIL_HUB";
159
+ type CollectorStringEnvKey = Exclude<keyof CollectorEnv, CollectorObjectBindingKey>;
160
+ /**
161
+ * Verifies that every string key in `declaredKeys` is categorized in either
162
+ * `COLLECTOR_OPTIONAL_STRING_ENV_KEYS` or `COLLECTOR_HOST_MANAGED_ENV_KEYS`
163
+ * without overlap. Throws if any key is uncategorized or duplicated.
164
+ */
165
+ declare function assertCollectorEnvManifestCompleteness(declaredKeys: readonly string[], manifest?: {
166
+ readonly forwarded: readonly string[];
167
+ readonly hostManaged: readonly string[];
168
+ }): void;
138
169
  interface CollectorRouteContext {
139
170
  hono: Context<{
140
171
  Bindings: CollectorEnv;
@@ -171,4 +202,4 @@ declare function createIngestAuth(config?: {
171
202
  };
172
203
  }>;
173
204
 
174
- export { type ChildSpanRunner as C, type Logger as L, type CollectorApp as a, type CollectorEnv as b, type CollectorRouteContext as c, consoleLogger as d, createIngestAuth as e, resetIngestAuthCache as r };
205
+ export { COLLECTOR_HOST_MANAGED_ENV_KEYS as C, type Logger as L, COLLECTOR_OPTIONAL_STRING_ENV_KEYS as a, COLLECTOR_STRING_ENV_MANIFEST as b, type ChildSpanRunner as c, type CollectorApp as d, type CollectorEnv as e, type CollectorHostManagedEnvKey as f, type CollectorManifestStringEnvKey as g, type CollectorObjectBindingKey as h, type CollectorOptionalStringEnvKey as i, type CollectorRouteContext as j, type CollectorStringEnvKey as k, assertCollectorEnvManifestCompleteness as l, consoleLogger as m, createIngestAuth as n, resetIngestAuthCache as r };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  LlmCallError,
3
3
  askEvidenceReferences
4
- } from "./chunk-ZSF5XP3B.js";
4
+ } from "./chunk-RASSTGNB.js";
5
5
 
6
6
  // src/lib/openai.ts
7
7
  import { EVIDENCE_REFERENCE_CONTRACT } from "@obsunified/types";
@@ -381,4 +381,4 @@ export {
381
381
  generateNarrativeOpenAI,
382
382
  runAskOpenAI
383
383
  };
384
- //# sourceMappingURL=openai-GSJZGFGL.js.map
384
+ //# sourceMappingURL=openai-VDKVVZAV.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obsunified/collector",
3
- "version": "2.2.3",
3
+ "version": "2.3.0",
4
4
  "description": "Plugin-based observability collector runtime with pluggable SQL/blob storage.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@bufbuild/protobuf": "^2.11.0",
40
40
  "@obsunified/pprof-decoder": "2.0.2",
41
- "@obsunified/types": "2.2.1"
41
+ "@obsunified/types": "2.3.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "hono": "^4.7.0",
@@ -66,6 +66,8 @@
66
66
  "build": "tsup",
67
67
  "type-check": "tsc --noEmit",
68
68
  "test": "vitest run --passWithNoTests",
69
+ "check:migrations": "vitest run src/migrations/parity.test.ts",
70
+ "check:db-parity": "node scripts/check-db-parity.mjs",
69
71
  "bench": "vitest bench --run",
70
72
  "codegen": "PATH=\"$PWD/node_modules/.bin:$PATH\" buf generate"
71
73
  }
@@ -2423,6 +2423,116 @@ describe("AutoSRE governance hardening", () => {
2423
2423
  db.close();
2424
2424
  });
2425
2425
 
2426
+ it("POST /internal/findings: schema-backed validation, trimming and defaults", async () => {
2427
+ const db = createMigratedSqliteDb();
2428
+ const { app, env } = createTestApp(db);
2429
+ const post = (body: unknown) =>
2430
+ app.request(
2431
+ "/internal/findings",
2432
+ {
2433
+ method: "POST",
2434
+ headers: { "Content-Type": "application/json" },
2435
+ body: JSON.stringify(body),
2436
+ },
2437
+ env,
2438
+ );
2439
+ const base = {
2440
+ title: "t",
2441
+ summary: "s",
2442
+ symptomEntityKind: "trace",
2443
+ symptomEntityId: "t1",
2444
+ faultLocusEntityKind: "service",
2445
+ faultLocusEntityId: SERVICE_NODE,
2446
+ };
2447
+ const required =
2448
+ "title, summary, symptomEntityKind, symptomEntityId, faultLocusEntityKind, and faultLocusEntityId are required";
2449
+
2450
+ // Combined required message: missing and empty-after-trim.
2451
+ for (const bad of [
2452
+ { ...base, title: undefined },
2453
+ { ...base, summary: " " },
2454
+ { ...base, faultLocusEntityId: 5 },
2455
+ ]) {
2456
+ const res = await post(bad);
2457
+ expect(res.status).toBe(400);
2458
+ expect(((await res.json()) as { error: string }).error).toBe(required);
2459
+ }
2460
+
2461
+ // causalChain explicit messages.
2462
+ const notArray = await post({ ...base, causalChain: "nope" });
2463
+ expect(notArray.status).toBe(400);
2464
+ expect(((await notArray.json()) as { error: string }).error).toBe(
2465
+ "causalChain must be an array",
2466
+ );
2467
+ const badPred = await post({
2468
+ ...base,
2469
+ causalChain: [
2470
+ {
2471
+ subjectKind: "trace",
2472
+ subjectId: "t1",
2473
+ predicate: "made_up",
2474
+ objectKind: "span",
2475
+ objectId: "s1",
2476
+ },
2477
+ ],
2478
+ });
2479
+ expect(badPred.status).toBe(400);
2480
+ expect(((await badPred.json()) as { error: string }).error).toBe(
2481
+ "causalChain[0].predicate is not a known evidence predicate: made_up",
2482
+ );
2483
+
2484
+ // Tightened: wrong-typed optional fields now 400 with path: message.
2485
+ const badConf = await post({ ...base, confidence: "high" });
2486
+ expect(badConf.status).toBe(400);
2487
+ expect(((await badConf.json()) as { error: string }).error).toContain(
2488
+ "confidence:",
2489
+ );
2490
+ const badTier = await post({ ...base, causalProofTier: "bogus" });
2491
+ expect(badTier.status).toBe(400);
2492
+ expect(((await badTier.json()) as { error: string }).error).toContain(
2493
+ "causalProofTier:",
2494
+ );
2495
+ const badKind = await post({ ...base, symptomEntityKind: "not_a_kind" });
2496
+ expect(badKind.status).toBe(400);
2497
+
2498
+ // Trimming + defaults.
2499
+ const ok = await post({
2500
+ title: " Padded title ",
2501
+ summary: " Padded summary ",
2502
+ symptomEntityKind: " trace ",
2503
+ symptomEntityId: " t1 ",
2504
+ faultLocusEntityKind: " service ",
2505
+ faultLocusEntityId: ` ${SERVICE_NODE} `,
2506
+ idempotencyKey: " ",
2507
+ incidentId: null,
2508
+ rootCauseEntityKind: null,
2509
+ cohortVerdict: null,
2510
+ });
2511
+ expect(ok.status).toBe(201);
2512
+ const created = (await ok.json()) as {
2513
+ finding: Record<string, unknown>;
2514
+ };
2515
+ expect(created.finding.title).toBe("Padded title");
2516
+ expect(created.finding.summary).toBe("Padded summary");
2517
+ expect(
2518
+ created.finding.symptom_entity_kind ?? created.finding.symptomEntityKind,
2519
+ ).toBe("trace");
2520
+ // Blank idempotencyKey is ignored: two identical posts create two findings.
2521
+ const again = await post({
2522
+ title: " Padded title ",
2523
+ summary: " Padded summary ",
2524
+ symptomEntityKind: "trace",
2525
+ symptomEntityId: "t1",
2526
+ faultLocusEntityKind: "service",
2527
+ faultLocusEntityId: SERVICE_NODE,
2528
+ idempotencyKey: " ",
2529
+ });
2530
+ expect(((await again.json()) as { id: string }).id).not.toBe(
2531
+ (created.finding as { id: string }).id,
2532
+ );
2533
+ db.close();
2534
+ });
2535
+
2426
2536
  it("J9: GET /internal/evals/runs/:id reports existence so counterfactual prerequisites can be checked first", async () => {
2427
2537
  const db = createMigratedSqliteDb();
2428
2538
  const { app, env } = createTestApp(db);