Forge
csharpdeeb25a2
1using System.Text.Json;
2using CascadeIDE.Models.Intercom;
3using CascadeIDE.Services;
4using Xunit;
5
6namespace CascadeIDE.Tests;
7
8public sealed class IntercomAttachmentRevealTests
9{
10 [Fact]
11 public void IntercomRevealAttachment_TryParse_AnchorJson()
12 {
13 var anchorJson = JsonSerializer.SerializeToElement(new
14 {
15 id = "a1",
16 file = "src/Foo.cs",
17 lineStart = 10,
18 lineEnd = 20,
19 memberKey = "M:Foo.Bar"
20 });
21 var args = new Dictionary<string, JsonElement>
22 {
23 ["anchor_json"] = anchorJson
24 };
25
26 Assert.True(IntercomRevealAttachmentMcpArgs.TryParse(args, out var anchor, out var selectExplicit, out _, out var err), err);
27 Assert.Equal("src/Foo.cs", anchor.File);
28 Assert.Equal(10, anchor.LineStart);
29 Assert.Equal(20, anchor.LineEnd);
30 Assert.Null(selectExplicit);
31 }
32
33 [Fact]
34 public void IntercomAttachmentRevealPlanner_Resolved_WhenFileExists()
35 {
36 var dir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), nameof(IntercomAttachmentRevealTests) + "_ws")).FullName;
37 var rel = Path.Combine("sub", "hit.cs");
38 var fullDir = Path.Combine(dir, "sub");
39 Directory.CreateDirectory(fullDir);
40 var full = Path.Combine(fullDir, "hit.cs");
41 File.WriteAllText(full, "// x\n");
42
43 var anchor = new AttachmentAnchor { File = rel.Replace('\\', '/'), LineStart = 1, LineEnd = 1 };
44 var plan = IntercomAttachmentRevealPlan.Create(anchor, dir);
45
46 Assert.Equal(IntercomAttachmentRevealPlan.OutcomeResolved, plan.ResolveOutcome);
47 Assert.True(File.Exists(plan.AbsoluteFilePath));
48 Assert.NotNull(plan.Lines);
49 }
50
51 [Fact]
52 public void IntercomAttachmentRevealPlanner_FileMissing_WhenNotOnDisk()
53 {
54 var dir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), nameof(IntercomAttachmentRevealTests) + "_missing")).FullName;
55 var anchor = new AttachmentAnchor { File = "nope/Missing.cs", LineStart = 1, LineEnd = 1 };
56 var plan = IntercomAttachmentRevealPlan.Create(anchor, dir);
57
58 Assert.Equal(IntercomAttachmentRevealPlan.OutcomeFileMissing, plan.ResolveOutcome);
59 Assert.Contains("file_missing", plan.Message, StringComparison.Ordinal);
60 }
61}
62
View only · write via MCP/CIDE