@chapterdev/mcp-dev-studio 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/agent/loop-skill.js +52 -5
- package/dist/agent/runner.js +10 -5
- package/dist/cli.js +51 -19
- package/dist/server/app.js +32 -2
- package/dist/server/listen.js +12 -0
- package/dist/ui/assets/index-D9hmZSmq.js +55 -0
- package/dist/ui/assets/index-G_SSBQNV.css +2 -0
- package/dist/ui/index.html +2 -2
- package/package.json +3 -3
- package/dist/ui/assets/index-89JVDkhA.css +0 -2
- package/dist/ui/assets/index-DWc84XNR.js +0 -54
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ MCP Dev Studio lets you:
|
|
|
9
9
|
1. **Test your MCP locally:** see if agents call the right tool and load the right skill.
|
|
10
10
|
2. **Run evals:** repeat every test in Claude Code and Codex and get a pass rate.
|
|
11
11
|
3. **Compare models:** one prompt, several agents and models, answers side by side.
|
|
12
|
-
4. **Auto-fix with your agent:** it
|
|
12
|
+
4. **Auto-fix with your agent:** it writes tests aimed at your weak spots, then fixes your tool descriptions and skills until they pass.
|
|
13
13
|
|
|
14
14
|

|
|
15
15
|
|
package/dist/agent/loop-skill.js
CHANGED
|
@@ -1,25 +1,55 @@
|
|
|
1
1
|
// The skill that teaches a coding agent (Claude Code, Codex) to iterate on an
|
|
2
2
|
// MCP server and its skills with mcp-dev-studio, while a person watches in the UI.
|
|
3
|
-
// `mcp-dev-studio
|
|
3
|
+
// `mcp-dev-studio setup` writes it into the project, stamped with the version that wrote it,
|
|
4
|
+
// so `eval` can tell people (and their agents) when an upgrade brought a newer one.
|
|
5
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
export const SKILL_DIRS = ['.claude/skills/mcp-dev-studio', '.agents/skills/mcp-dev-studio'];
|
|
4
8
|
export function loopSkill(p) {
|
|
5
9
|
return `---
|
|
6
10
|
name: mcp-dev-studio
|
|
7
11
|
description: Improve an MCP server's tool descriptions or its SKILL.md files by testing them in real agents (Claude Code, Codex) with mcp-dev-studio, then changing one thing at a time until the tests pass. Use when asked to fix, tune or test how agents use this MCP server or its skills, or why a skill does or doesn't load.
|
|
8
12
|
---
|
|
9
|
-
|
|
13
|
+
${p.version ? `\n<!-- Written by mcp-dev-studio ${p.version}. Update with: npx @chapterdev/mcp-dev-studio setup -->\n` : ''}
|
|
10
14
|
# Iterating with mcp-dev-studio
|
|
11
15
|
|
|
12
16
|
mcp-dev-studio runs saved tests against ${p.server} in real Claude Code and Codex, several times each, and records every run as an attempt. The person you're working with may have the studio open (\`npx @chapterdev/mcp-dev-studio\`); it shows each run live and the history of attempts, so leave notes that read well there.
|
|
13
17
|
|
|
18
|
+
## Start by understanding what they want
|
|
19
|
+
|
|
20
|
+
This skill can test and tune a whole server, but that's rarely the job. Begin as a collaborator, not a machine working through a checklist — ask what they're trying to do, then confirm a few things, and wait for the answers:
|
|
21
|
+
|
|
22
|
+
- **What are you trying to do?** A specific tool or skill that's misbehaving, a new one to check before it ships, a case that went wrong, or a general once-over? Scope the work to that. One flaky tool isn't a reason to rewrite every description.
|
|
23
|
+
- **Which server?** Test a **local or development** server. Never point tests at a production URL, and never read, reuse, or forge credentials to reach one (no secrets from the environment, keychains, or a cloud project). If the only server you can reach is production, stop and ask them to start a local one.
|
|
24
|
+
- **Read-only, or may tests change data?** By default, hide every tool that spends money, sends messages, or creates, changes, or deletes data (set \`hidden\` in the overrides), and tell them which you hid. Test a write tool only once they confirm the target is safe to change.
|
|
25
|
+
- **Watch it live?** Offer to open the studio so they can follow along: \`npx @chapterdev/mcp-dev-studio open\`. It opens the UI for this folder (starting it if needed) and returns, so you can keep working.
|
|
26
|
+
|
|
27
|
+
Keep it a conversation: say what you find, and check in before big or broad changes rather than reworking everything at once.
|
|
28
|
+
|
|
29
|
+
## Write tests that can fail
|
|
30
|
+
|
|
31
|
+
The loop only finds what the tests probe, and happy-path tests usually pass. For the tools and skills behind what they asked about, read the descriptions and parameters and list the weak spots you see, then write at least one test aimed at each. Note weak spots outside that scope, but raise them rather than fixing everything unasked.
|
|
32
|
+
|
|
33
|
+
- **Vague or missing parameter descriptions**: ask the way a person would, not the way the schema wants. If a parameter takes an id but doesn't say so, ask to act on the item by its name.
|
|
34
|
+
- **Bare tool descriptions**: a prompt that needs what the description leaves out, like allowed values or formats.
|
|
35
|
+
- **Overlapping tools**: a prompt only one of them should handle, with \`forbidTools\` for the other.
|
|
36
|
+
- **Over-broad or vague skill descriptions**: a should-load test (\`expectSkills\`) and a shouldn't-load test (\`forbidSkills\`) on a nearby but unrelated prompt.
|
|
37
|
+
|
|
38
|
+
Make the checks strict enough to catch the agent working around the flaw. A capable agent recovers from a failed call with extra lookups and still gets there, so set \`maxToolCalls\` to what a clear description would need, or have \`judge\` require no failed tool calls.
|
|
39
|
+
|
|
40
|
+
Test in the agent you're running in — you're Claude Code or Codex, so use that one (\`--host claude-code\` or \`--host codex\`). Don't ask which; the person can ask you to compare others.
|
|
41
|
+
|
|
14
42
|
## The loop
|
|
15
43
|
|
|
16
|
-
1. **Baseline.** \`npx @chapterdev/mcp-dev-studio eval --json --host
|
|
44
|
+
1. **Baseline.** \`npx @chapterdev/mcp-dev-studio eval --json --host <the agent you're in> --note "baseline"\` (add other agents only if they ask)
|
|
17
45
|
2. **Read why it failed.** In the JSON, each failing test has \`failures\` (check, detail, how many runs) and \`transcripts\`. Open a transcript before guessing: \`events\` shows every tool call and what the agent said.
|
|
18
46
|
3. **Change one thing** that explains the failure (see "What to change").
|
|
19
47
|
4. **Rerun what failed**, saying what you changed: \`npx @chapterdev/mcp-dev-studio eval --json --failed --host <same hosts> --note "<the change, in a few words>"\`. \`sinceLastAttempt.tests\` says which tests were fixed or broke.
|
|
20
48
|
5. **Check for regressions** with a full run once the failures pass. A change that fixes one test and breaks another isn't done.
|
|
21
49
|
6. **Keep or revert.** If an attempt made things worse, undo the change before trying the next idea.
|
|
22
|
-
7. **Stop** when everything passes
|
|
50
|
+
7. **Stop** when everything passes, or after about five attempts without progress. Then say what you changed, what each attempt showed, and what's still failing.
|
|
51
|
+
|
|
52
|
+
A suite that passes on its first run hasn't found anything yet. Before calling it done, check the transcripts for workarounds (failed calls, extra lookups, guessed values), add harder tests for the weak spots you listed, and run again. If a weak spot still won't fail, say so rather than leaving it out.
|
|
23
53
|
|
|
24
54
|
Agents vary, so results are rates. Explore with \`--trials 1\` and confirm with the default (3) before calling something fixed. Every run is real agent time; rerun only what you need.
|
|
25
55
|
|
|
@@ -32,7 +62,7 @@ Agents vary, so results are rates. Explore with \`--trials 1\` and confirm with
|
|
|
32
62
|
|
|
33
63
|
## Tests
|
|
34
64
|
|
|
35
|
-
Tests are JSON files in \`${p.tests}/\`. Add one when the person describes behaviour no test covers:
|
|
65
|
+
Tests are JSON files in \`${p.tests}/\`. Add one for each weak spot (see above), and when the person describes behaviour no test covers:
|
|
36
66
|
|
|
37
67
|
\`\`\`json
|
|
38
68
|
{
|
|
@@ -64,4 +94,21 @@ Run one test with \`--journey <part of its slug or name>\`.
|
|
|
64
94
|
Tests call the real server. If a tool changes real data (creates, sends, deletes), hide it in \`${p.store}/overrides.json\` with \`{ "tool_name": { "hidden": true } }\` unless the test is about that tool, and say so before running.
|
|
65
95
|
`;
|
|
66
96
|
}
|
|
97
|
+
/** Installed copies of the loop skill written by an older version (or before versions were stamped). */
|
|
98
|
+
export function outdatedSkills(project, version) {
|
|
99
|
+
const older = (a, b) => {
|
|
100
|
+
const [x, y] = [a, b].map((v) => v.split(/[.-]/).slice(0, 3).map(Number));
|
|
101
|
+
for (let i = 0; i < 3; i++)
|
|
102
|
+
if (x[i] !== y[i])
|
|
103
|
+
return (x[i] ?? 0) < (y[i] ?? 0);
|
|
104
|
+
return false;
|
|
105
|
+
};
|
|
106
|
+
return SKILL_DIRS.map((d) => join(d, 'SKILL.md')).filter((f) => {
|
|
107
|
+
const path = join(project, f);
|
|
108
|
+
if (!existsSync(path))
|
|
109
|
+
return false;
|
|
110
|
+
const stamp = /Written by mcp-dev-studio (\d+\.\d+\.\d+)/.exec(readFileSync(path, 'utf8'))?.[1];
|
|
111
|
+
return !stamp || older(stamp, version);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
67
114
|
//# sourceMappingURL=loop-skill.js.map
|
package/dist/agent/runner.js
CHANGED
|
@@ -79,18 +79,23 @@ export function newSessionId() {
|
|
|
79
79
|
export class FlagTracker {
|
|
80
80
|
seen = new Map();
|
|
81
81
|
lastErr = new Map();
|
|
82
|
-
|
|
82
|
+
/** The same tool failing call after call. */
|
|
83
|
+
failing = { name: '', n: 0 };
|
|
83
84
|
flags(name, args, isError, text, tokens) {
|
|
84
85
|
const flags = [];
|
|
85
86
|
const key = name + JSON.stringify(args);
|
|
86
|
-
|
|
87
|
+
const times = (this.seen.get(key) ?? 0) + 1;
|
|
88
|
+
this.seen.set(key, times);
|
|
89
|
+
if (times > 1)
|
|
87
90
|
flags.push('repeat');
|
|
88
|
-
this.seen.set(key, (this.seen.get(key) ?? 0) + 1);
|
|
89
91
|
if (this.lastErr.get(name) === true)
|
|
90
92
|
flags.push('retry');
|
|
91
93
|
this.lastErr.set(name, isError);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
// Looping means stuck: the same call a third time, or a third failure in a row from
|
|
95
|
+
// one tool. Calling a tool again with new arguments (three to-dos, three customers)
|
|
96
|
+
// is normal work.
|
|
97
|
+
this.failing = !isError ? { name: '', n: 0 } : this.failing.name === name ? { name, n: this.failing.n + 1 } : { name, n: 1 };
|
|
98
|
+
if (times >= 3 || this.failing.n >= 3)
|
|
94
99
|
flags.push('loop');
|
|
95
100
|
if (tokens > 1500)
|
|
96
101
|
flags.push('bloated');
|
package/dist/cli.js
CHANGED
|
@@ -17,13 +17,14 @@ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
|
17
17
|
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
18
18
|
import { splitCommand } from './mcp/connection.js';
|
|
19
19
|
import { createApp } from './server/app.js';
|
|
20
|
+
import { listenFrom } from './server/listen.js';
|
|
20
21
|
import { runEvalCli } from './eval/cli.js';
|
|
21
22
|
import { fileSink, httpSink, recordingPipe } from './analytics/recorder.js';
|
|
22
23
|
import { DEMO_ENTRY, Workspace } from './workspace.js';
|
|
23
24
|
import { autoPick, discover } from './discover.js';
|
|
24
25
|
import { detectClaudeCode } from './hosts/claude-code.js';
|
|
25
26
|
import { detectCodex } from './hosts/codex.js';
|
|
26
|
-
import { loopSkill } from './agent/loop-skill.js';
|
|
27
|
+
import { SKILL_DIRS, loopSkill, outdatedSkills } from './agent/loop-skill.js';
|
|
27
28
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
28
29
|
const pkg = JSON.parse(readFileSync(join(here, '..', 'package.json'), 'utf8'));
|
|
29
30
|
const HELP = `mcp-dev-studio ${pkg.version} — design, test and iterate on an Agent Surface (MCP + Skills)
|
|
@@ -33,14 +34,15 @@ Usage (run with npx @chapterdev/mcp-dev-studio …)
|
|
|
33
34
|
mcp-dev-studio "node server.js" A stdio server
|
|
34
35
|
mcp-dev-studio http://localhost:3001/mcp An HTTP server (Streamable HTTP, falls back to SSE)
|
|
35
36
|
mcp-dev-studio demo Built-in messy SaaS MCP server
|
|
37
|
+
mcp-dev-studio open Open the studio for this folder (start it if needed)
|
|
36
38
|
mcp-dev-studio eval [--journey <name>] Run saved tests in real agents, print pass rates
|
|
37
39
|
mcp-dev-studio setup Teach Claude Code / Codex here to iterate with the studio
|
|
38
40
|
mcp-dev-studio proxy --stdio "<cmd>" | --url Transparent MCP proxy that records usage
|
|
39
41
|
mcp-dev-studio demo-server Run the demo server over stdio
|
|
40
42
|
|
|
41
43
|
Options
|
|
42
|
-
--skills <dir> SKILL.md folder to co-edit (default .
|
|
43
|
-
--store <dir> Data dir (default
|
|
44
|
+
--skills <dir> SKILL.md folder to co-edit (default skills/, .claude/skills or .agents/skills)
|
|
45
|
+
--store <dir> Data dir (default ~/.mcp-dev-studio/projects/<repo>)
|
|
44
46
|
--cwd <dir> Working directory for --stdio
|
|
45
47
|
--header "K: V" HTTP header for --url (repeatable)
|
|
46
48
|
--token-file <path> Read a bearer token for --url from a file (keeps it out of ps)
|
|
@@ -58,7 +60,7 @@ Options
|
|
|
58
60
|
Keys: ANTHROPIC_API_KEY / OPENAI_API_KEY, or Settings in the UI.`;
|
|
59
61
|
async function main() {
|
|
60
62
|
const argv = process.argv.slice(2);
|
|
61
|
-
const COMMANDS = ['serve', 'eval', 'proxy', 'demo-server', 'skill', 'setup'];
|
|
63
|
+
const COMMANDS = ['serve', 'eval', 'proxy', 'demo-server', 'skill', 'setup', 'open'];
|
|
62
64
|
const command = argv[0] && COMMANDS.includes(argv[0]) ? argv.shift() : 'serve';
|
|
63
65
|
const { values, positionals } = parseArgs({
|
|
64
66
|
args: argv,
|
|
@@ -100,7 +102,7 @@ async function main() {
|
|
|
100
102
|
await import('./demo/stdio.js');
|
|
101
103
|
return;
|
|
102
104
|
}
|
|
103
|
-
if (!['serve', 'eval', 'proxy', 'skill', 'setup'].includes(command)) {
|
|
105
|
+
if (!['serve', 'eval', 'proxy', 'skill', 'setup', 'open'].includes(command)) {
|
|
104
106
|
console.error(`Unknown command "${command}".\n\n${HELP}`);
|
|
105
107
|
process.exit(2);
|
|
106
108
|
}
|
|
@@ -130,10 +132,10 @@ async function main() {
|
|
|
130
132
|
if (command === 'skill' || command === 'setup') {
|
|
131
133
|
// Inside the repo: relative. In the private store: ~/… so the path reads the same for everyone.
|
|
132
134
|
const rel = (p) => (relative(project, p).startsWith('..') ? p.replace(homedir(), '~') : relative(project, p) || '.');
|
|
133
|
-
const text = loopSkill({ store: rel(ws.store.root), skills: rel(ws.skills.dir), tests: rel(ws.store.testsDir), server: ws.store.savedServer()?.name ?? 'the MCP server' });
|
|
135
|
+
const text = loopSkill({ store: rel(ws.store.root), skills: rel(ws.skills.dir), tests: rel(ws.store.testsDir), server: ws.store.savedServer()?.name ?? 'the MCP server', version: pkg.version });
|
|
134
136
|
if (values.print)
|
|
135
137
|
return void process.stdout.write(text);
|
|
136
|
-
for (const dir of
|
|
138
|
+
for (const dir of SKILL_DIRS) {
|
|
137
139
|
mkdirSync(join(project, dir), { recursive: true });
|
|
138
140
|
writeFileSync(join(project, dir, 'SKILL.md'), text);
|
|
139
141
|
console.log(` wrote ${dir}/SKILL.md`);
|
|
@@ -141,6 +143,40 @@ async function main() {
|
|
|
141
143
|
console.log(`\n Claude Code and Codex in this folder now know how to test and tune your server with mcp-dev-studio.\n Try: "test how agents use this server and fix what fails" · keep \`npx @chapterdev/mcp-dev-studio\` open to watch\n`);
|
|
142
144
|
return;
|
|
143
145
|
}
|
|
146
|
+
// ── open: make a studio for this folder appear (starting one in the background if needed) ──
|
|
147
|
+
// So an agent mid-loop can show the person the UI and keep working: this returns, the studio stays up.
|
|
148
|
+
if (command === 'open') {
|
|
149
|
+
const first = Number(values.port ?? process.env.PORT ?? 4300);
|
|
150
|
+
const studioFor = (p) => fetch(`http://127.0.0.1:${p}/api/state`, { signal: AbortSignal.timeout(800) })
|
|
151
|
+
.then((r) => r.json())
|
|
152
|
+
.then((st) => (st.project === project ? p : undefined))
|
|
153
|
+
.catch(() => undefined);
|
|
154
|
+
const find = async () => {
|
|
155
|
+
for (let p = first; p < first + 20; p++) {
|
|
156
|
+
const hit = await studioFor(p);
|
|
157
|
+
if (hit)
|
|
158
|
+
return hit;
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
};
|
|
162
|
+
let port = await find();
|
|
163
|
+
if (!port) {
|
|
164
|
+
// Start `serve` detached; it outlives this command. Pass through the same connection flags.
|
|
165
|
+
spawn(process.execPath, [process.argv[1], 'serve', ...argv.filter((a) => a !== '--no-open'), '--no-open'], { stdio: 'ignore', detached: true }).on('error', () => { }).unref();
|
|
166
|
+
for (let i = 0; i < 40 && !port; i++) {
|
|
167
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
168
|
+
port = await find();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (!port) {
|
|
172
|
+
console.error('\n Could not start the studio. Run `npx @chapterdev/mcp-dev-studio` yourself to see why.\n');
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
const openUrl = `http://localhost:${port}`;
|
|
176
|
+
console.log(`\n Studio open for this folder.\n\n → ${openUrl}\n`);
|
|
177
|
+
openBrowser(openUrl);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
144
180
|
/** What to connect to without asking, and why (for the startup banner). */
|
|
145
181
|
const choose = async () => {
|
|
146
182
|
if (demo)
|
|
@@ -149,7 +185,7 @@ async function main() {
|
|
|
149
185
|
return { choice: { target: explicit, save: command === 'serve' }, why: 'from the command line', found: 0 };
|
|
150
186
|
const saved = ws.store.savedServer();
|
|
151
187
|
if (saved)
|
|
152
|
-
return { choice: saved, why: '
|
|
188
|
+
return { choice: saved, why: 'the server you picked last time', found: 0 };
|
|
153
189
|
const list = await discover(project);
|
|
154
190
|
const pick = autoPick(list);
|
|
155
191
|
return pick ? { choice: { name: pick.name, target: pick.target, start: pick.start, save: true }, why: `found in ${pick.from}`, found: list.length } : { why: '', found: list.length };
|
|
@@ -195,6 +231,10 @@ async function main() {
|
|
|
195
231
|
await ws.close();
|
|
196
232
|
process.exit(2);
|
|
197
233
|
}
|
|
234
|
+
// Agents read this too, so an upgrade's better instructions reach them.
|
|
235
|
+
const stale = outdatedSkills(project, pkg.version);
|
|
236
|
+
if (stale.length)
|
|
237
|
+
console.error(`Note: the mcp-dev-studio skill in ${stale.join(' and ')} is from an older version. Run \`npx @chapterdev/mcp-dev-studio setup\` to update it.`);
|
|
198
238
|
const code = await runEvalCli({ conn: ws.conn, store: ws.store, skills: ws.skills, filter: values.journey, json: values.json, trials: values.trials ? Number(values.trials) : undefined, failed: values.failed, note: values.note, hosts: values.host ? values.host.split(',').map((h) => h.trim()).filter(Boolean) : undefined });
|
|
199
239
|
await ws.close();
|
|
200
240
|
process.exit(code);
|
|
@@ -211,20 +251,12 @@ async function main() {
|
|
|
211
251
|
return;
|
|
212
252
|
}
|
|
213
253
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
for (; port < first + 20; port++) {
|
|
217
|
-
const app = createApp({ workspace: ws, uiDir: join(here, 'ui'), version: pkg.version, ingestUrl: `http://127.0.0.1:${port}/api/ingest` });
|
|
218
|
-
server = await new Promise((ok) => {
|
|
219
|
-
const s = app.listen(port, '127.0.0.1', () => ok(s)).once('error', () => ok(undefined));
|
|
220
|
-
});
|
|
221
|
-
if (server)
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
if (!server) {
|
|
254
|
+
const started = await listenFrom((port) => createApp({ workspace: ws, uiDir: join(here, 'ui'), version: pkg.version, ingestUrl: `http://127.0.0.1:${port}/api/ingest` }), first);
|
|
255
|
+
if (!started) {
|
|
225
256
|
console.error(`Ports ${first}–${first + 19} are all in use. Pass --port <n>.`);
|
|
226
257
|
process.exit(2);
|
|
227
258
|
}
|
|
259
|
+
const { server, port } = started;
|
|
228
260
|
const url = `http://localhost:${port}`;
|
|
229
261
|
const shutdown = async () => {
|
|
230
262
|
server.close();
|
package/dist/server/app.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// The studio's local HTTP API (+ the built UI). Bound to 127.0.0.1 only.
|
|
2
2
|
import express from 'express';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
5
|
+
import { join, relative } from 'node:path';
|
|
5
6
|
import { autoPick, discover } from '../discover.js';
|
|
6
7
|
import { watchStore } from '../store-watch.js';
|
|
7
8
|
import { modelOptions } from '../hosts/models.js';
|
|
@@ -451,6 +452,35 @@ export function createApp({ workspace: ws, uiDir, version, ingestUrl, sessionFac
|
|
|
451
452
|
res.end();
|
|
452
453
|
}));
|
|
453
454
|
// Tests are private by default; sharing moves them into the repo so teammates get them.
|
|
455
|
+
// What sharing would do, for the confirm dialog: which files, and what git will make of them.
|
|
456
|
+
app.get('/api/tests/share', (_req, res) => {
|
|
457
|
+
const git = (...args) => {
|
|
458
|
+
try {
|
|
459
|
+
return { ok: true, out: execFileSync('git', args, { cwd: ws.project, stdio: ['ignore', 'pipe', 'ignore'] }).toString() };
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
return { ok: false, out: '' };
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
const dir = ws.sharedTestsDir;
|
|
466
|
+
const inRepo = git('rev-parse', '--is-inside-work-tree').ok;
|
|
467
|
+
let files = [];
|
|
468
|
+
try {
|
|
469
|
+
files = readdirSync(store.testsDir).filter((f) => f.endsWith('.json')).sort();
|
|
470
|
+
}
|
|
471
|
+
catch {
|
|
472
|
+
/* no tests yet */
|
|
473
|
+
}
|
|
474
|
+
res.json({
|
|
475
|
+
shared: store.testsShared,
|
|
476
|
+
dir: relative(ws.project, dir),
|
|
477
|
+
files,
|
|
478
|
+
inRepo,
|
|
479
|
+
// check-ignore exits 0 when the path is ignored.
|
|
480
|
+
ignored: inRepo && git('check-ignore', '-q', join(dir, 'x.json')).ok,
|
|
481
|
+
uncommitted: inRepo && store.testsShared && git('status', '--porcelain', '--', dir).out.trim().length > 0,
|
|
482
|
+
});
|
|
483
|
+
});
|
|
454
484
|
app.post('/api/tests/share', (req, res) => {
|
|
455
485
|
if (ws.demo)
|
|
456
486
|
return void res.status(400).json({ error: 'The demo has no repo to share tests in' });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export async function listenFrom(make, first, tries = 20) {
|
|
2
|
+
for (let port = first; port < first + tries; port++) {
|
|
3
|
+
// Express 5 calls listen's callback on errors too (a busy port included), so check for one.
|
|
4
|
+
const server = await new Promise((ok) => {
|
|
5
|
+
const s = make(port).listen(port, '127.0.0.1', (err) => ok(err ? undefined : s));
|
|
6
|
+
});
|
|
7
|
+
if (server)
|
|
8
|
+
return { server, port };
|
|
9
|
+
}
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=listen.js.map
|