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, 04:45 UTC
| 1 | import { Branch } from "@alchemy.run/neon/Branch"; |
| 2 | import { Function } from "@alchemy.run/neon/Function"; |
| 3 | import { FunctionTrigger } from "@alchemy.run/neon/FunctionTrigger"; |
| 4 | import { Project } from "@alchemy.run/neon/Project"; |
| 5 | import { providers } from "@alchemy.run/neon/Providers"; |
| 6 | import { expect } from "@alchemy.run/test"; |
| 7 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 8 | import * as Api from "@distilled.cloud/neon"; |
| 9 | import * as Effect from "effect/Effect"; |
| 10 | import * as HttpClient from "effect/http/HttpClient"; |
| 11 | import * as HttpClientRequest from "effect/http/HttpClientRequest"; |
| 12 | |
| 13 | const { test } = Test.make({ providers: providers() }); |
| 14 | test.provider( |
| 15 | "schedule lifecycle, inherited disabled state and spoofed attestation", |
| 16 | (stack) => |
| 17 | Effect.gen(function* () { |
| 18 | yield* stack.destroy(); |
| 19 | const deploy = (cron: string, enabled: boolean, child = false) => |
| 20 | stack.deploy( |
| 21 | Effect.gen(function* () { |
| 22 | const project = yield* Project("TriggerProject", { |
| 23 | region: "aws-us-east-2", |
| 24 | }); |
| 25 | const api = yield* Function("Api", { |
| 26 | project, |
| 27 | main: new URL("./fixtures/function-trigger.ts", import.meta.url).href, |
| 28 | }); |
| 29 | const trigger = yield* FunctionTrigger("Schedule", { |
| 30 | function: api, |
| 31 | type: "schedule", |
| 32 | schedule: { cron }, |
| 33 | path: "/jobs", |
| 34 | enabled, |
| 35 | }); |
| 36 | const preview = child ? yield* Branch("Preview", { project }) : undefined; |
| 37 | return { project, api, trigger, preview }; |
| 38 | }), |
| 39 | ); |
| 40 | const first = yield* deploy("0 2 * * *", false); |
| 41 | expect(first.trigger.enabled).toBe(false); |
| 42 | const changed = yield* deploy("0 3 * * *", true, true); |
| 43 | expect(changed.trigger.triggerId).toBe(first.trigger.triggerId); |
| 44 | expect(changed.trigger.version).toBeGreaterThan(first.trigger.version); |
| 45 | const observed = yield* Api.getProjectBranchTrigger({ |
| 46 | project_id: changed.trigger.projectId, |
| 47 | branch_id: changed.trigger.branchId, |
| 48 | trigger_id: changed.trigger.triggerId, |
| 49 | }); |
| 50 | expect(observed.trigger).toMatchObject({ |
| 51 | enabled: true, |
| 52 | type: "schedule", |
| 53 | schedule: { cron: "0 3 * * *" }, |
| 54 | }); |
| 55 | const inherited = yield* Api.getProjectBranchTrigger({ |
| 56 | project_id: changed.project.projectId, |
| 57 | branch_id: changed.preview!.branchId, |
| 58 | trigger_id: changed.trigger.triggerId, |
| 59 | }); |
| 60 | expect(inherited.trigger).toMatchObject({ |
| 61 | inherited: true, |
| 62 | enabled: false, |
| 63 | next_run_at: null, |
| 64 | }); |
| 65 | const client = yield* HttpClient.HttpClient; |
| 66 | const spoof = yield* client.execute( |
| 67 | HttpClientRequest.post(`${changed.api.url}jobs`).pipe( |
| 68 | HttpClientRequest.setHeader("x-neon-trigger-invocation-id", "spoof"), |
| 69 | HttpClientRequest.bodyJsonUnsafe({ |
| 70 | version: 1, |
| 71 | invocation_id: "spoof", |
| 72 | trigger: { type: "schedule" }, |
| 73 | data: {}, |
| 74 | }), |
| 75 | ), |
| 76 | ); |
| 77 | expect(spoof.status).toBe(403); |
| 78 | yield* stack.deploy( |
| 79 | Effect.gen(function* () { |
| 80 | const project = yield* Project("TriggerProject", { |
| 81 | region: "aws-us-east-2", |
| 82 | }); |
| 83 | yield* Function("Api", { |
| 84 | project, |
| 85 | main: new URL("./fixtures/function-trigger.ts", import.meta.url).href, |
| 86 | }); |
| 87 | yield* Branch("Preview", { project }); |
| 88 | }), |
| 89 | ); |
| 90 | expect( |
| 91 | yield* Api.getProjectBranchTrigger({ |
| 92 | project_id: changed.trigger.projectId, |
| 93 | branch_id: changed.trigger.branchId, |
| 94 | trigger_id: changed.trigger.triggerId, |
| 95 | }).pipe( |
| 96 | Effect.as(false), |
| 97 | Effect.catchTag("NotFound", () => Effect.succeed(true)), |
| 98 | ), |
| 99 | ).toBe(true); |
| 100 | yield* stack.destroy(); |
| 101 | }), |
| 102 | { |
| 103 | tags: [ |
| 104 | "provider:neon", |
| 105 | "provider:neon:branch", |
| 106 | "provider:neon:function", |
| 107 | "provider:neon:project", |
| 108 | "live", |
| 109 | ], |
| 110 | timeout: 120_000, |
| 111 | }, |
| 112 | ); |