The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Scraper, ScraperLoggingConfiguration, Workspace } from "@alchemy.run/aws/AMP"; |
| 3 | import * as Logs from "@alchemy.run/aws/Logs"; |
| 4 | import { expect } from "@alchemy.run/test"; |
| 5 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 6 | import * as amp from "@distilled.cloud/aws/amp"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: AWS.providers() }); |
| 10 | |
| 11 | // Ungated probes: prove the scraper API surface returns the typed errors the |
| 12 | // Scraper provider relies on (observe/delete both catch |
| 13 | // ResourceNotFoundException), at near-zero cost. |
| 14 | test.provider( |
| 15 | "describeScraper returns a typed not-found for a nonexistent scraper", |
| 16 | () => |
| 17 | Effect.gen(function* () { |
| 18 | const error = yield* Effect.flip( |
| 19 | amp.describeScraper({ |
| 20 | scraperId: "s-00000000-0000-0000-0000-000000000000", |
| 21 | }), |
| 22 | ); |
| 23 | expect(error._tag).toBe("ResourceNotFoundException"); |
| 24 | }), |
| 25 | { tags: ["provider:aws", "provider:aws:amp", "live"], timeout: 30_000 }, |
| 26 | ); |
| 27 | |
| 28 | test.provider( |
| 29 | "getDefaultScraperConfiguration returns Prometheus YAML", |
| 30 | () => |
| 31 | Effect.gen(function* () { |
| 32 | const response = yield* amp.getDefaultScraperConfiguration({}); |
| 33 | const yaml = yield* Effect.sync(() => new TextDecoder().decode(response.configuration)); |
| 34 | expect(yaml).toContain("scrape_configs"); |
| 35 | }), |
| 36 | { tags: ["provider:aws", "provider:aws:amp", "live"], timeout: 30_000 }, |
| 37 | ); |
| 38 | |
| 39 | // Full scraper lifecycle requires a live Amazon EKS cluster to scrape and |
| 40 | // takes many minutes to provision (the service creates network interfaces |
| 41 | // and an IAM role) — far beyond the suite's provisioning budget. Gate it |
| 42 | // behind an entitled/provisioned environment: |
| 43 | // AWS_TEST_AMP_SCRAPER=1 |
| 44 | // AWS_TEST_AMP_SCRAPER_CLUSTER_ARN=arn:aws:eks:...:cluster/my-cluster |
| 45 | // AWS_TEST_AMP_SCRAPER_SUBNET_IDS=subnet-a,subnet-b |
| 46 | test.provider.skipIf(!process.env.AWS_TEST_AMP_SCRAPER)( |
| 47 | "scraper lifecycle (create, update alias, logging, destroy)", |
| 48 | (stack) => |
| 49 | Effect.gen(function* () { |
| 50 | yield* stack.destroy(); |
| 51 | |
| 52 | const clusterArn = process.env.AWS_TEST_AMP_SCRAPER_CLUSTER_ARN!; |
| 53 | const subnetIds = process.env.AWS_TEST_AMP_SCRAPER_SUBNET_IDS!.split(","); |
| 54 | const defaultConfig = yield* amp.getDefaultScraperConfiguration({}); |
| 55 | const scrapeConfiguration = yield* Effect.sync(() => |
| 56 | new TextDecoder().decode(defaultConfig.configuration), |
| 57 | ); |
| 58 | |
| 59 | const program = (alias: string) => |
| 60 | Effect.gen(function* () { |
| 61 | const workspace = yield* Workspace("ScraperWorkspace", { |
| 62 | alias: "alchemy-test-amp-scraper", |
| 63 | tags: { Environment: "test" }, |
| 64 | }); |
| 65 | const scraper = yield* Scraper("Scraper", { |
| 66 | alias, |
| 67 | scrapeConfiguration, |
| 68 | source: { eksConfiguration: { clusterArn, subnetIds } }, |
| 69 | destinationWorkspaceArn: workspace.workspaceArn, |
| 70 | tags: { Environment: "test" }, |
| 71 | }); |
| 72 | const logs = yield* Logs.LogGroup("ScraperLogs", { |
| 73 | logGroupName: "/aws/vendedlogs/prometheus/alchemy-test-scraper", |
| 74 | retention: "1 day", |
| 75 | }); |
| 76 | const logging = yield* ScraperLoggingConfiguration("Logging", { |
| 77 | scraperId: scraper.scraperId, |
| 78 | logGroupArn: logs.logGroupArn, |
| 79 | }); |
| 80 | return { workspace, scraper, logging }; |
| 81 | }); |
| 82 | |
| 83 | const created = yield* stack.deploy(program("alchemy-test-scraper")); |
| 84 | const scraperId = created.scraper.scraperId; |
| 85 | expect(scraperId).toMatch(/^s-/); |
| 86 | expect(created.scraper.status).toBe("ACTIVE"); |
| 87 | expect(created.logging.scraperId).toBe(scraperId); |
| 88 | |
| 89 | // Out-of-band verification via distilled. |
| 90 | const described = yield* amp.describeScraper({ scraperId }); |
| 91 | expect(described.scraper.tags?.["alchemy::id"]).toBe("Scraper"); |
| 92 | |
| 93 | // In-place alias update — same scraper id survives. |
| 94 | const updated = yield* stack.deploy(program("alchemy-test-scraper-2")); |
| 95 | expect(updated.scraper.scraperId).toBe(scraperId); |
| 96 | expect(updated.scraper.alias).toBe("alchemy-test-scraper-2"); |
| 97 | |
| 98 | yield* stack.destroy(); |
| 99 | }), |
| 100 | { |
| 101 | tags: ["provider:aws", "provider:aws:amp", "provider:aws:logs", "live"], |
| 102 | timeout: 1_800_000, |
| 103 | }, |
| 104 | ); |