feat: add provider profile removal
This commit is contained in:
@@ -12,7 +12,7 @@ const secretText = "sk-selftest-provider-profile-secret";
|
||||
const selfTest: SelfTestCase = async (context) => {
|
||||
const gitopsRenderer = await readFile(path.join(context.root, "scripts/src/gitops-render.ts"), "utf8");
|
||||
assert.equal(gitopsRenderer.includes("agentrun-v01-mgr-provider-secret-manager"), true);
|
||||
assert.equal(gitopsRenderer.includes('verbs: ["create", "get", "list", "patch", "update"]'), true);
|
||||
assert.equal(gitopsRenderer.includes('verbs: ["create", "delete", "get", "list", "patch", "update"]'), true);
|
||||
assert.equal(gitopsRenderer.includes('resourceNames: ["agentrun-v01-provider-codex", "agentrun-v01-provider-deepseek", "agentrun-v01-provider-minimax-m3", "agentrun-v01-provider-dsflash-go"]'), false);
|
||||
assert.equal(gitopsRenderer.includes('resources: ["secrets"]'), true);
|
||||
|
||||
@@ -23,9 +23,11 @@ const selfTest: SelfTestCase = async (context) => {
|
||||
const createdJobPath = path.join(context.tmp, "provider-validation-job.json");
|
||||
const secretStateDir = path.join(context.tmp, "provider-secret-state");
|
||||
await writeFile(fakeKubectl, `#!/usr/bin/env bun
|
||||
import { rmSync } from "node:fs";
|
||||
const args = Bun.argv.slice(2);
|
||||
const secretStateDir = ${JSON.stringify(secretStateDir)};
|
||||
const secretStatePath = (name) => secretStateDir + "/" + name + ".json";
|
||||
const deletedMarkerPath = (name) => secretStateDir + "/" + name + ".deleted";
|
||||
const fixtureSecret = (name) => ({ apiVersion: "v1", kind: "Secret", metadata: { name, namespace: "agentrun-v01", resourceVersion: "rv-selftest", creationTimestamp: "2026-06-05T00:00:00.000Z" }, data: { "auth.json": Buffer.from(JSON.stringify({ token: "redacted-fixture" })).toString("base64"), "config.toml": Buffer.from("model = \\\"fixture\\\"\\n").toString("base64") } });
|
||||
const readStdin = async () => {
|
||||
const chunks = [];
|
||||
@@ -34,7 +36,12 @@ const readStdin = async () => {
|
||||
};
|
||||
if (args[0] === "get" && args[1] === "secret") {
|
||||
const name = args[2];
|
||||
const deletedMarker = Bun.file(deletedMarkerPath(name));
|
||||
const stateFile = Bun.file(secretStatePath(name));
|
||||
if (await deletedMarker.exists()) {
|
||||
console.error('Error from server (NotFound): secrets "' + name + '" not found');
|
||||
process.exit(1);
|
||||
}
|
||||
if (await stateFile.exists()) {
|
||||
console.log(await stateFile.text());
|
||||
process.exit(0);
|
||||
@@ -49,11 +56,14 @@ if (args[0] === "get" && args[1] === "secret") {
|
||||
process.exit(0);
|
||||
}
|
||||
if (args[0] === "get" && args[1] === "secrets") {
|
||||
const items = [fixtureSecret("agentrun-v01-provider-codex"), fixtureSecret("agentrun-v01-provider-deepseek"), fixtureSecret("agentrun-v01-provider-minimax-m3")];
|
||||
const items = [];
|
||||
if (!(await Bun.file(deletedMarkerPath("agentrun-v01-provider-codex")).exists())) items.push(fixtureSecret("agentrun-v01-provider-codex"));
|
||||
if (!(await Bun.file(deletedMarkerPath("agentrun-v01-provider-deepseek")).exists())) items.push(fixtureSecret("agentrun-v01-provider-deepseek"));
|
||||
if (!(await Bun.file(deletedMarkerPath("agentrun-v01-provider-minimax-m3")).exists())) items.push(fixtureSecret("agentrun-v01-provider-minimax-m3"));
|
||||
const dsflashState = Bun.file(secretStatePath("agentrun-v01-provider-dsflash-go"));
|
||||
if (await dsflashState.exists()) items.push(JSON.parse(await dsflashState.text()));
|
||||
if (!(await Bun.file(deletedMarkerPath("agentrun-v01-provider-dsflash-go")).exists()) && await dsflashState.exists()) items.push(JSON.parse(await dsflashState.text()));
|
||||
const dynamicState = Bun.file(secretStatePath("agentrun-v01-provider-dsflash-go-cli-selftest"));
|
||||
if (await dynamicState.exists()) items.push(JSON.parse(await dynamicState.text()));
|
||||
if (!(await Bun.file(deletedMarkerPath("agentrun-v01-provider-dsflash-go-cli-selftest")).exists()) && await dynamicState.exists()) items.push(JSON.parse(await dynamicState.text()));
|
||||
console.log(JSON.stringify({ apiVersion: "v1", kind: "SecretList", items }));
|
||||
process.exit(0);
|
||||
}
|
||||
@@ -79,6 +89,7 @@ if (args[0] === "patch" && args[1] === "secret") {
|
||||
if (args[0] === "replace") {
|
||||
const text = await readStdin();
|
||||
const manifest = JSON.parse(text);
|
||||
try { rmSync(deletedMarkerPath(manifest.metadata.name)); } catch {}
|
||||
const stateFile = Bun.file(secretStatePath(manifest.metadata.name));
|
||||
if (!(await stateFile.exists())) {
|
||||
console.error('Error from server (NotFound): secrets "' + manifest.metadata.name + '" not found');
|
||||
@@ -94,6 +105,7 @@ if (args[0] === "create") {
|
||||
const text = await readStdin();
|
||||
const manifest = JSON.parse(text);
|
||||
if (manifest.kind === "Secret") {
|
||||
try { rmSync(deletedMarkerPath(manifest.metadata.name)); } catch {}
|
||||
const annotations = manifest.metadata?.annotations ?? {};
|
||||
await Bun.write(${JSON.stringify(createdSecretPath)}, JSON.stringify({ args, manifest }, null, 2));
|
||||
await Bun.write(secretStatePath(manifest.metadata.name), JSON.stringify({ ...manifest, metadata: { ...(manifest.metadata ?? {}), resourceVersion: "rv-created", annotations } }));
|
||||
@@ -104,6 +116,13 @@ if (args[0] === "create") {
|
||||
console.log(JSON.stringify({ apiVersion: manifest.apiVersion, kind: manifest.kind, metadata: { uid: "job-provider-validation", resourceVersion: "rv-job", name: manifest.metadata.name, namespace: manifest.metadata.namespace } }));
|
||||
process.exit(0);
|
||||
}
|
||||
if (args[0] === "delete" && args[1] === "secret") {
|
||||
const name = args[2];
|
||||
try { rmSync(secretStatePath(name)); } catch {}
|
||||
await Bun.write(deletedMarkerPath(name), "deleted\n");
|
||||
console.log(JSON.stringify({ kind: "Status", status: "Success", details: { name } }));
|
||||
process.exit(0);
|
||||
}
|
||||
console.error("unsupported fake kubectl args: " + JSON.stringify(args));
|
||||
process.exit(1);
|
||||
`);
|
||||
@@ -256,6 +275,30 @@ process.exit(1);
|
||||
assert.equal(dynamicListItems.some((item) => item.profile === dynamicProfile), true);
|
||||
assertNoSecretLeak(dynamicCredential);
|
||||
|
||||
const removedDeepseek = await client.delete("/api/v1/provider-profiles/deepseek") as JsonRecord;
|
||||
assert.equal(removedDeepseek.profile, "deepseek");
|
||||
assert.equal(removedDeepseek.removed, true);
|
||||
assert.equal(removedDeepseek.builtinCapabilityRetained, true);
|
||||
assertNoSecretLeak(removedDeepseek);
|
||||
const deepseekShownAfterRemove = await client.get("/api/v1/provider-profiles/deepseek") as JsonRecord;
|
||||
assert.equal(deepseekShownAfterRemove.configured, false);
|
||||
assert.equal(deepseekShownAfterRemove.failureKind, "secret-unavailable");
|
||||
const listAfterBuiltinRemove = await client.get("/api/v1/provider-profiles") as JsonRecord;
|
||||
assert.equal(listAfterBuiltinRemove.count, 5);
|
||||
const deepseekAfterRemove = ((listAfterBuiltinRemove.items as JsonRecord[]) ?? []).find((item) => item.profile === "deepseek") as JsonRecord | undefined;
|
||||
assert.equal(deepseekAfterRemove?.configured, false);
|
||||
assert.equal(deepseekAfterRemove?.failureKind, "secret-unavailable");
|
||||
|
||||
const removedDynamic = await client.delete(`/api/v1/provider-profiles/${encodeURIComponent(dynamicProfile)}`) as JsonRecord;
|
||||
assert.equal(removedDynamic.profile, dynamicProfile);
|
||||
assert.equal(removedDynamic.removed, true);
|
||||
assert.equal(removedDynamic.builtinCapabilityRetained, undefined);
|
||||
assertNoSecretLeak(removedDynamic);
|
||||
const listAfterDynamicRemove = await client.get("/api/v1/provider-profiles") as JsonRecord;
|
||||
assert.equal(listAfterDynamicRemove.count, 4);
|
||||
const itemsAfterDynamicRemove = (listAfterDynamicRemove.items as JsonRecord[]) ?? [];
|
||||
assert.equal(itemsAfterDynamicRemove.some((item) => item.profile === dynamicProfile), false);
|
||||
|
||||
await assert.rejects(
|
||||
() => client.put("/api/v1/provider-profiles/deepseek/credential", { apiKey: secretText, config: { baseUrl: "https://hyueapi.com/v1" } }),
|
||||
(error) => error instanceof Error && error.message.includes("not hyueapi.com"),
|
||||
@@ -279,7 +322,7 @@ process.exit(1);
|
||||
assert.equal(finalValidation.status, "completed");
|
||||
assert.equal(JSON.stringify(finalValidation).includes(secretText), false);
|
||||
assertNoSecretLeak(finalValidation);
|
||||
return { name: "provider-profile-management", tests: ["provider-profiles-list-redacted", "provider-profile-config", "provider-profile-set-key-redacted", "provider-profile-secret-replace-annotation-cleanup", "provider-profile-secret-create-upsert", "provider-profile-config-only-create", "provider-profile-dynamic-slug-roundtrip", "provider-profile-deepseek-moon-bridge", "provider-profile-manager-secret-rbac", "provider-profile-validation-runner-job"] };
|
||||
return { name: "provider-profile-management", tests: ["provider-profiles-list-redacted", "provider-profile-config", "provider-profile-set-key-redacted", "provider-profile-secret-replace-annotation-cleanup", "provider-profile-secret-create-upsert", "provider-profile-config-only-create", "provider-profile-dynamic-slug-roundtrip", "provider-profile-remove-builtin", "provider-profile-remove-dynamic-slug", "provider-profile-deepseek-moon-bridge", "provider-profile-manager-secret-rbac", "provider-profile-validation-runner-job"] };
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.server.close(() => resolve()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user