@checkstack/dependency-backend 1.0.2 → 1.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/CHANGELOG.md +168 -0
- package/package.json +19 -16
- package/src/dependency-gitops-kinds.test.ts +356 -0
- package/src/dependency-gitops-kinds.ts +173 -0
- package/src/index.ts +15 -0
- package/src/router.ts +1 -1
- package/src/services/dependency-service.ts +3 -3
- package/tsconfig.json +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,173 @@
|
|
|
1
1
|
# @checkstack/dependency-backend
|
|
2
2
|
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f6f9a5c: Add a GitOps `System.dependencies` extension and lock the matching UI.
|
|
8
|
+
|
|
9
|
+
Each entry references an upstream system by ref and tunes the impact:
|
|
10
|
+
|
|
11
|
+
```yaml
|
|
12
|
+
apiVersion: checkstack.io/v1alpha1
|
|
13
|
+
kind: System
|
|
14
|
+
metadata: { name: payments-api }
|
|
15
|
+
spec:
|
|
16
|
+
dependencies:
|
|
17
|
+
- targetRef: { kind: System, name: payments-db }
|
|
18
|
+
impactType: critical
|
|
19
|
+
transitive: false
|
|
20
|
+
label: "primary store"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The reconciler diffs the YAML-declared edges against the persisted ones
|
|
24
|
+
where this system is the source and converges via
|
|
25
|
+
create / update / delete. GitOps is the source of truth, so any edges
|
|
26
|
+
no longer listed are removed. Refs that resolve to the source system
|
|
27
|
+
itself are rejected; refs that fail to resolve abort the diff before
|
|
28
|
+
any mutation.
|
|
29
|
+
|
|
30
|
+
UI gates:
|
|
31
|
+
|
|
32
|
+
- The `DependencyEditor` (system editor drawer) hides Add and disables
|
|
33
|
+
Edit/Delete on upstream rows when the source system is GitOps-managed.
|
|
34
|
+
Downstream rows are gated per-row by the _other_ system's lock.
|
|
35
|
+
- The `DependencyMap` blocks `onConnect` when the source is locked,
|
|
36
|
+
surfaces a "Managed by GitOps" notice in the edge editor panel, and
|
|
37
|
+
disables Save/Delete there.
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [42abfff]
|
|
42
|
+
- Updated dependencies [f6f9a5c]
|
|
43
|
+
- Updated dependencies [1ef2e79]
|
|
44
|
+
- @checkstack/common@0.9.0
|
|
45
|
+
- @checkstack/gitops-common@0.3.0
|
|
46
|
+
- @checkstack/gitops-backend@0.3.0
|
|
47
|
+
- @checkstack/incident-common@1.1.0
|
|
48
|
+
- @checkstack/maintenance-common@1.1.0
|
|
49
|
+
- @checkstack/catalog-common@2.1.0
|
|
50
|
+
- @checkstack/catalog-backend@1.1.0
|
|
51
|
+
- @checkstack/backend-api@0.15.1
|
|
52
|
+
- @checkstack/dependency-common@1.0.2
|
|
53
|
+
- @checkstack/healthcheck-backend@1.0.4
|
|
54
|
+
- @checkstack/healthcheck-common@1.0.2
|
|
55
|
+
- @checkstack/notification-common@1.0.2
|
|
56
|
+
- @checkstack/signal-common@0.2.2
|
|
57
|
+
|
|
58
|
+
## 1.0.3
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- 50e5f5f: Runtime plugin system: install + uninstall plugins from npm, GitHub releases
|
|
63
|
+
(including private GitHub Enterprise instances), or tarball uploads at
|
|
64
|
+
runtime, with multi-package bundles, dependency-derived compatibility checks,
|
|
65
|
+
multi-instance coordination via a Postgres artifact store, and
|
|
66
|
+
single-coordinator destructive cleanup.
|
|
67
|
+
|
|
68
|
+
Highlights:
|
|
69
|
+
|
|
70
|
+
- New `PluginSource` discriminated union and `PluginInstaller` /
|
|
71
|
+
`PluginInstallerRegistry` interfaces in `@checkstack/backend-api`. The
|
|
72
|
+
GitHub variant accepts an optional `apiBaseUrl` so deployments backed by
|
|
73
|
+
GitHub Enterprise can install from `https://ghe.example.com/api/v3`
|
|
74
|
+
instead of `api.github.com`.
|
|
75
|
+
- New `installPackageMetadataSchema` (Zod) in `@checkstack/common` validates
|
|
76
|
+
every plugin's `package.json` at install time. Required fields: `name`,
|
|
77
|
+
`version`, `description`, `author`, `license`, `checkstack.type`,
|
|
78
|
+
`checkstack.pluginId`. Optional: `checkstack.bundle`,
|
|
79
|
+
`checkstack.usageInstructions`, `checkstack.allowInstallScripts`.
|
|
80
|
+
- New `pluginManagerContract` in `@checkstack/pluginmanager-common` with
|
|
81
|
+
`list`, `previewInstall`, `install`, `previewUninstall`, `uninstall`, and
|
|
82
|
+
`events` procedures.
|
|
83
|
+
- New `@checkstack/pluginmanager-frontend` admin UI: installed-plugins list
|
|
84
|
+
with per-row uninstall (typed-confirmation modal, schema/configs/cascade
|
|
85
|
+
toggles), install page with NPM / Tarball Upload / GitHub Release tabs
|
|
86
|
+
(Catalog tab disabled — coming soon), and an events page surfacing the
|
|
87
|
+
install/uninstall audit log.
|
|
88
|
+
- New `bunx @checkstack/scripts plugin-pack` CLI for plugin authors —
|
|
89
|
+
per-package mode produces an npm-shaped tarball; `--bundle` mode produces
|
|
90
|
+
an outer tarball containing every sibling declared in
|
|
91
|
+
`package.json#checkstack.bundle`. Published to npm so external authors
|
|
92
|
+
can `bunx` it directly without a workspace checkout.
|
|
93
|
+
- Compatibility derived from `package.json#dependencies` ranges
|
|
94
|
+
(`semver.satisfies` against the platform's loaded `@checkstack/*`
|
|
95
|
+
versions) — no separate `compatibility` field.
|
|
96
|
+
- Multi-instance: originator persists artifacts + `plugins` rows + broadcasts
|
|
97
|
+
install/uninstall; receiving instances do in-process register/unregister
|
|
98
|
+
only. Destructive ops (drop schema, delete plugin_configs, delete
|
|
99
|
+
artifacts, delete `plugins` rows) run exactly once on the originator.
|
|
100
|
+
- Fresh-instance bootstrap: `loadPlugins()` hydrates any
|
|
101
|
+
`is_uninstallable=true` plugin missing from `node_modules` from the
|
|
102
|
+
artifact store before normal Phase 1 register.
|
|
103
|
+
- New schema: `plugin_artifacts` (tarball storage), `plugin_install_events`
|
|
104
|
+
(audit/error log). `plugins` extended with `version`, `metadata`,
|
|
105
|
+
`source`, `bundle_id`, `is_primary`. Local plugin sync now writes
|
|
106
|
+
`version` from each plugin's `package.json` so the admin UI shows real
|
|
107
|
+
versions instead of `—`.
|
|
108
|
+
- Tarball-upload endpoint (`POST /api/pluginmanager/upload-tarball`) for
|
|
109
|
+
the install UI; access-gated by `pluginmanager.plugin.manage`.
|
|
110
|
+
- Plugin Manager menu link added to the user menu (main grid, alongside
|
|
111
|
+
Profile / Notification Settings / etc.).
|
|
112
|
+
|
|
113
|
+
Cross-cutting changes:
|
|
114
|
+
|
|
115
|
+
- Backend request/response logging now flows through `rootLogger` (winston)
|
|
116
|
+
instead of `hono/logger`. 5xx responses include the response body inline
|
|
117
|
+
so swallowed early-return errors are visible in the log.
|
|
118
|
+
- The `/api/:pluginId/*` dispatcher now logs which core service is missing
|
|
119
|
+
or which `pluginId` had no metadata when it 500s.
|
|
120
|
+
- New `registerCorePluginMetadata` on `PluginManager` for core routers
|
|
121
|
+
(like the plugin manager itself) that need their metadata visible to the
|
|
122
|
+
RPC dispatcher without going through the full plugin lifecycle.
|
|
123
|
+
- ESLint: `unicorn/no-null` is now disabled globally. Drizzle distinguishes
|
|
124
|
+
between `null` (writes a real SQL NULL) and `undefined` (skip the column
|
|
125
|
+
on insert), so treating them as interchangeable produced latent bugs at
|
|
126
|
+
the persistence boundary. The bulk of the patch-bumped packages above
|
|
127
|
+
reflect lint-fix touches that landed when this rule was relaxed.
|
|
128
|
+
- Workspace-wide license normalization to `Elastic-2.0` (matches
|
|
129
|
+
`LICENSE.md`). Every `package.json` in the workspace now declares the
|
|
130
|
+
same SPDX identifier; the patch bumps capture this.
|
|
131
|
+
|
|
132
|
+
Plugin packages (every `plugins/*`): added a `pack` npm script
|
|
133
|
+
(`bunx @checkstack/scripts plugin-pack`), mirrored each plugin's
|
|
134
|
+
`pluginId` from `plugin-metadata.ts` into `package.json#checkstack.pluginId`
|
|
135
|
+
so install-time validation passes, stubbed any missing required metadata
|
|
136
|
+
fields (`description`, `author`, `license`), and added
|
|
137
|
+
`checkstack.bundle` to multi-package plugin primaries (telegram, rcon, ssh,
|
|
138
|
+
jira, queue-bullmq, queue-memory, cache-memory).
|
|
139
|
+
|
|
140
|
+
Breaking changes:
|
|
141
|
+
|
|
142
|
+
- The legacy single-method `PluginInstaller` interface (`install(packageName)`)
|
|
143
|
+
is removed. Callers must use `coreServices.pluginInstallerRegistry`.
|
|
144
|
+
- The old `pluginAdminContract` and `createPluginAdminRouter` are removed.
|
|
145
|
+
Replaced by `pluginManagerContract` in `@checkstack/pluginmanager-common`
|
|
146
|
+
and `createPluginManagerRouter` in `core/backend`.
|
|
147
|
+
- `@checkstack/test-utils-backend` no longer exports
|
|
148
|
+
`createMockPluginInstaller` / `MockPluginInstaller` (the legacy interface
|
|
149
|
+
it shimmed is gone).
|
|
150
|
+
|
|
151
|
+
Note: bumps are limited to `minor` (for packages with new public API
|
|
152
|
+
surface) and `patch` (for downstream consumers, license normalization,
|
|
153
|
+
and lint fixes). No `major` bumps despite the `PluginInstaller` removal —
|
|
154
|
+
the legacy interface had no third-party consumers in the wild before this
|
|
155
|
+
runtime plugin system landed, and the contract surface is the same shape
|
|
156
|
+
modulo the rename.
|
|
157
|
+
|
|
158
|
+
- Updated dependencies [50e5f5f]
|
|
159
|
+
- @checkstack/backend-api@0.15.0
|
|
160
|
+
- @checkstack/catalog-backend@1.0.2
|
|
161
|
+
- @checkstack/catalog-common@2.0.1
|
|
162
|
+
- @checkstack/common@0.8.0
|
|
163
|
+
- @checkstack/dependency-common@1.0.1
|
|
164
|
+
- @checkstack/healthcheck-backend@1.0.3
|
|
165
|
+
- @checkstack/maintenance-common@1.0.1
|
|
166
|
+
- @checkstack/healthcheck-common@1.0.1
|
|
167
|
+
- @checkstack/incident-common@1.0.1
|
|
168
|
+
- @checkstack/notification-common@1.0.1
|
|
169
|
+
- @checkstack/signal-common@0.2.1
|
|
170
|
+
|
|
3
171
|
## 1.0.2
|
|
4
172
|
|
|
5
173
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/dependency-backend",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"license": "Elastic-2.0",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "src/index.ts",
|
|
6
7
|
"checkstack": {
|
|
@@ -13,26 +14,28 @@
|
|
|
13
14
|
"lint:code": "eslint . --max-warnings 0"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
|
-
"@checkstack/backend-api": "0.
|
|
17
|
-
"@checkstack/dependency-common": "1.0.
|
|
18
|
-
"@checkstack/catalog-common": "2.0.
|
|
19
|
-
"@checkstack/catalog-backend": "1.0.
|
|
20
|
-
"@checkstack/healthcheck-common": "1.0.
|
|
21
|
-
"@checkstack/healthcheck-backend": "1.0.
|
|
22
|
-
"@checkstack/maintenance-common": "1.0.
|
|
23
|
-
"@checkstack/incident-common": "1.0.
|
|
24
|
-
"@checkstack/notification-common": "1.0.
|
|
25
|
-
"@checkstack/signal-common": "0.2.
|
|
26
|
-
"@checkstack/
|
|
17
|
+
"@checkstack/backend-api": "0.15.0",
|
|
18
|
+
"@checkstack/dependency-common": "1.0.1",
|
|
19
|
+
"@checkstack/catalog-common": "2.0.1",
|
|
20
|
+
"@checkstack/catalog-backend": "1.0.2",
|
|
21
|
+
"@checkstack/healthcheck-common": "1.0.1",
|
|
22
|
+
"@checkstack/healthcheck-backend": "1.0.3",
|
|
23
|
+
"@checkstack/maintenance-common": "1.0.1",
|
|
24
|
+
"@checkstack/incident-common": "1.0.1",
|
|
25
|
+
"@checkstack/notification-common": "1.0.1",
|
|
26
|
+
"@checkstack/signal-common": "0.2.1",
|
|
27
|
+
"@checkstack/gitops-backend": "0.2.8",
|
|
28
|
+
"@checkstack/gitops-common": "0.2.2",
|
|
29
|
+
"@checkstack/common": "0.8.0",
|
|
27
30
|
"drizzle-orm": "^0.45.0",
|
|
28
31
|
"zod": "^4.2.1",
|
|
29
32
|
"@orpc/server": "^1.13.2"
|
|
30
33
|
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"@checkstack/drizzle-helper": "0.0.
|
|
33
|
-
"@checkstack/scripts": "0.
|
|
34
|
-
"@checkstack/test-utils-backend": "0.1.
|
|
35
|
-
"@checkstack/tsconfig": "0.0.
|
|
35
|
+
"@checkstack/drizzle-helper": "0.0.5",
|
|
36
|
+
"@checkstack/scripts": "0.3.0",
|
|
37
|
+
"@checkstack/test-utils-backend": "0.1.24",
|
|
38
|
+
"@checkstack/tsconfig": "0.0.7",
|
|
36
39
|
"@types/bun": "^1.0.0",
|
|
37
40
|
"drizzle-kit": "^0.31.10",
|
|
38
41
|
"typescript": "^5.0.0"
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { describe, it, expect, mock, beforeEach } from "bun:test";
|
|
2
|
+
import type { ReconcileContext } from "@checkstack/gitops-common";
|
|
3
|
+
import type { Dependency } from "@checkstack/dependency-common";
|
|
4
|
+
import type { DependencyService } from "./services/dependency-service";
|
|
5
|
+
import { buildSystemDependenciesExtension } from "./dependency-gitops-kinds";
|
|
6
|
+
|
|
7
|
+
const noopLogger = {
|
|
8
|
+
debug: () => {},
|
|
9
|
+
info: () => {},
|
|
10
|
+
warn: () => {},
|
|
11
|
+
error: () => {},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const buildContext = (
|
|
15
|
+
overrides: Partial<ReconcileContext> = {},
|
|
16
|
+
): ReconcileContext =>
|
|
17
|
+
({
|
|
18
|
+
logger: noopLogger,
|
|
19
|
+
resolveEntityRef: async () => undefined,
|
|
20
|
+
resolveSecretsBySchema: async ({ value }) => ({
|
|
21
|
+
resolved: value,
|
|
22
|
+
warnings: [],
|
|
23
|
+
}),
|
|
24
|
+
...overrides,
|
|
25
|
+
}) as ReconcileContext;
|
|
26
|
+
|
|
27
|
+
const refResolver =
|
|
28
|
+
(table: Record<string, string>) =>
|
|
29
|
+
async ({ entityName }: { kind: string; entityName: string }) =>
|
|
30
|
+
table[entityName];
|
|
31
|
+
|
|
32
|
+
const dep = (
|
|
33
|
+
id: string,
|
|
34
|
+
sourceSystemId: string,
|
|
35
|
+
targetSystemId: string,
|
|
36
|
+
overrides: Partial<Dependency> = {},
|
|
37
|
+
): Dependency => ({
|
|
38
|
+
id,
|
|
39
|
+
sourceSystemId,
|
|
40
|
+
targetSystemId,
|
|
41
|
+
impactType: "degraded",
|
|
42
|
+
transitive: false,
|
|
43
|
+
label: null,
|
|
44
|
+
createdAt: new Date(),
|
|
45
|
+
updatedAt: new Date(),
|
|
46
|
+
...overrides,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const stubService = (existing: Dependency[] = []) => {
|
|
50
|
+
let store = [...existing];
|
|
51
|
+
const getDependencies = mock(
|
|
52
|
+
async ({
|
|
53
|
+
systemId,
|
|
54
|
+
direction,
|
|
55
|
+
}: {
|
|
56
|
+
systemId: string;
|
|
57
|
+
direction?: "upstream" | "downstream" | "both";
|
|
58
|
+
}) => {
|
|
59
|
+
if (direction === "upstream") {
|
|
60
|
+
return store.filter((d) => d.sourceSystemId === systemId);
|
|
61
|
+
}
|
|
62
|
+
if (direction === "downstream") {
|
|
63
|
+
return store.filter((d) => d.targetSystemId === systemId);
|
|
64
|
+
}
|
|
65
|
+
return store.filter(
|
|
66
|
+
(d) => d.sourceSystemId === systemId || d.targetSystemId === systemId,
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
const createDependency = mock(
|
|
71
|
+
async (input: {
|
|
72
|
+
sourceSystemId: string;
|
|
73
|
+
targetSystemId: string;
|
|
74
|
+
impactType: "informational" | "degraded" | "critical";
|
|
75
|
+
transitive?: boolean;
|
|
76
|
+
label?: string;
|
|
77
|
+
}) => {
|
|
78
|
+
const created = dep(
|
|
79
|
+
`dep-${store.length + 1}`,
|
|
80
|
+
input.sourceSystemId,
|
|
81
|
+
input.targetSystemId,
|
|
82
|
+
{
|
|
83
|
+
impactType: input.impactType,
|
|
84
|
+
transitive: input.transitive ?? false,
|
|
85
|
+
label: input.label ?? null,
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
store.push(created);
|
|
89
|
+
return created;
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
const updateDependency = mock(
|
|
93
|
+
async (input: {
|
|
94
|
+
id: string;
|
|
95
|
+
systemId: string;
|
|
96
|
+
impactType?: "informational" | "degraded" | "critical";
|
|
97
|
+
transitive?: boolean;
|
|
98
|
+
label?: string | null;
|
|
99
|
+
}) => {
|
|
100
|
+
store = store.map((d) =>
|
|
101
|
+
d.id === input.id
|
|
102
|
+
? {
|
|
103
|
+
...d,
|
|
104
|
+
impactType: input.impactType ?? d.impactType,
|
|
105
|
+
transitive: input.transitive ?? d.transitive,
|
|
106
|
+
label: input.label === undefined ? d.label : input.label,
|
|
107
|
+
}
|
|
108
|
+
: d,
|
|
109
|
+
);
|
|
110
|
+
return store.find((d) => d.id === input.id);
|
|
111
|
+
},
|
|
112
|
+
);
|
|
113
|
+
const deleteDependency = mock(async (id: string) => {
|
|
114
|
+
const before = store.length;
|
|
115
|
+
store = store.filter((d) => d.id !== id);
|
|
116
|
+
return store.length < before;
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
getDependencies,
|
|
120
|
+
createDependency,
|
|
121
|
+
updateDependency,
|
|
122
|
+
deleteDependency,
|
|
123
|
+
service: {
|
|
124
|
+
getDependencies,
|
|
125
|
+
createDependency,
|
|
126
|
+
updateDependency,
|
|
127
|
+
deleteDependency,
|
|
128
|
+
} as unknown as DependencyService,
|
|
129
|
+
get current() {
|
|
130
|
+
return store;
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
describe("buildSystemDependenciesExtension", () => {
|
|
136
|
+
let stub: ReturnType<typeof stubService>;
|
|
137
|
+
let extension: ReturnType<typeof buildSystemDependenciesExtension>;
|
|
138
|
+
|
|
139
|
+
beforeEach(() => {
|
|
140
|
+
stub = stubService();
|
|
141
|
+
extension = buildSystemDependenciesExtension({
|
|
142
|
+
getService: () => stub.service,
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("registers under System kind, namespace 'dependencies'", () => {
|
|
147
|
+
expect(extension.kind).toBe("System");
|
|
148
|
+
expect(extension.namespace).toBe("dependencies");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("creates declared dependencies on first sync", async () => {
|
|
152
|
+
await extension.reconcile({
|
|
153
|
+
entity: {} as never,
|
|
154
|
+
entityId: "sys-payments",
|
|
155
|
+
extensionSpec: [
|
|
156
|
+
{
|
|
157
|
+
targetRef: { kind: "System", name: "db" },
|
|
158
|
+
impactType: "critical",
|
|
159
|
+
transitive: false,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
targetRef: { kind: "System", name: "cache" },
|
|
163
|
+
impactType: "degraded",
|
|
164
|
+
transitive: true,
|
|
165
|
+
label: "fast path",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
context: buildContext({
|
|
169
|
+
resolveEntityRef: refResolver({ db: "sys-db", cache: "sys-cache" }),
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(stub.createDependency).toHaveBeenCalledTimes(2);
|
|
174
|
+
expect(stub.createDependency).toHaveBeenNthCalledWith(1, {
|
|
175
|
+
sourceSystemId: "sys-payments",
|
|
176
|
+
targetSystemId: "sys-db",
|
|
177
|
+
impactType: "critical",
|
|
178
|
+
transitive: false,
|
|
179
|
+
label: undefined,
|
|
180
|
+
healthCheckRules: [],
|
|
181
|
+
});
|
|
182
|
+
expect(stub.createDependency).toHaveBeenNthCalledWith(2, {
|
|
183
|
+
sourceSystemId: "sys-payments",
|
|
184
|
+
targetSystemId: "sys-cache",
|
|
185
|
+
impactType: "degraded",
|
|
186
|
+
transitive: true,
|
|
187
|
+
label: "fast path",
|
|
188
|
+
healthCheckRules: [],
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("removes dependencies that are no longer declared", async () => {
|
|
193
|
+
stub = stubService([
|
|
194
|
+
dep("d1", "sys-payments", "sys-db"),
|
|
195
|
+
dep("d2", "sys-payments", "sys-cache"),
|
|
196
|
+
]);
|
|
197
|
+
extension = buildSystemDependenciesExtension({
|
|
198
|
+
getService: () => stub.service,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
await extension.reconcile({
|
|
202
|
+
entity: {} as never,
|
|
203
|
+
entityId: "sys-payments",
|
|
204
|
+
extensionSpec: [
|
|
205
|
+
{
|
|
206
|
+
targetRef: { kind: "System", name: "db" },
|
|
207
|
+
impactType: "degraded",
|
|
208
|
+
transitive: false,
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
context: buildContext({
|
|
212
|
+
resolveEntityRef: refResolver({ db: "sys-db" }),
|
|
213
|
+
}),
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
expect(stub.deleteDependency).toHaveBeenCalledTimes(1);
|
|
217
|
+
expect(stub.deleteDependency).toHaveBeenCalledWith("d2");
|
|
218
|
+
expect(stub.createDependency).not.toHaveBeenCalled();
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("updates an existing edge when impactType, transitive, or label changes", async () => {
|
|
222
|
+
stub = stubService([
|
|
223
|
+
dep("d1", "sys-payments", "sys-db", {
|
|
224
|
+
impactType: "degraded",
|
|
225
|
+
transitive: false,
|
|
226
|
+
label: null,
|
|
227
|
+
}),
|
|
228
|
+
]);
|
|
229
|
+
extension = buildSystemDependenciesExtension({
|
|
230
|
+
getService: () => stub.service,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
await extension.reconcile({
|
|
234
|
+
entity: {} as never,
|
|
235
|
+
entityId: "sys-payments",
|
|
236
|
+
extensionSpec: [
|
|
237
|
+
{
|
|
238
|
+
targetRef: { kind: "System", name: "db" },
|
|
239
|
+
impactType: "critical",
|
|
240
|
+
transitive: true,
|
|
241
|
+
label: "primary",
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
context: buildContext({
|
|
245
|
+
resolveEntityRef: refResolver({ db: "sys-db" }),
|
|
246
|
+
}),
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
expect(stub.updateDependency).toHaveBeenCalledWith({
|
|
250
|
+
id: "d1",
|
|
251
|
+
systemId: "sys-payments",
|
|
252
|
+
impactType: "critical",
|
|
253
|
+
transitive: true,
|
|
254
|
+
label: "primary",
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("is a no-op when an edge already matches the spec", async () => {
|
|
259
|
+
stub = stubService([
|
|
260
|
+
dep("d1", "sys-payments", "sys-db", {
|
|
261
|
+
impactType: "critical",
|
|
262
|
+
transitive: false,
|
|
263
|
+
label: null,
|
|
264
|
+
}),
|
|
265
|
+
]);
|
|
266
|
+
extension = buildSystemDependenciesExtension({
|
|
267
|
+
getService: () => stub.service,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
await extension.reconcile({
|
|
271
|
+
entity: {} as never,
|
|
272
|
+
entityId: "sys-payments",
|
|
273
|
+
extensionSpec: [
|
|
274
|
+
{
|
|
275
|
+
targetRef: { kind: "System", name: "db" },
|
|
276
|
+
impactType: "critical",
|
|
277
|
+
transitive: false,
|
|
278
|
+
},
|
|
279
|
+
],
|
|
280
|
+
context: buildContext({
|
|
281
|
+
resolveEntityRef: refResolver({ db: "sys-db" }),
|
|
282
|
+
}),
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
expect(stub.updateDependency).not.toHaveBeenCalled();
|
|
286
|
+
expect(stub.createDependency).not.toHaveBeenCalled();
|
|
287
|
+
expect(stub.deleteDependency).not.toHaveBeenCalled();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("treats an empty/undefined spec as 'remove all my upstream deps'", async () => {
|
|
291
|
+
stub = stubService([
|
|
292
|
+
dep("d1", "sys-payments", "sys-db"),
|
|
293
|
+
dep("d2", "sys-other", "sys-payments"), // downstream — must NOT be touched
|
|
294
|
+
]);
|
|
295
|
+
extension = buildSystemDependenciesExtension({
|
|
296
|
+
getService: () => stub.service,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
await extension.reconcile({
|
|
300
|
+
entity: {} as never,
|
|
301
|
+
entityId: "sys-payments",
|
|
302
|
+
extensionSpec: [],
|
|
303
|
+
context: buildContext(),
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
expect(stub.deleteDependency).toHaveBeenCalledTimes(1);
|
|
307
|
+
expect(stub.deleteDependency).toHaveBeenCalledWith("d1");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("rejects refs that resolve to the source system itself", async () => {
|
|
311
|
+
await expect(
|
|
312
|
+
extension.reconcile({
|
|
313
|
+
entity: {} as never,
|
|
314
|
+
entityId: "sys-payments",
|
|
315
|
+
extensionSpec: [
|
|
316
|
+
{
|
|
317
|
+
targetRef: { kind: "System", name: "self" },
|
|
318
|
+
impactType: "degraded",
|
|
319
|
+
transitive: false,
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
context: buildContext({
|
|
323
|
+
resolveEntityRef: refResolver({ self: "sys-payments" }),
|
|
324
|
+
}),
|
|
325
|
+
}),
|
|
326
|
+
).rejects.toThrow(/cannot depend on itself/);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("aborts the diff when a ref cannot be resolved (no mutations)", async () => {
|
|
330
|
+
stub = stubService([dep("d1", "sys-payments", "sys-db")]);
|
|
331
|
+
extension = buildSystemDependenciesExtension({
|
|
332
|
+
getService: () => stub.service,
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
await expect(
|
|
336
|
+
extension.reconcile({
|
|
337
|
+
entity: {} as never,
|
|
338
|
+
entityId: "sys-payments",
|
|
339
|
+
extensionSpec: [
|
|
340
|
+
{
|
|
341
|
+
targetRef: { kind: "System", name: "missing" },
|
|
342
|
+
impactType: "degraded",
|
|
343
|
+
transitive: false,
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
context: buildContext({
|
|
347
|
+
resolveEntityRef: async () => undefined,
|
|
348
|
+
}),
|
|
349
|
+
}),
|
|
350
|
+
).rejects.toThrow(/Cannot resolve System ref "missing"/);
|
|
351
|
+
|
|
352
|
+
expect(stub.deleteDependency).not.toHaveBeenCalled();
|
|
353
|
+
expect(stub.createDependency).not.toHaveBeenCalled();
|
|
354
|
+
expect(stub.updateDependency).not.toHaveBeenCalled();
|
|
355
|
+
});
|
|
356
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
CHECKSTACK_API_VERSION,
|
|
4
|
+
type EntityKindExtensionDefinition,
|
|
5
|
+
type EntityKindRegistry,
|
|
6
|
+
type ReconcileContext,
|
|
7
|
+
} from "@checkstack/gitops-common";
|
|
8
|
+
import { ImpactTypeSchema } from "@checkstack/dependency-common";
|
|
9
|
+
import type { DependencyService } from "./services/dependency-service";
|
|
10
|
+
|
|
11
|
+
interface DependencyGitOpsKindsDeps {
|
|
12
|
+
/** Lazy accessor — populated during init(), invoked at reconcile time. */
|
|
13
|
+
getService: () => DependencyService;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// ─── System.dependencies extension ──────────────────────────────────────────
|
|
17
|
+
//
|
|
18
|
+
// Declares upstream dependencies for a System. GitOps is the source of truth:
|
|
19
|
+
// the reconciler diffs the YAML-declared edges against the persisted ones for
|
|
20
|
+
// this system and applies create/update/delete to converge.
|
|
21
|
+
//
|
|
22
|
+
// `targetRef` references another System by name; `kind` is constrained to the
|
|
23
|
+
// literal "System" so the relationship is self-documenting.
|
|
24
|
+
|
|
25
|
+
const systemRefSchema = z
|
|
26
|
+
.object({
|
|
27
|
+
kind: z.literal("System"),
|
|
28
|
+
name: z.string().min(1),
|
|
29
|
+
})
|
|
30
|
+
.describe("Reference to the upstream System this system depends on.");
|
|
31
|
+
|
|
32
|
+
const dependencyEntrySchema = z.object({
|
|
33
|
+
targetRef: systemRefSchema,
|
|
34
|
+
impactType: ImpactTypeSchema.optional().default("degraded"),
|
|
35
|
+
transitive: z.boolean().optional().default(false),
|
|
36
|
+
label: z.string().optional(),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const systemDependenciesExtensionSchema = z
|
|
40
|
+
.array(dependencyEntrySchema)
|
|
41
|
+
.optional();
|
|
42
|
+
|
|
43
|
+
type SystemDependenciesExtension = z.infer<
|
|
44
|
+
typeof systemDependenciesExtensionSchema
|
|
45
|
+
>;
|
|
46
|
+
|
|
47
|
+
const edgeKey = (sourceId: string, targetId: string) =>
|
|
48
|
+
`${sourceId}->${targetId}`;
|
|
49
|
+
|
|
50
|
+
export function buildSystemDependenciesExtension(
|
|
51
|
+
deps: DependencyGitOpsKindsDeps,
|
|
52
|
+
): EntityKindExtensionDefinition<SystemDependenciesExtension> {
|
|
53
|
+
return {
|
|
54
|
+
apiVersion: CHECKSTACK_API_VERSION,
|
|
55
|
+
kind: "System",
|
|
56
|
+
namespace: "dependencies",
|
|
57
|
+
specSchema: systemDependenciesExtensionSchema,
|
|
58
|
+
|
|
59
|
+
reconcile: async ({
|
|
60
|
+
extensionSpec,
|
|
61
|
+
entityId,
|
|
62
|
+
context,
|
|
63
|
+
}: {
|
|
64
|
+
extensionSpec: SystemDependenciesExtension;
|
|
65
|
+
entityId: string;
|
|
66
|
+
context: ReconcileContext;
|
|
67
|
+
}) => {
|
|
68
|
+
const service = deps.getService();
|
|
69
|
+
const sourceSystemId = entityId;
|
|
70
|
+
const desired = extensionSpec ?? [];
|
|
71
|
+
|
|
72
|
+
// Resolve all target refs up-front so a single bad ref aborts the diff
|
|
73
|
+
// before we mutate anything.
|
|
74
|
+
const resolved: Array<{
|
|
75
|
+
targetSystemId: string;
|
|
76
|
+
impactType: "informational" | "degraded" | "critical";
|
|
77
|
+
transitive: boolean;
|
|
78
|
+
label: string | null;
|
|
79
|
+
}> = [];
|
|
80
|
+
for (const entry of desired) {
|
|
81
|
+
const targetSystemId = await context.resolveEntityRef({
|
|
82
|
+
kind: entry.targetRef.kind,
|
|
83
|
+
entityName: entry.targetRef.name,
|
|
84
|
+
});
|
|
85
|
+
if (!targetSystemId) {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Cannot resolve System ref "${entry.targetRef.name}" — ensure the upstream system exists`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (targetSystemId === sourceSystemId) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`Dependency target "${entry.targetRef.name}" resolves to the same system as the source — a system cannot depend on itself`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
resolved.push({
|
|
96
|
+
targetSystemId,
|
|
97
|
+
impactType: entry.impactType,
|
|
98
|
+
transitive: entry.transitive,
|
|
99
|
+
label: entry.label ?? null,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Existing edges where this system is the source (upstream deps).
|
|
104
|
+
const existing = await service.getDependencies({
|
|
105
|
+
systemId: sourceSystemId,
|
|
106
|
+
direction: "upstream",
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const existingByTarget = new Map(
|
|
110
|
+
existing.map((dep) => [edgeKey(dep.sourceSystemId, dep.targetSystemId), dep]),
|
|
111
|
+
);
|
|
112
|
+
const desiredKeys = new Set(
|
|
113
|
+
resolved.map((r) => edgeKey(sourceSystemId, r.targetSystemId)),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Remove edges that are no longer declared.
|
|
117
|
+
for (const [key, dep] of existingByTarget) {
|
|
118
|
+
if (!desiredKeys.has(key)) {
|
|
119
|
+
await service.deleteDependency(dep.id);
|
|
120
|
+
context.logger.info(
|
|
121
|
+
`GitOps: removed dependency ${dep.sourceSystemId} → ${dep.targetSystemId}`,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Add or update declared edges.
|
|
127
|
+
for (const entry of resolved) {
|
|
128
|
+
const key = edgeKey(sourceSystemId, entry.targetSystemId);
|
|
129
|
+
const current = existingByTarget.get(key);
|
|
130
|
+
if (!current) {
|
|
131
|
+
await service.createDependency({
|
|
132
|
+
sourceSystemId,
|
|
133
|
+
targetSystemId: entry.targetSystemId,
|
|
134
|
+
impactType: entry.impactType,
|
|
135
|
+
transitive: entry.transitive,
|
|
136
|
+
label: entry.label ?? undefined,
|
|
137
|
+
healthCheckRules: [],
|
|
138
|
+
});
|
|
139
|
+
context.logger.info(
|
|
140
|
+
`GitOps: created dependency ${sourceSystemId} → ${entry.targetSystemId} (${entry.impactType})`,
|
|
141
|
+
);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const needsUpdate =
|
|
146
|
+
current.impactType !== entry.impactType ||
|
|
147
|
+
current.transitive !== entry.transitive ||
|
|
148
|
+
(current.label ?? null) !== entry.label;
|
|
149
|
+
if (needsUpdate) {
|
|
150
|
+
await service.updateDependency({
|
|
151
|
+
id: current.id,
|
|
152
|
+
systemId: sourceSystemId,
|
|
153
|
+
impactType: entry.impactType,
|
|
154
|
+
transitive: entry.transitive,
|
|
155
|
+
label: entry.label,
|
|
156
|
+
});
|
|
157
|
+
context.logger.info(
|
|
158
|
+
`GitOps: updated dependency ${sourceSystemId} → ${entry.targetSystemId}`,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function registerDependencyGitOpsKinds({
|
|
167
|
+
kindRegistry,
|
|
168
|
+
...deps
|
|
169
|
+
}: DependencyGitOpsKindsDeps & {
|
|
170
|
+
kindRegistry: EntityKindRegistry;
|
|
171
|
+
}): void {
|
|
172
|
+
kindRegistry.registerKindExtension(buildSystemDependenciesExtension(deps));
|
|
173
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,8 @@ import { NotificationApi } from "@checkstack/notification-common";
|
|
|
20
20
|
import { catalogHooks } from "@checkstack/catalog-backend";
|
|
21
21
|
import { healthCheckHooks } from "@checkstack/healthcheck-backend";
|
|
22
22
|
import { evaluateAndNotifyDownstream } from "./notifications";
|
|
23
|
+
import { entityKindExtensionPoint } from "@checkstack/gitops-backend";
|
|
24
|
+
import { registerDependencyGitOpsKinds } from "./dependency-gitops-kinds";
|
|
23
25
|
|
|
24
26
|
// =============================================================================
|
|
25
27
|
// Plugin Definition
|
|
@@ -34,6 +36,18 @@ export default createBackendPlugin({
|
|
|
34
36
|
dependencyGroupSubscription,
|
|
35
37
|
]);
|
|
36
38
|
|
|
39
|
+
// ─── GitOps Entity Kind Registration ─────────────────────────────
|
|
40
|
+
let gitopsService: DependencyService | undefined;
|
|
41
|
+
const kindRegistry = env.getExtensionPoint(entityKindExtensionPoint);
|
|
42
|
+
registerDependencyGitOpsKinds({
|
|
43
|
+
kindRegistry,
|
|
44
|
+
getService: () => {
|
|
45
|
+
if (!gitopsService)
|
|
46
|
+
throw new Error("DependencyService not initialized");
|
|
47
|
+
return gitopsService;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
37
51
|
env.registerInit({
|
|
38
52
|
schema,
|
|
39
53
|
deps: {
|
|
@@ -51,6 +65,7 @@ export default createBackendPlugin({
|
|
|
51
65
|
const service = new DependencyService(
|
|
52
66
|
database as SafeDatabase<typeof schema>,
|
|
53
67
|
);
|
|
68
|
+
gitopsService = service;
|
|
54
69
|
const warningService = new WarningEvaluationService();
|
|
55
70
|
|
|
56
71
|
const router = createRouter({
|
package/src/router.ts
CHANGED
|
@@ -97,7 +97,7 @@ export class DependencyService {
|
|
|
97
97
|
targetSystemId: input.targetSystemId,
|
|
98
98
|
impactType: input.impactType,
|
|
99
99
|
transitive: input.transitive ?? false,
|
|
100
|
-
|
|
100
|
+
|
|
101
101
|
label: input.label ?? null,
|
|
102
102
|
});
|
|
103
103
|
|
|
@@ -213,7 +213,7 @@ export class DependencyService {
|
|
|
213
213
|
|
|
214
214
|
return {
|
|
215
215
|
...row,
|
|
216
|
-
|
|
216
|
+
|
|
217
217
|
label: row.label ?? null,
|
|
218
218
|
healthCheckRules: rules.length > 0 ? rules : undefined,
|
|
219
219
|
};
|
|
@@ -367,7 +367,7 @@ export class DependencyService {
|
|
|
367
367
|
const rules = rulesByDep.get(row.id);
|
|
368
368
|
return {
|
|
369
369
|
...row,
|
|
370
|
-
|
|
370
|
+
|
|
371
371
|
label: row.label ?? null,
|
|
372
372
|
healthCheckRules: rules && rules.length > 0 ? rules : undefined,
|
|
373
373
|
};
|