Skip to content

Commit 464b186

Browse files
authored
[Journal migration] Attribute retained repository observation test journals (#1375)
* Restack retained observation journal coverage on main * Remove unused retained observation journal helper
1 parent 78b60b0 commit 464b186

3 files changed

Lines changed: 159 additions & 173 deletions

File tree

‎packages/cli/tests/retained-repository-observations-deno.test.ts‎

Lines changed: 79 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* interrupted-child and fatal-append cases, all run on every runtime.
1818
*/
1919

20-
import { describe, it } from "@executablemd/test-support/bdd";
20+
import { beforeEach, describe, it } from "@executablemd/test-support/bdd";
2121
import { expect } from "@executablemd/test-support/expect";
2222
import { race, scoped, sleep, spawn, withResolvers } from "effection";
2323
import type { Operation } from "effection";
@@ -26,13 +26,13 @@ import { join } from "node:path";
2626
import { InMemoryStream } from "@executablemd/durable-streams";
2727
import type { DurableEvent, DurableStream } from "@executablemd/durable-streams";
2828
import { registerComponents } from "@executablemd/core";
29+
import { journalBeforeEach, useJournalStream } from "@executablemd/test-support/failure-journal";
2930
import {
3031
parseReplObservationRecord,
3132
REPL_REPOSITORY_OBSERVATION,
3233
} from "../src/repl/repositories/observation-records.ts";
3334
import { useObservationFixture, writeFixtureFile } from "../../git/tests/support/observations.ts";
3435
import {
35-
captureObservationEntry,
3636
entryCounters,
3737
methodsCalled,
3838
readKinds,
@@ -76,6 +76,7 @@ function observations(events: readonly DurableEvent[]) {
7676
}
7777

7878
describe("ROB5 — cancellation, persistence and ownership, on a native host", () => {
79+
beforeEach(journalBeforeEach("packages/cli/tests/retained-repository-observations-deno.test.ts"));
7980
it("leaves no completion when a finished read's append is cancelled", function* () {
8081
const fixture = yield* useObservationFixture();
8182
const place = yield* useEntryPlace(fixture);
@@ -140,91 +141,87 @@ describe("ROB5 — cancellation, persistence and ownership, on a native host", (
140141
let holding = false;
141142
let enteredWhileHeld = false;
142143

143-
yield* captureObservationEntry(
144-
{ owner: "packages/cli/tests/retained-repository-observations-deno.test.ts", name: heldRead },
145-
place,
146-
function* (stream) {
147-
const settled = yield* scoped(function* () {
148-
const task = yield* spawn(() =>
149-
runEntry(
150-
place,
151-
[
152-
"<All>",
153-
'<Spawn><Git.Diff compare="unstaged" as="patch" /></Spawn>',
154-
'<Spawn><WaitsForTheRead /><Git.Add paths="src/a.ts" /></Spawn>',
155-
"</All>",
156-
"",
157-
].join("\n"),
158-
stream,
159-
counted,
160-
{
161-
*between(): Operation<void> {
162-
// The second branch starts its mutation only once the read is
163-
// genuinely held, so the race the regression needs is arranged
164-
// rather than hoped for.
165-
yield* registerComponents([
166-
{
167-
name: "WaitsForTheRead",
168-
origin: "test://waits-for-the-read",
169-
props: { type: "object", properties: {}, additionalProperties: false },
170-
*fn(): Operation<string> {
171-
yield* readHeld.operation;
172-
return "";
173-
},
174-
},
175-
]);
144+
const stream = yield* useJournalStream(join(place.root, "entry.md"));
145+
const settled = yield* scoped(function* () {
146+
const task = yield* spawn(() =>
147+
runEntry(
148+
place,
149+
[
150+
"<All>",
151+
'<Spawn><Git.Diff compare="unstaged" as="patch" /></Spawn>',
152+
'<Spawn><WaitsForTheRead /><Git.Add paths="src/a.ts" /></Spawn>',
153+
"</All>",
154+
"",
155+
].join("\n"),
156+
stream,
157+
counted,
158+
{
159+
*between(): Operation<void> {
160+
// The second branch starts its mutation only once the read is
161+
// genuinely held, so the race the regression needs is arranged
162+
// rather than hoped for.
163+
yield* registerComponents([
164+
{
165+
name: "WaitsForTheRead",
166+
origin: "test://waits-for-the-read",
167+
props: { type: "object", properties: {}, additionalProperties: false },
168+
*fn(): Operation<string> {
169+
yield* readHeld.operation;
170+
return "";
171+
},
176172
},
177-
*barrier(method): Operation<void> {
178-
if (method === "add") {
179-
if (holding) {
180-
enteredWhileHeld = true;
181-
}
182-
mutationEntered.resolve();
183-
return;
184-
}
185-
if (method === "observe" && !holding) {
186-
holding = true;
187-
readHeld.resolve();
188-
// Long enough that a mutation on a queue of its own would have
189-
// reached the host by now, and short enough to end the case.
190-
yield* race([
191-
mutationEntered.operation,
192-
(function* (): Operation<void> {
193-
yield* sleep(2000);
194-
})(),
195-
]);
196-
holding = false;
197-
releaseRead.resolve();
198-
}
199-
},
200-
},
201-
),
202-
);
203-
yield* releaseRead.operation;
204-
// The read has finished its own turn; the mutation may now proceed.
205-
yield* race([
206-
mutationEntered.operation,
207-
(function* (): Operation<void> {
208-
yield* sleep(30_000);
209-
throw new Error("the mutation never reached native Git");
210-
})(),
211-
]);
212-
return yield* task;
213-
});
214-
215-
// Nothing of this entry's own Git entered while its read held the turn,
216-
// and the mutation did run once the read released it.
217-
expect(enteredWhileHeld).toBe(false);
218-
expect(settled.refusal).toBe(undefined);
219-
expect(readKinds(counted)).toContain("diff");
220-
expect(methodsCalled(counted)).toContain("add");
221-
},
222-
);
173+
]);
174+
},
175+
*barrier(method): Operation<void> {
176+
if (method === "add") {
177+
if (holding) {
178+
enteredWhileHeld = true;
179+
}
180+
mutationEntered.resolve();
181+
return;
182+
}
183+
if (method === "observe" && !holding) {
184+
holding = true;
185+
readHeld.resolve();
186+
// Long enough that a mutation on a queue of its own would have
187+
// reached the host by now, and short enough to end the case.
188+
yield* race([
189+
mutationEntered.operation,
190+
(function* (): Operation<void> {
191+
yield* sleep(2000);
192+
})(),
193+
]);
194+
holding = false;
195+
releaseRead.resolve();
196+
}
197+
},
198+
},
199+
),
200+
);
201+
yield* releaseRead.operation;
202+
// The read has finished its own turn; the mutation may now proceed.
203+
yield* race([
204+
mutationEntered.operation,
205+
(function* (): Operation<void> {
206+
yield* sleep(30_000);
207+
throw new Error("the mutation never reached native Git");
208+
})(),
209+
]);
210+
return yield* task;
211+
});
212+
213+
// Nothing of this entry's own Git entered while its read held the turn,
214+
// and the mutation did run once the read released it.
215+
expect(enteredWhileHeld).toBe(false);
216+
expect(settled.refusal).toBe(undefined);
217+
expect(readKinds(counted)).toContain("diff");
218+
expect(methodsCalled(counted)).toContain("add");
223219
});
224220

225221
it("answers a completed read after its checkout is repointed", function* () {
226222
const fixture = yield* useObservationFixture();
227223
const place = yield* useEntryPlace(fixture);
224+
const stream = yield* useJournalStream(join(place.root, "entry.md"));
228225
const counted = entryCounters();
229226
yield* writeFixtureFile(fixture.root, "src/a.ts", "export const a = 23;\n");
230227

@@ -235,7 +232,7 @@ describe("ROB5 — cancellation, persistence and ownership, on a native host", (
235232
"",
236233
].join("\n");
237234

238-
const live = yield* scoped(() => runEntry(place, source, new InMemoryStream(), counted));
235+
const live = yield* scoped(() => runEntry(place, source, stream, counted));
239236
expect(live.refusal).toBe(undefined);
240237
expect(readKinds(counted)).toContain("changes");
241238

0 commit comments

Comments
 (0)