@multiplatform.one/cli 8.0.0 → 8.1.0
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 +12 -6
- package/lib/commands/e2e.mjs +6 -15
- package/lib/commands/scaffold.mjs +62 -3
- package/lib/commands/verbs.mjs +31 -10
- package/lib/source.json +2 -2
- package/package.json +2 -2
- package/scripts/scaffold.sh +12 -0
- package/src/bin/multiplatformOne.ts +2 -2
- package/src/commands/e2e.ts +16 -21
- package/src/commands/scaffold.ts +60 -3
- package/src/commands/updateCleanups.spec.ts +282 -0
- package/src/commands/verbs.spec.ts +94 -5
- package/src/commands/verbs.ts +33 -12
- package/types/commands/e2e.d.ts +1 -1
- package/types/commands/e2e.d.ts.map +1 -1
- package/types/commands/scaffold.d.ts +1 -1
- package/types/commands/scaffold.d.ts.map +1 -1
- package/types/commands/verbs.d.ts +2 -2
- package/types/commands/verbs.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -94,11 +94,16 @@ git add -A && git commit -m "chore: mpo update <old> → <new>"
|
|
|
94
94
|
|
|
95
95
|
A three-way merge: **base** is the scaffold at the commit recorded in
|
|
96
96
|
`.mpo.json` with the recorded apps and services, **ours** is your `HEAD`,
|
|
97
|
-
**theirs** is
|
|
98
|
-
`--source`/`--checkout`). Your commits are preserved, the
|
|
99
|
-
land as the diff, every product app receives the One
|
|
100
|
-
nothing is committed. Conflicts land with normal markers;
|
|
101
|
-
on a clean merge (`--skip-install` to skip it).
|
|
97
|
+
**theirs** is that selection scaffolded at the commit this CLI was built
|
|
98
|
+
from (or `--source`/`--checkout`). Your commits are preserved, the
|
|
99
|
+
monorepo's changes land as the diff, every product app receives the One
|
|
100
|
+
app's changes, and nothing is committed. Conflicts land with normal markers;
|
|
101
|
+
`pnpm install` runs on a clean merge (`--skip-install` to skip it).
|
|
102
|
+
|
|
103
|
+
Each side runs the `scaffold.sh` its own commit carries, so whatever the
|
|
104
|
+
scaffold changed since your recorded commit lands too: a root rule it now
|
|
105
|
+
drops is removed from your project. If you edited those lines, the file
|
|
106
|
+
conflicts instead.
|
|
102
107
|
|
|
103
108
|
`.updateignore` entries (exact files or directory prefixes, not globs) and
|
|
104
109
|
`pnpm-lock.yaml` stay pinned to your version. Dependency-range drift in
|
|
@@ -168,7 +173,8 @@ sh scripts/scaffold.sh [--app <name>]... [--service <name>]... [--mpo-version <r
|
|
|
168
173
|
`pnpm --filter @multiplatform.one/cli test` runs the vitest specs: the
|
|
169
174
|
provenance and merge units, and `updateApp.spec.ts`, which scaffolds from
|
|
170
175
|
this checkout at `HEAD`, updates from a second clone that moved ahead, and
|
|
171
|
-
adds an app
|
|
176
|
+
adds an app, and `updateCleanups.spec.ts`, which updates from a stand-in
|
|
177
|
+
monorepo whose scaffold gains a cleanup. `make -C public/cli test/bats` runs `tests/*.bats` against
|
|
172
178
|
`scripts/scaffold.sh` directly (needs `bats`). `pnpm build` stamps
|
|
173
179
|
`lib/source.json` from `git rev-parse HEAD` (`MPO_SOURCE_SHA` /
|
|
174
180
|
`MPO_SOURCE_URL` override it), unless `HEAD` carries another CLI version;
|
package/lib/commands/e2e.mjs
CHANGED
|
@@ -53,21 +53,12 @@ async function getPresentAppNames(projectRoot) {
|
|
|
53
53
|
return [];
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
/** Discover app
|
|
56
|
+
/** Discover the app whose package.json names it the e2e app (`"mpo": { "e2e": true }`), for E2E test cwd. Returns app name (e.g. "one") or null. */
|
|
57
57
|
async function discoverE2EApp(projectRoot) {
|
|
58
|
-
const
|
|
59
|
-
for (const name of
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"playwright.config.ts",
|
|
63
|
-
"playwright.config.js",
|
|
64
|
-
"playwright.config.mjs"
|
|
65
|
-
]) try {
|
|
66
|
-
await fs.access(path.join(appPath, config));
|
|
67
|
-
return name;
|
|
68
|
-
} catch {}
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
58
|
+
const named = [];
|
|
59
|
+
for (const name of await getPresentAppNames(projectRoot)) if (JSON.parse(await fs.readFile(path.join(projectRoot, "apps", name, "package.json"), "utf8"))?.mpo?.e2e === true) named.push(name);
|
|
60
|
+
if (named.length > 1) throw new Error(`more than one app sets "mpo": { "e2e": true } in its package.json: ${named.join(", ")}. Keep it on the one app mpo test e2e should run and delete it from the others.`);
|
|
61
|
+
return named[0] ?? null;
|
|
71
62
|
}
|
|
72
63
|
async function detectServices(projectRoot) {
|
|
73
64
|
const services = [];
|
|
@@ -255,7 +246,7 @@ async function runE2ESession(projectRoot, options) {
|
|
|
255
246
|
if (options.upOnly) return;
|
|
256
247
|
const e2eApp = await discoverE2EApp(projectRoot);
|
|
257
248
|
if (!e2eApp) {
|
|
258
|
-
console.error("No E2E app found: no
|
|
249
|
+
console.error("No E2E app found: no apps/*/package.json sets \"mpo\": { \"e2e\": true }.");
|
|
259
250
|
await tearDown(projectRoot, sessionFilePath);
|
|
260
251
|
process.exit(1);
|
|
261
252
|
}
|
|
@@ -25,9 +25,9 @@ function reportKept(stdout) {
|
|
|
25
25
|
for (const path of kept) console.log(` ${path}`);
|
|
26
26
|
}
|
|
27
27
|
/** Run scaffold.sh and return the provenance it wrote. */
|
|
28
|
-
async function runScaffold(request) {
|
|
28
|
+
async function runScaffold(request, script = scaffoldScript()) {
|
|
29
29
|
await checkSourceAccess(request.source);
|
|
30
|
-
const args = [
|
|
30
|
+
const args = [script];
|
|
31
31
|
for (const app of request.apps) args.push("--app", app);
|
|
32
32
|
for (const service of request.services) args.push("--service", service);
|
|
33
33
|
if (request.mpoVersion) args.push("--mpo-version", request.mpoVersion);
|
|
@@ -50,6 +50,62 @@ async function runScaffold(request) {
|
|
|
50
50
|
if (!provenance?.source) throw new ScaffoldError(`scaffold.sh wrote no provenance into ${request.target}`, request);
|
|
51
51
|
return provenance;
|
|
52
52
|
}
|
|
53
|
+
/** Where the monorepo keeps its scaffold, at every commit since MPO-310. */
|
|
54
|
+
const scaffoldPath = "public/cli/scripts/scaffold.sh";
|
|
55
|
+
/**
|
|
56
|
+
* Write the scaffold.sh that `source` carries at `ref` to `file`; false when
|
|
57
|
+
* that commit carries none. A merge baseline made with it is what that
|
|
58
|
+
* commit's own CLI scaffolded, so whatever the scaffold learned between two
|
|
59
|
+
* commits (a cleanup of root wiring, say) is part of the difference between
|
|
60
|
+
* their baselines and reaches the project, with no step of it named here. A
|
|
61
|
+
* url is fetched shallow and blobless, then the one blob, as scaffold.sh does.
|
|
62
|
+
*/
|
|
63
|
+
async function scaffoldScriptAt(source, ref, file) {
|
|
64
|
+
await checkSourceAccess(source);
|
|
65
|
+
const script = [
|
|
66
|
+
"set -eu",
|
|
67
|
+
"SOURCE=\"$1\"; REF=\"$2\"; SCRIPT=\"$3\"; OUT=\"$4\"",
|
|
68
|
+
"if [ -d \"$SOURCE\" ]; then",
|
|
69
|
+
" REPO=\"$SOURCE\"",
|
|
70
|
+
" COMMIT=\"$(git -C \"$REPO\" rev-parse --verify --quiet \"$REF^{commit}\")\" ||",
|
|
71
|
+
" { printf \"%s is not a commit in %s\\n\" \"$REF\" \"$REPO\" >&2; exit 1; }",
|
|
72
|
+
"else",
|
|
73
|
+
" REPO=\"$(mktemp -d \"${TMPDIR:-/tmp}/mpo-scaffold-script.XXXXXX\")\"",
|
|
74
|
+
" trap 'rm -rf \"$REPO\"' EXIT",
|
|
75
|
+
" git init -q \"$REPO\"",
|
|
76
|
+
" git -C \"$REPO\" remote add origin \"$SOURCE\"",
|
|
77
|
+
" git -C \"$REPO\" fetch -q --depth 1 --filter=blob:none origin \"$REF\"",
|
|
78
|
+
" COMMIT=\"$(git -C \"$REPO\" rev-parse --verify --quiet \"FETCH_HEAD^{commit}\")\"",
|
|
79
|
+
"fi",
|
|
80
|
+
"BLOB=\"$(git -C \"$REPO\" ls-tree \"$COMMIT\" -- \"$SCRIPT\" | awk '$2 == \"blob\" { print $3 }')\"",
|
|
81
|
+
"[ -n \"$BLOB\" ] || exit 3",
|
|
82
|
+
"if [ \"$(git -C \"$REPO\" config --get remote.origin.promisor || true)\" = true ]; then",
|
|
83
|
+
" printf \"%s\\n\" \"$BLOB\" | git -C \"$REPO\" -c fetch.negotiationAlgorithm=noop fetch -q \\",
|
|
84
|
+
" --no-tags --no-write-fetch-head --filter=blob:none --stdin origin",
|
|
85
|
+
"fi",
|
|
86
|
+
"git -C \"$REPO\" cat-file blob \"$BLOB\" >\"$OUT\""
|
|
87
|
+
].join("\n");
|
|
88
|
+
try {
|
|
89
|
+
await spawn("sh", [
|
|
90
|
+
"-c",
|
|
91
|
+
script,
|
|
92
|
+
"sh",
|
|
93
|
+
source,
|
|
94
|
+
ref,
|
|
95
|
+
scaffoldPath,
|
|
96
|
+
file
|
|
97
|
+
], { stdio: [
|
|
98
|
+
"ignore",
|
|
99
|
+
"ignore",
|
|
100
|
+
"pipe"
|
|
101
|
+
] });
|
|
102
|
+
return true;
|
|
103
|
+
} catch (err) {
|
|
104
|
+
if (err.exitCode === 3) return false;
|
|
105
|
+
const detail = (err.stderr ?? "").trim().split("\n").filter(Boolean).pop() ?? err.message;
|
|
106
|
+
throw new Error(`could not read ${scaffoldPath} at ${ref} from ${source}: ${detail}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
53
109
|
/** A scaffold in a temp dir (merge baselines). */
|
|
54
110
|
async function scaffoldToTemp(request) {
|
|
55
111
|
const parent = mkdtempSync(join(tmpdir(), "mpo-scaffold-"));
|
|
@@ -59,12 +115,15 @@ async function scaffoldToTemp(request) {
|
|
|
59
115
|
force: true
|
|
60
116
|
});
|
|
61
117
|
try {
|
|
118
|
+
const script = join(parent, "scaffold.sh");
|
|
119
|
+
const carried = await scaffoldScriptAt(request.source, request.ref, script);
|
|
120
|
+
if (!carried) console.warn(`⚠️ ${request.ref} carries no ${scaffoldPath}; using this CLI's for that side`);
|
|
62
121
|
return {
|
|
63
122
|
dir,
|
|
64
123
|
provenance: await runScaffold({
|
|
65
124
|
...request,
|
|
66
125
|
target: dir
|
|
67
|
-
}),
|
|
126
|
+
}, carried ? script : void 0),
|
|
68
127
|
cleanup
|
|
69
128
|
};
|
|
70
129
|
} catch (err) {
|
package/lib/commands/verbs.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { discoverE2EApp } from "./e2e.mjs";
|
|
2
1
|
import fsSync from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import fs from "node:fs/promises";
|
|
@@ -110,13 +109,15 @@ function parseTestTiers(args) {
|
|
|
110
109
|
/**
|
|
111
110
|
* `bench run-tests` for every frappe app with a pyproject.toml, limited to the
|
|
112
111
|
* pytest marker expression. Skipped when the bench is not bootstrapped
|
|
113
|
-
* (no apps/frappe/sites)
|
|
112
|
+
* (no apps/frappe/sites), or failed when `required`; once it is, any app
|
|
113
|
+
* whose run fails fails the tier.
|
|
114
114
|
*/
|
|
115
|
-
async function runBenchTests(projectRoot, marker, spawn) {
|
|
115
|
+
async function runBenchTests(projectRoot, marker, spawn, required) {
|
|
116
116
|
const benchDir = path.join(projectRoot, "apps", "frappe");
|
|
117
117
|
const apps = (await getFrappeApps(projectRoot)).filter((app) => fsSync.existsSync(path.join(app.absolutePath, "pyproject.toml")));
|
|
118
118
|
if (!apps.length) return;
|
|
119
119
|
if (!fsSync.existsSync(path.join(benchDir, "sites"))) {
|
|
120
|
+
if (required) throw new Error(`no frappe bench (apps/frappe/sites): bench tests -m "${marker}" need one`);
|
|
120
121
|
console.warn(`no frappe bench (apps/frappe/sites): skipped bench tests -m "${marker}"`);
|
|
121
122
|
return;
|
|
122
123
|
}
|
|
@@ -139,25 +140,45 @@ async function runBenchTests(projectRoot, marker, spawn) {
|
|
|
139
140
|
}
|
|
140
141
|
if (failed.length) throw new Error(`bench tests -m "${marker}" failed: ${failed.join(", ")}`);
|
|
141
142
|
}
|
|
142
|
-
/** The unit tier: turbo test minus missing services
|
|
143
|
+
/** The unit tier: turbo test minus missing services, then the bench's non-integration tests. */
|
|
143
144
|
async function runUnitTests(projectRoot, spawn$1 = spawn) {
|
|
144
|
-
const excludeFilters = await getTurboExcludeFiltersForMissing(projectRoot);
|
|
145
|
-
const e2eApp = await discoverE2EApp(projectRoot);
|
|
146
145
|
await spawn$1("pnpm", [
|
|
147
146
|
"turbo",
|
|
148
147
|
"run",
|
|
149
148
|
"test",
|
|
150
|
-
...
|
|
149
|
+
...(await getTurboExcludeFiltersForMissing(projectRoot)).flatMap((f) => ["--filter", f])
|
|
151
150
|
], {
|
|
152
151
|
stdio: "inherit",
|
|
153
152
|
shell: true,
|
|
154
153
|
cwd: projectRoot
|
|
155
154
|
});
|
|
156
|
-
await runBenchTests(projectRoot, "not integration", spawn$1);
|
|
155
|
+
await runBenchTests(projectRoot, "not integration", spawn$1, false);
|
|
157
156
|
}
|
|
158
|
-
/** The integration tier: the bench's integration-marked tests
|
|
157
|
+
/** The integration tier: turbo test:integration, then the bench's integration-marked tests; a missing service fails it. */
|
|
159
158
|
async function runIntegrationTests(projectRoot, spawn$2 = spawn) {
|
|
160
|
-
await
|
|
159
|
+
const filters = (await getTurboExcludeFiltersForMissing(projectRoot)).flatMap((f) => ["--filter", f]);
|
|
160
|
+
const failures = [];
|
|
161
|
+
try {
|
|
162
|
+
await spawn$2("pnpm", [
|
|
163
|
+
"turbo",
|
|
164
|
+
"run",
|
|
165
|
+
"test:integration",
|
|
166
|
+
"--continue",
|
|
167
|
+
...filters
|
|
168
|
+
], {
|
|
169
|
+
stdio: "inherit",
|
|
170
|
+
shell: true,
|
|
171
|
+
cwd: projectRoot
|
|
172
|
+
});
|
|
173
|
+
} catch (error) {
|
|
174
|
+
failures.push(error.message);
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
await runBenchTests(projectRoot, "integration", spawn$2, true);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
failures.push(error.message);
|
|
180
|
+
}
|
|
181
|
+
if (failures.length) throw new Error(failures.join("\n"));
|
|
161
182
|
}
|
|
162
183
|
/** `mpo build`: the packages, then every present app with a build script, each once. */
|
|
163
184
|
async function runBuild(args, projectRoot, spawn$3 = spawn) {
|
package/lib/source.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@multiplatform.one/cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "multiplatform.one cli — mpo init clones and prunes the monorepo, mpo update merges it back",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"create-multiplatform-app",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@multiplatform.one/utils": "^8.
|
|
60
|
+
"@multiplatform.one/utils": "^8.1.0",
|
|
61
61
|
"commander": "^15.0.0",
|
|
62
62
|
"dotenv": "^17.4.2",
|
|
63
63
|
"inquirer": "^14.2.3",
|
package/scripts/scaffold.sh
CHANGED
|
@@ -345,6 +345,18 @@ fi
|
|
|
345
345
|
for _app in $APPS; do
|
|
346
346
|
[ ! -e "$TREE/apps/$_app" ] || die "apps/$_app already exists in the source tree; pick another product name"
|
|
347
347
|
cp -R "$TREE/apps/one" "$TREE/apps/$_app"
|
|
348
|
+
if [ "$_app" != "$FIRST_APP" ]; then
|
|
349
|
+
node - "$TREE/apps/$_app/package.json" <<'NODE'
|
|
350
|
+
const fs = require("node:fs");
|
|
351
|
+
const [file] = process.argv.slice(2);
|
|
352
|
+
const text = fs
|
|
353
|
+
.readFileSync(file, "utf8")
|
|
354
|
+
.replace(/,\n {2}"mpo": \{\n {4}"e2e": true\n {2}\}(?=\n\}\n?$)/, "")
|
|
355
|
+
.replace(/\n {2}"mpo": \{\n {4}"e2e": true\n {2}\},/, "");
|
|
356
|
+
if (JSON.parse(text).mpo?.e2e) throw new Error(`${file}: could not drop "mpo": { "e2e": true }`);
|
|
357
|
+
fs.writeFileSync(file, text);
|
|
358
|
+
NODE
|
|
359
|
+
fi
|
|
348
360
|
# A feature module of that name already satisfies the app/features twin
|
|
349
361
|
# (features/pokemon is the One app's own pokemon feature). The index
|
|
350
362
|
# routes import features/<app>/screen, so a module without one gets
|
|
@@ -422,13 +422,13 @@ program
|
|
|
422
422
|
.action(async (args: string[], options) => {
|
|
423
423
|
const parsed = parseTestTiers(args);
|
|
424
424
|
|
|
425
|
-
// Handle unit tests (turbo test with dynamic excludes: missing services
|
|
425
|
+
// Handle unit tests (turbo test with dynamic excludes: missing services, plus frappe app unit tests)
|
|
426
426
|
if (parsed.includes("unit")) {
|
|
427
427
|
await runUnitTests(projectRoot);
|
|
428
428
|
if (parsed.length === 1) return;
|
|
429
429
|
}
|
|
430
430
|
|
|
431
|
-
// Handle integration tests (frappe app integration tests)
|
|
431
|
+
// Handle integration tests (turbo test:integration plus frappe app integration tests)
|
|
432
432
|
if (parsed.includes("integration")) {
|
|
433
433
|
await runIntegrationTests(projectRoot);
|
|
434
434
|
if (parsed.length === 1) return;
|
package/src/commands/e2e.ts
CHANGED
|
@@ -64,25 +64,22 @@ async function getPresentAppNames(projectRoot: string): Promise<string[]> {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
/** Discover app
|
|
67
|
+
/** Discover the app whose package.json names it the e2e app (`"mpo": { "e2e": true }`), for E2E test cwd. Returns app name (e.g. "one") or null. */
|
|
68
68
|
export async function discoverE2EApp(projectRoot: string): Promise<string | null> {
|
|
69
|
-
const
|
|
70
|
-
for (const name of
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// continue
|
|
82
|
-
}
|
|
83
|
-
}
|
|
69
|
+
const named: string[] = [];
|
|
70
|
+
for (const name of await getPresentAppNames(projectRoot)) {
|
|
71
|
+
const pkg = JSON.parse(
|
|
72
|
+
await fs.readFile(path.join(projectRoot, "apps", name, "package.json"), "utf8"),
|
|
73
|
+
);
|
|
74
|
+
if (pkg?.mpo?.e2e === true) named.push(name);
|
|
75
|
+
}
|
|
76
|
+
if (named.length > 1) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`more than one app sets "mpo": { "e2e": true } in its package.json: ${named.join(", ")}. ` +
|
|
79
|
+
"Keep it on the one app mpo test e2e should run and delete it from the others.",
|
|
80
|
+
);
|
|
84
81
|
}
|
|
85
|
-
return null;
|
|
82
|
+
return named[0] ?? null;
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
export async function detectServices(projectRoot: string): Promise<string[]> {
|
|
@@ -319,12 +316,10 @@ export async function runE2ESession(projectRoot: string, options: E2EOptions): P
|
|
|
319
316
|
return;
|
|
320
317
|
}
|
|
321
318
|
|
|
322
|
-
// Run Playwright tests (discover app
|
|
319
|
+
// Run Playwright tests (discover the app its package.json names)
|
|
323
320
|
const e2eApp = await discoverE2EApp(projectRoot);
|
|
324
321
|
if (!e2eApp) {
|
|
325
|
-
console.error(
|
|
326
|
-
"No E2E app found: no app under apps/ has playwright.config.ts or playwright.config.js.",
|
|
327
|
-
);
|
|
322
|
+
console.error('No E2E app found: no apps/*/package.json sets "mpo": { "e2e": true }.');
|
|
328
323
|
await tearDown(projectRoot, sessionFilePath);
|
|
329
324
|
process.exit(1);
|
|
330
325
|
}
|
package/src/commands/scaffold.ts
CHANGED
|
@@ -53,9 +53,12 @@ function reportKept(stdout: string): void {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/** Run scaffold.sh and return the provenance it wrote. */
|
|
56
|
-
export async function runScaffold(
|
|
56
|
+
export async function runScaffold(
|
|
57
|
+
request: ScaffoldRequest,
|
|
58
|
+
script = scaffoldScript(),
|
|
59
|
+
): Promise<MpoProvenance> {
|
|
57
60
|
await checkSourceAccess(request.source);
|
|
58
|
-
const args = [
|
|
61
|
+
const args = [script];
|
|
59
62
|
for (const app of request.apps) args.push("--app", app);
|
|
60
63
|
for (const service of request.services) args.push("--service", service);
|
|
61
64
|
if (request.mpoVersion) args.push("--mpo-version", request.mpoVersion);
|
|
@@ -88,6 +91,55 @@ export interface TempScaffold {
|
|
|
88
91
|
cleanup: () => void;
|
|
89
92
|
}
|
|
90
93
|
|
|
94
|
+
/** Where the monorepo keeps its scaffold, at every commit since MPO-310. */
|
|
95
|
+
const scaffoldPath = "public/cli/scripts/scaffold.sh";
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Write the scaffold.sh that `source` carries at `ref` to `file`; false when
|
|
99
|
+
* that commit carries none. A merge baseline made with it is what that
|
|
100
|
+
* commit's own CLI scaffolded, so whatever the scaffold learned between two
|
|
101
|
+
* commits (a cleanup of root wiring, say) is part of the difference between
|
|
102
|
+
* their baselines and reaches the project, with no step of it named here. A
|
|
103
|
+
* url is fetched shallow and blobless, then the one blob, as scaffold.sh does.
|
|
104
|
+
*/
|
|
105
|
+
async function scaffoldScriptAt(source: string, ref: string, file: string): Promise<boolean> {
|
|
106
|
+
await checkSourceAccess(source);
|
|
107
|
+
const script = [
|
|
108
|
+
"set -eu",
|
|
109
|
+
'SOURCE="$1"; REF="$2"; SCRIPT="$3"; OUT="$4"',
|
|
110
|
+
'if [ -d "$SOURCE" ]; then',
|
|
111
|
+
' REPO="$SOURCE"',
|
|
112
|
+
' COMMIT="$(git -C "$REPO" rev-parse --verify --quiet "$REF^{commit}")" ||',
|
|
113
|
+
' { printf "%s is not a commit in %s\\n" "$REF" "$REPO" >&2; exit 1; }',
|
|
114
|
+
"else",
|
|
115
|
+
' REPO="$(mktemp -d "${TMPDIR:-/tmp}/mpo-scaffold-script.XXXXXX")"',
|
|
116
|
+
" trap 'rm -rf \"$REPO\"' EXIT",
|
|
117
|
+
' git init -q "$REPO"',
|
|
118
|
+
' git -C "$REPO" remote add origin "$SOURCE"',
|
|
119
|
+
' git -C "$REPO" fetch -q --depth 1 --filter=blob:none origin "$REF"',
|
|
120
|
+
' COMMIT="$(git -C "$REPO" rev-parse --verify --quiet "FETCH_HEAD^{commit}")"',
|
|
121
|
+
"fi",
|
|
122
|
+
'BLOB="$(git -C "$REPO" ls-tree "$COMMIT" -- "$SCRIPT" | awk \'$2 == "blob" { print $3 }\')"',
|
|
123
|
+
'[ -n "$BLOB" ] || exit 3',
|
|
124
|
+
'if [ "$(git -C "$REPO" config --get remote.origin.promisor || true)" = true ]; then',
|
|
125
|
+
' printf "%s\\n" "$BLOB" | git -C "$REPO" -c fetch.negotiationAlgorithm=noop fetch -q \\',
|
|
126
|
+
" --no-tags --no-write-fetch-head --filter=blob:none --stdin origin",
|
|
127
|
+
"fi",
|
|
128
|
+
'git -C "$REPO" cat-file blob "$BLOB" >"$OUT"',
|
|
129
|
+
].join("\n");
|
|
130
|
+
try {
|
|
131
|
+
await spawn("sh", ["-c", script, "sh", source, ref, scaffoldPath, file], {
|
|
132
|
+
stdio: ["ignore", "ignore", "pipe"],
|
|
133
|
+
});
|
|
134
|
+
return true;
|
|
135
|
+
} catch (err) {
|
|
136
|
+
if ((err as { exitCode?: number }).exitCode === 3) return false;
|
|
137
|
+
const stderr = ((err as { stderr?: string }).stderr ?? "").trim();
|
|
138
|
+
const detail = stderr.split("\n").filter(Boolean).pop() ?? (err as Error).message;
|
|
139
|
+
throw new Error(`could not read ${scaffoldPath} at ${ref} from ${source}: ${detail}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
91
143
|
/** A scaffold in a temp dir (merge baselines). */
|
|
92
144
|
export async function scaffoldToTemp(
|
|
93
145
|
request: Omit<ScaffoldRequest, "target" | "into">,
|
|
@@ -96,7 +148,12 @@ export async function scaffoldToTemp(
|
|
|
96
148
|
const dir = join(parent, "project");
|
|
97
149
|
const cleanup = () => rmSync(parent, { recursive: true, force: true });
|
|
98
150
|
try {
|
|
99
|
-
const
|
|
151
|
+
const script = join(parent, "scaffold.sh");
|
|
152
|
+
const carried = await scaffoldScriptAt(request.source, request.ref, script);
|
|
153
|
+
if (!carried) {
|
|
154
|
+
console.warn(`⚠️ ${request.ref} carries no ${scaffoldPath}; using this CLI's for that side`);
|
|
155
|
+
}
|
|
156
|
+
const provenance = await runScaffold({ ...request, target: dir }, carried ? script : undefined);
|
|
100
157
|
return { dir, provenance, cleanup };
|
|
101
158
|
} catch (err) {
|
|
102
159
|
cleanup();
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import spawn from "nano-spawn";
|
|
5
|
+
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { addApp } from "./addApp";
|
|
7
|
+
import { init } from "./init";
|
|
8
|
+
import { readProvenance } from "./provenance";
|
|
9
|
+
import { scaffoldScript } from "./scaffold";
|
|
10
|
+
import { updateApp } from "./updateApp";
|
|
11
|
+
|
|
12
|
+
// A stand-in monorepo of five files, so a scaffold takes well under a second.
|
|
13
|
+
// Its scaffold.sh starts as this CLI's own, and a later commit teaches it a
|
|
14
|
+
// cleanup made up here. Nothing in update or add-app names that cleanup: it can
|
|
15
|
+
// only reach a project when each side of the merge runs the scaffold.sh its own
|
|
16
|
+
// commit carries.
|
|
17
|
+
const heavy = 300_000;
|
|
18
|
+
const json = (value: unknown) => `${JSON.stringify(value, null, 2)}\n`;
|
|
19
|
+
const ownScript = readFileSync(scaffoldScript(), "utf-8");
|
|
20
|
+
const anchor = "# ── 6. provenance";
|
|
21
|
+
|
|
22
|
+
const legacyRule = ".PHONY: legacy\nlegacy:\n\t@echo legacy\n\n";
|
|
23
|
+
const makefile = `.PHONY: build\nbuild:\n\t@echo build\n\n${legacyRule}.PHONY: test\ntest:\n\t@echo test\n`;
|
|
24
|
+
const cleaned = makefile.replace(legacyRule, "");
|
|
25
|
+
const dropLegacy = "sed_file \"$TREE/Makefile\" '/^\\.PHONY: legacy$/,/^$/d'";
|
|
26
|
+
|
|
27
|
+
/** The scaffold with `step` run just before it writes .mpo.json. */
|
|
28
|
+
function scaffoldWith(step: string): string {
|
|
29
|
+
if (!ownScript.includes(anchor)) throw new Error(`scaffold.sh has no "${anchor}" line`);
|
|
30
|
+
return ownScript.replace(anchor, `${step}\n\n${anchor}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function git(cwd: string, args: string[]): Promise<string> {
|
|
34
|
+
const result = await spawn("git", args, { cwd });
|
|
35
|
+
return result.stdout.trim();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function newRepo(dir: string): Promise<void> {
|
|
39
|
+
mkdirSync(dir, { recursive: true });
|
|
40
|
+
await git(dir, ["init", "--quiet", "--initial-branch=main"]);
|
|
41
|
+
await git(dir, ["config", "user.email", "spec@example.com"]);
|
|
42
|
+
await git(dir, ["config", "user.name", "Spec"]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function commitAll(dir: string, message: string): Promise<string> {
|
|
46
|
+
await git(dir, ["add", "-A"]);
|
|
47
|
+
await git(dir, ["commit", "--quiet", "-m", message]);
|
|
48
|
+
return git(dir, ["rev-parse", "HEAD"]);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function writeFiles(dir: string, files: Record<string, string>): void {
|
|
52
|
+
for (const [file, content] of Object.entries(files)) {
|
|
53
|
+
mkdirSync(dirname(join(dir, file)), { recursive: true });
|
|
54
|
+
writeFileSync(join(dir, file), content);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A stand-in monorepo whose first commit carries `script` as its scaffold.sh. */
|
|
59
|
+
async function standIn(dir: string, script: string): Promise<string> {
|
|
60
|
+
await newRepo(dir);
|
|
61
|
+
// The url cases fetch commits by sha, as a project's base does from GitLab.
|
|
62
|
+
await git(dir, ["config", "uploadpack.allowFilter", "true"]);
|
|
63
|
+
await git(dir, ["config", "uploadpack.allowAnySHA1InWant", "true"]);
|
|
64
|
+
writeFiles(dir, {
|
|
65
|
+
"package.json": json({ name: "fixture", private: true }),
|
|
66
|
+
Makefile: makefile,
|
|
67
|
+
"apps/one/package.json": json({ name: "@platform/one", private: true }),
|
|
68
|
+
"public/cli/package.json": json({ name: "@multiplatform.one/cli", version: "1.0.0" }),
|
|
69
|
+
"public/cli/scripts/scaffold.sh": script,
|
|
70
|
+
});
|
|
71
|
+
return commitAll(dir, "chore: stand-in monorepo");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const read = (dir: string, file: string) => readFileSync(join(dir, file), "utf-8");
|
|
75
|
+
|
|
76
|
+
describe("mpo update runs the scaffold each commit carries", () => {
|
|
77
|
+
let sandbox: string;
|
|
78
|
+
let previousCwd: string;
|
|
79
|
+
let source: string;
|
|
80
|
+
let recorded: string;
|
|
81
|
+
let next: string;
|
|
82
|
+
|
|
83
|
+
beforeAll(async () => {
|
|
84
|
+
sandbox = mkdtempSync(join(tmpdir(), "mpo-update-cleanups-spec-"));
|
|
85
|
+
previousCwd = process.cwd();
|
|
86
|
+
source = join(sandbox, "source");
|
|
87
|
+
recorded = await standIn(source, ownScript);
|
|
88
|
+
writeFileSync(join(source, "public/cli/scripts/scaffold.sh"), scaffoldWith(dropLegacy));
|
|
89
|
+
next = await commitAll(source, "feat: the scaffold drops the legacy rule");
|
|
90
|
+
}, heavy);
|
|
91
|
+
|
|
92
|
+
afterEach(() => {
|
|
93
|
+
process.chdir(previousCwd);
|
|
94
|
+
vi.restoreAllMocks();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
afterAll(() => {
|
|
98
|
+
process.chdir(previousCwd);
|
|
99
|
+
rmSync(sandbox, { recursive: true, force: true });
|
|
100
|
+
}, heavy);
|
|
101
|
+
|
|
102
|
+
/** `mpo init` at the recorded commit, committed; optionally edited and committed again. */
|
|
103
|
+
async function project(
|
|
104
|
+
name: string,
|
|
105
|
+
edit?: (dir: string) => void,
|
|
106
|
+
from = { source, checkout: recorded },
|
|
107
|
+
): Promise<string> {
|
|
108
|
+
const parent = join(sandbox, name);
|
|
109
|
+
mkdirSync(parent);
|
|
110
|
+
process.chdir(parent);
|
|
111
|
+
await init("shop", {
|
|
112
|
+
...from,
|
|
113
|
+
services: [],
|
|
114
|
+
skipInstall: true,
|
|
115
|
+
skipGit: true,
|
|
116
|
+
yes: true,
|
|
117
|
+
});
|
|
118
|
+
const dir = join(parent, "shop");
|
|
119
|
+
await newRepo(dir);
|
|
120
|
+
await commitAll(dir, "feat: scaffold (mpo init)");
|
|
121
|
+
expect(read(dir, "Makefile")).toBe(makefile);
|
|
122
|
+
if (edit) {
|
|
123
|
+
edit(dir);
|
|
124
|
+
await commitAll(dir, "feat: the project's own edit");
|
|
125
|
+
}
|
|
126
|
+
process.chdir(dir);
|
|
127
|
+
return dir;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function expectQuietRerun(dir: string, from: string): Promise<void> {
|
|
131
|
+
const committed = await commitAll(dir, "chore: mpo update");
|
|
132
|
+
await updateApp({ source: from, skipInstall: true });
|
|
133
|
+
expect(await git(dir, ["rev-parse", "HEAD"])).toBe(committed);
|
|
134
|
+
expect(await git(dir, ["status", "--porcelain"])).toBe("");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
it(
|
|
138
|
+
"a cleanup added after the recorded commit leaves the project with the update",
|
|
139
|
+
async () => {
|
|
140
|
+
const dir = await project("untouched");
|
|
141
|
+
await updateApp({ source, skipInstall: true });
|
|
142
|
+
expect(read(dir, "Makefile")).toBe(cleaned);
|
|
143
|
+
expect(await git(dir, ["diff", "--cached", "--name-only"])).toBe("Makefile");
|
|
144
|
+
expect(readProvenance(dir)?.source?.sha).toBe(next);
|
|
145
|
+
await expectQuietRerun(dir, source);
|
|
146
|
+
},
|
|
147
|
+
heavy,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
it(
|
|
151
|
+
"reads each commit's scaffold from a git url as well",
|
|
152
|
+
async () => {
|
|
153
|
+
const dir = await project("from-url");
|
|
154
|
+
const url = `file://${source}`;
|
|
155
|
+
await updateApp({ source: url, skipInstall: true });
|
|
156
|
+
expect(read(dir, "Makefile")).toBe(cleaned);
|
|
157
|
+
expect(readProvenance(dir)?.source?.sha).toBe(next);
|
|
158
|
+
await expectQuietRerun(dir, url);
|
|
159
|
+
},
|
|
160
|
+
heavy,
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
it(
|
|
164
|
+
"the project's own edit to that file survives the cleanup",
|
|
165
|
+
async () => {
|
|
166
|
+
const deploy = ".PHONY: deploy\ndeploy:\n\t@echo deploy\n";
|
|
167
|
+
const dir = await project("edited-elsewhere", (dir) => {
|
|
168
|
+
writeFileSync(join(dir, "Makefile"), `${makefile}\n${deploy}`);
|
|
169
|
+
});
|
|
170
|
+
await updateApp({ source, skipInstall: true });
|
|
171
|
+
expect(read(dir, "Makefile")).toBe(`${cleaned}\n${deploy}`);
|
|
172
|
+
await expectQuietRerun(dir, source);
|
|
173
|
+
},
|
|
174
|
+
heavy,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
it(
|
|
178
|
+
"an edit to the lines the cleanup drops is a conflict the user sees, not an overwrite",
|
|
179
|
+
async () => {
|
|
180
|
+
const dir = await project("edited-rule", (dir) => {
|
|
181
|
+
writeFileSync(
|
|
182
|
+
join(dir, "Makefile"),
|
|
183
|
+
makefile.replace("\t@echo legacy", "\t@echo legacy, kept by the project"),
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
const lines: string[] = [];
|
|
187
|
+
vi.spyOn(console, "log").mockImplementation((...args) => {
|
|
188
|
+
lines.push(args.join(" "));
|
|
189
|
+
});
|
|
190
|
+
await updateApp({ source, skipInstall: true });
|
|
191
|
+
const merged = read(dir, "Makefile");
|
|
192
|
+
expect(merged).toContain("<<<<<<<");
|
|
193
|
+
expect(merged).toContain("legacy, kept by the project");
|
|
194
|
+
expect(merged).toContain(">>>>>>>");
|
|
195
|
+
const warning = lines.findIndex((line) => line.includes("merge conflicts"));
|
|
196
|
+
expect(warning).toBeGreaterThan(-1);
|
|
197
|
+
expect(lines.slice(warning + 1)).toContain(" Makefile");
|
|
198
|
+
},
|
|
199
|
+
heavy,
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
it(
|
|
203
|
+
"a project that already dropped the rule is left as it is",
|
|
204
|
+
async () => {
|
|
205
|
+
const dir = await project("already-clean", (dir) => {
|
|
206
|
+
writeFileSync(join(dir, "Makefile"), cleaned);
|
|
207
|
+
});
|
|
208
|
+
await updateApp({ source, skipInstall: true });
|
|
209
|
+
expect(read(dir, "Makefile")).toBe(cleaned);
|
|
210
|
+
expect(await git(dir, ["diff", "--cached", "--name-only"])).toBe("");
|
|
211
|
+
expect(await git(dir, ["status", "--porcelain"])).toBe("M .mpo.json");
|
|
212
|
+
await expectQuietRerun(dir, source);
|
|
213
|
+
},
|
|
214
|
+
heavy,
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
it(
|
|
218
|
+
"a recorded commit that carries no scaffold.sh gets this CLI's, and update says so",
|
|
219
|
+
async () => {
|
|
220
|
+
const bare = join(sandbox, "bare-source");
|
|
221
|
+
await standIn(bare, ownScript);
|
|
222
|
+
rmSync(join(bare, "public/cli/scripts"), { recursive: true });
|
|
223
|
+
const old = await commitAll(bare, "chore: no scaffold.sh yet");
|
|
224
|
+
writeFiles(bare, { "public/cli/scripts/scaffold.sh": scaffoldWith(dropLegacy) });
|
|
225
|
+
await commitAll(bare, "feat: scaffold.sh, dropping the legacy rule");
|
|
226
|
+
const dir = await project("no-script", undefined, { source: bare, checkout: old });
|
|
227
|
+
const warnings: string[] = [];
|
|
228
|
+
vi.spyOn(console, "warn").mockImplementation((...args) => {
|
|
229
|
+
warnings.push(args.join(" "));
|
|
230
|
+
});
|
|
231
|
+
await updateApp({ source: bare, skipInstall: true });
|
|
232
|
+
expect(warnings).toContain(
|
|
233
|
+
`⚠️ ${old} carries no public/cli/scripts/scaffold.sh; using this CLI's for that side`,
|
|
234
|
+
);
|
|
235
|
+
expect(read(dir, "Makefile")).toBe(cleaned);
|
|
236
|
+
},
|
|
237
|
+
heavy,
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe("mpo add-app runs the scaffold at the recorded commit", () => {
|
|
242
|
+
let sandbox: string;
|
|
243
|
+
let previousCwd: string;
|
|
244
|
+
|
|
245
|
+
beforeAll(() => {
|
|
246
|
+
sandbox = mkdtempSync(join(tmpdir(), "mpo-add-app-scaffold-spec-"));
|
|
247
|
+
previousCwd = process.cwd();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
afterEach(() => {
|
|
251
|
+
process.chdir(previousCwd);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
afterAll(() => {
|
|
255
|
+
process.chdir(previousCwd);
|
|
256
|
+
rmSync(sandbox, { recursive: true, force: true });
|
|
257
|
+
}, heavy);
|
|
258
|
+
|
|
259
|
+
it(
|
|
260
|
+
"root wiring that scaffold writes per app follows the new app",
|
|
261
|
+
async () => {
|
|
262
|
+
// Root wiring this CLI's scaffold never writes: only the recorded
|
|
263
|
+
// commit's scaffold can add the new app to it.
|
|
264
|
+
const script = scaffoldWith(`printf 'apps:%s\\n' " $APPS" >"$TREE/apps.txt"`);
|
|
265
|
+
const source = join(sandbox, "source");
|
|
266
|
+
const recorded = await standIn(source, script);
|
|
267
|
+
const scriptFile = join(sandbox, "scaffold.sh");
|
|
268
|
+
writeFileSync(scriptFile, script);
|
|
269
|
+
const dir = join(sandbox, "shop");
|
|
270
|
+
await spawn("sh", [scriptFile, "--app", "shop", "--", source, recorded, dir]);
|
|
271
|
+
await newRepo(dir);
|
|
272
|
+
await commitAll(dir, "feat: scaffold");
|
|
273
|
+
expect(read(dir, "apps.txt")).toBe("apps: shop\n");
|
|
274
|
+
|
|
275
|
+
process.chdir(dir);
|
|
276
|
+
await addApp("kiosk", { source, skipInstall: true });
|
|
277
|
+
expect(read(dir, "apps.txt")).toBe("apps: shop kiosk\n");
|
|
278
|
+
expect(readProvenance(dir)?.apps).toEqual(["shop", "kiosk"]);
|
|
279
|
+
},
|
|
280
|
+
heavy,
|
|
281
|
+
);
|
|
282
|
+
});
|
|
@@ -4,6 +4,7 @@ import { dirname, join } from "node:path";
|
|
|
4
4
|
import { waitForMariaDB, waitServices } from "@multiplatform.one/utils/dev";
|
|
5
5
|
import nanoSpawn from "nano-spawn";
|
|
6
6
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import { discoverE2EApp } from "./e2e";
|
|
7
8
|
import {
|
|
8
9
|
availableServices,
|
|
9
10
|
parseTestTiers,
|
|
@@ -49,6 +50,9 @@ const isTurboTest = (call: Call) =>
|
|
|
49
50
|
|
|
50
51
|
const benchCalls = (calls: Call[]) => calls.filter((call) => call.file === "bench");
|
|
51
52
|
|
|
53
|
+
const isTurboIntegration = (call: Call) =>
|
|
54
|
+
call.file === "pnpm" && call.args.slice(0, 3).join(" ") === "turbo run test:integration";
|
|
55
|
+
|
|
52
56
|
describe("mpo test tiers (FZ-10496)", () => {
|
|
53
57
|
let root: string;
|
|
54
58
|
|
|
@@ -86,17 +90,38 @@ describe("mpo test tiers (FZ-10496)", () => {
|
|
|
86
90
|
expect(benchCalls(calls)[0].cwd).toBe(join(root, "apps/frappe"));
|
|
87
91
|
});
|
|
88
92
|
|
|
89
|
-
it("
|
|
93
|
+
it("unit runs every app's turbo test, the e2e app's too (FZ-10556)", async () => {
|
|
94
|
+
write(
|
|
95
|
+
root,
|
|
96
|
+
"apps/one/package.json",
|
|
97
|
+
JSON.stringify({ name: "@platform/one", mpo: { e2e: true } }),
|
|
98
|
+
);
|
|
99
|
+
write(root, "apps/one/playwright.config.ts", "");
|
|
100
|
+
const { calls, spawn } = recorder();
|
|
101
|
+
await runUnitTests(root, spawn);
|
|
102
|
+
expect(calls).toEqual([{ file: "pnpm", args: ["turbo", "run", "test"], cwd: root }]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("integration runs the turbo test:integration task, then the bench's integration tests (FZ-10556)", async () => {
|
|
90
106
|
plantBench(root, { bootstrapped: true });
|
|
91
107
|
const { calls, spawn } = recorder();
|
|
92
108
|
await runIntegrationTests(root, spawn);
|
|
93
109
|
expect(calls.filter(isTurboTest)).toEqual([]);
|
|
94
110
|
expect(calls.map((call) => [call.file, ...call.args])).toEqual([
|
|
111
|
+
["pnpm", "turbo", "run", "test:integration", "--continue"],
|
|
95
112
|
["bench", "run-tests", "--app", "core", "--", "-m", "integration"],
|
|
96
113
|
["bench", "run-tests", "--app", "live", "--", "-m", "integration"],
|
|
97
114
|
]);
|
|
98
115
|
});
|
|
99
116
|
|
|
117
|
+
it("a failed test:integration still runs the bench before integration fails (FZ-10556)", async () => {
|
|
118
|
+
plantBench(root, { bootstrapped: true });
|
|
119
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
120
|
+
const { calls, spawn } = recorder(isTurboIntegration);
|
|
121
|
+
await expect(runIntegrationTests(root, spawn)).rejects.toThrow(/exit code 1/);
|
|
122
|
+
expect(benchCalls(calls)).toHaveLength(2);
|
|
123
|
+
});
|
|
124
|
+
|
|
100
125
|
it("a bootstrapped bench that fails fails integration, after every app ran", async () => {
|
|
101
126
|
plantBench(root, { bootstrapped: true });
|
|
102
127
|
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
@@ -116,14 +141,78 @@ describe("mpo test tiers (FZ-10496)", () => {
|
|
|
116
141
|
);
|
|
117
142
|
});
|
|
118
143
|
|
|
119
|
-
it("a bench that is not bootstrapped
|
|
144
|
+
it("unit skips a bench that is not bootstrapped, with a note", async () => {
|
|
120
145
|
plantBench(root, { bootstrapped: false });
|
|
121
146
|
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
122
147
|
const { calls, spawn } = recorder();
|
|
123
|
-
await
|
|
124
|
-
expect(calls).toEqual([]);
|
|
148
|
+
await runUnitTests(root, spawn);
|
|
149
|
+
expect(benchCalls(calls)).toEqual([]);
|
|
125
150
|
expect(warn).toHaveBeenCalledWith(
|
|
126
|
-
'no frappe bench (apps/frappe/sites): skipped bench tests -m "integration"',
|
|
151
|
+
'no frappe bench (apps/frappe/sites): skipped bench tests -m "not integration"',
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("integration fails on a bench that is not bootstrapped, naming it (FZ-10556)", async () => {
|
|
156
|
+
plantBench(root, { bootstrapped: false });
|
|
157
|
+
const { calls, spawn } = recorder();
|
|
158
|
+
await expect(runIntegrationTests(root, spawn)).rejects.toThrow(
|
|
159
|
+
'no frappe bench (apps/frappe/sites): bench tests -m "integration" need one',
|
|
160
|
+
);
|
|
161
|
+
expect(benchCalls(calls)).toEqual([]);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("integration with no frappe apps runs only test:integration", async () => {
|
|
165
|
+
const { calls, spawn } = recorder();
|
|
166
|
+
await runIntegrationTests(root, spawn);
|
|
167
|
+
expect(calls.map((call) => [call.file, ...call.args])).toEqual([
|
|
168
|
+
["pnpm", "turbo", "run", "test:integration", "--continue"],
|
|
169
|
+
]);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("the e2e app (FZ-10556)", () => {
|
|
174
|
+
let root: string;
|
|
175
|
+
|
|
176
|
+
beforeEach(() => {
|
|
177
|
+
root = mkdtempSync(join(tmpdir(), "mpo-e2e-app-spec-"));
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
afterEach(() => {
|
|
181
|
+
rmSync(root, { recursive: true, force: true });
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("is the app whose package.json names it, not the first with a playwright config", async () => {
|
|
185
|
+
write(root, "apps/frappe/package.json", JSON.stringify({ name: "@service/frappe" }));
|
|
186
|
+
write(root, "apps/frappe/playwright.config.ts", "");
|
|
187
|
+
write(
|
|
188
|
+
root,
|
|
189
|
+
"apps/one/package.json",
|
|
190
|
+
JSON.stringify({ name: "@platform/one", mpo: { e2e: true } }),
|
|
191
|
+
);
|
|
192
|
+
write(root, "apps/one/playwright.config.ts", "");
|
|
193
|
+
expect(await discoverE2EApp(root)).toBe("one");
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("is none when no app names itself", async () => {
|
|
197
|
+
write(root, "apps/one/package.json", JSON.stringify({ name: "@platform/one" }));
|
|
198
|
+
write(root, "apps/one/playwright.config.ts", "");
|
|
199
|
+
expect(await discoverE2EApp(root)).toBeNull();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("refuses two apps that both name themselves", async () => {
|
|
203
|
+
write(
|
|
204
|
+
root,
|
|
205
|
+
"apps/one/package.json",
|
|
206
|
+
JSON.stringify({ name: "@platform/one", mpo: { e2e: true } }),
|
|
207
|
+
);
|
|
208
|
+
write(
|
|
209
|
+
root,
|
|
210
|
+
"apps/two/package.json",
|
|
211
|
+
JSON.stringify({ name: "@platform/two", mpo: { e2e: true } }),
|
|
212
|
+
);
|
|
213
|
+
await expect(discoverE2EApp(root)).rejects.toThrow(
|
|
214
|
+
'more than one app sets "mpo": { "e2e": true } in its package.json: one, two. ' +
|
|
215
|
+
"Keep it on the one app mpo test e2e should run and delete it from the others.",
|
|
127
216
|
);
|
|
128
217
|
});
|
|
129
218
|
});
|
package/src/commands/verbs.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
} from "@multiplatform.one/utils/dev";
|
|
11
11
|
import nanoSpawn from "nano-spawn";
|
|
12
12
|
import YAML from "yaml";
|
|
13
|
-
import { discoverE2EApp } from "./e2e";
|
|
14
13
|
|
|
15
14
|
type Spawn = typeof nanoSpawn;
|
|
16
15
|
|
|
@@ -126,15 +125,24 @@ export function parseTestTiers(args: string[]): TestTier[] {
|
|
|
126
125
|
/**
|
|
127
126
|
* `bench run-tests` for every frappe app with a pyproject.toml, limited to the
|
|
128
127
|
* pytest marker expression. Skipped when the bench is not bootstrapped
|
|
129
|
-
* (no apps/frappe/sites)
|
|
128
|
+
* (no apps/frappe/sites), or failed when `required`; once it is, any app
|
|
129
|
+
* whose run fails fails the tier.
|
|
130
130
|
*/
|
|
131
|
-
async function runBenchTests(
|
|
131
|
+
async function runBenchTests(
|
|
132
|
+
projectRoot: string,
|
|
133
|
+
marker: string,
|
|
134
|
+
spawn: Spawn,
|
|
135
|
+
required: boolean,
|
|
136
|
+
): Promise<void> {
|
|
132
137
|
const benchDir = path.join(projectRoot, "apps", "frappe");
|
|
133
138
|
const apps = (await getFrappeApps(projectRoot)).filter((app) =>
|
|
134
139
|
fsSync.existsSync(path.join(app.absolutePath, "pyproject.toml")),
|
|
135
140
|
);
|
|
136
141
|
if (!apps.length) return;
|
|
137
142
|
if (!fsSync.existsSync(path.join(benchDir, "sites"))) {
|
|
143
|
+
if (required) {
|
|
144
|
+
throw new Error(`no frappe bench (apps/frappe/sites): bench tests -m "${marker}" need one`);
|
|
145
|
+
}
|
|
138
146
|
console.warn(`no frappe bench (apps/frappe/sites): skipped bench tests -m "${marker}"`);
|
|
139
147
|
return;
|
|
140
148
|
}
|
|
@@ -155,28 +163,41 @@ async function runBenchTests(projectRoot: string, marker: string, spawn: Spawn):
|
|
|
155
163
|
}
|
|
156
164
|
}
|
|
157
165
|
|
|
158
|
-
/** The unit tier: turbo test minus missing services
|
|
166
|
+
/** The unit tier: turbo test minus missing services, then the bench's non-integration tests. */
|
|
159
167
|
export async function runUnitTests(projectRoot: string, spawn: Spawn = nanoSpawn): Promise<void> {
|
|
160
168
|
const excludeFilters = await getTurboExcludeFiltersForMissing(projectRoot);
|
|
161
|
-
const
|
|
162
|
-
const filters = [
|
|
163
|
-
...excludeFilters.flatMap((f) => ["--filter", f]),
|
|
164
|
-
...(e2eApp ? ["--filter", `'!./apps/${e2eApp}'`] : []),
|
|
165
|
-
];
|
|
169
|
+
const filters = excludeFilters.flatMap((f) => ["--filter", f]);
|
|
166
170
|
await spawn("pnpm", ["turbo", "run", "test", ...filters], {
|
|
167
171
|
stdio: "inherit",
|
|
168
172
|
shell: true,
|
|
169
173
|
cwd: projectRoot,
|
|
170
174
|
});
|
|
171
|
-
await runBenchTests(projectRoot, "not integration", spawn);
|
|
175
|
+
await runBenchTests(projectRoot, "not integration", spawn, false);
|
|
172
176
|
}
|
|
173
177
|
|
|
174
|
-
/** The integration tier: the bench's integration-marked tests
|
|
178
|
+
/** The integration tier: turbo test:integration, then the bench's integration-marked tests; a missing service fails it. */
|
|
175
179
|
export async function runIntegrationTests(
|
|
176
180
|
projectRoot: string,
|
|
177
181
|
spawn: Spawn = nanoSpawn,
|
|
178
182
|
): Promise<void> {
|
|
179
|
-
await
|
|
183
|
+
const excludeFilters = await getTurboExcludeFiltersForMissing(projectRoot);
|
|
184
|
+
const filters = excludeFilters.flatMap((f) => ["--filter", f]);
|
|
185
|
+
const failures: string[] = [];
|
|
186
|
+
try {
|
|
187
|
+
await spawn("pnpm", ["turbo", "run", "test:integration", "--continue", ...filters], {
|
|
188
|
+
stdio: "inherit",
|
|
189
|
+
shell: true,
|
|
190
|
+
cwd: projectRoot,
|
|
191
|
+
});
|
|
192
|
+
} catch (error) {
|
|
193
|
+
failures.push((error as Error).message);
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
await runBenchTests(projectRoot, "integration", spawn, true);
|
|
197
|
+
} catch (error) {
|
|
198
|
+
failures.push((error as Error).message);
|
|
199
|
+
}
|
|
200
|
+
if (failures.length) throw new Error(failures.join("\n"));
|
|
180
201
|
}
|
|
181
202
|
|
|
182
203
|
/** `mpo build`: the packages, then every present app with a build script, each once. */
|
package/types/commands/e2e.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export interface E2EOptions {
|
|
|
6
6
|
noBuild?: boolean;
|
|
7
7
|
filter?: string;
|
|
8
8
|
}
|
|
9
|
-
/** Discover app
|
|
9
|
+
/** Discover the app whose package.json names it the e2e app (`"mpo": { "e2e": true }`), for E2E test cwd. Returns app name (e.g. "one") or null. */
|
|
10
10
|
export declare function discoverE2EApp(projectRoot: string): Promise<string | null>;
|
|
11
11
|
export declare function detectServices(projectRoot: string): Promise<string[]>;
|
|
12
12
|
export declare function generateCompose(services: string[], portOffset: number, projectRoot: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"e2e.d.ts","sourceRoot":"","sources":["../../src/commands/e2e.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAmDD,
|
|
1
|
+
{"version":3,"file":"e2e.d.ts","sourceRoot":"","sources":["../../src/commands/e2e.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAmDD,oJAAoJ;AACpJ,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAehF;AAED,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAkB3E;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAAE,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB,MAAM,CAsBR;AAiHD,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA+G3F"}
|
|
@@ -27,7 +27,7 @@ export declare class ScaffoldError extends Error {
|
|
|
27
27
|
constructor(message: string, request: ScaffoldRequest);
|
|
28
28
|
}
|
|
29
29
|
/** Run scaffold.sh and return the provenance it wrote. */
|
|
30
|
-
export declare function runScaffold(request: ScaffoldRequest): Promise<MpoProvenance>;
|
|
30
|
+
export declare function runScaffold(request: ScaffoldRequest, script?: string): Promise<MpoProvenance>;
|
|
31
31
|
export interface TempScaffold {
|
|
32
32
|
dir: string;
|
|
33
33
|
provenance: MpoProvenance;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/commands/scaffold.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAE3E,oFAAoF;AACpF,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,uCAAuC;IACvC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;gBACtB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe;CAItD;AAcD,0DAA0D;AAC1D,wBAAsB,WAAW,
|
|
1
|
+
{"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../../src/commands/scaffold.ts"],"names":[],"mappings":"AAKA,OAAO,EAA2B,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAE3E,oFAAoF;AACpF,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED,MAAM,WAAW,eAAe;IAC9B,0CAA0C;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,0CAA0C;IAC1C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,uCAAuC;IACvC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;gBACtB,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe;CAItD;AAcD,0DAA0D;AAC1D,wBAAsB,WAAW,CAC/B,OAAO,EAAE,eAAe,EACxB,MAAM,SAAmB,GACxB,OAAO,CAAC,aAAa,CAAC,CA2BxB;AAED,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,aAAa,CAAC;IAC1B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAmDD,kDAAkD;AAClD,wBAAsB,cAAc,CAClC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,MAAM,CAAC,GAChD,OAAO,CAAC,YAAY,CAAC,CAgBvB;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAiBf"}
|
|
@@ -6,9 +6,9 @@ export declare const testTiers: readonly ["unit", "integration", "e2e", "visual"
|
|
|
6
6
|
export type TestTier = (typeof testTiers)[number];
|
|
7
7
|
/** The tiers `mpo test` was asked for (comma or space separated); unit when none is named. */
|
|
8
8
|
export declare function parseTestTiers(args: string[]): TestTier[];
|
|
9
|
-
/** The unit tier: turbo test minus missing services
|
|
9
|
+
/** The unit tier: turbo test minus missing services, then the bench's non-integration tests. */
|
|
10
10
|
export declare function runUnitTests(projectRoot: string, spawn?: Spawn): Promise<void>;
|
|
11
|
-
/** The integration tier: the bench's integration-marked tests
|
|
11
|
+
/** The integration tier: turbo test:integration, then the bench's integration-marked tests; a missing service fails it. */
|
|
12
12
|
export declare function runIntegrationTests(projectRoot: string, spawn?: Spawn): Promise<void>;
|
|
13
13
|
/** `mpo build`: the packages, then every present app with a build script, each once. */
|
|
14
14
|
export declare function runBuild(args: string[], projectRoot: string, spawn?: Spawn): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verbs.d.ts","sourceRoot":"","sources":["../../src/commands/verbs.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,SAAS,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"verbs.d.ts","sourceRoot":"","sources":["../../src/commands/verbs.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAE9B,eAAO,MAAM,iBAAiB,UAA0C,CAAC;AA8FzE,eAAO,MAAM,SAAS,mDAAoD,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAQzD;AA2CD,gGAAgG;AAChG,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/F;AAED,2HAA2H;AAC3H,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED,wFAAwF;AACxF,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EAAE,EACd,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CA4Cf;AAED,sFAAsF;AACtF,wBAAsB,YAAY,CAChC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,0GAA0G;AAC1G,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EAAE,EACd,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,0DAA0D;AAC1D,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAKlF,CAAC"}
|