prompt-missing-file.test.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import path from "path"
  2. import { describe, expect, test } from "bun:test"
  3. import { Instance } from "../../src/project/instance"
  4. import { Session } from "../../src/session"
  5. import { SessionPrompt } from "../../src/session/prompt"
  6. import { tmpdir } from "../fixture/fixture"
  7. describe("session.prompt missing file", () => {
  8. test("does not fail the prompt when a file part is missing", async () => {
  9. await using tmp = await tmpdir({
  10. git: true,
  11. config: {
  12. agent: {
  13. build: {
  14. model: "openai/gpt-5.2",
  15. },
  16. },
  17. },
  18. })
  19. await Instance.provide({
  20. directory: tmp.path,
  21. fn: async () => {
  22. const session = await Session.create({})
  23. const missing = path.join(tmp.path, "does-not-exist.ts")
  24. const msg = await SessionPrompt.prompt({
  25. sessionID: session.id,
  26. agent: "build",
  27. noReply: true,
  28. parts: [
  29. { type: "text", text: "please review @does-not-exist.ts" },
  30. {
  31. type: "file",
  32. mime: "text/plain",
  33. url: `file://${missing}`,
  34. filename: "does-not-exist.ts",
  35. },
  36. ],
  37. })
  38. if (msg.info.role !== "user") throw new Error("expected user message")
  39. const hasFailure = msg.parts.some(
  40. (part) => part.type === "text" && part.synthetic && part.text.includes("Read tool failed to read"),
  41. )
  42. expect(hasFailure).toBe(true)
  43. await Session.remove(session.id)
  44. },
  45. })
  46. })
  47. })