Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/repl-bench/tests/mounted-typing.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it } from "@executablemd/test-support/bdd";
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
import { journalBeforeEach } from "@executablemd/test-support/failure-journal";
import { expect } from "@executablemd/test-support/expect";
import type { Operation } from "effection";
import { useReplPage } from "../../../packages/cli/tests/support/repl-page.ts";
Expand All @@ -11,6 +12,8 @@ import { generateTypingHistory } from "../../../packages/cli/tests/support/typin
import { EDITS, VIEWPORT, WARMUP, WORKLOADS } from "../lib/typing-latency-report.ts";
import type { TypingSample } from "../lib/typing-latency-report.ts";

const OWNER = "examples/repl-bench/tests/mounted-typing.test.ts";

const MARKER = "XMD:";
const CHARACTERS = "abcdefghijklmnopqrstuvwxyz".repeat(2).slice(0, EDITS);
const revision = Deno.env.get("XMD_TYPING_BENCH_REVISION");
Expand Down Expand Up @@ -62,6 +65,7 @@ function* sampleTyping(page: ReplPage): Operation<TypingSample[]> {

if (revision !== undefined) {
describe("mounted REPL typing latency", () => {
beforeEach(journalBeforeEach(OWNER));
for (const workload of WORKLOADS) {
it(workload.name, function* () {
const page = yield* useReplPage({ size: VIEWPORT });
Expand Down
55 changes: 41 additions & 14 deletions packages/cli/src/test-diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type { DurableEvent } from "@executablemd/durable-streams";
import { Test, testing } from "@executablemd/testing";
import type { FailureJournalHost, TestResult } from "@executablemd/testing";
import { randomUUID } from "node:crypto";
import { isAbsolute, join, relative, resolve, sep } from "node:path";
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
import { deliverWhole } from "./stdout-delivery.ts";
import type { DeliverySink } from "./stdout-delivery.ts";

Expand Down Expand Up @@ -79,6 +79,20 @@ export interface ExecutionDiagnostics {
observe(): Operation<void>;
/** Saves this execution's journal when `failed` says its outcome failed. */
journal<T>(failed: (value: T) => boolean): FailureJournalHost<T>;
/**
* Saves journal files a host wrote for this execution, as the UTF-8 text
* they held, beneath one directory named like this execution's journal.
*
* `path` is each file's place beneath the storage root, so two files of one
* root keep the names that tell them apart.
*/
saveFiles(files: readonly SavedJournalFile[]): Operation<void>;
}

/** One journal file as its host wrote it. */
export interface SavedJournalFile {
readonly path: string;
readonly text: string;
}

/**
Expand Down Expand Up @@ -167,6 +181,22 @@ function testDiagnosticsAt(
const displayedSource = shown(source);
const named = `${kind} ${ordinal} ${displayedSource}${profile === undefined ? "" : ` (${profile})`}`;
const context = kind === "root" ? "" : `${named}: `;
function* identify(files?: readonly string[]): Operation<void> {
yield* ensureDir(directory);
if (attribution !== undefined) {
yield* writeTextFile(
`${stem}.case.json`,
JSON.stringify({
...attribution,
kind,
ordinal,
source: displayedSource,
profile,
files,
}) + "\n",
);
}
}
return {
observe: () =>
observe(
Expand All @@ -186,19 +216,7 @@ function testDiagnosticsAt(
journal: <T>(failed: (value: T) => boolean): FailureJournalHost<T> => ({
failed,
*save(events: readonly DurableEvent[]) {
yield* ensureDir(directory);
if (attribution !== undefined) {
yield* writeTextFile(
`${stem}.case.json`,
JSON.stringify({
...attribution,
kind,
ordinal,
source: displayedSource,
profile,
}) + "\n",
);
}
yield* identify();
yield* writeTextFile(file, events.map(serializeDurableEvent).join(""));
emit(`journal saved: ${file} (${named})`);
},
Expand All @@ -207,6 +225,15 @@ function testDiagnosticsAt(
emit(`journal not saved for ${named}: ${error.message}`);
},
}),
*saveFiles(files: readonly SavedJournalFile[]) {
yield* identify(files.map(({ path }) => path));
for (const { path, text } of files) {
const target = join(stem, path);
yield* ensureDir(dirname(target));
yield* writeTextFile(target, text);
}
emit(`journal saved: ${stem} (${named})`);
},
};
},
delivery: () => delivery,
Expand Down
Loading
Loading