1
0

manifest.test.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { expect, test } from "bun:test"
  2. import { ConfigProvider, Effect, FileSystem, Layer } from "effect"
  3. import { DriveManifest } from "../src/manifest"
  4. test("loads and validates a Drive manifest through Effect services", async () => {
  5. const manifest = await Effect.runPromise(
  6. DriveManifest.resolve().pipe(
  7. Effect.provide(
  8. Layer.merge(
  9. FileSystem.layerNoop({
  10. readFileString: () =>
  11. Effect.succeed(
  12. JSON.stringify({
  13. endpoints: {
  14. ui: "ws://127.0.0.1:41000",
  15. backend: "ws://127.0.0.1:41050",
  16. },
  17. viewport: { cols: 120, rows: 50 },
  18. recording: { timeline: "/tmp/drive/timeline.jsonl" },
  19. }),
  20. ),
  21. }),
  22. ConfigProvider.layer(
  23. ConfigProvider.fromUnknown({
  24. OPENCODE_DRIVE: "test-instance",
  25. DRIVE_REGISTRY_DIR: "/tmp/drive",
  26. }),
  27. ),
  28. ),
  29. ),
  30. ),
  31. )
  32. expect(manifest).toEqual({
  33. endpoints: {
  34. ui: "ws://127.0.0.1:41000",
  35. backend: "ws://127.0.0.1:41050",
  36. },
  37. viewport: { cols: 120, rows: 50 },
  38. recording: { timeline: "/tmp/drive/timeline.jsonl" },
  39. })
  40. })
  41. test("reports schema-invalid manifests as typed decode failures", async () => {
  42. const error = await Effect.runPromise(
  43. DriveManifest.resolve().pipe(
  44. Effect.flip,
  45. Effect.provide(
  46. Layer.merge(
  47. FileSystem.layerNoop({
  48. readFileString: () =>
  49. Effect.succeed(
  50. JSON.stringify({
  51. endpoints: {
  52. ui: "https://example.com",
  53. backend: "ws://127.0.0.1:41050",
  54. },
  55. }),
  56. ),
  57. }),
  58. ConfigProvider.layer(
  59. ConfigProvider.fromUnknown({
  60. OPENCODE_DRIVE: "test-instance",
  61. DRIVE_REGISTRY_DIR: "/tmp/drive",
  62. }),
  63. ),
  64. ),
  65. ),
  66. ),
  67. )
  68. expect(error).toBeInstanceOf(DriveManifest.ResolveError)
  69. expect(error.reason).toBe("decode")
  70. })