Skip to content

Commit e638097

Browse files
authored
fix: keep test progress visible in agent runs (#131448)
1 parent 8a60896 commit e638097

5 files changed

Lines changed: 107 additions & 2 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { describe, expect, it } from "vitest";
2+
import { spawnNodeEvalSync } from "../src/test-utils/node-process.js";
3+
import { DEFAULT_VITEST_TEST_TIMEOUT_MS } from "./vitest/vitest.timeouts.ts";
4+
5+
const reporterConfigs = [
6+
"vitest.config.ts",
7+
"test/vitest/vitest.cli-process.config.ts",
8+
"test/vitest/vitest.ui.config.ts",
9+
"test/vitest/vitest.ui-e2e.config.ts",
10+
"test/vitest/vitest.e2e.config.ts",
11+
"ui/vitest.config.ts",
12+
"ui/vitest.node.config.ts",
13+
];
14+
15+
type ReporterEntry = [string, Record<string, unknown>];
16+
type ReporterResolution = {
17+
defaults: Array<{ config: string; reporters: ReporterEntry[]; cli: ReporterEntry[] }>;
18+
custom: ReporterEntry[];
19+
customCli: ReporterEntry[];
20+
injectedPty: ReporterEntry[];
21+
};
22+
23+
describe("Vitest reporter contracts", () => {
24+
it.each(["false", "true"])(
25+
"reports completed agent tests and preserves overrides with GITHUB_ACTIONS=%s",
26+
(githubActions) => {
27+
// Resolve in a fresh process: shared config and std-env capture their environment on import.
28+
// This starts no test workers and leaves the enclosing Vitest module/cache ownership alone.
29+
const result = spawnNodeEvalSync(
30+
`
31+
import path from "node:path";
32+
import { parseCLI, resolveConfig } from "vitest/node";
33+
import { sharedVitestConfig } from "./test/vitest/vitest.shared.config.ts";
34+
import { createTuiPtyVitestConfig } from "./test/vitest/vitest.tui-pty.config.ts";
35+
const defaults = [];
36+
for (const config of ${JSON.stringify(reporterConfigs)}) {
37+
const root = config.startsWith("ui/") ? path.resolve("ui") : process.cwd();
38+
const options = { root, config: path.resolve(config) };
39+
const normal = await resolveConfig(options);
40+
const cli = parseCLI(["vitest", "--reporter=json"]).options;
41+
const override = await resolveConfig({ ...cli, ...options });
42+
defaults.push({ config, reporters: normal.vitestConfig.reporters, cli: override.vitestConfig.reporters });
43+
}
44+
const customConfig = {
45+
...sharedVitestConfig,
46+
test: {
47+
...sharedVitestConfig.test,
48+
reporters: [["json", { outputFile: "custom-report.json" }]],
49+
},
50+
};
51+
const custom = await resolveConfig({ config: false }, customConfig);
52+
const customCli = await resolveConfig({
53+
...parseCLI(["vitest", "--reporter=json", "--reporter=json"]).options,
54+
config: false,
55+
}, customConfig);
56+
const injectedPty = await resolveConfig({ config: false }, createTuiPtyVitestConfig({
57+
GITHUB_ACTIONS: process.env.GITHUB_ACTIONS === "true" ? "false" : "true",
58+
}));
59+
console.log("REPORTER_RESOLUTION " + JSON.stringify({
60+
defaults,
61+
custom: custom.vitestConfig.reporters,
62+
customCli: customCli.vitestConfig.reporters,
63+
injectedPty: injectedPty.vitestConfig.reporters,
64+
}));
65+
`,
66+
{
67+
imports: ["tsx"],
68+
env: { ...process.env, AI_AGENT: "vitest-reporter-test", GITHUB_ACTIONS: githubActions },
69+
timeout: DEFAULT_VITEST_TEST_TIMEOUT_MS,
70+
},
71+
);
72+
expect(result.error, result.stderr).toBeUndefined();
73+
expect(result.signal, result.stderr).toBeNull();
74+
expect(result.status, result.stderr).toBe(0);
75+
const report = result.stdout
76+
.split("\n")
77+
.find((line) => line.startsWith("REPORTER_RESOLUTION "));
78+
expect(report, result.stdout).toBeDefined();
79+
const resolved = JSON.parse(
80+
report!.slice("REPORTER_RESOLUTION ".length),
81+
) as ReporterResolution;
82+
const expected = githubActions === "true" ? ["verbose", "github-actions"] : ["verbose"];
83+
for (const { config, reporters, cli } of resolved.defaults) {
84+
expect(
85+
reporters.map(([name]) => name),
86+
config,
87+
).toEqual(expected);
88+
expect(cli, `${config} CLI override`).toEqual([["json", {}]]);
89+
}
90+
expect(resolved.defaults).toHaveLength(reporterConfigs.length);
91+
expect(resolved.custom).toEqual([["json", { outputFile: "custom-report.json" }]]);
92+
expect(resolved.customCli).toEqual(resolved.custom);
93+
expect(resolved.injectedPty.map(([name]) => name)).toEqual(
94+
githubActions === "true" ? ["verbose"] : ["verbose", "github-actions"],
95+
);
96+
},
97+
);
98+
});

‎test/vitest/vitest.e2e.config.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export function createE2EVitestConfig(env: Record<string, string | undefined> =
3636
test: {
3737
...baseTest,
3838
maxWorkers: e2eWorkers,
39-
reporters: ["verbose"],
4039
silent: !verboseE2E,
4140
globalSetup: [resolveRepoRootPath("test/vitest/vitest.e2e.global-setup.ts")],
4241
setupFiles: [

‎test/vitest/vitest.shared.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ export const sharedVitestConfig = {
469469
},
470470
test: {
471471
dir: repoRoot,
472+
// Emit completed cases even under agent detection so healthy runs feed the output watchdog.
473+
reporters: ["verbose", ...(process.env.GITHUB_ACTIONS === "true" ? ["github-actions"] : [])],
472474
testTimeout: DEFAULT_VITEST_TEST_TIMEOUT_MS,
473475
// 180s on every platform: GitHub-hosted 4-core fallback runners (Blacksmith
474476
// outage breaker) push e2e beforeAll hooks past 120s; Windows always needed it.

‎ui/vitest.config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
jsdomOptimizedDeps,
1111
nonIsolatedRunnerPath,
1212
resolveDefaultVitestPool,
13+
sharedVitestConfig,
1314
} from "../test/vitest/vitest.shared.config.ts";
1415
import { uiIsolatedTestFiles } from "../test/vitest/vitest.ui-isolated-paths.mjs";
1516
import { controlUiLocaleModulesPlugin } from "./config/control-ui-locales.ts";
@@ -152,6 +153,7 @@ export default defineConfig({
152153
},
153154
test: {
154155
...sharedUiTestConfig,
156+
reporters: sharedVitestConfig.test.reporters,
155157
projects: [
156158
defineProject({
157159
plugins: [controlUiLocaleModulesPlugin()],

‎ui/vitest.node.config.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
// Control UI config module wires vitest behavior.
22
import { defineConfig } from "vitest/config";
3-
import { resolveDefaultVitestPool } from "../test/vitest/vitest.shared.config.ts";
3+
import {
4+
resolveDefaultVitestPool,
5+
sharedVitestConfig,
6+
} from "../test/vitest/vitest.shared.config.ts";
47
import { controlUiLocaleModulesPlugin } from "./config/control-ui-locales.ts";
58

69
// Node-only tests for pure logic (no Playwright/browser dependency).
710
export default defineConfig({
811
plugins: [controlUiLocaleModulesPlugin()],
912
test: {
13+
reporters: sharedVitestConfig.test.reporters,
1014
isolate: false,
1115
pool: resolveDefaultVitestPool(),
1216
testTimeout: 120_000,

0 commit comments

Comments
 (0)