|
1 | 1 | import { afterEach, describe, expect, test } from "bun:test"; |
2 | | -import { chmod, mkdir, mkdtemp, readdir, readFile, rm, stat, writeFile } from "node:fs/promises"; |
| 2 | +import { chmod, mkdir, mkdtemp, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises"; |
3 | 3 | import { tmpdir } from "node:os"; |
4 | 4 | import { join } from "node:path"; |
5 | 5 | import { |
@@ -217,18 +217,36 @@ describe("directory project declaration editing", () => { |
217 | 217 | expect(await readFile(statePath, "utf8")).toBe('{"remote":"latest"}\n'); |
218 | 218 | }); |
219 | 219 |
|
220 | | - test("removes a File declaration without deleting its local source", async () => { |
| 220 | + test("protects an automatically associated Agent-local File even without an authored mount", async () => { |
221 | 221 | const { directory, manager } = await projectFixture({ fileMount: false }); |
222 | 222 | const listed = await listProjectDeclarations(manager); |
| 223 | + expect(resource(listed.resources, "file", "input").references.map((reference) => reference.path)).toEqual([ |
| 224 | + "agents.assistant.files", |
| 225 | + ]); |
| 226 | + const preview = await previewDeclarationChange( |
| 227 | + { type: "file", id: "input", baseRevision: listed.revision, action: "delete" }, |
| 228 | + manager, |
| 229 | + ); |
| 230 | + expect(preview.can_commit).toBe(false); |
| 231 | + expect((await stat(join(directory, "agents/assistant/files/input/file.json"))).isFile()).toBe(true); |
| 232 | + }); |
| 233 | + |
| 234 | + test("removes an unreferenced shared File declaration without deleting its local source", async () => { |
| 235 | + const { directory, manager } = await projectFixture({ fileMount: false }); |
| 236 | + await mkdir(join(directory, "resources/files"), { recursive: true }); |
| 237 | + const fileDirectory = join(directory, "resources/files/input"); |
| 238 | + await rename(join(directory, "agents/assistant/files/input"), fileDirectory); |
| 239 | + await manager.refreshAfterSourceMutation(); |
| 240 | + const listed = await listProjectDeclarations(manager); |
223 | 241 | await commitDeclarationChange( |
224 | 242 | { type: "file", id: "input", baseRevision: listed.revision, action: "delete" }, |
225 | 243 | manager, |
226 | 244 | ); |
227 | 245 |
|
228 | | - expect(await stat(join(directory, "agents/assistant/files/input/file.json")).catch(() => null)).toBeNull(); |
229 | | - expect(await readFile(join(directory, "agents/assistant/files/input/input.txt"), "utf8")).toBe("Keep local file\n"); |
| 246 | + expect(await stat(join(fileDirectory, "file.json")).catch(() => null)).toBeNull(); |
| 247 | + expect(await readFile(join(fileDirectory, "input.txt"), "utf8")).toBe("Keep local file\n"); |
230 | 248 | expect( |
231 | | - await stat(join(directory, "agents/assistant/files/input", FILE_AUTO_ASSOCIATION_IGNORE_FILE)).then( |
| 249 | + await stat(join(fileDirectory, FILE_AUTO_ASSOCIATION_IGNORE_FILE)).then( |
232 | 250 | () => true, |
233 | 251 | () => false, |
234 | 252 | ), |
|
0 commit comments