Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/web/src/components/ChatView.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ it("an interrupted image-only first send of a new thread says it may not have be
.element()
.dispatchEvent(new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }));
await expect.element(page.getByRole("img", { name: "shot.png" })).toBeVisible();
// The thumbnail is visible while compression still blocks sending.
await expect.element(page.getByRole("button", { name: "Preview shot.png" })).toBeEnabled();
await userEvent.keyboard("{Enter}");
await vi.waitFor(() => expect(launch.calls).toHaveLength(1));
await userEvent.keyboard("next draft");
Expand Down
24 changes: 24 additions & 0 deletions packages/client-runtime/src/work-log/itemDetail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,27 @@ describe("MCP app tool output", () => {
expect(turnItemOutputText(bounded)).toBe("chart\n[image]");
});
});

describe("MCP results with the SDK's _meta", () => {
const meta = { "io.modelcontextprotocol/serverInfo": { name: "T3 Code", version: "1" } };
const structuredContent = {
check: "Server tests 7",
message: "expected [ 60 ]\nto equal [ 59 ]",
};
it.each([
[
"text and structured content",
{ content: JSON.stringify(structuredContent), structuredContent },
],
["text blocks only", { content: [{ type: "text", text: "Server tests: 7 passed" }] }],
[
"text blocks and structured content",
{ content: [{ type: "text", text: JSON.stringify(structuredContent) }], structuredContent },
],
])("reads %s the same with or without _meta", (_shape, result) => {
const plain = turnItemOutputText(toolItem(result));
const withMeta = turnItemOutputText(toolItem({ ...result, _meta: meta }));
expect(withMeta).toBe(plain);
expect(withMeta).not.toContain("serverInfo");
});
});
5 changes: 4 additions & 1 deletion packages/client-runtime/src/work-log/itemDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ function textFromBlocks(
if (typeof resource.text === "string") return resource.text;
if (typeof resource.uri === "string") return resource.uri;
}
const keys = Object.keys(value).filter((key) => key !== "isError" && key !== "is_error");
// MCP SDKs stamp `_meta` with server info on every result; it is never the tool's output.
const keys = Object.keys(value).filter(
(key) => key !== "isError" && key !== "is_error" && key !== "_meta",
);
if (keys.length === 1 && keys[0] === "content")
return textFromBlocks(value.content, depth + 1, imageBlocks);
if (keys.length === 2 && keys.includes("content") && keys.includes("structuredContent")) {
Expand Down
75 changes: 75 additions & 0 deletions packages/source-control-core/src/server/pullRequestChecks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,45 @@ describe("check log excerpts", () => {
lines: 1,
},
{ chunks: ["one\ntw", "o\nthree"], text: "one\ntwo\nthree", lines: 3 },
{
chunks: [
[
" ❯ ~effect/Effect/successCont ../../node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/esm/Effect.js:1:1",
" ❯ FiberImpl.runLoop ../../node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/esm/internal/fiberRuntime.js:1:1",
"##[start-action display=Install dependencies;id=install]",
"##[end-action id=install;outcome=success;conclusion=success;duration_ms=900]",
"Post job cleanup.",
"Cleaning up orphan processes",
" ❯ runAssertion src/example.test.ts:10:5",
].join("\n"),
],
text: " ❯ runAssertion src/example.test.ts:10:5",
lines: 7,
},
{
chunks: [
[
"##[error]TypeError: boom",
" at Object.<anonymous> (/home/runner/work/app/node_modules/foo/index.js:1:1)",
" at Object.<anonymous> (/home/runner/work/app/src/build.js:2:2)",
].join("\n"),
],
text: "##[error]TypeError: boom\n at Object.<anonymous> (/home/runner/work/app/src/build.js:2:2)",
lines: 3,
},
{
chunks: [
[
"##[start-action display=Install dependencies;id=install]",
"##[end-action id=install;outcome=success;conclusion=success;duration_ms=900]",
"##[start-action display=Build;id=build]",
"##[error]The action has timed out.",
"##[end-action id=build;outcome=failure;conclusion=failure;duration_ms=1250]",
].join("\n"),
],
text: "##[error]The action has timed out.\n##[end-action id=build;outcome=failure;conclusion=failure;duration_ms=1250]",
lines: 5,
},
])("strips formatting and counts lines across chunks %#", ({ chunks, text, lines }) => {
expect(excerptCheckLog(chunks)).toEqual({
_tag: "excerpt",
Expand All @@ -236,6 +275,42 @@ describe("check log excerpts", () => {
});
});

it("does not let noise consume error context or tail slots", () => {
const noise = [
" ❯ FiberImpl.runLoop ../../node_modules/.pnpm/effect@4.1.3/node_modules/effect/dist/esm/internal/fiberRuntime.js:1:1",
"##[start-action display=Install dependencies;id=install]",
"##[end-action id=install;outcome=success;conclusion=success;duration_ms=900]",
"Post job cleanup.",
"Cleaning up orphan processes",
];
const expected = [
"##[group]Run vp test",
"before 1",
"before 2",
"before 3",
"##[error]Assertion failed",
"after 1",
"after 2",
"after 3",
...Array.from({ length: 20 }, (_, i) => `tail ${i}`),
];
const result = excerptCheckLog([
[
...expected.slice(0, 4),
...noise,
...expected.slice(4, 5),
...noise,
...expected.slice(5),
...noise,
].join("\n"),
]);

expect(result.text).toBe(expected.join("\n"));
expect(result.totalLines).toBe(expected.length + noise.length * 3);
// Every real line is present, so dropped noise alone does not mark the excerpt truncated.
expect(result.truncated).toBe(false);
});

it("keeps error context, its Run header and the tail within both budgets", () => {
const lines = [
"##[group]Run vp test",
Expand Down
14 changes: 13 additions & 1 deletion packages/source-control-core/src/server/pullRequestChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ export const CHECK_LOG_EXCERPT_BUDGET = {
} as const;
type Line = { index: number; text: string };

// A failed composite step's end marker is the only record of which nested step failed.
const isLogNoise = (text: string) =>
(/^\s*(?:❯|at)\s/.test(text) && /node_modules[\\/]/.test(text)) ||
/^##\[start-action /.test(text) ||
/^##\[end-action .*outcome=(?:success|skipped)\b/.test(text) ||
/^(?:Post job cleanup\.|Cleaning up orphan processes)/.test(text);

export class CheckLogExcerpt {
private pending = "";
private totalLines = 0;
private noiseLines = 0;
private clipped = false;
private afterError = 0;
private header: Line | undefined;
Expand Down Expand Up @@ -150,6 +158,10 @@ export class CheckLogExcerpt {
.replace(/^\d{4}-\d\d-\d\dT[\d:.]+Z\s?/, "")
.replace(/\r$/, ""),
};
if (isLogNoise(line.text)) {
this.noiseLines++;
return;
}
// Step names do not appear in the log; a section failed when it carries ##[error].
if (line.text.startsWith("##[group]Run ")) {
if (this.failedSection) this.failedTail = this.tail;
Expand Down Expand Up @@ -208,7 +220,7 @@ export class CheckLogExcerpt {
_tag: "excerpt",
text: lines.join("\n"),
totalLines: this.totalLines,
truncated: this.clipped || lines.length < this.totalLines,
truncated: this.clipped || lines.length < this.totalLines - this.noiseLines,
};
}
}
Expand Down
58 changes: 53 additions & 5 deletions packages/source-control-github/src/server/GitHubRest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,35 @@ describe("GitHub check failures", () => {
check_run_url: "https://api.github.com/repos/acme/web/check-runs/123",
steps: [{ name: "Run lint", conclusion: "failure" }],
};
const exitOneAnnotation = {
path: ".github",
start_line: 0,
annotation_level: "failure",
message: "Process completed with exit code 1.",
};

it.effect("sees the signed log redirect itself and follows it without Authorization", () => {
const { layer, calls, fetch } = fetchHarness((url) => {
if (url.includes("/annotations"))
return json([
{
path: ".github",
start_line: 0,
annotation_level: "failure",
message: "Process completed with exit code 1.",
},
{
path: ".github",
start_line: 0,
annotation_level: "failure",
message: "Process completed with exit code 137.",
},
{
path: ".github/workflows/ci.yml",
start_line: 0,
annotation_level: "failure",
message: "Process completed with exit code 1.",
},
{ path: "a.ts", start_line: 4, annotation_level: "failure", message: "bad code" },
{ path: "budget.json", start_line: 0, annotation_level: "failure", message: "grew" },
]);
Expand All @@ -736,7 +760,9 @@ describe("GitHub check failures", () => {
headers: { location: "https://blob.example/log?signature=secret" },
});
if (url.startsWith("https://blob.example/"))
return new Response("2026-10-30T12:00:00Z ##[error]bad code\n");
return new Response(
"2026-10-30T12:00:00Z ##[error]bad code\n##[error]Process completed with exit code 1.\n",
);
return json(job);
});
return Effect.gen(function* () {
Expand All @@ -746,10 +772,16 @@ describe("GitHub check failures", () => {
attempt: 1,
failedSteps: ["Run lint"],
annotations: [
{ path: ".github", startLine: 0, message: "Process completed with exit code 137." },
{ path: "a.ts", startLine: 4, message: "bad code" },
{ path: "budget.json", startLine: 0, message: "grew" },
],
log: { _tag: "excerpt", text: "##[error]bad code", totalLines: 1, truncated: false },
log: {
_tag: "excerpt",
text: "##[error]bad code\n##[error]Process completed with exit code 1.",
totalLines: 2,
truncated: false,
},
});
expect(result).not.toHaveProperty("required");
const authorization = (call: (typeof calls)[number]) =>
Expand All @@ -770,7 +802,7 @@ describe("GitHub check failures", () => {
it.effect("reads an untouched job from an earlier attempt after a rerun", () => {
const { layer } = harness((request) =>
request.url.includes("/annotations")
? json([])
? json([exitOneAnnotation])
: request.url.endsWith("/logs")
? new Response("##[error]bad code\n")
: json(job),
Expand All @@ -783,6 +815,9 @@ describe("GitHub check failures", () => {
});
expect(result).toMatchObject({
attempt: 1,
annotations: [
{ path: ".github", startLine: 0, message: "Process completed with exit code 1." },
],
log: { _tag: "excerpt", text: "##[error]bad code" },
});
}).pipe(Effect.provide(layer));
Expand Down Expand Up @@ -816,14 +851,27 @@ describe("GitHub check failures", () => {
])("returns $reason for $name without extra reads", (test) => {
const { layer, requests } = harness((request) =>
request.url.includes("/annotations")
? json([])
? json([exitOneAnnotation])
: request.url.endsWith("/logs")
? json({ message: "Unavailable" }, { status: test.logStatus })
: json(test.job),
);
return Effect.gen(function* () {
const read = yield* makeGitHubCheckFailureReader;
expect((yield* read(input)).log).toEqual({ _tag: "unavailable", reason: test.reason });
const result = yield* read(input);
expect(result.log).toEqual({ _tag: "unavailable", reason: test.reason });
expect(result.annotations).toEqual(
test.requests === 3
? [
{
path: ".github",
startLine: 0,
level: "failure",
message: exitOneAnnotation.message,
},
]
: [],
);
expect(requests).toHaveLength(test.requests);
}).pipe(Effect.provide(layer));
});
Expand Down
21 changes: 15 additions & 6 deletions packages/source-control-github/src/server/gitHubCheckFailures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,21 @@ export const makeGitHubCheckFailureReader = Effect.gen(function* () {
status: JOB_CONCLUSIONS[job.conclusion ?? ""] ?? "neutral",
attempt: job.run_attempt,
failedSteps: failedSteps.slice(0, 20).map((name) => name.slice(0, 300)),
annotations: annotations.slice(0, 20).map((annotation) => ({
path: annotation.path.slice(0, 1024),
startLine: annotation.start_line,
level: annotation.annotation_level,
message: annotation.message.slice(0, 300),
})),
annotations: annotations
.filter(
// Only drop exit 1 when the delivered excerpt already contains it.
(annotation) =>
annotation.message !== "Process completed with exit code 1." ||
log._tag !== "excerpt" ||
!log.text.includes(annotation.message),
)
.slice(0, 20)
.map((annotation) => ({
path: annotation.path.slice(0, 1024),
startLine: annotation.start_line,
level: annotation.annotation_level,
message: annotation.message.slice(0, 300),
})),
log,
} satisfies PullRequestCheckFailure;
});
Expand Down
Loading