Skip to content

Commit 84ec81d

Browse files
fix(rstack): skip unconfigured Rstest captures
1 parent 13f2607 commit 84ec81d

5 files changed

Lines changed: 68 additions & 12 deletions

File tree

packages/rstack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@rsbuild/core": "catalog:",
8282
"@rslib/core": "catalog:",
8383
"@rslint/core": "catalog:",
84-
"@rstackjs/context": "git+https://github.com/rstackjs/context.git#6c992fac8c8e2b22a1a66f8f0d9a954437649bf7",
84+
"@rstackjs/context": "git+https://github.com/rstackjs/context.git#f2408b0497a0ee56ce0a9c72fa2603beb8375b42",
8585
"@rstest/core": "catalog:",
8686
"prettier": "catalog:",
8787
"tinypool": "catalog:",

packages/rstack/src/mcp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
createContextMcpServer,
99
resolveContextWorkspace,
1010
} from '@rstackjs/context';
11-
import { withRstackConfigTarget } from './config.ts';
11+
import { loadRstackConfig, withRstackConfigTarget } from './config.ts';
1212
import { resolveRelatedTests } from './relatedTests.ts';
1313

1414
declare const RSTACK_VERSION: string;
@@ -47,6 +47,11 @@ const runContextMcpServer = async (startPath: string): Promise<void> => {
4747
wrapperConfigPath: path.join(import.meta.dirname, 'rstestConfig.js'),
4848
withConfigTarget: withRstackConfigTarget,
4949
resolveRelatedTests,
50+
isTestConfigured: ({ packageRoot, configPath }) =>
51+
withRstackConfigTarget(packageRoot, configPath, async () => {
52+
const { configs } = await loadRstackConfig();
53+
return configs.test !== undefined;
54+
}),
5055
}),
5156
});
5257

packages/rstack/tests/context/mcp.test.ts

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ test('reads the current store for every project status call without workspace pa
10911091
expect(firstResult.content).toEqual([
10921092
{
10931093
type: 'text',
1094-
text: 'Rstack project status: 1 current context (0 ready, 1 pending); 0 context-store/read issues. See structuredContent for details.',
1094+
text: 'Rstack project status: 1 recorded context identity (0 ready, 1 pending); 0 context-store/read issues. See structuredContent for compact selection details.',
10951095
},
10961096
]);
10971097

@@ -1111,7 +1111,14 @@ test('reads the current store for every project status call without workspace pa
11111111
producer: run.producer,
11121112
context,
11131113
state: 'ready',
1114-
latestSnapshot: snapshot,
1114+
latestSnapshot: {
1115+
snapshotId: snapshot.snapshotId,
1116+
observedAt: snapshot.observedAt,
1117+
status: snapshot.status,
1118+
completeness: snapshot.completeness,
1119+
facets: ['summary'],
1120+
summary: {},
1121+
},
11151122
freshness: { state: 'unknown', changedPaths: [] },
11161123
},
11171124
],
@@ -1120,7 +1127,7 @@ test('reads the current store for every project status call without workspace pa
11201127
expect(secondResult.content).toEqual([
11211128
{
11221129
type: 'text',
1123-
text: 'Rstack project status: 1 current context (1 ready, 0 pending); 0 context-store/read issues. See structuredContent for details.',
1130+
text: 'Rstack project status: 1 recorded context identity (1 ready, 0 pending); 0 context-store/read issues. See structuredContent for compact selection details.',
11241131
},
11251132
]);
11261133
});
@@ -1144,7 +1151,7 @@ test('returns a valid empty project status', async () => {
11441151
expect(result.content).toEqual([
11451152
{
11461153
type: 'text',
1147-
text: 'Rstack project status: 0 current contexts (0 ready, 0 pending); 0 context-store/read issues. See structuredContent for details.',
1154+
text: 'Rstack project status: 0 recorded context identities (0 ready, 0 pending); 0 context-store/read issues. See structuredContent for compact selection details.',
11481155
},
11491156
]);
11501157
});
@@ -1793,6 +1800,50 @@ define.test({ include: ['./tests/*.never.ts'], passWithNoTests: ${fixture.testSt
17931800
});
17941801
});
17951802

1803+
test('does not capture tests when the selected Rstack package has no test config', async () => {
1804+
await withTempWorkspace(async (workspaceRoot) => {
1805+
const rstackEntry = pathToFileURL(path.resolve('dist/index.js')).href;
1806+
await writeFile(
1807+
path.join(workspaceRoot, 'package.json'),
1808+
JSON.stringify({ name: '@repo/app', type: 'module' }),
1809+
);
1810+
await writeFile(
1811+
path.join(workspaceRoot, 'rstack.config.ts'),
1812+
`import { define } from ${JSON.stringify(rstackEntry)};
1813+
define.app({});
1814+
`,
1815+
);
1816+
1817+
const transport = new StdioClientTransport({
1818+
command: process.execPath,
1819+
args: [path.resolve('bin/rs.js'), 'mcp'],
1820+
cwd: workspaceRoot,
1821+
env: getDefaultEnvironment(),
1822+
stderr: 'pipe',
1823+
});
1824+
const client = new Client({
1825+
name: 'rstack-unconfigured-test-capture',
1826+
version: '1.0.0',
1827+
});
1828+
1829+
try {
1830+
await client.connect(transport);
1831+
const result = await client.callTool({ name: 'test_snapshot', arguments: {} });
1832+
1833+
expect(result.isError).toBe(true);
1834+
expect(result.content).toEqual([
1835+
{
1836+
type: 'text',
1837+
text: 'Rstest is not configured for package root ".".',
1838+
},
1839+
]);
1840+
expect((await readProjectStatus(workspaceRoot)).contexts).toEqual([]);
1841+
} finally {
1842+
await client.close();
1843+
}
1844+
});
1845+
});
1846+
17961847
test('rejects unexpected fields at every Phase 3/4 MCP input boundary', async () => {
17971848
await withTempWorkspace(async (workspaceRoot) => {
17981849
await withMcpClient(workspaceRoot, async (client) => {

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ packages:
44
- website
55

66
allowBuilds:
7-
'@rstackjs/context@https://codeload.github.com/rstackjs/context/tar.gz/6c992fac8c8e2b22a1a66f8f0d9a954437649bf7': true
7+
'@rstackjs/context@https://codeload.github.com/rstackjs/context/tar.gz/f2408b0497a0ee56ce0a9c72fa2603beb8375b42': true
88
core-js: false
99
simple-git-hooks: false
1010

0 commit comments

Comments
 (0)