import * as Cloudflare from "@alchemy.run/cloudflare";
import { expect } from "@alchemy.run/test";
import * as Test from "@alchemy.run/test/Alchemy";
import { adopt } from "alchemy/AdoptPolicy";
import * as Provider from "alchemy/Provider";
import * as Effect from "effect/Effect";
import * as Redacted from "effect/Redacted";
import { MinimumLogLevel } from "effect/References";
import { testName } from "../../names.ts";
const { test } = Test.make({ providers: Cloudflare.providers() });
const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
// Deterministic per-test names — same on every run.
const SET_LIST = testName("alchemy-vulnscanner-cred-list-set");
const CRED_LIST = testName("alchemy-vulnscanner-cred-list");
test.provider(
"list enumerates the deployed credential",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const deployed = yield* stack.deploy(
Effect.gen(function* () {
const set = yield* Cloudflare.VulnerabilityScanner.VulnScannerCredentialSet("ListSet", {
name: SET_LIST,
}).pipe(adopt(true));
const credential = yield* Cloudflare.VulnerabilityScanner.VulnScannerCredential(
"ListCred",
{
credentialSetId: set.credentialSetId,
name: CRED_LIST,
location: "header",
locationName: "authorization",
value: Redacted.make("Bearer alchemy-list-test"),
},
).pipe(adopt(true));
return { set, credential };
}),
);
const provider = yield* Provider.findProvider(
Cloudflare.VulnerabilityScanner.VulnScannerCredential,
);
const all = yield* provider.list();
// Parent fan-out over credential sets contains the deployed credential,
// each element shaped exactly like `read`'s Attributes (value is
// write-only and absent from both).
expect(all.some((x) => x.credentialId === deployed.credential.credentialId)).toBe(true);
const found = all.find((x) => x.credentialId === deployed.credential.credentialId);
expect(found?.credentialSetId).toEqual(deployed.set.credentialSetId);
expect(found?.name).toEqual(CRED_LIST);
expect(found?.location).toEqual("header");
expect(found?.locationName).toEqual("authorization");
expect(found?.accountId).toEqual(deployed.credential.accountId);
yield* stack.destroy();
}).pipe(logLevel),
{ tags: ["provider:cloudflare", "provider:cloudflare:vulnerabilityscanner", "live"] },
);