The best way to control Claude Code, Codex and more from any computer or phone

main
ts 97 lines 3.63 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { PolicyStore, PolicyStoreAlias } from "@alchemy.run/aws/VerifiedPermissions";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as avp from "@distilled.cloud/aws/verifiedpermissions";
6 import * as Effect from "effect/Effect";
7 import * as Result from "effect/Result";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 const findAlias = (aliasName: string) =>
12 avp
13 .getPolicyStoreAlias({ aliasName })
14 .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)));
15
16 // AWS requires every alias name to be prefixed with `policy-store-alias/`.
17 // The 2026-07-15 probes that concluded the API was "not yet available" all
18 // used bare names (hyphenated, plain, underscore, slash, mixed-case), which
19 // fail with "Invalid input" — the provider now always applies the prefix.
20 // This ungated probe pins that a bare name surfaces a typed
21 // ValidationException. The full lifecycle below is still gated behind
22 // AWS_TEST_POLICY_STORE_ALIAS=1 until it has been confirmed green against a
23 // live account.
24 test.provider(
25 "createPolicyStoreAlias rejects an alias name without the policy-store-alias/ prefix",
26 (stack) =>
27 Effect.gen(function* () {
28 yield* stack.destroy();
29 const { store } = yield* stack.deploy(
30 Effect.gen(function* () {
31 const store = yield* PolicyStore("Store", {
32 validationMode: "OFF",
33 });
34 return { store };
35 }),
36 );
37 const result = yield* Effect.result(
38 avp.createPolicyStoreAlias({
39 aliasName: "alchemy-probe-alias",
40 policyStoreId: store.policyStoreId,
41 }),
42 );
43 expect(Result.isFailure(result)).toBe(true);
44 if (Result.isFailure(result)) {
45 expect(result.failure._tag).toBe("ValidationException");
46 }
47 yield* stack.destroy();
48 }),
49 {
50 tags: ["provider:aws", "provider:aws:verifiedpermissions", "live"],
51 timeout: 120_000,
52 },
53 );
54
55 test.provider.skipIf(!process.env.AWS_TEST_POLICY_STORE_ALIAS)(
56 "policy store alias lifecycle: create with generated name, verify, destroy (hard delete)",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const makeStack = Effect.gen(function* () {
62 const store = yield* PolicyStore("Store", { validationMode: "OFF" });
63 const alias = yield* PolicyStoreAlias("Alias", {
64 policyStoreId: store.policyStoreId,
65 // HardDelete frees the generated name immediately so repeated test
66 // runs never collide with a PendingDeletion alias
67 deletionMode: "HardDelete",
68 });
69 return { store, alias };
70 });
71
72 // create
73 const { store, alias } = yield* stack.deploy(makeStack);
74 expect(alias.aliasName.startsWith("policy-store-alias/")).toBe(true);
75 expect(alias.aliasArn).toContain(":policy-store-alias/");
76 expect(alias.policyStoreId).toBe(store.policyStoreId);
77
78 // out-of-band verify
79 const created = yield* findAlias(alias.aliasName);
80 expect(created?.policyStoreId).toBe(store.policyStoreId);
81 expect(created?.state).toBe("Active");
82
83 // idempotent redeploy — same alias, no replacement
84 const redeployed = yield* stack.deploy(makeStack);
85 expect(redeployed.alias.aliasName).toBe(alias.aliasName);
86 expect(redeployed.alias.aliasArn).toBe(alias.aliasArn);
87
88 // destroy
89 yield* stack.destroy();
90 const gone = yield* findAlias(alias.aliasName);
91 expect(gone).toBeUndefined();
92 }),
93 {
94 tags: ["provider:aws", "provider:aws:verifiedpermissions", "live"],
95 timeout: 180_000,
96 },
97 );