The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { WebsiteArtifact, WebsiteArtifactProvider } from "@alchemy.run/neon/Website/Artifact"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as FileSystem from "effect/FileSystem"; |
| 6 | import * as Path from "effect/Path"; |
| 7 | import { unzipSync } from "fflate"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: WebsiteArtifactProvider() }); |
| 10 | |
| 11 | test.provider( |
| 12 | "artifact lifecycle tracks files, preserves no-op hashes, repairs missing and corrupt ZIPs, and deletes staging", |
| 13 | (stack) => |
| 14 | Effect.gen(function* () { |
| 15 | yield* stack.destroy(); |
| 16 | const fs = yield* FileSystem.FileSystem; |
| 17 | const path = yield* Path.Path; |
| 18 | const root = yield* fs.makeTempDirectoryScoped({ |
| 19 | prefix: "neon-artifact-lifecycle-", |
| 20 | }); |
| 21 | const distDir = path.join(root, "dist"); |
| 22 | yield* fs.makeDirectory(distDir); |
| 23 | yield* fs.writeFileString(path.join(distDir, "index.html"), "first artifact"); |
| 24 | const deploy = stack.deploy(WebsiteArtifact("Artifact", { root, distDir, static: {} })); |
| 25 | const first = yield* deploy; |
| 26 | expect((yield* deploy).hash).toBe(first.hash); |
| 27 | yield* fs.writeFileString(path.join(distDir, "index.html"), "updated artifact"); |
| 28 | const updated = yield* deploy; |
| 29 | expect(updated.hash).not.toBe(first.hash); |
| 30 | expect(updated.artifactPath).not.toBe(first.artifactPath); |
| 31 | const archive = yield* fs.readFile(updated.artifactPath); |
| 32 | const files = yield* Effect.sync(() => unzipSync(archive)); |
| 33 | const html = Object.entries(files).find(([name]) => name.endsWith("/index.html"))![1]; |
| 34 | expect(yield* Effect.sync(() => new TextDecoder().decode(html))).toBe("updated artifact"); |
| 35 | yield* fs.writeFileString(updated.artifactPath, "corrupt"); |
| 36 | expect((yield* deploy).hash).toBe(updated.hash); |
| 37 | expect(yield* fs.readFile(updated.artifactPath)).toEqual(archive); |
| 38 | yield* fs.remove(updated.artifactPath); |
| 39 | expect((yield* deploy).hash).toBe(updated.hash); |
| 40 | expect(yield* fs.exists(updated.artifactPath)).toBe(true); |
| 41 | yield* stack.destroy(); |
| 42 | expect(yield* fs.exists(updated.directory)).toBe(false); |
| 43 | }).pipe(Effect.scoped), |
| 44 | { |
| 45 | tags: ["unit", "provider:neon", "provider:neon:website", "local"], |
| 46 | timeout: 120_000, |
| 47 | }, |
| 48 | ); |