@synth-deploy/server 0.1.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.
- package/dist/agent/debrief-retention.d.ts +12 -0
- package/dist/agent/debrief-retention.d.ts.map +1 -0
- package/dist/agent/debrief-retention.js +27 -0
- package/dist/agent/debrief-retention.js.map +1 -0
- package/dist/agent/envoy-client.d.ts +216 -0
- package/dist/agent/envoy-client.d.ts.map +1 -0
- package/dist/agent/envoy-client.js +266 -0
- package/dist/agent/envoy-client.js.map +1 -0
- package/dist/agent/envoy-registry.d.ts +102 -0
- package/dist/agent/envoy-registry.d.ts.map +1 -0
- package/dist/agent/envoy-registry.js +319 -0
- package/dist/agent/envoy-registry.js.map +1 -0
- package/dist/agent/health-checker.d.ts +39 -0
- package/dist/agent/health-checker.d.ts.map +1 -0
- package/dist/agent/health-checker.js +49 -0
- package/dist/agent/health-checker.js.map +1 -0
- package/dist/agent/mcp-client-manager.d.ts +36 -0
- package/dist/agent/mcp-client-manager.d.ts.map +1 -0
- package/dist/agent/mcp-client-manager.js +106 -0
- package/dist/agent/mcp-client-manager.js.map +1 -0
- package/dist/agent/stale-deployment-detector.d.ts +15 -0
- package/dist/agent/stale-deployment-detector.d.ts.map +1 -0
- package/dist/agent/stale-deployment-detector.js +50 -0
- package/dist/agent/stale-deployment-detector.js.map +1 -0
- package/dist/agent/step-runner.d.ts +31 -0
- package/dist/agent/step-runner.d.ts.map +1 -0
- package/dist/agent/step-runner.js +80 -0
- package/dist/agent/step-runner.js.map +1 -0
- package/dist/agent/synth-agent.d.ts +168 -0
- package/dist/agent/synth-agent.d.ts.map +1 -0
- package/dist/agent/synth-agent.js +1195 -0
- package/dist/agent/synth-agent.js.map +1 -0
- package/dist/api/agent.d.ts +36 -0
- package/dist/api/agent.d.ts.map +1 -0
- package/dist/api/agent.js +867 -0
- package/dist/api/agent.js.map +1 -0
- package/dist/api/api-keys.d.ts +4 -0
- package/dist/api/api-keys.d.ts.map +1 -0
- package/dist/api/api-keys.js +118 -0
- package/dist/api/api-keys.js.map +1 -0
- package/dist/api/artifacts.d.ts +5 -0
- package/dist/api/artifacts.d.ts.map +1 -0
- package/dist/api/artifacts.js +142 -0
- package/dist/api/artifacts.js.map +1 -0
- package/dist/api/auth.d.ts +4 -0
- package/dist/api/auth.d.ts.map +1 -0
- package/dist/api/auth.js +280 -0
- package/dist/api/auth.js.map +1 -0
- package/dist/api/deployments.d.ts +11 -0
- package/dist/api/deployments.d.ts.map +1 -0
- package/dist/api/deployments.js +1098 -0
- package/dist/api/deployments.js.map +1 -0
- package/dist/api/environments.d.ts +5 -0
- package/dist/api/environments.d.ts.map +1 -0
- package/dist/api/environments.js +69 -0
- package/dist/api/environments.js.map +1 -0
- package/dist/api/envoy-reports.d.ts +17 -0
- package/dist/api/envoy-reports.d.ts.map +1 -0
- package/dist/api/envoy-reports.js +138 -0
- package/dist/api/envoy-reports.js.map +1 -0
- package/dist/api/envoys.d.ts +5 -0
- package/dist/api/envoys.d.ts.map +1 -0
- package/dist/api/envoys.js +192 -0
- package/dist/api/envoys.js.map +1 -0
- package/dist/api/fleet.d.ts +11 -0
- package/dist/api/fleet.d.ts.map +1 -0
- package/dist/api/fleet.js +394 -0
- package/dist/api/fleet.js.map +1 -0
- package/dist/api/graph.d.ts +8 -0
- package/dist/api/graph.d.ts.map +1 -0
- package/dist/api/graph.js +355 -0
- package/dist/api/graph.js.map +1 -0
- package/dist/api/health.d.ts +20 -0
- package/dist/api/health.d.ts.map +1 -0
- package/dist/api/health.js +248 -0
- package/dist/api/health.js.map +1 -0
- package/dist/api/idp-schemas.d.ts +41 -0
- package/dist/api/idp-schemas.d.ts.map +1 -0
- package/dist/api/idp-schemas.js +17 -0
- package/dist/api/idp-schemas.js.map +1 -0
- package/dist/api/idp.d.ts +6 -0
- package/dist/api/idp.d.ts.map +1 -0
- package/dist/api/idp.js +620 -0
- package/dist/api/idp.js.map +1 -0
- package/dist/api/intake.d.ts +10 -0
- package/dist/api/intake.d.ts.map +1 -0
- package/dist/api/intake.js +418 -0
- package/dist/api/intake.js.map +1 -0
- package/dist/api/partitions.d.ts +5 -0
- package/dist/api/partitions.d.ts.map +1 -0
- package/dist/api/partitions.js +113 -0
- package/dist/api/partitions.js.map +1 -0
- package/dist/api/progress-event-store.d.ts +62 -0
- package/dist/api/progress-event-store.d.ts.map +1 -0
- package/dist/api/progress-event-store.js +118 -0
- package/dist/api/progress-event-store.js.map +1 -0
- package/dist/api/schemas.d.ts +1000 -0
- package/dist/api/schemas.d.ts.map +1 -0
- package/dist/api/schemas.js +328 -0
- package/dist/api/schemas.js.map +1 -0
- package/dist/api/security-boundaries.d.ts +4 -0
- package/dist/api/security-boundaries.d.ts.map +1 -0
- package/dist/api/security-boundaries.js +32 -0
- package/dist/api/security-boundaries.js.map +1 -0
- package/dist/api/settings.d.ts +4 -0
- package/dist/api/settings.d.ts.map +1 -0
- package/dist/api/settings.js +99 -0
- package/dist/api/settings.js.map +1 -0
- package/dist/api/system.d.ts +75 -0
- package/dist/api/system.d.ts.map +1 -0
- package/dist/api/system.js +558 -0
- package/dist/api/system.js.map +1 -0
- package/dist/api/telemetry.d.ts +4 -0
- package/dist/api/telemetry.d.ts.map +1 -0
- package/dist/api/telemetry.js +24 -0
- package/dist/api/telemetry.js.map +1 -0
- package/dist/api/users.d.ts +4 -0
- package/dist/api/users.d.ts.map +1 -0
- package/dist/api/users.js +173 -0
- package/dist/api/users.js.map +1 -0
- package/dist/archive-unpacker.d.ts +24 -0
- package/dist/archive-unpacker.d.ts.map +1 -0
- package/dist/archive-unpacker.js +239 -0
- package/dist/archive-unpacker.js.map +1 -0
- package/dist/artifact-analyzer.d.ts +59 -0
- package/dist/artifact-analyzer.d.ts.map +1 -0
- package/dist/artifact-analyzer.js +334 -0
- package/dist/artifact-analyzer.js.map +1 -0
- package/dist/auth/idp/index.d.ts +9 -0
- package/dist/auth/idp/index.d.ts.map +1 -0
- package/dist/auth/idp/index.js +5 -0
- package/dist/auth/idp/index.js.map +1 -0
- package/dist/auth/idp/ldap.d.ts +56 -0
- package/dist/auth/idp/ldap.d.ts.map +1 -0
- package/dist/auth/idp/ldap.js +276 -0
- package/dist/auth/idp/ldap.js.map +1 -0
- package/dist/auth/idp/oidc.d.ts +27 -0
- package/dist/auth/idp/oidc.d.ts.map +1 -0
- package/dist/auth/idp/oidc.js +97 -0
- package/dist/auth/idp/oidc.js.map +1 -0
- package/dist/auth/idp/role-mapping.d.ts +9 -0
- package/dist/auth/idp/role-mapping.d.ts.map +1 -0
- package/dist/auth/idp/role-mapping.js +16 -0
- package/dist/auth/idp/role-mapping.js.map +1 -0
- package/dist/auth/idp/saml.d.ts +40 -0
- package/dist/auth/idp/saml.d.ts.map +1 -0
- package/dist/auth/idp/saml.js +117 -0
- package/dist/auth/idp/saml.js.map +1 -0
- package/dist/auth/idp/types.d.ts +23 -0
- package/dist/auth/idp/types.d.ts.map +1 -0
- package/dist/auth/idp/types.js +2 -0
- package/dist/auth/idp/types.js.map +1 -0
- package/dist/fleet/fleet-executor.d.ts +35 -0
- package/dist/fleet/fleet-executor.d.ts.map +1 -0
- package/dist/fleet/fleet-executor.js +228 -0
- package/dist/fleet/fleet-executor.js.map +1 -0
- package/dist/fleet/fleet-store.d.ts +13 -0
- package/dist/fleet/fleet-store.d.ts.map +1 -0
- package/dist/fleet/fleet-store.js +13 -0
- package/dist/fleet/fleet-store.js.map +1 -0
- package/dist/fleet/index.d.ts +5 -0
- package/dist/fleet/index.d.ts.map +1 -0
- package/dist/fleet/index.js +4 -0
- package/dist/fleet/index.js.map +1 -0
- package/dist/fleet/representative-selector.d.ts +15 -0
- package/dist/fleet/representative-selector.d.ts.map +1 -0
- package/dist/fleet/representative-selector.js +71 -0
- package/dist/fleet/representative-selector.js.map +1 -0
- package/dist/graph/graph-executor.d.ts +36 -0
- package/dist/graph/graph-executor.d.ts.map +1 -0
- package/dist/graph/graph-executor.js +348 -0
- package/dist/graph/graph-executor.js.map +1 -0
- package/dist/graph/graph-inference.d.ts +22 -0
- package/dist/graph/graph-inference.d.ts.map +1 -0
- package/dist/graph/graph-inference.js +149 -0
- package/dist/graph/graph-inference.js.map +1 -0
- package/dist/graph/graph-store.d.ts +12 -0
- package/dist/graph/graph-store.d.ts.map +1 -0
- package/dist/graph/graph-store.js +61 -0
- package/dist/graph/graph-store.js.map +1 -0
- package/dist/graph/index.d.ts +5 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +4 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +837 -0
- package/dist/index.js.map +1 -0
- package/dist/intake/index.d.ts +6 -0
- package/dist/intake/index.d.ts.map +1 -0
- package/dist/intake/index.js +5 -0
- package/dist/intake/index.js.map +1 -0
- package/dist/intake/intake-processor.d.ts +17 -0
- package/dist/intake/intake-processor.d.ts.map +1 -0
- package/dist/intake/intake-processor.js +99 -0
- package/dist/intake/intake-processor.js.map +1 -0
- package/dist/intake/intake-store.d.ts +7 -0
- package/dist/intake/intake-store.d.ts.map +1 -0
- package/dist/intake/intake-store.js +7 -0
- package/dist/intake/intake-store.js.map +1 -0
- package/dist/intake/registry-poller.d.ts +41 -0
- package/dist/intake/registry-poller.d.ts.map +1 -0
- package/dist/intake/registry-poller.js +202 -0
- package/dist/intake/registry-poller.js.map +1 -0
- package/dist/intake/webhook-handlers.d.ts +37 -0
- package/dist/intake/webhook-handlers.d.ts.map +1 -0
- package/dist/intake/webhook-handlers.js +268 -0
- package/dist/intake/webhook-handlers.js.map +1 -0
- package/dist/logger.d.ts +5 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +15 -0
- package/dist/logger.js.map +1 -0
- package/dist/mcp/resources.d.ts +9 -0
- package/dist/mcp/resources.d.ts.map +1 -0
- package/dist/mcp/resources.js +72 -0
- package/dist/mcp/resources.js.map +1 -0
- package/dist/mcp/server.d.ts +15 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +20 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +9 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +88 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/middleware/auth.d.ts +29 -0
- package/dist/middleware/auth.d.ts.map +1 -0
- package/dist/middleware/auth.js +76 -0
- package/dist/middleware/auth.js.map +1 -0
- package/dist/middleware/permissions.d.ts +13 -0
- package/dist/middleware/permissions.d.ts.map +1 -0
- package/dist/middleware/permissions.js +32 -0
- package/dist/middleware/permissions.js.map +1 -0
- package/dist/pattern-store.d.ts +104 -0
- package/dist/pattern-store.d.ts.map +1 -0
- package/dist/pattern-store.js +299 -0
- package/dist/pattern-store.js.map +1 -0
- package/package.json +54 -0
- package/src/agent/debrief-retention.ts +44 -0
- package/src/agent/envoy-client.ts +474 -0
- package/src/agent/envoy-registry.ts +384 -0
- package/src/agent/health-checker.ts +70 -0
- package/src/agent/mcp-client-manager.ts +131 -0
- package/src/agent/stale-deployment-detector.ts +79 -0
- package/src/agent/step-runner.ts +124 -0
- package/src/agent/synth-agent.ts +1567 -0
- package/src/api/agent.ts +1075 -0
- package/src/api/api-keys.ts +129 -0
- package/src/api/artifacts.ts +194 -0
- package/src/api/auth.ts +320 -0
- package/src/api/deployments.ts +1347 -0
- package/src/api/environments.ts +97 -0
- package/src/api/envoy-reports.ts +159 -0
- package/src/api/envoys.ts +237 -0
- package/src/api/fleet.ts +510 -0
- package/src/api/graph.ts +516 -0
- package/src/api/health.ts +311 -0
- package/src/api/idp-schemas.ts +19 -0
- package/src/api/idp.ts +735 -0
- package/src/api/intake.ts +537 -0
- package/src/api/partitions.ts +147 -0
- package/src/api/progress-event-store.ts +153 -0
- package/src/api/schemas.ts +376 -0
- package/src/api/security-boundaries.ts +54 -0
- package/src/api/settings.ts +118 -0
- package/src/api/system.ts +704 -0
- package/src/api/telemetry.ts +32 -0
- package/src/api/users.ts +210 -0
- package/src/archive-unpacker.ts +271 -0
- package/src/artifact-analyzer.ts +438 -0
- package/src/auth/idp/index.ts +8 -0
- package/src/auth/idp/ldap.ts +340 -0
- package/src/auth/idp/oidc.ts +117 -0
- package/src/auth/idp/role-mapping.ts +22 -0
- package/src/auth/idp/saml.ts +148 -0
- package/src/auth/idp/types.ts +22 -0
- package/src/fleet/fleet-executor.ts +309 -0
- package/src/fleet/fleet-store.ts +13 -0
- package/src/fleet/index.ts +4 -0
- package/src/fleet/representative-selector.ts +83 -0
- package/src/graph/graph-executor.ts +446 -0
- package/src/graph/graph-inference.ts +184 -0
- package/src/graph/graph-store.ts +75 -0
- package/src/graph/index.ts +4 -0
- package/src/index.ts +916 -0
- package/src/intake/index.ts +5 -0
- package/src/intake/intake-processor.ts +111 -0
- package/src/intake/intake-store.ts +7 -0
- package/src/intake/registry-poller.ts +230 -0
- package/src/intake/webhook-handlers.ts +328 -0
- package/src/logger.ts +19 -0
- package/src/mcp/resources.ts +98 -0
- package/src/mcp/server.ts +34 -0
- package/src/mcp/tools.ts +117 -0
- package/src/middleware/auth.ts +103 -0
- package/src/middleware/permissions.ts +35 -0
- package/src/pattern-store.ts +409 -0
- package/tests/agent-mode.test.ts +536 -0
- package/tests/api-handlers.test.ts +1245 -0
- package/tests/archive-unpacker.test.ts +179 -0
- package/tests/artifact-analyzer.test.ts +240 -0
- package/tests/auth-middleware.test.ts +189 -0
- package/tests/decision-diary.test.ts +957 -0
- package/tests/diary-reader.test.ts +782 -0
- package/tests/envoy-client.test.ts +342 -0
- package/tests/envoy-reports.test.ts +156 -0
- package/tests/mcp-tools.test.ts +213 -0
- package/tests/orchestration.test.ts +536 -0
- package/tests/partition-deletion.test.ts +143 -0
- package/tests/partition-isolation.test.ts +830 -0
- package/tests/pattern-store.test.ts +371 -0
- package/tests/rbac-enforcement.test.ts +409 -0
- package/tests/ssrf-validation.test.ts +56 -0
- package/tests/stale-deployment.test.ts +85 -0
- package/tests/step-runner.test.ts +308 -0
- package/tests/ui-journey.test.ts +330 -0
- package/tsconfig.json +11 -0
- package/vitest.config.ts +27 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
2
|
+
import { PatternStore, computeConfidence } from "../src/pattern-store.js";
|
|
3
|
+
import type { CorrectionRecord } from "../src/pattern-store.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Test helpers
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
function tmpDbPath(): string {
|
|
13
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "pattern-store-test-"));
|
|
14
|
+
return path.join(dir, "patterns.db");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const cleanup: (() => void)[] = [];
|
|
18
|
+
|
|
19
|
+
function createStore(): PatternStore {
|
|
20
|
+
const dbPath = tmpDbPath();
|
|
21
|
+
const store = new PatternStore(dbPath);
|
|
22
|
+
cleanup.push(() => {
|
|
23
|
+
store.close();
|
|
24
|
+
try { fs.unlinkSync(dbPath); } catch { /* ignore */ }
|
|
25
|
+
try { fs.rmdirSync(path.dirname(dbPath)); } catch { /* ignore */ }
|
|
26
|
+
});
|
|
27
|
+
return store;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
for (const fn of cleanup) fn();
|
|
32
|
+
cleanup.length = 0;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// computeConfidence tests
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
describe("computeConfidence", () => {
|
|
40
|
+
it("returns 0 for empty corrections", () => {
|
|
41
|
+
expect(computeConfidence([])).toBe(0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("returns 0.5 for a single correction", () => {
|
|
45
|
+
const corrections: CorrectionRecord[] = [
|
|
46
|
+
{ timestamp: new Date(), field: "summary", from: "old", to: "new", artifactId: "a1" },
|
|
47
|
+
];
|
|
48
|
+
expect(computeConfidence(corrections)).toBe(0.5);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("boosts confidence for consistent corrections on the same field", () => {
|
|
52
|
+
const corrections: CorrectionRecord[] = [
|
|
53
|
+
{ timestamp: new Date(), field: "summary", from: "old", to: "correct", artifactId: "a1" },
|
|
54
|
+
{ timestamp: new Date(), field: "summary", from: "old2", to: "correct", artifactId: "a2" },
|
|
55
|
+
];
|
|
56
|
+
expect(computeConfidence(corrections)).toBe(0.65);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("resets confidence on contradictory corrections", () => {
|
|
60
|
+
const corrections: CorrectionRecord[] = [
|
|
61
|
+
{ timestamp: new Date(), field: "summary", from: "old", to: "correct-v1", artifactId: "a1" },
|
|
62
|
+
{ timestamp: new Date(), field: "summary", from: "old", to: "correct-v1", artifactId: "a2" },
|
|
63
|
+
{ timestamp: new Date(), field: "summary", from: "correct-v1", to: "correct-v2", artifactId: "a3" },
|
|
64
|
+
];
|
|
65
|
+
// First: 0.5, second: 0.65, third: contradictory -> 0.5
|
|
66
|
+
expect(computeConfidence(corrections)).toBe(0.5);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("caps confidence at 0.95", () => {
|
|
70
|
+
// Many consistent corrections
|
|
71
|
+
const corrections: CorrectionRecord[] = Array.from({ length: 10 }, (_, i) => ({
|
|
72
|
+
timestamp: new Date(),
|
|
73
|
+
field: "summary",
|
|
74
|
+
from: "old",
|
|
75
|
+
to: "correct",
|
|
76
|
+
artifactId: `a${i}`,
|
|
77
|
+
}));
|
|
78
|
+
expect(computeConfidence(corrections)).toBe(0.95);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("tracks fields independently", () => {
|
|
82
|
+
const corrections: CorrectionRecord[] = [
|
|
83
|
+
{ timestamp: new Date(), field: "summary", from: "a", to: "b", artifactId: "a1" },
|
|
84
|
+
{ timestamp: new Date(), field: "deploymentIntent", from: "x", to: "y", artifactId: "a1" },
|
|
85
|
+
{ timestamp: new Date(), field: "summary", from: "a", to: "b", artifactId: "a2" },
|
|
86
|
+
];
|
|
87
|
+
// First (summary): 0.5
|
|
88
|
+
// Second (deploymentIntent, new field): 0.5 (no boost)
|
|
89
|
+
// Third (summary, consistent): 0.65
|
|
90
|
+
expect(computeConfidence(corrections)).toBe(0.65);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
// PatternStore CRUD tests
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
describe("PatternStore — CRUD", () => {
|
|
99
|
+
it("creates a pattern on first correction", () => {
|
|
100
|
+
const store = createStore();
|
|
101
|
+
const pattern = store.recordCorrection(
|
|
102
|
+
{ source: "docker-registry", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
103
|
+
{ field: "summary", from: "generic", to: "Production Node.js service", artifactId: "art-1" },
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
expect(pattern.id).toBeDefined();
|
|
107
|
+
expect(pattern.source).toBe("docker-registry");
|
|
108
|
+
expect(pattern.artifactType).toBe("dockerfile");
|
|
109
|
+
expect(pattern.namePattern).toBe("Dockerfile");
|
|
110
|
+
expect(pattern.corrections.length).toBe(1);
|
|
111
|
+
expect(pattern.confidence).toBe(0.5);
|
|
112
|
+
expect(pattern.appliedCount).toBe(0);
|
|
113
|
+
expect(pattern.derivedAnalysis.summary).toBe("Production Node.js service");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("appends to existing pattern on subsequent corrections", () => {
|
|
117
|
+
const store = createStore();
|
|
118
|
+
store.recordCorrection(
|
|
119
|
+
{ source: "s3", artifactType: "node-package", namePattern: "package.json" },
|
|
120
|
+
{ field: "summary", from: "a", to: "b", artifactId: "art-1" },
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const updated = store.recordCorrection(
|
|
124
|
+
{ source: "s3", artifactType: "node-package", namePattern: "package.json" },
|
|
125
|
+
{ field: "summary", from: "a", to: "b", artifactId: "art-2" },
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
expect(updated.corrections.length).toBe(2);
|
|
129
|
+
expect(updated.confidence).toBe(0.65);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("retrieves pattern by ID", () => {
|
|
133
|
+
const store = createStore();
|
|
134
|
+
const created = store.recordCorrection(
|
|
135
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "*" },
|
|
136
|
+
{ field: "deploymentIntent", from: "", to: "ECS Fargate", artifactId: "a1" },
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const fetched = store.getById(created.id);
|
|
140
|
+
expect(fetched).toBeDefined();
|
|
141
|
+
expect(fetched!.id).toBe(created.id);
|
|
142
|
+
expect(fetched!.derivedAnalysis.deploymentIntent).toBe("ECS Fargate");
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("lists all patterns", () => {
|
|
146
|
+
const store = createStore();
|
|
147
|
+
store.recordCorrection(
|
|
148
|
+
{ source: "s1", artifactType: "t1", namePattern: "p1" },
|
|
149
|
+
{ field: "summary", from: "", to: "x", artifactId: "a1" },
|
|
150
|
+
);
|
|
151
|
+
store.recordCorrection(
|
|
152
|
+
{ source: "s2", artifactType: "t2", namePattern: "p2" },
|
|
153
|
+
{ field: "summary", from: "", to: "y", artifactId: "a2" },
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const all = store.listAll();
|
|
157
|
+
expect(all.length).toBe(2);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("deletes a pattern", () => {
|
|
161
|
+
const store = createStore();
|
|
162
|
+
const pattern = store.recordCorrection(
|
|
163
|
+
{ source: "s1", artifactType: "t1", namePattern: "p1" },
|
|
164
|
+
{ field: "summary", from: "", to: "x", artifactId: "a1" },
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const deleted = store.delete(pattern.id);
|
|
168
|
+
expect(deleted).toBe(true);
|
|
169
|
+
expect(store.getById(pattern.id)).toBeUndefined();
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("returns false when deleting non-existent pattern", () => {
|
|
173
|
+
const store = createStore();
|
|
174
|
+
expect(store.delete("nonexistent")).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// ---------------------------------------------------------------------------
|
|
179
|
+
// PatternStore — matching tests
|
|
180
|
+
// ---------------------------------------------------------------------------
|
|
181
|
+
|
|
182
|
+
describe("PatternStore — matching", () => {
|
|
183
|
+
it("finds exact name matches", () => {
|
|
184
|
+
const store = createStore();
|
|
185
|
+
store.recordCorrection(
|
|
186
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
187
|
+
{ field: "summary", from: "", to: "x", artifactId: "a1" },
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const matches = store.findMatches("ecr", "dockerfile", "Dockerfile");
|
|
191
|
+
expect(matches.length).toBe(1);
|
|
192
|
+
expect(matches[0].mode).toBe("suggest"); // only 1 correction, < 0.7
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("finds glob pattern matches", () => {
|
|
196
|
+
const store = createStore();
|
|
197
|
+
store.recordCorrection(
|
|
198
|
+
{ source: "s3", artifactType: "tarball", namePattern: "release-*.tar.gz" },
|
|
199
|
+
{ field: "summary", from: "", to: "x", artifactId: "a1" },
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
const matches = store.findMatches("s3", "tarball", "release-v2.3.tar.gz");
|
|
203
|
+
expect(matches.length).toBe(1);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("does not match different source", () => {
|
|
207
|
+
const store = createStore();
|
|
208
|
+
store.recordCorrection(
|
|
209
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
210
|
+
{ field: "summary", from: "", to: "x", artifactId: "a1" },
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
const matches = store.findMatches("s3", "dockerfile", "Dockerfile");
|
|
214
|
+
expect(matches.length).toBe(0);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("does not match different artifact type", () => {
|
|
218
|
+
const store = createStore();
|
|
219
|
+
store.recordCorrection(
|
|
220
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
221
|
+
{ field: "summary", from: "", to: "x", artifactId: "a1" },
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const matches = store.findMatches("ecr", "node-package", "Dockerfile");
|
|
225
|
+
expect(matches.length).toBe(0);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("returns 'auto' mode when >= 2 corrections and confidence >= 0.7", () => {
|
|
229
|
+
const store = createStore();
|
|
230
|
+
// Build up to >= 2 corrections with consistent values
|
|
231
|
+
store.recordCorrection(
|
|
232
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
233
|
+
{ field: "summary", from: "", to: "corrected", artifactId: "a1" },
|
|
234
|
+
);
|
|
235
|
+
store.recordCorrection(
|
|
236
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
237
|
+
{ field: "summary", from: "", to: "corrected", artifactId: "a2" },
|
|
238
|
+
);
|
|
239
|
+
// confidence is now 0.65, not yet 0.7
|
|
240
|
+
store.recordCorrection(
|
|
241
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
242
|
+
{ field: "summary", from: "", to: "corrected", artifactId: "a3" },
|
|
243
|
+
);
|
|
244
|
+
// confidence is now 0.80
|
|
245
|
+
|
|
246
|
+
const matches = store.findMatches("ecr", "dockerfile", "Dockerfile");
|
|
247
|
+
expect(matches.length).toBe(1);
|
|
248
|
+
expect(matches[0].mode).toBe("auto");
|
|
249
|
+
expect(matches[0].pattern.confidence).toBe(0.8);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("returns 'suggest' mode when corrections < 2", () => {
|
|
253
|
+
const store = createStore();
|
|
254
|
+
store.recordCorrection(
|
|
255
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
256
|
+
{ field: "summary", from: "", to: "corrected", artifactId: "a1" },
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const matches = store.findMatches("ecr", "dockerfile", "Dockerfile");
|
|
260
|
+
expect(matches[0].mode).toBe("suggest");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("tracks application count", () => {
|
|
264
|
+
const store = createStore();
|
|
265
|
+
const pattern = store.recordCorrection(
|
|
266
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
267
|
+
{ field: "summary", from: "", to: "corrected", artifactId: "a1" },
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
expect(pattern.appliedCount).toBe(0);
|
|
271
|
+
store.recordApplication(pattern.id);
|
|
272
|
+
store.recordApplication(pattern.id);
|
|
273
|
+
|
|
274
|
+
const updated = store.getById(pattern.id);
|
|
275
|
+
expect(updated!.appliedCount).toBe(2);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// ---------------------------------------------------------------------------
|
|
280
|
+
// PatternStore — derived analysis
|
|
281
|
+
// ---------------------------------------------------------------------------
|
|
282
|
+
|
|
283
|
+
describe("PatternStore — derived analysis", () => {
|
|
284
|
+
it("derives summary from corrections", () => {
|
|
285
|
+
const store = createStore();
|
|
286
|
+
const pattern = store.recordCorrection(
|
|
287
|
+
{ source: "s", artifactType: "t", namePattern: "p" },
|
|
288
|
+
{ field: "summary", from: "old", to: "New summary", artifactId: "a1" },
|
|
289
|
+
);
|
|
290
|
+
expect(pattern.derivedAnalysis.summary).toBe("New summary");
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("derives deploymentIntent from corrections", () => {
|
|
294
|
+
const store = createStore();
|
|
295
|
+
const pattern = store.recordCorrection(
|
|
296
|
+
{ source: "s", artifactType: "t", namePattern: "p" },
|
|
297
|
+
{ field: "deploymentIntent", from: "", to: "Kubernetes CronJob", artifactId: "a1" },
|
|
298
|
+
);
|
|
299
|
+
expect(pattern.derivedAnalysis.deploymentIntent).toBe("Kubernetes CronJob");
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("derives dependencies from comma-separated corrections", () => {
|
|
303
|
+
const store = createStore();
|
|
304
|
+
const pattern = store.recordCorrection(
|
|
305
|
+
{ source: "s", artifactType: "t", namePattern: "p" },
|
|
306
|
+
{ field: "dependencies", from: "", to: "redis, postgresql, rabbitmq", artifactId: "a1" },
|
|
307
|
+
);
|
|
308
|
+
expect(pattern.derivedAnalysis.dependencies).toEqual(["redis", "postgresql", "rabbitmq"]);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("derives configuration expectations from config.* fields", () => {
|
|
312
|
+
const store = createStore();
|
|
313
|
+
store.recordCorrection(
|
|
314
|
+
{ source: "s", artifactType: "t", namePattern: "p" },
|
|
315
|
+
{ field: "config.DATABASE_URL", from: "", to: "PostgreSQL connection string", artifactId: "a1" },
|
|
316
|
+
);
|
|
317
|
+
const pattern = store.recordCorrection(
|
|
318
|
+
{ source: "s", artifactType: "t", namePattern: "p" },
|
|
319
|
+
{ field: "config.REDIS_URL", from: "", to: "Redis connection URL", artifactId: "a1" },
|
|
320
|
+
);
|
|
321
|
+
expect(pattern.derivedAnalysis.configurationExpectations).toEqual({
|
|
322
|
+
DATABASE_URL: "PostgreSQL connection string",
|
|
323
|
+
REDIS_URL: "Redis connection URL",
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("uses latest correction value when field is corrected multiple times", () => {
|
|
328
|
+
const store = createStore();
|
|
329
|
+
store.recordCorrection(
|
|
330
|
+
{ source: "s", artifactType: "t", namePattern: "p" },
|
|
331
|
+
{ field: "summary", from: "old", to: "first correction", artifactId: "a1" },
|
|
332
|
+
);
|
|
333
|
+
const pattern = store.recordCorrection(
|
|
334
|
+
{ source: "s", artifactType: "t", namePattern: "p" },
|
|
335
|
+
{ field: "summary", from: "first correction", to: "second correction", artifactId: "a2" },
|
|
336
|
+
);
|
|
337
|
+
// Note: this is a contradictory correction (different `to` value)
|
|
338
|
+
expect(pattern.derivedAnalysis.summary).toBe("second correction");
|
|
339
|
+
// Confidence should reset due to contradiction
|
|
340
|
+
expect(pattern.confidence).toBe(0.5);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
// ---------------------------------------------------------------------------
|
|
345
|
+
// PatternStore — persistence
|
|
346
|
+
// ---------------------------------------------------------------------------
|
|
347
|
+
|
|
348
|
+
describe("PatternStore — persistence", () => {
|
|
349
|
+
it("survives close and reopen", () => {
|
|
350
|
+
const dbPath = tmpDbPath();
|
|
351
|
+
cleanup.push(() => {
|
|
352
|
+
try { fs.unlinkSync(dbPath); } catch { /* ignore */ }
|
|
353
|
+
try { fs.rmdirSync(path.dirname(dbPath)); } catch { /* ignore */ }
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Write
|
|
357
|
+
const store1 = new PatternStore(dbPath);
|
|
358
|
+
store1.recordCorrection(
|
|
359
|
+
{ source: "ecr", artifactType: "dockerfile", namePattern: "Dockerfile" },
|
|
360
|
+
{ field: "summary", from: "", to: "Persisted summary", artifactId: "a1" },
|
|
361
|
+
);
|
|
362
|
+
store1.close();
|
|
363
|
+
|
|
364
|
+
// Reopen
|
|
365
|
+
const store2 = new PatternStore(dbPath);
|
|
366
|
+
const patterns = store2.listAll();
|
|
367
|
+
expect(patterns.length).toBe(1);
|
|
368
|
+
expect(patterns[0].derivedAnalysis.summary).toBe("Persisted summary");
|
|
369
|
+
store2.close();
|
|
370
|
+
});
|
|
371
|
+
});
|