90e86a5e3d
* tweak: use theme tokens for debug bar surface * chore: update nix node_modules hashes * feat(tui): add heap snapshot functionality for TUI and server (#19028) * ci * change model for changelog * release: v1.3.2 * fix(opencode): skip typechecking generated models snapshot (#19018) * Revert "fix(app): more startup efficiency (#18985)" This reverts commit98b3340cee. * Revert "fix(app): startup efficiency (#18854)" This reverts commit546748a461. * effectify Worktree service (#18679) * fix: increase operations-per-run to 1000 and pin stale action to v10.2.0 The stale-issues workflow was hitting the default 30 operations limit, preventing it from processing all 2900+ issues/PRs. Increased to 1000 to handle the full backlog. Also pinned to exact v10.2.0 for reproducibility. * Add close-issues script and GitHub Action - Create script/github/close-issues.ts to close stale issues after 60 days - Add GitHub Action workflow to run daily at 2 AM - Remove old stale-issues workflow to avoid conflicts * Fix close-issues workflow permissions - Add contents: read permission for checkout - Use github.token instead of secrets.GITHUB_TOKEN * Process issues sequentially to avoid rate limits * Change issue close reason from not_planned to completed * fix(opencode): avoid snapshotting files over 2MB (#19043) * fix: provide merge context to beta conflict resolver (#19055) * tweak: only spawn lsp servers for files in current instance (or cwd if instance is global) (#19058) * fix: beta resolver typecheck + build smoke check (#19060) * fix: unblock beta conflict recovery (#19068) * electron: add createDirectory to open directory picker (#19071) * electron: remove file extension from electron-store wrapper (#19082) * app: pre-warm project globalSync state when navigate project via keybind (#19088) * fix(app): move message navigation off cmd+arrow (#18728) * Reapply "fix(app): startup efficiency (#18854)" This reverts commita379eb3867. * Reapply "fix(app): more startup efficiency (#18985)" This reverts commitcbe1337f24. * fix(app): hash inline script for csp * Revert "fix(app): startup efficiency" * Reapply "fix(app): startup efficiency" This reverts commit898456a25c. * fix(app): opencode web server url * chore(app): markdown playground in storyboard * chore(app): markdown playground in storyboard * feat(core): initial implementation of syncing (#17814) * chore: generate * chore: bump modelcontextprotocol/sdk to 1.27.1 (#19064) * chore: storybook tweaks * feat: restore git-backed review modes with effectful git service (#18900) * chore: generate * chore: update nix node_modules hashes * chore: cleanup * chore: remove dead code for todoread tool (#19128) * chore: storybook tweaks * fix(opencode): classify ZlibError from Bun fetch as retryable instead of unknown (#19104) Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> * fix(task): respect agent permission config for todowrite tool (#19125) * fix(app): agent normalization (#19169) * fix: Windows e2e stability (CrossSpawnSpawner, snapshot isolation, session race guards) (#19163) * fix+refactor(mcp): lifecycle tests, cancelPending fix, Effect migration (#19042) * effectify Bus service: migrate to Effect PubSub + InstanceState (#18579) * file: use Effect.cached for scan deduplication (#19164) * ignore: update disavowed list (#19184) * skill: use Effect.cached for load deduplication (#19165) * chore: generate * fix: bump gitlab-ai-provider to 5.3.3 for DWS tool approval support (#19185) * test: restore 5 workers on Windows e2e (#19188) * fix(opencode): image paste on Windows Terminal 1.25+ with kitty keyboard (#17674) * chore: update nix node_modules hashes * wip: zen * wip: zen * go: do not respect disabled zen models * fix: ensure enterprise url is set properly during auth flow (#19212) * revert: roll back git-backed review modes (#19295) * chore: generate * tui: bypass local SSE event streaming in worker (#19183) * feat: embed WebUI in binary with proxy flags (#19299) Co-authored-by: BlankParticle <blankparticle@gmail.com> * release: v1.3.3 * chore: generate * changelog ci tweaks * refactor(lsp): effectify LSP service with InstanceState (#19150) * chore: generate * feat: add gpt prompt so non codex gpt models have their own system prompt modeled after codex cli (#19220) * feat(core): remove workspace server, WorkspaceContext, start work towards better routing (#19316) * effectify Config service (#19139) * chore: generate * refactor(config): use cachedInvalidateWithTTL, bump effect to beta.37 (#19322) * fix(mcp): close transport on failed/timed-out connections (#19200) * fix(app): more startup perf (#19288) * chore: generate * chore: update nix node_modules hashes * fix(app): don't bundle fonts (#19329) * chore: generate * fix(app): default shell tool to collapsed * fix(app): remove fork session button * fix(ui): reduce markdown jank while responses stream (#19304) * fix: web ui bundle build on windows (#19337) * refactor(effect): yield services instead of promise facades (#19325) * chore: generate * refactor(vcs): replace async git() with ChildProcessSpawner (#19361) * fix(opencode): ignore generated models snapshot files (#19362) * fix(ui): keep partial markdown readable while responses stream (#19403) * chore: update nix node_modules hashes * fix(app): persist queued followups across project switches (#19421) * refactor(tool-registry): yield Config/Plugin services, use Effect.forEach (#19363) * chore: generate * tui plugins (#19347) * chore: generate * effectify Skill service internals (#19364) * chore: update nix node_modules hashes * effectify Plugin service internals (#19365) * refactor(core): split out instance and route through workspaces (#19335) * chore(app): more spacing controls * fix(ui): make streamed markdown feel more continuous (#19404) * fix(app): resize layout viewport when mobile keyboard appears (#15841) * fix(desktop-electron): match dev dock icon inset on macOS (#19429) * fix(app): default file tree to closed with minimum width (#19426) * fix flaky plugin tests (no mock.module for bun) (#19445) * tweak: add additional overflow error patterns (#19446) * no theme override in dev (#19456) * feat: AI SDK v6 support (#18433) * refactor(session): effectify Session service (#19449) * refactor(core): move more responsibility to workspace routing (#19455) * chore: update nix node_modules hashes * refactor(format): use ChildProcessSpawner instead of Process.spawn (#19457) * chore: generate * Single target plugin entrypoints (#19467) * refactor(session): effectify SessionCompaction service (#19459) * feat(ci): use Azure Artifact Signing for Windows releases (#15201) * fix(app): more startup efficiency (#19454) * update effect to 4.0.0-beta.42 (#19484) * chore: update nix node_modules hashes * tweak: adjust bash tool description to increase cache hit rates between projects (#19487) * refactor(session): move context into prompt footer (#19486) * refactor(prompt): remove variant cycle display from footer (#19489) * feat: add model variant selection dialog (#19488) * fix: restore subagent footer and fix style guide violations (#19491) * tweak(session): add top spacing and remove obsolete docs prompt * upgrade opentui to 0.1.91 (#19440) * refactor(file): use AppFileSystem instead of raw Filesystem (#19458) * chore: generate * chore: update nix node_modules hashes * kv theme before default fallback (#19523) * feat: open dialog for model variant selection instead of cycling (#19534) * refactor(session): effectify session processor (#19485) * feat: dialog variant menu and subagent improvements (#19537) * use theme color for prompt placeholder (#19535) * fix: update opencode-gitlab-auth to 2.0.1 (#19552) * chore: update nix node_modules hashes * prompt slot (#19563) * fix: respect semver build identifiers for nix (#11915) * fix: nix embedded web-ui support (#19561) * ignore: kill todo (#19566) * chore: update nix node_modules hashes * wip: zen * wip: zen * zen: ZDR policy * ci: cancel stale nix-hashes runs (#19571) * release: v1.3.4 * refactor: kilo compat for v1.3.4 * fix: migration types * refactor: upgrade kilo-gateway to ai sdk v6 * refactor: improve upstream merge script * fix: fix some tests * style(kilo-vscode): adjust indentation and formatting in parts-util and PopupSelector Normalize boolean expression indentation in isCompletionResult to use consistent 4-space alignment and reformat PopupSelectorProps generic interface declaration to split the Omit type across multiple lines. * docs(kilo-docs): update auto-generated source links Remove outdated URLs and add new bug report issue link pointing to anomalyco/opencode repository. Drop references to kilocode bug report template and config precedence order docs, reducing total unique URLs from 262 to 261. * fix(kilo-ui): remove unused NerdFonts story and MONO_NERD_FONTS import Drop the NerdFonts story from font.stories.tsx along with the unused MONO_NERD_FONTS import, as the exported constant is no longer available from the @opencode-ai/ui/font module. * chore: update visual regression baselines * fix(opencode): move Show conditional wrapper outside box in home onboarding Relocate the Show component to wrap the box element instead of being nested inside it, preventing the empty box from rendering when the onboarding tip is not visible. --------- Co-authored-by: Jay V <air@live.ca> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Brendan Allan <brendonovich@outlook.com> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: James Long <longster@gmail.com> Co-authored-by: André Cruz <acruz@cloudflare.com> Co-authored-by: Ariane Emory <97994360+ariane-emory@users.noreply.github.com> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: BlankParticle <blankparticle@gmail.com> Co-authored-by: Sebastian <hasta84@gmail.com> Co-authored-by: Burak Yigit Kaya <byk@sentry.io> Co-authored-by: Caleb Norton <n0603919@outlook.com> Co-authored-by: Imanol Maiztegui <imanol.mzd@gmail.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
460 lines
15 KiB
TypeScript
460 lines
15 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { Project } from "../../src/project/project"
|
|
import { Log } from "../../src/util/log"
|
|
import { $ } from "bun"
|
|
import path from "path"
|
|
import { tmpdir } from "../fixture/fixture"
|
|
import { GlobalBus } from "../../src/bus/global"
|
|
import { ProjectID } from "../../src/project/schema"
|
|
import { Effect, Layer, Stream } from "effect"
|
|
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
|
|
import { NodeFileSystem, NodePath } from "@effect/platform-node"
|
|
import { AppFileSystem } from "../../src/filesystem"
|
|
import * as CrossSpawnSpawner from "../../src/effect/cross-spawn-spawner"
|
|
|
|
Log.init({ print: false })
|
|
|
|
const encoder = new TextEncoder()
|
|
|
|
/**
|
|
* Creates a mock ChildProcessSpawner layer that intercepts git subcommands
|
|
* matching `failArg` and returns exit code 128, while delegating everything
|
|
* else to the real CrossSpawnSpawner.
|
|
*/
|
|
function mockGitFailure(failArg: string) {
|
|
return Layer.effect(
|
|
ChildProcessSpawner.ChildProcessSpawner,
|
|
Effect.gen(function* () {
|
|
const real = yield* ChildProcessSpawner.ChildProcessSpawner
|
|
return ChildProcessSpawner.make(
|
|
Effect.fnUntraced(function* (command) {
|
|
const std = ChildProcess.isStandardCommand(command) ? command : undefined
|
|
if (std?.command === "git" && std.args.some((a) => a === failArg)) {
|
|
return ChildProcessSpawner.makeHandle({
|
|
pid: ChildProcessSpawner.ProcessId(0),
|
|
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(128)),
|
|
isRunning: Effect.succeed(false),
|
|
kill: () => Effect.void,
|
|
stdin: { [Symbol.for("effect/Sink/TypeId")]: Symbol.for("effect/Sink/TypeId") } as any,
|
|
stdout: Stream.empty,
|
|
stderr: Stream.make(encoder.encode("fatal: simulated failure\n")),
|
|
all: Stream.empty,
|
|
getInputFd: () => ({ [Symbol.for("effect/Sink/TypeId")]: Symbol.for("effect/Sink/TypeId") }) as any,
|
|
getOutputFd: () => Stream.empty,
|
|
})
|
|
}
|
|
return yield* real.spawn(command)
|
|
}),
|
|
)
|
|
}),
|
|
).pipe(Layer.provide(CrossSpawnSpawner.defaultLayer))
|
|
}
|
|
|
|
function projectLayerWithFailure(failArg: string) {
|
|
return Project.layer.pipe(
|
|
Layer.provide(mockGitFailure(failArg)),
|
|
Layer.provide(AppFileSystem.defaultLayer),
|
|
Layer.provide(NodePath.layer),
|
|
)
|
|
}
|
|
|
|
describe("Project.fromDirectory", () => {
|
|
test("should handle git repository with no commits", async () => {
|
|
await using tmp = await tmpdir()
|
|
await $`git init`.cwd(tmp.path).quiet()
|
|
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
expect(project).toBeDefined()
|
|
expect(project.id).toBe(ProjectID.global)
|
|
expect(project.vcs).toBe("git")
|
|
expect(project.worktree).toBe(tmp.path)
|
|
|
|
const opencodeFile = path.join(tmp.path, ".git", "opencode")
|
|
expect(await Bun.file(opencodeFile).exists()).toBe(false)
|
|
})
|
|
|
|
test("should handle git repository with commits", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
expect(project).toBeDefined()
|
|
expect(project.id).not.toBe(ProjectID.global)
|
|
expect(project.vcs).toBe("git")
|
|
expect(project.worktree).toBe(tmp.path)
|
|
|
|
const kiloFile = path.join(tmp.path, ".git", "kilo")
|
|
expect(await Bun.file(kiloFile).exists()).toBe(true)
|
|
})
|
|
|
|
test("returns global for non-git directory", async () => {
|
|
await using tmp = await tmpdir()
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
expect(project.id).toBe(ProjectID.global)
|
|
})
|
|
|
|
test("derives stable project ID from root commit", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project: a } = await Project.fromDirectory(tmp.path)
|
|
const { project: b } = await Project.fromDirectory(tmp.path)
|
|
expect(b.id).toBe(a.id)
|
|
})
|
|
})
|
|
|
|
describe("Project.fromDirectory git failure paths", () => {
|
|
test("keeps vcs when rev-list exits non-zero (no commits)", async () => {
|
|
await using tmp = await tmpdir()
|
|
await $`git init`.cwd(tmp.path).quiet()
|
|
|
|
// rev-list fails because HEAD doesn't exist yet — this is the natural scenario
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
expect(project.vcs).toBe("git")
|
|
expect(project.id).toBe(ProjectID.global)
|
|
expect(project.worktree).toBe(tmp.path)
|
|
})
|
|
|
|
test("handles show-toplevel failure gracefully", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const layer = projectLayerWithFailure("--show-toplevel")
|
|
|
|
const { project, sandbox } = await Effect.runPromise(
|
|
Project.Service.use((svc) => svc.fromDirectory(tmp.path)).pipe(Effect.provide(layer)),
|
|
)
|
|
expect(project.worktree).toBe(tmp.path)
|
|
expect(sandbox).toBe(tmp.path)
|
|
})
|
|
|
|
test("handles git-common-dir failure gracefully", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const layer = projectLayerWithFailure("--git-common-dir")
|
|
|
|
const { project, sandbox } = await Effect.runPromise(
|
|
Project.Service.use((svc) => svc.fromDirectory(tmp.path)).pipe(Effect.provide(layer)),
|
|
)
|
|
expect(project.worktree).toBe(tmp.path)
|
|
expect(sandbox).toBe(tmp.path)
|
|
})
|
|
})
|
|
|
|
describe("Project.fromDirectory with worktrees", () => {
|
|
test("should set worktree to root when called from root", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
|
|
const { project, sandbox } = await Project.fromDirectory(tmp.path)
|
|
|
|
expect(project.worktree).toBe(tmp.path)
|
|
expect(sandbox).toBe(tmp.path)
|
|
expect(project.sandboxes).not.toContain(tmp.path)
|
|
})
|
|
|
|
test("should set worktree to root when called from a worktree", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
|
|
const worktreePath = path.join(tmp.path, "..", path.basename(tmp.path) + "-worktree")
|
|
try {
|
|
await $`git worktree add ${worktreePath} -b test-branch-${Date.now()}`.cwd(tmp.path).quiet()
|
|
|
|
const { project, sandbox } = await Project.fromDirectory(worktreePath)
|
|
|
|
expect(project.worktree).toBe(tmp.path)
|
|
expect(sandbox).toBe(worktreePath)
|
|
expect(project.sandboxes).toContain(worktreePath)
|
|
expect(project.sandboxes).not.toContain(tmp.path)
|
|
} finally {
|
|
await $`git worktree remove ${worktreePath}`
|
|
.cwd(tmp.path)
|
|
.quiet()
|
|
.catch(() => {})
|
|
}
|
|
})
|
|
|
|
test("worktree should share project ID with main repo", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
|
|
const { project: main } = await Project.fromDirectory(tmp.path)
|
|
|
|
const worktreePath = path.join(tmp.path, "..", path.basename(tmp.path) + "-wt-shared")
|
|
try {
|
|
await $`git worktree add ${worktreePath} -b shared-${Date.now()}`.cwd(tmp.path).quiet()
|
|
|
|
const { project: wt } = await Project.fromDirectory(worktreePath)
|
|
|
|
expect(wt.id).toBe(main.id)
|
|
|
|
// Cache should live in the common .git dir, not the worktree's .git file
|
|
const cache = path.join(tmp.path, ".git", "kilo")
|
|
const exists = await Bun.file(cache).exists()
|
|
expect(exists).toBe(true)
|
|
} finally {
|
|
await $`git worktree remove ${worktreePath}`
|
|
.cwd(tmp.path)
|
|
.quiet()
|
|
.catch(() => {})
|
|
}
|
|
})
|
|
|
|
test("separate clones of the same repo should share project ID", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
|
|
// Create a bare remote, push, then clone into a second directory
|
|
const bare = tmp.path + "-bare"
|
|
const clone = tmp.path + "-clone"
|
|
try {
|
|
await $`git clone --bare ${tmp.path} ${bare}`.quiet()
|
|
await $`git clone ${bare} ${clone}`.quiet()
|
|
|
|
const { project: a } = await Project.fromDirectory(tmp.path)
|
|
const { project: b } = await Project.fromDirectory(clone)
|
|
|
|
expect(b.id).toBe(a.id)
|
|
} finally {
|
|
await $`rm -rf ${bare} ${clone}`.quiet().nothrow()
|
|
}
|
|
})
|
|
|
|
test("should accumulate multiple worktrees in sandboxes", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
|
|
const worktree1 = path.join(tmp.path, "..", path.basename(tmp.path) + "-wt1")
|
|
const worktree2 = path.join(tmp.path, "..", path.basename(tmp.path) + "-wt2")
|
|
try {
|
|
await $`git worktree add ${worktree1} -b branch-${Date.now()}`.cwd(tmp.path).quiet()
|
|
await $`git worktree add ${worktree2} -b branch-${Date.now() + 1}`.cwd(tmp.path).quiet()
|
|
|
|
await Project.fromDirectory(worktree1)
|
|
const { project } = await Project.fromDirectory(worktree2)
|
|
|
|
expect(project.worktree).toBe(tmp.path)
|
|
expect(project.sandboxes).toContain(worktree1)
|
|
expect(project.sandboxes).toContain(worktree2)
|
|
expect(project.sandboxes).not.toContain(tmp.path)
|
|
} finally {
|
|
await $`git worktree remove ${worktree1}`
|
|
.cwd(tmp.path)
|
|
.quiet()
|
|
.catch(() => {})
|
|
await $`git worktree remove ${worktree2}`
|
|
.cwd(tmp.path)
|
|
.quiet()
|
|
.catch(() => {})
|
|
}
|
|
})
|
|
})
|
|
|
|
describe("Project.discover", () => {
|
|
test("should discover favicon.png in root", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
const pngData = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
|
|
await Bun.write(path.join(tmp.path, "favicon.png"), pngData)
|
|
|
|
await Project.discover(project)
|
|
|
|
const updated = Project.get(project.id)
|
|
expect(updated).toBeDefined()
|
|
expect(updated!.icon).toBeDefined()
|
|
expect(updated!.icon?.url).toStartWith("data:")
|
|
expect(updated!.icon?.url).toContain("base64")
|
|
expect(updated!.icon?.color).toBeUndefined()
|
|
})
|
|
|
|
test("should not discover non-image files", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
await Bun.write(path.join(tmp.path, "favicon.txt"), "not an image")
|
|
|
|
await Project.discover(project)
|
|
|
|
const updated = Project.get(project.id)
|
|
expect(updated).toBeDefined()
|
|
expect(updated!.icon).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe("Project.update", () => {
|
|
test("should update name", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
const updated = await Project.update({
|
|
projectID: project.id,
|
|
name: "New Project Name",
|
|
})
|
|
|
|
expect(updated.name).toBe("New Project Name")
|
|
|
|
const fromDb = Project.get(project.id)
|
|
expect(fromDb?.name).toBe("New Project Name")
|
|
})
|
|
|
|
test("should update icon url", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
const updated = await Project.update({
|
|
projectID: project.id,
|
|
icon: { url: "https://example.com/icon.png" },
|
|
})
|
|
|
|
expect(updated.icon?.url).toBe("https://example.com/icon.png")
|
|
|
|
const fromDb = Project.get(project.id)
|
|
expect(fromDb?.icon?.url).toBe("https://example.com/icon.png")
|
|
})
|
|
|
|
test("should update icon color", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
const updated = await Project.update({
|
|
projectID: project.id,
|
|
icon: { color: "#ff0000" },
|
|
})
|
|
|
|
expect(updated.icon?.color).toBe("#ff0000")
|
|
|
|
const fromDb = Project.get(project.id)
|
|
expect(fromDb?.icon?.color).toBe("#ff0000")
|
|
})
|
|
|
|
test("should update commands", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
const updated = await Project.update({
|
|
projectID: project.id,
|
|
commands: { start: "npm run dev" },
|
|
})
|
|
|
|
expect(updated.commands?.start).toBe("npm run dev")
|
|
|
|
const fromDb = Project.get(project.id)
|
|
expect(fromDb?.commands?.start).toBe("npm run dev")
|
|
})
|
|
|
|
test("should throw error when project not found", async () => {
|
|
await expect(
|
|
Project.update({
|
|
projectID: ProjectID.make("nonexistent-project-id"),
|
|
name: "Should Fail",
|
|
}),
|
|
).rejects.toThrow("Project not found: nonexistent-project-id")
|
|
})
|
|
|
|
test("should emit GlobalBus event on update", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
let eventPayload: any = null
|
|
const on = (data: any) => {
|
|
eventPayload = data
|
|
}
|
|
GlobalBus.on("event", on)
|
|
|
|
try {
|
|
await Project.update({
|
|
projectID: project.id,
|
|
name: "Updated Name",
|
|
})
|
|
|
|
expect(eventPayload).not.toBeNull()
|
|
expect(eventPayload.payload.type).toBe("project.updated")
|
|
expect(eventPayload.payload.properties.name).toBe("Updated Name")
|
|
} finally {
|
|
GlobalBus.off("event", on)
|
|
}
|
|
})
|
|
|
|
test("should update multiple fields at once", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
const updated = await Project.update({
|
|
projectID: project.id,
|
|
name: "Multi Update",
|
|
icon: { url: "https://example.com/favicon.ico", color: "#00ff00" },
|
|
commands: { start: "make start" },
|
|
})
|
|
|
|
expect(updated.name).toBe("Multi Update")
|
|
expect(updated.icon?.url).toBe("https://example.com/favicon.ico")
|
|
expect(updated.icon?.color).toBe("#00ff00")
|
|
expect(updated.commands?.start).toBe("make start")
|
|
})
|
|
})
|
|
|
|
describe("Project.list and Project.get", () => {
|
|
test("list returns all projects", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
const all = Project.list()
|
|
expect(all.length).toBeGreaterThan(0)
|
|
expect(all.find((p) => p.id === project.id)).toBeDefined()
|
|
})
|
|
|
|
test("get returns project by id", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
const found = Project.get(project.id)
|
|
expect(found).toBeDefined()
|
|
expect(found!.id).toBe(project.id)
|
|
})
|
|
|
|
test("get returns undefined for unknown id", () => {
|
|
const found = Project.get(ProjectID.make("nonexistent"))
|
|
expect(found).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe("Project.setInitialized", () => {
|
|
test("sets time_initialized on project", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
|
|
expect(project.time.initialized).toBeUndefined()
|
|
|
|
Project.setInitialized(project.id)
|
|
|
|
const updated = Project.get(project.id)
|
|
expect(updated?.time.initialized).toBeDefined()
|
|
})
|
|
})
|
|
|
|
describe("Project.addSandbox and Project.removeSandbox", () => {
|
|
test("addSandbox adds directory and removeSandbox removes it", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
const sandboxDir = path.join(tmp.path, "sandbox-test")
|
|
|
|
await Project.addSandbox(project.id, sandboxDir)
|
|
|
|
let found = Project.get(project.id)
|
|
expect(found?.sandboxes).toContain(sandboxDir)
|
|
|
|
await Project.removeSandbox(project.id, sandboxDir)
|
|
|
|
found = Project.get(project.id)
|
|
expect(found?.sandboxes).not.toContain(sandboxDir)
|
|
})
|
|
|
|
test("addSandbox emits GlobalBus event", async () => {
|
|
await using tmp = await tmpdir({ git: true })
|
|
const { project } = await Project.fromDirectory(tmp.path)
|
|
const sandboxDir = path.join(tmp.path, "sandbox-event")
|
|
|
|
const events: any[] = []
|
|
const on = (evt: any) => events.push(evt)
|
|
GlobalBus.on("event", on)
|
|
|
|
await Project.addSandbox(project.id, sandboxDir)
|
|
|
|
GlobalBus.off("event", on)
|
|
expect(events.some((e) => e.payload.type === Project.Event.Updated.type)).toBe(true)
|
|
})
|
|
})
|