TypeScript
fix(shared): inverted terminal ranges emit no fake lines (#27843)
samkelly880d7171d30a4e0
diff --git a/packages/shared/src/composerContextReferences.test.ts b/packages/shared/src/composerContextReferences.test.tsindex a90312bc5c4..40aa4f7743b 100644--- a/packages/shared/src/composerContextReferences.test.ts+++ b/packages/shared/src/composerContextReferences.test.ts@@ -221,6 +221,16 @@ describe("provider projection", () => {expect(project("a\n")).toContain("3 | a\n4 | \n</context>");});+ it("emits no terminal lines when the captured range is inverted", () => {+ const projected = projectComposerContextForProvider({+ text: "[log](t3-context://v1/terminal/ctx_t)",+ records: [{ ...terminal, lineStart: 10, lineEnd: 5, text: "a\nb\nc\nd\ne\nf" }],+ });+ expect(projected).toContain('<context kind="terminal" id="ctx_t">');+ expect(projected).toContain("terminal: Terminal 1\n</context>");+ expect(projected).not.toContain(" | ");+ });+it("emits every marker in place and each payload once, escaped, in first-reference order", () => {const text = ["Look at  and [T1](t3-context://v1/terminal/ctx_t).",diff --git a/packages/shared/src/composerContextReferences.ts b/packages/shared/src/composerContextReferences.tsindex 85ba03e973b..914d65ec760 100644--- a/packages/shared/src/composerContextReferences.ts+++ b/packages/shared/src/composerContextReferences.ts@@ -253,9 +253,10 @@ function formatComposerContextProviderPayload(record: KnownComposerContextRecord`attachmentId: ${record.attachmentId}`,].join("\n");case "terminal": {+ const lineCount = Math.max(0, record.lineEnd - record.lineStart + 1);const lines = record.text.split("\n")- .slice(0, record.lineEnd - record.lineStart + 1)+ .slice(0, lineCount).map((line, index) => `${record.lineStart + index} | ${line}`);return [`terminal: ${record.terminalLabel}`, ...lines].join("\n");}