Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

2.4 KB
Raw Blame
import * as Cloudflare from "@/Cloudflare";
import { adopt } from "@/AdoptPolicy";
import * as Provider from "@/Provider";
import * as Test from "@/Test/Alchemy";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
import * as Redacted from "effect/Redacted";
import { MinimumLogLevel } from "effect/References";

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 = "alchemy-vulnscanner-cred-list-set";
const CRED_LIST = "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),
);