Skip to content

Commit 72e2e7b

Browse files
committed
Merge shared journal foundation into #1360
2 parents dcf590c + b8aa8db commit 72e2e7b

22 files changed

Lines changed: 702 additions & 126 deletions

‎.github/workflows/ci.yml‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,20 @@ jobs:
186186
- name: Check REPL bench tools
187187
working-directory: repl bench checkout
188188
run: |
189-
deno test --allow-all --cached-only --frozen --node-modules-dir=none \
189+
deno test --reporter=dot --allow-all --cached-only --frozen --node-modules-dir=none \
190190
--ignore=examples/repl-bench/tests/driver-exit.test.ts,examples/repl-bench/tests/teardown.test.ts \
191191
examples/repl-bench/tests
192192
193193
- name: Exercise the REPL through a host terminal
194194
if: github.event_name == 'push'
195195
working-directory: repl bench checkout
196196
run: |
197-
deno test --allow-all --cached-only --frozen --node-modules-dir=none \
197+
deno test --reporter=dot --allow-all --cached-only --frozen --node-modules-dir=none \
198198
examples/repl-bench/tests/driver-exit.test.ts \
199199
examples/repl-bench/tests/teardown.test.ts
200+
echo "Running Markdown REPL Bench journeys"
200201
deno run --allow-all --cached-only --frozen --node-modules-dir=none \
201-
packages/cli/src/deno.ts test examples/repl-bench/journeys
202+
packages/cli/src/deno.ts test examples/repl-bench/journeys --reporter=failures
202203
203204
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
204205
if: github.event_name == 'push' && (failure() || cancelled())
@@ -284,19 +285,19 @@ jobs:
284285
./dist/xmd test smoke-test/README.md \
285286
--include smoke-test \
286287
--include packages/core/components \
287-
--raw
288+
--reporter=failures
288289
289290
# Progress on stderr and a failed test's journal, from the binary rather
290291
# than the source entrypoint the runtime shards launch.
291292
- name: Test diagnostics from the compiled binary
292-
run: deno test --allow-all --frozen scripts/tests/test-diagnostics-compiled.test.ts
293+
run: deno test --reporter=dot --allow-all --frozen scripts/tests/test-diagnostics-compiled.test.ts
293294

294295
- name: Smoke test attached-service ping-pong with the compiled binary
295296
run: |
296297
./dist/xmd test smoke-test/attached-service-ping-pong.test.md \
297298
--include smoke-test \
298299
--include packages/core/components \
299-
--raw
300+
--reporter=failures
300301
301302
# Foreground execution is about what a caller sees and what status they
302303
# get, and only the binary shows both surviving `deno compile`.
@@ -314,14 +315,14 @@ jobs:
314315
# search path supplied the implementation. It lives here because its
315316
# subject is `dist/xmd`, and this is the job that builds one.
316317
- name: Form dispatch across the compiled binary's loaded copies
317-
run: deno test --allow-all --frozen scripts/tests/component-form-dispatch.test.ts
318+
run: deno test --reporter=dot --allow-all --frozen scripts/tests/component-form-dispatch.test.ts
318319

319320
# `<Plan>` is packaged Markdown rather than a module, so it is exactly the
320321
# kind of thing `deno compile` ships only because an `--include` names it.
321322
# Asking the binary which Component source it carries is what catches a forgotten
322323
# include here rather than at a person's first `xmd plan`.
323324
- name: The <Plan> Component the compiled binary carries
324-
run: deno test --allow-all --frozen scripts/tests/plan-component-compiled.test.ts
325+
run: deno test --reporter=dot --allow-all --frozen scripts/tests/plan-component-compiled.test.ts
325326

326327
# The compiled entrypoint states its own Prompt usage host facts, a
327328
# different assembly from the source CLI's, so its carriage is asserted
@@ -336,13 +337,13 @@ jobs:
336337
# reopened location. This drives the same journey the source row drives,
337338
# on a real terminal, against the binary this job just built.
338339
- name: A REPL entry's files across the compiled binary
339-
run: deno test --allow-all --frozen scripts/tests/repl-repositories-compiled.test.ts
340+
run: deno test --reporter=dot --allow-all --frozen scripts/tests/repl-repositories-compiled.test.ts
340341

341342
- name: A REPL entry's issues across the compiled binary
342-
run: deno test --allow-all --frozen scripts/tests/repl-issues-compiled.test.ts
343+
run: deno test --reporter=dot --allow-all --frozen scripts/tests/repl-issues-compiled.test.ts
343344

344345
- name: A REPL entry's publications across the compiled binary
345-
run: deno test --allow-all --frozen scripts/tests/repl-push-compiled.test.ts
346+
run: deno test --reporter=dot --allow-all --frozen scripts/tests/repl-push-compiled.test.ts
346347

347348
# Each package's `components.md` is a packaged asset on the same footing,
348349
# and the long-form documentation is the only thing that reports whether
@@ -374,7 +375,7 @@ jobs:
374375
# source at once — the built-in components under `components/`, and the
375376
# structural directives, which resolve no file at all.
376377
- name: Smoke test the built-ins with no search path
377-
run: ./dist/xmd test packages/core/src --raw
378+
run: ./dist/xmd test packages/core/src --reporter=failures
378379

379380
# An inline root document exercises the compiled module graph the same way
380381
# a file does, and only the binary proves the graph survived `deno compile`.
@@ -520,13 +521,13 @@ jobs:
520521
# Covers the compiled binary relaunching itself as `xmd test-agent`,
521522
# which the source-mode worker command never exercises.
522523
- name: Smoke test the compiled binary as a test agent
523-
run: ./dist/xmd test smoke-test/test-agent/README.md --raw
524+
run: ./dist/xmd test smoke-test/test-agent/README.md --reporter=failures
524525

525526
- name: Smoke test xmd run through ACPX
526527
run: |
527528
./dist/xmd test smoke-test/agent/README.md \
528529
--include smoke-test/agent/components \
529-
--raw
530+
--reporter=failures
530531
531532
# A failed or cancelled run leaves the journals of the executions that
532533
# failed; a passing one uploads nothing.
@@ -611,7 +612,7 @@ jobs:
611612
# each rewrite `node_modules` into their own layout, so a Deno step after
612613
# one of them resolves through links the other pruned (#279).
613614
- name: Host contract under Deno
614-
run: deno test --allow-all --frozen packages/runtime/tests/host-files.test.ts
615+
run: deno test --reporter=dot --allow-all --frozen packages/runtime/tests/host-files.test.ts
615616

616617
- name: Host contract as a compiled binary
617618
run: |

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ documents. Name an affected suite's path instead, beside any TypeScript paths:
224224
deno task test examples/adversarial-implementation/tests/Implementation.test.md
225225
```
226226

227+
Call `xmd test` directly to choose the reporter for a Markdown test.
228+
229+
```bash
230+
deno task xmd test examples/adversarial-implementation/tests/Implementation.test.md --reporter=failures
231+
```
232+
233+
[Choose a test reporter](specs/testing-spec.md#choose-a-reporter).
234+
227235
### Complete
228236

229237
Run the complete applicable battery concurrently, yielding delivery

‎deno.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@durable-streams/server": "npm:@durable-streams/server@^0.3.8",
2121
"@executablemd/test-support/bdd": "./packages/test-support/bdd.ts",
2222
"@executablemd/test-support/expect": "./packages/test-support/expect.ts",
23+
"@executablemd/test-support/failure-journal": "./packages/test-support/failure-journal.ts",
2324
"@executablemd/test-support/journal": "./packages/test-support/journal.ts",
2425
"@executablemd/test-support/launch": "./packages/test-support/launch.ts",
2526
"@effectionx/test-adapter": "npm:@effectionx/test-adapter@0.7.4",

‎packages/cli/src/cli.ts‎

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ const planConfig = object({
430430
},
431431
});
432432

433+
const TEST_REPORTER_OPTION = "--reporter";
434+
const testReporter = z.enum(["pretty", "failures"]);
435+
433436
const testConfig = object({
434437
path: {
435438
description: "markdown document or directory to test (defaults to the current directory)",
@@ -439,6 +442,10 @@ const testConfig = object({
439442
description: "glob for test documents, relative to a directory target (repeatable)",
440443
...field(z.array(z.string()), field.default(["**/*.test.md"]), field.array()),
441444
},
445+
reporter: {
446+
description: "test output: pretty (default) or failures",
447+
...field(testReporter, field.default("pretty")),
448+
},
442449
include: {
443450
description: "component search directory",
444451
...field(z.array(z.string()), field.default(["components", "."]), field.array()),
@@ -1776,17 +1783,23 @@ type TestPlugins = (document: string) => Operation<CommandPlugins>;
17761783
/**
17771784
* `xmd test` — one document, or every document a directory holds.
17781785
*
1779-
* A directory keeps going after a failure and decides the status once at the
1780-
* end. A single document behaves exactly as it always has: one reported
1781-
* failure, no heading, no summary.
1786+
* A directory runs every matching document and settles the exit status once.
17821787
*/
17831788
function* test(
17841789
config: TestConfig,
17851790
args: string[],
17861791
installService: HostServiceInstaller,
17871792
testPlugins: TestPlugins,
17881793
): Operation<void> {
1789-
const patterns = readPatternFlags(args);
1794+
const reporterFlags = readTestOption(args, TEST_REPORTER_OPTION);
1795+
const reporter = testReporter.safeParse(reporterFlags.values[0] ?? "pretty");
1796+
if (reporterFlags.missingValue || reporterFlags.values.length > 1 || !reporter.success) {
1797+
console.error("--reporter accepts one value: pretty or failures");
1798+
yield* exit(1);
1799+
return;
1800+
}
1801+
const failuresOnly = reporter.data === "failures";
1802+
const patterns = readTestOption(args, PATTERN_OPTION);
17901803
if (patterns.missingValue) {
17911804
console.error(
17921805
`${PATTERN_OPTION} requires a value — write \`${PATTERN_OPTION} <glob>\`, or ` +
@@ -1814,14 +1827,27 @@ function* test(
18141827
return;
18151828
}
18161829
announceSecretDetection(config.secretDetection);
1817-
const { value: result, delivery } = yield* withTestProgress((diagnostics) =>
1818-
runTestDocument({ ...config, root: { path } }, testPlugins, installService, diagnostics),
1830+
const {
1831+
value: result,
1832+
delivery,
1833+
summary,
1834+
} = yield* withTestProgress(failuresOnly, (diagnostics) =>
1835+
runTestDocument(
1836+
{ ...config, root: { path }, discardOutput: failuresOnly },
1837+
testPlugins,
1838+
installService,
1839+
diagnostics,
1840+
),
18191841
);
18201842
if (!result.ok) {
18211843
reportFailure(result.error);
1822-
yield* exit(1);
18231844
} else if (!delivery.ok) {
18241845
reportFailure(delivery.error);
1846+
}
1847+
if (failuresOnly) {
1848+
console.error(summary);
1849+
}
1850+
if (!result.ok || !delivery.ok) {
18251851
yield* exit(1);
18261852
}
18271853
return;
@@ -1847,15 +1873,22 @@ function* test(
18471873
// and a directory of fifty documents would otherwise say so fifty times.
18481874
announceSecretDetection(config.secretDetection);
18491875

1850-
const { value: failures, delivery } = yield* withTestProgress(function* (diagnostics) {
1876+
const {
1877+
value: failures,
1878+
delivery,
1879+
summary,
1880+
} = yield* withTestProgress(failuresOnly, function* (diagnostics) {
18511881
const failed: string[] = [];
18521882
for (const document of target.documents) {
1853-
process.stdout.write(`\n# ${document.relativePath}\n\n`);
1883+
if (!failuresOnly) {
1884+
process.stdout.write(`\n# ${document.relativePath}\n\n`);
1885+
}
18541886
const result = yield* runTestDocument(
18551887
{
18561888
...config,
18571889
root: { path: document.path },
18581890
include: componentSearchPath(document, target.root, config.include),
1891+
discardOutput: failuresOnly,
18591892
},
18601893
testPlugins,
18611894
installService,
@@ -1869,11 +1902,19 @@ function* test(
18691902
return failed;
18701903
});
18711904

1872-
if (failures.length > 0) {
1873-
console.error(`\n${failures.length} of ${target.documents.length} documents failed`);
1874-
yield* exit(1);
1875-
} else if (!delivery.ok) {
1905+
const failedDocuments =
1906+
failures.length > 0
1907+
? `${failures.length} of ${target.documents.length} documents failed`
1908+
: undefined;
1909+
if (failedDocuments === undefined && !delivery.ok) {
18761910
reportFailure(delivery.error);
1911+
}
1912+
if (failuresOnly) {
1913+
console.error(failedDocuments === undefined ? summary : `${summary} · ${failedDocuments}`);
1914+
} else if (failedDocuments !== undefined) {
1915+
console.error(`\n${failedDocuments}`);
1916+
}
1917+
if (failures.length > 0 || !delivery.ok) {
18771918
yield* exit(1);
18781919
}
18791920
}
@@ -1886,15 +1927,22 @@ function* test(
18861927
* returns, so whatever the command reports next follows them.
18871928
*/
18881929
function* withTestProgress<T>(
1930+
failuresOnly: boolean,
18891931
body: (diagnostics: TestDiagnostics) => Operation<T>,
1890-
): Operation<{ value: T; delivery: Result<void> }> {
1891-
let delivery: () => Result<void> = () => Ok(undefined);
1892-
const value = yield* scoped(function* () {
1893-
const diagnostics = yield* useTestDiagnostics(process.stderr);
1894-
delivery = diagnostics.delivery;
1895-
return yield* body(diagnostics);
1932+
): Operation<{ value: T; delivery: Result<void>; summary: string }> {
1933+
const started = performance.now();
1934+
const run = yield* scoped(function* () {
1935+
const diagnostics = yield* useTestDiagnostics(process.stderr, failuresOnly);
1936+
const value = yield* body(diagnostics);
1937+
return { value, diagnostics };
18961938
});
1897-
return { value, delivery: delivery() };
1939+
const { pass, fail } = run.diagnostics.results();
1940+
const elapsed = Math.round(performance.now() - started);
1941+
return {
1942+
value: run.value,
1943+
delivery: run.diagnostics.delivery(),
1944+
summary: `[xmd test] ${pass} passed | ${fail} failed (${elapsed}ms)`,
1945+
};
18981946
}
18991947

19001948
/**
@@ -2002,15 +2050,13 @@ function findPropsFlag(args: string[]): string | undefined {
20022050

20032051
const PATTERN_OPTION = "--pattern";
20042052

2005-
interface PatternFlags {
2006-
/** Values the caller wrote, in the order they wrote them. */
2053+
interface TestOption {
20072054
values: string[];
2008-
/** A `--pattern` that ran out of argv or was followed by another option. */
20092055
missingValue: boolean;
20102056
}
20112057

20122058
/**
2013-
* Read `--pattern` from argv.
2059+
* Read an explicitly supplied test option from argv.
20142060
*
20152061
* The resolved configuration answers none of the questions this serves. It
20162062
* cannot say whether the option was given at all — the default is a real
@@ -2021,15 +2067,15 @@ interface PatternFlags {
20212067
* A separated value that begins with `-` is another option, not a glob;
20222068
* `--pattern=<glob>` expresses a glob that really does begin with one.
20232069
*/
2024-
function readPatternFlags(args: string[]): PatternFlags {
2070+
function readTestOption(args: string[], option: string): TestOption {
20252071
const values: string[] = [];
20262072
let missingValue = false;
20272073

20282074
for (const [index, arg] of args.entries()) {
20292075
if (arg === "--") {
20302076
break;
20312077
}
2032-
if (arg === PATTERN_OPTION) {
2078+
if (arg === option) {
20332079
const value = args[index + 1];
20342080
if (value === undefined || value.startsWith("-")) {
20352081
missingValue = true;
@@ -2038,8 +2084,8 @@ function readPatternFlags(args: string[]): PatternFlags {
20382084
values.push(value);
20392085
continue;
20402086
}
2041-
if (arg.startsWith(`${PATTERN_OPTION}=`)) {
2042-
values.push(arg.slice(PATTERN_OPTION.length + 1));
2087+
if (arg.startsWith(`${option}=`)) {
2088+
values.push(arg.slice(option.length + 1));
20432089
}
20442090
}
20452091

0 commit comments

Comments
 (0)