kubeagent 0.1.36 → 0.1.44
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/README.md +32 -0
- package/dist/auth.js +15 -0
- package/dist/check/index.js +77 -0
- package/dist/check/run.js +114 -0
- package/dist/cli.js +25 -2
- package/dist/detector/sources.js +1 -1
- package/dist/diagnoser/index.js +37 -11
- package/dist/monitor/index.js +45 -14
- package/dist/notify/discord.js +6 -9
- package/dist/notify/ssrf-guard.js +150 -0
- package/dist/notify/teams.js +6 -9
- package/dist/notify/webhook.js +7 -9
- package/dist/orchestrator.js +2 -1
- package/dist/telemetry.js +27 -1
- package/package.json +10 -1
- package/dist/auth.d.ts +0 -29
- package/dist/cli.d.ts +0 -2
- package/dist/config.d.ts +0 -75
- package/dist/debug.d.ts +0 -10
- package/dist/detector/cache.d.ts +0 -6
- package/dist/detector/cache.test.d.ts +0 -1
- package/dist/detector/cache.test.js +0 -54
- package/dist/detector/catalog.d.ts +0 -17
- package/dist/detector/catalog.test.d.ts +0 -1
- package/dist/detector/catalog.test.js +0 -33
- package/dist/detector/eol.d.ts +0 -13
- package/dist/detector/eol.test.d.ts +0 -1
- package/dist/detector/eol.test.js +0 -78
- package/dist/detector/image-parser.d.ts +0 -11
- package/dist/detector/image-parser.test.d.ts +0 -1
- package/dist/detector/image-parser.test.js +0 -87
- package/dist/detector/index.d.ts +0 -33
- package/dist/detector/index.test.d.ts +0 -1
- package/dist/detector/index.test.js +0 -210
- package/dist/detector/osv.d.ts +0 -12
- package/dist/detector/osv.test.d.ts +0 -1
- package/dist/detector/osv.test.js +0 -86
- package/dist/detector/report.d.ts +0 -6
- package/dist/detector/sources.d.ts +0 -42
- package/dist/diagnoser/index.d.ts +0 -17
- package/dist/diagnoser/tools.d.ts +0 -119
- package/dist/kb/loader.d.ts +0 -1
- package/dist/kb/writer.d.ts +0 -12
- package/dist/kubectl-config.d.ts +0 -7
- package/dist/kubectl.d.ts +0 -13
- package/dist/monitor/checks.d.ts +0 -71
- package/dist/monitor/index.d.ts +0 -17
- package/dist/monitor/resolve.test.d.ts +0 -1
- package/dist/monitor/resolve.test.js +0 -21
- package/dist/monitor/types.d.ts +0 -11
- package/dist/notify/discord.d.ts +0 -4
- package/dist/notify/index.d.ts +0 -6
- package/dist/notify/pagerduty.d.ts +0 -9
- package/dist/notify/pagerduty.test.d.ts +0 -1
- package/dist/notify/pagerduty.test.js +0 -97
- package/dist/notify/setup.d.ts +0 -9
- package/dist/notify/slack.d.ts +0 -4
- package/dist/notify/teams.d.ts +0 -3
- package/dist/notify/telegram.d.ts +0 -9
- package/dist/notify/webhook.d.ts +0 -3
- package/dist/notify/webhook.test.d.ts +0 -1
- package/dist/notify/webhook.test.js +0 -53
- package/dist/onboard/cluster-scan.d.ts +0 -42
- package/dist/onboard/code-scan.d.ts +0 -9
- package/dist/onboard/index.d.ts +0 -3
- package/dist/onboard/interview.d.ts +0 -12
- package/dist/onboard/project-matcher.d.ts +0 -25
- package/dist/orchestrator.d.ts +0 -3
- package/dist/proxy-client.d.ts +0 -27
- package/dist/render.d.ts +0 -5
- package/dist/telemetry.d.ts +0 -1
- package/dist/telemetry.test.d.ts +0 -1
- package/dist/telemetry.test.js +0 -18
- package/dist/update-notifier.d.ts +0 -1
- package/dist/update-notifier.test.d.ts +0 -1
- package/dist/update-notifier.test.js +0 -50
- package/dist/verifier.d.ts +0 -9
- package/dist/version-check.d.ts +0 -14
- package/dist/version-check.test.d.ts +0 -1
- package/dist/version-check.test.js +0 -179
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { mkdtempSync, rmSync, writeFileSync, mkdirSync, existsSync, readFileSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
// Mock chalk to return plain strings
|
|
6
|
-
vi.mock("chalk", () => {
|
|
7
|
-
const identity = (s) => s;
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
const handler = {
|
|
10
|
-
get: () => new Proxy(identity, handler),
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
-
apply: (_t, _this, args) => args[0],
|
|
13
|
-
};
|
|
14
|
-
return { default: new Proxy(identity, handler) };
|
|
15
|
-
});
|
|
16
|
-
let tmpHome;
|
|
17
|
-
let originalHome;
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
tmpHome = mkdtempSync(join(tmpdir(), "kubeagent-version-test-"));
|
|
20
|
-
originalHome = process.env.HOME;
|
|
21
|
-
process.env.HOME = tmpHome;
|
|
22
|
-
});
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
if (originalHome !== undefined)
|
|
25
|
-
process.env.HOME = originalHome;
|
|
26
|
-
else
|
|
27
|
-
delete process.env.HOME;
|
|
28
|
-
rmSync(tmpHome, { recursive: true, force: true });
|
|
29
|
-
vi.restoreAllMocks();
|
|
30
|
-
});
|
|
31
|
-
describe("isBelow", () => {
|
|
32
|
-
it("returns true when current is older", async () => {
|
|
33
|
-
const { isBelow } = await import("./version-check.js");
|
|
34
|
-
expect(isBelow("0.1.5", "0.2.0")).toBe(true);
|
|
35
|
-
expect(isBelow("0.1.5", "0.1.6")).toBe(true);
|
|
36
|
-
expect(isBelow("0.0.9", "1.0.0")).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
it("returns false when current is equal or newer", async () => {
|
|
39
|
-
const { isBelow } = await import("./version-check.js");
|
|
40
|
-
expect(isBelow("0.2.0", "0.2.0")).toBe(false);
|
|
41
|
-
expect(isBelow("0.2.1", "0.2.0")).toBe(false);
|
|
42
|
-
expect(isBelow("1.0.0", "0.9.99")).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
it("strips a leading v", async () => {
|
|
45
|
-
const { isBelow } = await import("./version-check.js");
|
|
46
|
-
expect(isBelow("v0.1.0", "0.2.0")).toBe(true);
|
|
47
|
-
expect(isBelow("0.1.0", "v0.2.0")).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe("enforceMinVersion", () => {
|
|
51
|
-
it("exits with code 1 when current version is below min", async () => {
|
|
52
|
-
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
53
|
-
ok: true,
|
|
54
|
-
json: () => Promise.resolve({ minSupported: "0.5.0" }),
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
-
});
|
|
57
|
-
const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
58
|
-
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((_code) => {
|
|
59
|
-
throw new Error("__exit__");
|
|
60
|
-
}));
|
|
61
|
-
const { enforceMinVersion } = await import("./version-check.js");
|
|
62
|
-
await expect(enforceMinVersion("0.1.0", "https://api.example.com")).rejects.toThrow("__exit__");
|
|
63
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
64
|
-
const output = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
|
|
65
|
-
expect(output).toContain("no longer supported");
|
|
66
|
-
expect(output).toContain("0.5.0");
|
|
67
|
-
});
|
|
68
|
-
it("does nothing when current version meets the floor", async () => {
|
|
69
|
-
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
70
|
-
ok: true,
|
|
71
|
-
json: () => Promise.resolve({ minSupported: "0.1.0" }),
|
|
72
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
});
|
|
74
|
-
const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
75
|
-
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => { }));
|
|
76
|
-
const { enforceMinVersion } = await import("./version-check.js");
|
|
77
|
-
await enforceMinVersion("0.1.0", "https://api.example.com");
|
|
78
|
-
expect(exitSpy).not.toHaveBeenCalled();
|
|
79
|
-
expect(errSpy).not.toHaveBeenCalled();
|
|
80
|
-
});
|
|
81
|
-
it("falls back to stale cache on network error", async () => {
|
|
82
|
-
// Seed an older cached floor for THIS server URL that already proved
|
|
83
|
-
// this version stale.
|
|
84
|
-
const url = "https://api.example.com";
|
|
85
|
-
mkdirSync(join(tmpHome, ".kubeagent"), { recursive: true });
|
|
86
|
-
writeFileSync(join(tmpHome, ".kubeagent", "version-check.json"), JSON.stringify({
|
|
87
|
-
[url]: {
|
|
88
|
-
// checkedAt > 24h ago so we attempt a refetch
|
|
89
|
-
checkedAt: Date.now() - 48 * 60 * 60 * 1000,
|
|
90
|
-
minSupported: "0.5.0",
|
|
91
|
-
},
|
|
92
|
-
}), "utf-8");
|
|
93
|
-
globalThis.fetch = vi.fn().mockRejectedValue(new Error("offline"));
|
|
94
|
-
const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
95
|
-
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((_code) => {
|
|
96
|
-
throw new Error("__exit__");
|
|
97
|
-
}));
|
|
98
|
-
const { enforceMinVersion } = await import("./version-check.js");
|
|
99
|
-
await expect(enforceMinVersion("0.1.0", url)).rejects.toThrow("__exit__");
|
|
100
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
101
|
-
expect(errSpy).toHaveBeenCalled();
|
|
102
|
-
});
|
|
103
|
-
it("returns silently with no cache and a network error", async () => {
|
|
104
|
-
globalThis.fetch = vi.fn().mockRejectedValue(new Error("offline"));
|
|
105
|
-
const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
|
|
106
|
-
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => { }));
|
|
107
|
-
const { enforceMinVersion } = await import("./version-check.js");
|
|
108
|
-
await enforceMinVersion("0.1.0", "https://api.example.com");
|
|
109
|
-
expect(exitSpy).not.toHaveBeenCalled();
|
|
110
|
-
expect(errSpy).not.toHaveBeenCalled();
|
|
111
|
-
});
|
|
112
|
-
it("uses cached value within 24h without refetching", async () => {
|
|
113
|
-
const url = "https://api.example.com";
|
|
114
|
-
mkdirSync(join(tmpHome, ".kubeagent"), { recursive: true });
|
|
115
|
-
writeFileSync(join(tmpHome, ".kubeagent", "version-check.json"), JSON.stringify({ [url]: { checkedAt: Date.now(), minSupported: "0.2.0" } }), "utf-8");
|
|
116
|
-
const fetchSpy = vi.fn();
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
-
globalThis.fetch = fetchSpy;
|
|
119
|
-
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((_code) => {
|
|
120
|
-
throw new Error("__exit__");
|
|
121
|
-
}));
|
|
122
|
-
vi.spyOn(console, "error").mockImplementation(() => { });
|
|
123
|
-
const { enforceMinVersion } = await import("./version-check.js");
|
|
124
|
-
await expect(enforceMinVersion("0.1.0", url)).rejects.toThrow("__exit__");
|
|
125
|
-
expect(fetchSpy).not.toHaveBeenCalled();
|
|
126
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
127
|
-
});
|
|
128
|
-
it("writes cache after a successful fetch", async () => {
|
|
129
|
-
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
130
|
-
ok: true,
|
|
131
|
-
json: () => Promise.resolve({ minSupported: "0.1.0" }),
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
133
|
-
});
|
|
134
|
-
vi.spyOn(process, "exit").mockImplementation((() => { }));
|
|
135
|
-
vi.spyOn(console, "error").mockImplementation(() => { });
|
|
136
|
-
const { enforceMinVersion } = await import("./version-check.js");
|
|
137
|
-
await enforceMinVersion("0.1.5", "https://api.example.com");
|
|
138
|
-
const cachePath = join(tmpHome, ".kubeagent", "version-check.json");
|
|
139
|
-
expect(existsSync(cachePath)).toBe(true);
|
|
140
|
-
const cache = JSON.parse(readFileSync(cachePath, "utf-8"));
|
|
141
|
-
expect(cache["https://api.example.com"].minSupported).toBe("0.1.0");
|
|
142
|
-
});
|
|
143
|
-
it("does not apply a floor cached for a different server URL", async () => {
|
|
144
|
-
const otherUrl = "https://other-server.example.com";
|
|
145
|
-
mkdirSync(join(tmpHome, ".kubeagent"), { recursive: true });
|
|
146
|
-
writeFileSync(join(tmpHome, ".kubeagent", "version-check.json"), JSON.stringify({
|
|
147
|
-
[otherUrl]: { checkedAt: Date.now(), minSupported: "99.0.0" },
|
|
148
|
-
}), "utf-8");
|
|
149
|
-
// Target server returns a permissive floor; other-server's strict floor
|
|
150
|
-
// must NOT be applied here.
|
|
151
|
-
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
152
|
-
ok: true,
|
|
153
|
-
json: () => Promise.resolve({ minSupported: "0.1.0" }),
|
|
154
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
155
|
-
});
|
|
156
|
-
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => { }));
|
|
157
|
-
vi.spyOn(console, "error").mockImplementation(() => { });
|
|
158
|
-
const { enforceMinVersion } = await import("./version-check.js");
|
|
159
|
-
await enforceMinVersion("0.1.0", "https://api.example.com");
|
|
160
|
-
expect(exitSpy).not.toHaveBeenCalled();
|
|
161
|
-
});
|
|
162
|
-
it("ignores the legacy single-entry cache shape", async () => {
|
|
163
|
-
// Old format: {checkedAt, minSupported} at the root. Should be discarded
|
|
164
|
-
// since we don't know which server it came from.
|
|
165
|
-
mkdirSync(join(tmpHome, ".kubeagent"), { recursive: true });
|
|
166
|
-
writeFileSync(join(tmpHome, ".kubeagent", "version-check.json"), JSON.stringify({ checkedAt: Date.now(), minSupported: "99.0.0" }), "utf-8");
|
|
167
|
-
globalThis.fetch = vi.fn().mockResolvedValue({
|
|
168
|
-
ok: true,
|
|
169
|
-
json: () => Promise.resolve({ minSupported: "0.1.0" }),
|
|
170
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
171
|
-
});
|
|
172
|
-
const exitSpy = vi.spyOn(process, "exit").mockImplementation((() => { }));
|
|
173
|
-
vi.spyOn(console, "error").mockImplementation(() => { });
|
|
174
|
-
const { enforceMinVersion } = await import("./version-check.js");
|
|
175
|
-
await enforceMinVersion("0.1.0", "https://api.example.com");
|
|
176
|
-
// Legacy floor (99.0.0) ignored, fresh fetch (0.1.0) applied — no exit.
|
|
177
|
-
expect(exitSpy).not.toHaveBeenCalled();
|
|
178
|
-
});
|
|
179
|
-
});
|