Buckets:
| import { describe, expect } from "bun:test" | |
| import { Effect, Layer, Schema } from "effect" | |
| import { Database } from "@opencode-ai/core/database/database" | |
| import { EventV2 } from "@opencode-ai/core/event" | |
| import { Project } from "@opencode-ai/core/project" | |
| import { ProjectDirectories } from "@opencode-ai/core/project/directories" | |
| import { ProjectTable } from "@opencode-ai/core/project/sql" | |
| import { AbsolutePath } from "@opencode-ai/core/schema" | |
| import { testEffect } from "./lib/effect" | |
| const database = Database.layerFromPath(":memory:") | |
| const events = EventV2.layer.pipe(Layer.provide(database)) | |
| const directories = ProjectDirectories.layer.pipe(Layer.provide(database), Layer.provide(events)) | |
| const it = testEffect(Layer.mergeAll(database, events, directories)) | |
| const projectID = Project.ID.make("project-directories") | |
| const directory = AbsolutePath.make("/tmp/project-directories") | |
| function setup() { | |
| return Database.Service.use(({ db }) => | |
| db | |
| .insert(ProjectTable) | |
| .values({ id: projectID, worktree: directory, sandboxes: [], time_created: 1, time_updated: 1 }) | |
| .onConflictDoNothing() | |
| .run() | |
| .pipe(Effect.orDie), | |
| ) | |
| } | |
| describe("ProjectDirectories", () => { | |
| it.effect("decodes directory schemas", () => | |
| Effect.sync(() => { | |
| expect(Schema.decodeUnknownSync(ProjectDirectories.ListInput)({ projectID })).toEqual({ projectID }) | |
| expect(Schema.decodeUnknownSync(ProjectDirectories.ListOutput)([{ directory }])).toEqual([{ directory }]) | |
| }), | |
| ) | |
| it.effect("creates once and ignores conflicts", () => | |
| Effect.gen(function* () { | |
| yield* setup() | |
| const service = yield* ProjectDirectories.Service | |
| expect(yield* service.create({ projectID, directory })).toBe(true) | |
| expect(yield* service.create({ projectID, directory, strategy: "git_worktree" })).toBe(false) | |
| expect(yield* service.list(projectID)).toEqual([{ directory, strategy: undefined }]) | |
| }), | |
| ) | |
| it.effect("replaces the strategy when requested", () => | |
| Effect.gen(function* () { | |
| yield* setup() | |
| const service = yield* ProjectDirectories.Service | |
| yield* service.create({ projectID, directory, strategy: "old/strategy" }) | |
| expect(yield* service.create({ projectID, directory, strategy: "new/strategy", behavior: "replace" })).toBe(true) | |
| expect(yield* service.create({ projectID, directory, strategy: "new/strategy", behavior: "replace" })).toBe(false) | |
| expect(yield* service.create({ projectID, directory, behavior: "replace" })).toBe(true) | |
| expect(yield* service.create({ projectID, directory, behavior: "replace" })).toBe(false) | |
| expect(yield* service.create({ projectID, directory, strategy: "new/strategy", behavior: "replace" })).toBe(true) | |
| expect(yield* service.list(projectID)).toEqual([{ directory, strategy: "new/strategy" }]) | |
| }), | |
| ) | |
| }) | |
Xet Storage Details
- Size:
- 2.86 kB
- Xet hash:
- ebcf7cfc6c6c91825646db6fdda7e3c977272b132e120490179c02aa8876e3fb
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.